Académique Documents
Professionnel Documents
Culture Documents
What is CORBA?
• Common Object Request Broker
Architecture
• Communication infrastructure for
distributed objects
• Allows a heterogeneous, distributed
collection of objects to collaborate
transparently
What is CORBA good for?
• Developing distributed applications
• Locating remote objects on a network
• Sending messages and Receiving
response to / from those objects
What is the OMG?
• Designers of CORBA
• Consortium of 700+ companies
– Not including Microsoft
• Members:
• platform vendors
• database vendors
• software tool developers
• corporate developers
• software application vendors
Basic CORBA Architecture
Client Server
request response
ORB ORB
“Object Bus”
ORB
• Object Request Broker
– “Object Bus”
• Handles all communication among objects
• Each host (machine) has its own ORB
• ORBs know how to talk to each other
• ORB also provides basic services to client
ORB Responsibilities
• Find the object implementation for the
request
• Prepare the object implementation to
receive the request
• Communicate the data making up the
request
• Retrieve results of request
• There’s an ORB on the server too
• ORB receives request
IIOP
• Internet Inter-Orb Protocol
• Network or “wire” protocol
• Works across TCP/IP (the Internet
protocol)
Steps for Implementing CORBA
Objects
• Write Interface using IDL.
• Use IDL Compilers.
• Add Implementation code for server objects.
• Server prg to create and register the server
objects.
• Write server prg to create and register server
objects.
• Write client to locate and invoke services.
• Start the naming service and server prg on
server and client prg on client.
IDL
• Interface Definition Language only express
interfaces.
• Defines protocol to access objects
• Like a contract
• Well-specified
• Language-independent
• Language bindings are std by OMG
IDL Example
4. module HelloApp
5. {
6. interface Hello
7. {
8. string sayHello();
9. oneway void shutdown();
10. };
11. };
Stub Skeleton
IDL Interface
implements implements
extends
Remote Object
Client Stub Skeleton
(Server)
Implementing a server
• Creates and initializes an ORB instance
• Gets a reference to the root POA and activates the
POAManager
• Creates a servant instance (the implementation of one
CORBA Hello object) and tells the ORB about it
• Gets a CORBA object reference for a naming context in
which to register the new CORBA object
• Gets the root naming context
• Registers the new object in the naming context under the
name "Hello"
• Waits for invocations of the new object from the client
Implementing Server and Servant
• The servant, HelloImpl, is the
implementation of the Hello IDL interface;
each Hello instance is implemented by a
HelloImpl instance. The servant is a
subclass of HelloPOA.
• The servant contains one method for each
IDL operation, sayHello() and shutdown()
methods. Code to deal with the ORB is
provided by the skeleton.
Importing Required Packages
// The package containing 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;
POA
• Object adapter is the mechanism that connects a request
using an object reference with the server code to service
that request.
• The Portable Object Adapter, or POA, is a particular type
of object adapter that is defined by the CORBA
specification.
The POA is designed to meet the following goals:
• Allow programmers to construct object implementations
that are portable between different ORB products.
• Provide support for objects with persistent identities.
• Provide support for transparent activation of objects.
• Allow a single servant to support multiple object identities
simultaneously.
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"; }
// implement shutdown() method
public void shutdown() { orb.shutdown(false); }
}
public class HelloServer {
public static void main(String args[]) {
try{ // create and initialize the ORB
ORB orb = ORB.init(args, null);
// get reference to rootpoa & activate the POAManager
POA rootpoa =
POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
// create servant and register it with the ORB
HelloImpl helloImpl = new HelloImpl();
helloImpl.setORB(orb);
// get object reference from the servant and convert to CORBA
object
org.omg.CORBA.Object ref =
rootpoa.servant_to_reference(helloImpl);
Hello href = HelloHelper.narrow(ref);
POA Manager
• Each POA object has an associated POAManager object
that controls the processing state of the POAs.
• The POAManager can also deactivate the POA. A POA
Manager may be associated with one or more POA
objects.
The POAManager can have the following states:
• Holding - In this state, associated POAs will queue
incoming requests.
• Active - In this state, associated POAs will start
processing requests.
• Discarding - In this state, associated POAs will discard
incoming requests.
• Inactive - In this state, associated POAs will reject the
requests that have not begun executing as well as as
any new requests.
// get the root naming context
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();
Implementing a client
• Create an ORB
• Get a reference to the Naming Context
• Look up the correct name in that Naming
Context
• Receive an object reference to that object
– Actually, to its Stub
• Invoke methods on the reference
import HelloApp.*; // the package containing our stubsimport
org.omg.CosNaming.*; // HelloClient will use the Naming Serviceimport
org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*; // All
CORBA applications need these classes
ORB orb = ORB.init(args, null);
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
String name = "Hello";
helloImpl = HelloHelper.narrow(ncRef.resolve_str(name));
System.out.println("Obtained a handle on server object: " + helloImpl);
System.out.println(helloImpl.sayHello()); helloImpl.shutdown();
Execution
• start orbd -ORBInitialPort 1050 -
ORBInitialHost localhost
• start java HelloServer -ORBInitialPort
1050 -ORBInitialHost localhost
• java HelloClient -ORBInitialPort 1050 -
ORBInitialHost localhost