com.netflix.astyanax.test
Class TestHostConnectionPool

java.lang.Object
  extended by com.netflix.astyanax.test.TestHostConnectionPool
All Implemented Interfaces:
HostConnectionPool<TestClient>

public class TestHostConnectionPool
extends java.lang.Object
implements HostConnectionPool<TestClient>


Constructor Summary
TestHostConnectionPool(Host host)
           
 
Method Summary
 void addLatencySample(long lastLatency, long now)
          Add a single latency sample after an operation on a connection belonging to this pool
 Connection<TestClient> borrowConnection(int timeout)
          Borrow a connection from the host.
 boolean closeConnection(Connection<TestClient> connection)
          Close this connection and update internal state
 int getActiveConnectionCount()
           
 int getBlockedThreadCount()
           
 int getBusyConnectionCount()
           
 int getClosedConnectionCount()
           
 int getConnectAttemptCount()
           
 int getErrorsSinceLastSuccess()
           
 int getFailedOpenConnectionCount()
           
 Host getHost()
           
 int getIdleConnectionCount()
           
 int getOpenedConnectionCount()
           
 int getPendingConnectionCount()
           
 double getScore()
           
 boolean isActive()
           
 boolean isReconnecting()
           
 boolean isShutdown()
           
 void markAsDown(ConnectionException reason)
          Shut down the host so no more connections may be created when borrowConnections is called and connections will be terminated when returnConnection is called.
 int primeConnections(int numConnections)
          Create numConnections new connections and add them to the
 boolean returnConnection(Connection<TestClient> connection)
          Return a connection to the host's pool.
 void shutdown()
          Completely shut down this connection pool as part of a client shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestHostConnectionPool

public TestHostConnectionPool(Host host)
Method Detail

borrowConnection

public Connection<TestClient> borrowConnection(int timeout)
                                        throws ConnectionException
Description copied from interface: HostConnectionPool
Borrow a connection from the host. May create a new connection if one is not available.

Specified by:
borrowConnection in interface HostConnectionPool<TestClient>
Returns:
A borrowed connection. Connection must be returned either by calling returnConnection or closeConnection.
Throws:
ConnectionException

returnConnection

public boolean returnConnection(Connection<TestClient> connection)
Description copied from interface: HostConnectionPool
Return a connection to the host's pool. May close the connection if the pool is down or the last exception on the connection is determined to be fatal.

Specified by:
returnConnection in interface HostConnectionPool<TestClient>
Returns:
True if connection was closed

markAsDown

public void markAsDown(ConnectionException reason)
Description copied from interface: HostConnectionPool
Shut down the host so no more connections may be created when borrowConnections is called and connections will be terminated when returnConnection is called.

Specified by:
markAsDown in interface HostConnectionPool<TestClient>

shutdown

public void shutdown()
Description copied from interface: HostConnectionPool
Completely shut down this connection pool as part of a client shutdown

Specified by:
shutdown in interface HostConnectionPool<TestClient>

primeConnections

public int primeConnections(int numConnections)
                     throws ConnectionException,
                            java.lang.InterruptedException
Description copied from interface: HostConnectionPool
Create numConnections new connections and add them to the

Specified by:
primeConnections in interface HostConnectionPool<TestClient>
Throws:
ConnectionException
java.lang.InterruptedException

getHost

public Host getHost()
Specified by:
getHost in interface HostConnectionPool<TestClient>
Returns:
Get the host to which this pool is associated

getActiveConnectionCount

public int getActiveConnectionCount()
Specified by:
getActiveConnectionCount in interface HostConnectionPool<TestClient>
Returns:
Get number of open connections including any that are currently borrowed and those that are currently idel

getPendingConnectionCount

public int getPendingConnectionCount()
Specified by:
getPendingConnectionCount in interface HostConnectionPool<TestClient>
Returns:
Get the number of pending connection open attempts

getBlockedThreadCount

public int getBlockedThreadCount()
Specified by:
getBlockedThreadCount in interface HostConnectionPool<TestClient>
Returns:
Get number of threads blocked waiting for a free connection

getIdleConnectionCount

public int getIdleConnectionCount()
Specified by:
getIdleConnectionCount in interface HostConnectionPool<TestClient>
Returns:
Return the number of idle active connections. These are connections that can be borrowed immediatley without having to make a new connection to the remote server.

getBusyConnectionCount

public int getBusyConnectionCount()
Specified by:
getBusyConnectionCount in interface HostConnectionPool<TestClient>
Returns:
Get number of currently borrowed connections

isReconnecting

public boolean isReconnecting()
Specified by:
isReconnecting in interface HostConnectionPool<TestClient>
Returns:
Return true if the pool is marked as down and is trying to reconnect

getScore

public double getScore()
Specified by:
getScore in interface HostConnectionPool<TestClient>
Returns:
Return implementation specific score to be used by weighted pool selection algorithms

addLatencySample

public void addLatencySample(long lastLatency,
                             long now)
Description copied from interface: HostConnectionPool
Add a single latency sample after an operation on a connection belonging to this pool

Specified by:
addLatencySample in interface HostConnectionPool<TestClient>

closeConnection

public boolean closeConnection(Connection<TestClient> connection)
Description copied from interface: HostConnectionPool
Close this connection and update internal state

Specified by:
closeConnection in interface HostConnectionPool<TestClient>

getOpenedConnectionCount

public int getOpenedConnectionCount()
Specified by:
getOpenedConnectionCount in interface HostConnectionPool<TestClient>
Returns:
Get total number of connections opened since the pool was created

getFailedOpenConnectionCount

public int getFailedOpenConnectionCount()
Specified by:
getFailedOpenConnectionCount in interface HostConnectionPool<TestClient>
Returns:
Get the total number of failed connection open attempts

getClosedConnectionCount

public int getClosedConnectionCount()
Specified by:
getClosedConnectionCount in interface HostConnectionPool<TestClient>
Returns:
Get total number of connections closed

getErrorsSinceLastSuccess

public int getErrorsSinceLastSuccess()
Specified by:
getErrorsSinceLastSuccess in interface HostConnectionPool<TestClient>
Returns:
Get number of errors since the last successful operation

isActive

public boolean isActive()
Specified by:
isActive in interface HostConnectionPool<TestClient>
Returns:
Return true if the pool is active.

isShutdown

public boolean isShutdown()
Specified by:
isShutdown in interface HostConnectionPool<TestClient>
Returns:
Return true if the has been shut down and is no longer accepting traffic.

getConnectAttemptCount

public int getConnectAttemptCount()
Specified by:
getConnectAttemptCount in interface HostConnectionPool<TestClient>
Returns:
Return the number of open connection attempts