org.jwarp.service.connectionpool
Class PoolService

java.lang.Object
  |
  +--org.jwarp.service.AService
        |
        +--org.jwarp.service.connectionpool.PoolService
All Implemented Interfaces:
IConfigurable, IExceptionProvider, IPoolService, IReferenceable, IService

public class PoolService
extends AService
implements IPoolService

Poolmanager for managing the application's database access. A poolmanager can be initialised for loading all db drivers needed. Connection pools can be defined and used for getting connections. Effectively not direct connections will be returned but wrappers that wrap the java.sql.Connection interface. If you use a connection from this pool just call close when you are finished using the connection. The connection itself knows to which pool she should be returned. The poolmanager is implemented as a singleton.

Version:
1.0
Author:
Anatole Tresch

Fields inherited from class org.jwarp.service.AService
context, createdDate, dependencies, emptyProperties, exceptionListeners, log, resumedDate, serviceName, serviceStatus, serviceType, startedDate, stoppedDate, suspendedDate, systemTicket
 
Fields inherited from interface org.jwarp.service.connectionpool.IPoolService
SERVICE_TYPE
 
Fields inherited from interface org.jwarp.service.IService
SERVICE_STATUS_CREATED, SERVICE_STATUS_NOT_AVAILABLE, SERVICE_STATUS_READY, SERVICE_STATUS_RESUMING, SERVICE_STATUS_RUNNING, SERVICE_STATUS_STARTING, SERVICE_STATUS_STOPPED, SERVICE_STATUS_STOPPING, SERVICE_STATUS_SUSPENDED
 
Constructor Summary
PoolService()
          Creates a new pool manager.
 
Method Summary
 void checkFreeConnections()
          Checkes for too many free connections.
 void configure(org.jdom.Element config)
          Init the pool manager with the properties passed.
 void createPool(java.lang.String poolName, java.lang.String dbDriver, java.lang.String dbUrl, java.lang.String dbUid, java.lang.String dbPwd, int dbInitConns, int dbMaxConns, int dbConnectTimeout, java.lang.String logTarget, ITicket ticket)
          Create a new db pool.
 java.sql.Connection getConnection(java.lang.String poolName, ITicket ticket)
          Get a connection from the given pool.
 java.util.Iterator getDrivers(ITicket ticket)
          Get the actual loaded drivers
 ConnectionPool getPool(java.lang.String name, ITicket ticket)
          Get the pool named name
 java.util.Iterator getPools(ITicket ticket)
          Get a list of all managed pools
 void release()
          Tries to tell all pools managed by this manager to release all connections.
 void removePool(java.lang.String poolName, ITicket ticket)
          Remove a db pool.
 
Methods inherited from class org.jwarp.service.AService
addExceptionListener, checkContext, createLogFromXML, getContext, getCreationDate, getDependencies, getExceptionListeners, getLog, getLogLevel, getName, getReference, getResumedDate, getShutDownDate, getStartDate, getStatus, getSuspendedDate, getType, removeAllExceptionListeners, removeExceptionListener, resume, sendExceptionEvent, setContext, setDependencies, setLogLevel, setName, shutdown, start, suspend
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jwarp.service.IService
checkContext, getDependencies, getLogLevel, getName, getStatus, getType, resume, setContext, setDependencies, setLogLevel, shutdown, start, suspend
 
Methods inherited from interface org.jwarp.common.IExceptionProvider
addExceptionListener, getExceptionListeners, removeAllExceptionListeners, removeExceptionListener
 

Constructor Detail

PoolService

public PoolService()
Creates a new pool manager. Because of singleton pattern it is private.
Method Detail

configure

public void configure(org.jdom.Element config)
               throws ConfigurationException
Init the pool manager with the properties passed.
Specified by:
configure in interface IConfigurable
Overrides:
configure in class AService
Parameters:
properties - The properties
Throws:
PoolInitException - if a pool can not be initialised successfully.

createPool

public void createPool(java.lang.String poolName,
                       java.lang.String dbDriver,
                       java.lang.String dbUrl,
                       java.lang.String dbUid,
                       java.lang.String dbPwd,
                       int dbInitConns,
                       int dbMaxConns,
                       int dbConnectTimeout,
                       java.lang.String logTarget,
                       ITicket ticket)
                throws java.lang.SecurityException,
                       java.sql.SQLException
Description copied from interface: IPoolService
Create a new db pool.
Specified by:
createPool in interface IPoolService

removePool

public void removePool(java.lang.String poolName,
                       ITicket ticket)
                throws java.lang.SecurityException
Description copied from interface: IPoolService
Remove a db pool.
Specified by:
removePool in interface IPoolService

getPool

public ConnectionPool getPool(java.lang.String name,
                              ITicket ticket)
                       throws java.lang.SecurityException
Get the pool named name
Specified by:
getPool in interface IPoolService
Parameters:
name - The pools name
Returns:
the pool or null if the pool does not exist.

getPools

public java.util.Iterator getPools(ITicket ticket)
Get a list of all managed pools
Specified by:
getPools in interface IPoolService
Returns:
An enumeration of all defined pools.

getDrivers

public java.util.Iterator getDrivers(ITicket ticket)
Get the actual loaded drivers
Specified by:
getDrivers in interface IPoolService

getConnection

public java.sql.Connection getConnection(java.lang.String poolName,
                                         ITicket ticket)
                                  throws java.lang.SecurityException,
                                         InvalidPoolException,
                                         MaxConnectException
Get a connection from the given pool.
Specified by:
getConnection in interface IPoolService
Parameters:
The - pool name.
Returns:
A database connection.
Throws:
InvalidPoolException - if the specified pool can not be found
MaxConnectException - if all connections are checked out

checkFreeConnections

public void checkFreeConnections()
Checkes for too many free connections. If there are too many some connections will be closed and removed from the pool. Called by ConnectionPoolUpdateThread.
Specified by:
checkFreeConnections in interface IPoolService
See Also:
ConnectionPoolUpdateThread

release

public void release()
Tries to tell all pools managed by this manager to release all connections.
Specified by:
release in interface IPoolService

©   O R C A   S y s t e m s