Did this page help you?

   Yes   No   Tell us about it...

com.amazonaws.services.simpleworkflow.flow.worker
Class BackoffThrottler

java.lang.Object
  extended by com.amazonaws.services.simpleworkflow.flow.worker.BackoffThrottler

public class BackoffThrottler
extends Object

Used to throttle code execution in presence of failures using exponential backoff logic. The formula used to calculate the next sleep interval is:

 min(pow(backoffCoefficient, failureCount - 1) * initialSleep, maxSleep);
 

Example usage:

 BackoffThrottler throttler = new BackoffThrottler(1000, 60000, 2);
 while(!stopped) {
     try {
         throttler.throttle();
         // some code that can fail and should be throttled
         ...
         throttler.success();
     }
     catch (Exception e) {
         throttler.failure();
     }
 }
 


Constructor Summary
BackoffThrottler(long initialSleep, long maxSleep, double backoffCoefficient)
          Construct an instance of the throttler.
 
Method Summary
 void failure()
          Increment failure count.
 void success()
          Resent failure count to 0.
 void throttle()
          Sleep if there were failures since the last success call.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BackoffThrottler

public BackoffThrottler(long initialSleep,
                        long maxSleep,
                        double backoffCoefficient)
Construct an instance of the throttler.

Parameters:
initialSleep - time to sleep on the first failure
maxSleep - maximum time to sleep independently of number of failures
backoffCoefficient - coefficient used to calculate the next time to sleep.
Method Detail

throttle

public void throttle()
              throws InterruptedException
Sleep if there were failures since the last success call.

Throws:
InterruptedException

success

public void success()
Resent failure count to 0.


failure

public void failure()
Increment failure count.



Copyright © 2010 Amazon Web Services, Inc. All Rights Reserved.