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:55 UTC
[03/10] incubator-brooklyn git commit: Create entity.subscriptions()
for grouping
Create entity.subscriptions() for grouping
- Deprecate EntityLocal.*subscri*()
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/3e46621c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/3e46621c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/3e46621c
Branch: refs/heads/master
Commit: 3e46621cf490569289954ffadc631e1b6e99df03
Parents: 1a6c4e3
Author: Aled Sage <al...@gmail.com>
Authored: Mon Sep 21 08:20:57 2015 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Sep 23 10:32:55 2015 +0100
----------------------------------------------------------------------
.../org/apache/brooklyn/api/entity/Entity.java | 47 ++++++-
.../apache/brooklyn/api/entity/EntityLocal.java | 28 ++++-
.../brooklyn/core/entity/AbstractEntity.java | 122 ++++++++++++++++---
.../brooklyn/core/entity/EntityInternal.java | 15 ++-
4 files changed, 183 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3e46621c/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java b/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java
index 612ce29..8388d28 100644
--- a/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java
+++ b/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java
@@ -25,9 +25,11 @@ import javax.annotation.Nullable;
import org.apache.brooklyn.api.effector.Effector;
import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.mgmt.SubscriptionContext;
+import org.apache.brooklyn.api.mgmt.SubscriptionHandle;
+import org.apache.brooklyn.api.mgmt.SubscriptionManager;
import org.apache.brooklyn.api.mgmt.Task;
import org.apache.brooklyn.api.objs.BrooklynObject;
-import org.apache.brooklyn.api.objs.Configurable.ConfigurationSupport;
import org.apache.brooklyn.api.policy.Policy;
import org.apache.brooklyn.api.policy.PolicySpec;
import org.apache.brooklyn.api.sensor.AttributeSensor;
@@ -36,6 +38,7 @@ import org.apache.brooklyn.api.sensor.EnricherSpec;
import org.apache.brooklyn.api.sensor.Feed;
import org.apache.brooklyn.api.sensor.Sensor;
import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
import org.apache.brooklyn.util.guava.Maybe;
@@ -274,6 +277,8 @@ public interface Entity extends BrooklynObject {
SensorSupport sensors();
+ SubscriptionSupport subscriptions();
+
@Beta
public interface SensorSupport {
@@ -319,4 +324,44 @@ public interface Entity extends BrooklynObject {
*/
<T> void emit(Sensor<T> sensor, T value);
}
+
+ @Beta
+ public interface SubscriptionSupport {
+ /**
+ * 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(Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener);
+
+ /** @see SubscriptionManager#subscribeToChildren(Map, Entity, Sensor, SensorEventListener) */
+ // FIXME remove from interface?
+ @Beta
+ <T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, SensorEventListener<? super T> listener);
+
+ /** @see SubscriptionManager#subscribeToMembers(Group, Sensor, SensorEventListener) */
+ // FIXME remove from interface?
+ @Beta
+ <T> SubscriptionHandle subscribeToMembers(Group group, Sensor<T> sensor, SensorEventListener<? super T> listener);
+
+ /**
+ * Unsubscribes from the given producer.
+ *
+ * @see SubscriptionContext#unsubscribe(SubscriptionHandle)
+ */
+ @Beta
+ boolean unsubscribe(Entity producer);
+
+ /**
+ * Unsubscribes the given handle.
+ *
+ * @see SubscriptionContext#unsubscribe(SubscriptionHandle)
+ */
+ @Beta
+ boolean unsubscribe(Entity producer, SubscriptionHandle handle);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3e46621c/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 b3fa078..c0b7a42 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
@@ -105,8 +105,10 @@ public interface EntityLocal extends Entity {
* @return a subscription id which can be used to unsubscribe
*
* @see SubscriptionManager#subscribe(Map, Entity, Sensor, SensorEventListener)
+ *
+ * @deprecated since 0.9.0; see {@link SubscriptionSupportInternal#getSubscriptionContext()}, e.g. with {@code subscriptions().getSubscriptionContext()}
*/
- // FIXME remove from interface?
+ @Deprecated
@Beta
<T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener);
@@ -120,14 +122,22 @@ public interface EntityLocal extends Entity {
// 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) */
- // FIXME remove from interface?
+
+ /**
+ * @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(...)}
+ */
+ @Deprecated
@Beta
<T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, SensorEventListener<? super T> listener);
- /** @see SubscriptionManager#subscribeToMembers(Group, Sensor, SensorEventListener) */
- // FIXME remove from interface?
+ /**
+ * @see SubscriptionManager#subscribeToMembers(Group, Sensor, SensorEventListener)
+ *
+ * @deprecated since 0.9.0; see {@link SubscriptionSupport#subscribeToMembers(Entity, Sensor, SensorEventListener)}, e.g. with {@code subscriptions().subscribeToMembers(...)}
+ */
+ @Deprecated
@Beta
<T> SubscriptionHandle subscribeToMembers(Group group, Sensor<T> sensor, SensorEventListener<? super T> listener);
@@ -135,7 +145,10 @@ public interface EntityLocal extends Entity {
* Unsubscribes from the given producer.
*
* @see SubscriptionContext#unsubscribe(SubscriptionHandle)
+ *
+ * @deprecated since 0.9.0; see {@link SubscriptionSupport#unsubscribe(Entity)}, e.g. with {@code subscriptions().unsubscribe(...)}
*/
+ @Deprecated
@Beta
boolean unsubscribe(Entity producer);
@@ -143,7 +156,10 @@ public interface EntityLocal extends Entity {
* Unsubscribes the given handle.
*
* @see SubscriptionContext#unsubscribe(SubscriptionHandle)
+ *
+ * @deprecated since 0.9.0; see {@link SubscriptionSupport#unsubscribe(Entity, SubscriptionHandle)}, e.g. with {@code subscriptions().unsubscribe(...)}
*/
+ @Deprecated
@Beta
boolean unsubscribe(Entity producer, SubscriptionHandle handle);
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3e46621c/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 03254dd..7a626a4 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
@@ -220,6 +220,8 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
private final BasicSensorSupport sensors = new BasicSensorSupport();
+ private final BasicSubscriptionSupport subscriptions = new BasicSubscriptionSupport();
+
/**
* The config values of this entity. Updating this map should be done
* via getConfig/setConfig.
@@ -1331,10 +1333,83 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
// -------- SUBSCRIPTIONS --------------
- /** @see EntityLocal#subscribe */
+ @Override
+ @Beta
+ // the concrete type rather than an interface is returned because Groovy subclasses
+ // complain (incorrectly) if we return SubscriptionSupportInternal
+ // TODO revert to SubscriptionSupportInternal when groovy subclasses work without this (eg new groovy version)
+ public BasicSubscriptionSupport subscriptions() {
+ return subscriptions;
+ }
+
+ /**
+ * Direct use of this class is strongly discouraged. It will become private in a future release,
+ * once {@link #subscriptions()} is reverted to return {@link SubscriptionSupportInternal} instead of
+ * {@link BasicSubscriptionSupport}.
+ */
+ @Beta
+ // TODO revert to private when config() is reverted to return SensorSupportInternal
+ public class BasicSubscriptionSupport implements SubscriptionSupportInternal {
+
+ @Override
+ public <T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener) {
+ return getSubscriptionTracker().subscribe(producer, sensor, listener);
+ }
+
+ @Override
+ public <T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, SensorEventListener<? super T> listener) {
+ return getSubscriptionTracker().subscribeToChildren(parent, sensor, listener);
+ }
+
+ @Override
+ public <T> SubscriptionHandle subscribeToMembers(Group group, Sensor<T> sensor, SensorEventListener<? super T> listener) {
+ return getSubscriptionTracker().subscribeToMembers(group, sensor, listener);
+ }
+
+ /**
+ * Unsubscribes the given producer.
+ *
+ * @see SubscriptionContext#unsubscribe(SubscriptionHandle)
+ */
+ @Override
+ public boolean unsubscribe(Entity producer) {
+ return getSubscriptionTracker().unsubscribe(producer);
+ }
+
+ /**
+ * Unsubscribes the given handle.
+ *
+ * @see SubscriptionContext#unsubscribe(SubscriptionHandle)
+ */
+ @Override
+ public boolean unsubscribe(Entity producer, SubscriptionHandle handle) {
+ return getSubscriptionTracker().unsubscribe(producer, handle);
+ }
+
+ @Override
+ public SubscriptionContext getSubscriptionContext() {
+ synchronized (AbstractEntity.this) {
+ return getManagementSupport().getSubscriptionContext();
+ }
+ }
+
+ protected SubscriptionTracker getSubscriptionTracker() {
+ synchronized (AbstractEntity.this) {
+ if (_subscriptionTracker == null) {
+ _subscriptionTracker = new SubscriptionTracker(getSubscriptionContext());
+ }
+ return _subscriptionTracker;
+ }
+ }
+ }
+
+ /**
+ * @deprecated since 0.9.0; see {@code subscriptions().subscribe(producer, sensor, listener)}
+ */
@Override
+ @Deprecated
public <T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener) {
- return getSubscriptionTracker().subscribe(producer, sensor, listener);
+ return subscriptions().subscribe(producer, sensor, listener);
}
/** @see EntityLocal#subscribe */
@@ -1344,48 +1419,57 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
return getSubscriptionTracker().subscribe(flags, producer, sensor, listener);
}
- /** @see EntityLocal#subscribeToChildren */
+ /**
+ * @deprecated since 0.9.0; see {@code subscriptions().subscribeToChildren(parent, sensor, listener)}
+ */
@Override
+ @Deprecated
public <T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, SensorEventListener<? super T> listener) {
- return getSubscriptionTracker().subscribeToChildren(parent, sensor, listener);
+ return subscriptions().subscribeToChildren(parent, sensor, listener);
}
- /** @see EntityLocal#subscribeToMembers */
+ /**
+ * @deprecated since 0.9.0; see {@code subscriptions().subscribeToMembers(producer, sensor, listener)}
+ */
@Override
+ @Deprecated
public <T> SubscriptionHandle subscribeToMembers(Group group, Sensor<T> sensor, SensorEventListener<? super T> listener) {
- return getSubscriptionTracker().subscribeToMembers(group, sensor, listener);
+ return subscriptions().subscribeToMembers(group, sensor, listener);
}
/**
- * Unsubscribes the given producer.
- *
- * @see SubscriptionContext#unsubscribe(SubscriptionHandle)
+ * @deprecated since 0.9.0; see {@code subscriptions().unsubscribe(producer)}
*/
@Override
+ @Deprecated
public boolean unsubscribe(Entity producer) {
- return getSubscriptionTracker().unsubscribe(producer);
+ return subscriptions().unsubscribe(producer);
}
/**
- * Unsubscribes the given handle.
- *
- * @see SubscriptionContext#unsubscribe(SubscriptionHandle)
+ * @deprecated since 0.9.0; see {@code subscriptions().unsubscribe(producer, handle)}
*/
@Override
+ @Deprecated
public boolean unsubscribe(Entity producer, SubscriptionHandle handle) {
- return getSubscriptionTracker().unsubscribe(producer, handle);
+ return subscriptions().unsubscribe(producer, handle);
}
+ /**
+ * @deprecated since 0.9.0; see {@code subscriptions().getSubscriptionContext()}
+ */
@Override
+ @Deprecated
public synchronized SubscriptionContext getSubscriptionContext() {
- return getManagementSupport().getSubscriptionContext();
+ return subscriptions().getSubscriptionContext();
}
+ /**
+ * @deprecated since 0.9.0; for internal use only
+ */
+ @Deprecated
protected synchronized SubscriptionTracker getSubscriptionTracker() {
- if (_subscriptionTracker == null) {
- _subscriptionTracker = new SubscriptionTracker(getSubscriptionContext());
- }
- return _subscriptionTracker;
+ return subscriptions().getSubscriptionTracker();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/3e46621c/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java b/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java
index 3811ce8..1ebcaf1 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/EntityInternal.java
@@ -151,7 +151,11 @@ public interface EntityInternal extends BrooklynObjectInternal, EntityLocal, Reb
* Do not cache this object; instead call getExecutionContext() each time you need to use it.
*/
ExecutionContext getExecutionContext();
-
+
+ /**
+ * @deprecated since 0.9.0; see {@link SubscriptionSupportInternal#getSubscriptionContext()}, e.g. with {@code subscriptions().getSubscriptionContext()}
+ */
+ @Deprecated
SubscriptionContext getSubscriptionContext();
/** returns the dynamic type corresponding to the type of this entity instance */
@@ -190,6 +194,8 @@ public interface EntityInternal extends BrooklynObjectInternal, EntityLocal, Reb
SensorSupportInternal sensors();
+ SubscriptionSupportInternal subscriptions();
+
@Beta
public interface SensorSupportInternal extends Entity.SensorSupport {
/**
@@ -203,8 +209,6 @@ public interface EntityInternal extends BrooklynObjectInternal, EntityLocal, Reb
@Beta
void remove(AttributeSensor<?> attribute);
-
-
}
public interface FeedSupport {
@@ -228,4 +232,9 @@ public interface EntityInternal extends BrooklynObjectInternal, EntityLocal, Reb
*/
boolean removeAllFeeds();
}
+
+ @Beta
+ public interface SubscriptionSupportInternal extends Entity.SubscriptionSupport {
+ SubscriptionContext getSubscriptionContext();
+ }
}