To create and use a Java RMI server object, you must first create a class for the object. This takes two steps. First, you must create an interface that extends the Java interface "java.rmi.Remote". Not only does the interface need to extend Remote, all the methods that can be called remotely must throw the RemoteException. Second, you must write a class that implements the interface. Once this is done, you can create an RMI server object and register it for use with the Java RMI Registry.
Here is a very simple illustration of this concept. First, an interface must be created in Java:
public interface TestRemoteInterface extends Remote { String TestRemoteMethod() throws RemoteException; }
Next, a class that implements the TestRemoteInterface must be written. In the case of the methods of this class, you do not need to throw RemoteException, because the interface method declarations have that. Here is an example of such a class in Java:
public class TestRMIServer implements TestRemoteInterface { public TestRMIServer() {} public String TestRemoteMethod() { return "TestRemoteMethod successfully called."; } }
Once this has been written, compiled, and packaged, you can register the server with the RMI registry. First, you must start the RMI registry on the host that will be the RMI server. You can do this using the command "start rmiregistry". Next, you can use a COBOL program to start the RMI server. In this COBOL program, make a call to the C$JAVA routine with the op-code CJAVA-STARTREMOTESERVER.
Here is an example of the code required to start an RMI server which uses the interface and server classes shown above:
CALL "C$JAVA" USING CJAVA-NEW, "acuUtilities/TestRMIServer", "()V" GIVING REMOTE-SERVER. CALL "C$JAVA" USING CJAVA-STARTREMOTESERVER, REMOTE-SERVER, "TestRemoteInterface", PORT-NUMBER GIVING STATUS-VAL.
The first step is to create the server object. The second step is to start the server. CJAVA-STARTREMOTESERVER takes the remote server object handle just created, the name of the remote server to register, and the port number on which the server will listen. Once the server has started, that instance of the runtime that started it will block and remain running, listening for requests for the server from RMI clients.