Jacorb Application Development

Source: Internet
Author: User

Jacorb generally consists of the following five steps:

1. Write the definition of the IDL Interface
The interface is defined in SSS. IDL Using IDL (Interface Definition Language ).

2. Compile the IDL Interface Definition to generate a Java class
Run the following command to compile the interface file:
$ IDL-d.../. server. IDL
This command generates multiple Java source files. The JAVA source files are generated according to the OMG standard IDL-Java language ing definition.
The IDL compiler generates Java interfaces plansupplier, plansupplieroperations, planconsumer, planconsumeroperations, and plansupplierstub, worker, worker, planconsumerstub, planconsumerpoa, and plancomerpoatie.
Note that the IDL compiler will generate a directory structure corresponding to the definition module in the IDL Interface file. If-d... is not specified, a subdirectory will be created in the current directory.

3. Implement the interface generated in step 2
Now we can implement the functions described in the interface definition. This Java class is named plansupplierserverimpl and planconsumerserverimpl. In addition to all the functions described in the interface definition, it should also be a subclass of plansupplierpoa and planconsumerpoa. Plansupplierpoa and planconsumerpoa contain Code related to receiving remote calls and returning results to the client.

4. Write the server startup class and register it with ORB
In this step, you need to write a class to call the plansupplierserverimpl and planconsumerserverimpl classes and register them to PoA so that remote objects can be accessed through the plansupplier and planconsumer interfaces.
I. initialize ORB
Orb = orb. INIT (ARGs, props );

Ii. Obtain a PoA reference
Org. Omg. CORBA. Object objpoaroot = orb. resolve_initial_references ("rootpoa"); // obtain the root PoA object
POA poaroot = poahelper. Narrow (objpoaroot); // obtain PoA. ORB can obtain a // initial reference through "rootpoa". This reference is only a CORBA. object, and poahelper needs to be instantiated as a reference of PoA.

Iii. Activate this object
Poaroot. the_poamanager (). Activate (); // because the reference is in the "hold" status when it was just created, no request can be processed in this status. Activate PoA by calling the activate () method of the PoA // poamanager object. Now, you can use PoA to convert a Java object into a CORBA object.

Vi. provide reference to this object (to enable the newly created CORBA object to be accessed by the client) // this process is completed through the Directory Service -- naming server --.
Org. Omg. CORBA. Object objnce = orb. resolve_initial_references ("nameservice ");
NCE = namingcontextexthelper. Narrow (objnce); // the reference of the naming server is instantiated as the correct name server object

V. Publish a reference to a CORBA object
// Bind 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 );
// Bind the name object to the reference of servant
Namecomponent [] NCT = nce. to_name (bindingname );
NCE. rebind (NCT, OBJ );
} // The object name is passed in as the BIND () parameter. Instead of passing only one string, the cosnaming. namecomponents object that represents the name should be passed in.

5. Write the client to get the service object reference
I. initialize ORB
Orb = orb. INIT (ARGs, props );

II. The client obtains service references through the naming Server
Org. Omg. CORBA. Object objnce = orb. resolve_initial_references ("nameservice"); // obtain the Naming Service. Use the resolve () method
// Search for the reference of "nameservice" on the name server
NCE = namingcontextexthelper. Narrow (objnce); // The returned result is the org. Omg. CORBA. Object object, which needs to be instantiated as namingcontextext

After successfully compiling all Java classes, you can start servers and clients in different Java virtual machines. Of course, the naming service should be started first. If the Naming Service has not been started, run the following command to start it:
$ NS/home/ME/public_html/ns_ref
/Home/ME/public_html/ns_ref is a local writable file, which can be accessed by the server and client through URL. In this way, you can obtain the reference of the Naming Service from both the server and the client without using the port number to achieve mutual access.

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.