com.arjuna.ats.arjuna.coordinator
Class TransactionReaper

java.lang.Object
  extended by com.arjuna.ats.arjuna.coordinator.TransactionReaper

public class TransactionReaper
extends java.lang.Object

Class to record transactions with non-zero timeout values, and class to implement a transaction reaper thread which terminates these transactions once their timeout elapses.

Since:
JTS 1.0.
Version:
$Id: TransactionReaper.java 2342 2006-03-30 13:06:17Z $
Author:
Mark Little (mark@arjuna.com)

Field Summary
static long defaultCancelFailWaitPeriod
           
static long defaultCancelWaitPeriod
           
static long defaultCheckPeriod
           
static int defaultZombieMax
           
static java.lang.String DYNAMIC
           
static java.lang.String NORMAL
           
static java.lang.String PERIODIC
           
 
Method Summary
 void addListener(ReaperMonitor listener)
           
 void check()
          process all entries in the timeout queue which have expired.
 long checkingPeriod()
           
 void doCancellations()
           
 long getRemainingTimeoutMills(java.lang.Object control)
          Given the transaction instance, this will return the time left before the transaction is automatically rolled back if it has not been terminated.
 int getTimeout(java.lang.Object control)
          Given a Control, return the associated timeout, or 0 if we do not know about it.
 void insert(Reapable control, int timeout)
          timeout is given in seconds, but we work in milliseconds.
static void instantiate()
          Currently we let the reaper thread run at same priority as other threads.
static boolean isDynamic()
           
 long numberOfTimeouts()
          Return the number of timeouts registered.
 long numberOfTransactions()
           
 void remove(java.lang.Object control)
           
 boolean removeListener(ReaperMonitor listener)
           
static void terminate(boolean waitForTransactions)
          Terminate the transaction reaper.
static long transactionLifetime()
           
static TransactionReaper transactionReaper()
          Starting with 4.8, this method will always return an instance, will never return null.
 void waitForCancellations()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORMAL

public static final java.lang.String NORMAL
See Also:
Constant Field Values

DYNAMIC

public static final java.lang.String DYNAMIC
See Also:
Constant Field Values

PERIODIC

public static final java.lang.String PERIODIC
See Also:
Constant Field Values

defaultCheckPeriod

public static final long defaultCheckPeriod
See Also:
Constant Field Values

defaultCancelWaitPeriod

public static final long defaultCancelWaitPeriod
See Also:
Constant Field Values

defaultCancelFailWaitPeriod

public static final long defaultCancelFailWaitPeriod
See Also:
Constant Field Values

defaultZombieMax

public static final int defaultZombieMax
See Also:
Constant Field Values
Method Detail

checkingPeriod

public final long checkingPeriod()

check

public final void check()
process all entries in the timeout queue which have expired. entries for newly expired transactions are passed to a worker thread for cancellation and requeued for subsequent progress checks. the worker is given a kick if such checks find it is wedged.

Timeout is given in milliseconds.


waitForCancellations

public final void waitForCancellations()

doCancellations

public final void doCancellations()

numberOfTransactions

public final long numberOfTransactions()
Returns:
the number of items in the reaper's list.
Since:
JTS 2.2. Note: this is a) expensive and b) an approximation. Should be called only by test code.

numberOfTimeouts

public final long numberOfTimeouts()
Return the number of timeouts registered. Note: this is a) expensive and b) an approximation. Should be called only by test code.

Returns:
The number of timeouts registered.

addListener

public final void addListener(ReaperMonitor listener)

removeListener

public final boolean removeListener(ReaperMonitor listener)

insert

public final void insert(Reapable control,
                         int timeout)
timeout is given in seconds, but we work in milliseconds. Attempting to insert an element that is already present is an error (IllegalStateException)


remove

public final void remove(java.lang.Object control)

getRemainingTimeoutMills

public final long getRemainingTimeoutMills(java.lang.Object control)
Given the transaction instance, this will return the time left before the transaction is automatically rolled back if it has not been terminated.

Parameters:
control -
Returns:
the remaining time in milliseconds.

getTimeout

public final int getTimeout(java.lang.Object control)
Given a Control, return the associated timeout, or 0 if we do not know about it.

Return in seconds! Takes an Object because TransactionFactoryImple.getTransactionInfo and ArjunaTransactionImple.propagationContext use it and don't have a Reapable.


instantiate

public static void instantiate()
Currently we let the reaper thread run at same priority as other threads. Could get priority from environment.


transactionReaper

public static TransactionReaper transactionReaper()
Starting with 4.8, this method will always return an instance, will never return null. This causes the reaper to be instantiated unnecessarily in some cases, but that's cheaper than the alternatives.

Returns:
a TransactionReaper singleton.

terminate

public static void terminate(boolean waitForTransactions)
Terminate the transaction reaper. This is a synchronous operation and will only return once the reaper has been shutdown cleanly.

Note, this method assumes that the transaction system has been shutdown already so no new transactions can be created, or we could be here for a long time!

Parameters:
waitForTransactions - if true then the reaper will wait until all transactions have terminated (or been terminated by it). If false then the reaper will call setRollbackOnly on all the transactions.

isDynamic

public static boolean isDynamic()

transactionLifetime

public static long transactionLifetime()