Clocker-pattern: update for checkNotNull on 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/2a818bd4
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/2a818bd4
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/2a818bd4

Branch: refs/heads/master
Commit: 2a818bd4be58aef7cba3bb25426cd50e89c8092e
Parents: 25c4bd4
Author: Aled Sage <[email protected]>
Authored: Wed May 4 21:10:21 2016 +0100
Committer: Aled Sage <[email protected]>
Committed: Wed May 4 21:10:21 2016 +0100

----------------------------------------------------------------------
 .../location/dynamic/clocker/StubHostLocation.java    | 14 +++++++++++---
 .../dynamic/clocker/StubInfrastructureLocation.java   | 11 +++++++++--
 2 files changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a818bd4/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubHostLocation.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubHostLocation.java
 
b/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubHostLocation.java
index bdea2f0..8ab2df9 100644
--- 
a/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubHostLocation.java
+++ 
b/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubHostLocation.java
@@ -68,9 +68,17 @@ public class StubHostLocation extends AbstractLocation 
implements MachineProvisi
     @Override
     public void init() {
         super.init();
-        dockerHost = (StubHost) checkNotNull(getConfig(OWNER), "owner");
-        machine = (SshMachineLocation) checkNotNull(getConfig(MACHINE), 
"machine");
-        addReloadListener();
+        
+        // TODO BasicLocationRebindsupport.addCustoms currently calls init() 
unfortunately!
+        // Don't checkNotNull in that situation - it could be this location is 
orphaned!
+        if (isRebinding()) {
+            dockerHost = (StubHost) config().get(OWNER);
+            machine = config().get(MACHINE);
+        } else {
+            dockerHost = (StubHost) checkNotNull(getConfig(OWNER), "owner");
+            machine = (SshMachineLocation) checkNotNull(getConfig(MACHINE), 
"machine");
+            addReloadListener();
+        }
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a818bd4/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubInfrastructureLocation.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubInfrastructureLocation.java
 
b/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubInfrastructureLocation.java
index 57c52a4..aaa7d30 100644
--- 
a/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubInfrastructureLocation.java
+++ 
b/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/StubInfrastructureLocation.java
@@ -63,8 +63,15 @@ public class StubInfrastructureLocation extends 
AbstractLocation implements Mach
     @Override
     public void init() {
         super.init();
-        infrastructure = (StubInfrastructure) checkNotNull(getConfig(OWNER), 
"owner");
-        addReloadListener();
+        
+        // TODO BasicLocationRebindsupport.addCustoms currently calls init() 
unfortunately!
+        // Don't checkNotNull in that situation - it could be this location is 
orphaned!
+        if (isRebinding()) {
+            infrastructure = (StubInfrastructure) getConfig(OWNER);
+        } else {
+            infrastructure = (StubInfrastructure) 
checkNotNull(getConfig(OWNER), "owner");
+            addReloadListener();
+        }
     }
     
     @Override

Reply via email to