com.continuent.tungsten.replicator.util
Class Watch<E>

java.lang.Object
  extended by com.continuent.tungsten.replicator.util.Watch<E>
All Implemented Interfaces:
java.util.concurrent.Future<E>

public class Watch<E>
extends java.lang.Object
implements java.util.concurrent.Future<E>

Implements a "watch" operation that waits for a predicate to be fulfilled on a particular event in an event processing queue.

Author:
Robert Hodges/a>

Constructor Summary
Watch(WatchPredicate<E> predicate, int taskCount)
          Create watch with predicate and task count.
Watch(WatchPredicate<E> predicate, int taskCount, WatchAction<E> action)
          Create watch with all components.
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
          
 E get()
          
 E get(long timeout, java.util.concurrent.TimeUnit unit)
          
 WatchAction<E> getAction()
          Returns the action or null if no action is defined.
 boolean[] getMatched()
          Returns the array of matched conditions.
 WatchPredicate<E> getPredicate()
          Returns the watch predicate.
 boolean isCancelled()
          
 boolean isDone()
          
 boolean offer(E event, int taskId)
          Offer an event to this watch instance.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Watch

public Watch(WatchPredicate<E> predicate,
             int taskCount)
Create watch with predicate and task count.


Watch

public Watch(WatchPredicate<E> predicate,
             int taskCount,
             WatchAction<E> action)
Create watch with all components.

Parameters:
predicate - Predicate to match
action - Action to execute
taskCount - Number of tasks that must report for a match
Method Detail

getPredicate

public WatchPredicate<E> getPredicate()
Returns the watch predicate.


getAction

public WatchAction<E> getAction()
Returns the action or null if no action is defined.


getMatched

public boolean[] getMatched()
Returns the array of matched conditions.


cancel

public boolean cancel(boolean mayInterruptIfRunning)

Specified by:
cancel in interface java.util.concurrent.Future<E>
See Also:
Future.cancel(boolean)

get

public E get()
      throws java.lang.InterruptedException,
             java.util.concurrent.ExecutionException

Specified by:
get in interface java.util.concurrent.Future<E>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
See Also:
Future.get()

get

public E get(long timeout,
             java.util.concurrent.TimeUnit unit)
      throws java.lang.InterruptedException,
             java.util.concurrent.ExecutionException,
             java.util.concurrent.TimeoutException

Specified by:
get in interface java.util.concurrent.Future<E>
Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
See Also:
Future.get(long, java.util.concurrent.TimeUnit)

isCancelled

public boolean isCancelled()

Specified by:
isCancelled in interface java.util.concurrent.Future<E>
See Also:
Future.isCancelled()

isDone

public boolean isDone()

Specified by:
isDone in interface java.util.concurrent.Future<E>
See Also:
Future.isDone()

offer

public boolean offer(E event,
                     int taskId)
              throws java.lang.InterruptedException
Offer an event to this watch instance. If it accepts the event we note the task ID and return true.

Throws:
java.lang.InterruptedException

toString

public java.lang.String toString()

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