org.ov4j.retry
Class RetryHandler

java.lang.Object
  extended by org.ov4j.retry.RetryHandler

public class RetryHandler
extends java.lang.Object

This is the main handler of all retried calls.

Author:
smolloy

Constructor Summary
RetryHandler(IContainer<ClassComparable,RetryableCallId> cont, IContainer<ClassComparable,java.lang.Long> argCont)
          Constructor.
 
Method Summary
 java.lang.Long cacheArgs(java.lang.Object... args)
          Cache arguments of the call.
protected  void callDone(RetryableCall call)
          The call is done, remove it from cache.
 void clear()
          Clear all retry data.
 void close()
          Close the handler.
protected  IRetryable findInstance(java.lang.String className)
          Find an instance of the given class.
 java.lang.Object[] getArgs(java.lang.Long id)
          Retrieve the arguments from cache.
 int getMaximumRetries()
           
 long getRetryInterval()
           
 int getVersionRollover()
           
 void register(java.lang.Class<?> cls, IRetryable instance)
          Registers the instance to receive retry callbacks.
 boolean retry(java.lang.reflect.Method theMethod, java.lang.Object instance, java.lang.Object... args)
          Retry a call.
 void setMaximumRetries(int maximumRetries)
           
 void setRetryInterval(long retryInterval)
           
 void setVersionRollover(int versionRollover)
           
 void unregister(java.lang.Class<?> cls)
          Unregisters the instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RetryHandler

public RetryHandler(IContainer<ClassComparable,RetryableCallId> cont,
                    IContainer<ClassComparable,java.lang.Long> argCont)
             throws java.io.IOException
Constructor.

Parameters:
cont - The container in which to store data.
argCont - The container in which to store arguments
Throws:
java.io.IOException
Method Detail

cacheArgs

public java.lang.Long cacheArgs(java.lang.Object... args)
Cache arguments of the call.

Parameters:
args - Arguments to be cached.
Returns:
Unique ID to retrieve the arguments.

callDone

protected void callDone(RetryableCall call)
                 throws java.io.IOException
The call is done, remove it from cache.

Parameters:
call - Call which is done.
Throws:
java.io.IOException

clear

public void clear()
Clear all retry data.


close

public void close()
Close the handler.


findInstance

protected IRetryable findInstance(java.lang.String className)
Find an instance of the given class.

Parameters:
className -
Returns:
An instance of the specified classname, or null if none was found.

getArgs

public java.lang.Object[] getArgs(java.lang.Long id)
                           throws java.io.IOException
Retrieve the arguments from cache.

Parameters:
id - Unique id to fetch.
Returns:
The arguments associated with this id.
Throws:
java.io.IOException

getMaximumRetries

public int getMaximumRetries()
Returns:
Returns the maximumRetries.

getRetryInterval

public long getRetryInterval()
Returns:
Returns the retryInterval.

getVersionRollover

public int getVersionRollover()
Returns:
The version rollover.

register

public void register(java.lang.Class<?> cls,
                     IRetryable instance)
Registers the instance to receive retry callbacks. NOTES: - Registering a second instance of the same class will override the first one. - Make sure to unregister the instances when they are no longer needed or they will not get garbage collected as the RetryHandler will keep a reference.

Parameters:
cls - Class handled by this instance
instance -

retry

public boolean retry(java.lang.reflect.Method theMethod,
                     java.lang.Object instance,
                     java.lang.Object... args)
Retry a call.

Parameters:
theMethod - Method to be called.
instance - Object on which to call the method.
args - Arguments to pass to the call.
Returns:
Whether or not the call was successfully registered for retry.

setMaximumRetries

public void setMaximumRetries(int maximumRetries)
Parameters:
maximumRetries - The maximumRetries to set.

setRetryInterval

public void setRetryInterval(long retryInterval)
Parameters:
retryInterval - The retryInterval to set.

setVersionRollover

public void setVersionRollover(int versionRollover)
Parameters:
versionRollover - The version rollover to set.

unregister

public void unregister(java.lang.Class<?> cls)
Unregisters the instance.

Parameters:
cls -
See Also:
#register(IRetryable instance)


Copyright © 2004-2007 Steve Molloy. All Rights Reserved.