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:57 UTC
[05/10] incubator-brooklyn git commit: Adds Entity.groups(),
for group-related methods
Adds Entity.groups(), for group-related methods
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/7708363a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/7708363a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/7708363a
Branch: refs/heads/master
Commit: 7708363a26dc50c747ea980e600a9a3e01530ac7
Parents: 4ad6cc9
Author: Aled Sage <al...@gmail.com>
Authored: Mon Sep 21 10:14:14 2015 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Sep 23 10:33:50 2015 +0100
----------------------------------------------------------------------
.../org/apache/brooklyn/api/entity/Entity.java | 39 +++++++++
.../brooklyn/core/entity/AbstractEntity.java | 91 +++++++++++++++-----
2 files changed, 109 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7708363a/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 dd141f0..d302cff 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
@@ -178,7 +178,10 @@ public interface Entity extends BrooklynObject {
* The {@link Collection} of {@link Group}s that this entity is a member of.
*
* Groupings can be used to allow easy management/monitoring of a group of entities.
+ *
+ * @deprecated since 0.9.0; see {@link GroupSupport#getGroups()} and {@link #groups()}
*/
+ @Deprecated
Collection<Group> getGroups();
/**
@@ -187,7 +190,10 @@ public interface Entity extends BrooklynObject {
* Users should call {@link Group#addMember(Entity)} instead; this method will then
* automatically be called. However, the reverse is not true (calling this method will
* not tell the group; this behaviour may change in a future release!)
+ *
+ * @deprecated since 0.9.0; see {@link GroupSupport#getGroups()} and {@link #groups()}
*/
+ @Deprecated
void addGroup(Group group);
/**
@@ -196,7 +202,10 @@ public interface Entity extends BrooklynObject {
* Users should call {@link Group#removeMember(Entity)} instead; this method will then
* automatically be called. However, the reverse is not true (calling this method will
* not tell the group; this behaviour may change in a future release!)
+ *
+ * @deprecated since 0.9.0; see {@link GroupSupport#getGroups()} and {@link #groups()}
*/
+ @Deprecated
void removeGroup(Group group);
/**
@@ -305,6 +314,8 @@ public interface Entity extends BrooklynObject {
EnricherSupport enrichers();
+ GroupSupport groups();
+
@Beta
public interface SensorSupport {
@@ -398,4 +409,32 @@ public interface Entity extends BrooklynObject {
*/
boolean removeEnricher(Enricher enricher);
}
+
+ @Beta
+ public interface GroupSupport {
+ /**
+ * The {@link Collection} of {@link Group}s that this entity is a member of.
+ *
+ * Groupings can be used to allow easy management/monitoring of a group of entities.
+ */
+ Collection<Group> getGroups();
+
+ /**
+ * Add this entity as a member of the given {@link Group}. Called by framework.
+ * <p>
+ * Users should call {@link Group#addMember(Entity)} instead; this method will then
+ * automatically be called. However, the reverse is not true (calling this method will
+ * not tell the group; this behaviour may change in a future release!)
+ */
+ void addGroup(Group group);
+
+ /**
+ * Removes this entity as a member of the given {@link Group}. Called by framework.
+ * <p>
+ * Users should call {@link Group#removeMember(Entity)} instead; this method will then
+ * automatically be called. However, the reverse is not true (calling this method will
+ * not tell the group; this behaviour may change in a future release!)
+ */
+ void removeGroup(Group group);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7708363a/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 48a07a4..0084038 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
@@ -190,7 +190,7 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
// then we need temp vals here. When setManagementContext is called, we'll switch these out for the read-deal;
// i.e. for the values backed by storage
private Reference<Entity> parent = new BasicReference<Entity>();
- private Set<Group> groups = Sets.newLinkedHashSet();
+ private Set<Group> groupsInternal = Sets.newLinkedHashSet();
private Set<Entity> children = Sets.newLinkedHashSet();
private Reference<List<Location>> locations = new BasicReference<List<Location>>(ImmutableList.<Location>of()); // dups removed in addLocations
private Reference<Long> creationTimeUtc = new BasicReference<Long>(System.currentTimeMillis());
@@ -226,6 +226,8 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
private final BasicEnricherSupport enrichers = new BasicEnricherSupport();
+ private final BasicGroupSupport groups = new BasicGroupSupport();
+
/**
* The config values of this entity. Updating this map should be done
* via getConfig/setConfig.
@@ -467,7 +469,7 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
if (BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_USE_BROOKLYN_LIVE_OBJECTS_DATAGRID_STORAGE)) {
Entity oldParent = parent.get();
- Set<Group> oldGroups = groups;
+ Set<Group> oldGroups = groupsInternal;
Set<Entity> oldChildren = children;
List<Location> oldLocations = locations.get();
EntityConfigMap oldConfig = configsInternal;
@@ -477,7 +479,7 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
String oldIconUrl = iconUrl.get();
parent = managementContext.getStorage().getReference(getId()+"-parent");
- groups = SetFromLiveMap.create(managementContext.getStorage().<Group,Boolean>getMap(getId()+"-groups"));
+ groupsInternal = SetFromLiveMap.create(managementContext.getStorage().<Group,Boolean>getMap(getId()+"-groups"));
children = SetFromLiveMap.create(managementContext.getStorage().<Entity,Boolean>getMap(getId()+"-children"));
locations = managementContext.getStorage().getNonConcurrentList(getId()+"-locations");
creationTimeUtc = managementContext.getStorage().getReference(getId()+"-creationTime");
@@ -491,7 +493,7 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
// before setting the parent etc. However, for backwards compatibility we still support some
// things calling the entity's constructor directly.
if (oldParent != null) parent.set(oldParent);
- if (oldGroups.size() > 0) groups.addAll(oldGroups);
+ if (oldGroups.size() > 0) groupsInternal.addAll(oldGroups);
if (oldChildren.size() > 0) children.addAll(oldChildren);
if (oldLocations.size() > 0) locations.set(ImmutableList.copyOf(oldLocations));
if (creationTimeUtc.isNull()) creationTimeUtc.set(oldCreationTimeUtc);
@@ -685,26 +687,78 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
return changed;
}
- @Override
- public void addGroup(Group group) {
- boolean changed = groups.add(group);
- getApplication();
+ // -------- GROUPS --------------
+
+ @Override
+ @Beta
+ // the concrete type rather than an interface is returned because Groovy subclasses
+ // complain (incorrectly) if we return EnricherSupportInternal
+ // TODO revert to EnricherSupportInternal when groovy subclasses work without this (eg new groovy version)
+ public BasicGroupSupport groups() {
+ return groups;
+ }
+
+ /**
+ * Direct use of this class is strongly discouraged. It will become private in a future release,
+ * once {@link #groups()} is reverted to return {@link {GroupSupport} instead of
+ * {@link BasicGroupSupport}.
+ */
+ @Beta
+ // TODO revert to private when groups() is reverted to return GroupSupport
+ public class BasicGroupSupport implements GroupSupport {
+ @Override
+ public void addGroup(Group group) {
+ boolean changed = groupsInternal.add(group);
+ getApplication();
+
+ if (changed) {
+ emit(AbstractEntity.GROUP_ADDED, group);
+ }
+ }
+
+ @Override
+ public void removeGroup(Group group) {
+ boolean changed = groupsInternal.remove(group);
+ getApplication();
+
+ if (changed) {
+ emit(AbstractEntity.GROUP_REMOVED, group);
+ }
+ }
- if (changed) {
- emit(AbstractEntity.GROUP_ADDED, group);
+ @Override
+ public Collection<Group> getGroups() {
+ return ImmutableList.copyOf(groupsInternal);
}
}
+
+ /**
+ * @deprecated since 0.9.0; see {@link #groups()} and {@link GroupSupport#addGroup(Group)}
+ */
+ @Override
+ @Deprecated
+ public void addGroup(Group group) {
+ groups().addGroup(group);
+ }
+ /**
+ * @deprecated since 0.9.0; see {@link #groups()} and {@link GroupSupport#removeGroup(Group)}
+ */
@Override
+ @Deprecated
public void removeGroup(Group group) {
- boolean changed = groups.remove(group);
- getApplication();
-
- if (changed) {
- emit(AbstractEntity.GROUP_REMOVED, group);
- }
+ groups().removeGroup(group);
}
+ /**
+ * @deprecated since 0.9.0; see {@link #groups()} and {@link GroupSupport#getGroups()}
+ */
+ @Override
+ @Deprecated
+ public Collection<Group> getGroups() {
+ return groups().getGroups();
+ }
+
@Override
public Entity getParent() {
return parent.get();
@@ -715,11 +769,6 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
return ImmutableList.copyOf(children);
}
- @Override
- public Collection<Group> getGroups() {
- return ImmutableList.copyOf(groups);
- }
-
/**
* Returns the application, looking it up if not yet known (registering if necessary)
*/