snaq.util
Class PoolTracer

java.lang.Object
  extended by snaq.util.PoolTracer
All Implemented Interfaces:
EventListener, ObjectPoolListener

public class PoolTracer
extends Object
implements ObjectPoolListener

Class to create a simple trace of pool usage statistics to a log file. The default date format is local time in ISO 8601 compatible format.

Author:
Giles Winstanley

Constructor Summary
PoolTracer(ObjectPool pool, File file)
          Creates a new PoolTracer which logs to the specified file.
PoolTracer(ObjectPool pool, PrintWriter logWriter, boolean closeOnExit)
          Creates a new PoolTracer which logs to the specified PrintWriter.
PoolTracer(ObjectPool pool, String filename)
          Creates a new ObjectPoolAudit which logs to the specified File.
PoolTracer(Properties props)
          Creates a new PoolTracer which logs to the specified file.
 
Method Summary
 MessageFormat getMessageFormatInstance()
          Returns the current MessageFormat instance used for formatting log messages.
 void maxPoolLimitExceeded(ObjectPoolEvent evt)
          Called when a check-out request causes the poolSize limit to be exceeded.
 void maxPoolLimitReached(ObjectPoolEvent evt)
          Called when a check-out request causes the poolSize limit to be reached.
 void maxSizeLimitError(ObjectPoolEvent evt)
          Called when a check-out request attempts to exceed the maxSize limit.
 void maxSizeLimitReached(ObjectPoolEvent evt)
          Called when a check-out request causes the maxSize limit to be reached.
 void poolCheckIn(ObjectPoolEvent evt)
          Called when an item is checked back in to the pool.
 void poolCheckOut(ObjectPoolEvent evt)
          Called when an item is checked out of the pool.
 void poolFlushed(ObjectPoolEvent evt)
          Called when the pool is flushed of all free/unused items.
 void poolInitCompleted(ObjectPoolEvent evt)
          Called when the pool's ObjectPool.init(int) method has completed.
 void poolParametersChanged(ObjectPoolEvent evt)
          Called when the pool's parameters are changed.
 void poolReleased(ObjectPoolEvent evt)
          Called when the pool is released (no more events are fired by the pool after this event).
 void setDateFormat(DateFormat df)
          Sets the date formatter for the logging.
 void setMessageFormat(MessageFormat mf)
          Sets the MessageFormat instance used for formatting log messages.
 void validationError(ObjectPoolEvent evt)
          Called when an item is found to be invalid.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PoolTracer

public PoolTracer(ObjectPool pool,
                  PrintWriter logWriter,
                  boolean closeOnExit)
Creates a new PoolTracer which logs to the specified PrintWriter.

Parameters:
pool - ObjectPool for which to trace activity
logWriter - PrintWriter to use for writing trace activity
closeOnExit - whether to close the PrintWriter on release

PoolTracer

public PoolTracer(ObjectPool pool,
                  File file)
           throws FileNotFoundException
Creates a new PoolTracer which logs to the specified file. Note: if the file already exists it is truncated to zero-length, then used for writing the log.

Parameters:
pool - ObjectPool for which to trace activity
file - File to which to log trace activity
Throws:
FileNotFoundException

PoolTracer

public PoolTracer(ObjectPool pool,
                  String filename)
           throws FileNotFoundException
Creates a new ObjectPoolAudit which logs to the specified File.

Parameters:
pool - ObjectPool for which to trace activity
filename - name of file to which to log trace activity
Throws:
FileNotFoundException

PoolTracer

public PoolTracer(Properties props)
           throws FileNotFoundException
Creates a new PoolTracer which logs to the specified file. Note: if the file already exists it is truncated to zero-length, then used for writing the log.

Parameters:
props - Properties defining trace activity
Throws:
FileNotFoundException
Method Detail

setDateFormat

public void setDateFormat(DateFormat df)
Sets the date formatter for the logging. The default is the same as used by the LogUtil class.

Parameters:
df - DateFormat instance to use for formatting log messages

setMessageFormat

public void setMessageFormat(MessageFormat mf)
Sets the MessageFormat instance used for formatting log messages. To use the default instance, just call this method with a null argument.

Format strings are specified using the following variables:

The default format is as follows:

 {0}: minpool={1,number,#}, maxpool={2,number,#}, maxsize={3,number,#}, expiry={4,number,#}, out={5,number,#}, free={6,number,#}, hitRate={8,number,0.0##%}
 

Parameters:
mf - MessageFormat instance to use for formatting log messages

getMessageFormatInstance

public MessageFormat getMessageFormatInstance()
Returns the current MessageFormat instance used for formatting log messages.


poolInitCompleted

public void poolInitCompleted(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when the pool's ObjectPool.init(int) method has completed.

Specified by:
poolInitCompleted in interface ObjectPoolListener

validationError

public void validationError(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when an item is found to be invalid.

Specified by:
validationError in interface ObjectPoolListener

maxPoolLimitReached

public void maxPoolLimitReached(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when a check-out request causes the poolSize limit to be reached.

Specified by:
maxPoolLimitReached in interface ObjectPoolListener

maxPoolLimitExceeded

public void maxPoolLimitExceeded(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when a check-out request causes the poolSize limit to be exceeded.

Specified by:
maxPoolLimitExceeded in interface ObjectPoolListener

maxSizeLimitReached

public void maxSizeLimitReached(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when a check-out request causes the maxSize limit to be reached.

Specified by:
maxSizeLimitReached in interface ObjectPoolListener

maxSizeLimitError

public void maxSizeLimitError(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when a check-out request attempts to exceed the maxSize limit.

Specified by:
maxSizeLimitError in interface ObjectPoolListener

poolCheckIn

public void poolCheckIn(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when an item is checked back in to the pool.

Specified by:
poolCheckIn in interface ObjectPoolListener

poolCheckOut

public void poolCheckOut(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when an item is checked out of the pool.

Specified by:
poolCheckOut in interface ObjectPoolListener

poolParametersChanged

public void poolParametersChanged(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when the pool's parameters are changed.

Specified by:
poolParametersChanged in interface ObjectPoolListener

poolFlushed

public void poolFlushed(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when the pool is flushed of all free/unused items.

Specified by:
poolFlushed in interface ObjectPoolListener

poolReleased

public void poolReleased(ObjectPoolEvent evt)
Description copied from interface: ObjectPoolListener
Called when the pool is released (no more events are fired by the pool after this event).

Specified by:
poolReleased in interface ObjectPoolListener