ORBD Name Service
CORBA General Object Services (or COS Name Services) provides the tree directory referenced by the object, just like the file directory provided by the file system. A similar service is provided by TNameServ in earlier versions of JDK. TNAMSERV is a temporary name service, which is only available at runtime. If you close the name service, all name index will disappear. TNAMESERV is still retained in J2SE1.4 to keep and previous versions.
J2SE1.4 ORBD (ORB Backstage Service) service provides temporary and permanent name services. Both services are the implementation of the COS name service. Unlike the temporary name service, the permanent name service provides permanent saving for the name index. That is, even the ORBD is restarted, the permanent name service will automatically restore all name index content.
The client needs to get the root name index before you can start. This can be achieved by the following code:
Org.omg.corba.object objref = orb.resolve_initial_references ("Nameservce");
NamingContexText CTX = NamingContextextHelper.Narrow (Objref);
If you use J2SE1.4 TNAMSERV to provide a temporary name service, the above code header returns an object reference to the temporary name service. Object reference Objref is a universal CORBA object, in order to use it as a NamingContextExt object, you must convert it into a suitable type. Method Narrow is required in CORBA to implement this conversion. Also, if you use ORBD in J2SE 1.4, the above code is returned to an object reference to the permanent name service. If you want to use a temporary name service in ORBD, use the parameter TNAMESERVICE instead of NAMESERVICE:
Org.omg.corba.object objref = orb.resolve_initial_references ("TNAMESERVCE");
NamingContexText CTX = NamingContextextHelper.Narrow (Objref);
NamingContexText and NamingContextextHelper are newly added classes in J2SE1.4. They are extended name service (INS), which is a name system for accessing the URL of the CORBA Name Services, which uses a common boot program and shares a common initial name index. INS is an extension of the COS Name Service, which provides the following new features:
n parsing the character name (such as Company / Department / HumanResources / Expenses).
N CORBA objects Reference URL (CORBALOC: and CORBANAME: format).
n NamingContextext contains standard API functions that can be converted between CosName, URL, and String.
INS can use the following character object reference format:
1. Universal Object Reference (IOR): It is an object reference that ORB can resolve, and can interact with the General ORB protocol and Internet ORB protocol. The client can use the orb.object_to_string (objref) method to get an object reference.
2. URL format for reading: Corbaloc and Corbaname provide the URL address of the CORBA object. CORBALOC does not need to be parsed and specified by the Name service; Corbaname can parse the character name from a specific name index. As follows:
CORBALOC: IIOP: 1.2@somain.com: 3000 / TraderService The above code shows how to get an object reference to TraderService from the 3000 port of the host somedomain.com.
Look at these codes:
CORBANAME :: Somedomain.com: 4000 # conference / speakers
The above code parses the character name from the root name context. In this example, the name service is locked by the URL and then parsing the name conference / speakers. Somdomain.com is the host name, the port number is 4000.
Array add: permanent service
Now let's look at how to develop a permanent service, which can still exist even if it is already in the case where it is creating its process. Also we must also follow the same steps as the previous example to develop: write the IDL interface, implement the interface, develop server and client programs.
In this example we will use the same IDL interface as the previous example, ready.
Compile Add.IDL interfaces with the IDLJ compiler.
Prompt> idlj -fall add.idl
This command generates a client and server framework.
The next step is to implement the interface. The implementation process is similar to the sample code 2. But here we name this implementation is AddserveRVant. This file is shown, for example, code 5.
Code Example 5: AddserveRvant.java
Import arithapp. *;
Import org.omg.corba.orb;
Class Addservant Extends AddPoA {
Private Orb ORB;
Public Addservant (Orb ORB) {
THIS.ORB = ORB;
}
//Mplement the addarrays () Method
Public void addarrays (int A [], int b [],
Arithapp.addpackage.ArrayHolder Result) {
Result.Value = new int [arithapp.add.size];
For (int i = 0; I Result.Value [i] = a [i] b [i]; } } } This permanent server is implemented below. Implementation such as code 6. The server completes the following tasks: n Create and initialize an ORB instance. n Create a server. n Receive references to root POA. n Define the policy that specifies that the server is permanent. n Create a permanent PoA. n Activate the Poamanager of the permanent PoA. n Assume the server with permanent POA. n Get the CORBA object reference to the root name index, then register the object reference under Addserver. n Waiting for the customer's call request. Code Example 6: Addserver3.java Import arithapp. *; Import org.omg.corba.orb; Import org.omg.corba.object; Import org.omg.cosnaming.namecomponent; Import Org.omg.cosnaming.namingContext; Import Org.omg.cosnaming.namingContexTextHelper; Import org.omg.corba.policy; Import Org.omg.PortableServer.Servant; Import Org.omg.PortablesRver. *; Import Org.omg.PortableServer.poA; Public class addserver3 {public static void main (string args []) { Try { // Create and Initialize the ORB ORB ORB = Orb.init (args, null); // Create Servant and Instantiate IT Addservant Servant = New Addservant (ORB); // Get Reference to Rootpoa and Activate The Poamanager Poa rootpoa = poahelper.narrow ORB.Resolve_initial_references ("rootpoa")); // Create the Persistent Policy Policy [] policy = new policy [1]; Policy [0] = rootpoa.create_lifespan_policy ( LifeSpanPolicyValue.Persistent); // Create a persistent poa by passing the policy Poa Poa = Rootpoa.create_poa ("Childpoa", Null, Policy; // Activate Persistentpoa's Poamanager. Without this // all calls to persistent Server Will HANG // Because Poamanager // Will be in the 'hold' state. Poa.the_poamanager (). Activate (); // Associate the Servant with Persistentpoa Poa.activate_Object (servant); // resolve rootnaming context and bind a name // for the servant. // "NameService" is buy it .... Persistent Name Service. Org.omg.corba.Object obj = Orb.resolve_initial_references ("Nameservice"); NamingContexText rootcontext = NamingContexTextHelper.narrow (obj); // bind the object reference in the naming context NameComponent [] nc = Rootcontext.to_name ("addserver"); RootContext.rebind (NC, Poa.servant_to_reference); // Wait for Client Requests Orb.run (); } catch (exception e) { System.err.println ("Exception In addserver3 startup " e); } } }