[jboss-cvs] JBoss Messaging SVN: r2414 - in trunk/src/main/org/jboss/jms/client: remoting and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Feb 24 08:46:40 EST 2007


Author: ovidiu.feodorov at jboss.com
Date: 2007-02-24 08:46:40 -0500 (Sat, 24 Feb 2007)
New Revision: 2414

Modified:
   trunk/src/main/org/jboss/jms/client/FailoverCommandCenter.java
   trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
Log:
extra synchronization to prevent the case when multiple threads execute the client-side failover

Modified: trunk/src/main/org/jboss/jms/client/FailoverCommandCenter.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/FailoverCommandCenter.java	2007-02-24 10:06:39 UTC (rev 2413)
+++ trunk/src/main/org/jboss/jms/client/FailoverCommandCenter.java	2007-02-24 13:46:40 UTC (rev 2414)
@@ -65,10 +65,8 @@
       log.debug("failure detected by " + source);
 
       // generate a FAILURE_DETECTED event
-      broadcastFailoverEvent(new FailoverEvent(FailoverEvent.FAILURE_DETECTED, this));
+      broadcastFailoverEvent(new FailoverEvent(FailoverEvent.FAILURE_DETECTED, source));
 
-      log.debug(this + " initiating client-side failover");
-
       CreateConnectionResult res = null;
       boolean failoverSuccessful = false;
 
@@ -79,14 +77,22 @@
 
          valve.close();
 
-         if (remotingConnection.isFailed())
+         synchronized(this)
          {
-            log.debug(this + " ignoring failure detection notification, as failover was " +
-               "already performed on this connection");
-            return;
+            // testing for failed connection and setting the failed flag need to be done in one
+            // atomic operation, otherwise multiple threads can get to perform the client-side
+            // failover concurrently
+            if (remotingConnection.isFailed())
+            {
+               log.debug(this + " ignoring failure detection notification, as failover was " +
+                  "already (or is in process of being) performed on this connection");
+               return;
+            }
+
+            remotingConnection.setFailed();
          }
 
-         remotingConnection.setFailed();
+         log.debug(this + " starting client-side failover");
 
          // generate a FAILOVER_STARTED event. The event must be broadcasted AFTER valve closure,
          // to insure the client-side stack is in a deterministic state

Modified: trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2007-02-24 10:06:39 UTC (rev 2413)
+++ trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2007-02-24 13:46:40 UTC (rev 2414)
@@ -313,7 +313,7 @@
       return callbackManager;
    }
 
-   public boolean isFailed()
+   public synchronized boolean isFailed()
    {
       return failed;
    }
@@ -322,7 +322,7 @@
     * Used by the FailoverCommandCenter to mark this remoting connection as "condemned", following
     * a failure detected by either a failed invocation, or the ConnectionListener.
     */
-   public void setFailed()
+   public synchronized void setFailed()
    {
       failed = true;
 




More information about the jboss-cvs-commits mailing list