[jboss-svn-commits] JBL Code SVN: r27588 - in labs/jbosstm/trunk/ArjunaCore: arjuna/classes/com/arjuna/ats/arjuna/coordinator/listener and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jul 5 14:54:42 EDT 2009


Author: mark.little at jboss.com
Date: 2009-07-05 14:54:42 -0400 (Sun, 05 Jul 2009)
New Revision: 27588

Added:
   labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/listener/
   labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/listener/ReaperMonitor.java
   labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperMonitorTest.java
Modified:
   labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java
   labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java
   labs/jbosstm/trunk/ArjunaCore/docs/user_guide/ProgrammersGuide.odt
Log:
https://jira.jboss.org/jira/browse/JBTM-484

Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java	2009-07-05 18:09:11 UTC (rev 27587)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java	2009-07-05 18:54:42 UTC (rev 27588)
@@ -35,6 +35,7 @@
 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.arjuna.coordinator.listener.ReaperMonitor;
 
 import com.arjuna.ats.internal.arjuna.coordinator.*;
 
@@ -205,6 +206,8 @@
 					 "TransactionReaper::check ()");
 	    }
 
+	    System.err.println("**checking");
+	    
 	    do
 	    {
 		final ReaperElement e ;
@@ -230,6 +233,7 @@
 		}
 
 		final long now = System.currentTimeMillis();
+
 		if (now < e._absoluteTimeout)
 		{
 		    // go back to sleep
@@ -442,6 +446,8 @@
 					    "com.arjuna.ats.arjuna.coordinator.TransactionReaper_10",
 					    new Object[]{e._control.get_uid()});
 				}
+				
+				notifyListeners(e._control, false);
 			    }
 			    else
 			    {
@@ -556,21 +562,23 @@
 
 		try
 		{
-            if (e._control.running()) {
+		    if (e._control.running()) {
 
-                // try to cancel the transaction
+		        // try to cancel the transaction
 
-                if (e._control.cancel() == ActionStatus.ABORTED)
-                {
-                    cancelled = true;
+		        if (e._control.cancel() == ActionStatus.ABORTED)
+		        {
+		            cancelled = true;
 
-                    if (TxControl.enableStatistics) {
-                        // note that we also count timeouts as application rollbacks via
-                        // the stats unpdate in the TwoPhaseCoordinator cancel() method.
-                        TxStats.incrementTimeouts();
-                    }
-                }
-            }
+		            if (TxControl.enableStatistics) {
+		                // note that we also count timeouts as application rollbacks via
+		                // the stats unpdate in the TwoPhaseCoordinator cancel() method.
+		                TxStats.incrementTimeouts();
+		            }
+
+		            notifyListeners(e._control, true);
+		        }
+		    }
 		}
 		catch (Exception e1)
 		{
@@ -689,6 +697,8 @@
 					new Object[]{Thread.currentThread(),
 						     e._control.get_uid()});
 			    }
+			    
+	                    notifyListeners(e._control, false);
 			}
 			else
 			{
@@ -746,6 +756,16 @@
                 return _timeouts.size();
         }
 
+        public final void addListener (ReaperMonitor listener)
+        {
+            _listeners.add(listener);
+        }
+        
+        public final boolean removeListener (ReaperMonitor listener)
+        {
+            return _listeners.remove(listener);
+        }
+        
 	/**
 	 * timeout is given in seconds, but we work in milliseconds.
 	 */
@@ -1049,6 +1069,26 @@
         }
 	}
 
+	private final void notifyListeners (Reapable element, boolean rollback)
+	{
+	    // notify listeners. Ignore errors.
+
+	    for (int i = 0; i < _listeners.size(); i++)
+	    {
+	        try
+	        {
+	            if (rollback)
+	                _listeners.get(i).rolledBack(element.get_uid());
+	            else
+	                _listeners.get(i).markedRollbackOnly(element.get_uid());
+	        }
+	        catch (final Throwable ex)
+	        {
+	            // ignore
+	        }
+	    }
+	}
+	
 	/**
 	 * Currently we let the reaper thread run at same priority as other threads.
 	 * Could get priority from environment.
@@ -1291,6 +1331,8 @@
 	private Map _timeouts = Collections.synchronizedMap(new HashMap()); // key = Reapable, value = ReaperElement
 
 	private List _workQueue = new LinkedList(); // C of ReaperElement
+	
+	private Vector<ReaperMonitor> _listeners = new Vector<ReaperMonitor>();
 
 	private long _checkPeriod = 0;
 

Added: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/listener/ReaperMonitor.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/listener/ReaperMonitor.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/listener/ReaperMonitor.java	2009-07-05 18:54:42 UTC (rev 27588)
@@ -0,0 +1,62 @@
+/*
+ * 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) 2000, 2001,
+ *
+ * Arjuna Solutions Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.  
+ *
+ * $Id: TxStats.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.arjuna.ats.arjuna.coordinator.listener;
+
+import com.arjuna.ats.arjuna.common.Uid;
+
+/**
+ * An instance of this interface will be called whenever a transaction is either timed-out
+ * or set rollback-only by the transaction reaper.
+ * 
+ * @author marklittle
+ */
+
+public interface ReaperMonitor
+{
+    /**
+     * The indicated transaction has been rolled back by the reaper.
+     * 
+     * @param txId the transaction id.
+     */
+    
+    public void rolledBack (Uid txId);
+    
+    /**
+     * The indicated transaction has been marked as rollback-only by the reaper.
+     * 
+     * @param txId the transaction id.
+     */
+    
+    public void markedRollbackOnly (Uid txId);
+    
+    // TODO notify of errors?
+}

Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java	2009-07-05 18:09:11 UTC (rev 27587)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java	2009-07-05 18:54:42 UTC (rev 27588)
@@ -68,6 +68,11 @@
 
 		_absoluteTimeout = timeout * 1000 + System.currentTimeMillis();
 	}
+	
+	public String toString ()
+	{
+	    return "ReaperElement < "+_control+", "+_timeout+", "+statusName()+", "+_worker+" >";
+	}
 
 	/**
 	 * Order by absoluteTimeout first, then by Uid.

Added: labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperMonitorTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperMonitorTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/reaper/ReaperMonitorTest.java	2009-07-05 18:54:42 UTC (rev 27588)
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+package com.hp.mwtests.ts.arjuna.reaper;
+
+import com.arjuna.ats.arjuna.AtomicAction;
+
+import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.TransactionReaper;
+import com.arjuna.ats.arjuna.coordinator.listener.ReaperMonitor;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class ReaperMonitorTest
+{
+    class DummyMonitor implements ReaperMonitor
+    {
+        public void rolledBack (Uid txId)
+        {
+            success = true;
+        }
+        
+        public void markedRollbackOnly (Uid txId)
+        {
+            success = false;
+        }
+        
+        public boolean success = false;
+    }
+    
+    @Test
+    public void test()
+    {
+        TransactionReaper.create(100);
+        TransactionReaper reaper = TransactionReaper.transactionReaper();
+        DummyMonitor listener = new DummyMonitor();
+       
+        reaper.addListener(listener);
+        
+        AtomicAction A = new AtomicAction();
+
+        A.begin();
+
+        reaper.insert(A, 1);
+        
+        try
+        {
+            Thread.sleep(1100);
+        }
+        catch (final Throwable ex)
+        {  
+        }
+
+        reaper.check();
+        
+        try
+        {
+            Thread.sleep(500);
+        }
+        catch (final Throwable ex)
+        {  
+        }
+        
+        reaper.check();
+        
+        assertTrue(listener.success);
+    }
+
+    public static boolean success = false;
+}

Modified: labs/jbosstm/trunk/ArjunaCore/docs/user_guide/ProgrammersGuide.odt
===================================================================
(Binary files differ)




More information about the jboss-svn-commits mailing list