Remote Method Invocation with JavaRMI Automatically generated Skeleton





![Initialisation+Registration. . . public static void main(String args[]) {try { // create instance Server Initialisation+Registration. . . public static void main(String args[]) {try { // create instance Server](https://slidetodoc.com/presentation_image/a47a672ae92b102dff2badf2d21a9b18/image-6.jpg)
![Remote Invocation of the Server public class Client { static public void main(String args[]) Remote Invocation of the Server public class Client { static public void main(String args[])](https://slidetodoc.com/presentation_image/a47a672ae92b102dff2badf2d21a9b18/image-7.jpg)






![Initialisation+Registration static public void main(String args[]) { try { // access CORBA, activate POA Initialisation+Registration static public void main(String args[]) { try { // access CORBA, activate POA](https://slidetodoc.com/presentation_image/a47a672ae92b102dff2badf2d21a9b18/image-14.jpg)
![Remote Invocation of the Server class Client { static void main(String args[]) { try{ Remote Invocation of the Server class Client { static void main(String args[]) { try{](https://slidetodoc.com/presentation_image/a47a672ae92b102dff2badf2d21a9b18/image-15.jpg)





- Slides: 20

Remote Method Invocation with Java-RMI Automatically generated Skeleton - Demarshalling - Dispatch Stub - Marshalling Network Server. I Server Client Contains only functionality

What does the client see? • A remote object (proxy, stub) can – be casted to all interface the server implements, – be accessed only via interface methods. • On a remote invocation – non-remote arguments are copied (using serialization), – remote arguments are given as reference, different to local invocation – java. rmi. Remote. Exception can always be thrown. • Remote Objects always support the interface Remote. (Tag interface)

How to build the server? Class diagram: Remote. Object Remote. Server Provided by the JDK Unicast. Remote. Object Activatable Server. Impl Provided by the programer - every method which is remotely invocable must be declared to throw Remote. Exception. - Skeletons/Stubs are created with the JDK tool rmic.

Coordination with a naming service • The naming service (rmiregistry) – is a remote Java object, – manages relationships between Strings (i. e. names) and remote Java objects (on the same host). • remote Java objects register themselves with java. rmi. Naming. bind(String name, Remote obj); java. rmi. Naming. rebind(String name, Remote obj); • the name has the form: “//host: port/identifier“ (default: host=localhost, port=1099) • clients use the name to receive a stub: Remote Naming. lookup(String name);

Examplary Server interface: interface Server. I extends Remote { public void do. Some. Service() throws Remote. Exception; } Server implementation: class Server extends Unicast. Remote. Object implements Server. I { public Server() throws Remote. Exception { super(); } public void do. Some. Service() throws Remote. Exception { System. out. println("Working hard. . "); }. .
![InitialisationRegistration public static void mainString args try create instance Server Initialisation+Registration. . . public static void main(String args[]) {try { // create instance Server](https://slidetodoc.com/presentation_image/a47a672ae92b102dff2badf2d21a9b18/image-6.jpg)
Initialisation+Registration. . . public static void main(String args[]) {try { // create instance Server my. Server = new Server(); // bind it to the naming service Naming. rebind(“//elfe: 4711/Hard. Server", my. Server); // done } catch(Exception ex) { ex. print. Stack. Trace(); System. exit(5); } } }
![Remote Invocation of the Server public class Client static public void mainString args Remote Invocation of the Server public class Client { static public void main(String args[])](https://slidetodoc.com/presentation_image/a47a672ae92b102dff2badf2d21a9b18/image-7.jpg)
Remote Invocation of the Server public class Client { static public void main(String args[]) { try { // locate Server Remote rs = Naming. lookup(“//elfe: 4711/Hard. Server"); Server. I server = (Server. I) rs; // use service server. do. Some. Service(); // done } catch(Exception ex) { ex. print. Stack. Trace(); System. exit(5); } } }

Compilation, Configuration, Startup Compile classes jedi> javac Server. java Server. I. java Client. java Create Skeletons and Stubs jedi> rmic Server Start naming service on elfe> rmiregistry 4711 & Start server on elfe> java Server & Start client somewhere jedi> java Client Working hard. . on elfe

Installation of Jac. ORB • Source code with examples and documentation: http: //www. inf. fu-berlin. de/~brose/jacorb • local installation in the Sun pool: setenv JACO /import/public/opt/Jac. ORB 1_1 setenv PATH $JACO/bin: $PATH setenv CLASSPATH $JACO/lib/idl. jar: $JACO/lib/jacorb. jar: $CLASSPATH cp $JACO/jacorb_properties. template ~/. jacorb_properties edit ~/. jacorb_properties (an install script is on the WWW) • adapt the URL settings in the property file; at least this entry: jacorb. Name. Server. URL=file: /. .

Overview about CORBA Server Client Servant Impl. IDL Interface Servant Skeleton Stub POA ORB POA

Class Hierarchie for CORBA Servers for the Interface Foo Servant <<interface>> Foo. Operations Foo. POA <<interface>> Foo Delegates to Foo. Impl Servants are no CORBA objects Foo. POATie Foo. Delegate. Impl Delegate allows use of inheritence: new Foo. POATie(new Foo. Delegate. Impl()

The CORBA COS Naming Service • A naming context – stores relationships between names and Objects, – is itself a CORBA object (allows hierarchical, potentially cyclic name spaces). • name = sequence<name_components>, name_component=(string id, string kind) • ORB provides bootstrapping with the root context Name. Server (ORB uses jacorb. Name. Server. URL; it points to an IOR) • bind an object in a subcontext Naming. Context. bind(Name n, Object o); • resolve an object Object Naming. Context. resolve(Name n); • create a new sub context Naming. Context. new_context(); Naming. Context. bind_new_context(Name n); • bug in JDK use Naming. Context. Ext !

Examplary Server now in CORBA Server IDL interface: interface Server { void do. Some. Service(); }; Server implementation: class Server. Impl extends Server. POA { public void do. Some. Service() { System. out. println("Working hard. . "); } // main method follows
![InitialisationRegistration static public void mainString args try access CORBA activate POA Initialisation+Registration static public void main(String args[]) { try { // access CORBA, activate POA](https://slidetodoc.com/presentation_image/a47a672ae92b102dff2badf2d21a9b18/image-14.jpg)
Initialisation+Registration static public void main(String args[]) { try { // access CORBA, activate POA ORB orb = org. omg. CORBA. ORB. init(args, null); POA poa = POAHelper. narrow(orb. resolve_initial_references("Root. POA")); poa. the_POAManager(). activate(); // from now on requests are handled !!! // get name server Naming. Context. Ext nc = Naming. Context. Ext. Helper. narrow(orb. resolve_initial_references("N ame. Service")); // generate a server and register it at the POA org. omg. CORBA. Object cob = poa. servant_to_reference(new Server. Impl()); // generate a name Name. Component [] name = new Name. Component[1]; name[0] = new Name. Component( "Hard. Server", "some kind"); // bind server to name nc. bind(name, cob);
![Remote Invocation of the Server class Client static void mainString args try Remote Invocation of the Server class Client { static void main(String args[]) { try{](https://slidetodoc.com/presentation_image/a47a672ae92b102dff2badf2d21a9b18/image-15.jpg)
Remote Invocation of the Server class Client { static void main(String args[]) { try{ // get ORB and naming service ORB orb = org. omg. CORBA. ORB. init(args, null); Naming. Context. Ext nc = Naming. Context. Ext. Helper. narrow(orb. resolve_initial_references(" Name. Service")); // generate the name Name. Component [] name = new Name. Component[1]; name[0] = new Name. Component( "Hard. Server", "some kind"); // query naming service, cast the stub org. omg. CORBA. Object cob = nc. resolve(name); Server server = Server. Helper. narrow(cob); // use the generated Helper class // use service server. do. Some. Service(); } catch(Exception ex){ ex. print. Stack. Trace(); }

Compile the Example • Generate skeleton, stubs, helper classes from the IDL > idl server. idl – Skeletons: Server. POA. java, Server. POATie. java – Stub: _Server. Stub. java – Helpers: Server. Helper. java, Server. Holder. java – Interfaces: Server. java, Server. Operations. java • compile the classes > javac *. java (take care of your CLASSPATH!)

Startup your Scenario • Start the naming service > ns NSIOR should be: file(jacorb. Name. Server. URL) E. g. : file: /home/tnfink/ns. ior • start the server jedi> jaco Server. Impl Server is ready. • Start the client troll> jaco Client Working hard. (auf jedi)

Miscellaneous Methods • Convert CORBA object references to Java Strings: String ORB. object_to_string(org. omg. CORBA. Object obj); org. omg. CORBA. Object ORB. string_to_object(String ior); • test for existance of an CORBA object (i. e. stub) boolean Object. _non_existent(); • test if two CORBA objects are equal boolean Object. _is_equivalent(Object other); a return of false does not guarantee inequality! • Duplicate a CORBA object (reference) Object. duplicate();

Miscellaneous Tools, Parameters • naming service GUI >nmg • analysis of IORs > dior -f ns. ior ------IOR components----Type. Id : IDL: omg. org/Cos. Naming/Naming. Context. Ext: 1. 0 Profile Id : TAG_INTERNET_IOP IIOP Version : 1. 1 Host : 160. 45. 110. 127 Port : 1281. . . • Parameter for debug output (0=none, 1=important, . . . 10) jacorb. verbosity = 0

Java RMI CORBA • Java RMI – is easy to learn and use, – does not support heterogeneity, scalability, reliability • CORBA – needs effort for learning – is a sophisticated industrial tool for the real world.