A The WebLogic Cluster API

Learn how to use the Oracle WebLogic Server Cluster API.

This appendix includes the following sections:

How to Use the API

The WebLogic Cluster public API is contained in a single interface, weblogic.rmi.cluster.CallRouter.

Class java.lang.Object
   Interface weblogic.rmi.cluster.CallRouter
      (extends java.io.Serializable)

A class implementing this interface must be provided to the RMI compiler (rmic) to enable parameter-based routing. Run rmic on the service implementation using these options (to be entered on one line):

$ java weblogic.rmic -clusterable -callRouter 
    <callRouterClass> <remoteObjectClass>

The call router is called by the clusterable stub each time a remote method is invoked. The router is responsible for returning the name of the server to which the call should be routed.

Each server in the cluster is uniquely identified by its name as defined with the WebLogic Server Console. These are the names that the method router must use for identifying servers.

Example: Consider the ExampleImpl class which implements a remote interface Example, with one method foo:

public class ExampleImpl implements Example {
  public void foo(String arg) { return arg; }
}

This CallRouter implementation ExampleRouter ensures that all foo calls with 'arg' < "n" go to server1 (or server3 if server1 is unreachable) and that all calls with 'arg' >= "n" go to server2 (or server3 if server2 is unreachable).

public class ExampleRouter implements CallRouter {
  private static final String[] aToM = { "server1", "server3" };
  private static final String[] nToZ = { "server2", "server3" };

  public String[] getServerList(Method m, Object[] params) {
    if (m.GetName().equals("foo")) {
      if (((String)params[0]).charAt(0) < 'n') {
        return aToM;
      } else {
        return nToZ;
      }
    } else {
      return null;
    }
  }
}

This rmic call associates the ExampleRouter with ExampleImpl to enable parameter-based routing:

$ rmic -clusterable -callRouter ExampleRouter ExampleImpl

Custom Call Routing and Collocation Optimization

If a replica is available on the same server instance as the object calling it, the call will not be load balanced, because it is more efficient to use the local replica.

See Optimization for Collocated Objects.