com.sas.iquery.util
Class RetryUtil

com.sas.iquery.util.RetryUtil

public class RetryUtil

Utility class to simplify adding a try-retry behavior for methods.

Example:

 RetryUtil.Actor actor = new RetryUtil.Actor() {
     AssociationList list = acList;


Nested Class Summary
static class RetryUtil.ActionFailed
          Exception thrown by the RetryUtil.tryAction() method when the action fails and cannot be retried or all retries fail.
static interface RetryUtil.Actor<V>
           
static class RetryUtil.FailAction
          Exception thrown by the RetryUtil.tryAction() method when the action fails and no retry should be done.
static class RetryUtil.RedoAction
          Exception thrown by the Actor.action() method when a retry should be done.
 
Field Summary
static java.lang.String IQ_RETRYUTIL_LOGGING
          Logging context to enable monitoring of RetryUtil retry behavior.
static java.lang.Integer IQ_RETRYUTIL_MAX_RETRIES_DEFAULT
          Default value for IQ.RetryUtil.MaxRetries if not specified is 10 retries.
static java.lang.String IQ_RETRYUTIL_MAX_RETRIES_PROPNAME
          System property to control the number of retries when attempting to retrieve members from an AssociationList that is being modified.
static java.lang.Integer IQ_RETRYUTIL_WAIT_MS_DEFAULT
          Default value for IQ.RetryUtil.RetryWaitMs is 10 milliseconds wait between attempts.
static java.lang.String IQ_RETRYUTIL_WAIT_MS_PROPNAME
          System property to control the number of milliseconds to wait between attempts to retrieve members from an AssociationList that is being modified.
 
Constructor Summary
RetryUtil()
           
 
Method Summary
static
<T> T
tryAction(RetryUtil.Actor<T> actor)
          Performs the action() of the Actor object and returns the value from that method for either 10 attempts or for the value of the system property "IQ.RetryUtil.MaxRetries".
static
<T> T
tryAction(RetryUtil.Actor<T> actor, org.apache.log4j.Logger logger)
          Performs the action() of the Actor object and returns the value from that method for either 10 attempts or for the value of the system property "IQ.RetryUtil.MaxRetries".
static
<T> T
tryAction(RetryUtil.Actor<T> actor, long maxRetries, long retryWaitMs, org.apache.log4j.Logger logger)
          Performs the action() of the Actor object and returns the value from that method.
 

Field Detail

IQ_RETRYUTIL_WAIT_MS_PROPNAME

public static final java.lang.String IQ_RETRYUTIL_WAIT_MS_PROPNAME
System property to control the number of milliseconds to wait between attempts to retrieve members from an AssociationList that is being modified. A value of 0 or greater will cause the retrieving thread to execute a Thread.sleep(milliseconds) between attempts and any interrupts recieved during that sleep will cause the most recent retry failure to be thrown.

See Also:
Constant Field Values

IQ_RETRYUTIL_WAIT_MS_DEFAULT

public static final java.lang.Integer IQ_RETRYUTIL_WAIT_MS_DEFAULT
Default value for IQ.RetryUtil.RetryWaitMs is 10 milliseconds wait between attempts.


IQ_RETRYUTIL_MAX_RETRIES_PROPNAME

public static final java.lang.String IQ_RETRYUTIL_MAX_RETRIES_PROPNAME
System property to control the number of retries when attempting to retrieve members from an AssociationList that is being modified. A value less than 1 will not retry and will throw the first java.util.ConcurrentModificationException encountered (if any).

See Also:
Constant Field Values

IQ_RETRYUTIL_MAX_RETRIES_DEFAULT

public static final java.lang.Integer IQ_RETRYUTIL_MAX_RETRIES_DEFAULT
Default value for IQ.RetryUtil.MaxRetries if not specified is 10 retries.


IQ_RETRYUTIL_LOGGING

public static final java.lang.String IQ_RETRYUTIL_LOGGING
Logging context to enable monitoring of RetryUtil retry behavior.

See Also:
Constant Field Values
Constructor Detail

RetryUtil

public RetryUtil()
Method Detail

tryAction

public static <T> T tryAction(RetryUtil.Actor<T> actor,
                              org.apache.log4j.Logger logger)
                   throws RetryUtil.ActionFailed
Performs the action() of the Actor object and returns the value from that method for either 10 attempts or for the value of the system property "IQ.RetryUtil.MaxRetries". If that property is set to less than 1, then no retries will be made.

Parameters:
actor -
logger - logger to use for log messages, if null then no logging will be done.
Returns:
result from the Actor.action() call.
Throws:
RetryUtil.ActionFailed - if the action and retries fail, its getCause() should return any exception responsible.

tryAction

public static <T> T tryAction(RetryUtil.Actor<T> actor)
                   throws RetryUtil.ActionFailed
Performs the action() of the Actor object and returns the value from that method for either 10 attempts or for the value of the system property "IQ.RetryUtil.MaxRetries". If that property is set to less than 1, then no retries will be made. By default, this method writes log messages to the IQ.RetryUtil.Logging context.

Parameters:
actor -
Returns:
result from the Actor.action() call.
Throws:
RetryUtil.ActionFailed - if the action and retries fail, its getCause() should return any exception responsible.

tryAction

public static <T> T tryAction(RetryUtil.Actor<T> actor,
                              long maxRetries,
                              long retryWaitMs,
                              org.apache.log4j.Logger logger)
                   throws RetryUtil.ActionFailed
Performs the action() of the Actor object and returns the value from that method. If the retry value is set to less than 1, then no retries will be made.

Parameters:
actor -
maxRetries - maximum number of retries after the first attempt (<1 means no retries).
retryWaitMs - maximum time to wait between attempts in milliseconds (<0 means do not pause the thread).
logger - null if no logger messages should be output.
Returns:
result from the Actor.action() call.
Throws:
RetryUtil.ActionFailed - if the action and retries fail, its getCause() should return any exception responsible.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.