com.ibm.di.queue
Class MemBufferQ

java.lang.Object
  extended by com.ibm.di.queue.MemBufferQ
All Implemented Interfaces:
ActionListener, EventListener

public class MemBufferQ
extends Object
implements ActionListener

A FIFO queue


Constructor Summary
MemBufferQ(int nEntries)
          Constructor Initializes the memory buffer pipe when paging is disabled
MemBufferQ(int nEntries, int pagesize)
          Constructor Initializes the memory buffer pipe when paging is enabled
 
Method Summary
 void actionPerformed(ActionEvent e)
           
 void AddToChunk(Object x)
           
 void blockAdd(boolean enable)
          Enable disable blocking add this is used only when paging support is disabled.
 void enablePersistence(boolean enable)
          enablePersistence : enable/disable paging support using system store
 void handle(int purpose)
          handle : issues triggers to the registered callbacks
 void initDB(String sDBName, String jdbcLogin, String jdbcPassword, String sTblName)
          Initializes the system store paramemters.
 boolean isEmpty()
           
 Object peek()
          Same as read but does not remove data from the memq never use peek() for polling the memq in reader thread this is because the memq id implemented using a synchronized data structure and polling memq continuously would not relinquish control of memq to the writer thread as a result the reader will wait infinitely and writer would fail leading to loss of data.
 Object peekPage()
           
 void purgeQueue()
          Purges the queue.
 Object read()
          synchronized method: The first item inserted in the queue and not yet removed.
 Object read(int timeout)
          synchronized method: The first item inserted in the queue and not yet removed.
 void register(QCallback a, int purpose)
          Registers a callback which will be called when memQ is empty/full/data available it is assumed that the callback implements the handle()function.
 int size()
           
 void terminate()
          Terminates the system store threads.
 void terminate(boolean dropSystemStore)
          terminates the system store threads and drops table if dropSystemStore set to true
 void unregister(QCallback a, int purpose)
          unregister : unregisters a callback
 void write(Object x)
          write : add an object to the end of memq contains embedded logic that would trigger whenever memQ is full/empty or when an object is added to empty queue so that objects waiting for data can be triggered
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemBufferQ

public MemBufferQ(int nEntries,
                  int pagesize)
Constructor Initializes the memory buffer pipe when paging is enabled


MemBufferQ

public MemBufferQ(int nEntries)
Constructor Initializes the memory buffer pipe when paging is disabled

Method Detail

AddToChunk

public void AddToChunk(Object x)

initDB

public void initDB(String sDBName,
                   String jdbcLogin,
                   String jdbcPassword,
                   String sTblName)
            throws Exception
Initializes the system store paramemters.

Parameters:
sDBName - system store database name
jdbcLogin - username to connect to the db
jdbcPassword - password to connect to the db
sTblName - table name
Throws:
Exception - if system store is not initialized properly

isEmpty

public boolean isEmpty()
Returns:
True if memQ is empty

size

public int size()
Returns:
Number of items in the memq.

read

public Object read()
synchronized method: The first item inserted in the queue and not yet removed. Requires !isEmpty (). Reading removes the item from the queue. read with no timeout.


read

public Object read(int timeout)
synchronized method: The first item inserted in the queue and not yet removed. Requires !isEmpty (). Reading removes the item from the queue. Waits for timeout


peekPage

public Object peekPage()

write

public void write(Object x)
           throws Exception
write : add an object to the end of memq contains embedded logic that would trigger whenever memQ is full/empty or when an object is added to empty queue so that objects waiting for data can be triggered

Parameters:
x - object to be added
Throws:
Exception - if add fails

peek

public Object peek()
Same as read but does not remove data from the memq never use peek() for polling the memq in reader thread this is because the memq id implemented using a synchronized data structure and polling memq continuously would not relinquish control of memq to the writer thread as a result the reader will wait infinitely and writer would fail leading to loss of data. Use callbacks functionality by registering your object to receive a trigger when data is available for reading in the memq.

Returns:
object read
See Also:
register(QCallback a, int purpose)

register

public void register(QCallback a,
                     int purpose)
Registers a callback which will be called when memQ is empty/full/data available it is assumed that the callback implements the handle()function.

Parameters:
a - object to be triggered
purpose - full/empty/data available

unregister

public void unregister(QCallback a,
                       int purpose)
                throws Exception
unregister : unregisters a callback

Parameters:
a - object to be unregistered
purpose - full/empty/data available if -1 unregister the object from all callbacks
Throws:
Exception - if callback object is not found

handle

public void handle(int purpose)
handle : issues triggers to the registered callbacks

Parameters:
purpose - full/empty/data available

enablePersistence

public void enablePersistence(boolean enable)
enablePersistence : enable/disable paging support using system store

Parameters:
enable - paging support enabled if true and disabled if false

blockAdd

public void blockAdd(boolean enable)
Enable disable blocking add this is used only when paging support is disabled.

Parameters:
enable - if true, add to memq blocks infinitely until there is space for an object to be added to memq if false, add throws an exception if memq is full

actionPerformed

public void actionPerformed(ActionEvent e)
Specified by:
actionPerformed in interface ActionListener

terminate

public void terminate()
Terminates the system store threads.


terminate

public void terminate(boolean dropSystemStore)
terminates the system store threads and drops table if dropSystemStore set to true

Parameters:
dropSystemStore -

purgeQueue

public void purgeQueue()
Purges the queue. The isBeingPurged Flag is set which blocks all reader or writer threads until the purge operation is not completed. Deletes all data from the associated table in System Store if this queue has paging enabled.