|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.dataforte.cassandra.pool.ConnectionPool
public class ConnectionPool
An implementation of a connection pool for Cassandra Thrift connections. Supports reaping of abandoned connections Derived from org.apache.tomcat.jdbc.pool.ConnectionPool by fhanik
| Nested Class Summary | |
|---|---|
protected class |
ConnectionPool.PoolMaintenance
|
| Field Summary | |
|---|---|
protected ConnectionPoolMBean |
jmxPool
reference to the JMX mbean |
static String |
POOL_JMX_PREFIX
Prefix type for JMX registration |
static String |
POOL_JMX_TYPE_PREFIX
|
| Constructor Summary | |
|---|---|
ConnectionPool(PoolConfiguration prop)
Instantiate a connection pool. |
|
| Method Summary | |
|---|---|
protected void |
abandon(PooledConnection con)
thread safe way to abandon a connection signals a connection to be abandoned. this will disconnect the connection, and log the stack trace if logAbanded=true |
protected PooledConnection |
borrowConnection(long now,
PooledConnection con)
Validates and configures a previously idle connection |
void |
checkAbandoned()
Iterates through all the busy connections and checks for connections that have timed out |
void |
checkIdle()
Iterates through the idle connections and resizes the idle pool based on parameters PoolProperties.maxIdle, PoolProperties.minIdle
, PoolProperties.minEvictableIdleTimeMillis |
void |
close()
|
void |
close(boolean force)
Closes the pool and all disconnects all idle connections Active connections will be closed upon the close method is called on the underlying connection instead of being
returned to the pool |
protected PooledConnection |
create()
Create a new pooled connection object. |
protected PooledConnection |
createConnection(long now,
PooledConnection con)
Creates a Cassandra connection and tries to connect to the database. |
protected void |
createMBean()
Create MBean object that can be registered. |
protected void |
disconnectEvent(PooledConnection con,
boolean finalizing)
Hook to perform final actions on a pooled connection object once it has been disconnected and will be discarded |
protected void |
finalize(PooledConnection con)
Hook to perform final actions on a pooled connection object once it has been disconnected and will be discarded |
int |
getActive()
Returns the number of connections that are in use |
CassandraRing |
getCassandraRing()
|
org.apache.cassandra.thrift.Cassandra.Client |
getConnection()
Borrows a connection from the pool. |
int |
getIdle()
Returns the number of idle connections |
ConnectionPoolMBean |
getJmxPool()
Return the object that is potentially registered in JMX for notifications |
String |
getName()
Returns the name of this pool |
PoolConfiguration |
getPoolProperties()
Returns the pool properties associated with this connection pool |
int |
getSize()
Returns the total size of this pool, this includes both busy and idle connections |
static String |
getStackTrace(Throwable x)
Convert an exception into a String |
protected static String |
getThreadDump()
Creates a stack trace representing the existing thread's current state. |
int |
getWaitCount()
Return the number of threads waiting for a connection |
protected void |
init(PoolConfiguration properties)
Initialize the connection pool - called from the constructor |
boolean |
isClosed()
Returns true if close has been called, and the connection
pool is unusable |
void |
refreshRing()
Refreshes the ring information |
void |
release(org.apache.cassandra.thrift.Cassandra.Client connection)
|
protected void |
release(PooledConnection con)
thread safe way to release a connection |
protected void |
returnConnection(PooledConnection con)
Returns a connection to the pool If the pool is closed, the connection will be released If the connection is not part of the busy queue, it will be released. |
protected boolean |
shouldAbandon()
Determines if a connection should be abandoned based on PoolProperties.abandonWhenPercentageFull setting. |
protected boolean |
shouldClose(PooledConnection con,
int action)
Determines if a connection should be closed upon return to the pool. |
protected void |
suspect(PooledConnection con)
thread safe way to abandon a connection signals a connection to be abandoned. this will disconnect the connection, and log the stack trace if logAbanded=true |
void |
testAllIdle()
Forces a validation of all idle connections if PoolProperties.testWhileIdle is set. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String POOL_JMX_PREFIX
public static final String POOL_JMX_TYPE_PREFIX
protected ConnectionPoolMBean jmxPool
| Constructor Detail |
|---|
public ConnectionPool(PoolConfiguration prop)
throws org.apache.thrift.TException
PoolProperties should not be
reused for another connection pool.
prop - PoolProperties - all the properties for this connection pool
Exception
SQLException
org.apache.thrift.TException| Method Detail |
|---|
public org.apache.cassandra.thrift.Cassandra.Client getConnection()
throws org.apache.thrift.TException
maxActive connections a connection is returned immediately. If no
connection is available, the pool will attempt to fetch a connection for
maxWait milliseconds.
org.apache.cassandra.thrift.InvalidRequestException
org.apache.cassandra.thrift.AuthorizationException
org.apache.cassandra.thrift.AuthenticationException
SQLException - - if the wait times out or a failure occurs creating a
connection
org.apache.thrift.TExceptionpublic String getName()
public int getWaitCount()
public PoolConfiguration getPoolProperties()
public int getSize()
public int getActive()
public int getIdle()
public boolean isClosed()
close has been called, and the connection
pool is unusable
public void close()
public void close(boolean force)
close method is called on the underlying connection instead of being
returned to the pool
force - - true to even close the active connections
protected void init(PoolConfiguration properties)
throws org.apache.thrift.TException
properties - PoolProperties - properties used to initialize the pool with
Exception
SQLException - if initialization fails
org.apache.thrift.TExceptionprotected void abandon(PooledConnection con)
con - PooledConnectionprotected void suspect(PooledConnection con)
con - PooledConnectionprotected void release(PooledConnection con)
con - PooledConnection
protected PooledConnection createConnection(long now,
PooledConnection con)
throws org.apache.thrift.TException
now - timestamp of when this was calledcon - the previous pooled connection - argument not used
SQLException
org.apache.thrift.TException
protected PooledConnection borrowConnection(long now,
PooledConnection con)
throws org.apache.thrift.TException
now - - timestampcon - - the connection to validate and configure
org.apache.cassandra.thrift.InvalidRequestException
org.apache.cassandra.thrift.AuthorizationException
org.apache.cassandra.thrift.AuthenticationException
SQLException - if a validation error happens
org.apache.thrift.TException
protected boolean shouldClose(PooledConnection con,
int action)
con - - the connectionaction - - the validation action that should be performed
public void release(org.apache.cassandra.thrift.Cassandra.Client connection)
protected void returnConnection(PooledConnection con)
PoolProperties.testOnReturn is set to true it
will be validated
con - PooledConnection to be returned to the poolprotected boolean shouldAbandon()
PoolProperties.abandonWhenPercentageFull setting.
public void checkAbandoned()
public void checkIdle()
PoolProperties.maxIdle, PoolProperties.minIdle
, PoolProperties.minEvictableIdleTimeMillis
public void testAllIdle()
PoolProperties.testWhileIdle is set.
public void refreshRing()
protected static String getThreadDump()
Thread.getStackTrace() elementspublic static String getStackTrace(Throwable x)
x - - the throwable
protected PooledConnection create()
protected void finalize(PooledConnection con)
con -
protected void disconnectEvent(PooledConnection con,
boolean finalizing)
con - public ConnectionPoolMBean getJmxPool()
ConnectionPoolMBean
interfacepublic CassandraRing getCassandraRing()
protected void createMBean()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||