com.continuent.tungsten.replicator.storage
Class InMemoryQueueStore

java.lang.Object
  extended by com.continuent.tungsten.replicator.storage.InMemoryQueueStore
All Implemented Interfaces:
ReplicatorPlugin, Store
Direct Known Subclasses:
PrefetchStore, PrefetchStore

public class InMemoryQueueStore
extends java.lang.Object
implements Store

Implements an in-memory event store. This queue has no memory beyond its current contents.

Version:
1.0
Author:
Robert Hodges

Field Summary
protected  ReplDBMSHeader lastHeader
           
protected  int maxSize
           
protected  java.lang.String name
           
protected  int partitions
           
protected  java.util.concurrent.LinkedBlockingQueue<ReplDBMSEvent> queue
           
protected  long transactionCount
           
 
Constructor Summary
InMemoryQueueStore()
           
 
Method Summary
 void configure(PluginContext context)
          Complete plug-in configuration.
 ReplDBMSEvent get()
          Removes and returns next event from the queue, blocking if empty.
 ReplDBMSHeader getLastHeader()
          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.
 ReplDBMSEvent peek()
          Returns but does not remove next event from the queue if it exists or returns null if queue is empty.
 ReplDBMSEvent poll()
          Removes and returns next event from the queue, returning null if empty.
 void prepare(PluginContext context)
          Allocate an in-memory queue.
 void put(ReplDBMSEvent event)
          Puts an event in the queue, blocking if it is full.
 void release(PluginContext context)
          Release queue.
 void setLastHeader(ReplDBMSHeader header)
          Sets the last header processed.
 void setMaxOfflineInterval(int maxOfflineInterval)
          Sets the maximum number of seconds for a clean shutdown.
 void setMaxSize(int size)
           
 void setName(java.lang.String name)
          Sets the storage name.
 void setPartitionerClass(java.lang.String partitionerClass)
          Sets the class used for partitioning transactions across queues.
 void setPartitions(int partitions)
          Sets the number of queue partitions, i.e., channels.
 void setSyncInterval(int syncInterval)
          Sets the number of events to process before generating an automatic control event if sync is enabled.
 int size()
          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
 

Field Detail

name

protected java.lang.String name

queue

protected java.util.concurrent.LinkedBlockingQueue<ReplDBMSEvent> queue

maxSize

protected int maxSize

lastHeader

protected ReplDBMSHeader lastHeader

transactionCount

protected long transactionCount

partitions

protected int partitions
Constructor Detail

InMemoryQueueStore

public InMemoryQueueStore()
Method Detail

getName

public java.lang.String getName()
Description copied from interface: Store
Gets the storage name.

Specified by:
getName in interface Store

setName

public void setName(java.lang.String name)
Description copied from interface: Store
Sets the storage name.

Specified by:
setName in interface Store

getMaxSize

public int getMaxSize()

setMaxSize

public void setMaxSize(int size)

setLastHeader

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


getLastHeader

public ReplDBMSHeader getLastHeader()
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()

setPartitions

public void setPartitions(int partitions)
Sets the number of queue partitions, i.e., channels. This may not be more than 1.


setPartitionerClass

public void setPartitionerClass(java.lang.String partitionerClass)
Sets the class used for partitioning transactions across queues.


setSyncInterval

public void setSyncInterval(int syncInterval)
Sets the number of events to process before generating an automatic control event if sync is enabled.


setMaxOfflineInterval

public void setMaxOfflineInterval(int maxOfflineInterval)
Sets the maximum number of seconds for a clean shutdown.


put

public void put(ReplDBMSEvent event)
         throws java.lang.InterruptedException,
                ReplicatorException
Puts an event in the queue, blocking if it is full.

Throws:
ReplicatorException
java.lang.InterruptedException

get

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

Throws:
java.lang.InterruptedException

poll

public ReplDBMSEvent poll()
                   throws java.lang.InterruptedException
Removes and returns next event from the queue, returning null if empty. This method is used for unit testing, where it prevents cases from hanging if a queue is unexpectedly empty.

Throws:
java.lang.InterruptedException

peek

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


size

public int size()
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()
Description copied from interface: Store
Returns status information as a set of named properties.

Specified by:
status in interface Store