jrunx.cluster
Class ClusterAlgorithm
java.lang.Object
|
+--jrunx.cluster.ClusterAlgorithm
- All Implemented Interfaces:
- ClusterConstants, java.io.Serializable
- Direct Known Subclasses:
- AbstractBuddyAlgorithm, InvocationAlgorithm, RoundRobinAlgorithm
- public abstract class ClusterAlgorithm
- extends java.lang.Object
- implements ClusterConstants, java.io.Serializable
This abstract class represents the base algorithm used in selecting a stub for clustering.
At minimum, subclasses must override the selectService(ArrayList services) method.
When a RemoteInvocationHandler or other invoker of clusterable services uses an
algorithm, it invokes the invokeService(Invocation inv) method.
This causes the algorithm to first select a service using the
selectService(ArrayList services) method, in which an algorithm can use its own
specific means of choosing a ClusterableService from the list of available services.
After selecting the service, the invokeService(Invocation inv, ClusterableService svc)
method is invoked, where svc denotes the selected service. The method
is invoked on the chosen service, and if an Exception occurs it is checked to see whether
it is recoverable (based on ClusterException.isReinvokable(...)). If it
is recoverable, a new service is selected and the method is re-invoked. If it is not
recoverable or if a new service cannot possibly be selected, then the Exception is thrown.
Custom algorithms can be created by extending this class, and by supplying the new class
as an argument to the setAlgorithm method of a ClusterableService (or by adding
it to the service XML, if the service is externalized in jrun.xml or another XML file).
- Author:
- PS Neville
- See Also:
RoundRobinAlgorithm,
BuddyAlgorithm,
StickyRoundRobinAlgorithm, Serialized Form
|
Field Summary |
protected static java.util.Random |
rand
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
rand
protected static java.util.Random rand
ClusterAlgorithm
public ClusterAlgorithm()
selectService
public abstract ClusterableService selectService(java.util.ArrayList services)
throws java.rmi.RemoteException
invokeService
public Invocation invokeService(Invocation inv)
throws java.lang.Throwable
- Throws:
java.rmi.RemoteException - propagated back to the client if there are no valid stubs
invokeService
protected Invocation invokeService(Invocation inv,
ClusterableService svc)
throws java.lang.Throwable
chooseRandom
public static java.lang.Object chooseRandom(java.util.ArrayList objects)
- Convenience method for randomly selecting an object from an array.
chooseStub
public static java.lang.Object chooseStub(java.util.ArrayList objects,
java.lang.String serverName)
- Convenience method for selecting an object from array based on the ServerName.
chooseRandom
public static java.lang.Object chooseRandom(java.util.ArrayList objects,
java.lang.Object exclude)
- Convenience method for randomly selecting an object from an array,
and excluding one of the array's members.
getPrefered
public static ClusterableService getPrefered()
Copyright � 2002 Macromedia Corporation. All Rights Reserved.