Corporate Info | News | Solutions | Products | Partners | Services | Events | Download | How To Buy
Using WebLogic Server Clusters: Previous Topic | Next Topic | Contents | Index

The WebLogic Cluster API

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

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

How to use the API

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, which is set by starting the WebLogic Server with the weblogic.system.name property. 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

Copyright © 2000 BEA Systems, Inc. All rights reserved. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.