com.netflix.astyanax.connectionpool.impl
Class RoundRobinExecuteWithFailover<CL,R>

java.lang.Object
  extended by com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl<CL,R>
      extended by com.netflix.astyanax.connectionpool.impl.RoundRobinExecuteWithFailover<CL,R>
Type Parameters:
CL -
R -
All Implemented Interfaces:
ExecuteWithFailover<CL,R>

public class RoundRobinExecuteWithFailover<CL,R>
extends AbstractExecuteWithFailoverImpl<CL,R>

Class that extends AbstractExecuteWithFailoverImpl to provide functionality for borrowing a Connection from a list of HostConnectionPool(s) in a round robin fashion.

It maintains state of the current and next pool to be used by a revolving index over the list of pools, hence round robin. It also maintains state of how many retries have been done for this instance and consults the ConnectionPoolConfiguration.getMaxFailoverCount() threshold.

See Also:
AbstractExecuteWithFailoverImpl} for details on how failover is repeatedly called for ensuring that an {@link Operation} can be executed with resiliency., RoundRobinConnectionPoolImpl} for the impl that references this class., AbstractHostPartitionConnectionPool} for more context on how failover functionality is used within the context of an operation execution

Field Summary
protected  HostConnectionPool<CL> pool
           
protected  java.util.List<HostConnectionPool<CL>> pools
           
protected  int size
           
protected  int waitDelta
           
protected  int waitMultiplier
           
 
Fields inherited from class com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl
config, connection
 
Constructor Summary
RoundRobinExecuteWithFailover(ConnectionPoolConfiguration config, ConnectionPoolMonitor monitor, java.util.List<HostConnectionPool<CL>> pools, int index)
           
 
Method Summary
 Connection<CL> borrowConnection(Operation<CL,R> operation)
           
 boolean canRetry()
           
 HostConnectionPool<CL> getCurrentHostConnectionPool()
           
 int getNextHostIndex()
           
 
Methods inherited from class com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl
getCurrentHost, releaseConnection, tryOperation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pool

protected HostConnectionPool<CL> pool

pools

protected final java.util.List<HostConnectionPool<CL>> pools

size

protected final int size

waitDelta

protected int waitDelta

waitMultiplier

protected int waitMultiplier
Constructor Detail

RoundRobinExecuteWithFailover

public RoundRobinExecuteWithFailover(ConnectionPoolConfiguration config,
                                     ConnectionPoolMonitor monitor,
                                     java.util.List<HostConnectionPool<CL>> pools,
                                     int index)
                              throws ConnectionException
Throws:
ConnectionException
Method Detail

getNextHostIndex

public int getNextHostIndex()

canRetry

public boolean canRetry()
Specified by:
canRetry in class AbstractExecuteWithFailoverImpl<CL,R>
Returns:
boolean

getCurrentHostConnectionPool

public HostConnectionPool<CL> getCurrentHostConnectionPool()
Specified by:
getCurrentHostConnectionPool in class AbstractExecuteWithFailoverImpl<CL,R>
Returns:
HostConnectionPool

borrowConnection

public Connection<CL> borrowConnection(Operation<CL,R> operation)
                                throws ConnectionException
Specified by:
borrowConnection in class AbstractExecuteWithFailoverImpl<CL,R>
Returns:
Connection
Throws:
ConnectionException