to.etc.dbpool
Class PoolManager

java.lang.Object
  extended by to.etc.dbpool.PoolManager

public final class PoolManager
extends java.lang.Object

Root of the database pool manager code.

Author:
Frits Jalvingh Created on Nov 2, 2010

Constructor Summary
PoolManager()
           
 
Method Summary
 void addMessageListener(IPoolMessageHandler pmh)
           
 ConnectionPool definePool(java.io.File poolfile, java.lang.String id)
          This defines a pool, taking it's config from a properties file.
 ConnectionPool definePool(PoolConfigSource cs, java.lang.String id)
          Defines the pool with the specified ID from the ConfigSource passed.
 ConnectionPool definePool(java.lang.String id)
          This defines a pool using the default poolfile ".dbpool.properties" stored in the user's home directory.
 ConnectionPool definePool(java.lang.String id, java.lang.String driver, java.lang.String url, java.lang.String userid, java.lang.String password, java.lang.String driverpath)
           
 void destroyAll()
          Destroy all current pools.
 void destroyPool(java.lang.String poolid)
           
static PoolManager getInstance()
           
 ConnectionPool getPool(java.lang.String id)
          Finds the named pool.
 int getPoolCount()
          Return the #of pools currently defined.
 ConnectionPool[] getPoolList()
          Return all currently defined pools.
 ConnectionPool initializePool(java.io.File poolfile, java.lang.String id)
          This combines defining and initializing a pool, taking it's config from a properties file.
 ConnectionPool initializePool(PoolConfigSource cs, java.lang.String id)
          This combines defining and initializing a pool.
 ConnectionPool initializePool(java.lang.String id)
          Initializes the pool defined by ID by pre-allocating the first min connections from it.
 boolean isCollectStatistics()
           
 void logUnexpected(java.lang.Exception t, java.lang.String s)
           
 void logUnexpected(java.lang.String s)
           
 void panic(java.lang.String shortdesc, java.lang.String body)
           
 void removeMessageListener(IPoolMessageHandler pmh)
           
 void sendLogUnexpected(java.lang.Exception t, java.lang.String s)
           
 void sendPanic(java.lang.String shortdesc, java.lang.String body)
           
 void setCollectStatistics(boolean on)
           
 boolean startCollecting(java.lang.String key, InfoCollector collector)
          Registers a statistics collection listener for the current thread.
protected  void startExpiredConnectionScanner()
          Starts the scanner if database locking security is requested.
 InfoCollector stopCollecting(java.lang.String key)
          Returns the collector with the specified key.
 InfoCollector threadCollector()
           
 InfoCollectorSink threadData()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PoolManager

public PoolManager()
Method Detail

getInstance

public static PoolManager getInstance()

panic

public void panic(java.lang.String shortdesc,
                  java.lang.String body)

logUnexpected

public void logUnexpected(java.lang.Exception t,
                          java.lang.String s)

logUnexpected

public void logUnexpected(java.lang.String s)

addMessageListener

public void addMessageListener(IPoolMessageHandler pmh)

removeMessageListener

public void removeMessageListener(IPoolMessageHandler pmh)

sendLogUnexpected

public void sendLogUnexpected(java.lang.Exception t,
                              java.lang.String s)

sendPanic

public void sendPanic(java.lang.String shortdesc,
                      java.lang.String body)

getPoolCount

public int getPoolCount()
Return the #of pools currently defined.

Returns:

getPool

@Nonnull
public ConnectionPool getPool(@Nonnull
                                      java.lang.String id)
                       throws java.sql.SQLException
Finds the named pool. Throws an exception if not found.

Throws:
java.sql.SQLException

getPoolList

public ConnectionPool[] getPoolList()
Return all currently defined pools.

Returns:

definePool

public ConnectionPool definePool(PoolConfigSource cs,
                                 java.lang.String id)
                          throws java.sql.SQLException
Defines the pool with the specified ID from the ConfigSource passed. The pool is defined but NOT initialized. The same pool can be defined more than once provided it's parameters are all the same. After this call the pool can be used but it operates in "unpooled" mode, meaning that all allocated connections will be discarded after a close.

Throws:
java.sql.SQLException

definePool

public ConnectionPool definePool(java.lang.String id,
                                 java.lang.String driver,
                                 java.lang.String url,
                                 java.lang.String userid,
                                 java.lang.String password,
                                 java.lang.String driverpath)
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

definePool

public ConnectionPool definePool(java.io.File poolfile,
                                 java.lang.String id)
                          throws java.lang.Exception
This defines a pool, taking it's config from a properties file.

Parameters:
poolfile -
id -
Throws:
java.lang.Exception

definePool

public ConnectionPool definePool(java.lang.String id)
                          throws java.lang.Exception
This defines a pool using the default poolfile ".dbpool.properties" stored in the user's home directory. If no such file is found then an exception is thrown.

Parameters:
id -
Returns:
Throws:
java.lang.Exception

initializePool

public ConnectionPool initializePool(java.lang.String id)
                              throws java.lang.Exception
Initializes the pool defined by ID by pre-allocating the first min connections from it. If the pool has already initialized it returns immediately. If the first connections fail to be allocated properly then an exception occurs and the pool is deinitialized. After this call the pool operates in pooled mode.

Throws:
java.lang.Exception

initializePool

public ConnectionPool initializePool(PoolConfigSource cs,
                                     java.lang.String id)
                              throws java.sql.SQLException
This combines defining and initializing a pool.

Parameters:
cs - The configsource to take definitions from
id - The ID of the pool to define.
Throws:
java.lang.Exception
java.sql.SQLException

initializePool

public ConnectionPool initializePool(java.io.File poolfile,
                                     java.lang.String id)
                              throws java.lang.Exception
This combines defining and initializing a pool, taking it's config from a properties file.

Parameters:
poolfile -
id -
Throws:
java.lang.Exception

destroyAll

public void destroyAll()
Destroy all current pools.


destroyPool

public void destroyPool(java.lang.String poolid)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException

startExpiredConnectionScanner

protected void startExpiredConnectionScanner()
Starts the scanner if database locking security is requested.


threadData

public InfoCollectorSink threadData()
Returns:

threadCollector

public InfoCollector threadCollector()

startCollecting

public boolean startCollecting(java.lang.String key,
                               InfoCollector collector)
Registers a statistics collection listener for the current thread. If statistics gathering is disabled the call is ignored and returns false. Else the listener is added and will receive all statement events; in this case the call returns true.


stopCollecting

public InfoCollector stopCollecting(java.lang.String key)
Returns the collector with the specified key. If statistics collection is not enabled this returns null always; else it returns and removes the collector- if found.

Parameters:
key -
Returns:

setCollectStatistics

public void setCollectStatistics(boolean on)

isCollectStatistics

public boolean isCollectStatistics()