Professional Documents
Culture Documents
5/4/2012
CORBA
Defines a framework for object-oriented distributed applications. Allows distributed programs in different languages and different platforms to interact as though they were in a single programming language on one computer. Brings advantages of OO to distributed systems. Allows you design a distributed application as a set of cooperating objects and to reuse existing objects.
5/4/2012 2
naming service
object client
stub
ORB network operating system logical data flow physical data flow
5/4/2012
5/4/2012 4
5/4/2012
Implementation Detail
5/4/2012
5/4/2012
5/4/2012
CORBA Application
Diagram
An ORB compatible with the IOR protocol will allow an object reference to be registered with and retrieved from any IOR-compliant directory service. CORBA object references represented in this protocol are called Interoperable Object References (IORs).
5/4/2012
10
The type of the object. The host where the object can be found. The port number of the server for that object. An object key, a string of bytes identifying the object. The object key is used by an object server to locate the object.
5/4/2012
11
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.
5/4/2012 12
5/4/2012
13
As in Java RMI, a CORBA distributed object is located using an object reference. Since CORBA is language-independent, a CORBA object reference is an abstract entity mapped to a language-specific object reference by an ORB, in a representation chosen by the developer of the ORB.
5/4/2012
14
CORBA specifies a generic directory service. The Naming Service serves as a directory for CORBA objects, and, as such, is platform independent and programming language independent. The Naming Service permits ORB-based clients to obtain references to objects they wish to use. It allows names to be associated with object references. Clients may query a naming service using a predetermined name to obtain the associated object reference.
15
5/4/2012
To export a distributed object, a CORBA object server contacts a Naming Service to bind a symbolic name to the object. The Naming Service maintains a database of names and the objects associated with them. To obtain a reference to the object, an object client requests the Naming Service to look up the object associated with the name . The API for the Naming Service is specified in interfaces defined in IDL, and includes methods that allow servers to bind names to objects and clients to resolve those names.
16
5/4/2012
naming context1
...
naming context2
...
naming context1
...
object name n
naming context1
object name 1
...
5/4/2012
17
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.
18
5/4/2012
5/4/2012
19
clothing
Appliances
...
...
women
5/4/2012
men
television
20
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.
distributed object implementation object adapter ORB
5/4/2012 22
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.
5/4/2012 23
5/4/2012
24
CORBA Flow
Client Virtual Machine Client Server Virtual Machine Remote Object
Stub
Skeleton Server
CORBA Flow
1. Server Creates Remote Object Client Virtual Machine 2. Server Registers Remote Object Client Server Virtual Machine Remote Object
1
Stub
Skeleton Server
2
CORBA Flow
Client Virtual Machine Client Server Virtual Machine
3. Client requests object from Name Server Remote 4. Name Server returns remote reference Object (and stub gets created) Stub Skeleton Server
4
CORBA Flow
Client Virtual Machine Client
5 6 7
Stub
Skeleton Server
5. Client invokes stub method 6. Stub talks to skeleton 7. Skeleton invokes remote object Fred method Name Server Virtual Machine Copyright 1997 Alex Chaffee
5/4/2012
29
Java package interface String int long float double class Method
30
V D
+ CORBA IDL:
module { interface MathLibrary { long add( in long x, in long y ); string About( in string version ); }; };
+ Java :
package Math; public interface MathLibrary { int add (int x, int y); String About(String version); }
5/4/2012 31
5/4/2012
32
The fall command option is necessary for the compiler to generate all the files needed. In general, the files can be found in a subdirectory named <some name>App when an interface file named <some name>.idl is compiled. If the compilation is successful, the following files can be found in a HelloApp subdirectory:
HelloOperations.java HelloHelper.java _HelloStub.java
5/4/2012
5/4/2012
34
5/4/2012
35
HelloApp/HelloOperations.java
package HelloApp; public interface HelloOperations { String sayHello (); } // interface HelloOperations
5/4/2012
36
HelloApp/Hello.java
This interface contains the Java version of our IDL interface. The Hello.java interface extends org.omg.CORBA.Object, providing standard CORBA object functionality. It also extends the HelloOperations interface and org.omg.CORBA.portable.IDLEntity.
package HelloApp; public interface Hello extends HelloOperations, org.omg.CORBA.Object, org.omg.CORBA.portable.IDLEntity { } // interface Hello
5/4/2012
37
The Java class HelloHelper provides auxiliary functionality needed to support a CORBA object in the context of the Java language. In particular, a method, narrow,allows a CORBA object reference to be cast to its corresponding type in Java, so that a CORBA object may be operated on using syntax for Java object. The Helper class is responsible for reading and writing the data type to CORBA streams, and inserting and extracting the data type from anythings.
5/4/2012
38
5/4/2012
39
_HelloStub.java
The Java class HelloStub is the stub file, the client-side proxy, providing CORBA functionality for the client . It extends
org.omg.CORBA.portable.ObjectImpl
5/4/2012
40
5/4/2012
41
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.
5/4/2012
42
//
02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13.
compilation of
01.import
HelloApp.*; import org.omg.CosNaming.*; import java.util.Properties; class HelloImpl extends HelloPOA { private ORB orb; public void setORB(ORB orb_val) { orb = orb_val; } // implement sayHello() method public String sayHello() { return "\nHello world !!\n"; } } //end class
43
5/4/2012
5/4/2012
44
Understanding HelloServer.java
1. Creating and Initializing an ORB Object
A CORBA server needs a local ORB object, as does the CORBA client.
The ORB variable is declared and initialized inside the try-catch block. ORB orb = ORB.init(args, null);
5/4/2012
46
Understanding HelloServer.java
2. Get a Reference to the Root POA and Activate the POAManager The ORB obtains the initial object references to services such as the Name Service using the method resolve_initial_references
The reference to the root POA is retrieved and the POAManager is activated from within the try-catch block. POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate();
5/4/2012
47
5/4/2012
49
The string "NameService" is defined for all CORBA ORBs. When you pass in that string, the ORB returns a naming context object that is an object reference for the name service
5/4/2012
50
5/4/2012 51
Registering the Servant with the Name Server 6. Registers the new object in the naming context under the name "Hello":
Finally, we pass path and the servant object to the naming service, binding the servant object to the "Hello" id: ncRef.rebind(path, href); Now, when the client calls resolve("Hello") on the initial naming context, the naming service returns an object reference to the Hello servant.
52
5/4/2012
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. //To use it as a NamingContextExt object, you must // narrow it to its proper type NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); // bind the Object Reference in Naming String name = "Hello";
5/4/2012
54
HelloApp/HelloServer.java - continued
//This operation converts a Stringified Name into an // equivalent array of Name Components. NameComponent path[] = ncRef.to_name( name ); ncRef.rebind(path, href); System.out.println("HelloServer ready and waiting ..."); // wait for invocations from clients orb.run(); } catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out); } System.out.println("HelloServer Exiting ..."); } }
5/4/2012 55
Understanding HelloServer.java
Importing Required Packages
// The package containing our stubs import HelloApp.*; // HelloServer will use the naming service import org.omg.CosNaming.*; // The package containing special exceptions thrown by the name service import org.omg.CosNaming.NamingContextPackage.*; // All CORBA applications need these classes import org.omg.CORBA.*; // Classes needed for the Portable Server Inheritance Model import org.omg.PortableServer.*; import org.omg.PortableServer.POA; // Properties to initiate the ORB import java.util.Properties;
5/4/2012 56
A client program can be a Java application, an applet, or a servlet. The client code is responsible for:
creating and initializing the ORB, looking up the object using the Interoperable Naming Service, invoking the narrow method of the Helper object to cast the object reference to a reference to a Hello object implementation, and invoking remote methods using the reference. The objects sayHello method is invoked to receive a string.
5/4/2012
57
Understanding HelloClient.java
Importing Required Packages import HelloApp.*; // the package containing our stubs // HelloClient will use the Naming Service import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; // All CORBA applications need these classes import org.omg.CORBA.*;
5/4/2012
58
5/4/2012
59
5/4/2012
60
As with all CORBA object references, objRef is a generic CORBA object. To use it as a NamingContextExt object, you must narrow it to its proper type.
5/4/2012
61
To publish a reference in the Naming Service to the Hello object implementing the Hello interface, you first need an identifying string for the Hello object. String name = "Hello"; Finally, we pass name to the naming service's resolve_str() method to get an object reference to the Hello server and narrow it to a Hello object: helloImpl = HelloHelper.narrow(ncRef.resolve-str(name)); System.out.println("Obtained a handle on server object: " + helloImpl);
5/4/2012
62
5/4/2012
63
// 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());
5/4/2012 64
2. Copy the directory containing Hello.idl (including the subdirectory generated by idlj) to the client
machine.
3. In the
HelloApp directory on the client machine: create HelloClient.java. Compile the *.java files,
including the stubs and skeletons (which are in the directory HelloApp):
javac *.java HelloApp/*.java
5/4/2012 65
Compiling and Running a Java IDL application 4. In the HelloApp directory on the server machine:
Create HelloServer.java. Compile the .java files: javac *.java HelloApp/*.java On the server machine: Start the Java Object Request Broker Daemon, orbd, which includes a Naming Service.
To do this on Unix:
orbd -ORBInitialPort 1050 -ORBInitialHost servermachinename&
To do this on Windows:
start orbd -ORBInitialPort 1050 -ORBInitialHost servermachinename
5/4/2012
66
Compiling and Running a Java IDL application 5. On the server machine, start the Hello server, as follows:
java HelloServer ORBInitialHost <nameserver host name> -ORBInitialPort 1050
6. On the client machine, run the Hello application client. From a DOS prompt or shell, type:
java HelloClient -ORBInitialHost nameserverhost -ORBInitialPort 1050
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.
5/4/2012 67
7. Kill or stop orbd when finished. The name server will continue to wait for invocations until it is explicitly stopped. 8. Stop the object server.
5/4/2012
68
http://download.oracle.com/javase/1.4.2/docs/gui de/idl/jidlExample.html
5/4/2012
69
Summary-1
the Common Object Request Broker Architecture (CORBA), and a specific CORBA facility based on the architecture: Java IDL
5/4/2012
70
Summary-2
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.
71
5/4/2012
Summary-3
72
5/4/2012