Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 422F218176 for ; Wed, 23 Sep 2015 10:52:01 +0000 (UTC) Received: (qmail 69797 invoked by uid 500); 23 Sep 2015 10:52:01 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 69772 invoked by uid 500); 23 Sep 2015 10:52:01 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 69763 invoked by uid 99); 23 Sep 2015 10:52:01 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Sep 2015 10:52:01 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B884D180A3D for ; Wed, 23 Sep 2015 10:52:00 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.774 X-Spam-Level: X-Spam-Status: No, score=0.774 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.006] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id FhDQ3NXoBLOW for ; Wed, 23 Sep 2015 10:51:54 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 1632A44473 for ; Wed, 23 Sep 2015 10:51:54 +0000 (UTC) Received: (qmail 69455 invoked by uid 99); 23 Sep 2015 10:51:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Sep 2015 10:51:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8A279E0AF9; Wed, 23 Sep 2015 10:51:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.incubator.apache.org Date: Wed, 23 Sep 2015 10:51:55 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Mon Sep 21 08:20:57 2015 +0100 Committer: Aled Sage 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 { */ void emit(Sensor 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 + SubscriptionHandle subscribe(Entity producer, Sensor sensor, SensorEventListener listener); + + /** @see SubscriptionManager#subscribeToChildren(Map, Entity, Sensor, SensorEventListener) */ + // FIXME remove from interface? + @Beta + SubscriptionHandle subscribeToChildren(Entity parent, Sensor sensor, SensorEventListener listener); + + /** @see SubscriptionManager#subscribeToMembers(Group, Sensor, SensorEventListener) */ + // FIXME remove from interface? + @Beta + SubscriptionHandle subscribeToMembers(Group group, Sensor sensor, SensorEventListener 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 SubscriptionHandle subscribe(Entity producer, Sensor sensor, SensorEventListener listener); @@ -120,14 +122,22 @@ public interface EntityLocal extends Entity { // FIXME remove from interface? @Beta SubscriptionHandle subscribe(Map flags, Entity producer, Sensor sensor, SensorEventListener 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 SubscriptionHandle subscribeToChildren(Entity parent, Sensor sensor, SensorEventListener 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 SubscriptionHandle subscribeToMembers(Group group, Sensor sensor, SensorEventListener 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 SubscriptionHandle subscribe(Entity producer, Sensor sensor, SensorEventListener listener) { + return getSubscriptionTracker().subscribe(producer, sensor, listener); + } + + @Override + public SubscriptionHandle subscribeToChildren(Entity parent, Sensor sensor, SensorEventListener listener) { + return getSubscriptionTracker().subscribeToChildren(parent, sensor, listener); + } + + @Override + public SubscriptionHandle subscribeToMembers(Group group, Sensor sensor, SensorEventListener 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 SubscriptionHandle subscribe(Entity producer, Sensor sensor, SensorEventListener 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 SubscriptionHandle subscribeToChildren(Entity parent, Sensor sensor, SensorEventListener 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 SubscriptionHandle subscribeToMembers(Group group, Sensor sensor, SensorEventListener 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(); + } }