brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [06/16] git commit: comments and rebind-related tidy-up on use of FIRST
Date Sun, 19 Oct 2014 00:59:53 GMT
comments and rebind-related tidy-up on use of FIRST


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

Branch: refs/heads/master
Commit: 81b027b791553bce9e038adc0cdb69eeb3ad1c3b
Parents: baee8c5
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Sat Oct 18 03:41:26 2014 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Sat Oct 18 03:41:26 2014 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/basic/AbstractGroup.java    |  2 ++
 .../entity/basic/AbstractGroupImpl.java         | 24 ++++++++++++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/81b027b7/core/src/main/java/brooklyn/entity/basic/AbstractGroup.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/AbstractGroup.java b/core/src/main/java/brooklyn/entity/basic/AbstractGroup.java
index ec4ed8b..41a3cc2 100644
--- a/core/src/main/java/brooklyn/entity/basic/AbstractGroup.java
+++ b/core/src/main/java/brooklyn/entity/basic/AbstractGroup.java
@@ -48,9 +48,11 @@ public interface AbstractGroup extends Entity, Group, Changeable {
     AttributeSensor<Collection<Entity>> GROUP_MEMBERS = Sensors.newSensor(
             new TypeToken<Collection<Entity>>() { }, "group.members", "Members
of the group");
 
+    // FIXME should definitely remove this, it is ambiguous if an entity is in multiple clusters.
 also should be "is_first" or something to indicate boolean.
     AttributeSensor<Boolean> FIRST_MEMBER = Sensors.newBooleanSensor(
             "cluster.first", "Set on an entity if it is the first member of a cluster");
 
+    // FIXME can we remove this too?
     AttributeSensor<Entity> FIRST = Sensors.newSensor(Entity.class,
             "cluster.first.entity", "The first member of the cluster");
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/81b027b7/core/src/main/java/brooklyn/entity/basic/AbstractGroupImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/AbstractGroupImpl.java b/core/src/main/java/brooklyn/entity/basic/AbstractGroupImpl.java
index 7da2094..837003c 100644
--- a/core/src/main/java/brooklyn/entity/basic/AbstractGroupImpl.java
+++ b/core/src/main/java/brooklyn/entity/basic/AbstractGroupImpl.java
@@ -117,18 +117,23 @@ public abstract class AbstractGroupImpl extends AbstractEntity implements
Abstra
                 return false;
             }
 
+            // FIXME do not set sensors on members; possibly we don't need FIRST at all,
just look at the first in MEMBERS, and take care to guarantee order there
             Entity first = getAttribute(FIRST);
             if (first == null) {
                 ((EntityLocal) member).setAttribute(FIRST_MEMBER, true);
                 ((EntityLocal) member).setAttribute(FIRST, member);
                 setAttribute(FIRST, member);
             } else {
-                ((EntityLocal) member).setAttribute(FIRST_MEMBER, false);
-                ((EntityLocal) member).setAttribute(FIRST, first);
+                if (first.equals(member) || first.equals(member.getAttribute(FIRST))) {
+                    // do nothing (rebinding)
+                } else {
+                    ((EntityLocal) member).setAttribute(FIRST_MEMBER, false);
+                    ((EntityLocal) member).setAttribute(FIRST, first);
+                }
             }
 
             member.addGroup((Group)getProxyIfAvailable());
-            boolean changed = members.add(member);
+            boolean changed = addMemberInternal(member);
             if (changed) {
                 log.debug("Group {} got new member {}", this, member);
                 setAttribute(GROUP_SIZE, getCurrentSize());
@@ -153,6 +158,13 @@ public abstract class AbstractGroupImpl extends AbstractEntity implements
Abstra
         }
     }
 
+    // visible for rebind
+    public boolean addMemberInternal(Entity member) {
+        synchronized (members) {
+            return members.add(member);
+        }
+    }
+
     /**
      * Returns {@code true} if the group was changed as a result of the call.
      */
@@ -163,9 +175,13 @@ public abstract class AbstractGroupImpl extends AbstractEntity implements
Abstra
             boolean changed = (member != null && members.remove(member));
             if (changed) {
                 log.debug("Group {} lost member {}", this, member);
-                // TODO ideally the following 3 are synched
+                // TODO ideally the following are all synched
                 setAttribute(GROUP_SIZE, getCurrentSize());
                 setAttribute(GROUP_MEMBERS, getMembers());
+                if (member.equals(getAttribute(FIRST))) {
+                    // TODO should we elect a new FIRST ?  as is the *next* will become first.
 could we do away with FIRST altogether?
+                    setAttribute(FIRST, null);
+                }
                 // emit after the above so listeners can use getMembers() and getCurrentSize()
                 emit(MEMBER_REMOVED, member);
 


Mime
View raw message