org.apache.jcs.engine
Class PooledCacheEventQueue

java.lang.Object
  extended by org.apache.jcs.engine.PooledCacheEventQueue
All Implemented Interfaces:
ICacheEventQueue

public class PooledCacheEventQueue
extends java.lang.Object
implements ICacheEventQueue

An event queue is used to propagate ordered cache events to one and only one target listener.

This is a modified version of the experimental version. It uses a PooledExecutor and a BoundedBuffer to queue up events and execute them as threads become available.

The PooledExecutor is static, because presumably these processes will be IO bound, so throwing more than a few threads at them will serve no purpose other than to saturate the IO interface. In light of this, having one thread per region seems unnecessary. This may prove to be false.


Field Summary
 
Fields inherited from interface org.apache.jcs.engine.behavior.ICacheEventQueue
POOLED_QUEUE_TYPE, SINGLE_QUEUE_TYPE
 
Constructor Summary
PooledCacheEventQueue(ICacheListener listener, long listenerId, java.lang.String cacheName, int maxFailure, int waitBeforeRetry, java.lang.String threadPoolName)
          Constructor for the CacheEventQueue object
 
Method Summary
 void addDisposeEvent()
          Adds a feature to the DisposeEvent attribute of the ICacheEventQueue object
 void addPutEvent(ICacheElement ce)
          Constructs a PutEvent for the object and passes it to the event queue.
 void addRemoveAllEvent()
          Adds a feature to the RemoveAllEvent attribute of the ICacheEventQueue object
 void addRemoveEvent(java.io.Serializable key)
          Adds a feature to the RemoveEvent attribute of the ICacheEventQueue object
 void destroy()
          Destroy the queue.
 long getListenerId()
          Gets the listenerId attribute of the ICacheEventQueue object
 java.lang.String getQueueType()
          Return the type of event queue we are using, either single or pooled.
 IStats getStatistics()
          Returns the historical and statistical data for an event queue cache.
 java.lang.String getStats()
           
 int getWaitToDieMillis()
          Returns the time to wait for events before killing the background thread.
 void initialize(ICacheListener listener, long listenerId, java.lang.String cacheName, int maxFailure, int waitBeforeRetry, java.lang.String threadPoolName)
          Initializes the queue.
 boolean isAlive()
          Gets the alive attribute of the ICacheEventQueue object.
 boolean isEmpty()
          If the Queue is using a bounded channel we can determine the size.
 boolean isWorking()
          A Queue is working unless it has reached its max failure count.
 void setAlive(boolean aState)
           
 void setWaitToDieMillis(int wtdm)
          Sets the time to wait for events before killing the background thread.
 void setWorking(boolean isWorkingArg)
           
 int size()
          Returns the number of elements in the queue.
 void stopProcessing()
          Event Q is empty.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PooledCacheEventQueue

public PooledCacheEventQueue(ICacheListener listener,
                             long listenerId,
                             java.lang.String cacheName,
                             int maxFailure,
                             int waitBeforeRetry,
                             java.lang.String threadPoolName)
Constructor for the CacheEventQueue object

Parameters:
listener -
listenerId -
cacheName -
maxFailure -
waitBeforeRetry -
threadPoolName -
Method Detail

initialize

public void initialize(ICacheListener listener,
                       long listenerId,
                       java.lang.String cacheName,
                       int maxFailure,
                       int waitBeforeRetry,
                       java.lang.String threadPoolName)
Initializes the queue.

Specified by:
initialize in interface ICacheEventQueue
Parameters:
listener -
listenerId -
cacheName -
maxFailure -
waitBeforeRetry -
threadPoolName -

getQueueType

public java.lang.String getQueueType()
Description copied from interface: ICacheEventQueue
Return the type of event queue we are using, either single or pooled.

Specified by:
getQueueType in interface ICacheEventQueue
Returns:
the queue type

stopProcessing

public void stopProcessing()
Event Q is empty.


getWaitToDieMillis

public int getWaitToDieMillis()
Returns the time to wait for events before killing the background thread.

Returns:
the time to wait before shutting down in ms.

setWaitToDieMillis

public void setWaitToDieMillis(int wtdm)
Sets the time to wait for events before killing the background thread.

Parameters:
wtdm -

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String info.

isAlive

public boolean isAlive()
Description copied from interface: ICacheEventQueue
Gets the alive attribute of the ICacheEventQueue object. Alive just indicates that there are active threads. This is less important that if the queue is working.

Specified by:
isAlive in interface ICacheEventQueue
Returns:
true if not destroyed.

setAlive

public void setAlive(boolean aState)
Parameters:
aState -

getListenerId

public long getListenerId()
Description copied from interface: ICacheEventQueue
Gets the listenerId attribute of the ICacheEventQueue object

Specified by:
getListenerId in interface ICacheEventQueue
Returns:
The listenerId value

destroy

public void destroy()
Destroy the queue. Interrupt all threads.

Specified by:
destroy in interface ICacheEventQueue

addPutEvent

public void addPutEvent(ICacheElement ce)
                 throws java.io.IOException
Constructs a PutEvent for the object and passes it to the event queue.

Specified by:
addPutEvent in interface ICacheEventQueue
Parameters:
ce - The feature to be added to the PutEvent attribute
Throws:
java.io.IOException

addRemoveEvent

public void addRemoveEvent(java.io.Serializable key)
                    throws java.io.IOException
Description copied from interface: ICacheEventQueue
Adds a feature to the RemoveEvent attribute of the ICacheEventQueue object

Specified by:
addRemoveEvent in interface ICacheEventQueue
Parameters:
key - The feature to be added to the RemoveEvent attribute
Throws:
java.io.IOException

addRemoveAllEvent

public void addRemoveAllEvent()
                       throws java.io.IOException
Description copied from interface: ICacheEventQueue
Adds a feature to the RemoveAllEvent attribute of the ICacheEventQueue object

Specified by:
addRemoveAllEvent in interface ICacheEventQueue
Throws:
java.io.IOException

addDisposeEvent

public void addDisposeEvent()
                     throws java.io.IOException
Description copied from interface: ICacheEventQueue
Adds a feature to the DisposeEvent attribute of the ICacheEventQueue object

Specified by:
addDisposeEvent in interface ICacheEventQueue
Throws:
java.io.IOException

getStats

public java.lang.String getStats()
Returns:
Statistics info

getStatistics

public IStats getStatistics()
Description copied from interface: ICacheEventQueue
Returns the historical and statistical data for an event queue cache.

Specified by:
getStatistics in interface ICacheEventQueue
Returns:
IStats

isWorking

public boolean isWorking()
Description copied from interface: ICacheEventQueue
A Queue is working unless it has reached its max failure count.

Specified by:
isWorking in interface ICacheEventQueue
Returns:
whether or not the queue is functional

setWorking

public void setWorking(boolean isWorkingArg)
Parameters:
isWorkingArg - whether the queue is functional

isEmpty

public boolean isEmpty()
If the Queue is using a bounded channel we can determine the size. If it is zero or we can't determine the size, we return true.

Specified by:
isEmpty in interface ICacheEventQueue
Returns:
whether or not there are items in the queue

size

public int size()
Returns the number of elements in the queue. If the queue cannot determine the size accurately it will return 1.

Specified by:
size in interface ICacheEventQueue
Returns:
number of items in the queue.


Copyright © 2002-2011 Apache Software Foundation. All Rights Reserved.