Client-side programming tips for the Java ORB service

 

Resolution of initial references to services

Client applications can use the ORBInitRef and ORBDefaultInitRef properties to configure the network location that the Java ORB service uses to find a service such as naming. When set, these properties are included in the parameters that are used to initialize the ORB, as illustrated in the following example


org.omg.CORBA.ORB.init(java.lang.String[] args, 
                       java.util.Properties props)

We can set these properties in client code or by command-line argument. It is possible to specify more than one service location by using multiple ORBInitRef property settings (one for each service), but only a single ORBDefaultInitRef value can be specified. For more information about the two properties and the order of precedence that the ORB uses to locate services, read the CORBA/IIOP specification, cited in Object Request Brokers: Resources for learning.

For setting in client code, these properties are com.ibm.CORBA.ORBInitRef.service_name and com.ibm.CORBA.ORBDefaultInitRef, respectively. For example, to specify that the naming service (NameService) is located in sample.server.com at port 2809, set the com.ibm.CORBA.ORBInitRef.NameService property to corbaloc::sample.server.com:2809/NameService.

For setting by command-line argument, these properties are -ORBInitRef and -ORBDefaultInitRef, respectively. To locate the same naming service specified previously, use the following Java command (split here for publication only)

java program -ORBInitRef 
     NameService=corbaloc::sample.server.com:2809/NameService

After these properties are set for services supported by the ORB, J2EE applications obtain the initial reference to a given service by calling the resolve_initial_references function on the ORB, as defined in the CORBA/IIOP specification.

 

Preferred API for obtaining an ORB instance

For J2EE applications, use either of the following approaches. However, it is strongly recommended that you use the Java Naming and Directory Interface (JNDI) approach to ensure that the same ORB instance is used throughout the client application; you avoid the unintended inconsistencies that might occur when different ORB instances are used.

JNDI approach: For J2EE applications (including enterprise beans, J2EE clients and servlets), one can obtain an ORB instance by creating a JNDI InitialContext object and looking up the ORB under the java:comp/ORB name , as illustrated in the following example

javax.naming.Context ctx = new javax.naming.InitialContext();
org.omg.CORBA.ORB orb = 
   (org.omg.CORBA.ORB)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("java:comp/ORB"), 
                                                            org.omg.CORBA.ORB.class);

The ORB instance obtained using JNDI is a singleton object, shared by all the J2EE components that are running in the same Java virtual machine process.

CORBA approach: Because thin-client applications do not run in a J2EE container, they cannot use JNDI interfaces to look up the ORB. In this case, one can obtain an ORB instance by using CORBA programming interfaces, as follows

java.util.Properties props = new java.util.Properties();
java.lang.String[] args = new java.lang.String[0];
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, props);

In contrast to the JNDI approach, the CORBA specification requires that a new ORB instance be created each time the ORB.init method is called. If necessary to change the ORB default settings, one can add ORB property settings to the Properties object that is passed in the ORB.init method call.

The use of the com.ibm.ejs.oa.EJSORB.getORBinstance method, supported in previous releases of WAS is deprecated.

 

API restrictions with sharing an ORB instance among J2EE application components

For performance reasons, it often makes sense to share a single ORB instance among components in a J2EE application. As required by the J2EE Specification, V1.3, all Web and EJB containers provide an ORB instance in the JNDI namespace as java:comp/ORB. Each container can share this instance among application components but is not required to. For proper isolation between application components, application code must comply with the following restrictions:

  • Do not call the ORB shutdown or destroy methods
  • Do not call org.omg.CORBA_2_3.ORB methods register_value_factory or unregister_value_factory

In addition, do not share an ORB instance among application components in different J2EE applications.

 

Required use of rmic and idlj that ship with the IBM Developer Kit

The Java Runtime Environment (JRE) used by WAS includes the rmic and idlj tools. You use the tools to generate Java language bindings for the CORBA/IIOP protocol.

During product installation, the tools are installed in the $WAS_INSTALL/java/ibm_bin directory , where $WAS_INSTALL is the installation directory for the product. Versions of these tools included with Java development kits in the $JAVA_HOME/bin directory other than the IBM Developer Kit installed with WAS are incompatible with WAS.

When you install WAS, the $WAS_INSTALL/java/ibm_bin directory is included in the $PATH search order to enable use of the rmic and idlj scripts provided by IBM. Because the scripts are in the $WAS_INSTALL/java/ibm_bin directory instead of the JRE standard $WAS_INSTALL/java/bin directory, it is unlikely that one can overwrite them when applying maintenance to a JRE not provided by IBM.

In addition to the rmic and idlj tools, the JRE also includes Interface Definition Language (IDL) files. The files are based on those defined by the Object Management Group (OMG) and can be used by applications that need an IDL definition of selected ORB interfaces. The files are placed in the $WAS_INSTALL/java/ibm_lib directory.

Before using either the rmic or idlj tool, ensure that the $WAS_INSTALL/java/ibm_bin directory is included in the proper PATH variable search order in the environment. If your application uses IDL files in the $WAS_INSTALL/java/ibm_lib directory, also ensure that the directory is included in the PATH variable.


 

See Also


Object Request Brokers: Resources for learning

 

Related Information


Manage Object Request Brokers

 



 

 

IBM is a trademark of the IBM Corporation in the United States, other countries, or both.