com.twitter.common.util
Class BackoffDecider.Builder

java.lang.Object
  extended by com.twitter.common.util.BackoffDecider.Builder
Enclosing class:
BackoffDecider

public static class BackoffDecider.Builder
extends Object

Builder class to configure a BackoffDecider. The builder allows for customization of many different parameters to the BackoffDecider, while defining defaults wherever possible. The following defaults are used:


Method Summary
 BackoffDecider build()
          Gets a reference to the built decider object.
 BackoffDecider.Builder groupWith(Set<BackoffDecider> deciderGroup)
          Makes the decider a part of a group.
 BackoffDecider.Builder withBucketCount(int numBuckets)
          Sets the number of time slices that the decider will use to partition aggregate statistics.
 BackoffDecider.Builder withClock(Clock clock)
           
 BackoffDecider.Builder withRandom(Random random)
           
 BackoffDecider.Builder withRecoveryPeriod(Amount<Long,Time> recoveryPeriod)
          Overrides the default recovery period behavior.
 BackoffDecider.Builder withRecoveryType(BackoffDecider.RecoveryType recoveryType)
          Sets the recovery mechanism to use when in the recovery period.
 BackoffDecider.Builder withRequestWindow(Amount<Long,Time> requestWindow)
          Sets the time window over which to analyze failures.
 BackoffDecider.Builder withSeedSize(int seedSize)
          Sets the number of requests that must be accumulated before the error rate will be calculated.
 BackoffDecider.Builder withStatsProvider(StatsProvider statsProvider)
          Sets the stats provider that statistics should be exported to.
 BackoffDecider.Builder withStrategy(BackoffStrategy strategy)
          Overrides the default backoff strategy.
 BackoffDecider.Builder withTolerateFailureRate(double toleratedRate)
          Sets the tolerated failure rate for the decider.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

withSeedSize

public BackoffDecider.Builder withSeedSize(int seedSize)
Sets the number of requests that must be accumulated before the error rate will be calculated. This improves the genesis problem where the first few requests are errors, causing flapping in and out of backoff state.

Parameters:
seedSize - Request seed size.
Returns:
A reference to the builder.

withTolerateFailureRate

public BackoffDecider.Builder withTolerateFailureRate(double toleratedRate)
Sets the tolerated failure rate for the decider. If the rate is exceeded for the time window, the decider begins backing off.

Parameters:
toleratedRate - The tolerated failure rate (between 0.0 and 1.0, exclusive).
Returns:
A reference to the builder.

groupWith

public BackoffDecider.Builder groupWith(Set<BackoffDecider> deciderGroup)
Makes the decider a part of a group. When a decider is a part of a group, it will monitor the other deciders to ensure that all deciders do not back off at once.

Parameters:
deciderGroup - Group to make this decider a part of. More deciders may be added to the group after this call is made.
Returns:
A reference to the builder.

withStrategy

public BackoffDecider.Builder withStrategy(BackoffStrategy strategy)
Overrides the default backoff strategy.

Parameters:
strategy - Backoff strategy to use.
Returns:
A reference to the builder.

withRecoveryPeriod

public BackoffDecider.Builder withRecoveryPeriod(@Nullable
                                                 Amount<Long,Time> recoveryPeriod)
Overrides the default recovery period behavior. By default, the recovery period is equal to the previous backoff period (which is equivalent to setting the recovery period to null here). A non-null value here will assign a fixed recovery period.

Parameters:
recoveryPeriod - Fixed recovery period.
Returns:
A reference to the builder.

withRequestWindow

public BackoffDecider.Builder withRequestWindow(Amount<Long,Time> requestWindow)
Sets the time window over which to analyze failures. Beyond the time window, request history is discarded (and ignored).

Parameters:
requestWindow - The analysis time window.
Returns:
A reference to the builder.

withBucketCount

public BackoffDecider.Builder withBucketCount(int numBuckets)
Sets the number of time slices that the decider will use to partition aggregate statistics.

Parameters:
numBuckets - Bucket count.
Returns:
A reference to the builder.

withRecoveryType

public BackoffDecider.Builder withRecoveryType(BackoffDecider.RecoveryType recoveryType)
Sets the recovery mechanism to use when in the recovery period.

Parameters:
recoveryType - The recovery mechanism to use.
Returns:
A reference to the builder.

withStatsProvider

public BackoffDecider.Builder withStatsProvider(StatsProvider statsProvider)
Sets the stats provider that statistics should be exported to.

Parameters:
statsProvider - Stats provider to use.
Returns:
A reference to the builder.

withRandom

public BackoffDecider.Builder withRandom(Random random)

withClock

public BackoffDecider.Builder withClock(Clock clock)

build

public BackoffDecider build()
Gets a reference to the built decider object.

Returns:
A decider object.