Network Deployment (Distributed operating systems), v8.0 > Reference > Developer best practices
Client-side programming tips for the ORB service
Every Internet InterORB Protocol (IIOP) request and response exchange consists of a client-side ORB and a server-side ORB. It is important that any application that uses IIOP is properly programmed to communicate with the client-side ORB.
The following tips should help you ensure that an application that uses IIOP to handle request and response exchanges is properly programmed to communicate with the client-side ORB.
Related
ORBs: Resources for learning
ORB service settings
Manage ORBs
Resolution of initial references to services
Client applications can use the ORBInitRef and ORBDefaultInitRef properties to configure the network location that the 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)You 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.
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:
After these properties are set for services that the ORB supports, Java Platform, Enterprise Edition (Java EE) applications can call the resolve_initial_references function on the ORB, as defined in the CORBA/IIOP specification, to obtain the initial reference to a given service.
Preferred API for obtaining an ORB instance
For Java EE applications, you can 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 Java EE applications (including enterprise beans, Java EE clients and servlets), you 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 Java EE components that are running in the same Java virtual machine process. Use the JNDI approach to take advantage of WLM functionality and cluster failover within the application. For information on how to obtain an InitialContext from a server cluster, see the example for using a CORBA object URL with multiple name server addresses, which is in the topic on getting an initial context by setting the provider URL property.CORBA approach: Because thin-client applications do not run in a Java EE container, they cannot use JNDI interfaces to look up the ORB. In this case, you 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, you 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 this product is deprecated.
API restrictions with sharing an ORB instance among Java EE application components
For performance reasons, it often makes sense to share a single ORB instance among components in a Java EE application. As required by the Java EE Specification, Version 1.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 Java EE applications.
Required use of rmic and idlj that ship with the IBM Developer Kit
The Java Runtime Environment (JRE) used by this product 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_HOME/java/ibm_bin directory. Versions of these tools included with Java development kits in the $JAVA_HOME/bin directory other than the IBM Developer Kit installed with this product are incompatible with this product.
When you install this product, the WAS_HOME/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_HOME/java/ibm_bin directory instead of the JRE standard WAS_HOME/java/bin directory, it is unlikely that you 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_HOME/java/ibm_lib directory.
Before using either the rmic or idlj tool, ensure that the WAS_HOME/java/ibm_bin directory is included in the proper PATH variable search order in the environment. If the application uses IDL files in the WAS_HOME/java/ibm_lib directory, also ensure that the directory is included in the PATH variable.