brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject incubator-brooklyn git commit: more code review of #705
Date Thu, 25 Jun 2015 14:04:40 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master b5cc2779d -> 664849507


more code review of #705

tidy yaml time enricher,
and don't log location error message so aggressively


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

Branch: refs/heads/master
Commit: 6648495077669378a6540d939e9d8f44a68a1ff6
Parents: b5cc277
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Jun 25 14:20:20 2015 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Thu Jun 25 14:20:20 2015 +0100

----------------------------------------------------------------------
 .../basic/YamlTimeWeightedDeltaEnricher.java    | 41 +++++++++++---------
 .../location/basic/BasicLocationRegistry.java   |  2 +-
 2 files changed, 23 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/66484950/core/src/main/java/brooklyn/enricher/basic/YamlTimeWeightedDeltaEnricher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/enricher/basic/YamlTimeWeightedDeltaEnricher.java
b/core/src/main/java/brooklyn/enricher/basic/YamlTimeWeightedDeltaEnricher.java
index b515da4..5a384e0 100644
--- a/core/src/main/java/brooklyn/enricher/basic/YamlTimeWeightedDeltaEnricher.java
+++ b/core/src/main/java/brooklyn/enricher/basic/YamlTimeWeightedDeltaEnricher.java
@@ -41,6 +41,7 @@ import com.google.common.base.Function;
 public class YamlTimeWeightedDeltaEnricher<T extends Number> extends AbstractTransformer<T,Double>
{
     private static final Logger LOG = LoggerFactory.getLogger(YamlTimeWeightedDeltaEnricher.class);
     
+    transient Object lock = new Object();
     Number lastValue;
     long lastTime = -1;
     
@@ -52,28 +53,30 @@ public class YamlTimeWeightedDeltaEnricher<T extends Number> extends
AbstractTra
         return new Function<SensorEvent<T>, Double>() {
             @Override
             public Double apply(SensorEvent<T> event) {
-                Number current = TypeCoercions.coerce(event.getValue(), Double.class);
-                
-                if (current == null) return null;
+                synchronized (lock) {
+                    Double current = TypeCoercions.coerce(event.getValue(), Double.class);
 
-                long eventTime = event.getTimestamp();
-                long unitMillis = getConfig(DELTA_PERIOD).toMilliseconds();
-                Double result = null;
-                
-                if (eventTime > 0 && eventTime > lastTime) {
-                    if (lastValue == null || lastTime < 0) {
-                        // cannot calculate time-based delta with a single value
-                        if (LOG.isTraceEnabled()) LOG.trace("{} received event but no last
value so will not emit, null -> {} at {}", new Object[] {this, current, eventTime}); 
-                    } else {
-                        double duration = eventTime - lastTime;
-                        result = (current.doubleValue() - lastValue.doubleValue()) / (duration
/ unitMillis);
+                    if (current == null) return null;
+
+                    long eventTime = event.getTimestamp();
+                    long unitMillis = getConfig(DELTA_PERIOD).toMilliseconds();
+                    Double result = null;
+
+                    if (eventTime > 0 && eventTime > lastTime) {
+                        if (lastValue == null || lastTime < 0) {
+                            // cannot calculate time-based delta with a single value
+                            if (LOG.isTraceEnabled()) LOG.trace("{} received event but no
last value so will not emit, null -> {} at {}", new Object[] {this, current, eventTime});

+                        } else {
+                            double duration = eventTime - lastTime;
+                            result = (current - lastValue.doubleValue()) / (duration / unitMillis);
+                        }
                     }
+
+                    lastValue = current;
+                    lastTime = eventTime;
+
+                    return result;
                 }
-                
-                lastValue = current;
-                lastTime = eventTime;
-                
-                return result;
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/66484950/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java b/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java
index 2b1980c..0fc6913 100644
--- a/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java
+++ b/core/src/main/java/brooklyn/location/basic/BasicLocationRegistry.java
@@ -344,7 +344,7 @@ public class BasicLocationRegistry implements LocationRegistry {
                             + resolvers.keySet()+" are the only available location resolvers.
"
                             + "More information can be found in the logs.";
                 } else {
-                    log.warn("Location resolution failed for '"+spec+"' (will fail shortly):
known resolvers are: "+resolvers.keySet());
+                    log.debug("Location resolution failed for '"+spec+"' (if this is being
loaded it will fail shortly): known resolvers are: "+resolvers.keySet());
                     errmsg = "Unknown location '"+spec+"': "
                             + "either this location is not recognised or there is a problem
with location resolver configuration.";
                 }


Mime
View raw message