com.netflix.astyanax.connectionpool
Interface HostConnectionPool<CL>

Type Parameters:
CL -
All Known Implementing Classes:
SimpleHostConnectionPool, TestHostConnectionPool

public interface HostConnectionPool<CL>

Interface for a pool of Connection(s) for a single Host The interface prescribes certain key features required by clients of this class, such as

  1. Basic connection pool life cycle management such as prime connections (init) and shutdown

  2. Basic Connection life cycle management such as borrow / return / close / markAsDown

  3. Tracking the Host associated with the connection pool.

  4. Visibility into the status of the connection pool and it's connections.
    1. Tracking status of pool - isConnecting / isActive / isShutdown
    2. Tracking basic counters for connections - active / pending / blocked / idle / busy / closed etc
    3. Tracking latency scores for connections to this host.
    4. Tracking failures for connections to this host.
This class is intended to be used within a collection of HostConnectionPool tracked by a ConnectionPool for all the Host(s) within a cassandra cluster.

See Also:
SimpleHostConnectionPool} for sample implementations of this class., ConnectionPool} for references to this class.

Method Summary
 void addLatencySample(long lastLatency, long now)
          Add a single latency sample after an operation on a connection belonging to this pool
 Connection<CL> borrowConnection(int timeout)
          Borrow a connection from the host.
 boolean closeConnection(Connection<CL> 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<CL> connection)
          Return a connection to the host's pool.
 void shutdown()
          Completely shut down this connection pool as part of a client shutdown
 

Method Detail

borrowConnection

Connection<CL> borrowConnection(int timeout)
                                throws ConnectionException
Borrow a connection from the host. May create a new connection if one is not available.

Parameters:
timeout -
Returns:
A borrowed connection. Connection must be returned either by calling returnConnection or closeConnection.
Throws:
ConnectionException

returnConnection

boolean returnConnection(Connection<CL> connection)
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.

Parameters:
connection -
Returns:
True if connection was closed

closeConnection

boolean closeConnection(Connection<CL> connection)
Close this connection and update internal state

Parameters:
connection -

markAsDown

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.


shutdown

void shutdown()
Completely shut down this connection pool as part of a client shutdown


primeConnections

int primeConnections(int numConnections)
                     throws ConnectionException,
                            java.lang.InterruptedException
Create numConnections new connections and add them to the

Throws:
ConnectionException
java.lang.InterruptedException

getHost

Host getHost()
Returns:
Get the host to which this pool is associated

getActiveConnectionCount

int getActiveConnectionCount()
Returns:
Get number of open connections including any that are currently borrowed and those that are currently idel

getPendingConnectionCount

int getPendingConnectionCount()
Returns:
Get the number of pending connection open attempts

getBlockedThreadCount

int getBlockedThreadCount()
Returns:
Get number of threads blocked waiting for a free connection

getIdleConnectionCount

int getIdleConnectionCount()
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

int getBusyConnectionCount()
Returns:
Get number of currently borrowed connections

isReconnecting

boolean isReconnecting()
Returns:
Return true if the pool is marked as down and is trying to reconnect

isActive

boolean isActive()
Returns:
Return true if the pool is active.

isShutdown

boolean isShutdown()
Returns:
Return true if the has been shut down and is no longer accepting traffic.

getScore

double getScore()
Returns:
Return implementation specific score to be used by weighted pool selection algorithms

addLatencySample

void addLatencySample(long lastLatency,
                      long now)
Add a single latency sample after an operation on a connection belonging to this pool

Parameters:
lastLatency -

getOpenedConnectionCount

int getOpenedConnectionCount()
Returns:
Get total number of connections opened since the pool was created

getFailedOpenConnectionCount

int getFailedOpenConnectionCount()
Returns:
Get the total number of failed connection open attempts

getClosedConnectionCount

int getClosedConnectionCount()
Returns:
Get total number of connections closed

getErrorsSinceLastSuccess

int getErrorsSinceLastSuccess()
Returns:
Get number of errors since the last successful operation

getConnectAttemptCount

int getConnectAttemptCount()
Returns:
Return the number of open connection attempts