bea.com | products | dev2dev | support | askBEA
 Download Docs   Site Map   Glossary 
Search

Using WebLogic Server Clusters

 Previous Next Contents View as PDF  

The WebLogic Cluster API

The following section describes the WebLogic Cluster API including:

 


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

 

Back to Top Previous Next