This section tells you how to use the RMI-IIOP development style to create a stateless CORBA object application (approach 2 in Developing stateless CORBA objects, rather than the CORBA development approach described in previous sections).
When using RMI-IIOP there is no need to define an interface using IDL—though, if required, the IDL can optionally be generated later. Instead, we start by defining at least one remote interface. Note that, in this context, a “remote interface” means any Java interface that extends java.rmi.Remote. This is not the same thing as an enterprise bean's “Remote Interface”. Using the terminology just defined, both an enterprise bean's Remote Interface and its Home Interface would qualify as “remote interfaces”, because they both ultimately extend java.rmi.Remote.
package hello;
public interface HelloWorldRMI extends java.rmi.Remote
{
public String sayHello(String msgFromClient) throws java.rmi.RemoteException;
}
The above interface defines a single method called sayHello that takes a String as a parameter and returns a String. All the methods on the interface must be defined to throw java.rmi.RemoteException.
package hello;
public class _HelloWorldRMIImpl implements HelloWorldRMI
{
public String sayHello(String msgFromClient)
{ return "Hello: You said: " + msgFromClient;}
}
The implementation class implements the interface previously created. The naming convention used for the implementation class is _<interface name>Impl. This naming convention is required if the server object is to be located using the CORBA CosLifeCycle Generic Factory approach. If you do not use this naming convention, the Generic Factory will not be able to construct instances of your stateless CORBA object.
One of the advantages of RMI-IIOP over the more traditional IDL-based development process is that you are not forced to extend a base class. This means that you can chose to use your own inheritance hierarchy if you wish. You may also implement multiple remote interfaces with a single server object.
You should compile both of the above classes using the javac compiler or equivalent.
The next thing to do is to produce the server-side Tie file for this stateless CORBA object. This is done using the RMI compiler (RMIC). You must use an RMI compiler shipped with an IBM® Java 2 SDK. If you use the version of RMIC supplied with a Sun MicroSystems' Java 2 SDK, the generated Tie file is not guaranteed to work with the CICS® ORB.
rmic -iiop hello._HelloWorldRMIImpl
Note
that RMIC is being run against the server-side implementation class.rmic -iiop hello.HelloWorldRMI
Note
that RMIC is being run against the remote interface class. hello\HelloWorldRMI.class - the remote interface
hello\_HelloWorldRMIImpl.class - the stateless CORBA object
hello\__HelloWorldRMIImpl_Tie.class - the RMI-IIOP server side Tie file
hello\_HelloWorldRMI_Stub.class - the RMI-IIOP client side Stub file
ORB orb = ORB.init((String[]) null, (java.util.Properties) null);
// The following method reads the generic factory IOR from a file and returns
// it in the string
String factoryIOR = getFactoryIOR();
// Turn the stringified reference into the proxy
org.omg.CORBA.Object genFacRef = orb.string_to_object(factoryIOR);
// narrow to correct interface
GenericFactory fact = GenericFactoryHelper.narrow(genFacRef);
// The Generic factory needs a key, which is a sequence of namecomponents
NameComponent nc = new NameComponent("hello::HelloWorldRMI","object interface");
//Now create the object
org.omg.CORBA.Object objRef=fact.create_object(new NameComponent[]{nc},
new NVP[] {});
// and narrow to correct interface using the RMI-IIOP narrow operation
HelloWorldRMI remote = (HelloWorldRMI) javax.rmi.PortableRemoteObject.narrow
(objRef, HelloWorldRMI.class);
// Invoke the remote method
System.out.println("Received from Server: "+remote.sayHello("Hi!")+"\n");}
As with the IDL-based client application, it will be necessary to have the omgcos.jar file from the CICS lib HFS directory on your workstation and client machines in order to find the CosLifeCycle classes.
All that remains is to package the server- and client-side applications into JAR files and to add the server-side JAR file to the CICS shareable application class path.
rmic -idl hello.HelloWorldRMI