entity.getAllAttributes() return everything

- Even if the AttributeSensor is unknown for a given key name, still
  return it.
- There’s a race where persister thread calls getAllAttributes() at
  same time as new attribute type is being added to entityType.
  Previously the sensor was not returned, so was not persisted.

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

Branch: refs/heads/master
Commit: 48c7b447a5cf9d29527289a5c2e6f40821fb7196
Parents: 69e2f86
Author: Aled Sage <[email protected]>
Authored: Fri Nov 7 08:19:53 2014 +0000
Committer: Aled Sage <[email protected]>
Committed: Fri Nov 7 08:19:53 2014 +0000

----------------------------------------------------------------------
 .../java/brooklyn/entity/basic/AbstractEntity.java     | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/48c7b447/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java 
b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
index c5ca83a..4590990 100644
--- a/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
+++ b/core/src/main/java/brooklyn/entity/basic/AbstractEntity.java
@@ -55,6 +55,7 @@ import brooklyn.event.SensorEventListener;
 import brooklyn.event.basic.AttributeMap;
 import brooklyn.event.basic.AttributeSensorAndConfigKey;
 import brooklyn.event.basic.BasicNotificationSensor;
+import brooklyn.event.basic.Sensors;
 import brooklyn.event.feed.AbstractFeed;
 import brooklyn.event.feed.ConfigToAttributes;
 import brooklyn.internal.BrooklynFeatureEnablement;
@@ -1032,12 +1033,16 @@ public abstract class AbstractEntity extends 
AbstractBrooklynObject implements E
         Map<AttributeSensor, Object> result = Maps.newLinkedHashMap();
         Map<String, Object> attribs = attributesInternal.asMap();
         for (Map.Entry<String,Object> entry : attribs.entrySet()) {
-            AttributeSensor attribKey = (AttributeSensor) 
entityType.getSensor(entry.getKey());
+            AttributeSensor<?> attribKey = (AttributeSensor<?>) 
entityType.getSensor(entry.getKey());
             if (attribKey == null) {
-                LOG.warn("When retrieving all attributes of {}, ignoring 
attribute {} because no matching AttributeSensor found", this, entry.getKey());
-            } else {
-                result.put(attribKey, entry.getValue());
+                // Most likely a race: e.g. persister thread calling 
getAllAttributes; writer thread
+                // has written attribute value and is in process of calling 
entityType.addSensorIfAbsent(attribute)
+                // Just use a synthetic AttributeSensor, rather than ignoring 
value.
+                // TODO If it's not a race, then don't log.warn every time!
+                LOG.warn("When retrieving all attributes of {}, no 
AttributeSensor for attribute {} (creating synthetic)", this, entry.getKey());
+                attribKey = Sensors.newSensor(Object.class, entry.getKey());
             }
+            result.put(attribKey, entry.getValue());
         }
         return result;
     }

Reply via email to