springs.util.retries
Class RetryingStrategy

java.lang.Object
  |
  +--springs.util.retries.RetryingStrategy
All Implemented Interfaces:
java.lang.Cloneable

public class RetryingStrategy
extends java.lang.Object
implements java.lang.Cloneable

A retrying strategy.

Author:
Sergio Ilarri Artigas

Field Summary
private  int _hours
           
private  java.lang.Exception _lastException
           
private  long _millis
           
private  int _mins
           
private  int _nHours
           
private  int _nMillis
           
private  int _nMins
           
private  int _nSecs
           
private  int _secs
           
 
Constructor Summary
RetryingStrategy(long millis, int nMillis, int secs, int nSecs, int mins, int nMins, int hours, int nHours)
          Constructor.
 
Method Summary
 java.lang.Object clone()
           
 long failed(java.lang.Exception e)
          Registers a fail and gets the milliseconds to wait until the next try.
 long getMillisNextAttempt()
          Gets the milliseconds to wait until the next try.
private  void throwOutOfAttemptsException()
          Throws an OutOfAttemptsException.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_millis

private long _millis

_nMillis

private int _nMillis

_nSecs

private int _nSecs

_nMins

private int _nMins

_nHours

private int _nHours

_hours

private int _hours

_mins

private int _mins

_secs

private int _secs

_lastException

private java.lang.Exception _lastException
Constructor Detail

RetryingStrategy

public RetryingStrategy(long millis,
                        int nMillis,
                        int secs,
                        int nSecs,
                        int mins,
                        int nMins,
                        int hours,
                        int nHours)
Constructor. Retries the task in the event of fail according to the following strategy: up to nMillis times waiting in between millis milliseconds, up to nSecs times waiting in between secs seconds, then up to nMins times waiting in between mins minutes, then up to nHours times waiting in between hours hours.

Method Detail

failed

public long failed(java.lang.Exception e)
            throws OutOfAttemptsException
Registers a fail and gets the milliseconds to wait until the next try.

Parameters:
e - the exception thrown.
Returns:
the milliseconds to wait until the next try.
Throws:
OutOfAttemptsException - if there are no more attempts left.
See Also:
Exception, OutOfAttemptsException

getMillisNextAttempt

public long getMillisNextAttempt()
                          throws OutOfAttemptsException
Gets the milliseconds to wait until the next try.

Returns:
the milliseconds to wait until the next try.
Throws:
OutOfAttemptsException - if there are no more attempts left.
See Also:
OutOfAttemptsException

throwOutOfAttemptsException

private void throwOutOfAttemptsException()
                                  throws OutOfAttemptsException
Throws an OutOfAttemptsException.

Throws:
OutOfAttemptsException - always.
See Also:
OutOfAttemptsException

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object