You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2017/12/18 15:42:20 UTC

[3/5] brooklyn-server git commit: Pull-up mutex support.

Pull-up mutex support.


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

Branch: refs/heads/master
Commit: 2e0889505958ece611b4b4a60555527d35ae444b
Parents: 061cf15
Author: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Authored: Thu Dec 7 18:50:55 2017 +0000
Committer: Alasdair Hodge <gi...@alasdairhodge.co.uk>
Committed: Mon Dec 11 14:34:50 2017 +0000

----------------------------------------------------------------------
 .../core/location/AbstractMachineLocation.java  | 15 ++++
 .../LocalhostMachineProvisioningLocation.java   | 14 ++--
 .../location/ssh/SshMachineLocation.java        | 75 +++++++++-----------
 3 files changed, 55 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2e088950/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java b/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java
index 99e2ffe..17a1217 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/AbstractMachineLocation.java
@@ -26,6 +26,8 @@ import org.apache.brooklyn.api.location.OsDetails;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.mutex.MutexSupport;
+import org.apache.brooklyn.util.core.mutex.WithMutexes;
 
 import com.google.common.base.Optional;
 
@@ -46,6 +48,9 @@ public abstract class AbstractMachineLocation extends AbstractLocation implement
     private volatile MachineDetails machineDetails;
     private final Object machineDetailsLock = new Object();
 
+    private transient WithMutexes mutexSupport;
+    private transient final Object mutexSupportCreationLock = new Object();
+
 
     public AbstractMachineLocation() {
         this(MutableMap.of());
@@ -88,4 +93,14 @@ public abstract class AbstractMachineLocation extends AbstractLocation implement
 
     protected abstract MachineDetails detectMachineDetails();
 
+    public WithMutexes mutexes() {
+        synchronized (mutexSupportCreationLock) {
+            // create on demand so that it is not null after serialization
+            if (mutexSupport == null) {
+                mutexSupport = new MutexSupport();
+            }
+            return mutexSupport;
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2e088950/core/src/main/java/org/apache/brooklyn/location/localhost/LocalhostMachineProvisioningLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/location/localhost/LocalhostMachineProvisioningLocation.java b/core/src/main/java/org/apache/brooklyn/location/localhost/LocalhostMachineProvisioningLocation.java
index 1ea8a4d..9677f8c 100644
--- a/core/src/main/java/org/apache/brooklyn/location/localhost/LocalhostMachineProvisioningLocation.java
+++ b/core/src/main/java/org/apache/brooklyn/location/localhost/LocalhostMachineProvisioningLocation.java
@@ -113,7 +113,7 @@ public class LocalhostMachineProvisioningLocation extends FixedListMachineProvis
      * @see #LocalhostMachineProvisioningLocation()
      */
     @Deprecated
-    public LocalhostMachineProvisioningLocation(Map properties) {
+    public LocalhostMachineProvisioningLocation(Map<?,?> properties) {
         super(properties);
     }
     public LocalhostMachineProvisioningLocation(String name) {
@@ -269,7 +269,7 @@ public class LocalhostMachineProvisioningLocation extends FixedListMachineProvis
                 true);
 
         private static final WithMutexes mutexSupport = new MutexSupport();
-        
+
         private final Set<Integer> portsObtained = Sets.newLinkedHashSet();
 
         public LocalhostMachine() {
@@ -277,15 +277,15 @@ public class LocalhostMachineProvisioningLocation extends FixedListMachineProvis
         }
         /** @deprecated since 0.6.0 use no-arg constructor (and spec) then configure */
         @Deprecated
-        public LocalhostMachine(Map properties) {
-            super(MutableMap.builder().putAll(properties).put("mutexSupport", mutexSupport).build());
+        public LocalhostMachine(Map<?,?> properties) {
+            super(MutableMap.builder().putAll(properties).build());
         }
-        
+
         @Override
-        protected WithMutexes getMutexSupport() {
+        public WithMutexes mutexes() {
             return mutexSupport;
         }
-        
+
         @Override
         public boolean obtainSpecificPort(int portNumber) {
             if (!isSudoAllowed() && portNumber <= 1024)

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2e088950/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 7ed83f8..d2b7d10 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
@@ -79,7 +79,6 @@ import org.apache.brooklyn.util.core.internal.ssh.ShellTool;
 import org.apache.brooklyn.util.core.internal.ssh.SshException;
 import org.apache.brooklyn.util.core.internal.ssh.SshTool;
 import org.apache.brooklyn.util.core.internal.ssh.sshj.SshjTool;
-import org.apache.brooklyn.util.core.mutex.MutexSupport;
 import org.apache.brooklyn.util.core.mutex.WithMutexes;
 import org.apache.brooklyn.util.core.task.ScheduledTask;
 import org.apache.brooklyn.util.core.task.Tasks;
@@ -166,6 +165,7 @@ public class SshMachineLocation extends AbstractMachineLocation implements Machi
      */
     public static final String SSH_TOOL_CLASS_PROPERTIES_PREFIX = SSH_TOOL_CLASS.getName()+".";
 
+
     public static final ConfigKey<Duration> SSH_CACHE_EXPIRY_DURATION = ConfigKeys.newConfigKey(Duration.class,
             "sshCacheExpiryDuration", "Expiry time for unused cached ssh connections", Duration.FIVE_MINUTES);
 
@@ -189,12 +189,6 @@ public class SshMachineLocation extends AbstractMachineLocation implements Machi
     @SetFromFlag(nullable = false)
     protected InetAddress address;
 
-    // TODO should not allow this to be set from flag; it is not persisted so that will be lost
-    // (mainly used for localhost currently so not a big problem)
-    @Nullable  // lazily initialized; use getMutexSupport()
-    @SetFromFlag
-    private transient WithMutexes mutexSupport;
-
     @SetFromFlag
     private Set<Integer> usedPorts;
 
@@ -421,17 +415,6 @@ public class SshMachineLocation extends AbstractMachineLocation implements Machi
         return this;
     }
     
-    private transient final Object mutexSupportCreationLock = new Object();
-    protected WithMutexes getMutexSupport() {
-        synchronized (mutexSupportCreationLock) {
-            // create on demand so that it is not null after serialization
-            if (mutexSupport == null) {
-                mutexSupport = new MutexSupport();
-            }
-            return mutexSupport;
-        }
-    }
-    
     protected void addSshPoolCacheCleanupTask() {
         if (cleanupTask!=null && !cleanupTask.isDone()) {
             return;
@@ -1009,30 +992,6 @@ public class SshMachineLocation extends AbstractMachineLocation implements Machi
         }
     }
 
-    @Override
-    public void acquireMutex(String mutexId, String description) throws RuntimeInterruptedException {
-        try {
-            getMutexSupport().acquireMutex(mutexId, description);
-        } catch (InterruptedException ie) {
-            throw new RuntimeInterruptedException("Interrupted waiting for mutex: " + mutexId, ie);
-        }
-    }
-
-    @Override
-    public boolean tryAcquireMutex(String mutexId, String description) {
-        return getMutexSupport().tryAcquireMutex(mutexId, description);
-    }
-
-    @Override
-    public void releaseMutex(String mutexId) {
-        getMutexSupport().releaseMutex(mutexId);
-    }
-
-    @Override
-    public boolean hasMutex(String mutexId) {
-        return getMutexSupport().hasMutex(mutexId);
-    }
-
     //We want the SshMachineLocation to be serializable and therefore the pool needs to be dealt with correctly.
     //In this case we are not serializing the pool (we made the field transient) and create a new pool when deserialized.
     //This fix is currently needed for experiments, but isn't used in normal Brooklyn usage.
@@ -1057,4 +1016,36 @@ public class SshMachineLocation extends AbstractMachineLocation implements Machi
         return getConfig(SshTool.PROP_PASSWORD);
     }
 
+    /** @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);
+        }
+    }
+
+    /** @deprecated since 1.0.0; mutex-related methods are now accessible via {@link #mutexes()} */
+    @Override
+    @Deprecated
+    public boolean tryAcquireMutex(String mutexId, String description) {
+        return mutexes().tryAcquireMutex(mutexId, description);
+    }
+
+    /** @deprecated since 1.0.0; mutex-related methods are now accessible via {@link #mutexes()} */
+    @Override
+    @Deprecated
+    public void releaseMutex(String mutexId) {
+        mutexes().releaseMutex(mutexId);
+    }
+
+    /** @deprecated since 1.0.0; mutex-related methods are now accessible via {@link #mutexes()} */
+    @Override
+    @Deprecated
+    public boolean hasMutex(String mutexId) {
+        return mutexes().hasMutex(mutexId);
+    }
+
 }