brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/2] brooklyn-server git commit: multi-sensor-aggregator: respect the EntityFilter
Date Thu, 17 Mar 2016 18:44:48 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master a16f8c740 -> 16ee522c5


multi-sensor-aggregator: respect the EntityFilter

This is useful for apps that want to override the 
ComputeServiceIndicatorsFromChildrenAndMembers. For example, in 
clocker the app’s health depends on just two of the children (rather 
than all/one or quorum).

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

Branch: refs/heads/master
Commit: f718bff32f127066492b8cf5892b7b7205a0e1ee
Parents: b70c2b0
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Mar 17 06:46:36 2016 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Mar 17 06:46:36 2016 +0000

----------------------------------------------------------------------
 .../core/entity/lifecycle/ServiceStateLogic.java  |  6 ++++++
 .../stock/AbstractMultipleSensorAggregator.java   | 18 +++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f718bff3/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
b/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
index e64e41e..3eaf022 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
@@ -69,6 +69,7 @@ import org.slf4j.LoggerFactory;
 import com.google.common.base.Function;
 import com.google.common.base.Functions;
 import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
 import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -604,6 +605,11 @@ public class ServiceStateLogic {
             configure(ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK,
check);
             return self();
         }
+        
+        public ComputeServiceIndicatorsFromChildrenAndMembersSpec entityFilter(Predicate<?
super Entity> val) {
+            configure(ComputeServiceIndicatorsFromChildrenAndMembers.ENTITY_FILTER, val);
+            return self();
+        }
     }
 
     /** provides the default {@link ComputeServiceIndicatorsFromChildrenAndMembers} enricher,


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f718bff3/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractMultipleSensorAggregator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractMultipleSensorAggregator.java
b/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractMultipleSensorAggregator.java
index d63aa57..e0f0d6d 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractMultipleSensorAggregator.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractMultipleSensorAggregator.java
@@ -20,7 +20,6 @@ package org.apache.brooklyn.enricher.stock;
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -37,7 +36,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
 
 /** Building on {@link AbstractAggregator} for a single source sensor (on multiple children
and/or members) */
 public abstract class AbstractMultipleSensorAggregator<U> extends AbstractAggregator<Object,U>
implements SensorEventListener<Object> {
@@ -129,15 +127,17 @@ public abstract class AbstractMultipleSensorAggregator<U> extends
AbstractAggreg
     @Override
     public void onEvent(SensorEvent<Object> event) {
         Entity e = event.getSource();
-        synchronized (values) {
-            Map<Entity,Object> vs = values.get(event.getSensor().getName());
-            if (vs==null) {
-                LOG.debug(this+" received event when no entry for sensor ("+event+"); likely
just added or removed, and will initialize subsequently if needed");
-            } else {
-                vs.put(e, event.getValue());
+        if (entityFilter.apply(e)) {
+            synchronized (values) {
+                Map<Entity,Object> vs = values.get(event.getSensor().getName());
+                if (vs==null) {
+                    LOG.debug(this+" received event when no entry for sensor ("+event+");
likely just added or removed, and will initialize subsequently if needed");
+                } else {
+                    vs.put(e, event.getValue());
+                }
             }
+            onUpdated();
         }
-        onUpdated();
     }
 
     public <T> Map<Entity,T> getValues(Sensor<T> sensor) {


Mime
View raw message