Entering content frame

Process documentation Developing Failover-ready RMI-P4 Applications Locate the document in its SAP Library structure

Purpose

To develop a failover-ready RMI-P4 application, you must do some additional coding that allows the system to register your remote objects in the Cross System. The process consists of the same steps as when you developed the Account remote object described in Developing RMI-P4 Applications.

Recommendation

We recommend that you use enterprise beans as remote objects in your applications, and therefore use the EJB failover mechanism instead of the pure RMI-P4 one. For more information about this, see Failover for Enterprise Beans.

Process Flow

The process consists of the same steps as when you developed the Account remote object described in Developing RMI-P4 Applications. You only need to define a factory for your remote objects as explained in step 3.

To better illustrate the programming tasks on each step, we will use the example of a failover-ready Hello remote object.

...

       1.      Define the Hello remote interface.

package exapmles.rmi_p4;

 

import java.rmi.Remote;

 

public interface Hello extends Remote {

  public String sayhello();

}

       2.      Implement the remote interface. You must also implement the com.sap.engine.interfaces.cross.Redirectable interface in this class:

package exapmles.rmi_p4;

 

import com.sap.engine.interfaces.cross.Redirectable;

 

public class RedirectableHelloImpl implements Hello, Redirectable {

  public static final String OBJ_KEY = "Hello Server";

  public String sayhello() {

    return "Hello World!";

  }

 

  public String getIdentifier() {

    return OBJ_KEY;

  }

}

       3.      Define the factory for the implementation of the remote object:

package exapmles.rmi_p4;

 

import com.sap.engine.interfaces.cross.CrossObjectFactory;

 

 

public class HelloObjectFactory implements CrossObjectFactory {

 

  public Object getObject(String s) {

    return new RedirectableHelloImpl();

  }

 

}

       4.      You have to register the HelloObjectFactoryto the Remote Object Container. You do this in the following two steps:

                            a.      Lookup the com.sap.engine.interfaces.cross.CrossInterface using the interfaces/cross string in the lookup() method. To be able to perform the lookup, your application must have a reference to the cross interface.

For more information about setting application references refer to Editing Application References.

                            b.      Call the registerObjectFactory(String name, CrossObjectFactory cof) method of the CrossInterface. The parameter name has the same value as the return value of the getIdentifier() method in the remote object’s implementation class. In this case, the name equals “Hello Server”. As a second parameter to the method, you must provide the HelloObjectFactory.

Note

The code that registers the corresponding object factory must be present on each server process, so that a new instance of the remote object can be created after the call has been redirected.

       5.      You implement the client for the Hello remote object exactly as described for the standard RMI-P4 applications.

 

Leaving content frame