Author: rgodfrey
Date: Fri Mar 29 12:42:45 2013
New Revision: 1462459

URL: http://svn.apache.org/r1462459
Log:
QPID-4673 : [Java Broker AMQP 1.0] Remove potential for deadlock between 
connection and subscription in 1.0 codepath (merged from trunk revision 1461844)

Modified:
    
qpid/branches/0.22/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Subscription_1_0.java

Modified: 
qpid/branches/0.22/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Subscription_1_0.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/0.22/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Subscription_1_0.java?rev=1462459&r1=1462458&r2=1462459&view=diff
==============================================================================
--- 
qpid/branches/0.22/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Subscription_1_0.java
 (original)
+++ 
qpid/branches/0.22/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Subscription_1_0.java
 Fri Mar 29 12:42:45 2013
@@ -717,15 +717,18 @@ class Subscription_1_0 implements Subscr
         getEndpoint().detach();
     }
 
-    public synchronized boolean wouldSuspend(final QueueEntry msg)
+    public boolean wouldSuspend(final QueueEntry msg)
     {
-        final boolean hasCredit = _link.isAttached() && 
getEndpoint().hasCreditToSend();
-        if(!hasCredit && getState() == State.ACTIVE)
+        synchronized (_link.getLock())
         {
-            suspend();
-        }
+            final boolean hasCredit = _link.isAttached() && 
getEndpoint().hasCreditToSend();
+            if(!hasCredit && getState() == State.ACTIVE)
+            {
+                suspend();
+            }
 
-        return !hasCredit;
+            return !hasCredit;
+        }
     }
 
     public boolean trySendLock()
@@ -733,11 +736,14 @@ class Subscription_1_0 implements Subscr
         return _stateChangeLock.tryLock();
     }
 
-    public synchronized void suspend()
+    public void suspend()
     {
-        if(_state.compareAndSet(State.ACTIVE, State.SUSPENDED))
+        synchronized(_link.getLock())
         {
-            _stateListener.stateChange(this, State.ACTIVE, State.SUSPENDED);
+            if(_state.compareAndSet(State.ACTIVE, State.SUSPENDED))
+            {
+                _stateListener.stateChange(this, State.ACTIVE, 
State.SUSPENDED);
+            }
         }
     }
 
@@ -808,26 +814,32 @@ class Subscription_1_0 implements Subscr
         return false;  //TODO
     }
 
-    public synchronized void queueEmpty()
+    public void queueEmpty()
     {
-        if(_link.drained())
+        synchronized(_link.getLock())
         {
-            if(_state.compareAndSet(State.ACTIVE, State.SUSPENDED))
+            if(_link.drained())
             {
-                _stateListener.stateChange(this, State.ACTIVE, 
State.SUSPENDED);
+                if(_state.compareAndSet(State.ACTIVE, State.SUSPENDED))
+                {
+                    _stateListener.stateChange(this, State.ACTIVE, 
State.SUSPENDED);
+                }
             }
         }
     }
 
-    public synchronized void flowStateChanged()
+    public void flowStateChanged()
     {
-        if(isSuspended() && getEndpoint() != null)
+        synchronized(_link.getLock())
         {
-            if(_state.compareAndSet(State.SUSPENDED, State.ACTIVE))
+            if(isSuspended() && getEndpoint() != null)
             {
-                _stateListener.stateChange(this, State.SUSPENDED, 
State.ACTIVE);
+                if(_state.compareAndSet(State.SUSPENDED, State.ACTIVE))
+                {
+                    _stateListener.stateChange(this, State.SUSPENDED, 
State.ACTIVE);
+                }
+                _transactionId = _link.getTransactionId();
             }
-            _transactionId = _link.getTransactionId();
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to