org.firebirdsql.pool

Class AbstractConnectionPool

Implemented Interfaces:
PooledObjectListener
Known Direct Subclasses:
BasicAbstractConnectionPool

public abstract class AbstractConnectionPool
extends java.lang.Object
implements PooledObjectListener

Abstract class for creating connection pools. Subclasses must implement factory method to produce physical connections to the database (method getConnectionManager() and few utility methods (getLogger() and getPoolName()).
Author:
Roman Rokytskyy

Nested Class Summary

protected static class
AbstractConnectionPool.UserPasswordPair
Structure class to store user name and password.

Constructor Summary

AbstractConnectionPool()
Create instance of this class.

Method Summary

protected void
finalize()
Shutdown pool if object is garbage collected.
abstract ConnectionPoolConfiguration
getConfiguration()
Get configuration of this data source.
protected abstract PooledConnectionManager
getConnectionManager()
Get instance of PooledConnectionManager responsible for instantiating pooled connections.
abstract int
getFreeSize()
Get number of free connections in this pool.
protected abstract org.firebirdsql.logging.Logger
getLogger()
Get logger for this instance.
protected abstract String
getPoolName()
Get name of the pool.
protected PooledObject
getPooledConnection(org.firebirdsql.pool.PooledConnectionQueue queue)
Get pooled connection.
org.firebirdsql.pool.PooledConnectionQueue
getQueue(Object key)
Get queue for the specified user name and password.
abstract int
getTotalSize()
Get total size of physical connections opened to the database.
abstract int
getWorkingSize()
Get number of connections that are in use.
protected void
physicalConnectionDeallocated(PooledObjectEvent event)
Notify about the deallocation of the physical connection (for example, when connection is removed by the idle remover thread).
void
pooledObjectReleased(PooledObjectEvent event)
Notify about new available connection.
void
restart()
Restart this JDBC pool.
void
shutdown()
Shutdown this JDBC pool.

Constructor Details

AbstractConnectionPool

protected AbstractConnectionPool()
Create instance of this class.

Method Details

finalize

protected void finalize()
            throws Throwable
Shutdown pool if object is garbage collected.

getConfiguration

public abstract ConnectionPoolConfiguration getConfiguration()
Get configuration of this data source.
Returns:
instance of ConnectionPoolConfiguration describing this data source.

getConnectionManager

protected abstract PooledConnectionManager getConnectionManager()
            throws SQLException
Get instance of PooledConnectionManager responsible for instantiating pooled connections.
Returns:
instance of PooledConnectionManager

getFreeSize

public abstract int getFreeSize()
            throws SQLException
Get number of free connections in this pool. This method returns the number of free open connections to the specified database. It might return 0, but this does not mean that next request will block. This will happen only if getMaxSize() != 0 && getMaxSize() == getWorkingSize(), meaning that we have allocated maximum number of connections and all of them are in use.
Returns:
number of free connections left.

getLogger

protected abstract org.firebirdsql.logging.Logger getLogger()
Get logger for this instance. By default all log messages belong to this class. Subclasses can override this behavior.
Returns:
instance of Logger.

getPoolName

protected abstract String getPoolName()
Get name of the pool. This name will be displayed in log when pool is started.
Returns:
name of the connection queue.

getPooledConnection

protected PooledObject getPooledConnection(org.firebirdsql.pool.PooledConnectionQueue queue)
            throws SQLException
Get pooled connection. This method will block until there will be free connection to return.
Parameters:
queue - instance of PooledConnectionQueue where connection will be obtained.
Returns:
instance of PooledObject.

getQueue

public org.firebirdsql.pool.PooledConnectionQueue getQueue(Object key)
            throws SQLException
Get queue for the specified user name and password.
Parameters:
key - key identifying pool.
Returns:
instance of PooledConnectionQueue.

getTotalSize

public abstract int getTotalSize()
            throws SQLException
Get total size of physical connections opened to the database.
Returns:
total number of opened connections to the database.

getWorkingSize

public abstract int getWorkingSize()
            throws SQLException
Get number of connections that are in use.
Returns:
number of working connections.

physicalConnectionDeallocated

protected void physicalConnectionDeallocated(PooledObjectEvent event)
Notify about the deallocation of the physical connection (for example, when connection is removed by the idle remover thread).
Parameters:
event - instance of PooledObjectEvent.

pooledObjectReleased

public void pooledObjectReleased(PooledObjectEvent event)
Notify about new available connection. This method is called by javax.sql.PooledConnection when its wrapped connection being closed.
Specified by:
pooledObjectReleased in interface PooledObjectListener
Parameters:
event - instance of PooledObjectEvent containing information about closed connection.

restart

public void restart()
Restart this JDBC pool. This method restarts all JDBC connections.

shutdown

public void shutdown()
Shutdown this JDBC pool. This method closes all JDBC connections and marks pool as shut down.

Copyright B) 2001 David Jencks and other authors. All rights reserved.