Local Objects vs. Distributed Objects: Distributed Object-Based Systems
Local Objects vs. Distributed Objects: Distributed Object-Based Systems
Distributed Objects
Local objects are those whose methods can only be invoked by a local process, a process that runs on the same computer on which the object exists. A distributed object is one whose methods can be invoked by a remote process, a process running on a computer connected via a network to the computer on which the object exists.
remote invocation A B
remote invocation
object registry object client client proxy runtime support network support physical data path logical data path object server server proxy runtime support network support
2-16
Dynamic invocation
declare the interface in IDL, compile the IDL file to generate client and server stubs, link them with client and server side code to generate the client and the server executables referred to as static invocation requires the object interface to be known when the client is being developed the method invocation is composed at run-time
useful for applications where object interfaces are discovered at run-time, e.g. object browser, batch processing systems for object invocations, agents
11
10
12
Object Registry
The RMI API allows a number of directory services to be used for registering a distributed object. One such service is the Java Naming and Directory Interface (JNDI), which is more general than the RMI registry, in the sense that it can be used by applications that do not use the RMI API. We will use a simple directory service called the RMI registry, rmiregistry, which is provided with the Java Software Development Kit (SDK). The RMI Registry is a service whose server, when active, runs on the object servers host machine, by convention and by default on the TCP port 1099.
13
15
The interaction between the stub and the skeleton A time-event diagram describing the interaction between the stub and the skeleton:
stub time skeleton marshal parameters; send Request unmarshal parameters Invoke method execute code and return a value Remote Method
maps the platform-independent stub/skeleton layer to the platform-dependent transport layer; carries out remote reference protocols sets up, maintains, and shuts down connections; and carries out the transport protocol
17
19
...
...
For example:
rmic SomeImpl As a result of the compilation, two proxy files will be generated, each prefixed with the implementation class name:
SomeImpl_skel.class SomeImpl_stub.class.
22
24
25
27
// register the object under the name some registryURL = "rmi://localhost:" + portNum + "/some"; Naming.rebind(registryURL, exportedObj);
The Naming class provides methods for storing and obtaining references from the registry. In particular, the rebind method allow an object reference to be stored in the registry with a URL in the form of rmi://<host name>:<port number>/<reference name> The rebind method will overwrite any reference in the registry bound with the given reference name. If the overwriting is not desirable, there is also a bind method. The host name should be the name of the server, or simply localhost. The reference name is a name of your choice, and should be unique in the registry.
26
28
29
30
32
Note that the syntax for the invocation of the remote methods is the same as for local methods. It is a common mistake to cast the object retrieved from the registry to the interface implementation class or the server object class . Instead it should be cast as the interface class.
33 35
34
36
5. 6.
Open a directory for all the files to be generated for this application. Specify and compile the remote-server interface in SomeInterface.java Implement and compile the interface in SomeImpl.java Use the RMI compiler rmic to process the implementation class and generate the stub file and skelton file for the remote object: rmic SomeImpl The files generated can be found in the directory as SomeImpl_Skel.class and SomeImpl_Stub.class. Steps 3 and 4 must be repeated each time that a change is made to the interface implementation. Create and compile the object server program SomeServer.java. Activate the object server java SomeServer
37
39
3. 4. 5.
Start with a remote interface with a single signature, its implementation using a stub, a server program which exports the object, and a client program which invokes the remote method. Test the template programs on one host until the remote method can be made successfully. 2. Add one signature at a time to the interface. With each addition, modify the client program to invoke the added method. 3. Fill in the definition of each remote method, one at a time. Test and thoroughly debug each newly added method before proceeding with the next one. 4. After all remote methods have been thoroughly tested, develop the client application using an incremental approach. With each increment, test and debug the programs.
38
40
10
The remote method invocation API is an efficient tool for building network applications. It can be used in lieu of the socket API in a network application. Some of the tradeoffs between the RMI API and the socket API are as follows:
The socket API is closely related to the operating system, and hence has less execution overhead. For applications which require high performance, this may be a consideration. The RMI API provides the abstraction which eases the task of software development. Programs developed with a higher level of abstraction are more comprehensible and hence easier to debug.
HelloServer
UnicastRemoteObject
sayHello( )
HelloImpl
HelloClient
listRegistry( ) startRegistry( )
UML diagram
client registry server rebind( ) look up( ) sayHello( )
sequence diagram
41
43
HelloInterface.java
import java.rmi.*; public interface HelloInterface extends Remote { public String sayHello(String name) throws java.rmi.RemoteException; }
42
44
11
HelloImpl.java
import java.rmi.*; import java.rmi.server.*; public class HelloImpl extends UnicastRemoteObject implements HelloInterface { public HelloImpl() throws RemoteException { super(); } public String sayHello(String name) throws RemoteException { return "Hello, World! " + name; } }
45
47
HelloClient.java
public class HelloClient { public static void main(String args[ ]) { try { int RMIPort; String hostName; InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); System.out.println("Enter the RMIRegistry host number: "); hostName = br.readLine(); System.out.println("Enter the RMIRegistry port number: "); String portNum = br.readLine(); RMIPort = Integer.parseInt(portNum); String registryURL = "rmi://"+hostName+":"+portNum+"/hello"; HelloInterface h = (HelloInterface)Naming.lookup(registryURL); System.out.println("Lookup completed "); String message = h.sayHello("Daffy Duck"); System.out.println("HelloClient: " + message); } catch (Exception e) { System.out.println("Exception in HelloClient: " + e); } } }
46
public class HelloServer { public static void main(String args[ ]) { } private static void startRegistry(int RMIPortNum) throws RemoteException { } private static void listRegistry(String registryURL) throws RemoteException, MalformedURLException { } }
48
12
public static void main(String args[ ]) { InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); String portNum, registryURL; try{ System.out.println("Enter the RMIregistry port number:"); portNum = (br.readLine()).trim(); int RMIPortNum = Integer.parseInt(portNum); startRegistry(RMIPortNum); HelloImpl exportedObj = new HelloImpl(); registryURL = "rmi://localhost:" + portNum + "/hello"; Naming.rebind(registryURL,exportedObj); System.out.println("Server registered. Registry currently contains:"); listRegistry(registryURL); System.out.println("Hello Server ready."); } //end try catch (Exception re) { System.out.println("Exception in HelloServer.main: " + re); } }
private static void listRegistry(String registryURL) throws RemoteException, MalformedURLException { System.out.println("Registry " + registryURL + " contains:"); String[] names = Naming.list(registryURL); for (int i =0;i< names.length;i++) System.out.println(names[i]); }
HelloServer.java (listRegistry)
51
HelloServer.java (main)
49
// This method starts an RMI registry at port RMIPortNum if // it does not already exist. private static void startRegistry(int RMIPortNum) throws RemoteException { try { Registry registry = LocateRegistry.getRegistry(RMIPortNum); registry.list(); } catch (RemoteException e) { System.out.println("RMI registry cannot be located at port " + RMIPortNum); Registry registry = LocateRegistry.createRegistry(RMIPortNum); System.out.println("RMI registry created at port " + RMIPortNum);
HelloServer.java (startRegistry)
50 52
13
RMI Callbacks
Callback
Server
...
Client A client issues a request to the server repeatedly until the desired response is obtained. Client A client registers itself with the server, and wait until the server calls back.
53
55
Introduction
In the client server model, the server is passive: the IPC is initiated by the client; the server waits for the arrival of requests and provides responses. Some applications require the server to initiate communication upon certain events. Examples applications are:
monitoring games auctioning voting/polling chat-toom message/bulletin board groupware
Two-way communications
Some applications require that both sides may initiate IPC. Using sockets, duplex communication can be achieved by using two sockets on either side. With connection-oriented sockets, each side acts as both a client and a server.
Process 1
54
56
14
RMI Callbacks
A callback client registers itself with an RMI server. The server makes a callback to each registered client upon the occurrence of a certain event.
Server Clients C1 The callback list
ClientImpl.class
S erverImpl_S tub.class ClientImpl_skel.class
ServerImpl.class
ClientImpl_S tub.class S erverImpl_skel.class
C3
C5
57
59
SomeInterface_stub.class 3,4
X
CallbackInterface_skel.class
CallbackInterface_skel.class 5 CallbackInterface_stub.class 1. Client looks up the interface object in the RMIregistry on the server host. 2. The RMIRegistry returns a remote reference to the interface object. 3. Via the server stub, the client process invokes a remote method to register itself for callback, passing a remote reference to itself to the server. The server saves the reference in its callback list. 4. Via the server stub, the client process interacts with the skeleton of the interface object to access the methods in the interface object. 5. When the anticipated event takes place, the server makes a callback to each registered client via the callback interface stub on the server side and the callback interface skeleton on the client side. SomeServer.class
java.policy
java.polcy
58
60
15
sayHello( )
notifyMe( )
UnicastRemoteObject
HelloServer
HelloImpl
C al lbackClie nt
listRegistry( ) startRegistry( )
UML diagram
client
registry
server rebind( )
sequence diagram
61
63
64
16
9.
Open a directory for all the files to be generated for this application. Specify the remote-server interface, and compile it to generate the interface class file. Build the remote server class by implementing the interface, and compile it using javac. Use rmic to process the server class to generate a stub.class file and a skelton.class file: rmic SomeServer If stub downloading is desired, copy the stub file to an appropriate directory on the HTTP host. Activate the RMIRegistry, if it has not already been activated. Set up a java.policy file. Activate the server, specifying (i) the codebase if stub downloading is desired, (ii) the server host name, and (iii) the security policy file. Obtain the CallbackInterface. Compile it with javac, then use rmic to generate the stub file for the callback.
67
68
17
71
HelloServer, HelloClient
UnicastRemoteObject HelloInterface sayHello UnicastRemoteObject CallbackInterface sayHello
CORBA
The Common Object Request Broker Architecture (CORBA) is a standard architecture for a distributed objects system. CORBA is designed to allow distributed objects to interoperate in a heterogenous environment, where objects can be implemented in different programming language and/or deployed on different platforms
70 72
RMIregistry
HelloServer
18
naming service
object client
stub
ORB network operating system logical data flow physical data flow
73
75
CORBA
CORBA is not in inself a distributed objects facility; instead, it is a set of protocols. A distributed object facility which adhere to these protocols is said to be CORBA-compliant, and the distributed objects that the facility support can interoperate with objects supported by other CORBA-compliant facilities. CORBA is a very rich set of protocols. We will instead focus on the key concepts of CORBA related to the distributed objects paradigm. We will also study a facility based on CORBA: the Java IDL.
74
76
19
Inter-ORB Protocols
The IIOP specification includes the following elements: 1. Transport management requirements: specifies the connection and disconnection requirements, and the roles for the object client and object server in making and unmaking connections. 2. Definition of common data representation: a coding scheme for marshalling and unmarshalling data of each IDL data type. 3. Message formats: different types of message format are defined. The messages allow clients to send requests to object servers and receive replies. A client uses a Request message to invoke a method declared in a CORBA interface for an object and receives a reply message from the server.
77
79
Inter-ORB Protocols
To allow ORBs to be interoperable, the OMG specified a protocol known as the General Inter-ORB Protocol (GIOP), a specification which provides a general framework for protocols to be built on top of specific transport layers. A special case of the protocol is the InterORB Protocol (IIOP), which is the GIOP applied to the TCP/IP transport layer.
Object Bus
An ORB which adheres to the specifications of the IIOP may interoperate with any other IIOP-compliant ORBs over the Internet. This gives rise to the term object bus, where the Internet is seen as a bus that interconnects CORBA objects
CORBA
object
CORBA
object
CORBA
object
ORB
ORB
...
ORB
The Internet
78 80
20
ORB products
There are a large number of proprietary as well as experimental ORBs available: (See CORBA Product Profiles, http://www.puder.org/corba/matrix/)
Orbix IONA Borland Visibroker PrismTechs OpenFusion Web Logic Enterprise from BEA Ada Broker from ENST Free ORBs
81
83
82
84
21
85
87
The representation consists of the character prefix IOR: followed by a series of hexadecimal numeric characters, each character representing 4 bits of binary data in the IOR.
22
naming context1
...
naming context2
...
naming context1
...
object name n
naming context1
object name 1
...
89
91
A Naming Context
A naming context correspond to a folder or directory in a file hierarchy, while object names corresponds to a file. The full name of an object, including all the associated naming contexts, is known as a compound name. The first component of a compound name gives the name of a naming context, in which the second component is accessed. This process continues until the last component of the compound name has been reached. Naming contexts and name bindings are created using methods provided in the Naming Service interface.
90
...
...
women men television
92
23
Object Adapters
In the basic architecture of CORBA, the implementation of a distributed object interfaces with the skeleton to interact with the stub on the object client side. As the architecture evolved, a software component in addition to the skeleton was needed on the server side: an object adapter.
93
95
Object Adapter
An object adapter simplifies the responsibilities of an ORB by assisting an ORB in delivering a client request to an object implementation. When an ORB receives a clients request, it locates the object adapter associated with the object and forwards the request to the adapter. The adapter interacts with the object implementations skeleton, which performs data marshalling and invoke the appropriate method in the object.
94 96
by name);
Concurrency Service: Event Service: for event synchronization; Logging Service: for event logging; Scheduling Service: for event scheduling; Security Service: for security management; Trading Service: for locating a service by the type (instead of Time Service: a service for time-related events; Notification Service: for events notification; Object Transaction Service: for transactional processing.
Each service is defined in a standard IDL that can be implemented by a developer of the service object, and whose methods can be invoked by a CORBA client.
24
97
99
100
25
HelloApp/Hello.java
The signature interface file combines the characteristics of (HelloOperations.java) the Java operations interface with the characteristics of the CORBA classes that it extends.
01. package HelloApp; 03. /** 04. * HelloApp/Hello.java 05. * Generated by the IDL-to-Java compiler (portable), 06. * version "3.1" from Hello.idl 07. */ 09. public interface Hello extends HelloOperations, 10. org.omg.CORBA.Object, 11. org.omg.CORBA.portable.IDLEntity 12. { 13. } // interface Hello
103
HelloApp/HelloOperations.java
The file contains the methods specified in the original IDL file: in this case the methods sayHello( ) and shutdown().
package HelloApp; 01. package HelloApp; 04. /** 05. * HelloApp/HelloOperations.java 06. * Generated by the IDL-to-Java compiler (portable), 07. * version "3.1" from Hello.idl 08. */ 09. 10. public interface HelloOperations 11. { 12. String sayHello (); 13. void shutdown (); 14. } // interface HelloOperations
102
104
26
107
_HelloStub.java
The Java class HelloStub (Figure 7e) is the stub file, the client-side proxy, which interfaces with the client object. It extends org.omg.CORBA.portable.ObjectImpl and implements the Hello.java interface.
The application
Server-side Classes On the server side, two classes need to be provided: the servant and the server. The servant, HelloImpl, is the implementation of the Hello IDL interface; each Hello object is an instantiation of this class.
106
108
27
HelloApp/HelloServer.java continued
// get the root naming context // NameService invokes the transient name service org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt, which is part of the // Interoperable Naming Service (INS) specification. NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // bind the Object Reference in Naming String name = "Hello"; NameComponent path[] = ncRef.to_name( name ); ncRef.rebind(path, href); System.out.println ("HelloServer ready and waiting ..."); // wait for invocations from clients orb.run();
109 111
28
// A sample object client application. import HelloApp.*; import org.omg.CosNaming.*; public class HelloClient{ static Hello helloImpl; public static void main(String args[]){ try{ ORB orb = ORB.init(args, null); org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); helloImpl = HelloHelper.narrow(ncRef.resolve_str(Hello)); System.out.println(helloImpl.sayHello()); helloImpl.shutdown();
To do this on Unix:
orbd -ORBInitialPort 1050 -ORBInitialHost servermachinename&
To do this on Windows:
start orbd -ORBInitialPort 1050 -ORBInitialHost servermachinename
113
115
2.
Copy the directory containing Hello.idl (including the subdirectory generated by idlj) to the client machine. directory on the client machine: create HelloClient.java. Compile the *.java files, including the stubs and skeletons (which are in the directory HelloApp):
HelloApp javac *.java HelloApp/*.java
114
3. In the
all on one line. Note that nameserverhost is the host on which the IDL name server is running. In this case, it is the server machine.
116
29
Summary - 2
Each side requires a proxy which interacts with the systems runtime support to perform the necessary IPC. an object registry must be available which allow distributed objects to be registered and looked up. Among the best-known distributed object system protocols are the Java Remote Method Invocation (RMI), the Distributed Component Object, Model (DCOM), the Common Object Request Broker Architecture (CORBA) , and the Simple Object Access Protocol (SOAP).
117 119
Summary - 1
The distributed object paradigm is at a higher level of abstraction than the message-passing paradigm. Using the paradigm, a process invokes methods of a remote object, passing in data as arguments and receiving a return value with each call, using syntax similar to local method calls. In a distributed object system, an object server provides a distributed object whose methods can be invoked by an object client.
Summary - 3
Java RMI is representative of distributed object systems.
The architecture of the Java Remote Method Invocation API includes three abstract layers on both the client side and the server side. The software for a RMI application includes a remote interface, server-side software, and client-side software. What are the tradeoffs between the socket API and the Java RMI API?
118
120
30
Summary-4
Client callback:
Client callback is useful for an application where the clients desire to be notified by the server of the occurrence of some event. Client callback allows an object server to make remote method call to a client via a reference to a client remote interface.
Summary-6
The key topics introduced with CORBA are:
The basic CORBA architecture and its emphasis on object interoperability and platform independence Object Request Broker (ORB) and its functionalities The Inter-ORB Protocol (IIOP) and its significance CORBA object reference and the Interoperable Object Reference (IOR) protocol CORBA Naming Service and the Interoperable Naming Service (INS) Standard CORBA object services and how they are provided. Object adapters, portable object Adapters (POA) and their significance.
121
123
Summary-5
Client callback:
To provide client callback, the client-side software
supplies a remote interface, instantiate an object which implements the interface, passes a reference to the object to the server via a remote method call to the server. collects these client references in a data structure. when the awaited event occurs, the object server invokes the callback method (defined in the client remote interface) to pass data to the client. Two sets of stub-skeletons are needed: one for the server remote interface, the other one for the client remote interface.
Two sets of stub-skeletons are needed: one for the server remote interface, the other one for the client remote interface.
122
31