[jboss-svn-commits] JBL Code SVN: r11683 - in labs/jbosstm/tags: JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri May 4 10:31:11 EDT 2007


Author: kevin.conner at jboss.com
Date: 2007-05-04 10:31:10 -0400 (Fri, 04 May 2007)
New Revision: 11683

Added:
   labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/
   labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java
   labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java
   labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperTestCase.java
Removed:
   labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java
   labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java
   labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperTestCase.java
Log:
Tagged for JBOSSTS_4_2_3_SP3

Copied: labs/jbosstm/tags/JBOSSTS_4_2_3_SP3 (from rev 11677, labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP)

Deleted: labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java	2007-05-04 12:06:33 UTC (rev 11677)
+++ labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java	2007-05-04 14:31:10 UTC (rev 11683)
@@ -1,536 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- *
- * (C) 2005-2006,
- * @author JBoss Inc.
- */
-/*
- * Copyright (C) 1998, 1999, 2000, 2001,
- *
- * Arjuna Solutions Limited,
- * Newcastle upon Tyne,
- * Tyne and Wear,
- * UK.
- *
- * $Id: TransactionReaper.java 2342 2006-03-30 13:06:17Z  $
- */
-
-package com.arjuna.ats.arjuna.coordinator;
-
-import com.arjuna.ats.arjuna.common.Environment;
-import com.arjuna.ats.arjuna.common.arjPropertyManager;
-import com.arjuna.ats.arjuna.coordinator.Reapable;
-import com.arjuna.ats.arjuna.coordinator.ActionStatus;
-
-import com.arjuna.ats.internal.arjuna.template.OrderedList;
-import com.arjuna.ats.internal.arjuna.template.OrderedListIterator;
-import com.arjuna.ats.internal.arjuna.coordinator.*;
-
-import com.arjuna.ats.arjuna.logging.tsLogger;
-import com.arjuna.ats.arjuna.logging.FacilityCode;
-
-import com.arjuna.common.util.logging.*;
-
-import java.util.*;
-
-/**
- * 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.
- *
- * @author Mark Little (mark at arjuna.com)
- * @version $Id: TransactionReaper.java 2342 2006-03-30 13:06:17Z $
- * @since JTS 1.0.
- *
- *
- * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_1
- *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_1] -
- *          TransactionReaper - could not create transaction list. Out of
- *          memory.
- * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_2
- *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_2] -
- *          TransactionReaper::check - comparing {0}
- * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_3
- *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_3] -
- *          TransactionReaper::check - rollback for {0}
- * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_4
- *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_4] -
- *          TransactionReaper failed to force rollback on {0}
- * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_5
- *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_5] -
- *          TransactionReaper failed to force rollback_only on {0}
- * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_6
- *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_6] -
- *          TransactionReaper::getTimeout for {0} returning {1}
- */
-
-public class TransactionReaper
-{
-
-	public static final String NORMAL = "NORMAL";
-
-	public static final String DYNAMIC = "DYNAMIC";
-
-	public TransactionReaper(long checkPeriod)
-	{
-		if (tsLogger.arjLogger.debugAllowed())
-		{
-			tsLogger.arjLogger.debug(DebugLevel.CONSTRUCTORS,
-					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
-					"TransactionReaper::TransactionReaper ( " + checkPeriod
-							+ " )");
-		}
-
-		_checkPeriod = checkPeriod;
-
-		if (_transactions == null)
-		{
-			if (tsLogger.arjLoggerI18N.isFatalEnabled())
-			{
-				tsLogger.arjLoggerI18N
-						.fatal("com.arjuna.ats.arjuna.coordinator.TransactionReaper_1");
-			}
-
-			throw new OutOfMemoryError();
-		}
-	}
-
-	public void finalize()
-	{
-		if (tsLogger.arjLogger.debugAllowed())
-		{
-			tsLogger.arjLogger.debug(DebugLevel.DESTRUCTORS,
-					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
-					"TransactionReaper.finalize ()");
-		}
-
-		_transactions = null;
-	}
-
-	public final synchronized long checkingPeriod()
-	{
-		if (_dynamic)
-		{
-			final ReaperElement head = (ReaperElement) _transactions.first();  //_list.peak();
-			if (head != null)
-			{
-				return head._absoluteTimeout - System.currentTimeMillis();
-			}
-		}
-		return _checkPeriod;
-	}
-
-	/*
-	 * Should be no need to protect with a mutex since only one thread is ever
-	 * doing the work.
-	 */
-
-	/**
-	 * Only check for one at a time to prevent starvation.
-	 *
-	 * Timeout is given in milliseconds.
-	 */
-
-	public final boolean check()
-	{
-		if (tsLogger.arjLogger.debugAllowed())
-		{
-			tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
-					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
-					"TransactionReaper::check ()");
-		}
-
-		if (_transactions.size() == 0)
-			return true;
-
-		synchronized(_transactions) {
-			Iterator iter = _transactions.iterator();
-			while (iter.hasNext()) {
-				ReaperElement e = (ReaperElement)iter.next();
-
-				if (tsLogger.arjLoggerI18N.debugAllowed())
-				{
-					tsLogger.arjLoggerI18N
-							.debug(
-									DebugLevel.FUNCTIONS,
-									VisibilityLevel.VIS_PUBLIC,
-									FacilityCode.FAC_ATOMIC_ACTION,
-									"com.arjuna.ats.arjuna.coordinator.TransactionReaper_2",
-									new Object[]
-									{ Long.toString(e._absoluteTimeout) });
-				}
-
-			final long now = System.currentTimeMillis();
-			if (now >= e._absoluteTimeout)
-			{
-				if (e._control.running())
-				{
-					/*
-					 * If this is a local transaction, then we can roll it back
-					 * completely. Otherwise, just mark it as rollback only.
-					 */
-
-					boolean problem = false;
-
-					//if (TxControl.enableStatistics)
-					//{
-					//	TxStats.incrementTimeouts();
-					//}
-
-					try
-					{
-						if (e._control.cancel() == ActionStatus.ABORTED)
-						{
-							if (tsLogger.arjLoggerI18N.debugAllowed())
-							{
-								tsLogger.arjLoggerI18N
-										.debug(
-												DebugLevel.FUNCTIONS,
-												VisibilityLevel.VIS_PUBLIC,
-												FacilityCode.FAC_ATOMIC_ACTION,
-												"com.arjuna.ats.arjuna.coordinator.TransactionReaper_3",
-												new Object[]
-												{ e._control.get_uid() });
-							}
-						}
-						else
-							problem = true;
-					}
-					catch (Exception ex2)
-					{
-						if (tsLogger.arjLoggerI18N.isWarnEnabled())
-						{
-							tsLogger.arjLoggerI18N
-									.warn(
-											"com.arjuna.ats.arjuna.coordinator.TransactionReaper_4",
-											new Object[]
-											{ e._control });
-						}
-
-						problem = true;
-					}
-
-					if (problem)
-					{
-						boolean error = false;
-						boolean printDebug = tsLogger.arjLoggerI18N
-								.isWarnEnabled();
-
-						try
-						{
-							error = !e._control.preventCommit();
-						}
-						catch (Exception ex3)
-						{
-							error = true;
-						}
-
-						if (error || printDebug)
-						{
-							if (error)
-							{
-								if (tsLogger.arjLoggerI18N.isWarnEnabled())
-								{
-									tsLogger.arjLoggerI18N
-											.warn(
-													"com.arjuna.ats.arjuna.coordinator.TransactionReaper_5",
-													new Object[]
-													{ e._control });
-								}
-							}
-							else
-							{
-								if (tsLogger.arjLoggerI18N.debugAllowed())
-								{
-									tsLogger.arjLoggerI18N
-											.debug(
-													DebugLevel.FUNCTIONS,
-													VisibilityLevel.VIS_PUBLIC,
-													FacilityCode.FAC_ATOMIC_ACTION,
-													"com.arjuna.ats.arjuna.coordinator.TransactionReaper_3",
-													new Object[]
-													{ e._control });
-								}
-							}
-						}
-					}
-				}
-
-				iter.remove();
-			}
-			else
-			{
-				break;
-			}
-		}
-		}
-
-		return true;
-	}
-
-	/**
-	 * @return the number of items in the reaper's list.
-	 * @since JTS 2.2.
-	 */
-
-	public final long numberOfTransactions()
-	{
-		return _transactions.size();
-	}
-
-	/**
-	 * timeout is given in seconds, but we work in milliseconds.
-	 */
-
-	public final boolean insert(Reapable control, int timeout)
-	{
-		if (tsLogger.arjLogger.debugAllowed())
-		{
-			tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
-					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
-					"TransactionReaper::insert ( " + control + ", " + timeout
-							+ " )");
-		}
-
-		/*
-		 * Ignore if the timeout is zero, since this means the transaction
-		 * should never timeout.
-		 */
-
-		if (timeout == 0)
-			return true;
-
-		ReaperElement e = new ReaperElement(control, timeout);
-
-		/**
-		 * Ignore if it's already in the list with a different timeout.
-		 * (This should never happen)
-		 */
-
-		Integer oldTimeout = (Integer)_timeouts.get(control);
-		if(oldTimeout != null) {
-			ReaperElement key = new ReaperElement((Reapable)control, oldTimeout.intValue());
-			if(_transactions.contains(key)) {
-				return false;
-			}
-		}
-
-		synchronized (this)
-		{
-			TransactionReaper._lifetime += timeout;
-
-			/*
-			 * If the timeout for this transaction is less than the current
-			 * timeout for the reaper thread (or one is not set for the reaper
-			 * thread) then use that timeout and interrupt the thread to get it
-			 * to recheck.
-			 */
-
-			final long timeoutms = timeout * 1000;
-			if ((timeoutms < _checkPeriod) || (_checkPeriod == Long.MAX_VALUE))
-			{
-				_checkPeriod = timeoutms; // convert to milliseconds!
-				notify();
-			}
-		}
-
-		/*
-		 * Can release the lock because the collection is internally synchronized.
-		 */
-
-		_timeouts.put(control, new Integer(timeout));
-		return _transactions.add(e);
-	}
-
-	public final boolean remove(java.lang.Object control)
-	{
-		if (tsLogger.arjLogger.debugAllowed())
-		{
-			tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
-					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
-					"TransactionReaper::remove ( " + control + " )");
-		}
-
-		if (control == null)
-			return false;
-
-		Integer timeout = (Integer)_timeouts.get(control);
-		if(timeout == null) {
-			return false;
-		}
-		ReaperElement key = new ReaperElement((Reapable)control, timeout.intValue());
-		return _transactions.remove(key);
-	}
-
-	/**
-	 * Given a Control, return the associated timeout, or 0 if we do not know
-	 * about it.
-	 *
-	 * Return in seconds!
-	 */
-
-	public final int getTimeout(Object control)
-	{
-		if ((_transactions.size() == 0) || (control == null))
-		{
-			if (tsLogger.arjLogger.debugAllowed())
-			{
-				tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
-						VisibilityLevel.VIS_PUBLIC,
-						FacilityCode.FAC_ATOMIC_ACTION,
-						"TransactionReaper::getTimeout for " + control
-								+ " returning 0");
-			}
-
-			return 0;
-		}
-
-		Integer timeout = (Integer)_timeouts.get(control);
-
-		if(timeout == null) {
-			timeout = new Integer(0);
-		}
-
-		tsLogger.arjLoggerI18N
-				.debug(
-						DebugLevel.FUNCTIONS,
-						VisibilityLevel.VIS_PUBLIC,
-						FacilityCode.FAC_ATOMIC_ACTION,
-						"com.arjuna.ats.arjuna.coordinator.TransactionReaper_6",
-						new Object[]
-								{ control, timeout });
-
-		return timeout.intValue();
-	}
-
-	/**
-	 * Currently we let the reaper thread run at same priority as other threads.
-	 * Could get priority from environment.
-	 */
-
-	public static synchronized TransactionReaper create(long checkPeriod)
-	{
-		if (tsLogger.arjLogger.debugAllowed())
-		{
-			tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
-					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
-					"TransactionReaper::create ( " + checkPeriod + " )");
-		}
-
-		if (TransactionReaper._theReaper == null)
-		{
-			String mode = arjPropertyManager.propertyManager
-					.getProperty(Environment.TX_REAPER_MODE);
-
-			if (mode != null)
-			{
-				if (mode.compareTo(TransactionReaper.DYNAMIC) == 0)
-					TransactionReaper._dynamic = true;
-			}
-
-			if (!TransactionReaper._dynamic)
-			{
-				String timeoutEnv = arjPropertyManager.propertyManager
-						.getProperty(Environment.TX_REAPER_TIMEOUT);
-
-				if (timeoutEnv != null)
-				{
-					Long l = null;
-
-					try
-					{
-						l = new Long(timeoutEnv);
-						checkPeriod = l.longValue();
-
-						l = null;
-					}
-					catch (NumberFormatException e)
-					{
-						tsLogger.arjLogger.warn("TransactionReaper::create - "
-								+ e);
-					}
-				}
-			}
-			else
-				checkPeriod = Long.MAX_VALUE;
-
-			TransactionReaper._theReaper = new TransactionReaper(checkPeriod);
-
-			_reaperThread = new ReaperThread(TransactionReaper._theReaper);
-			// _reaperThread.setPriority(Thread.MIN_PRIORITY);
-
-			_reaperThread.setDaemon(true);
-
-			_reaperThread.start();
-		}
-
-		return TransactionReaper._theReaper;
-	}
-
-	public static TransactionReaper create()
-	{
-		return create(TransactionReaper.defaultCheckPeriod);
-	}
-
-	public static TransactionReaper transactionReaper()
-	{
-		return transactionReaper(false);
-	}
-
-	/*
-	 * If parameter is true then do a create.
-	 */
-
-	public static synchronized TransactionReaper transactionReaper(
-			boolean createReaper)
-	{
-		if (createReaper)
-			return create();
-		else
-			return _theReaper;
-	}
-
-	/*
-	 * Don't bother synchronizing as this is only an estimate anyway.
-	 */
-
-	public static final synchronized long transactionLifetime()
-	{
-		return TransactionReaper._lifetime;
-	}
-
-	public static final long defaultCheckPeriod = 120000; // in milliseconds
-
-	static final void reset()
-	{
-		_theReaper = null;
-	}
-
-	private SortedSet _transactions = Collections.synchronizedSortedSet(new TreeSet()); // C of ReaperElement
-	private Map _timeouts = Collections.synchronizedMap(new WeakHashMap()); // key = Reapable, value = Integer
-
-	private long _checkPeriod = 0;
-
-	private static TransactionReaper _theReaper = null;
-
-	private static ReaperThread _reaperThread = null;
-
-	private static boolean _dynamic = false;
-
-	private static long _lifetime = 0;
-
-}

Copied: labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java (from rev 11682, labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java)
===================================================================
--- labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java	                        (rev 0)
+++ labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java	2007-05-04 14:31:10 UTC (rev 11683)
@@ -0,0 +1,532 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 1998, 1999, 2000, 2001,
+ *
+ * Arjuna Solutions Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: TransactionReaper.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.arjuna.ats.arjuna.coordinator;
+
+import com.arjuna.ats.arjuna.common.Environment;
+import com.arjuna.ats.arjuna.common.arjPropertyManager;
+import com.arjuna.ats.arjuna.coordinator.Reapable;
+import com.arjuna.ats.arjuna.coordinator.ActionStatus;
+
+import com.arjuna.ats.internal.arjuna.coordinator.*;
+
+import com.arjuna.ats.arjuna.logging.tsLogger;
+import com.arjuna.ats.arjuna.logging.FacilityCode;
+
+import com.arjuna.common.util.logging.*;
+
+import java.util.*;
+
+/**
+ * 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.
+ *
+ * @author Mark Little (mark at arjuna.com)
+ * @version $Id: TransactionReaper.java 2342 2006-03-30 13:06:17Z $
+ * @since JTS 1.0.
+ *
+ *
+ * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_1
+ *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_1] -
+ *          TransactionReaper - could not create transaction list. Out of
+ *          memory.
+ * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_2
+ *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_2] -
+ *          TransactionReaper::check - comparing {0}
+ * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_3
+ *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_3] -
+ *          TransactionReaper::check - rollback for {0}
+ * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_4
+ *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_4] -
+ *          TransactionReaper failed to force rollback on {0}
+ * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_5
+ *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_5] -
+ *          TransactionReaper failed to force rollback_only on {0}
+ * @message com.arjuna.ats.arjuna.coordinator.TransactionReaper_6
+ *          [com.arjuna.ats.arjuna.coordinator.TransactionReaper_6] -
+ *          TransactionReaper::getTimeout for {0} returning {1}
+ */
+
+public class TransactionReaper
+{
+
+	public static final String NORMAL = "NORMAL";
+
+	public static final String DYNAMIC = "DYNAMIC";
+
+	public TransactionReaper(long checkPeriod)
+	{
+		if (tsLogger.arjLogger.debugAllowed())
+		{
+			tsLogger.arjLogger.debug(DebugLevel.CONSTRUCTORS,
+					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
+					"TransactionReaper::TransactionReaper ( " + checkPeriod
+							+ " )");
+		}
+
+		_checkPeriod = checkPeriod;
+
+		if (_transactions == null)
+		{
+			if (tsLogger.arjLoggerI18N.isFatalEnabled())
+			{
+				tsLogger.arjLoggerI18N
+						.fatal("com.arjuna.ats.arjuna.coordinator.TransactionReaper_1");
+			}
+
+			throw new OutOfMemoryError();
+		}
+	}
+
+	public void finalize()
+	{
+		if (tsLogger.arjLogger.debugAllowed())
+		{
+			tsLogger.arjLogger.debug(DebugLevel.DESTRUCTORS,
+					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
+					"TransactionReaper.finalize ()");
+		}
+
+		_transactions = null;
+	}
+
+	public final synchronized long checkingPeriod()
+	{
+		if (_dynamic)
+		{
+                    try
+                    {
+			final ReaperElement head = (ReaperElement) _transactions.first();  //_list.peak();
+			return head._absoluteTimeout - System.currentTimeMillis();
+                    }
+                    catch (final NoSuchElementException nsee) {} // fall through
+		}
+		return _checkPeriod;
+	}
+
+	/*
+	 * Should be no need to protect with a mutex since only one thread is ever
+	 * doing the work.
+	 */
+
+	/**
+	 * Only check for one at a time to prevent starvation.
+	 *
+	 * Timeout is given in milliseconds.
+	 */
+
+	public final boolean check()
+	{
+		if (tsLogger.arjLogger.debugAllowed())
+		{
+			tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
+					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
+					"TransactionReaper::check ()");
+		}
+
+		do {
+			final ReaperElement e ;
+                        try
+                        {
+                            e = (ReaperElement)_transactions.first();
+                        }
+                        catch (final NoSuchElementException nsee)
+                        {
+                            return true ;
+                        }
+
+			if (tsLogger.arjLoggerI18N.debugAllowed())
+			{
+				tsLogger.arjLoggerI18N
+						.debug(
+								DebugLevel.FUNCTIONS,
+								VisibilityLevel.VIS_PUBLIC,
+								FacilityCode.FAC_ATOMIC_ACTION,
+								"com.arjuna.ats.arjuna.coordinator.TransactionReaper_2",
+								new Object[]
+								{ Long.toString(e._absoluteTimeout) });
+			}
+
+			final long now = System.currentTimeMillis();
+			if (now >= e._absoluteTimeout)
+			{
+				if (e._control.running())
+				{
+					/*
+					 * If this is a local transaction, then we can roll it back
+					 * completely. Otherwise, just mark it as rollback only.
+					 */
+
+					boolean problem = false;
+
+					//if (TxControl.enableStatistics)
+					//{
+					//	TxStats.incrementTimeouts();
+					//}
+
+					try
+					{
+						if (e._control.cancel() == ActionStatus.ABORTED)
+						{
+							if (tsLogger.arjLoggerI18N.debugAllowed())
+							{
+								tsLogger.arjLoggerI18N
+										.debug(
+												DebugLevel.FUNCTIONS,
+												VisibilityLevel.VIS_PUBLIC,
+												FacilityCode.FAC_ATOMIC_ACTION,
+												"com.arjuna.ats.arjuna.coordinator.TransactionReaper_3",
+												new Object[]
+												{ e._control.get_uid() });
+							}
+						}
+						else
+							problem = true;
+					}
+					catch (Exception ex2)
+					{
+						if (tsLogger.arjLoggerI18N.isWarnEnabled())
+						{
+							tsLogger.arjLoggerI18N
+									.warn(
+											"com.arjuna.ats.arjuna.coordinator.TransactionReaper_4",
+											new Object[]
+											{ e._control });
+						}
+
+						problem = true;
+					}
+
+					if (problem)
+					{
+						boolean error = false;
+						boolean printDebug = tsLogger.arjLoggerI18N
+								.isWarnEnabled();
+
+						try
+						{
+							error = !e._control.preventCommit();
+						}
+						catch (Exception ex3)
+						{
+							error = true;
+						}
+
+						if (error || printDebug)
+						{
+							if (error)
+							{
+								if (tsLogger.arjLoggerI18N.isWarnEnabled())
+								{
+									tsLogger.arjLoggerI18N
+											.warn(
+													"com.arjuna.ats.arjuna.coordinator.TransactionReaper_5",
+													new Object[]
+													{ e._control });
+								}
+							}
+							else
+							{
+								if (tsLogger.arjLoggerI18N.debugAllowed())
+								{
+									tsLogger.arjLoggerI18N
+											.debug(
+													DebugLevel.FUNCTIONS,
+													VisibilityLevel.VIS_PUBLIC,
+													FacilityCode.FAC_ATOMIC_ACTION,
+													"com.arjuna.ats.arjuna.coordinator.TransactionReaper_3",
+													new Object[]
+													{ e._control });
+								}
+							}
+						}
+					}
+				}
+
+				_transactions.remove(e) ;
+			}
+			else
+			{
+				break;
+			}
+		} while(true) ;
+
+		return true;
+	}
+
+	/**
+	 * @return the number of items in the reaper's list.
+	 * @since JTS 2.2.
+	 */
+
+	public final long numberOfTransactions()
+	{
+		return _transactions.size();
+	}
+
+	/**
+	 * timeout is given in seconds, but we work in milliseconds.
+	 */
+
+	public final boolean insert(Reapable control, int timeout)
+	{
+		if (tsLogger.arjLogger.debugAllowed())
+		{
+			tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
+					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
+					"TransactionReaper::insert ( " + control + ", " + timeout
+							+ " )");
+		}
+
+		/*
+		 * Ignore if the timeout is zero, since this means the transaction
+		 * should never timeout.
+		 */
+
+		if (timeout == 0)
+			return true;
+
+		ReaperElement e = new ReaperElement(control, timeout);
+
+		/**
+		 * Ignore if it's already in the list with a different timeout.
+		 * (This should never happen)
+		 */
+		if(_transactions.contains(e)) {
+			return false;
+		}
+
+		synchronized (this)
+		{
+			TransactionReaper._lifetime += timeout;
+
+			/*
+			 * If the timeout for this transaction is less than the current
+			 * timeout for the reaper thread (or one is not set for the reaper
+			 * thread) then use that timeout and interrupt the thread to get it
+			 * to recheck.
+			 */
+
+			final long timeoutms = timeout * 1000;
+			if ((timeoutms < _checkPeriod) || (_checkPeriod == Long.MAX_VALUE))
+			{
+				_checkPeriod = timeoutms; // convert to milliseconds!
+				notify();
+			}
+		}
+
+		/*
+		 * Can release the lock because the collection is internally synchronized.
+		 */
+
+		_timeouts.put(control, new Integer(timeout));
+		return _transactions.add(e);
+	}
+
+	public final boolean remove(java.lang.Object control)
+	{
+		if (tsLogger.arjLogger.debugAllowed())
+		{
+			tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
+					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
+					"TransactionReaper::remove ( " + control + " )");
+		}
+
+		if (control == null)
+			return false;
+
+		Integer timeout = (Integer)_timeouts.get(control);
+		if(timeout == null) {
+			return false;
+		}
+		ReaperElement key = new ReaperElement((Reapable)control, timeout.intValue());
+		return _transactions.remove(key);
+	}
+
+	/**
+	 * Given a Control, return the associated timeout, or 0 if we do not know
+	 * about it.
+	 *
+	 * Return in seconds!
+	 */
+
+	public final int getTimeout(Object control)
+	{
+		if ((_transactions.size() == 0) || (control == null))
+		{
+			if (tsLogger.arjLogger.debugAllowed())
+			{
+				tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
+						VisibilityLevel.VIS_PUBLIC,
+						FacilityCode.FAC_ATOMIC_ACTION,
+						"TransactionReaper::getTimeout for " + control
+								+ " returning 0");
+			}
+
+			return 0;
+		}
+
+		Integer timeout = (Integer)_timeouts.get(control);
+
+		if(timeout == null) {
+			timeout = new Integer(0);
+		}
+
+		tsLogger.arjLoggerI18N
+				.debug(
+						DebugLevel.FUNCTIONS,
+						VisibilityLevel.VIS_PUBLIC,
+						FacilityCode.FAC_ATOMIC_ACTION,
+						"com.arjuna.ats.arjuna.coordinator.TransactionReaper_6",
+						new Object[]
+								{ control, timeout });
+
+		return timeout.intValue();
+	}
+
+	/**
+	 * Currently we let the reaper thread run at same priority as other threads.
+	 * Could get priority from environment.
+	 */
+
+	public static synchronized TransactionReaper create(long checkPeriod)
+	{
+		if (tsLogger.arjLogger.debugAllowed())
+		{
+			tsLogger.arjLogger.debug(DebugLevel.FUNCTIONS,
+					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
+					"TransactionReaper::create ( " + checkPeriod + " )");
+		}
+
+		if (TransactionReaper._theReaper == null)
+		{
+			String mode = arjPropertyManager.propertyManager
+					.getProperty(Environment.TX_REAPER_MODE);
+
+			if (mode != null)
+			{
+				if (mode.compareTo(TransactionReaper.DYNAMIC) == 0)
+					TransactionReaper._dynamic = true;
+			}
+
+			if (!TransactionReaper._dynamic)
+			{
+				String timeoutEnv = arjPropertyManager.propertyManager
+						.getProperty(Environment.TX_REAPER_TIMEOUT);
+
+				if (timeoutEnv != null)
+				{
+					Long l = null;
+
+					try
+					{
+						l = new Long(timeoutEnv);
+						checkPeriod = l.longValue();
+
+						l = null;
+					}
+					catch (NumberFormatException e)
+					{
+						tsLogger.arjLogger.warn("TransactionReaper::create - "
+								+ e);
+					}
+				}
+			}
+			else
+				checkPeriod = Long.MAX_VALUE;
+
+			TransactionReaper._theReaper = new TransactionReaper(checkPeriod);
+
+			_reaperThread = new ReaperThread(TransactionReaper._theReaper);
+			// _reaperThread.setPriority(Thread.MIN_PRIORITY);
+
+			_reaperThread.setDaemon(true);
+
+			_reaperThread.start();
+		}
+
+		return TransactionReaper._theReaper;
+	}
+
+	public static TransactionReaper create()
+	{
+		return create(TransactionReaper.defaultCheckPeriod);
+	}
+
+	public static TransactionReaper transactionReaper()
+	{
+		return transactionReaper(false);
+	}
+
+	/*
+	 * If parameter is true then do a create.
+	 */
+
+	public static synchronized TransactionReaper transactionReaper(
+			boolean createReaper)
+	{
+		if (createReaper)
+			return create();
+		else
+			return _theReaper;
+	}
+
+	/*
+	 * Don't bother synchronizing as this is only an estimate anyway.
+	 */
+
+	public static final synchronized long transactionLifetime()
+	{
+		return TransactionReaper._lifetime;
+	}
+
+	public static final long defaultCheckPeriod = 120000; // in milliseconds
+
+	static final void reset()
+	{
+		_theReaper = null;
+	}
+
+	private SortedSet _transactions = Collections.synchronizedSortedSet(new TreeSet()); // C of ReaperElement
+	private Map _timeouts = Collections.synchronizedMap(new WeakHashMap()); // key = Reapable, value = Integer
+
+	private long _checkPeriod = 0;
+
+	private static TransactionReaper _theReaper = null;
+
+	private static ReaperThread _reaperThread = null;
+
+	private static boolean _dynamic = false;
+
+	private static long _lifetime = 0;
+
+}

Deleted: labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java	2007-05-04 12:06:33 UTC (rev 11677)
+++ labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java	2007-05-04 14:31:10 UTC (rev 11683)
@@ -1,127 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- *
- * (C) 2005-2006,
- * @author JBoss Inc.
- */
-/*
- * Copyright (C) 1998, 1999, 2000, 2001,
- *
- * Arjuna Solutions Limited,
- * Newcastle upon Tyne,
- * Tyne and Wear,
- * UK.
- *
- * $Id: ReaperElement.java 2342 2006-03-30 13:06:17Z  $
- */
-
-package com.arjuna.ats.internal.arjuna.coordinator;
-
-import com.arjuna.common.util.logging.*;
-
-import com.arjuna.ats.arjuna.logging.tsLogger;
-import com.arjuna.ats.arjuna.coordinator.Reapable;
-import com.arjuna.ats.arjuna.logging.FacilityCode;
-
-import com.arjuna.ats.internal.arjuna.template.OrderedListElement;
-
-public class ReaperElement implements Comparable
-{
-
-	/*
-	 * Currently, once created the reaper object and thread stay around forever.
-	 * We could destroy both once the list of transactions is null. Depends upon
-	 * the relative cost of recreating them over keeping them around.
-	 */
-
-	public ReaperElement(Reapable control, int timeout)
-	{
-		if (tsLogger.arjLogger.debugAllowed())
-		{
-			tsLogger.arjLogger.debug(DebugLevel.CONSTRUCTORS,
-					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
-					"ReaperElement::ReaperElement ( " + control + ", "
-							+ timeout + " )");
-		}
-
-		_control = control;
-		_timeout = timeout;
-
-		/*
-		 * Given a timeout period in seconds, calculate its absolute value from
-		 * the current time of day in milliseconds.
-		 */
-
-		_absoluteTimeout = timeout * 1000 + System.currentTimeMillis();
-	}
-
-	public void finalize()
-	{
-		if (tsLogger.arjLogger.debugAllowed())
-		{
-			tsLogger.arjLogger.debug(DebugLevel.DESTRUCTORS,
-					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
-					"ReaperElement.finalize ()");
-		}
-
-		_control = null;
-	}
-
-
-	public boolean equals(Object obj)
-	{
-		return (this.compareTo(obj) == 0 ? true : false);
-	}
-
-	public int hashCode()
-	{
-		int hashCode = _control.get_uid().hashCode();
-		hashCode ^= _absoluteTimeout;
-		return hashCode;
-	}
-
-	/**
-	 * Order by absoluteTimeout first, then by Uid.
-	 * This is required so that the set maintained by the TransactionReaper
-	 * is in timeout order for efficient processing.
-	 *
-	 * @param o
-	 * @return
-	 */
-	public int compareTo(Object o)
-	{
-		ReaperElement other = (ReaperElement)o;
-
-		if(_absoluteTimeout == other._absoluteTimeout) {
-			if(_control.get_uid().equals(other._control.get_uid())) {
-				return 0;
-			} else if (_control.get_uid().greaterThan(other._control.get_uid())) {
-				return 1;
-			} else {
-				return -1;
-			}
-		} else {
-			return (_absoluteTimeout > other._absoluteTimeout) ? 1 : -1;
-		}
-	}
-
-	public Reapable _control;
-
-	public long _absoluteTimeout;
-
-	public int _timeout;
-}

Copied: labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java (from rev 11682, labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java)
===================================================================
--- labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java	                        (rev 0)
+++ labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java	2007-05-04 14:31:10 UTC (rev 11683)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 1998, 1999, 2000, 2001,
+ *
+ * Arjuna Solutions Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: ReaperElement.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.arjuna.ats.internal.arjuna.coordinator;
+
+import com.arjuna.common.util.logging.*;
+
+import com.arjuna.ats.arjuna.logging.tsLogger;
+import com.arjuna.ats.arjuna.coordinator.Reapable;
+import com.arjuna.ats.arjuna.logging.FacilityCode;
+
+public class ReaperElement implements Comparable
+{
+
+	/*
+	 * Currently, once created the reaper object and thread stay around forever.
+	 * We could destroy both once the list of transactions is null. Depends upon
+	 * the relative cost of recreating them over keeping them around.
+	 */
+
+	public ReaperElement(Reapable control, int timeout)
+	{
+		if (tsLogger.arjLogger.debugAllowed())
+		{
+			tsLogger.arjLogger.debug(DebugLevel.CONSTRUCTORS,
+					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
+					"ReaperElement::ReaperElement ( " + control + ", "
+							+ timeout + " )");
+		}
+
+		_control = control;
+		_timeout = timeout;
+
+		/*
+		 * Given a timeout period in seconds, calculate its absolute value from
+		 * the current time of day in milliseconds.
+		 */
+
+		_absoluteTimeout = timeout * 1000 + System.currentTimeMillis();
+	}
+
+	public void finalize()
+	{
+		if (tsLogger.arjLogger.debugAllowed())
+		{
+			tsLogger.arjLogger.debug(DebugLevel.DESTRUCTORS,
+					VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_ATOMIC_ACTION,
+					"ReaperElement.finalize ()");
+		}
+
+		_control = null;
+	}
+
+
+	public boolean equals(Object obj)
+	{
+		return (compareTo(obj) == 0);
+	}
+
+	public int hashCode()
+	{
+		int hashCode = _control.get_uid().hashCode();
+		hashCode ^= _absoluteTimeout;
+		return hashCode;
+	}
+
+	/**
+	 * Order by absoluteTimeout first, then by Uid.
+	 * This is required so that the set maintained by the TransactionReaper
+	 * is in timeout order for efficient processing.
+	 *
+	 * @param o
+	 * @return
+	 */
+	public int compareTo(Object o)
+	{
+		ReaperElement other = (ReaperElement)o;
+
+                if(_control.get_uid().equals(other._control.get_uid())) {
+                        return 0;
+                } else if(_absoluteTimeout == other._absoluteTimeout) {
+			return (_control.get_uid().greaterThan(other._control.get_uid()) ? 1 : -1) ;
+		} else {
+			return (_absoluteTimeout > other._absoluteTimeout) ? 1 : -1;
+		}
+	}
+
+	public Reapable _control;
+
+	public long _absoluteTimeout;
+
+	public int _timeout;
+}

Deleted: labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperTestCase.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperTestCase.java	2007-05-04 12:06:33 UTC (rev 11677)
+++ labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperTestCase.java	2007-05-04 14:31:10 UTC (rev 11683)
@@ -1,132 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- *
- * (C) 2007,
- * @author JBoss, a division of Red Hat.
- */
-package com.hp.mwtests.ts.arjuna.reaper;
-
-import junit.framework.TestCase;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import com.arjuna.ats.arjuna.coordinator.TransactionReaper;
-import com.arjuna.ats.arjuna.coordinator.Reapable;
-import com.arjuna.ats.arjuna.common.Uid;
-import com.arjuna.ats.internal.arjuna.coordinator.ReaperElement;
-
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-/**
- * Exercises some aspects of the TransactionReaper functionality.
- * @author jonathan.halliday at redhat.com, 2007-04-30
- */
-public class ReaperTestCase extends TestCase
-{
-	public static Test suite() {
-		return new TestSuite(ReaperTestCase.class);
-	}
-
-	public void testReaper() throws Exception {
-
-		// test set+readback of interval
-		TransactionReaper.create(100);
-		TransactionReaper reaper = TransactionReaper.transactionReaper();
-		assertTrue(reaper.checkingPeriod() == 100);
-
-
-		Reapable reapable = new MockReapable(new Uid());
-		Reapable reapable2 = new MockReapable(new Uid());
-		Reapable reapable3 = new MockReapable(new Uid());
-
-		ReaperElement reaperElement = new ReaperElement(reapable, 30);
-		ReaperElement reaperElement2 = new ReaperElement(reapable2, 20);
-		ReaperElement reaperElement3 = new ReaperElement(reapable3, 10);
-
-		// test that ordering is by timeout, regardless of insertion order
-		SortedSet sortedSet = new TreeSet();
-		sortedSet.add(reaperElement);
-		sortedSet.add(reaperElement3);
-		sortedSet.add(reaperElement2);
-
-		assertTrue(sortedSet.first() == reaperElement3);
-		assertTrue(sortedSet.last() == reaperElement);
-
-		// test insertion of timeout=0 is a nullop
-		assertTrue(reaper.insert(reapable, 0));
-		assertTrue(reaper.numberOfTransactions() == 0);
-		assertFalse(reaper.remove(reapable));
-
-		// test that duplicate insertion fails
-		assertTrue(reaper.insert(reapable, 10));
-		assertFalse(reaper.insert(reapable, 10));
-		assertTrue(reaper.numberOfTransactions() == 1);
-		assertTrue(reaper.remove(reapable));
-		assertTrue(reaper.numberOfTransactions() == 0);
-
-		// test that timeout change fails
-		assertTrue(reaper.insert(reapable, 10));
-		assertFalse(reaper.insert(reapable, 20));
-		assertTrue(reaper.numberOfTransactions() == 1);
-		assertTrue(reaper.getTimeout(reapable) == 10);
-		assertTrue(reaper.remove(reapable));
-		assertTrue(reaper.numberOfTransactions() == 0);
-
-		// test reaping
-		reaper.insert(reapable, 1); // seconds
-		reaper.insert(reapable2, 5);
-		assertTrue(reaper.numberOfTransactions() == 2);
-		reaper.check();
-		assertTrue(reaper.numberOfTransactions() == 2);
-		Thread.sleep(2*1000);
-		reaper.check();
-		assertTrue(reaper.numberOfTransactions() == 1);
-		Thread.sleep(4*1000);
-		reaper.check();
-		assertTrue(reaper.numberOfTransactions() == 0);
-
-	}
-
-	public class MockReapable implements Reapable
-	{
-		public MockReapable(Uid uid) {
-			this.uid = uid;
-		}
-
-		public boolean running()
-		{
-			return false;  //To change body of implemented methods use File | Settings | File Templates.
-		}
-
-		public boolean preventCommit()
-		{
-			return false;  //To change body of implemented methods use File | Settings | File Templates.
-		}
-
-		public int cancel()
-		{
-			return 0;  //To change body of implemented methods use File | Settings | File Templates.
-		}
-
-		public Uid get_uid()
-		{
-			return uid;
-		}
-
-		private Uid uid;
-	}
-}

Copied: labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperTestCase.java (from rev 11682, labs/jbosstm/branches/JBOSSTS_4_2_3_GA_SP/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperTestCase.java)
===================================================================
--- labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperTestCase.java	                        (rev 0)
+++ labs/jbosstm/tags/JBOSSTS_4_2_3_SP3/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperTestCase.java	2007-05-04 14:31:10 UTC (rev 11683)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2007,
+ * @author JBoss, a division of Red Hat.
+ */
+package com.hp.mwtests.ts.arjuna.reaper;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import com.arjuna.ats.arjuna.coordinator.TransactionReaper;
+import com.arjuna.ats.arjuna.coordinator.Reapable;
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.internal.arjuna.coordinator.ReaperElement;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * Exercises some aspects of the TransactionReaper functionality.
+ * @author jonathan.halliday at redhat.com, 2007-04-30
+ */
+public class ReaperTestCase extends TestCase
+{
+	public static Test suite() {
+		return new TestSuite(ReaperTestCase.class);
+	}
+
+	public void testReaper() throws Exception {
+
+		// test set+readback of interval
+		TransactionReaper.create(100);
+		TransactionReaper reaper = TransactionReaper.transactionReaper();
+		assertEquals(100, reaper.checkingPeriod());
+
+
+		Reapable reapable = new MockReapable(new Uid());
+		Reapable reapable2 = new MockReapable(new Uid());
+		Reapable reapable3 = new MockReapable(new Uid());
+
+		ReaperElement reaperElement = new ReaperElement(reapable, 30);
+		ReaperElement reaperElement2 = new ReaperElement(reapable2, 20);
+		ReaperElement reaperElement3 = new ReaperElement(reapable3, 10);
+
+		// test that ordering is by timeout, regardless of insertion order
+		SortedSet sortedSet = new TreeSet();
+		sortedSet.add(reaperElement);
+		sortedSet.add(reaperElement3);
+		sortedSet.add(reaperElement2);
+
+		assertTrue(sortedSet.first() == reaperElement3);
+		assertTrue(sortedSet.last() == reaperElement);
+
+		// test insertion of timeout=0 is a nullop
+		assertTrue(reaper.insert(reapable, 0));
+		assertTrue(reaper.numberOfTransactions() == 0);
+		assertFalse(reaper.remove(reapable));
+
+		// test that duplicate insertion fails
+		assertTrue(reaper.insert(reapable, 10));
+		assertFalse(reaper.insert(reapable, 10));
+		assertEquals(1, reaper.numberOfTransactions());
+		assertTrue(reaper.remove(reapable));
+		assertEquals(0, reaper.numberOfTransactions());
+
+		// test that timeout change fails
+		assertTrue(reaper.insert(reapable, 10));
+		assertFalse(reaper.insert(reapable, 20));
+		assertEquals(1, reaper.numberOfTransactions());
+                assertEquals(10, reaper.getTimeout(reapable));
+		assertTrue(reaper.remove(reapable));
+                assertEquals(0, reaper.numberOfTransactions());
+
+		// test reaping
+		reaper.insert(reapable, 1); // seconds
+		reaper.insert(reapable2, 5);
+                assertEquals(2, reaper.numberOfTransactions());
+		reaper.check();
+                assertEquals(2, reaper.numberOfTransactions());
+		Thread.sleep(2*1000);
+		reaper.check();
+                assertEquals(1, reaper.numberOfTransactions());
+		Thread.sleep(4*1000);
+		reaper.check();
+                assertEquals(0, reaper.numberOfTransactions());
+
+	}
+
+	public class MockReapable implements Reapable
+	{
+		public MockReapable(Uid uid) {
+			this.uid = uid;
+		}
+
+		public boolean running()
+		{
+			return false;  //To change body of implemented methods use File | Settings | File Templates.
+		}
+
+		public boolean preventCommit()
+		{
+			return false;  //To change body of implemented methods use File | Settings | File Templates.
+		}
+
+		public int cancel()
+		{
+			return 0;  //To change body of implemented methods use File | Settings | File Templates.
+		}
+
+		public Uid get_uid()
+		{
+			return uid;
+		}
+
+		private Uid uid;
+	}
+}




More information about the jboss-svn-commits mailing list