com.twitter.common.net.loadbalancing
Class MarkDeadStrategyWithHostCheck<S>

java.lang.Object
  extended by com.twitter.common.net.loadbalancing.MarkDeadStrategy<S>
      extended by com.twitter.common.net.loadbalancing.MarkDeadStrategyWithHostCheck<S>
Type Parameters:
S - typically socket address of a backend host.
All Implemented Interfaces:
LoadBalancingStrategy<S>

public class MarkDeadStrategyWithHostCheck<S>
extends MarkDeadStrategy<S>

A load balancing strategy that extends the functionality of the mark dead strategy by integrating a hostChecker that allows hosts to transition out of a dead state if the most recent connection to the host was successful.


Nested Class Summary
protected static class MarkDeadStrategyWithHostCheck.LiveHostChecker<S>
          LiveHostChecker implements Filter to determine whether a host is alive based on the result of the most recent connection attempt to that host.
 
Nested classes/interfaces inherited from interface com.twitter.common.net.loadbalancing.LoadBalancingStrategy
LoadBalancingStrategy.ConnectionResult
 
Field Summary
protected  MarkDeadStrategyWithHostCheck.LiveHostChecker<S> liveHostChecker
           
 
Fields inherited from class com.twitter.common.net.loadbalancing.MarkDeadStrategy
hostChecker
 
Constructor Summary
MarkDeadStrategyWithHostCheck(LoadBalancingStrategy<S> wrappedStrategy, Function<S,BackoffDecider> backoffFactory)
          Creates a mark dead strategy with the given wrapped strategy and backoff decider factory.
 
Method Summary
 void addConnectResult(S backendKey, LoadBalancingStrategy.ConnectionResult result, long connectTimeNanos)
          Overrides the base class implementation by adding this connection result to the host checker.
 
Methods inherited from class com.twitter.common.net.loadbalancing.MarkDeadStrategy
addRequestResult, connectionReturned, nextBackend, offerBackends
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

liveHostChecker

protected final MarkDeadStrategyWithHostCheck.LiveHostChecker<S> liveHostChecker
Constructor Detail

MarkDeadStrategyWithHostCheck

public MarkDeadStrategyWithHostCheck(LoadBalancingStrategy<S> wrappedStrategy,
                                     Function<S,BackoffDecider> backoffFactory)
Creates a mark dead strategy with the given wrapped strategy and backoff decider factory. It uses a hostChecker Predicate that allows hosts to transition out of a dead state if the most recent connection to the host was successful.

Parameters:
wrappedStrategy - one of the implementations of the load balancing strategy.
backoffFactory - backoff decider factory per host.
Method Detail

addConnectResult

public void addConnectResult(S backendKey,
                             LoadBalancingStrategy.ConnectionResult result,
                             long connectTimeNanos)
Overrides the base class implementation by adding this connection result to the host checker.

Specified by:
addConnectResult in interface LoadBalancingStrategy<S>
Overrides:
addConnectResult in class MarkDeadStrategy<S>
Parameters:
backendKey - typically the socket address of the backend.
result - result of what happened when the client tried to connect to this backend.
connectTimeNanos - time took to connect to the backend in nano seconds.