com.continuent.tungsten.replicator.util
Class AtomicCounter

java.lang.Object
  extended by com.continuent.tungsten.replicator.util.AtomicCounter

public class AtomicCounter
extends java.lang.Object

Defines a simple "atomic counter" that allows clients to increment the encapsulated sequence number and wait synchronously until particular values are reached. This class is thread-safe.

Version:
1.0
Author:
Teemu Ollakka, Robert Hodges

Constructor Summary
AtomicCounter(long seqno)
          Creates a new Sequencer object with a starting value.
 
Method Summary
 long decrAndGetSeqno()
          Decrement seqno and notify waiters, then return value.
 long getSeqno()
          Get value of current seqno.
 long incrAndGetSeqno()
          Increment seqno and notify waiters, then return value.
 void setSeqno(long seqno)
          Sets values of current seqno.
 java.lang.String toString()
          Print a string representation of the value.
 void waitSeqnoGreaterEqual(long waitSeqno)
          Wait until seqno is greater than or equal to the desired value.
 boolean waitSeqnoGreaterEqual(long waitSeqno, long millis)
          Wait until seqno is greater than or equal to the desired value *or* we exceed the timeout.
 void waitSeqnoLessEqual(long waitSeqno)
          Wait until seqno is less than or equal to the desired value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AtomicCounter

public AtomicCounter(long seqno)
Creates a new Sequencer object with a starting value.

Parameters:
seqno - Initial sequence number
Method Detail

getSeqno

public long getSeqno()
Get value of current seqno.


setSeqno

public void setSeqno(long seqno)
Sets values of current seqno. Value can only be set upward.


incrAndGetSeqno

public long incrAndGetSeqno()
Increment seqno and notify waiters, then return value.


decrAndGetSeqno

public long decrAndGetSeqno()
Decrement seqno and notify waiters, then return value.


waitSeqnoGreaterEqual

public void waitSeqnoGreaterEqual(long waitSeqno)
                           throws java.lang.InterruptedException
Wait until seqno is greater than or equal to the desired value.

Parameters:
waitSeqno - Sequence number to wait for
Throws:
java.lang.InterruptedException - if somebody cancels the wait

waitSeqnoGreaterEqual

public boolean waitSeqnoGreaterEqual(long waitSeqno,
                                     long millis)
                              throws java.lang.InterruptedException
Wait until seqno is greater than or equal to the desired value *or* we exceed the timeout.

Parameters:
waitSeqno - Sequence number to wait for
millis - Number of milliseconds to wait
Returns:
True if wait was successful, otherwise false
Throws:
java.lang.InterruptedException - if somebody cancels the wait

waitSeqnoLessEqual

public void waitSeqnoLessEqual(long waitSeqno)
                        throws java.lang.InterruptedException
Wait until seqno is less than or equal to the desired value.

Parameters:
waitSeqno - Sequence number to wait for
Throws:
java.lang.InterruptedException - if somebody cancels the wait

toString

public java.lang.String toString()
Print a string representation of the value.

Overrides:
toString in class java.lang.Object