|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.netflix.astyanax.connectionpool.impl.SimpleHostConnectionPool<CL>
public class SimpleHostConnectionPool<CL>
Pool of connections for a single host and implements the HostConnectionPool interface
Salient Features
The class provides a bunch of counters for visibility into the connection pool status e.g no of
that are available / active / pending / blocked etc.
This class also provides an async mechanism to create / prime and borrow Connection(s) using a LinkedBlockingQueue
Clients borrowing connections can wait at the end of the queue for a connection to be available. They send a tryOpenAsync() request
to create a new connection before waiting, but don't necessarily wait for the same connection to be opened, since they could be unblocked by
another client returning a previously used Connection
The class also provides a markAsDown(ConnectionException) method which helps purge all connections and then
attempts to init a new set of connections to the host.
| 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()
|
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)
Mark the host as down. |
int |
primeConnections(int numConnections)
Create numConnections new connections and add them to the |
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 |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected final ConnectionPoolConfiguration config
| Constructor Detail |
|---|
public SimpleHostConnectionPool(Host host,
ConnectionFactory<CL> factory,
ConnectionPoolMonitor monitor,
ConnectionPoolConfiguration config,
SimpleHostConnectionPool.Listener<CL> listener)
| Method Detail |
|---|
public int primeConnections(int numConnections)
throws ConnectionException,
java.lang.InterruptedException
HostConnectionPool
primeConnections in interface HostConnectionPool<CL>ConnectionException
java.lang.InterruptedException
public Connection<CL> borrowConnection(int timeout)
throws ConnectionException
borrowConnection in interface HostConnectionPool<CL>timeout - - Max wait timeout if max connections have been allocated and
pool is empty. 0 to throw a MaxConnsPerHostReachedException.
TimeoutException - if timeout specified and no new connection is available
MaxConnsPerHostReachedException if max connections created
and no timeout was specified
ConnectionExceptionpublic boolean returnConnection(Connection<CL> connection)
returnConnection in interface HostConnectionPool<CL>connection -
public boolean closeConnection(Connection<CL> connection)
HostConnectionPool
closeConnection in interface HostConnectionPool<CL>public void markAsDown(ConnectionException reason)
markAsDown in interface HostConnectionPool<CL>public void shutdown()
HostConnectionPool
shutdown in interface HostConnectionPool<CL>public boolean isShutdown()
isShutdown in interface HostConnectionPool<CL>public boolean isReconnecting()
isReconnecting in interface HostConnectionPool<CL>public Host getHost()
getHost in interface HostConnectionPool<CL>public int getActiveConnectionCount()
getActiveConnectionCount in interface HostConnectionPool<CL>public int getIdleConnectionCount()
getIdleConnectionCount in interface HostConnectionPool<CL>public int getPendingConnectionCount()
getPendingConnectionCount in interface HostConnectionPool<CL>public int getBlockedThreadCount()
getBlockedThreadCount in interface HostConnectionPool<CL>public int getOpenedConnectionCount()
getOpenedConnectionCount in interface HostConnectionPool<CL>public int getFailedOpenConnectionCount()
getFailedOpenConnectionCount in interface HostConnectionPool<CL>public int getClosedConnectionCount()
getClosedConnectionCount in interface HostConnectionPool<CL>public int getConnectAttemptCount()
getConnectAttemptCount in interface HostConnectionPool<CL>public int getBusyConnectionCount()
getBusyConnectionCount in interface HostConnectionPool<CL>public double getScore()
getScore in interface HostConnectionPool<CL>
public void addLatencySample(long latency,
long now)
HostConnectionPool
addLatencySample in interface HostConnectionPool<CL>public int getErrorsSinceLastSuccess()
getErrorsSinceLastSuccess in interface HostConnectionPool<CL>public java.lang.String toString()
toString in class java.lang.Objectpublic boolean isActive()
isActive in interface HostConnectionPool<CL>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||