com.netflix.astyanax.connectionpool.impl
Class SimpleHostConnectionPool<CL>

java.lang.Object
  extended by com.netflix.astyanax.connectionpool.impl.SimpleHostConnectionPool<CL>
All Implemented Interfaces:
HostConnectionPool<CL>

public class SimpleHostConnectionPool<CL>
extends Object
implements HostConnectionPool<CL>

Pool of connections for a single host. Features 1. Async open connection 2.

Author:
elandau

Nested Class Summary
static interface SimpleHostConnectionPool.Listener<CL>
          Interface to notify the owning connection pool of up/down state changes.
 
Field Summary
protected  ConnectionPoolConfiguration config
           
 
Constructor Summary
SimpleHostConnectionPool(Host host, ConnectionFactory<CL> factory, ConnectionPoolMonitor monitor, ConnectionPoolConfiguration config, SimpleHostConnectionPool.Listener<CL> listener)
           
 
Method Summary
 void addLatencySample(long latency, long now)
          Add a single latency sample after an operation on a connection belonging to this pool
 Connection<CL> borrowConnection(int timeout)
          Create a connection as long the max hasn't been reached
 boolean closeConnection(Connection<CL> connection)
          Close this connection and update internal state
 int getActiveConnectionCount()
          Get number of open connections including any that are currently borrowed and those that are currently idel
 int getBlockedThreadCount()
          Get number of threads blocked waiting for a free connection
 int getBusyConnectionCount()
          Get number of currently borrowed connections
 Host getHost()
          Get the host to which this pool is associated
 int getIdleConnectionCount()
          Return the number of idle active connections.
 double getMeanLatency()
          Get the average latency as calculated by the scoring strategy
 int getPendingConnectionCount()
          Get the number of pending connection open attempts
 double getScore()
          Return implementation specific score to be used by weighted pool selection algorithms
 int growConnections(int numConnections)
          Create numConnections new connections and add them to the
 boolean isShutdown()
          Determine if pool is shut down.
 void markAsDown(ConnectionException reason)
          Mark the host as down.
 Connection<CL> openConnection()
          Open a new connection synchronously
 boolean returnConnection(Connection<CL> connection)
          Return a connection to this host
 void shutdown()
          Completely shut down this connection pool as part of a client shutdown
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

config

protected final ConnectionPoolConfiguration config
Constructor Detail

SimpleHostConnectionPool

public SimpleHostConnectionPool(Host host,
                                ConnectionFactory<CL> factory,
                                ConnectionPoolMonitor monitor,
                                ConnectionPoolConfiguration config,
                                SimpleHostConnectionPool.Listener<CL> listener)
Method Detail

growConnections

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

Specified by:
growConnections in interface HostConnectionPool<CL>
Throws:
ConnectionException
InterruptedException

borrowConnection

public Connection<CL> borrowConnection(int timeout)
                                throws ConnectionException
Create a connection as long the max hasn't been reached

Specified by:
borrowConnection in interface HostConnectionPool<CL>
Parameters:
timeout - - Max wait timeout if max connections have been allocated and pool is empty. 0 to throw a MaxConnsPerHostReachedException.
Returns:
Throws:
TimeoutException - if timeout specified and no new connection is available MaxConnsPerHostReachedException if max connections created and no timeout was specified
ConnectionException

returnConnection

public boolean returnConnection(Connection<CL> connection)
Return a connection to this host

Specified by:
returnConnection in interface HostConnectionPool<CL>
Parameters:
connection -
Returns:
True if connection was closed

closeConnection

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

Specified by:
closeConnection in interface HostConnectionPool<CL>
Returns:

markAsDown

public void markAsDown(ConnectionException reason)
Mark the host as down. No new connections will be created from this host. Connections currently in use will be allowed to continue processing.

Specified by:
markAsDown in interface HostConnectionPool<CL>

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<CL>

openConnection

public Connection<CL> openConnection()
                              throws ConnectionException
Open a new connection synchronously

Specified by:
openConnection in interface HostConnectionPool<CL>
Returns:
Throws:
ConnectionException

isShutdown

public boolean isShutdown()
Description copied from interface: HostConnectionPool
Determine if pool is shut down.

Specified by:
isShutdown in interface HostConnectionPool<CL>
Returns:

getHost

public Host getHost()
Description copied from interface: HostConnectionPool
Get the host to which this pool is associated

Specified by:
getHost in interface HostConnectionPool<CL>
Returns:

getActiveConnectionCount

public int getActiveConnectionCount()
Description copied from interface: HostConnectionPool
Get number of open connections including any that are currently borrowed and those that are currently idel

Specified by:
getActiveConnectionCount in interface HostConnectionPool<CL>
Returns:

getIdleConnectionCount

public int getIdleConnectionCount()
Description copied from interface: HostConnectionPool
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.

Specified by:
getIdleConnectionCount in interface HostConnectionPool<CL>
Returns:

getPendingConnectionCount

public int getPendingConnectionCount()
Description copied from interface: HostConnectionPool
Get the number of pending connection open attempts

Specified by:
getPendingConnectionCount in interface HostConnectionPool<CL>
Returns:

getBlockedThreadCount

public int getBlockedThreadCount()
Description copied from interface: HostConnectionPool
Get number of threads blocked waiting for a free connection

Specified by:
getBlockedThreadCount in interface HostConnectionPool<CL>
Returns:

getBusyConnectionCount

public int getBusyConnectionCount()
Description copied from interface: HostConnectionPool
Get number of currently borrowed connections

Specified by:
getBusyConnectionCount in interface HostConnectionPool<CL>
Returns:

getScore

public double getScore()
Description copied from interface: HostConnectionPool
Return implementation specific score to be used by weighted pool selection algorithms

Specified by:
getScore in interface HostConnectionPool<CL>
Returns:

getMeanLatency

public double getMeanLatency()
Description copied from interface: HostConnectionPool
Get the average latency as calculated by the scoring strategy

Specified by:
getMeanLatency in interface HostConnectionPool<CL>
Returns:

addLatencySample

public void addLatencySample(long latency,
                             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<CL>

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.