brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] brooklyn-server git commit: Lazily instantiate ‘runScriptFactory’ to prevent config access during rebind
Date Fri, 27 Jan 2017 12:01:33 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/0.9.x 77ded8ed3 -> f9b733347


Lazily instantiate ‘runScriptFactory’ to prevent config access during rebind

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

Branch: refs/heads/0.9.x
Commit: 702995d4255f9fca512141dab83b947fd62c217b
Parents: 2803a98
Author: Alasdair Hodge <github@alasdairhodge.co.uk>
Authored: Fri Nov 11 15:59:22 2016 +0000
Committer: Alasdair Hodge <github@alasdairhodge.co.uk>
Committed: Thu Jan 26 10:15:14 2017 +0000

----------------------------------------------------------------------
 .../jclouds/JcloudsSshMachineLocation.java       | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/702995d4/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
index 6074eb5..ab9e225 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
@@ -124,7 +124,7 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements
Jcl
 
     private transient Optional<Image> _image;
 
-    private RunScriptOnNode.Factory runScriptFactory;
+    private transient RunScriptOnNode.Factory runScriptFactory;
     
     public JcloudsSshMachineLocation() {
     }
@@ -144,8 +144,6 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements
Jcl
     public void init() {
         if (jcloudsParent != null) {
             super.init();
-            ComputeServiceContext context = jcloudsParent.getComputeService().getContext();
-            runScriptFactory = context.utils().injector().getInstance(RunScriptOnNode.Factory.class);
             if (node != null) {
                 setNode(node);
             }
@@ -163,11 +161,7 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements
Jcl
     public void rebind() {
         super.rebind();
         
-        if (jcloudsParent != null) {
-            // can be null on rebind, if location has been "orphaned" somehow
-            ComputeServiceContext context = jcloudsParent.getComputeService().getContext();
-            runScriptFactory = context.utils().injector().getInstance(RunScriptOnNode.Factory.class);
-        } else {
+        if (jcloudsParent == null) {
             LOG.warn("Location {} does not have parent; cannot retrieve jclouds compute-service
or "
                     + "run-script factory; later operations may fail (continuing)", this);
         }
@@ -423,7 +417,7 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements
Jcl
     public ListenableFuture<ExecResponse> submitRunScript(Statement script, RunScriptOptions
options) {
         Optional<NodeMetadata> node = getOptionalNode();
         if (node.isPresent()) {
-            return runScriptFactory.submit(node.get(), script, options);
+            return getRunScriptFactory().submit(node.get(), script, options);
         } else {
             throw new IllegalStateException("Node "+nodeId+" not present in "+getParent());
         }
@@ -599,4 +593,11 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements
Jcl
         if (value != null) builder.put(key, value);
     }
 
+    private synchronized RunScriptOnNode.Factory getRunScriptFactory() {
+        if (runScriptFactory == null) {
+            ComputeServiceContext context = jcloudsParent.getComputeService().getContext();
+            runScriptFactory = context.utils().injector().getInstance(RunScriptOnNode.Factory.class);
+        }
+        return runScriptFactory;
+    }
 }


Mime
View raw message