com.continuent.tungsten.replicator.util
Class AtomicIntervalGuard<D>

java.lang.Object
  extended by com.continuent.tungsten.replicator.util.AtomicIntervalGuard<D>

public class AtomicIntervalGuard<D>
extends java.lang.Object

Tracks the sequence number and time interval between a group of tasks processing transactions to ensure that the first and last tasks do not get too far apart in the log. Class methods are fully synchronized, which results in a large number of lock requests. Changes to these classes should be carefully checked for performance via unit tests.

Since the initial implementation this class has been extended to add a datum that may optionally be stored with each thread. This allows clients to track additional hi/low properties for themselves.

Author:
Robert Hodges

Constructor Summary
AtomicIntervalGuard(int expected)
          Allocates a thread interval array.
 
Method Summary
 D getHiDatum()
          Return the datum of the highest entry in the array.
 long getHiLatency()
          Return the latency in seconds between the commit time and the automatically generated commit time.
 long getHiSeqno()
          Get highest seqno in the array.
 long getHiTime()
          Return the highest time in the array.
 long getInterval()
          Return the interval between highest and lowest values.
 D getLowDatum()
          Return the datum of the lowest entry in the array.
 long getLowLatency()
          Return lowest latency in milliseconds between the commit time and the automatically generated commit time in the array.
 long getLowSeqno()
          Get lowest seqno in the array.
 long getLowTime()
          Return the lowest time in the array.
 void report(int id, long seqno, long time)
          Report position for an individual task without added datum.
 void report(int id, long seqno, long time, D datum)
          Report position for an individual task.
 void report(int id, long seqno, long time, long reportTime, D datum)
          Report position for an individual task.
 int size()
          Return the number of entries currently in the array.
 java.lang.String toString()
          
 void unreport(int id)
          Remove a particular task from the reported position array.
 void validate()
          Ensures that the array is consistent by checking various safety conditions.
 long waitMinTime(long time, long seqno)
          Wait until the minimum time in array is greater than or equal to the request time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AtomicIntervalGuard

public AtomicIntervalGuard(int expected)
Allocates a thread interval array.

Parameters:
expected - Expected number of threads for correct operation
Method Detail

report

public void report(int id,
                   long seqno,
                   long time)
Report position for an individual task without added datum.


report

public void report(int id,
                   long seqno,
                   long time,
                   D datum)
Report position for an individual task. This call makes an important assumption that sequence numbers never move backward, which simplifies maintenance of the array.

Parameters:
id - Thread ID
seqno - Sequence number reached by thread
time - Original timestamp of transaction
datum - An optional datum associated with the transaction

report

public void report(int id,
                   long seqno,
                   long time,
                   long reportTime,
                   D datum)
Report position for an individual task. This call makes an important assumption that sequence numbers never move backward, which simplifies maintenance of the array.

Parameters:
id - Thread ID
seqno - Sequence number reached by thread
time - Original timestamp of transaction
reportTime - Original time + latency
datum - An optional datum associated with the transaction
Throws:
ReplicatorException - Thrown if there is an illegal update.

unreport

public void unreport(int id)
Remove a particular task from the reported position array.

Parameters:
id - Thread ID

size

public int size()
Return the number of entries currently in the array.


getLowSeqno

public long getLowSeqno()
Get lowest seqno in the array.


getLowTime

public long getLowTime()
Return the lowest time in the array.


getLowLatency

public long getLowLatency()
Return lowest latency in milliseconds between the commit time and the automatically generated commit time in the array.


getLowDatum

public D getLowDatum()
Return the datum of the lowest entry in the array.


getHiSeqno

public long getHiSeqno()
Get highest seqno in the array.


getHiTime

public long getHiTime()
Return the highest time in the array.


getHiLatency

public long getHiLatency()
Return the latency in seconds between the commit time and the automatically generated commit time.


getHiDatum

public D getHiDatum()
Return the datum of the highest entry in the array.


getInterval

public long getInterval()
Return the interval between highest and lowest values.


waitMinTime

public long waitMinTime(long time,
                        long seqno)
                 throws java.lang.InterruptedException
Wait until the minimum time in array is greater than or equal to the request time. If there is nothing in the array we return immediately.

Parameters:
time - Return if this time is less than or equal to the trailing commit timestamp
seqno - Return if this seqno is less than or equal to the trailing seqno
Returns:
Returns the head time or 0 if array is empty
Throws:
java.lang.InterruptedException

toString

public java.lang.String toString()

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

validate

public void validate()
              throws java.lang.RuntimeException
Ensures that the array is consistent by checking various safety conditions. (Where's Eiffel when you need it?)

Throws:
java.lang.RuntimeException