Beruflich Dokumente
Kultur Dokumente
05/13/12
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.
05/13/12 2
a m
i n
s e r v i c oe b j e c t
c l i e n
i m
o b j e c t p l e m e n s k e l e t o n
s t u
O n
R e t w
B o r k g n
R e t w
B o r k g
o p e r a t i n s y s t e m
o p e r a t i n s y s t e m d a t a d a t a f l o w f l o w
3
l o g i c a l p h
05/13/12
y s i c a l
Object Request Broker (ORB) A software component that mediates transfer of messages from a program to an object located on a remote host. Hides underlying network communications from a programmer. ORB allows you to create software objects whose member functions can be invoked by client programs located anywhere. A server program contains instances of CORBA objects.
05/13/12 4
Object Request Broker (ORB) 1) When a client invokes a member function on a CORBA object, the ORB intercepts the function call. 2) ORB directs the function call across the network to the target object. 3) The ORB then collects the results from the function call returns these to the function call.
05/13/12
Implementation Detail
05/13/12
o b j e c t
c l i e n
r i t t e n
o b j e c t i m p l e m i n J a v a i nC + + s b k y e c l o e m tC +o p + ni l g i en i nng
c o m p
e n
s t u b i n J a v a g e n e r a t e d t h Ce O Ro B j Ae c t i n t e r f a c e b
i lC i n O g R o t B h b i n t e r f a c e
e r a t e j eA e c t
r i t t e n
i n
J a v aO
C +i t + t e n r
i n
05/13/12
05/13/12
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).
05/13/12
10
Interoperable Object Reference (IOR) An IOR is a string that contains encoding for the following information:
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.
Interoperable Object Reference (IOR) The following is an example of the string representation of an IOR [5]:
IOR:000000000000000d49444c3a677269643a312e3000000 00000000001000000000000004c0001000000000015756c74 72612e6475626c696e2e696f6e612e6965000009630000002 83a5c756c7472612e6475626c696e2e696f6e612e69653a67 7269643a303a3a49523a67726964003a
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.
05/13/12 12
Object Servers and Object Clients As in Java RMI, a CORBA distributed object is exported by an object server, similar to the object server in RMI. An object client retrieves a reference to a distributed object from a naming or directory service, to be described, and invokes the methods of the distributed object.
05/13/12
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.
05/13/12
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
05/13/12
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.
05/13/12
16
a m c oi n n 1g t e x t
. . .
. . .
a m c oi n n g t e x t 2
a m c oi n n 1g t e x t
. . .n
a m c oi n n 1g t e x t
. . . o b j e c t n a 1m e
o b j e c t n a nm e
05/13/12
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.
05/13/12
18
05/13/12
19
Example of a naming hierarchy As shown, an object representing the mens clothing department is named store.clothing.men, where store and clothing are naming contexts, and men is an object name.
s t o r e c l o t h i n g A p p l i a n
. c. e. s
. . .
w
05/13/12
e mn
e n
t e l e v
i s i o
n
20
05/13/12
21
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.
d i s t r i b u i m p l e m o b j e c t O
05/13/12
t e d o b j e c t e n t a t i o n a d a p t e r
B
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. 05/13/12 23
The Portable Object Adapter There are different types of CORBA object adapters. The Portable Object Adapter, or POA, is a particular type of object adapter that is defined by the CORBA specification. An object adapter that is a POA allows an object implementation to function with different ORBs, hence the word portable.
05/13/12
24
CORBA Flow
Client Virtual Machine Client Server Virtual Machine Remote Object Skeleton
Stub
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
CORBA Flow
Client Virtual Machine Client Server Virtual Machine
3. Client requests object fromRemote Server Name 4. Name Server returns remote reference Object (and stub gets created) Stub Skeleton
4
Server
CORBA Flow
Client Virtual Machine Client
5 6 7
Stub
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
05/13/12
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); }
05/13/12 31
05/13/12
32
05/13/12
34
The *Operations.java file There is a file HelloOperations.java found in HelloApp/ after you compiled using idlj It is known as a Java operations interface in general It is a Java interface file that is equivalent to the CORBA IDL interface file (Hello.idl)
05/13/12
35
HelloApp/HelloOperations.java package HelloApp; public interface HelloOperations { String sayHello (); } // interface HelloOperations
05/13/12
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
05/13/12
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.
05/13/12
38
HelloHolder.java, the Holder class This final class holds a public instance member of type Hello. Whenever the IDL type is an out or an inout parameter, the Holder class is used (In IDL, a parameter may be declared to be out if it is an output argument, and inout if the parameter contains an input value as well as carries an output value).
05/13/12
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
05/13/12
40
HelloPOA.java, the server skeleton The Java class HelloPOA is the skeleton, the server-side proxy, combined with the portable object adapter. It extends org.omg.PortableServer.Servant, and implements the InvokeHandler interface and the HelloOperations interface. The server class HelloImpl extends HelloPOA
05/13/12
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.
05/13/12
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; // thiet lap gia tri orb public void setORB(ORB orb_val) { orb = orb_val; } // implement sayHello() method public String sayHello() { return "\nHello world !!\n"; } } //end class
43
05/13/12
05/13/12
44
05/13/12
45
The ORB variable is declared and initialized inside the try-catch block. ORB orb = ORB.init(args, null);
05/13/12
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();
05/13/12
47
Managing the Servant Object 4. get the object reference associated with the servant. The narrow() method is required to cast CORBA object references to their proper types. org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloImpl); Hello href = HelloHelper.narrow(ref);
05/13/12
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
05/13/12
50
05/13/12 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
05/13/12
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";
05/13/12
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 ..."); } }
05/13/12 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;
05/13/12 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.
05/13/12
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.*;
05/13/12
58
05/13/12
59
05/13/12
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.
05/13/12
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);
05/13/12
62
05/13/12
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());
05/13/12 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
05/13/12 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
05/13/12 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.
05/13/12 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.
05/13/12
68
http://download.oracle.com/javase/1.4.2/docs/gui de/idl/jidlExample.html
05/13/12
69
Summary-1
the Common Object Request Broker Architecture (CORBA), and a specific CORBA facility based on the architecture: Java IDL
05/13/12
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
05/13/12
Summary-3
72
05/13/12