com.continuent.tungsten.replicator.thl
Class THLParallelReadTask

java.lang.Object
  extended by com.continuent.tungsten.replicator.thl.THLParallelReadTask
All Implemented Interfaces:
java.lang.Runnable

public class THLParallelReadTask
extends java.lang.Object
implements java.lang.Runnable

Performs coordinated reads on the THL on behalf of a particular client (a task thread) and buffers log records up to a local limit.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
THLParallelReadTask(int taskId, THL thl, Partitioner partitioner, AtomicCounter headSeqnoCounter, AtomicIntervalGuard<?> intervalGuard, int maxSize, int maxControlEvents, int syncInterval, com.continuent.tungsten.fsm.event.EventDispatcher dispatcher)
          Instantiate a read task.
 
Method Summary
 void addWatchSyncPredicate(WatchPredicate<ReplDBMSHeader> predicate)
          Adds a watch predicate.
 ReplEvent get()
          Removes and returns next event from the queue, blocking if empty.
 ReplEvent peek()
          Returns but does not remove next event from the queue if it exists or returns null if queue is empty.
 void prepare(PluginContext context)
          Connect to THL and seek start sequence number.
 void putControlEvent(ReplControlEvent controlEvent)
          Inserts a control event.
 void release()
          Terminate reader task and free all resources.
 void run()
          Implements read loop on the log to feed event queue.
 void setRestartHeader(ReplDBMSHeader header)
          Set the starting header.
 int size()
          Returns the current queue size.
 void start()
          Start the task thread.
 void stop()
          Cancel the thread.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

THLParallelReadTask

public THLParallelReadTask(int taskId,
                           THL thl,
                           Partitioner partitioner,
                           AtomicCounter headSeqnoCounter,
                           AtomicIntervalGuard<?> intervalGuard,
                           int maxSize,
                           int maxControlEvents,
                           int syncInterval,
                           com.continuent.tungsten.fsm.event.EventDispatcher dispatcher)
Instantiate a read task.

Method Detail

setRestartHeader

public void setRestartHeader(ReplDBMSHeader header)
Set the starting header. This must be called before prepare().


prepare

public void prepare(PluginContext context)
             throws ReplicatorException,
                    java.lang.InterruptedException
Connect to THL and seek start sequence number. Must be called before run().

Throws:
ReplicatorException
java.lang.InterruptedException

start

public void start()
Start the task thread. This must be called after prepare.


stop

public void stop()
Cancel the thread. This must be called prior to release.


release

public void release()
Terminate reader task and free all resources. Must be called following run().


run

public void run()
Implements read loop on the log to feed event queue.

Specified by:
run in interface java.lang.Runnable

size

public int size()
Returns the current queue size.


get

public ReplEvent get()
              throws java.lang.InterruptedException,
                     ReplicatorException
Removes and returns next event from the queue, blocking if empty. This call blocks if no event is available. Internally it polls so that we correctly detect if the thread has failed.

Returns:
The next event in the queue
Throws:
java.lang.InterruptedException - Thrown if method is interrupted
ReplicatorException - Thrown if the reader thread has failed

peek

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

Throws:
java.lang.InterruptedException

putControlEvent

public void putControlEvent(ReplControlEvent controlEvent)
                     throws java.lang.InterruptedException
Inserts a control event.

Throws:
java.lang.InterruptedException

addWatchSyncPredicate

public void addWatchSyncPredicate(WatchPredicate<ReplDBMSHeader> predicate)
                           throws java.lang.InterruptedException
Adds a watch predicate.

Throws:
java.lang.InterruptedException

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()