com.continuent.tungsten.replicator.storage.parallel
Class ParallelQueueStore

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

public class ParallelQueueStore
extends java.lang.Object
implements ParallelStore

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

Version:
1.0
Author:
Robert Hodges

Nested Class Summary
 class ParallelQueueStore.QueueMetadataImpl
           
 
Constructor Summary
ParallelQueueStore()
           
 
Method Summary
 void configure(PluginContext context)
          Complete plug-in configuration.
 ReplEvent get(int taskId)
          Removes and returns next event from the queue, blocking if empty.
 ReplDBMSHeader getLastHeader(int taskId)
          Returns the last header processed.
 int getMaxOfflineInterval()
          Returns the maximum number of seconds to do a clean shutdown.
 int getMaxSize()
          Maximum size of individual queues.
 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.
 Partitioner getPartitioner()
           
 java.lang.String getPartitionerClass()
          Returns the class used for partitioning transactions across queues.
 int getPartitions()
          Returns the number of partitions for events.
 long getStoreSize()
          Returns the current number of events across all queues of store.
 int getSyncInterval()
          Returns the number of events between sync intervals.
 void insertStopEvent()
          Inserts stop control event after next complete transaction.
 void insertWatchSyncEvent(WatchPredicate<ReplDBMSHeader> predicate)
          Inserts watch synchronization event after next complete transaction that matches the provided predicate.
 boolean isSyncEnabled()
          Returns true if automatic control events for synchronization are enabled.
 ReplEvent 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 setMaxOfflineInterval(int maxOfflineInterval)
          Sets the maximum number of seconds for a clean shutdown.
 void setMaxSize(int size)
          Returns the maximum size of individual queues.
 void setName(java.lang.String name)
          Sets the storage name.
 void setPartitioner(Partitioner partitioner)
           
 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.
 void setSyncEnabled(boolean syncEnabled)
          Enables/disables automatic generation of control events to ensure queue consumers have up-to-date positions in the log.
 void setSyncInterval(int syncInterval)
          Sets the number of events to process before generating an automatic control event if sync is enabled.
 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

ParallelQueueStore

public ParallelQueueStore()
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()
Maximum size of individual queues.


setMaxSize

public void setMaxSize(int size)
Description copied from interface: ParallelStore
Returns the maximum size of individual queues.

Specified by:
setMaxSize in interface ParallelStore

setPartitions

public void setPartitions(int partitions)
Sets the number of queue partitions.

Specified by:
setPartitions in interface ParallelStore

getPartitions

public int getPartitions()
Returns the number of partitions for events.

Specified by:
getPartitions in interface ParallelStore

getPartitioner

public Partitioner getPartitioner()

setPartitioner

public void setPartitioner(Partitioner partitioner)

getPartitionerClass

public java.lang.String getPartitionerClass()
Description copied from interface: ParallelStore
Returns the class used for partitioning transactions across queues.

Specified by:
getPartitionerClass in interface ParallelStore

setPartitionerClass

public void setPartitionerClass(java.lang.String partitionerClass)
Description copied from interface: ParallelStore
Sets the class used for partitioning transactions across queues.

Specified by:
setPartitionerClass in interface ParallelStore

getSyncInterval

public int getSyncInterval()
Returns the number of events between sync intervals.

Specified by:
getSyncInterval in interface ParallelStore

setSyncInterval

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

Specified by:
setSyncInterval in interface ParallelStore

isSyncEnabled

public boolean isSyncEnabled()
Returns true if automatic control events for synchronization are enabled.


setSyncEnabled

public void setSyncEnabled(boolean syncEnabled)
Enables/disables automatic generation of control events to ensure queue consumers have up-to-date positions in the log. This feature is mostly used for testing, as it makes it easier to count queue contents if sync control events are turned off.

Parameters:
syncEnabled - If true sync control events are generated

setMaxOfflineInterval

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

Specified by:
setMaxOfflineInterval in interface ParallelStore
See Also:
ParallelStore.setMaxOfflineInterval(int)

getMaxOfflineInterval

public int getMaxOfflineInterval()
Returns the maximum number of seconds to do a clean shutdown.

Specified by:
getMaxOfflineInterval in interface ParallelStore
See Also:
ParallelStore.getMaxOfflineInterval()

getStoreSize

public long getStoreSize()
Returns the current number of events across all queues of store.


setLastHeader

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

Throws:
ReplicatorException

getLastHeader

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

Throws:
ReplicatorException

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. Putting events into parallel queues needs to occur atomically so this method is synchronized. (Getting/peeking from queues on the other hand must not be synchronized or we would deadlock due to critical sectio processing.)

Throws:
java.lang.InterruptedException
ReplicatorException

get

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

Throws:
java.lang.InterruptedException
ReplicatorException

peek

public ReplEvent peek(int taskId)
               throws ReplicatorException,
                      java.lang.InterruptedException
Returns but does not remove next event from the queue if it exists or returns null if queue is empty.

Throws:
ReplicatorException
java.lang.InterruptedException

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.

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)

insertStopEvent

public void insertStopEvent()
                     throws java.lang.InterruptedException
Inserts stop control event after next complete transaction.

Specified by:
insertStopEvent in interface ParallelStore
Throws:
java.lang.InterruptedException
See Also:
ParallelStore.insertStopEvent()

insertWatchSyncEvent

public void insertWatchSyncEvent(WatchPredicate<ReplDBMSHeader> predicate)
                          throws java.lang.InterruptedException
Inserts watch synchronization event after next complete transaction that matches the provided predicate.

Specified by:
insertWatchSyncEvent in interface ParallelStore
Throws:
java.lang.InterruptedException
See Also:
ParallelStore.insertWatchSyncEvent(com.continuent.tungsten.replicator.util.WatchPredicate)

status

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

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