com.jolbox.bonecp
Class ConnectionPartition

java.lang.Object
  extended by com.jolbox.bonecp.ConnectionPartition
All Implemented Interfaces:
Serializable

public class ConnectionPartition
extends Object
implements Serializable

Connection Partition structure

Author:
wwadge
See Also:
Serialized Form

Field Summary
protected  BoneCP pool
          Handle to the pool.
protected  ReentrantReadWriteLock statsLock
          Statistics lock.
 
Constructor Summary
ConnectionPartition(BoneCP pool)
          Partition constructor
 
Method Summary
protected  void addFreeConnection(ConnectionHandle connectionHandle)
          Adds a free connection.
protected  int getAcquireIncrement()
           
protected  int getAvailableConnections()
          Returns the number of avail connections
protected  LinkedTransferQueue<ConnectionHandle> getConnectionsPendingRelease()
          Gets handle to a release connection handle queue.
protected  int getCreatedConnections()
           
protected  TransferQueue<ConnectionHandle> getFreeConnections()
           
protected  int getMaxConnections()
           
protected  int getMinConnections()
           
protected  String getPassword()
           
protected  BlockingQueue<Object> getPoolWatchThreadSignalQueue()
          Returns a handle to the poolWatchThreadSignalQueue
protected  long getQueryExecuteTimeLimitinNanoSeconds()
          Store the unit translation here to avoid recalculating it in the constructor of StatementHandle.
 int getRemainingCapacity()
          Returns no of free slots.
protected  String getUrl()
           
protected  String getUsername()
           
protected  boolean isUnableToCreateMoreTransactions()
          Returns true if we have created all the connections we can
protected  void setFreeConnections(TransferQueue<ConnectionHandle> freeConnections)
           
protected  void setUnableToCreateMoreTransactions(boolean unableToCreateMoreTransactions)
          Sets connection creation possible status
protected  void trackConnectionFinalizer(ConnectionHandle connectionHandle)
          This method is a replacement for finalize() but avoids all its pitfalls (see Joshua Bloch et.
protected  void updateCreatedConnections(int increment)
          Updates leased connections statistics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

statsLock

protected ReentrantReadWriteLock statsLock
Statistics lock.


pool

protected BoneCP pool
Handle to the pool.

Constructor Detail

ConnectionPartition

public ConnectionPartition(BoneCP pool)
Partition constructor

Parameters:
pool - handle to connection pool
Method Detail

getPoolWatchThreadSignalQueue

protected BlockingQueue<Object> getPoolWatchThreadSignalQueue()
Returns a handle to the poolWatchThreadSignalQueue

Returns:
the poolWatchThreadSignal

updateCreatedConnections

protected void updateCreatedConnections(int increment)
Updates leased connections statistics

Parameters:
increment - value to add/subtract

addFreeConnection

protected void addFreeConnection(ConnectionHandle connectionHandle)
                          throws SQLException
Adds a free connection.

Parameters:
connectionHandle -
Throws:
SQLException - on error

trackConnectionFinalizer

protected void trackConnectionFinalizer(ConnectionHandle connectionHandle)
This method is a replacement for finalize() but avoids all its pitfalls (see Joshua Bloch et. all). Keeps a handle on the connection. If the application called closed, then it means that the handle gets pushed back to the connection pool and thus we get a strong reference again. If the application forgot to call close() and subsequently lost the strong reference to it, the handle becomes eligible to garbage connection and thus the the finalizeReferent method kicks in to safely close off the database handle. Note that we do not return the connectionHandle back to the pool since that is not possible (for otherwise the GC would not have kicked in), but we merely safely release the database internal handle and update our counters instead.

Parameters:
connectionHandle - handle to watch

getFreeConnections

protected TransferQueue<ConnectionHandle> getFreeConnections()
Returns:
the freeConnections

setFreeConnections

protected void setFreeConnections(TransferQueue<ConnectionHandle> freeConnections)
Parameters:
freeConnections - the freeConnections to set

getAcquireIncrement

protected int getAcquireIncrement()
Returns:
the acquireIncrement

getMinConnections

protected int getMinConnections()
Returns:
the minConnections

getMaxConnections

protected int getMaxConnections()
Returns:
the maxConnections

getCreatedConnections

protected int getCreatedConnections()
Returns:
the leasedConnections

getUrl

protected String getUrl()
Returns:
the url

getUsername

protected String getUsername()
Returns:
the username

getPassword

protected String getPassword()
Returns:
the password

isUnableToCreateMoreTransactions

protected boolean isUnableToCreateMoreTransactions()
Returns true if we have created all the connections we can

Returns:
true if we have created all the connections we can

setUnableToCreateMoreTransactions

protected void setUnableToCreateMoreTransactions(boolean unableToCreateMoreTransactions)
Sets connection creation possible status

Parameters:
unableToCreateMoreTransactions - t/f

getConnectionsPendingRelease

protected LinkedTransferQueue<ConnectionHandle> getConnectionsPendingRelease()
Gets handle to a release connection handle queue.

Returns:
release connection handle queue

getAvailableConnections

protected int getAvailableConnections()
Returns the number of avail connections

Returns:
avail connections.

getRemainingCapacity

public int getRemainingCapacity()
Returns no of free slots.

Returns:
remaining capacity.

getQueryExecuteTimeLimitinNanoSeconds

protected long getQueryExecuteTimeLimitinNanoSeconds()
Store the unit translation here to avoid recalculating it in the constructor of StatementHandle.

Returns:
value


Copyright © 2009-2011 JolBox. All Rights Reserved.