brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/3] brooklyn-server git commit: Change signature of WithMutexes.acquireMutex() to throw unchecked RuntimeInterruptedException
Date Thu, 11 Jan 2018 14:47:31 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 387ec1143 -> a850dc87d


Change signature of WithMutexes.acquireMutex() to throw unchecked RuntimeInterruptedException

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/fe2c4356
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/fe2c4356
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/fe2c4356

Branch: refs/heads/master
Commit: fe2c43569a1f3f736e5716a293028fd5b6ce7fa2
Parents: 792f4dd
Author: Alasdair Hodge <github@alasdairhodge.co.uk>
Authored: Thu Jan 11 11:37:48 2018 +0000
Committer: Alasdair Hodge <github@alasdairhodge.co.uk>
Committed: Thu Jan 11 11:37:48 2018 +0000

----------------------------------------------------------------------
 .../brooklyn/location/ssh/SshMachineLocation.java      |  9 ++-------
 .../apache/brooklyn/util/core/mutex/MutexSupport.java  | 13 ++++++++++---
 .../apache/brooklyn/util/core/mutex/WithMutexes.java   |  8 ++++++--
 .../brooklyn/util/core/mutex/WithMutexesTest.java      | 13 +++++++------
 .../entity/software/base/lifecycle/ScriptHelper.java   |  9 +++------
 5 files changed, 28 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fe2c4356/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java b/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java
index fc1fadc..909cc2b 100644
--- a/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java
+++ b/core/src/main/java/org/apache/brooklyn/location/ssh/SshMachineLocation.java
@@ -84,7 +84,6 @@ import org.apache.brooklyn.util.core.task.ScheduledTask;
 import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.core.task.system.internal.ExecWithLoggingHelpers;
 import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.exceptions.RuntimeInterruptedException;
 import org.apache.brooklyn.util.guava.KeyTransformingLoadingCache.KeyTransformingSameTypeLoadingCache;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.pool.BasicPool;
@@ -1016,12 +1015,8 @@ public class SshMachineLocation extends AbstractMachineLocation implements
Machi
     /** @deprecated since 1.0.0; mutex-related methods are now accessible via {@link #mutexes()}
*/
     @Override
     @Deprecated
-    public void acquireMutex(String mutexId, String description) throws RuntimeInterruptedException
{
-        try {
-            mutexes().acquireMutex(mutexId, description);
-        } catch (InterruptedException ie) {
-            throw new RuntimeInterruptedException("Interrupted waiting for mutex: " + mutexId,
ie);
-        }
+    public void acquireMutex(String mutexId, String description) {
+        mutexes().acquireMutex(mutexId, description);
     }
 
     /** @deprecated since 1.0.0; mutex-related methods are now accessible via {@link #mutexes()}
*/

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fe2c4356/core/src/main/java/org/apache/brooklyn/util/core/mutex/MutexSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/mutex/MutexSupport.java b/core/src/main/java/org/apache/brooklyn/util/core/mutex/MutexSupport.java
index 4e3c712..aadff08 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/mutex/MutexSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/mutex/MutexSupport.java
@@ -23,6 +23,7 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -67,14 +68,20 @@ public class MutexSupport implements WithMutexes {
         if (s!=null) return s.isCallingThreadAnOwner();
         return false;
     }
-    
+
     @Override
-    public void acquireMutex(String mutexId, String description) throws InterruptedException
{
+    public void acquireMutex(String mutexId, String description) {
         SemaphoreWithOwners s = getSemaphore(mutexId, true);
         if (description!=null) Tasks.setBlockingDetails(description+" - waiting for "+mutexId);
         if (log.isDebugEnabled())
             log.debug("Acquiring mutex: "+mutexId+"@"+this+" - "+description);
-        s.acquire(); 
+
+        try {
+            s.acquire();
+        } catch (InterruptedException ie) {
+            throw Exceptions.propagate(ie);
+        }
+
         if (description!=null) Tasks.setBlockingDetails(null);
         s.setDescription(description);
         if (log.isDebugEnabled())

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fe2c4356/core/src/main/java/org/apache/brooklyn/util/core/mutex/WithMutexes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/mutex/WithMutexes.java b/core/src/main/java/org/apache/brooklyn/util/core/mutex/WithMutexes.java
index 76be3ed..60522e9 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/mutex/WithMutexes.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/mutex/WithMutexes.java
@@ -18,6 +18,8 @@
  */
 package org.apache.brooklyn.util.core.mutex;
 
+import org.apache.brooklyn.util.exceptions.RuntimeInterruptedException;
+
 /** interface which allows multiple callers to co-operate using named mutexes, inspectably,
  * and containing implementation as inner class
  * <p>
@@ -31,8 +33,10 @@ public interface WithMutexes {
     public boolean hasMutex(String mutexId);
     
     /** acquires a mutex, if available, otherwise blocks on its becoming available;
-     * caller must release after use */
-    public void acquireMutex(String mutexId, String description) throws InterruptedException;
+     * caller must release after use
+     * @throws RuntimeInterruptedException if the thread was interrupted waiting for the
underlying mutex
+     */
+    public void acquireMutex(String mutexId, String description);
 
     /** acquires a mutex and returns true, if available; otherwise immediately returns false;
      * caller must release after use if this returns true */

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fe2c4356/core/src/test/java/org/apache/brooklyn/util/core/mutex/WithMutexesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/mutex/WithMutexesTest.java b/core/src/test/java/org/apache/brooklyn/util/core/mutex/WithMutexesTest.java
index d99975c..9df5fcc 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/mutex/WithMutexesTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/mutex/WithMutexesTest.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import org.apache.brooklyn.util.core.mutex.MutexSupport;
 import org.apache.brooklyn.util.core.mutex.SemaphoreWithOwners;
 import org.apache.brooklyn.util.core.mutex.WithMutexes;
+import org.apache.brooklyn.util.exceptions.RuntimeInterruptedException;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -70,7 +71,7 @@ public class WithMutexesTest {
             public void run() {
                 try {
                     m.acquireMutex("foo", "thread 2 foo");
-                } catch (InterruptedException e) {
+                } catch (RuntimeInterruptedException e) {
                     e.printStackTrace();
                 }
                 m.releaseMutex("foo");
@@ -92,13 +93,13 @@ public class WithMutexesTest {
 
     
     public static class SampleWithMutexesDelegatingMixin implements WithMutexes {
-        
+
         /* other behaviour would typically go here... */
-        
+
         WithMutexes mutexSupport = new MutexSupport();
-        
+
         @Override
-        public void acquireMutex(String mutexId, String description) throws InterruptedException
{
+        public void acquireMutex(String mutexId, String description) {
             mutexSupport.acquireMutex(mutexId, description);
         }
 
@@ -117,7 +118,7 @@ public class WithMutexesTest {
             return mutexSupport.hasMutex(mutexId);
         }
     }
-    
+
     @Test
     public void testDelegatingMixinPattern() throws InterruptedException {
         WithMutexes m = new SampleWithMutexesDelegatingMixin();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fe2c4356/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/ScriptHelper.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/ScriptHelper.java
b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/ScriptHelper.java
index 8b13a9e..82d9985 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/ScriptHelper.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/lifecycle/ScriptHelper.java
@@ -19,7 +19,6 @@
 package org.apache.brooklyn.entity.software.base.lifecycle;
 
 import static java.lang.String.format;
-import groovy.lang.Closure;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -55,6 +54,8 @@ import com.google.common.annotations.Beta;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 
+import groovy.lang.Closure;
+
 public class ScriptHelper {
 
     public static final Logger log = LoggerFactory.getLogger(ScriptHelper.class);
@@ -216,11 +217,7 @@ public class ScriptHelper {
         mutexAcquire = new Runnable() {
             @Override
             public void run() {
-                try {
-                    mutexSupport.acquireMutex(mutexId, description);
-                } catch (InterruptedException e) {
-                    throw new RuntimeInterruptedException(e);
-                }
+                mutexSupport.acquireMutex(mutexId, description);
             }
         };
 


Mime
View raw message