org.barracudamvc.core.event
Class DefaultEventPool

java.lang.Object
  extended byorg.barracudamvc.core.event.DefaultEventPool
All Implemented Interfaces:
EventPool

public class DefaultEventPool
extends Object
implements EventPool

This class acts as a pool for Events. Should significantly improve performance by allowing us to reuse event objects.


Field Summary
protected  long cleanupInterval
           
static long DEFAULT_CLEANUP_INTERVAL
           
static int DEFAULT_MAX_RETRIES
           
static int DEFAULT_POOL_SIZE
           
static long DEFAULT_RETRY_INTERVAL
           
static long DEFAULT_TIMEOUT
           
protected  Map eventMap
           
protected  long lastCleanup
           
protected  long lastUpdate
           
protected static org.apache.log4j.Logger logger
           
protected  int maxRetries
           
protected  int poolSize
           
protected  long retryInterval
           
protected  Object sync
           
protected  long timeout
           
 
Constructor Summary
DefaultEventPool()
          Default constructor.
DefaultEventPool(int ipoolSize, long itimeout, long iretryInterval, int imaxRetries, long icleanupInterval)
          Public constructor.
 
Method Summary
 BaseEvent checkoutEvent(Class event)
          check out an event from the EventPool.
 void cleanupLockedEvents()
          Cleanup any locked events which weren't released (they should all be).
 void releaseEvent(BaseEvent event)
          check the event back in, allowing someone else to have access to it.
 void shutdown()
          Shutdown the event pool
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger

DEFAULT_POOL_SIZE

public static int DEFAULT_POOL_SIZE

DEFAULT_TIMEOUT

public static long DEFAULT_TIMEOUT

DEFAULT_RETRY_INTERVAL

public static long DEFAULT_RETRY_INTERVAL

DEFAULT_MAX_RETRIES

public static int DEFAULT_MAX_RETRIES

DEFAULT_CLEANUP_INTERVAL

public static long DEFAULT_CLEANUP_INTERVAL

eventMap

protected Map eventMap

poolSize

protected int poolSize

timeout

protected long timeout

retryInterval

protected long retryInterval

maxRetries

protected int maxRetries

cleanupInterval

protected long cleanupInterval

lastUpdate

protected long lastUpdate

lastCleanup

protected long lastCleanup

sync

protected Object sync
Constructor Detail

DefaultEventPool

public DefaultEventPool()
Default constructor. Defaults to pool size of 50 with a timeout of 60 seconds. Retry interval of 50 millis, with max retries of 3. Cleanup thread runs every 10 minutes.


DefaultEventPool

public DefaultEventPool(int ipoolSize,
                        long itimeout,
                        long iretryInterval,
                        int imaxRetries,
                        long icleanupInterval)
Public constructor.

Parameters:
ipoolSize - - how many event instances to keep for each class of event)
itimeout - - how long may an event be checked out before it may be reclaimed by the pool
iretryInterval - - how long between retries if there are no events currently available
imaxRetries - - maximum number of retries
icleanupInterval - - how often should the cleanup thread run (millisecs).
Method Detail

checkoutEvent

public BaseEvent checkoutEvent(Class event)
                        throws NoAvailableEventsException,
                               InvalidClassException
check out an event from the EventPool.

Specified by:
checkoutEvent in interface EventPool
Parameters:
event - the class of event we are interested in checking out
Returns:
the checked out event
Throws:
NoAvailableEventsException - if there are no available events in the queue
InvalidClassException - if the event class is not valid

releaseEvent

public void releaseEvent(BaseEvent event)
check the event back in, allowing someone else to have access to it.

Specified by:
releaseEvent in interface EventPool
Parameters:
event - the event we're releasing our lock on

cleanupLockedEvents

public void cleanupLockedEvents()
Cleanup any locked events which weren't released (they should all be). You should not ever really need to run this method. It will get invoked automatically when the cleaner-upper runs

Specified by:
cleanupLockedEvents in interface EventPool

shutdown

public void shutdown()
Shutdown the event pool

Specified by:
shutdown in interface EventPool


Copyright © 2004 BarracudaMVC.org All Rights Reserved.