|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.logicalcobwebs.proxool.ConnectionPool
class ConnectionPool
This is where most things happen. (In fact, probably too many things happen in this one class).
Field Summary | |
---|---|
private Admin |
admin
|
private CompositeConnectionListener |
compositeConnectionListener
|
private CompositeStateListener |
compositeStateListener
|
private int[] |
connectionCountByState
This keeps a count of how many connections there are in each state |
private boolean |
connectionPoolUp
|
private ConnectionResetter |
connectionResetter
Initialised in constructor . |
private long |
connectionsRefusedCount
|
private long |
connectionsServedCount
|
private ReaderPreferenceReadWriteLock |
connectionStatusReadWriteLock
|
private ConnectionValidatorIF |
connectionValidator
|
private java.util.Date |
dateStarted
|
private ConnectionPoolDefinition |
definition
|
protected static boolean |
FORCE_EXPIRY
|
private boolean |
locked
|
private Log |
log
Here we deviate from the standard of using the classname for the log name. |
private static Log |
LOG
Use this for messages that aren't useful for the pool specific log |
private static boolean |
loggedLegend
|
private static java.lang.String |
MSG_MAX_CONNECTION_COUNT
|
private int |
nextAvailableConnection
This is the "round robin" that makes sure we use all the connections |
private WriterPreferenceReadWriteLock |
primaryReadWriteLock
If you want to shutdown the pool you should get a write lock on this. |
private Prototyper |
prototyper
|
private java.util.List |
proxyConnections
This is the pool itself |
protected static boolean |
REQUEST_EXPIRY
|
private java.lang.Thread |
shutdownThread
This gets set during shutdown(int, java.lang.String) . |
private static java.lang.String[] |
STATUS_DESCRIPTIONS
|
private long |
timeOfLastRefusal
|
private int |
upState
|
Constructor Summary | |
---|---|
protected |
ConnectionPool(ConnectionPoolDefinition definition)
|
Method Summary | |
---|---|
protected void |
acquireConnectionStatusReadLock()
|
protected void |
acquireConnectionStatusWriteLock()
|
protected void |
acquirePrimaryReadLock()
Call this if you want to do something important to the pool. |
protected void |
acquirePrimaryWriteLock()
Call this everytime you build a connection. |
void |
addConnectionListener(ConnectionListenerIF connectionListener)
|
protected boolean |
addProxyConnection(ProxyConnectionIF proxyConnection)
Add a ProxyConnection to the pool |
void |
addStateListener(StateListenerIF stateListener)
|
protected boolean |
attemptConnectionStatusReadLock(long msecs)
|
protected void |
changeStatus(int oldStatus,
int newStatus)
You should acquire a write lock
before calling this method |
protected java.lang.String |
displayStatistics()
|
protected void |
expireAllConnections(java.lang.String reason,
boolean merciful)
|
boolean |
expireConnection(long id,
boolean forceExpiry)
Manually expire a connection. |
protected void |
expireConnectionAsSoonAsPossible(ProxyConnectionIF proxyConnection,
java.lang.String reason,
boolean merciful)
|
protected void |
expireProxyConnection(ProxyConnectionIF proxyConnection,
java.lang.String reason,
boolean forceExpiry)
|
int |
getActiveConnectionCount()
You should acquire
a read lock if you want this to be accurate (but that might have
an impact on the performance of your pool). |
protected Admin |
getAdmin()
Get the admin for this pool |
int |
getAvailableConnectionCount()
You should acquire
a read lock if you want this to be accurate (but that might have
an impact on the performance of your pool). |
protected java.sql.Connection |
getConnection()
Get a connection from the pool. |
long |
getConnectionCount()
|
protected java.util.Collection |
getConnectionInfos()
|
long |
getConnectionsRefusedCount()
The number of connections refused. |
long |
getConnectionsServedCount()
The number of connections provided. |
java.util.Date |
getDateStarted()
When this pool was started |
protected ConnectionPoolDefinition |
getDefinition()
|
Log |
getLog()
|
int |
getOfflineConnectionCount()
You should acquire
a read lock if you want this to be accurate (but that might have
an impact on the performance of your pool). |
protected Prototyper |
getPrototyper()
|
private ProxyConnectionIF |
getProxyConnection(int i)
Get a ProxyConnection by index |
protected ProxyConnectionIF[] |
getProxyConnections()
Return an array of all the connections |
protected static java.lang.String |
getStatusDescription(int status)
|
protected long |
getTimeOfLastRefusal()
The time (in milliseconds) that we last refused a connection |
int |
getUpState()
|
protected void |
initialiseConnectionResetter(java.sql.Connection connection)
Initialises the ConnectionResetter. |
protected boolean |
isConnectionListenedTo()
Is there a listener for connections |
protected boolean |
isConnectionPoolUp()
Is the pool up? |
protected boolean |
isLocked()
|
protected void |
lock()
|
protected void |
onBirth(java.sql.Connection connection)
Call the onBirth() method on each StateListenerIF . |
protected void |
onDeath(java.sql.Connection connection)
Call the onDeath() method on each StateListenerIF . |
protected void |
onExecute(java.lang.String command,
long elapsedTime,
java.lang.Exception exception)
Call the onExecute() method on each StateListenerIF . |
protected void |
putConnection(ProxyConnectionIF proxyConnection)
When you have finished with a Connection you should put it back here. |
protected void |
registerRemovedConnection(int status)
|
protected void |
releaseConnectionStatusReadLock()
|
protected void |
releaseConnectionStatusWriteLock()
|
protected void |
releasePrimaryReadLock()
|
protected void |
releasePrimaryWriteLock()
|
boolean |
removeConnectionListener(ConnectionListenerIF connectionListener)
|
protected void |
removeProxyConnection(ProxyConnectionIF proxyConnection,
java.lang.String reason,
boolean forceExpiry,
boolean triggerSweep)
Remove a ProxyConnection by calling its onDeath event,
closing it (for real) and then removing it from the list. |
boolean |
removeStateListener(StateListenerIF stateListener)
|
protected boolean |
resetConnection(java.sql.Connection connection,
java.lang.String id)
Resets a Connection to its
original state. |
void |
setConnectionListener(ConnectionListenerIF connectionListener)
Deprecated. use addConnectionListener(ConnectionListenerIF) instead. |
protected void |
setDefinition(ConnectionPoolDefinition definition)
Changes both the way that any new connections will be made, and the behaviour of the pool. |
void |
setStateListener(StateListenerIF stateListener)
Deprecated. use addStateListener(StateListenerIF) instead. |
void |
setUpState(int upState)
|
protected void |
shutdown(int delay,
java.lang.String finalizerName)
Call this to shutdown gracefully. |
protected void |
start()
Starts up house keeping and prototyper threads. |
private boolean |
testConnection(ProxyConnectionIF proxyConnection)
Test the connection (if required) If the connection fails the test, it is removed from the pool. |
protected void |
throwConnection(ProxyConnectionIF proxyConnection,
java.lang.String reason)
This means that there's something wrong the connection and it's probably best if no one uses it again. |
java.lang.String |
toString()
|
protected void |
unlock()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final Log LOG
private Log log
private ReaderPreferenceReadWriteLock connectionStatusReadWriteLock
private WriterPreferenceReadWriteLock primaryReadWriteLock
private static final java.lang.String[] STATUS_DESCRIPTIONS
private static final java.lang.String MSG_MAX_CONNECTION_COUNT
private java.util.List proxyConnections
private int nextAvailableConnection
private long connectionsServedCount
private long connectionsRefusedCount
private int[] connectionCountByState
private ConnectionPoolDefinition definition
private CompositeConnectionListener compositeConnectionListener
private CompositeStateListener compositeStateListener
private long timeOfLastRefusal
private int upState
private static boolean loggedLegend
private Admin admin
private boolean locked
private java.util.Date dateStarted
private boolean connectionPoolUp
private java.lang.Thread shutdownThread
shutdown(int, java.lang.String)
. We use it to notify shutdown
that all connections are now non-active.
private Prototyper prototyper
private ConnectionResetter connectionResetter
constructor
.
private ConnectionValidatorIF connectionValidator
protected static final boolean FORCE_EXPIRY
protected static final boolean REQUEST_EXPIRY
Constructor Detail |
---|
protected ConnectionPool(ConnectionPoolDefinition definition) throws ProxoolException
ProxoolException
Method Detail |
---|
protected void start() throws ProxoolException
ProxoolException
protected java.sql.Connection getConnection() throws java.sql.SQLException
java.sql.SQLException
private boolean testConnection(ProxyConnectionIF proxyConnection)
proxyConnection
- the connection to test
protected boolean addProxyConnection(ProxyConnectionIF proxyConnection)
proxyConnection
- new connection
protected static java.lang.String getStatusDescription(int status)
protected void putConnection(ProxyConnectionIF proxyConnection)
protected void throwConnection(ProxyConnectionIF proxyConnection, java.lang.String reason)
private ProxyConnectionIF getProxyConnection(int i)
protected ProxyConnectionIF[] getProxyConnections()
protected void removeProxyConnection(ProxyConnectionIF proxyConnection, java.lang.String reason, boolean forceExpiry, boolean triggerSweep)
onDeath
event,
closing it (for real) and then removing it from the list.
proxyConnection
- the connection to removereason
- for log auditforceExpiry
- true means close now, whether it is active or not; false means if it is active then
merely mark it for expiry so that it is removed as soon as it finished being activetriggerSweep
- if true then this removal will trigger a prototype sweepprotected void expireProxyConnection(ProxyConnectionIF proxyConnection, java.lang.String reason, boolean forceExpiry)
protected void shutdown(int delay, java.lang.String finalizerName) throws java.lang.Throwable
delay
- how long to wait for connections to become free before forcing them to close anyway
java.lang.Throwable
public int getAvailableConnectionCount()
acquire
a read lock if you want this to be accurate (but that might have
an impact on the performance of your pool).
getAvailableConnectionCount
in interface ConnectionPoolStatisticsIF
ConnectionPoolStatisticsIF.getAvailableConnectionCount()
public int getActiveConnectionCount()
acquire
a read lock if you want this to be accurate (but that might have
an impact on the performance of your pool).
getActiveConnectionCount
in interface ConnectionPoolStatisticsIF
ConnectionPoolStatisticsIF.getActiveConnectionCount()
public int getOfflineConnectionCount()
acquire
a read lock if you want this to be accurate (but that might have
an impact on the performance of your pool).
getOfflineConnectionCount
in interface ConnectionPoolStatisticsIF
ConnectionPoolStatisticsIF.getOfflineConnectionCount()
protected java.lang.String displayStatistics()
protected void expireAllConnections(java.lang.String reason, boolean merciful)
protected void expireConnectionAsSoonAsPossible(ProxyConnectionIF proxyConnection, java.lang.String reason, boolean merciful)
protected void registerRemovedConnection(int status)
protected void changeStatus(int oldStatus, int newStatus)
acquire
a write lock
before calling this method
oldStatus
- so we know which count to decrementnewStatus
- so we know which count to incrementpublic long getConnectionsServedCount()
ConnectionPoolStatisticsIF
getConnectionsServedCount
in interface ConnectionPoolStatisticsIF
public long getConnectionsRefusedCount()
ConnectionPoolStatisticsIF
getConnectionsRefusedCount
in interface ConnectionPoolStatisticsIF
protected ConnectionPoolDefinition getDefinition()
protected void setDefinition(ConnectionPoolDefinition definition) throws ProxoolException
ProxoolException
public void setStateListener(StateListenerIF stateListener)
addStateListener(StateListenerIF)
instead.
public void addStateListener(StateListenerIF stateListener)
public boolean removeStateListener(StateListenerIF stateListener)
public void setConnectionListener(ConnectionListenerIF connectionListener)
addConnectionListener(ConnectionListenerIF)
instead.
public void addConnectionListener(ConnectionListenerIF connectionListener)
public boolean removeConnectionListener(ConnectionListenerIF connectionListener)
protected void onBirth(java.sql.Connection connection) throws java.sql.SQLException
java.sql.SQLException
protected void onDeath(java.sql.Connection connection) throws java.sql.SQLException
java.sql.SQLException
protected void onExecute(java.lang.String command, long elapsedTime, java.lang.Exception exception) throws java.sql.SQLException
java.sql.SQLException
protected boolean isConnectionListenedTo()
listener
for connections
public java.lang.String toString()
toString
in class java.lang.Object
public int getUpState()
public void setUpState(int upState)
protected java.util.Collection getConnectionInfos()
public boolean expireConnection(long id, boolean forceExpiry)
id
- the id of the connection to killforceExpiry
- use true to expire even if it is in use
public Log getLog()
protected void initialiseConnectionResetter(java.sql.Connection connection)
Initialises
the ConnectionResetter.
connection
- sample Connection to use for default valuesprotected boolean resetConnection(java.sql.Connection connection, java.lang.String id)
Resets
a Connection to its
original state.
connection
- the one to resetpublic java.util.Date getDateStarted()
ConnectionPoolStatisticsIF
getDateStarted
in interface ConnectionPoolStatisticsIF
ConnectionPoolStatisticsIF.getDateStarted()
protected Admin getAdmin()
protected boolean isLocked()
protected void lock()
protected void unlock()
protected void acquirePrimaryReadLock() throws java.lang.InterruptedException
java.lang.InterruptedException
- if we couldn'tprotected void releasePrimaryReadLock()
acquirePrimaryReadLock()
protected void acquirePrimaryWriteLock() throws java.lang.InterruptedException
up
.
java.lang.InterruptedException
- if there was a problem.protected void releasePrimaryWriteLock()
acquirePrimaryReadLock()
protected boolean isConnectionPoolUp()
shutdown
(or is in the process of being shutdown).protected long getTimeOfLastRefusal()
protected void acquireConnectionStatusWriteLock()
protected void releaseConnectionStatusWriteLock()
protected void acquireConnectionStatusReadLock()
protected boolean attemptConnectionStatusReadLock(long msecs)
protected void releaseConnectionStatusReadLock()
protected Prototyper getPrototyper()
public long getConnectionCount()
getConnectionCount
in interface ConnectionPoolStatisticsIF
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |