org.ow2.jonas.resource.internal.pool.lib
Class HArrayPool

java.lang.Object
  extended by org.ow2.jonas.resource.internal.pool.lib.HArrayPool
All Implemented Interfaces:
Pool

public class HArrayPool
extends Object
implements Pool

The class HArrayPool implements a Pool as a HashSet of ManagedConnections, managing free/active resources. Updated to use an LRU list of free resources Author: Eric HARDESTY


Constructor Summary
HArrayPool(org.objectweb.util.monolog.api.Logger logger, String jndiname)
          HArrayPool constructor
 
Method Summary
 void adjust()
          Adjust the pool size, according to poolMax and minSize values.
 void closeAllConnections()
          Close all connections in the pool when server is shutting down.
 void forceCloseConnection(int connectionId)
          force the close of the Connection identified by ots Id
 int getBusyMaxRecent()
           
 int getBusyMinRecent()
           
 ManagedConnection getConnectionById(int connectionId)
          Return the ManagedConnection identified by this Id
 Map getConnectionDetails(ManagedConnection res, Transaction tx)
          Return a Map with details about a Connection
 int getConnectionFailures()
           
 int getConnectionLeaks()
           
 int getCurrentBusy()
           
 int getCurrentOpened()
           
 int getCurrentWaiters()
           
 int getInitSize()
           
 int getJdbcConnLevel()
          getJdbcConnLevel gets the jdbc connection level
 String getJdbcTestStatement()
          getJdbcTestStatement gets the JDBC test statement for this pool
 PoolMatchFactory getMatchFactory()
          getMatchFactory retrieves the PoolMatchFactory assigned to this Pool.
 int getMaxAge()
          getMaxAge gets the max age for a pool entry
 int getMaxOpentime()
          getMaxOpentime gets the max age for a pool entry
 int getMaxSize()
          getMaxSize retrieves the maximum size assigned to this Pool.
 int getMaxWaiters()
          getMaxWaiters gets the maximum number of waiters for a connection in this Pool.
 int getMaxWaitTime()
          getMaxWaitTime gets the maximum number of seconds to wait for a connection in this Pool.
 int getMinSize()
          getMinSize retrieves the minimum size assigned to this Pool.
 int[] getOpenedConnections(long usedTimeMs)
          return a list of idents that represent the connections opened for a given nb of seconds
 int getOpenedCount()
           
 int getRejectedFull()
           
 int getRejectedOpen()
           
 int getRejectedOther()
           
 int getRejectedTimeout()
           
 Object getResource(Object hints)
          Get a Resource from the freelist, matching hints.
 int getSamplingPeriod()
          getSamplingPeriod gets the number of seconds between statistics sampling for this Pool.
 int getServedOpen()
           
 int getSize()
          Get the size of the pool
 long getTimeout()
          getTimeout retrieves the timeout assigned to this Pool.
 int getWaiterCount()
           
 int getWaitersHigh()
           
 int getWaitersHighRecent()
           
 long getWaitingHigh()
           
 long getWaitingHighRecent()
           
 long getWaitingTime()
           
 void recomputeBusy()
          compute current min/max busyConnections
 void releaseResource(Object resource, boolean destroy)
          Remove Resource from activeList
 void sampling()
          sampling updates the interval pool information
 void setInitSize(int v)
          setInitSize creates initsize resoures to this Pool.
 void setJdbcConnLevel(int jdbcConnLevel)
          setJdbcConnLevel sets the JDBC connection level for this pool
 void setJdbcTestStatement(String jdbcTestStatement)
          setJdbcTestStatement sets the JDBC test statement for this pool
 void setMatchFactory(PoolMatchFactory pmf)
          setMatchFactory assigns a PoolMatchFactory to this Pool.
 void setMaxAge(int maxAge)
          setMaxAge sets the max age for a pool entry
 void setMaxOpentime(int mx)
          setMaxOpentime sets the max age for an entry to be opened
 void setMaxSize(int val)
          setMaxSize assigns a maximum size to this Pool.
 void setMaxWaiters(int nb)
          setMaxWaiters sets the maximum number of waiters for a connection in this Pool.
 void setMaxWaitTime(int sec)
          setMaxWaitTime sets the maximum number of seconds to wait for a connection in this Pool.
 void setMinSize(int val)
          setMinSize assigns a minimum size to this Pool.
 void setObservable(boolean obs)
          Set the pool observable
 void setSamplingPeriod(int sec)
          setSamplingPeriod sets the number of seconds between statistics sampling for this Pool.
 void setTimeout(long crto)
          setTimeout assigns a timeout to this Pool.
 void startMonitor()
          startMonitor starts the pool monitor for this Pool.
 void validateMCs()
          validateMCs validates ManagedConnections in Pool every 10 minutes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HArrayPool

public HArrayPool(org.objectweb.util.monolog.api.Logger logger,
                  String jndiname)
HArrayPool constructor

Parameters:
logger - Logger for the pool to use
jndiname - jndi name of the RA
Method Detail

setObservable

public void setObservable(boolean obs)
Set the pool observable

Specified by:
setObservable in interface Pool
Parameters:
obs - = true if keep stack traces at open

getCurrentBusy

public int getCurrentBusy()
Specified by:
getCurrentBusy in interface Pool
Returns:
int number of busy connections

getCurrentOpened

public int getCurrentOpened()
Specified by:
getCurrentOpened in interface Pool
Returns:
int number of physically opened connections

getInitSize

public int getInitSize()
Specified by:
getInitSize in interface Pool
Returns:
init The pool init size.
See Also:
Pool.getInitSize()

setInitSize

public void setInitSize(int v)
                 throws Exception
Description copied from interface: Pool
setInitSize creates initsize resoures to this Pool.

Specified by:
setInitSize in interface Pool
Parameters:
v - The init size to be created.
Throws:
Exception - if an error occurs
See Also:
Pool.setInitSize(int)

getJdbcConnLevel

public int getJdbcConnLevel()
Description copied from interface: Pool
getJdbcConnLevel gets the jdbc connection level

Specified by:
getJdbcConnLevel in interface Pool
Returns:
int jdbc connection level specified
See Also:
Pool.getJdbcConnLevel()

setJdbcConnLevel

public void setJdbcConnLevel(int jdbcConnLevel)
Description copied from interface: Pool
setJdbcConnLevel sets the JDBC connection level for this pool

Specified by:
setJdbcConnLevel in interface Pool
Parameters:
jdbcConnLevel - int JDBC connection level
See Also:
Pool.setJdbcConnLevel(int)

getJdbcTestStatement

public String getJdbcTestStatement()
Description copied from interface: Pool
getJdbcTestStatement gets the JDBC test statement for this pool

Specified by:
getJdbcTestStatement in interface Pool
Returns:
String JDBC test statement
See Also:
Pool.getJdbcTestStatement()

setJdbcTestStatement

public void setJdbcTestStatement(String jdbcTestStatement)
Description copied from interface: Pool
setJdbcTestStatement sets the JDBC test statement for this pool

Specified by:
setJdbcTestStatement in interface Pool
Parameters:
jdbcTestStatement - String JDBC test statement
See Also:
Pool.setJdbcTestStatement(java.lang.String)

getMaxAge

public int getMaxAge()
Description copied from interface: Pool
getMaxAge gets the max age for a pool entry

Specified by:
getMaxAge in interface Pool
Returns:
int max number of minutes to keep a connection in the pool.
See Also:
Pool.getMaxAge()

setMaxAge

public void setMaxAge(int maxAge)
Description copied from interface: Pool
setMaxAge sets the max age for a pool entry

Specified by:
setMaxAge in interface Pool
Parameters:
maxAge - int max number of minutes to keep a connection in the pool.
See Also:
Pool.setMaxAge(int)

getMaxOpentime

public int getMaxOpentime()
Description copied from interface: Pool
getMaxOpentime gets the max age for a pool entry

Specified by:
getMaxOpentime in interface Pool
Returns:
max age for connections (in mns)

setMaxOpentime

public void setMaxOpentime(int mx)
Description copied from interface: Pool
setMaxOpentime sets the max age for an entry to be opened

Specified by:
setMaxOpentime in interface Pool
Parameters:
mx - max time of open connection in minutes

getMaxSize

public int getMaxSize()
Description copied from interface: Pool
getMaxSize retrieves the maximum size assigned to this Pool.

Specified by:
getMaxSize in interface Pool
Returns:
The maximum size currently assigned to this Pool.
See Also:
Pool.getMaxSize()

setMaxSize

public void setMaxSize(int val)
                throws Exception
Description copied from interface: Pool
setMaxSize assigns a maximum size to this Pool.

Specified by:
setMaxSize in interface Pool
Parameters:
val - int maximum size to be assigned.
Throws:
Exception - if an error occurs
See Also:
Pool.setMaxSize(int)

getMaxWaiters

public int getMaxWaiters()
Description copied from interface: Pool
getMaxWaiters gets the maximum number of waiters for a connection in this Pool.

Specified by:
getMaxWaiters in interface Pool
Returns:
max nb of waiters

setMaxWaiters

public void setMaxWaiters(int nb)
Description copied from interface: Pool
setMaxWaiters sets the maximum number of waiters for a connection in this Pool.

Specified by:
setMaxWaiters in interface Pool
Parameters:
nb - max nb of waiters

getMaxWaitTime

public int getMaxWaitTime()
Description copied from interface: Pool
getMaxWaitTime gets the maximum number of seconds to wait for a connection in this Pool.

Specified by:
getMaxWaitTime in interface Pool
Returns:
waiter timeout in seconds

setMaxWaitTime

public void setMaxWaitTime(int sec)
Description copied from interface: Pool
setMaxWaitTime sets the maximum number of seconds to wait for a connection in this Pool.

Specified by:
setMaxWaitTime in interface Pool
Parameters:
sec - max time to wait for a connection, in seconds

getMinSize

public int getMinSize()
Description copied from interface: Pool
getMinSize retrieves the minimum size assigned to this Pool.

Specified by:
getMinSize in interface Pool
Returns:
The minimum size currently assigned to this Pool.
See Also:
Pool.getMinSize()

setMinSize

public void setMinSize(int val)
                throws Exception
Description copied from interface: Pool
setMinSize assigns a minimum size to this Pool.

Specified by:
setMinSize in interface Pool
Parameters:
val - int minimum size to be assigned.
Throws:
Exception - if an error occurs
See Also:
Pool.setMinSize(int)

getSamplingPeriod

public int getSamplingPeriod()
Description copied from interface: Pool
getSamplingPeriod gets the number of seconds between statistics sampling for this Pool.

Specified by:
getSamplingPeriod in interface Pool
Returns:
sampling period in sec.

setSamplingPeriod

public void setSamplingPeriod(int sec)
Description copied from interface: Pool
setSamplingPeriod sets the number of seconds between statistics sampling for this Pool.

Specified by:
setSamplingPeriod in interface Pool
Parameters:
sec - sampling period in sec.

getSize

public int getSize()
Get the size of the pool

Specified by:
getSize in interface Pool
Returns:
int size of the pool

getTimeout

public long getTimeout()
Description copied from interface: Pool
getTimeout retrieves the timeout assigned to this Pool.

Specified by:
getTimeout in interface Pool
Returns:
The timeout currently assigned to this Pool.
See Also:
Pool.getTimeout()

setTimeout

public void setTimeout(long crto)
Description copied from interface: Pool
setTimeout assigns a timeout to this Pool.

Specified by:
setTimeout in interface Pool
Parameters:
crto - long timeout to be assigned.
See Also:
not used

getBusyMaxRecent

public int getBusyMaxRecent()
Specified by:
getBusyMaxRecent in interface Pool
Returns:
maximum nb of busy connections in last sampling period

getBusyMinRecent

public int getBusyMinRecent()
Specified by:
getBusyMinRecent in interface Pool
Returns:
minimum nb of busy connections in last sampling period

getCurrentWaiters

public int getCurrentWaiters()
Specified by:
getCurrentWaiters in interface Pool
Returns:
current number of connection waiters

getOpenedCount

public int getOpenedCount()
Specified by:
getOpenedCount in interface Pool
Returns:
int number of physical jdbc connection opened

getConnectionFailures

public int getConnectionFailures()
Specified by:
getConnectionFailures in interface Pool
Returns:
int number of connection failures on open

getConnectionLeaks

public int getConnectionLeaks()
Specified by:
getConnectionLeaks in interface Pool
Returns:
int number of connection leaks

getServedOpen

public int getServedOpen()
Specified by:
getServedOpen in interface Pool
Returns:
int number of connection served

getRejectedFull

public int getRejectedFull()
Specified by:
getRejectedFull in interface Pool
Returns:
int number of open calls that were rejected due to waiter overflow

getRejectedTimeout

public int getRejectedTimeout()
Specified by:
getRejectedTimeout in interface Pool
Returns:
int number of open calls that were rejected by timeout

getRejectedOther

public int getRejectedOther()
Specified by:
getRejectedOther in interface Pool
Returns:
int number of open calls that were rejected

getRejectedOpen

public int getRejectedOpen()
Specified by:
getRejectedOpen in interface Pool
Returns:
int number of open calls that were rejected

getWaitersHigh

public int getWaitersHigh()
Specified by:
getWaitersHigh in interface Pool
Returns:
maximum nb of waiters since the datasource creation

getWaitersHighRecent

public int getWaitersHighRecent()
Specified by:
getWaitersHighRecent in interface Pool
Returns:
maximum nb of waiters in last sampling period

getWaiterCount

public int getWaiterCount()
Specified by:
getWaiterCount in interface Pool
Returns:
total nb of waiters since the datasource creation

getWaitingTime

public long getWaitingTime()
Specified by:
getWaitingTime in interface Pool
Returns:
total waiting time since the datasource creation

getWaitingHigh

public long getWaitingHigh()
Specified by:
getWaitingHigh in interface Pool
Returns:
max waiting time since the datasource creation

getWaitingHighRecent

public long getWaitingHighRecent()
Specified by:
getWaitingHighRecent in interface Pool
Returns:
max waiting time in last sampling period

getResource

public Object getResource(Object hints)
                   throws Exception
Get a Resource from the freelist, matching hints. the matchFactory is used to check the hints. If freelist is empty, create a new resource

Specified by:
getResource in interface Pool
Parameters:
hints -
Returns:
the matching resource
Throws:
Exception - cannot get a Resource
See Also:
Pool.getResource(java.lang.Object)

releaseResource

public void releaseResource(Object resource,
                            boolean destroy)
                     throws Exception
Remove Resource from activeList

Specified by:
releaseResource in interface Pool
Parameters:
resource - ManagedConnection to be released
destroy - true if do not keep it in freeList
Throws:
Exception - if an error occurs
See Also:
Pool.releaseResource(java.lang.Object, boolean)

closeAllConnections

public void closeAllConnections()
Close all connections in the pool when server is shutting down.

Specified by:
closeAllConnections in interface Pool

getMatchFactory

public PoolMatchFactory getMatchFactory()
Description copied from interface: Pool
getMatchFactory retrieves the PoolMatchFactory assigned to this Pool.

Specified by:
getMatchFactory in interface Pool
Returns:
The PoolMatchFactory currently assigned to this Pool.
See Also:
Pool.getMatchFactory()

setMatchFactory

public void setMatchFactory(PoolMatchFactory pmf)
Description copied from interface: Pool
setMatchFactory assigns a PoolMatchFactory to this Pool.

Specified by:
setMatchFactory in interface Pool
Parameters:
pmf - The PoolMatchFactory to be assigned.
See Also:
Pool.setMatchFactory(org.ow2.jonas.resource.internal.pool.PoolMatchFactory)

startMonitor

public void startMonitor()
Description copied from interface: Pool
startMonitor starts the pool monitor for this Pool.

Specified by:
startMonitor in interface Pool
See Also:
Pool.startMonitor()

getOpenedConnections

public int[] getOpenedConnections(long usedTimeMs)
return a list of idents that represent the connections opened for a given nb of seconds

Specified by:
getOpenedConnections in interface Pool
Parameters:
usedTimeMs - nb of milliseconds the Connection has been opened
Returns:
array of idents representing the Connections

forceCloseConnection

public void forceCloseConnection(int connectionId)
force the close of the Connection identified by ots Id

Specified by:
forceCloseConnection in interface Pool
Parameters:
connectionId - int that represent the Connection

getConnectionById

public ManagedConnection getConnectionById(int connectionId)
Description copied from interface: Pool
Return the ManagedConnection identified by this Id

Specified by:
getConnectionById in interface Pool
Parameters:
connectionId - Ident that represent the connection
Returns:
the Managed Connection

getConnectionDetails

public Map getConnectionDetails(ManagedConnection res,
                                Transaction tx)
Description copied from interface: Pool
Return a Map with details about a Connection

Specified by:
getConnectionDetails in interface Pool
Parameters:
res - the connection
tx - Transaction associated to this Connection, or null.
Returns:
map given the details about this connection.

validateMCs

public void validateMCs()
                 throws Exception
Description copied from interface: Pool
validateMCs validates ManagedConnections in Pool every 10 minutes

Specified by:
validateMCs in interface Pool
Throws:
Exception - if an error occurs
See Also:
Pool.validateMCs()

adjust

public void adjust()
            throws Exception
Adjust the pool size, according to poolMax and minSize values. Also remove old connections in the freeList. do not synchronize this method: the lock should not be kept too long especially during the connection close that could block.

Specified by:
adjust in interface Pool
Throws:
Exception - if an exception occurs

recomputeBusy

public void recomputeBusy()
compute current min/max busyConnections


sampling

public void sampling()
              throws Exception
Description copied from interface: Pool
sampling updates the interval pool information

Specified by:
sampling in interface Pool
Throws:
Exception - if an error occurs
See Also:
Pool.sampling()


Copyright © 2010 OW2 Consortium. All Rights Reserved.