brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [01/18] incubator-brooklyn git commit: Support suppressDuplicates for attributes in feeds
Date Tue, 11 Aug 2015 20:42:39 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 0dc391191 -> ef3af1213


Support suppressDuplicates for attributes in feeds


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

Branch: refs/heads/master
Commit: 7f046a1ce49591cfabd211c03bbcc57f93c65137
Parents: ee3c1ca
Author: Aled Sage <aled.sage@gmail.com>
Authored: Sat Apr 18 12:50:48 2015 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Aug 11 17:51:12 2015 +0100

----------------------------------------------------------------------
 .../java/brooklyn/event/feed/AttributePollHandler.java | 12 +++++++++++-
 core/src/main/java/brooklyn/event/feed/FeedConfig.java | 13 ++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7f046a1c/core/src/main/java/brooklyn/event/feed/AttributePollHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/feed/AttributePollHandler.java b/core/src/main/java/brooklyn/event/feed/AttributePollHandler.java
index 2029237..1bf39af 100644
--- a/core/src/main/java/brooklyn/event/feed/AttributePollHandler.java
+++ b/core/src/main/java/brooklyn/event/feed/AttributePollHandler.java
@@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Objects;
+
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.basic.EntityInternal;
@@ -52,6 +54,7 @@ public class AttributePollHandler<V> implements PollHandler<V>
{
     @SuppressWarnings("rawtypes")
     private final AttributeSensor sensor;
     private final AbstractFeed feed;
+    private final boolean suppressDuplicates;
     
     // allow 30 seconds before logging at WARN, if there has been no success yet;
     // after success WARN immediately
@@ -64,12 +67,14 @@ public class AttributePollHandler<V> implements PollHandler<V>
{
     private volatile Long currentProblemStartTime = null;
     private volatile boolean currentProblemLoggedAsWarning = false;
     private volatile boolean lastWasProblem = false;
+
     
     public AttributePollHandler(FeedConfig<V,?,?> config, EntityLocal entity, AbstractFeed
feed) {
         this.config = checkNotNull(config, "config");
         this.entity = checkNotNull(entity, "entity");
         this.sensor = checkNotNull(config.getSensor(), "sensor");
         this.feed = checkNotNull(feed, "feed");
+        this.suppressDuplicates = config.getSupressDuplicates();
     }
 
     @Override
@@ -218,7 +223,12 @@ public class AttributePollHandler<V> implements PollHandler<V>
{
         } else if (sensor == FeedConfig.NO_SENSOR) {
             // nothing
         } else {
-            entity.setAttribute(sensor, TypeCoercions.coerce(v, sensor.getType()));
+            Object coercedV = TypeCoercions.coerce(v, sensor.getType());
+            if (suppressDuplicates && Objects.equal(coercedV, entity.getAttribute(sensor)))
{
+                // no change; nothing
+            } else {
+                entity.setAttribute(sensor, coercedV);
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7f046a1c/core/src/main/java/brooklyn/event/feed/FeedConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/event/feed/FeedConfig.java b/core/src/main/java/brooklyn/event/feed/FeedConfig.java
index 64642e1..6796730 100644
--- a/core/src/main/java/brooklyn/event/feed/FeedConfig.java
+++ b/core/src/main/java/brooklyn/event/feed/FeedConfig.java
@@ -62,7 +62,8 @@ public class FeedConfig<V, T, F extends FeedConfig<V, T, F>>
{
     private Function<? super V, T> onfailure;
     private Function<? super Exception, T> onexception;
     private Predicate<? super V> checkSuccess;
-
+    private boolean suppressDuplicates;
+    
     public FeedConfig(AttributeSensor<T> sensor) {
         this.sensor = checkNotNull(sensor, "sensor");
     }
@@ -73,6 +74,7 @@ public class FeedConfig<V, T, F extends FeedConfig<V, T, F>>
{
         this.onfailure = other.onfailure;
         this.onexception = other.onexception;
         this.checkSuccess = other.checkSuccess;
+        this.suppressDuplicates = other.suppressDuplicates;
     }
 
     @SuppressWarnings("unchecked")
@@ -100,6 +102,10 @@ public class FeedConfig<V, T, F extends FeedConfig<V, T, F>>
{
         return onexception;
     }
 
+    public boolean getSupressDuplicates() {
+        return suppressDuplicates;
+    }
+    
     /** sets the predicate used to check whether a feed run is successful */
     public F checkSuccess(Predicate<? super V> val) {
         this.checkSuccess = checkNotNull(val, "checkSuccess");
@@ -175,6 +181,11 @@ public class FeedConfig<V, T, F extends FeedConfig<V, T, F>>
{
         return onFailureOrException(Functions.constant(val));
     }
 
+    public F suppressDuplicates(boolean val) {
+        suppressDuplicates = val;
+        return self();
+    }
+    
     public boolean hasSuccessHandler() {
         return this.onsuccess != null;
     }


Mime
View raw message