com.continuent.tungsten.replicator.storage
Class InMemoryMultiQueue

java.lang.Object
  extended by com.continuent.tungsten.replicator.storage.InMemoryMultiQueue
All Implemented Interfaces:
ReplicatorPlugin, Store

public class InMemoryMultiQueue
extends java.lang.Object
implements Store

Implements an in-memory queue store with multiple queues. This is used for testing other parallel queues where we need to simulate ability to apply in parallel across a bunch of threads and tell what happened on each.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
InMemoryMultiQueue()
           
 
Method Summary
 void configure(PluginContext context)
          Complete plug-in configuration.
 ReplDBMSEvent get(int taskId)
          Removes and returns next event from the queue, blocking if empty.
 ReplDBMSEvent get(int taskId, long waitMillis)
          Removes and returns next event from the queue, waiting up to specified number of milliseconds.
 ReplDBMSHeader getLastHeader(int taskId)
          Returns the last header processed.
 int getMaxSize()
           
 long getMaxStoredSeqno()
          Returns the maximum persistently stored sequence number.
 long getMinStoredSeqno()
          Returns the minimum persistently stored sequence number.
 java.lang.String getName()
          Gets the storage name.
 int getPartitions()
           
 ReplDBMSEvent peek(int taskId)
          Returns but does not remove next event from the queue if it exists or returns null if queue is empty.
 void prepare(PluginContext context)
          Allocate an in-memory queue.
 void put(int taskId, ReplDBMSEvent event)
          Puts an event in the queue, blocking if it is full.
 void release(PluginContext context)
          Release queue.
 void setLastHeader(int taskId, ReplDBMSHeader header)
          Sets the last header processed.
 void setMaxSize(int size)
           
 void setName(java.lang.String name)
          Sets the storage name.
 void setPartitions(int partitions)
           
 int size(int taskId)
          Returns the current queue size.
 TungstenProperties status()
          Returns status information as a set of named properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryMultiQueue

public InMemoryMultiQueue()
Method Detail

getName

public java.lang.String getName()
Gets the storage name.

Specified by:
getName in interface Store
See Also:
Store.getName()

setName

public void setName(java.lang.String name)
Sets the storage name.

Specified by:
setName in interface Store
See Also:
Store.setName(java.lang.String)

getMaxSize

public int getMaxSize()

setMaxSize

public void setMaxSize(int size)

getPartitions

public int getPartitions()

setPartitions

public void setPartitions(int partitions)

setLastHeader

public void setLastHeader(int taskId,
                          ReplDBMSHeader header)
Sets the last header processed. This is required for restart.


getLastHeader

public ReplDBMSHeader getLastHeader(int taskId)
Returns the last header processed.


getMaxStoredSeqno

public long getMaxStoredSeqno()
Returns the maximum persistently stored sequence number.

Specified by:
getMaxStoredSeqno in interface Store
See Also:
Store.getMaxStoredSeqno()

getMinStoredSeqno

public long getMinStoredSeqno()
Returns the minimum persistently stored sequence number.

Specified by:
getMinStoredSeqno in interface Store
See Also:
Store.getMinStoredSeqno()

put

public void put(int taskId,
                ReplDBMSEvent event)
         throws java.lang.InterruptedException,
                ReplicatorException
Puts an event in the queue, blocking if it is full. This call fails if failAll is true, which can be used to test error handling.

Throws:
java.lang.InterruptedException
ReplicatorException

get

public ReplDBMSEvent get(int taskId)
                  throws java.lang.InterruptedException
Removes and returns next event from the queue, blocking if empty.

Throws:
java.lang.InterruptedException

get

public ReplDBMSEvent get(int taskId,
                         long waitMillis)
                  throws java.lang.InterruptedException
Removes and returns next event from the queue, waiting up to specified number of milliseconds. Returns null if nothing is read in this time.

Throws:
java.lang.InterruptedException

peek

public ReplDBMSEvent peek(int taskId)
Returns but does not remove next event from the queue if it exists or returns null if queue is empty.


size

public int size(int taskId)
Returns the current queue size.


configure

public void configure(PluginContext context)
               throws ReplicatorException
Complete plug-in configuration. This is called after setters are invoked at the time that the replicator goes through configuration.

Specified by:
configure in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if configuration is incomplete or fails
See Also:
ReplicatorPlugin.configure(com.continuent.tungsten.replicator.plugin.PluginContext)

prepare

public void prepare(PluginContext context)
             throws ReplicatorException
Allocate an in-memory queue. Prepare plug-in for use. This method is assumed to allocate all required resources. It is called before the plug-in performs any operations.

Specified by:
prepare in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if resource allocation fails
See Also:
ReplicatorPlugin.prepare(com.continuent.tungsten.replicator.plugin.PluginContext)

release

public void release(PluginContext context)
             throws ReplicatorException
Release queue. Release all resources used by plug-in. This is called before the plug-in is deallocated.

Specified by:
release in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if resource deallocation fails
See Also:
ReplicatorPlugin.release(com.continuent.tungsten.replicator.plugin.PluginContext)

status

public TungstenProperties status()
Returns status information as a set of named properties.

Specified by:
status in interface Store
See Also:
Store.status()