cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject git commit: updated refs/heads/4.4 to 6e09351
Date Fri, 28 Mar 2014 22:29:08 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.4 024efbfbd -> 6e093514e


CLOUDSTACK-6305: protect lock leaking from unhandled exception


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6e093514
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6e093514
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6e093514

Branch: refs/heads/4.4
Commit: 6e093514e463fde23fe7d9dcf15996cbbbce5a21
Parents: 024efbf
Author: Kelven Yang <kelveny@gmail.com>
Authored: Fri Mar 28 15:28:39 2014 -0700
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Fri Mar 28 15:28:39 2014 -0700

----------------------------------------------------------------------
 .../framework/messagebus/MessageBusBase.java    | 65 ++++++++++++--------
 1 file changed, 39 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6e093514/framework/ipc/src/org/apache/cloudstack/framework/messagebus/MessageBusBase.java
----------------------------------------------------------------------
diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messagebus/MessageBusBase.java
b/framework/ipc/src/org/apache/cloudstack/framework/messagebus/MessageBusBase.java
index a9c433c..9432da0 100644
--- a/framework/ipc/src/org/apache/cloudstack/framework/messagebus/MessageBusBase.java
+++ b/framework/ipc/src/org/apache/cloudstack/framework/messagebus/MessageBusBase.java
@@ -58,10 +58,13 @@ public class MessageBusBase implements MessageBus {
         assert (subject != null);
         assert (subscriber != null);
         if (_gate.enter()) {
-            SubscriptionNode current = locate(subject, null, true);
-            assert (current != null);
-            current.addSubscriber(subscriber);
-            _gate.leave();
+            try {
+                SubscriptionNode current = locate(subject, null, true);
+                assert (current != null);
+                current.addSubscriber(subscriber);
+            } finally {
+                _gate.leave();
+            }
         } else {
             synchronized (_pendingActions) {
                 _pendingActions.add(new ActionRecord(ActionType.Subscribe, subject, subscriber));
@@ -72,14 +75,17 @@ public class MessageBusBase implements MessageBus {
     @Override
     public void unsubscribe(String subject, MessageSubscriber subscriber) {
         if (_gate.enter()) {
-            if (subject != null) {
-                SubscriptionNode current = locate(subject, null, false);
-                if (current != null)
-                    current.removeSubscriber(subscriber, false);
-            } else {
-                _subscriberRoot.removeSubscriber(subscriber, true);
+            try {
+                if (subject != null) {
+                    SubscriptionNode current = locate(subject, null, false);
+                    if (current != null)
+                        current.removeSubscriber(subscriber, false);
+                } else {
+                    _subscriberRoot.removeSubscriber(subscriber, true);
+                }
+            } finally {
+                _gate.leave();
             }
-            _gate.leave();
         } else {
             synchronized (_pendingActions) {
                 _pendingActions.add(new ActionRecord(ActionType.Unsubscribe, subject, subscriber));
@@ -90,9 +96,12 @@ public class MessageBusBase implements MessageBus {
     @Override
     public void clearAll() {
         if (_gate.enter()) {
-            _subscriberRoot.clearAll();
-            doPrune();
-            _gate.leave();
+            try {
+                _subscriberRoot.clearAll();
+                doPrune();
+            } finally {
+                _gate.leave();
+            }
         } else {
             synchronized (_pendingActions) {
                 _pendingActions.add(new ActionRecord(ActionType.ClearAll, null, null));
@@ -103,8 +112,11 @@ public class MessageBusBase implements MessageBus {
     @Override
     public void prune() {
         if (_gate.enter()) {
-            doPrune();
-            _gate.leave();
+            try {
+                doPrune();
+            } finally {
+                _gate.leave();
+            }
         } else {
             synchronized (_pendingActions) {
                 _pendingActions.add(new ActionRecord(ActionType.Prune, null, null));
@@ -132,18 +144,19 @@ public class MessageBusBase implements MessageBus {
     public void publish(String senderAddress, String subject, PublishScope scope, Object
args) {
 
         if (_gate.enter(true)) {
+            try {
+                List<SubscriptionNode> chainFromTop = new ArrayList<SubscriptionNode>();
+                SubscriptionNode current = locate(subject, chainFromTop, false);
 
-            List<SubscriptionNode> chainFromTop = new ArrayList<SubscriptionNode>();
-            SubscriptionNode current = locate(subject, chainFromTop, false);
-
-            if (current != null)
-                current.notifySubscribers(senderAddress, subject, args);
-
-            Collections.reverse(chainFromTop);
-            for (SubscriptionNode node : chainFromTop)
-                node.notifySubscribers(senderAddress, subject, args);
+                if (current != null)
+                    current.notifySubscribers(senderAddress, subject, args);
 
-            _gate.leave();
+                Collections.reverse(chainFromTop);
+                for (SubscriptionNode node : chainFromTop)
+                    node.notifySubscribers(senderAddress, subject, args);
+            } finally {
+                _gate.leave();
+            }
         }
     }
 


Mime
View raw message