340 likes | 635 Views
Java/CORBA. CSE525. CORBA. CORBA stands for Common Object Request Broker Architecture It is the product of a consortium called the Object Management Group (OMG) over 800 companies does not include Microsoft which has its own competing architecture DCOM (Distributed Component Object Model).
E N D
Java/CORBA CSE525
CORBA • CORBA stands for Common Object Request Broker Architecture • It is the product of a consortium called the Object Management Group (OMG) • over 800 companies • does not include Microsoft which has its own competing architecture DCOM (Distributed Component Object Model)
CORBA • CORBA defines how software components should be built and how they can interoperate. By choosing CORBA one chooses an open field for distributed computing. • CORBA is middleware; that is, software that bridges clients and servers supporting discovery and communication of distributed objects - often called a “software bus”
CORBA • CORBA provides both • object interoperability (bus) standards • bus services: create objects, delete objects, … • Success of OMG/CORBA is that they create specifications…NOT CODE and they combine this with a requirement that the specification have a demonstrable implementation
CORBA OBJECTS • binary components that can exist anywhere on a network. • remote clients may access these objects via method invocation. • location of component transparent to the client. • implementation language of the server object is unknown to the client.
Language independence • In order to achieve programming language independence the client must know the interface that the service offers. The interface is a contract between client and server. If you advertise a method then you will respond as advertised. • BUT WHAT LANGUAGE FOR THE INTERFACE?
The Interface Definition Language (IDL) • CORBA specifies a language called IDL. • IDL is a purely declarative language, there are no control constructs associated with the language. • An IDL specification can be translated into a C++ header file, a Java interface, an ADA specification, a Smalltalk …., an ObjectiveC ...
IDL • IDL must specify • a components attributes • parent classes it inherits from • exceptions it raises • events it emits • methods it supports including parameters, returns and their types.
IDL • IDL must provide the lowest common denominator (greatest number of common features) of all languages to which IDL can be translated. • IDL is largely influenced by C++
In 1990 the OMG published the Object Management Architecture guide. Revised in 1992 and again in 1995 the main components of the architecture are: • Object Request Broker: • defines the object bus • CORBA services: • defines the system-level framework to deal with the bus. • CORBA facilities • horizontal and vertical application frameworks • Application Objects • consumers of CORBA
The Object Resource Broker (ORB) • This software lets object make requests to and receive responses from other objects located locally or remotely. • VERSIONS • CORBA 1.1 only specified IDL and APIs for interfacing to the ORB • CORBA 2.0 specified interoperability across vendor ORBs
ORBs ORBs must provide • support for static method invocation (compile time determination of method called) or dynamic method invocation (discovery at runtime of the methods offered by an object). • provide an Interface Repository that provides information to other ORBs
An Example • Step 1 : Write the interface. module HelloApp interface Hello { string sayHello(); }; }; • Run a program that translates the IDL to the target language
IDL to Java • The CORBA/Java standards define • the map from IDL to Java • a Java to IDL mapping (to allow RMI to migrate to CORBA) • relationships between IDL and “beans”
Major Java/Corba players The big three are • Visibroker for Java • OrbixWeb • Java IDL
JavaSoft’s IDL • Currently the Java IDL supports both static and dynamic CORBA invocations, but it does not support the “Interface Repository” which is a run-time distributed database that contains the metadata required by ORBs to provide unique and globally identifiable components among multivendor ORBs.
JavaSoft’s IDL Because this ORB comes free with Java 1.2, we include and discuss its usage. • The program “idltojava” translates the idl into a java interface class along with classes that provide for a server skeleton, a client stub, helper classes that contain methods to deal with Corba objects and a class that provides support of “out” and “in-out” parameters which are a part of IDL, but not easily dealt with in Java.
idltojava idltojava -fno-cpp Hello.idl produces 5 files in a subdirectory HelloApp: • Hello.java this is the Java interface version of the IDL. The class extends org.omg.CORBA.object so that CORBA object functionality ispresent • _HelloImplBase.java an abstract class that provides functionality for the server. • _HelloStub.java the client stub that implements the Hello.java interface.
idltojava • HelloHelper.java providing functionality required to cast CORBA object references to their correct type. • HelloHolder.java providing the operations for out, inout arguments which are foreign to Java semantics • The subdirectory containing these files corresponds to the idl module translated into a java package (directory)
RMI vs CORBA • As with RMI, the classes generated are of little concern to the programmer, but do provide the information and run time support for dynamic invocation. The programmer’s concern is the client and the server.
Writing the Client • Import the packages required by the client import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CORBA.*; • declare the client class public class HelloClient { // the main goes here // }
Main program • The main sets up a try-catch block try { //client code } catch(Exception e) { System.out.println(“Error:” + e); e.printStackTrace(System.out); }
Client code • The client needs an ORB ORB orb = ORB.init(args,null); • Orb is asked to locate the object it needs. As with RMI, a naming service will provide this information. org.omg.CORBA.Object objref = orb.resolve_initial_references(“NameService”);
Client code • The naming service object is a generic CORBA object and must be “narrowed” to the correct type. The HelloHelper class is being used here. NamingContext ncRef = NamingContextHelper.narrow(objRef); • Now the goal is to use the naming service object to get a reference to the remote object.
Client code • getting the object requires using the naming service’s method “resolve” which requires a parameter of type NameComponent[]. So we need to first create a NameComponent NameComponent nc = new NameComponent( “Hello” , “”); NameComponent path[] = {nc};
Client code • Now we can get the reference we need Hello helloRef = HelloHelper.narrow( ncRef.resolve(path)); • From this point on the helloRef acts as a local object. String Hello = helloRef.sayHello(); System.out.println(Hello);
Developing the Server • Import the packages required import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import org.omg.CORBA.*;
Developing the Server • Declare the Class to implement the interface public class HelloServant extends _HelloImplBase { public String sayHello() { return “\nHello world\n”; }
Developing the Server • Now declare the Server Class public class HelloServer { static public void main(String args[]) { try { //server code goes here } catch(Exception e) { System.err.println(“Error: “+ e); e.printStackTrace(System.out); }
Developing the Server • The server also needs an ORB ORB orb = ORB.init(args,null); • Now create an instance of the HelloServant class to do the work HelloServant helloRef = new HelloServant(); • and connect the servant to the ORB orb.connect(helloRef);
Developing the Server • The server needs to register with the naming service…but first get this service org.omb.CORBA.Object objRef = orb.resolve_initial_references(“NamingService”) NamingContext ncRef = NamingContextHelper.narrow(objRef); NameComponent nc = new NameComponent (“Hello”,””);
Developing the Server NameComponent path[] = {nc}; • Now register ncRef.rebind(path,helloRef); • and set up a wait to give the service synchronized(sync) { sync.wait(); }
Running the client & server • Start the Java IDL name server tnameserv -ORBInitialPort 32767 & The default port is 900, but only superusers can initiate services on ports under 1024. • Start the server java HelloServer -ORBInitialPort 32767 & • Run the client java HelloClient -ORBInitialPort 32767