Trabalho de sistemas distribuídos - middleware

Páginas: 7 (1573 palavras) Publicado: 24 de novembro de 2012
Trabalho sobre Middleware
Exemplos de aplicações cliente-servidor

1. Aplicação JAVA - Corba


package address_book_system;
import address_book_system.address_bookPackage.*;

import java.util.Hashtable;
import java.util.Enumeration;

//
//
// AddressBookServant
//
// This servant class is responsible for implementing
// three methods
//
// * String name_from_email (String email );
// * String email_from_name ( String name );
// * void record_user ( String name, String email );
//
//

class AddressBookServant extends _address_bookImplBase
{
private Hashtable name2email;

public AddressBookServant()
{
// Create a new hashtable to store name & email
name2email = new Hashtable();
}

// Get the name of this email userpublic String name_from_email ( String email )
throws unknown_user
{
if (name2email.contains(email))
{
// Begin search for that name
for (Enumeration e = name2email.keys();
e.hasMoreElements();)
{
String name = (String) e.nextElement();
String e_mail = (String) name2email.get(name);

// Match on email ?
if(email.compareTo(e_mail) == 0)
{
return name;
}
}
}

// User not found - throw unknown user exception
throw new unknown_user();
}

// Get the email of this person
public String email_from_name ( String name )
throws unknown_user
{
// If user exists
if (name2email.containsKey(name))
{
// Return email address
return (String) name2email.get(name);
}// User doesn't exist
throw new unknown_user();
}

// Add a new user to the system
public void record_user ( String name, String email )
throws user_exists
{
// Is the user already listed
if (name2email.containsKey( name ) ||
name2email.contains( email ) )
{
// If so, throw exception
throw new user_exists();
}

// Add to our hash tablename2email.put (name, email);
}
}


1.1 - Aplicação Corba - Server Side


package address_book_system;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;

//
//
// AddressBookServer
//
// This server is responsible for creating an object
// request broker (ORB), and registering an AddressBookServant
// with a naming service//
//
public class AddressBookServer
{
public static void main(String args[])
{
try
{
// Create a new object request broker
ORB orb = ORB.init(args, null);

// Create a new address book ...
AddressBookServant servant = new AddressBookServant();

// ... and connect it to our orb
orb.connect(servant);

// Object Request Broker InitialisedSystem.out.println ("Address book ORB initialised");

// Obtain reference for our nameservice
org.omg.CORBA.Object object =
orb.resolve_initial_references("NameService");

// Since we have only an object reference, we must
// cast it to a NamingContext. We use a helper
// class for this purpose
NamingContext namingContext =
NamingContextHelper.narrow(object);

// Add a new namingcomponent for our interface
NameComponent list[] =
{ new NameComponent("address_book", "") };

// Now notify naming service of our new interface
namingContext.rebind(list, servant);

// Wait for clients
for (;;){}
}
catch (Exception e)
{
System.err.println ("ORB Error - " + e);
e.printStackTrace(System.out);
System.exit(0);
}
}
}


1.2 - Aplicação Corba– Client Side


package address_book_system;
import address_book_system.address_bookPackage.*;

import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import java.io.*;

//
//
// AddressBookClient
//
// This client demonstrates the AddressBook server and servant.
// A menu is presented to the user, allow he or she to add
// users, and look up their names & email addresses
//
//...
Ler documento completo

Por favor, assinar para o acesso.

Estes textos também podem ser interessantes

  • Sistemas Distribuidos
  • Sistemas Distribuídos
  • Trabalho de Sistemas Distribuídos
  • Trabalho Sistemas Distribuidos
  • Arquitetura de sistemas distribuidos trabalho
  • Trabalho de sistemas distribuidos
  • Trabalho Sistemas distribuidos
  • trabalho de sistemas distribuidos

Seja um membro do Trabalhos Feitos

CADASTRE-SE AGORA!