brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [3/7] brooklyn-server git commit: AbstractTransformingEnricher sub-classes: use EnricherSpec
Date Mon, 12 Jun 2017 14:47:22 GMT
AbstractTransformingEnricher sub-classes: use EnricherSpec


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

Branch: refs/heads/master
Commit: 263304b2410e21d58f34c02edaa5f6b5fc58ec0a
Parents: 91c4a5d
Author: Aled Sage <aled.sage@gmail.com>
Authored: Sun Jun 11 13:54:26 2017 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Sun Jun 11 14:57:39 2017 +0100

----------------------------------------------------------------------
 .../stock/AbstractTransformingEnricher.java     |  4 +-
 .../stock/AbstractTypeTransformingEnricher.java |  6 +--
 .../brooklyn/policy/enricher/DeltaEnricher.java |  7 ++-
 .../policy/enricher/RollingMeanEnricher.java    | 15 +++++-
 .../enricher/RollingTimeWindowMeanEnricher.java | 22 ++++----
 .../enricher/TimeFractionDeltaEnricher.java     | 56 ++++++++++++++++++--
 .../enricher/TimeWeightedDeltaEnricher.java     | 36 +++++++++++--
 .../policy/enricher/DeltaEnrichersTests.java    | 38 +++++++++----
 .../policy/enricher/RebindEnricherTest.java     | 30 +++++++++--
 .../enricher/RollingMeanEnricherTest.java       | 22 ++++++--
 .../RollingTimeWindowMeanEnricherTest.java      | 15 ++++--
 .../enricher/TimeFractionDeltaEnricherTest.java | 52 +++++++++---------
 .../brooklyn/entity/java/JavaAppUtils.java      | 16 ++++--
 .../entity/java/VanillaJavaAppRebindTest.java   | 16 ++++--
 .../org/apache/brooklyn/util/time/Duration.java |  5 ++
 15 files changed, 258 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformingEnricher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformingEnricher.java
b/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformingEnricher.java
index 6378421..37b8b28 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformingEnricher.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTransformingEnricher.java
@@ -29,10 +29,10 @@ import org.apache.brooklyn.api.sensor.Sensor;
 @Deprecated
 public abstract class AbstractTransformingEnricher<T> extends AbstractTypeTransformingEnricher<T,T>
{
 
-    public AbstractTransformingEnricher() { // for rebinding
+    protected AbstractTransformingEnricher() { // for EnricherSpec and rebinding
     }
     
-    public AbstractTransformingEnricher(Entity producer, Sensor<T> source, Sensor<T>
target) {
+    protected AbstractTransformingEnricher(Entity producer, Sensor<T> source, Sensor<T>
target) {
         super(producer, source, target);
     }
     

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTypeTransformingEnricher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTypeTransformingEnricher.java
b/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTypeTransformingEnricher.java
index 47b9dcf..4c5294d 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTypeTransformingEnricher.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/AbstractTypeTransformingEnricher.java
@@ -39,15 +39,15 @@ public abstract class AbstractTypeTransformingEnricher<T,U> extends
AbstractEnri
     private Entity producer;
     
     @SetFromFlag
-    private Sensor<T> source;
+    protected Sensor<T> source;
     
     @SetFromFlag
     protected Sensor<U> target;
 
-    public AbstractTypeTransformingEnricher() { // for rebind
+    protected AbstractTypeTransformingEnricher() { // for EnricherSpec and rebind
     }
     
-    public AbstractTypeTransformingEnricher(Entity producer, Sensor<T> source, Sensor<U>
target) {
+    protected AbstractTypeTransformingEnricher(Entity producer, Sensor<T> source, Sensor<U>
target) {
         this.producer = producer;
         this.source = source;
         this.target = target;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/main/java/org/apache/brooklyn/policy/enricher/DeltaEnricher.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/org/apache/brooklyn/policy/enricher/DeltaEnricher.java b/policy/src/main/java/org/apache/brooklyn/policy/enricher/DeltaEnricher.java
index 1320e45..83da4ca 100644
--- a/policy/src/main/java/org/apache/brooklyn/policy/enricher/DeltaEnricher.java
+++ b/policy/src/main/java/org/apache/brooklyn/policy/enricher/DeltaEnricher.java
@@ -23,6 +23,7 @@ import static org.apache.brooklyn.util.JavaGroovyEquivalents.elvis;
 import org.apache.brooklyn.api.catalog.Catalog;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.api.sensor.SensorEvent;
 import org.apache.brooklyn.enricher.stock.AbstractTransformingEnricher;
@@ -36,9 +37,13 @@ import org.apache.brooklyn.util.core.flags.TypeCoercions;
 public class DeltaEnricher<T extends Number> extends AbstractTransformingEnricher<T>
{
     Number last = 0;
 
-    public DeltaEnricher() { // for rebinding
+    public DeltaEnricher() { // for EnricherSpec and rebinding
     }
     
+    /**
+     * @deprecated since 0.12.0; use {@link EnricherSpec}
+     */
+    @Deprecated
     public DeltaEnricher(Entity producer, Sensor<T> source, AttributeSensor<T>
target) {
         super(producer, source, target);
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricher.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricher.java
b/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricher.java
index 082b851..c403cda 100644
--- a/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricher.java
+++ b/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricher.java
@@ -23,6 +23,7 @@ import java.util.LinkedList;
 import org.apache.brooklyn.api.catalog.Catalog;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.SensorEvent;
 import org.apache.brooklyn.enricher.stock.AbstractTypeTransformingEnricher;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
@@ -41,9 +42,13 @@ public class RollingMeanEnricher<T extends Number> extends AbstractTypeTransform
     @SetFromFlag
     int windowSize;
 
-    public RollingMeanEnricher() { // for rebinding
+    public RollingMeanEnricher() { // for EnricherSpec and rebinding
     }
     
+    /**
+     * @deprecated since 0.12.0; use {@link EnricherSpec}
+     */
+    @Deprecated
     public RollingMeanEnricher(Entity producer, AttributeSensor<T> source, AttributeSensor<Double>
target,
             int windowSize) {
         super(producer, source, target);
@@ -52,6 +57,14 @@ public class RollingMeanEnricher<T extends Number> extends AbstractTypeTransform
             this.uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"->"+target.getName();
     }
     
+    @Override
+    public void init() {
+        super.init();
+        if (uniqueTag == null && source != null && target != null) {
+            uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"->"+target.getName();
+        }
+    }
+    
     /** @returns null when no data has been received or windowSize is 0 */
     public Double getAverage() {
         pruneValues();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricher.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricher.java
b/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricher.java
index cd16eaa..6a023d8 100644
--- a/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricher.java
+++ b/policy/src/main/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricher.java
@@ -24,6 +24,7 @@ import java.util.LinkedList;
 import org.apache.brooklyn.api.catalog.Catalog;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.api.sensor.SensorEvent;
 import org.apache.brooklyn.config.ConfigKey;
@@ -97,23 +98,24 @@ public class RollingTimeWindowMeanEnricher<T extends Number> extends
AbstractTyp
     public RollingTimeWindowMeanEnricher() { // for rebinding
     }
 
+    /**
+     * @deprecated since 0.12.0; use {@link EnricherSpec}
+     */
+    @Deprecated
     public RollingTimeWindowMeanEnricher(Entity producer, AttributeSensor<T> source,

         AttributeSensor<Double> target, Duration timePeriod) {
         super(producer, source, target);
         this.timePeriod = Preconditions.checkNotNull(timePeriod, "timePeriod");
-        
-        if (source!=null && target!=null)
-            this.uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"/"+timePeriod+"->"+target.getName();
     }
 
-    /** @deprecated since 0.6.0 use Duration parameter rather than long with millis */
-    @Deprecated
-    public RollingTimeWindowMeanEnricher(Entity producer, AttributeSensor<T> source,

-            AttributeSensor<Double> target, long timePeriod) {
-        this(producer, source, target, Duration.millis(timePeriod));
+    @Override
+    public void init() {
+        super.init();
+        if (uniqueTag == null && source != null && target != null) {
+            uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"/"+timePeriod+"->"+target.getName();
+        }
     }
-
-
+    
     @Override
     public void onEvent(SensorEvent<T> event) {
         onEvent(event, event.getTimestamp());

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricher.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricher.java
b/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricher.java
index e8db170..c6c0d28 100644
--- a/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricher.java
+++ b/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricher.java
@@ -21,16 +21,17 @@ package org.apache.brooklyn.policy.enricher;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.brooklyn.api.catalog.Catalog;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.api.sensor.SensorEvent;
 import org.apache.brooklyn.enricher.stock.AbstractTypeTransformingEnricher;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
 import org.apache.brooklyn.util.javalang.JavaClassNames;
 import org.apache.brooklyn.util.time.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Converts an absolute measure of time into a fraction of time, based on the delta between
consecutive values 
@@ -46,8 +47,16 @@ import org.apache.brooklyn.util.time.Duration;
 public class TimeFractionDeltaEnricher<T extends Number> extends AbstractTypeTransformingEnricher<T,Double>
{
     private static final Logger LOG = LoggerFactory.getLogger(TimeFractionDeltaEnricher.class);
     
+    /**
+     * @deprecated since 0.12.0; use {@link #durationPerOrigUnit}
+     */
+    //Kept for backwards compatibility with persisted state.
+    @SetFromFlag
+    @Deprecated
+    private Long nanosPerOrigUnit;
+    
     @SetFromFlag
-    private long nanosPerOrigUnit;
+    private Duration durationPerOrigUnit;
     
     protected Number lastValue;
     protected long lastTimestamp = -1;
@@ -55,10 +64,18 @@ public class TimeFractionDeltaEnricher<T extends Number> extends
AbstractTypeTra
     public TimeFractionDeltaEnricher() { // for rebinding
     }
     
+    /**
+     * @deprecated since 0.12.0; use {@link EnricherSpec}
+     */
+    @Deprecated
     public TimeFractionDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double>
target, TimeUnit origUnits) {
         this(producer, source, target, origUnits.toNanos(1));
     }
     
+    /**
+     * @deprecated since 0.12.0; use {@link EnricherSpec}
+     */
+    @Deprecated
     public TimeFractionDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double>
target, long nanosPerOrigUnit) {
         super(producer, source, target);
         this.nanosPerOrigUnit = nanosPerOrigUnit;
@@ -68,6 +85,37 @@ public class TimeFractionDeltaEnricher<T extends Number> extends
AbstractTypeTra
     }
     
     @Override
+    public void init() {
+        super.init();
+        if (durationPerOrigUnit == null) {
+            if (nanosPerOrigUnit != null) {
+                durationPerOrigUnit = Duration.nanos(nanosPerOrigUnit);
+            } else {
+                durationPerOrigUnit = Duration.nanos(1);
+            }
+        }
+        nanosPerOrigUnit = null;
+        
+        if (uniqueTag == null && source != null && target != null) {
+            uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"*"+durationPerOrigUnit+"->"+target.getName();
+        }
+    }
+    
+    @Override
+    public void rebind() {
+        super.rebind();
+        
+        if (durationPerOrigUnit == null) {
+            if (nanosPerOrigUnit != null) {
+                durationPerOrigUnit = Duration.nanos(nanosPerOrigUnit);
+            } else {
+                durationPerOrigUnit = Duration.nanos(1);
+            }
+        }
+        nanosPerOrigUnit = null;
+    }
+    
+    @Override
     public void onEvent(SensorEvent<T> event) {
         onEvent(event, event.getTimestamp());
     }
@@ -93,7 +141,7 @@ public class TimeFractionDeltaEnricher<T extends Number> extends
AbstractTypeTra
                         new Object[] {this, lastValue, lastTimestamp, current, eventTimestamp});
             } else {
                 long duration = eventTimestamp - lastTimestamp;
-                double fraction = toNanos(current.doubleValue() - lastValue.doubleValue(),
nanosPerOrigUnit) / TimeUnit.MILLISECONDS.toNanos(duration);
+                double fraction = toNanos(current.doubleValue() - lastValue.doubleValue(),
durationPerOrigUnit.nanos()) / TimeUnit.MILLISECONDS.toNanos(duration);
                 entity.sensors().set((AttributeSensor<Double>)target, fraction);
                 if (LOG.isTraceEnabled()) LOG.trace("set {} to {}, {} -> {} at {} (previous
at {})", 
                         new Object[] {this, fraction, lastValue, current, eventTimestamp,
lastTimestamp}); 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeWeightedDeltaEnricher.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeWeightedDeltaEnricher.java
b/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeWeightedDeltaEnricher.java
index 3f48433..6237839 100644
--- a/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeWeightedDeltaEnricher.java
+++ b/policy/src/main/java/org/apache/brooklyn/policy/enricher/TimeWeightedDeltaEnricher.java
@@ -18,11 +18,10 @@
  */
 package org.apache.brooklyn.policy.enricher;
 
-import groovy.lang.Closure;
-
 import org.apache.brooklyn.api.catalog.Catalog;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.api.sensor.SensorEvent;
 import org.apache.brooklyn.enricher.stock.AbstractTypeTransformingEnricher;
@@ -38,6 +37,8 @@ import com.google.common.annotations.Beta;
 import com.google.common.base.Function;
 import com.google.common.base.Functions;
 
+import groovy.lang.Closure;
+
 /**
  * Converts an absolute sensor into a delta sensor (i.e. the diff between the current and
previous value),
  * presented as a units/timeUnit based on the event timing.
@@ -68,6 +69,10 @@ public class TimeWeightedDeltaEnricher<T extends Number> extends
AbstractTypeTra
     @SetFromFlag
     Function<Double,Double> postProcessor;
     
+    /**
+     * @deprecated since 0.12.0; use {@link EnricherSpec}
+     */
+    @Deprecated
     // default 1 second
     public static <T extends Number> TimeWeightedDeltaEnricher<T> getPerSecondDeltaEnricher(Entity
producer, Sensor<T> source, Sensor<Double> target) {
         return new TimeWeightedDeltaEnricher<T>(producer, source, target, 1000);
@@ -76,18 +81,26 @@ public class TimeWeightedDeltaEnricher<T extends Number> extends
AbstractTypeTra
     public TimeWeightedDeltaEnricher() { // for rebind
     }
     
+    /**
+     * @deprecated since 0.12.0; use {@link EnricherSpec}
+     */
+    @Deprecated
     public TimeWeightedDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double>
target, int unitMillis) {
         this(producer, source, target, unitMillis, Functions.<Double>identity());
     }
     
     /**
-     * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
+     * @deprecated since 0.11.0; explicit groovy utilities/support will be deleted; also
use {@link EnricherSpec}
      */
     @Deprecated
     public TimeWeightedDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double>
target, int unitMillis, Closure<Double> postProcessor) {
         this(producer, source, target, unitMillis, GroovyJavaMethods.<Double,Double>functionFromClosure(postProcessor));
     }
     
+    /**
+     * @deprecated since 0.12.0; use {@link EnricherSpec}
+     */
+    @Deprecated
     public TimeWeightedDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double>
target, int unitMillis, Function<Double,Double> postProcessor) {
         super(producer, source, target);
         this.unitMillis = unitMillis;
@@ -98,6 +111,15 @@ public class TimeWeightedDeltaEnricher<T extends Number> extends
AbstractTypeTra
     }
     
     @Override
+    public void init() {
+        super.init();
+        
+        if (uniqueTag == null && source != null && target != null) {
+            uniqueTag = JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"/"+Duration.millis(unitMillis)+"->"+target.getName();
+        }
+    }
+
+    @Override
     public void onEvent(SensorEvent<T> event) {
         onEvent(event, event.getTimestamp());
     }
@@ -109,7 +131,7 @@ public class TimeWeightedDeltaEnricher<T extends Number> extends
AbstractTypeTra
             // Can't compute a delta; 
             // don't assume current=zero because then things like requestCount->requestsPerSecond
is negative!
             // instead assume same as last time, so delta == 0
-            double deltaPostProcessed = postProcessor.apply(0d);
+            double deltaPostProcessed = getPostProcessor().apply(0d);
             entity.sensors().set((AttributeSensor<Double>)target, deltaPostProcessed);
             if (LOG.isTraceEnabled()) LOG.trace("set {} to {}, {} -> {} at {}", new Object[]
{this, deltaPostProcessed, lastValue, current, eventTime});
             return;
@@ -123,7 +145,7 @@ public class TimeWeightedDeltaEnricher<T extends Number> extends
AbstractTypeTra
                 double duration = (lastTime < 0) ? unitMillis : eventTime - lastTime;
                 if (eventTime == lastTime) duration = 0.1; // 0.1 of a millisecond is a relatively
small number: 
                 double delta = (current.doubleValue() - lastValue.doubleValue()) / (duration
/ unitMillis);
-                double deltaPostProcessed = postProcessor.apply(delta);
+                double deltaPostProcessed = getPostProcessor().apply(delta);
                 entity.sensors().set((AttributeSensor<Double>)target, deltaPostProcessed);
                 if (LOG.isTraceEnabled()) LOG.trace("set {} to {}, {} -> {} at {}", new
Object[] {this, deltaPostProcessed, lastValue, current, eventTime}); 
             }
@@ -134,4 +156,8 @@ public class TimeWeightedDeltaEnricher<T extends Number> extends
AbstractTypeTra
             lastTime = -1;
         }
     }
+    
+    private Function<Double, Double> getPostProcessor() {
+        return (postProcessor != null) ? postProcessor : Functions.<Double>identity();
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java
b/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java
index 62cdef8..4c67b96 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/DeltaEnrichersTests.java
@@ -24,10 +24,12 @@ import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.SubscriptionContext;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
 import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.util.time.Duration;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -52,9 +54,12 @@ public class DeltaEnrichersTests extends BrooklynAppUnitTestSupport {
     @Test
     public void testDeltaEnricher() {
         AttributeSensor<Integer> deltaSensor = new BasicAttributeSensor<Integer>(Integer.class,
"delta sensor");
-        DeltaEnricher<Integer> delta = new DeltaEnricher<Integer>(producer, intSensor,
deltaSensor);
-        producer.enrichers().add(delta);
-        
+        @SuppressWarnings("unchecked")
+        DeltaEnricher<Integer> delta = producer.enrichers().add(EnricherSpec.create(DeltaEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", deltaSensor));
+
         delta.onEvent(intSensor.newEvent(producer, 0));
         delta.onEvent(intSensor.newEvent(producer, 0));
         assertEquals(producer.getAttribute(deltaSensor), (Integer)0);
@@ -69,9 +74,12 @@ public class DeltaEnrichersTests extends BrooklynAppUnitTestSupport {
     @Test
     public void testMonospaceTimeWeightedDeltaEnricher() {
         AttributeSensor<Double> deltaSensor = new BasicAttributeSensor<Double>(Double.class,
"per second delta delta sensor");
-        TimeWeightedDeltaEnricher<Integer> delta =
-            TimeWeightedDeltaEnricher.<Integer>getPerSecondDeltaEnricher(producer,
intSensor, deltaSensor);
-        producer.enrichers().add(delta);
+        @SuppressWarnings("unchecked")
+        TimeWeightedDeltaEnricher<Integer> delta = producer.enrichers().add(EnricherSpec.create(TimeWeightedDeltaEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", deltaSensor)
+                .configure("unitMillis", 1000));
         
         // Don't start with timestamp=0: that may be treated special 
         delta.onEvent(intSensor.newEvent(producer, 0), 1000);
@@ -89,9 +97,12 @@ public class DeltaEnrichersTests extends BrooklynAppUnitTestSupport {
     @Test
     public void testVariableTimeWeightedDeltaEnricher() {
         AttributeSensor<Double> deltaSensor = new BasicAttributeSensor<Double>(Double.class,
"per second delta delta sensor");
-        TimeWeightedDeltaEnricher<Integer> delta =
-            TimeWeightedDeltaEnricher.<Integer>getPerSecondDeltaEnricher(producer,
intSensor, deltaSensor);
-        producer.enrichers().add(delta);
+        @SuppressWarnings("unchecked")
+        TimeWeightedDeltaEnricher<Integer> delta = producer.enrichers().add(EnricherSpec.create(TimeWeightedDeltaEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", deltaSensor)
+                .configure("unitMillis", 1000));
         
         delta.onEvent(intSensor.newEvent(producer, 0), 1000);
         delta.onEvent(intSensor.newEvent(producer, 0), 3000);
@@ -109,8 +120,13 @@ public class DeltaEnrichersTests extends BrooklynAppUnitTestSupport {
     @Test
     public void testPostProcessorCalledForDeltaEnricher() {
         AttributeSensor<Double> deltaSensor = new BasicAttributeSensor<Double>(Double.class,
"per second delta delta sensor");
-        TimeWeightedDeltaEnricher<Integer> delta = new TimeWeightedDeltaEnricher<Integer>(producer,
intSensor, deltaSensor, 1000, new AddConstant(123d));
-        producer.enrichers().add(delta);
+        @SuppressWarnings("unchecked")
+        TimeWeightedDeltaEnricher<Integer> delta = producer.enrichers().add(EnricherSpec.create(TimeWeightedDeltaEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", deltaSensor)
+                .configure("unitMillis", 1000)
+                .configure("postProcessor", new AddConstant(123d)));
         
         delta.onEvent(intSensor.newEvent(producer, 0), 1000);
         delta.onEvent(intSensor.newEvent(producer, 0), 2000);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java
b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java
index 21124ae..975fd9f 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RebindEnricherTest.java
@@ -24,6 +24,7 @@ import java.net.URL;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
@@ -57,7 +58,10 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp {
     
     @Test
     public void testDeltaEnricher() throws Exception {
-        origApp.enrichers().add(new DeltaEnricher<Integer>(origApp, INT_METRIC, INT_METRIC2));
+        origApp.enrichers().add(EnricherSpec.create(DeltaEnricher.class)
+                .configure("producer", origApp)
+                .configure("source", INT_METRIC)
+                .configure("target", INT_METRIC2));
         
         TestApplication newApp = rebind();
 
@@ -93,7 +97,11 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp {
 
     @Test
     public void testRollingMeanEnricher() throws Exception {
-        origApp.enrichers().add(new RollingMeanEnricher<Integer>(origApp, INT_METRIC,
DOUBLE_METRIC, 2));
+        origApp.enrichers().add(EnricherSpec.create(RollingMeanEnricher.class)
+                .configure("producer", origApp)
+                .configure("source", INT_METRIC)
+                .configure("target", DOUBLE_METRIC)
+                .configure("windowSize", 2));
         
         TestApplication newApp = rebind();
 
@@ -103,7 +111,11 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp {
 
     @Test
     public void testRollingTimeWindowMeanEnricher() throws Exception {
-        origApp.enrichers().add(new RollingTimeWindowMeanEnricher<Integer>(origApp,
INT_METRIC, DOUBLE_METRIC, Duration.of(10, TimeUnit.MILLISECONDS)));
+        origApp.enrichers().add(EnricherSpec.create(RollingTimeWindowMeanEnricher.class)
+                .configure("producer", origApp)
+                .configure("source", INT_METRIC)
+                .configure("target", DOUBLE_METRIC)
+                .configure("timePeriod", Duration.millis(10)));
         
         TestApplication newApp = rebind();
 
@@ -115,7 +127,11 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp {
     
     @Test
     public void testTimeFractionDeltaEnricher() throws Exception {
-        origApp.enrichers().add(new TimeFractionDeltaEnricher<Integer>(origApp, INT_METRIC,
DOUBLE_METRIC, TimeUnit.MILLISECONDS));
+        origApp.enrichers().add(EnricherSpec.create(TimeFractionDeltaEnricher.class)
+                .configure("producer", origApp)
+                .configure("source", INT_METRIC)
+                .configure("target", DOUBLE_METRIC)
+                .configure("durationPerOrigUnit", Duration.millis(1)));
         
         final TestApplication newApp = rebind();
 
@@ -132,7 +148,11 @@ public class RebindEnricherTest extends RebindTestFixtureWithApp {
     
     @Test
     public void testTimeWeightedDeltaEnricher() throws Exception {
-        origApp.enrichers().add(new TimeWeightedDeltaEnricher<Integer>(origApp, INT_METRIC,
DOUBLE_METRIC, 1000));
+        origApp.enrichers().add(EnricherSpec.create(TimeWeightedDeltaEnricher.class)
+                .configure("producer", origApp)
+                .configure("source", INT_METRIC)
+                .configure("target", DOUBLE_METRIC)
+                .configure("unitMillis", 1000));
         
         final TestApplication newApp = rebind();
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java
b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java
index 4db1a6f..2286ce1 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingMeanEnricherTest.java
@@ -23,6 +23,7 @@ import static org.testng.Assert.assertEquals;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
 import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
@@ -40,6 +41,7 @@ public class RollingMeanEnricherTest extends BrooklynAppUnitTestSupport
{
     RollingMeanEnricher<Integer> averager;
 
     @BeforeMethod(alwaysRun=true)
+    @SuppressWarnings("unchecked")
     @Override
     public void setUp() throws Exception {
         super.setUp();
@@ -49,9 +51,15 @@ public class RollingMeanEnricherTest extends BrooklynAppUnitTestSupport
{
         deltaSensor = new BasicAttributeSensor<Integer>(Integer.class, "delta sensor");
         avgSensor = new BasicAttributeSensor<Double>(Double.class, "avg sensor");
         
-        producer.enrichers().add(new DeltaEnricher<Integer>(producer, intSensor, deltaSensor));
-        averager = new RollingMeanEnricher<Integer>(producer, deltaSensor, avgSensor,
4);
-        producer.enrichers().add(averager);
+        producer.enrichers().add(EnricherSpec.create(DeltaEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", deltaSensor));
+        averager = producer.enrichers().add(EnricherSpec.create(RollingMeanEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", deltaSensor)
+                .configure("windowSize", 4));
     }
 
     @Test
@@ -60,9 +68,13 @@ public class RollingMeanEnricherTest extends BrooklynAppUnitTestSupport
{
     }
     
     @Test
+    @SuppressWarnings("unchecked")
     public void testZeroWindowSize() {
-        averager = new RollingMeanEnricher<Integer>(producer, deltaSensor, avgSensor,
0);
-        producer.enrichers().add(averager);
+        averager = producer.enrichers().add(EnricherSpec.create(RollingMeanEnricher.class)
+                .configure("producer", producer)
+                .configure("source", deltaSensor)
+                .configure("target", avgSensor)
+                .configure("windowSize", 0));
         
         averager.onEvent(intSensor.newEvent(producer, 10));
         assertEquals(averager.getAverage(), null);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java
b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java
index 90854e7..e911fe4 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/RollingTimeWindowMeanEnricherTest.java
@@ -23,11 +23,13 @@ import static org.testng.Assert.assertEquals;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
 import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.policy.enricher.RollingTimeWindowMeanEnricher.ConfidenceQualifiedNumber;
+import org.apache.brooklyn.util.time.Duration;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
@@ -46,6 +48,7 @@ public class RollingTimeWindowMeanEnricherTest extends BrooklynAppUnitTestSuppor
     private final long timePeriod = 1000;
     
     @BeforeMethod(alwaysRun=true)
+    @SuppressWarnings("unchecked")
     @Override
     public void setUp() throws Exception {
         super.setUp();
@@ -55,9 +58,15 @@ public class RollingTimeWindowMeanEnricherTest extends BrooklynAppUnitTestSuppor
         deltaSensor = new BasicAttributeSensor<Integer>(Integer.class, "delta sensor");
         avgSensor = new BasicAttributeSensor<Double>(Double.class, "avg sensor");
         
-        producer.enrichers().add(new DeltaEnricher<Integer>(producer, intSensor, deltaSensor));
-        averager = new RollingTimeWindowMeanEnricher<Integer>(producer, deltaSensor,
avgSensor, timePeriod);
-        producer.enrichers().add(averager);
+        producer.enrichers().add(EnricherSpec.create(DeltaEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", deltaSensor));
+        averager = producer.enrichers().add(EnricherSpec.create(RollingTimeWindowMeanEnricher.class)
+                .configure("producer", producer)
+                .configure("source", deltaSensor)
+                .configure("target", avgSensor)
+                .configure("timePeriod", timePeriod));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java
b/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java
index 6b1dfff..cc5cde0 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/enricher/TimeFractionDeltaEnricherTest.java
@@ -20,52 +20,48 @@ package org.apache.brooklyn.policy.enricher;
 
 import static org.testng.Assert.assertEquals;
 
-import java.util.concurrent.TimeUnit;
-
-import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.SubscriptionContext;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
-import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.sensor.BasicSensorEvent;
 import org.apache.brooklyn.core.sensor.Sensors;
-import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.policy.enricher.TimeFractionDeltaEnricher;
-import org.testng.annotations.AfterMethod;
+import org.apache.brooklyn.util.time.Duration;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-public class TimeFractionDeltaEnricherTest {
+public class TimeFractionDeltaEnricherTest extends BrooklynAppUnitTestSupport {
 
     private static final double PRECISION = 0.000001;
     
-    private TestApplication app;
-    private EntityLocal producer;
+    private Entity producer;
 
     Sensor<Integer> intSensor;
     AttributeSensor<Double> fractionSensor;
     SubscriptionContext subscription;
     
     @BeforeMethod(alwaysRun=true)
-    public void before() {
-        app = TestApplication.Factory.newManagedInstanceForTests();
-        producer = app.createAndManageChild(EntitySpec.create(TestEntity.class));
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        producer = app.addChild(EntitySpec.create(TestEntity.class));
         
         intSensor = Sensors.newIntegerSensor("int sensor");
         fractionSensor = Sensors.newDoubleSensor("fraction sensor");
     }
 
-    @AfterMethod(alwaysRun=true)
-    public void after() {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
-    }
-
     @Test
     public void testCalculatesFractions() {
-        TimeFractionDeltaEnricher<Integer> enricher = new TimeFractionDeltaEnricher<Integer>(producer,
intSensor, fractionSensor, TimeUnit.MILLISECONDS);
-        producer.enrichers().add(enricher);
+        @SuppressWarnings("unchecked")
+        TimeFractionDeltaEnricher<Integer> enricher = producer.enrichers().add(EnricherSpec.create(TimeFractionDeltaEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", fractionSensor)
+                .configure("durationPerOrigUnit", Duration.millis(1)));
         
         enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L));
         enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1001000L));
@@ -83,8 +79,12 @@ public class TimeFractionDeltaEnricherTest {
     
     @Test
     public void testConvertsTimeUnits() {
-        TimeFractionDeltaEnricher<Integer> enricher = new TimeFractionDeltaEnricher<Integer>(producer,
intSensor, fractionSensor, TimeUnit.MICROSECONDS);
-        producer.enrichers().add(enricher);
+        @SuppressWarnings("unchecked")
+        TimeFractionDeltaEnricher<Integer> enricher = producer.enrichers().add(EnricherSpec.create(TimeFractionDeltaEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", fractionSensor)
+                .configure("durationPerOrigUnit", Duration.micros(1)));
         
         enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L));
         enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 1000000,
1001000L));
@@ -93,8 +93,12 @@ public class TimeFractionDeltaEnricherTest {
     
     @Test
     public void testConverts100NanosTimeBlocks() {
-        TimeFractionDeltaEnricher<Integer> enricher = new TimeFractionDeltaEnricher<Integer>(producer,
intSensor, fractionSensor, 100);
-        producer.enrichers().add(enricher);
+        @SuppressWarnings("unchecked")
+        TimeFractionDeltaEnricher<Integer> enricher = producer.enrichers().add(EnricherSpec.create(TimeFractionDeltaEnricher.class)
+                .configure("producer", producer)
+                .configure("source", intSensor)
+                .configure("target", fractionSensor)
+                .configure("durationPerOrigUnit", Duration.nanos(100)));
         
         enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L));
         enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 10000000,
1001000L));

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/software/base/src/main/java/org/apache/brooklyn/entity/java/JavaAppUtils.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/java/JavaAppUtils.java
b/software/base/src/main/java/org/apache/brooklyn/entity/java/JavaAppUtils.java
index cde0a9e..0f44f3c 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/java/JavaAppUtils.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/java/JavaAppUtils.java
@@ -30,6 +30,7 @@ import javax.annotation.Nullable;
 import javax.management.openmbean.CompositeData;
 
 import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.core.config.render.RendererHints;
 import org.apache.brooklyn.feed.http.HttpValueFunctions;
 import org.apache.brooklyn.feed.jmx.JmxAttributePollConfig;
@@ -93,12 +94,17 @@ public class JavaAppUtils {
     }
 
     public static void connectJavaAppServerPolicies(Entity entity, Duration windowPeriod)
{
-        entity.enrichers().add(new TimeFractionDeltaEnricher<Double>(entity, UsesJavaMXBeans.PROCESS_CPU_TIME,

-                UsesJavaMXBeans.PROCESS_CPU_TIME_FRACTION_LAST, TimeUnit.MILLISECONDS));
+        entity.enrichers().add(EnricherSpec.create(TimeFractionDeltaEnricher.class)
+                .configure("producer", entity)
+                .configure("source", UsesJavaMXBeans.PROCESS_CPU_TIME)
+                .configure("target", UsesJavaMXBeans.PROCESS_CPU_TIME_FRACTION_LAST)
+                .configure("durationPerOrigUnit", Duration.millis(1)));
 
-        entity.enrichers().add(new RollingTimeWindowMeanEnricher<Double>(entity,
-                UsesJavaMXBeans.PROCESS_CPU_TIME_FRACTION_LAST, UsesJavaMXBeans.PROCESS_CPU_TIME_FRACTION_IN_WINDOW,
-                windowPeriod));
+        entity.enrichers().add(EnricherSpec.create(RollingTimeWindowMeanEnricher.class)
+                .configure("producer", entity)
+                .configure("source", UsesJavaMXBeans.PROCESS_CPU_TIME_FRACTION_LAST)
+                .configure("target", UsesJavaMXBeans.PROCESS_CPU_TIME_FRACTION_IN_WINDOW)
+                .configure("timePeriod", windowPeriod));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/software/base/src/test/java/org/apache/brooklyn/entity/java/VanillaJavaAppRebindTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/java/VanillaJavaAppRebindTest.java
b/software/base/src/test/java/org/apache/brooklyn/entity/java/VanillaJavaAppRebindTest.java
index a5d0fbc..35125be 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/java/VanillaJavaAppRebindTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/java/VanillaJavaAppRebindTest.java
@@ -24,6 +24,7 @@ import java.io.File;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
@@ -31,6 +32,7 @@ import org.apache.brooklyn.core.mgmt.rebind.RebindTestUtils;
 import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.entity.java.JavaOptsTest.TestingJavaOptsVanillaJavaAppImpl;
+import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 import org.apache.brooklyn.policy.enricher.RollingTimeWindowMeanEnricher;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.ResourceUtils;
@@ -41,7 +43,6 @@ import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
-import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 
 import com.google.common.base.Predicates;
 import com.google.common.collect.ImmutableList;
@@ -156,13 +157,22 @@ public class VanillaJavaAppRebindTest {
         public void onManagementStarted() {
             super.onManagementStarted();
             LOG.info("mgmt started for "+this);
-            enrichers().add(new RollingTimeWindowMeanEnricher<Double>(this, PROCESS_CPU_TIME,
AVG1, Duration.TEN_SECONDS));
+            enrichers().add(EnricherSpec.create(RollingTimeWindowMeanEnricher.class)
+                    .configure("producer", this)
+                    .configure("source", PROCESS_CPU_TIME)
+                    .configure("target", AVG1)
+                    .configure("timePeriod", Duration.TEN_SECONDS));
         }
+        
         @Override
         protected void connectSensors() {
             super.connectSensors();
             LOG.info("connecting sensors for "+this);
-            enrichers().add(new RollingTimeWindowMeanEnricher<Double>(this, PROCESS_CPU_TIME,
AVG2, Duration.TEN_SECONDS));
+            enrichers().add(EnricherSpec.create(RollingTimeWindowMeanEnricher.class)
+                    .configure("producer", this)
+                    .configure("source", PROCESS_CPU_TIME)
+                    .configure("target", AVG2)
+                    .configure("timePeriod", Duration.TEN_SECONDS));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/263304b2/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java b/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java
index f649bef..64ab629 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/time/Duration.java
@@ -178,6 +178,11 @@ public class Duration implements Comparable<Duration>, Serializable
{
     }
 
     /** creates new {@link Duration} instance of the given length of time */
+    public static Duration micros(Number n) {
+        return new Duration((long) (n.doubleValue() * TimeUnit.MICROSECONDS.toNanos(1)),
TimeUnit.NANOSECONDS);
+    }
+
+    /** creates new {@link Duration} instance of the given length of time */
     public static Duration nanos(Number n) {
         return new Duration(n.longValue(), TimeUnit.NANOSECONDS);
     }


Mime
View raw message