Parsing Engine

danbikel.util.proxy
Class Retry

java.lang.Object
  extended by danbikel.util.proxy.Retry
All Implemented Interfaces:
Serializable, InvocationHandler
Direct Known Subclasses:
AbstractSwitchboardUser.SBUserRetry

public class Retry
extends Object
implements InvocationHandler, Serializable

An invocation handler for which proxy instances may be constructed for RMI clients such that if a remote method fails, the method will be re-invoked repeatedly until success. The number of retries of the remote method is specified at construction time.

See Also:
Serialized Form

Field Summary
static int retryIndefinitely
          Indicates to re-try the remote object indefinitely.
 
Constructor Summary
Retry(Object stub, int retries, long sleep)
          Constructs a proxy invocation handler to retry an RMI server in the event of a method failure.
 
Method Summary
 Object invoke(Object proxy, Method method, Object[] args)
           
protected  boolean keepTrying()
          Returns whether to keep trying a remote method in the face of failure.
static Object proxyFor(Object stub, int retries, long sleep)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

retryIndefinitely

public static final int retryIndefinitely
Indicates to re-try the remote object indefinitely.

The value of this constant is -1.

See Also:
Constant Field Values
Constructor Detail

Retry

public Retry(Object stub,
             int retries,
             long sleep)
Constructs a proxy invocation handler to retry an RMI server in the event of a method failure. Note that the total number of tries will be one more than the value of this parameter.

Parameters:
stub - the remote object stub which should be validated and which will be performing the actual method computation
retries - the number of times the method will be re-tried on the RMI server before giving up to re-try indefinitely
sleep - the number of milliseconds to sleep in between tries
Throws:
IllegalArgumentException - if retries is neither non-negative nor retryIndefinitely
Method Detail

proxyFor

public static Object proxyFor(Object stub,
                              int retries,
                              long sleep)

keepTrying

protected boolean keepTrying()
Returns whether to keep trying a remote method in the face of failure. This method is guaranteed to be called before each attempt at a method invocation. By overriding this method, subclasses may perform arbitrary tests to determine whether to stop re-trying the RMI server. The default implementation simply returns true.

Returns:
true under all circumstances

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Specified by:
invoke in interface InvocationHandler
Throws:
Throwable

Parsing Engine

Author: Dan Bikel.