Jacorb Application Development

Source: Internet
Author: User
Tags object object

Jacorb application development is generally divided into the following five steps:

1. Write IDL Interface definition
interface is defined in SSS.IDL using IDL (Interface Definition Language)

2. Compiling IDL interface definitions to generate Java classes
Compile this interface file using the following command:
$idl-D. /.. Server.idl
This command generates multiple Java source files, and the generation of the Java source files is defined in accordance with the OMG standard Idl-java language mapping.
The IDL compiler produces Java interfaces plansupplier, Plansupplieroperations, Planconsumer, planconsumeroperations, and pile and skeleton files _plansupplierstub , Plansupplierpoa, Plansupplierpoatie, Planconsumerstub, Planconsumerpoa, Plancomerpoatie.
Note the IDL compiler will produce a directory structure that corresponds to the module defined in the IDL interface file. If we do not specify-D. /.., the subdirectory will be created in the current directory.

3. Implement the interface generated in step 2
Now we're going to implement the functionality described in the interface definition. This Java class is named Plansupplierserverimpl, Planconsumerserverimpl, except that to implement all the features described in the interface definition, It should also be subclasses of the class Plansupplierpoa and Planconsumerpoa that were generated earlier. Plansupplierpoa and PLANCONSUMERPOA contain related code that accepts remote calls and returns the results to the client.

4. Write Server startup class and register to Orb
This step is to write a class to invoke the Plansupplierserverimpl and Planconsumerserverimpl classes and register them with POA so that remote objects can access it through the Plansupplier and Planconsumer interfaces.
I. Initializing The Orb
Orb = Orb.init (args, props);

Ii. getting a POA reference
Org.omg.CORBA.Object objpoaroot = orb.resolve_initial_references ("Rootpoa"); Get root PoA object
POA poaroot = Poahelper.narrow (objpoaroot); Get POA. The orb can get AN//initial reference through "Rootpoa", a reference that is just a corba.object and requires the use of poahelper to instance to a POA reference.

Iii. activating the Object
Poaroot.the_poamanager (). Activate (); Because the reference was just created as a "hold" state, no request can be processed in this state. The POA is activated by calling the Activate () method of the PoA//poamanager object. It is now possible to convert a Java object into a CORBA object through POA.

VI. Provide a reference to this object (in order for the newly created CORBA object to be accessed by the client)//This process is accomplished through a directory service-named server
Org.omg.CORBA.Object objnce = orb.resolve_initial_references ("Nameservice");
nce = Namingcontextexthelper.narrow (objnce); The naming server's reference is instantiated as the correct named server object

V. Publish a CORBA object reference
Binding servant
Iterator it = Servants.keyset (). iterator ();
while (It.hasnext ()) {
Servant Servant = (Servant) it.next ();
String bindingname = (string) servants.get (servant);
Org.omg.CORBA.Object obj = poaroot.servant_to_reference (servant);
Binding moniker to servant reference
namecomponent[] NCT = Nce.to_name (bindingname);
Nce.rebind (NCT, obj);
The name of the//object is passed in as a parameter to bind () and cannot pass only one string, but should be passed in to the Cosnaming.namecomponents object representing the name

5. Write client to get service object reference
i.  Initialize orb
    orb = orb.init (args, props);
   
Ii. clients get a reference to a service through a named server
    org.omg.CORBA.Object objnce = orb.resolve_initial _references ("Nameservice"); //Get the naming service. Use the Resolve () method to
                                                                                     //Name of reference to find "Nameservice" on the server
     nce = Namingcontextexthelper.narrow (objnce);  //Return result is a Org.omg.CORBA.Object object that needs to be instantiated as Namingcontextext
   

After all Java classes have been successfully compiled, you can now start servers and clients in different Java virtual machines. Of course, the naming service should start first, and if the naming service has not started, use the following command to start:
$ns/home/me/public_html/ns_ref
/home/me/public_html/ns_ref is a local writable file that both the server and the client can access through the URL. In this way, the port number is not used, and both the server and the client can obtain a reference to the naming service, which enables access to each other.

To start the server:
$jaco lamost.sss.corbaif.CorbaSrvAgent

Next, run the client:
$jaco lamost.sss.corbaif.CorbaClntAgent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.