[jboss-svn-commits] JBL Code SVN: r24830 - in labs/jbosstm/trunk/ArjunaCore/arjuna: classes/com/arjuna/ats/internal/arjuna/recovery and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jan 20 11:22:42 EST 2009


Author: mark.little at jboss.com
Date: 2009-01-20 11:22:42 -0500 (Tue, 20 Jan 2009)
New Revision: 24830

Added:
   labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/recovery/RecoveryLifecycleTest.java
Modified:
   labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/recovery/RecoveryManager.java
   labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/recovery/Listener.java
Log:
https://jira.jboss.org/jira/browse/JBTM-468

Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/recovery/RecoveryManager.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/recovery/RecoveryManager.java	2009-01-20 16:18:50 UTC (rev 24829)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/recovery/RecoveryManager.java	2009-01-20 16:22:42 UTC (rev 24830)
@@ -65,10 +65,13 @@
 
     public void run ()
     {
-	_theImple.scan();
+        if (_theImple != null)
+        {
+            _theImple.scan();
 
-	if (_callback != null)
-	    _callback.completed();
+            if (_callback != null)
+                _callback.completed();
+        }
     }
 
     private RecoveryManagerImple _theImple;
@@ -150,11 +153,15 @@
     /**
      * Force a recovery scan now. This is a blocking operation
      * and will only return once the recovery scan has completed.
+     * 
+     * @throws IllegalStateException if the recovery manager has been shutdown.
      */
 
     public final void scan ()
     {
-	_theImple.scan();
+        checkState();
+        
+        _theImple.scan();
     }
 
     /**
@@ -165,17 +172,25 @@
      * @param callback callback The callback mechanism used to
      * inform users that the scan has completed. If this is <code>null</code>
      * then no callback will happen and asynchronous scanning will occur.
+     * 
+     * @throws IllegalStateException if the recovery manager has been shutdown.
      */
 
     public final void scan (RecoveryScan callback)
     {
+        checkState();
+        
 	ScanThread st = new ScanThread(_theImple, callback);
 
 	st.start();
     }
 
     /**
-     * Stop the periodic recovery manager waiting for any recovery scan in progress to complete
+     * Stop the periodic recovery manager waiting for any recovery scan in progress to complete.
+     * 
+     * @throws IllegalStateException if the recovery manager has been shutdown.
+     * 
+     * @deprecated use terminate instead.
      */
 
     public final void stop ()
@@ -185,19 +200,75 @@
 
     /**
      * Stop the periodic recovery manager.
-     * @param async false means wait for any recovery scan in progress to complete
+     * @param async false means wait for any recovery scan in progress to complete.
+     * @throws IllegalStateException if the recovery manager has been shutdown.
+     * 
+     * @deprecated use terminate instead.
      */
 
     public final void stop (boolean async)
     {
+        checkState();
+        
         _theImple.stop(async);
     }
     
+    /**
+     * Terminate and cleanup the recovery manager. There is no going back from this. This is a
+     * synchronous operation so return means that the recovery has completed.
+     * 
+     * @throws IllegalStateException if the recovery manager has been shutdown.
+     */
+    
+    public final void terminate ()
+    {
+        terminate(false);
+    }
+    
+    /**
+     * Terminate and cleanup the recovery manager. There is no going back from this. Can be called
+     * synchronous or asynchronously.
+     * 
+     * @param async false means wait for any recovery scan in progress to complete.
+     * @throws IllegalStateException if the recovery manager has been shutdown.
+     */
+    
+    public final synchronized void terminate (boolean async)
+    {
+        checkState();
+        
+        _theImple.stop(async);
+        _theImple = null;
+    }
+    
+    /**
+     * If the recovery manager has been shutdown previously then recreate it in
+     * the same mode as before. Otherwise ignore.
+     */
+    
+    public final synchronized void initialize ()
+    {
+        if (_theImple == null)
+        {
+            if ((_mode == RecoveryManager.INDIRECT_MANAGEMENT) && !delayRecoveryManagerThread)
+                _theImple = new RecoveryManagerImple(true);
+            else
+                _theImple = new RecoveryManagerImple(false);
+        }
+    }
+    
     // does nothing when running embedded.
     
+    /**
+     * @throws IllegalStateException if the recovery manager has been shutdown.
+     */
+    
     public void waitForTermination ()
     {
+        checkState();
+        
         _theImple.waitForTermination();
+        _theImple = null;
     }
     
     /**
@@ -206,23 +277,61 @@
      * preserve data integrity.
      *
      * @param async false means wait for the recovery manager to finish any scans before returning.
+     * @throws IllegalStateException if the recovery manager has been shutdown.
+     * @deprecated use suspend
      */
 
     public void suspendScan (boolean async)
     {
-	_theImple.suspendScan(async);
+        suspend(async);
     }
 
+    /**
+     * Suspend the recovery manager. If the recovery manager is in the process of
+     * doing recovery scans then it will be suspended afterwards, in order to
+     * preserve data integrity.
+     *
+     * @param async false means wait for the recovery manager to finish any scans before returning.
+     * @throws IllegalStateException if the recovery manager has been shutdown.
+     */
+    
+    public void suspend (boolean async)
+    {
+        checkState();
+        
+        _theImple.suspendScan(async);
+    }
+    
+    /**
+     * @throws IllegalStateException if the recovery manager has been shutdown.
+     * @deprecated use resume
+     */
+    
     public void resumeScan ()
     {
-	_theImple.resumeScan();
+        resume();
     }
 
     /**
+     * @throws IllegalStateException if the recovery manager has been shutdown.
+     */
+    
+    public void resume ()
+    {
+        checkState();
+        
+        _theImple.resumeScan();
+    }
+    
+    /**
      * Start the recovery manager thread.
+     * 
+     * @throws IllegalStateException if the recovery manager has been shutdown.
      */
     public void startRecoveryManagerThread()
     {
+        checkState();
+        
         _theImple.start() ;
     }
 
@@ -230,10 +339,13 @@
      * Add a recovery module to the system.
      *
      * @param module module The module to add.
+     * @throws IllegalStateException if the recovery manager has been shutdown.
      */
 
     public final void addModule (RecoveryModule module)
     {
+        checkState();
+        
 	_theImple.addModule(module);
     }
 
@@ -242,20 +354,27 @@
      *
      * @param module The module to remove.
      * @param waitOnScan true if the remove operation should wait for any in-progress scan to complete
+     * @throws IllegalStateException if the recovery manager has been shutdown.
      */
 
     public final void removeModule (RecoveryModule module, boolean waitOnScan)
     {
+        checkState();
+        
 	_theImple.removeModule(module, waitOnScan);
     }
 
     /**
      * Obtain a snapshot list of available recovery modules.
+     * 
      * @return a snapshot list of the currently installed recovery modules
+     * @throws IllegalStateException if the recovery manager has been shutdown.
      */
 
     public final Vector getModules ()
     {
+        checkState();
+        
 	return _theImple.getModules();
     }
 
@@ -382,6 +501,12 @@
 
 	_mode = mode;
     }
+    
+    private final void checkState ()
+    {
+        if (_theImple == null)
+            throw new IllegalStateException();
+    }
 
     private RecoveryManagerImple _theImple = null;
     private int _mode;

Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/recovery/Listener.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/recovery/Listener.java	2009-01-20 16:18:50 UTC (rev 24829)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/recovery/Listener.java	2009-01-20 16:22:42 UTC (rev 24830)
@@ -133,15 +133,24 @@
 
             new_conn.start();
          }
-         catch ( InterruptedIOException ex )
+         catch ( final InterruptedIOException ex )
          {
             // timeout on the listener socket expired.
          }
-         catch ( IOException ex )
+         catch (final SocketException ex)
          {
-	     if (tsLogger.arjLoggerI18N.isWarnEnabled())
-		 tsLogger.arjLoggerI18N.warn("com.arjuna.ats.internal.arjuna.recovery.Listener_2");
+             if (tsLogger.arjLogger.debugAllowed())
+             {
+                 tsLogger.arjLogger.debug( DebugLevel.FUNCTIONS, VisibilityLevel.VIS_PUBLIC, FacilityCode.FAC_CRASH_RECOVERY,
+                         "Recovery listener existing "+ 
+                         _listener_service.getClass().getName() );
+             }
          }
+         catch ( final IOException ex )
+         {
+	     if (tsLogger.arjLoggerI18N.debugAllowed())
+		 tsLogger.arjLoggerI18N.debug("com.arjuna.ats.internal.arjuna.recovery.Listener_2"+" "+ex);
+         }
          catch (final Exception ex)
          {
          }

Added: labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/recovery/RecoveryLifecycleTest.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/recovery/RecoveryLifecycleTest.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/tests/classes/com/hp/mwtests/ts/arjuna/recovery/RecoveryLifecycleTest.java	2009-01-20 16:22:42 UTC (rev 24830)
@@ -0,0 +1,86 @@
+/*
+ * 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) 2004,
+ *
+ * Arjuna Technologies Limited,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: EmbeddedRecoveryTest.java 2342 2006-03-30 13:06:17Z  $
+ */
+
+package com.hp.mwtests.ts.arjuna.recovery;
+
+import com.arjuna.ats.arjuna.AtomicAction;
+import com.arjuna.ats.arjuna.coordinator.*;
+import com.arjuna.ats.arjuna.common.*;
+import com.arjuna.ats.arjuna.recovery.RecoveryManager;
+
+import com.hp.mwtests.ts.arjuna.resources.*;
+
+import org.jboss.dtf.testframework.unittest.Test;
+
+public class RecoveryLifecycleTest extends Test
+{
+
+    public void run (String[] args)
+    {
+	RecoveryManager manager = RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT);
+	DummyRecoveryModule module = new DummyRecoveryModule();
+
+	manager.addModule(module);
+
+	manager.scan();
+
+	if (!module.finished())
+	    assertFailure();
+
+	manager.terminate();
+	
+	manager.initialize();
+	
+	module = new DummyRecoveryModule();
+	
+	if (module.finished())
+	    assertFailure();
+	
+	manager.addModule(module);
+
+        manager.scan();
+
+        if (module.finished())
+            assertSuccess();
+        else
+            assertFailure();
+    }
+
+    public static void main (String[] args)
+    {
+        RecoveryLifecycleTest test = new RecoveryLifecycleTest();
+
+    	test.initialise(null, null, args, new org.jboss.dtf.testframework.unittest.LocalHarness());
+
+    	test.run(args);
+    }
+
+}




More information about the jboss-svn-commits mailing list