Jacorb's application development is generally divided into the following five steps:
1. Write an IDL interface definition interface Use the IDL (Interface Definition Language) to define in SSS.IDL
2. Compile IDL Interface Definition Generate Java class Compile this interface file: $ IDL -D ../ .. server.idl This command will generate multiple Java source files, the generating of the Java source file according to the Idl of the OMG standard Java language mapping definition. IDL compiler generates Java interfaces PlanSupplier, PlanSupplierOperations, PlanConsumer, PlanConsumerOperations, and piles and skeleton files _PlanSupplierStub, PlanSupplierPOA, PlanSupplierPOATie, PlanConsumerStub, PlanConsumerPOA, PlanComerPOATie. Note that the IDL compiler will generate a directory structure corresponding to the module defined in the IDL interface file. If we don't specify -d .. / .. will create a subdirectory in the current directory.
3. Implementing the interface generated in step 2 Now let's implement the functions described in the interface definition. This Java class is named PlansupplierServerImpl, and PlanconSumerServerImpl, in addition to all of the features described in the interface definition, it should be subclass of class PLANSUPPLIERPOA and PlanconSumerpoa generated in front. The PLANSUPPLIERPOA and PLANCONSUMERPOA include related code that accepts remote calls and returns the results to the client.
4. Write the server startup class and register to ORB to write a class to call the PlansupplierServerImpl and PlanconSumerServerImpl classes, and register it to POA, so that the remote object can access it through the PlansUpplier and Planconsumer interface. I. Initialize Orb orb = Orb.init (Args, Props);
II. Get a POA reference org.omg.Corba.Object objpoaroot = orb.resolve_initial_references ("rootpoa"); // Get root PoA object Poa Poaroot = poahelper.narrow (ObjPoaroot); // Get POA. ORB can get one // initial reference through "rootpoa", this reference is just a CORBA.Object, you need to use PoaHelper to instantiate to POA references.
III. Activate the object Poaroot.The_PoAManager (). Activate (); // Because the reference is "holding" status, in this state, any request cannot be processed. Activate POA activation by calling the activate () method of the POA // PoAManager object. You can now translate a Java object into a CORBA object via POA.
VI. Provides a reference to this object (in order to access the new CORBA object can be accessed by the client) // This process passes through the directory service - Naming server - to complete the org.omg.corba.object objnce = orb.resolve_initial_references "Nameservice"); Nce = NamingContextextHelper.narrow (ObjNCE); // Naming Server Reference Instantiation to the Correct Naming Server Object V. Release CORBA Object Reference // Bind Servant Iterator IT = Servants.KeySet (). Iterator ); Whil (it.hasnext ()) {servant servant = (servant) it.next (); string bindingname = (string) servants.get (servant); org.omg.corba.object obj = poaroot.servant_to_reference (servant) ); // Bind name object to servant's reference namecomponent [] nce.rebind (nct, obj);} // The name of the object is incorporated into bind () parameters, cannot only Passing a string, but should be incompatible with the cosnaming.nameComponents object 5. Write the client to get the service object reference I. Initialize orb = orb.init (args, prOps); ii. Client Get through the Name Server References of services org.omg.corba.object objnce = orb.resolve_initial_references ("NAMESERVICE"); // Get naming services. Use the resolve () method to find the "Nameservice" reference nce = namingContextExThelper.narrow (Objnce); // The result is org.omg.corba.object object, need to instantiate to NamingContextext
After you have successfully compiled all the Java classes, you can now start the server and client in different Java virtual machines. Of course, it should be that the naming service is first started. If the naming service has not started, start using the following command: $ ns / home / me / public_html / ns_ref / home / me / public_html / ns_ref is a local writable file, server And clients can be accessed by URL. This allows the port number, and the server and client can get a reference to the naming service to achieve interview.
Start server: $ jaco lamost.sss.corbaif.corbasrvagent
Then, run the client: $ jaco lamost.sss.corbaif.corbaclntagent