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 2015/09/23 12:51:59 UTC

[07/10] incubator-brooklyn git commit: Move entityLocal.subscribe(map, …) to SubscriptionSupport

Move entityLocal.subscribe(map, …) to SubscriptionSupport

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

Branch: refs/heads/master
Commit: ee52d48d6d2b82e45283d6fe56c70442064e7e71
Parents: 7708363
Author: Aled Sage <al...@gmail.com>
Authored: Wed Sep 23 10:40:43 2015 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Sep 23 10:40:43 2015 +0100

----------------------------------------------------------------------
 .../org/apache/brooklyn/api/entity/EntityLocal.java    | 11 -----------
 .../org/apache/brooklyn/api/objs/BrooklynObject.java   | 10 ++++++++++
 .../apache/brooklyn/core/entity/AbstractEntity.java    | 12 +++++-------
 .../brooklyn/core/location/AbstractLocation.java       |  5 +++++
 .../brooklyn/core/objs/AbstractEntityAdjunct.java      | 13 ++++++-------
 .../apache/brooklyn/enricher/stock/UpdatingMap.java    |  2 +-
 .../brooklyn/core/entity/EntitySubscriptionTest.java   | 12 ++++++------
 .../core/policy/basic/PolicySubscriptionTest.java      |  4 ++--
 .../entity/software/base/SoftwareProcessImpl.java      |  4 ++--
 9 files changed, 37 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ee52d48d/api/src/main/java/org/apache/brooklyn/api/entity/EntityLocal.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/EntityLocal.java b/api/src/main/java/org/apache/brooklyn/api/entity/EntityLocal.java
index 0ecc73a..aeb7249 100644
--- a/api/src/main/java/org/apache/brooklyn/api/entity/EntityLocal.java
+++ b/api/src/main/java/org/apache/brooklyn/api/entity/EntityLocal.java
@@ -115,17 +115,6 @@ public interface EntityLocal extends Entity {
     <T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener);
 
     /**
-     * Allow us to subscribe to data from a {@link Sensor} on another entity.
-     * 
-     * @return a subscription id which can be used to unsubscribe
-     *
-     * @see SubscriptionManager#subscribe(Map, Entity, Sensor, SensorEventListener)
-     */
-    // FIXME remove from interface?
-    @Beta
-    <T> SubscriptionHandle subscribe(Map<String, ?> flags, Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener);
- 
-    /**
      * @see SubscriptionManager#subscribeToChildren(Map, Entity, Sensor, SensorEventListener)
      * 
      * @deprecated since 0.9.0; see {@link SubscriptionSupport#subscribeToChildren(Entity, Sensor, SensorEventListener)}, e.g. with {@code subscriptions().subscribeToChildren(...)}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ee52d48d/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObject.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObject.java b/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObject.java
index 094586f..f3fcad4 100644
--- a/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObject.java
+++ b/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObject.java
@@ -99,6 +99,16 @@ public interface BrooklynObject extends Identifiable, Configurable {
         @Beta
         <T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener);
      
+        /**
+         * Allow us to subscribe to data from a {@link Sensor} on another entity.
+         * 
+         * @return a subscription id which can be used to unsubscribe
+         *
+         * @see SubscriptionManager#subscribe(Map, Entity, Sensor, SensorEventListener)
+         */
+        @Beta
+        <T> SubscriptionHandle subscribe(Map<String, ?> flags, Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener);
+
         /** @see SubscriptionManager#subscribeToChildren(Map, Entity, Sensor, SensorEventListener) */
         @Beta
         <T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, SensorEventListener<? super T> listener);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ee52d48d/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
index 0084038..291389f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
@@ -1410,6 +1410,11 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
         }
 
         @Override
+        public <T> SubscriptionHandle subscribe(Map<String, ?> flags, Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener) {
+            return getSubscriptionTracker().subscribe(flags, producer, sensor, listener);
+        }
+
+        @Override
         public <T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, SensorEventListener<? super T> listener) {
             return getSubscriptionTracker().subscribeToChildren(parent, sensor, listener);
         }
@@ -1480,13 +1485,6 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
         return subscriptions().subscribe(producer, sensor, listener);
     }
 
-    /** @see EntityLocal#subscribe */
-    @Override
-    @Beta
-    public <T> SubscriptionHandle subscribe(Map<String, ?> flags, Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener) {
-        return getSubscriptionTracker().subscribe(flags, producer, sensor, listener);
-    }
-
     /**
      * @deprecated since 0.9.0; see {@code subscriptions().subscribeToChildren(parent, sensor, listener)}
      */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ee52d48d/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java b/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
index b8859d6..26e58e1 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/AbstractLocation.java
@@ -507,6 +507,11 @@ public abstract class AbstractLocation extends AbstractBrooklynObject implements
         }
 
         @Override
+        public <T> SubscriptionHandle subscribe(Map<String, ?> flags, Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener) {
+            return getSubscriptionTracker().subscribe(flags, producer, sensor, listener);
+        }
+
+        @Override
         public <T> SubscriptionHandle subscribeToMembers(Group producerGroup, Sensor<T> sensor, SensorEventListener<? super T> listener) {
             return getSubscriptionTracker().subscribeToMembers(producerGroup, sensor, listener);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ee52d48d/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
index 814923a..69c52ff 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
@@ -213,6 +213,12 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject imple
         }
 
         @Override
+        public <T> SubscriptionHandle subscribe(Map<String, ?> flags, Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener) {
+            if (!checkCanSubscribe()) return null;
+            return getSubscriptionTracker().subscribe(flags, producer, sensor, listener);
+        }
+
+        @Override
         public <T> SubscriptionHandle subscribeToMembers(Group producerGroup, Sensor<T> sensor, SensorEventListener<? super T> listener) {
             if (!checkCanSubscribe(producerGroup)) return null;
             return getSubscriptionTracker().subscribeToMembers(producerGroup, sensor, listener);
@@ -481,13 +487,6 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject imple
         return getSubscriptionTracker().subscribe(producer, sensor, listener);
     }
 
-    @Beta
-    /** @see SubscriptionContext#subscribe(Map, Entity, Sensor, SensorEventListener) */
-    public <T> SubscriptionHandle subscribe(Map<String, ?> flags, Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener) {
-        if (!checkCanSubscribe()) return null;
-        return getSubscriptionTracker().subscribe(flags, producer, sensor, listener);
-    }
-
     /**
      * @deprecated since 0.9.0; see {@link SubscriptionSupport#subscribeToMembers(Entity, Sensor, SensorEventListener)} and {@link BrooklynObject#subscriptions()}
      */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ee52d48d/core/src/main/java/org/apache/brooklyn/enricher/stock/UpdatingMap.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/UpdatingMap.java b/core/src/main/java/org/apache/brooklyn/enricher/stock/UpdatingMap.java
index 01084e1..d37bf06 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/UpdatingMap.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/UpdatingMap.java
@@ -122,7 +122,7 @@ public class UpdatingMap<S,TKey,TVal> extends AbstractEnricher implements Sensor
         this.computing = (Function) getRequiredConfig(COMPUTING);
         this.removingIfResultIsNull = getConfig(REMOVING_IF_RESULT_IS_NULL);
 
-        subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, sourceSensor, this);
+        subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, sourceSensor, this);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ee52d48d/core/src/test/java/org/apache/brooklyn/core/entity/EntitySubscriptionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/entity/EntitySubscriptionTest.java b/core/src/test/java/org/apache/brooklyn/core/entity/EntitySubscriptionTest.java
index 620d8e0..38848ef 100644
--- a/core/src/test/java/org/apache/brooklyn/core/entity/EntitySubscriptionTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/entity/EntitySubscriptionTest.java
@@ -246,8 +246,8 @@ public class EntitySubscriptionTest {
         observedEntity.sensors().set(TestEntity.SEQUENCE, 123);
         observedEntity.sensors().set(TestEntity.NAME, "myname");
         
-        entity.subscribe(ImmutableMap.of("notifyOfInitialValue", true), observedEntity, TestEntity.SEQUENCE, listener);
-        entity.subscribe(ImmutableMap.of("notifyOfInitialValue", true), observedEntity, TestEntity.NAME, listener);
+        entity.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), observedEntity, TestEntity.SEQUENCE, listener);
+        entity.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), observedEntity, TestEntity.NAME, listener);
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {
@@ -275,9 +275,9 @@ public class EntitySubscriptionTest {
     // TODO A visual inspection test that we get a log.warn telling us we can't get the initial-value
     @Test
     public void testSubscriptionForInitialValueWhenNotValid() {
-        entity.subscribe(ImmutableMap.of("notifyOfInitialValue", true), observedEntity, TestEntity.MY_NOTIF, listener);
-        entity.subscribe(ImmutableMap.of("notifyOfInitialValue", true), observedEntity, null, listener);
-        entity.subscribe(ImmutableMap.of("notifyOfInitialValue", true), null, TestEntity.NAME, listener);
-        entity.subscribe(ImmutableMap.of("notifyOfInitialValue", true), null, null, listener);
+        entity.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), observedEntity, TestEntity.MY_NOTIF, listener);
+        entity.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), observedEntity, null, listener);
+        entity.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), null, TestEntity.NAME, listener);
+        entity.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), null, null, listener);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ee52d48d/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicySubscriptionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicySubscriptionTest.java b/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicySubscriptionTest.java
index ab5bc4a..0a7b003 100644
--- a/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicySubscriptionTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/policy/basic/PolicySubscriptionTest.java
@@ -126,8 +126,8 @@ public class PolicySubscriptionTest extends BrooklynAppUnitTestSupport {
         entity.sensors().set(TestEntity.SEQUENCE, 123);
         entity.sensors().set(TestEntity.NAME, "myname");
         
-        policy.subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, TestEntity.SEQUENCE, listener);
-        policy.subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, TestEntity.NAME, listener);
+        policy.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, TestEntity.SEQUENCE, listener);
+        policy.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, TestEntity.NAME, listener);
         
         Asserts.succeedsEventually(new Runnable() {
             @Override public void run() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ee52d48d/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
index b635242..7f4658c 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
@@ -157,8 +157,8 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements Soft
             if (!(entity instanceof SoftwareProcess)) {
                 throw new IllegalArgumentException("Expected SoftwareProcess, but got entity "+entity);
             }
-            subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, Attributes.SERVICE_STATE_ACTUAL, this);
-            subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, Attributes.SERVICE_UP, this);
+            subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, Attributes.SERVICE_STATE_ACTUAL, this);
+            subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, Attributes.SERVICE_UP, this);
         }
 
         @Override