org.apache.jcs.engine
Class CacheEventQueue

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

public class CacheEventQueue
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 should lazy initilaize the processor thread, and kill the thread if the queue goes emtpy for a specified period, now set to 1 minute. If something comes in after that a new processor thread should be created.


Field Summary
 
Fields inherited from interface org.apache.jcs.engine.behavior.ICacheEventQueue
POOLED_QUEUE_TYPE, SINGLE_QUEUE_TYPE
 
Constructor Summary
CacheEventQueue(ICacheListener listener, long listenerId, java.lang.String cacheName)
          Constructs with the specified listener and the cache name.
CacheEventQueue(ICacheListener listener, long listenerId, java.lang.String cacheName, int maxFailure, int waitBeforeRetry)
          Constructor for the CacheEventQueue object
 
Method Summary
 void addDisposeEvent()
          Adds a feature to the DisposeEvent attribute of the ICacheEventQueue object
 void addPutEvent(ICacheElement ce)
          This adds a put event to the queue.
 void addRemoveAllEvent()
          This adds a remove all event to the queue.
 void addRemoveEvent(java.io.Serializable key)
          This adds a remove event to the queue.
 void destroy()
          Event Q is emtpy.
 long getListenerId()
          Gets the listenerId attribute of the ICacheEventQueue object
 java.lang.String getQueueType()
          What type of queue is this.
 IStats getStatistics()
          This method returns semi-structured data on this queue.
 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()
          If they queue has an active thread it is considered alive.
 boolean isEmpty()
          Are there elements in the queue.
 boolean isWorking()
          A Queue is working unless it has reached its max failure count.
 void setAlive(boolean aState)
          Sets whether the queue is actively processing -- if there are working threads.
 void setWaitToDieMillis(int wtdm)
          Sets the time to wait for events before killing the background thread.
 void setWorking(boolean b)
          This means that the queue is functional.
 int size()
          Returns the number of elements in the queue.
 void stopProcessing()
          Kill the processor thread and indicate that the queue is detroyed and no longer alive, but it can still be working.
 java.lang.String toString()
          Creates a brief string identifying the listener and the region.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CacheEventQueue

public CacheEventQueue(ICacheListener listener,
                       long listenerId,
                       java.lang.String cacheName)
Constructs with the specified listener and the cache name.

Parameters:
listener -
listenerId -
cacheName -

CacheEventQueue

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

Parameters:
listener -
listenerId -
cacheName -
maxFailure -
waitBeforeRetry -
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()
What type of queue is this.

Specified by:
getQueueType in interface ICacheEventQueue
Returns:
queueType

stopProcessing

public void stopProcessing()
Kill the processor thread and indicate that the queue is detroyed and no longer alive, but it can still be working.


getWaitToDieMillis

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

Returns:
int

setWaitToDieMillis

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

Parameters:
wtdm - the ms for the q to sit idle.

toString

public java.lang.String toString()
Creates a brief string identifying the listener and the region.

Overrides:
toString in class java.lang.Object
Returns:
String debugging info.

isAlive

public boolean isAlive()
If they queue has an active thread it is considered alive.

Specified by:
isAlive in interface ICacheEventQueue
Returns:
The alive value

setAlive

public void setAlive(boolean aState)
Sets whether the queue is actively processing -- if there are working threads.

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()
Event Q is emtpy.

Calling destroy interupts the processor thread.

Specified by:
destroy in interface ICacheEventQueue

addPutEvent

public void addPutEvent(ICacheElement ce)
                 throws java.io.IOException
This adds a put event to the queue. When it is processed, the element will be put to the listener.

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
This adds a remove event to the queue. When processed the listener's remove method will be called for the key.

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
This adds a remove all event to the queue. When it is processed, all elements will be removed from the cache.

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

getStatistics

public IStats getStatistics()
This method returns semi-structured data on this queue.

Specified by:
getStatistics in interface ICacheEventQueue
Returns:
information on the status and history of the queue
See Also:
ICacheEventQueue.getStatistics()

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 the queue is functional.

setWorking

public void setWorking(boolean b)
This means that the queue is functional. If we reached the max number of failures, the queue is marked as non functional and will never work again.

Parameters:
b -

isEmpty

public boolean isEmpty()
Description copied from interface: ICacheEventQueue
Are there elements in the queue.

Specified by:
isEmpty in interface ICacheEventQueue
Returns:
whether there are any items in the queue.

size

public int size()
Returns the number of elements in the queue.

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


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