com.twitter.common.net.loadbalancing
Interface LoadBalancingStrategy<K>

All Known Implementing Classes:
LeastConnectedStrategy, MarkDeadStrategy, MarkDeadStrategyWithHostCheck, RandomStrategy, RoundRobinStrategy, SubsetStrategy, TrafficMonitorAdapter

public interface LoadBalancingStrategy<K>

A strategy for balancing request load among backends. Strategies should be externally synchronized, and therefore do not have to worry about reentrant access.


Nested Class Summary
static class LoadBalancingStrategy.ConnectionResult
           
 
Method Summary
 void addConnectResult(K key, LoadBalancingStrategy.ConnectionResult result, long connectTimeNanos)
          Offers information about a connection result.
 void addRequestResult(K key, RequestTracker.RequestResult result, long requestTimeNanos)
          Offers information about a request result.
 void connectionReturned(K key)
          Offers information about a connection that was returned.
 K nextBackend()
          Gets the next backend that a request should be sent to.
 void offerBackends(Set<K> offeredBackends, Closure<Collection<K>> onBackendsChosen)
          Offers a set of backends that the load balancer should choose from to distribute load amongst.
 

Method Detail

offerBackends

void offerBackends(Set<K> offeredBackends,
                   Closure<Collection<K>> onBackendsChosen)
Offers a set of backends that the load balancer should choose from to distribute load amongst.

Parameters:
offeredBackends - Backends to choose from.
onBackendsChosen - A callback that should be notified when the offered backends have been (re)chosen from.

nextBackend

K nextBackend()
              throws ResourceExhaustedException
Gets the next backend that a request should be sent to.

Returns:
Next backend to send a request.
Throws:
ResourceExhaustedException - If there are no available backends.

addConnectResult

void addConnectResult(K key,
                      LoadBalancingStrategy.ConnectionResult result,
                      long connectTimeNanos)
Offers information about a connection result.

Parameters:
key - Backend key.
result - Connection result.
connectTimeNanos - Time spent waiting for connection to be established.

connectionReturned

void connectionReturned(K key)
Offers information about a connection that was returned.

Parameters:
key - Backend key.

addRequestResult

void addRequestResult(K key,
                      RequestTracker.RequestResult result,
                      long requestTimeNanos)
Offers information about a request result.

Parameters:
key - Backend key.
result - Request result.
requestTimeNanos - Time spent waiting for a connection to be established.