Delete SensorTransformingEnricher

Was deprecated in 0.7.0; did not have a constructor usable when
deserialising from persisted state, so that backwards compatibility
is not a worry!

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

Branch: refs/heads/master
Commit: a49ebc522e6ba9ec09d630f5d31e74abb5f05bb9
Parents: bbe1171
Author: Aled Sage <[email protected]>
Authored: Sun Jun 11 14:03:58 2017 +0100
Committer: Aled Sage <[email protected]>
Committed: Sun Jun 11 14:57:40 2017 +0100

----------------------------------------------------------------------
 .../stock/SensorTransformingEnricher.java       | 115 -------------------
 .../TransformingEnricherDeprecatedTest.java     |  92 ---------------
 2 files changed, 207 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a49ebc52/core/src/main/java/org/apache/brooklyn/enricher/stock/SensorTransformingEnricher.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/brooklyn/enricher/stock/SensorTransformingEnricher.java
 
b/core/src/main/java/org/apache/brooklyn/enricher/stock/SensorTransformingEnricher.java
deleted file mode 100644
index 339325b..0000000
--- 
a/core/src/main/java/org/apache/brooklyn/enricher/stock/SensorTransformingEnricher.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.enricher.stock;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.api.sensor.Sensor;
-import org.apache.brooklyn.api.sensor.SensorEvent;
-import org.apache.brooklyn.util.groovy.GroovyJavaMethods;
-import org.apache.brooklyn.util.javalang.JavaClassNames;
-import groovy.lang.Closure;
-
-import com.google.common.base.Function;
-
-/**
- * @deprecated since 0.7.0; use {@link Enrichers.builder()}
- * @see Transformer if need to sub-class
- */
-@Deprecated
-public class SensorTransformingEnricher<T,U> extends 
AbstractTypeTransformingEnricher {
-
-    private Function<? super T, ? extends U> transformation;
-
-    public SensorTransformingEnricher(Entity producer, Sensor<T> source, 
Sensor<U> target, Function<? super T, ? extends U> transformation) {
-        super(producer, source, target);
-        this.transformation = transformation;
-        this.uniqueTag = 
JavaClassNames.simpleClassName(getClass())+":"+source.getName()+"*->"+target.getName();;
-    }
-
-    /**
-     * @deprecated since 0.11.0; explicit groovy utilities/support will be 
deleted.
-     */
-    @Deprecated
-    public SensorTransformingEnricher(Entity producer, Sensor<T> source, 
Sensor<U> target, Closure transformation) {
-        this(producer, source, target, 
GroovyJavaMethods.functionFromClosure(transformation));
-    }
-
-    public SensorTransformingEnricher(Sensor<T> source, Sensor<U> target, 
Function<T,U> transformation) {
-        this(null, source, target, transformation);
-    }
-
-    /**
-     * @deprecated since 0.11.0; explicit groovy utilities/support will be 
deleted.
-     */
-    @Deprecated
-    public SensorTransformingEnricher(Sensor<T> source, Sensor<U> target, 
Closure transformation) {
-        this(null, source, target, 
GroovyJavaMethods.functionFromClosure(transformation));
-    }
-
-    @Override
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    public void onEvent(SensorEvent event) {
-        if (accept((T)event.getValue())) {
-            if (target instanceof AttributeSensor)
-                entity.sensors().set((AttributeSensor)target, 
compute((T)event.getValue()));
-            else 
-                entity.sensors().emit(target, compute((T)event.getValue()));
-        }
-    }
-
-    protected boolean accept(T value) {
-        return true;
-    }
-
-    protected U compute(T value) {
-        return transformation.apply(value);
-    }
-
-    /** 
-     * creates an enricher which listens to a source (from the producer), 
-     * transforms it and publishes it under the target
-     * 
-     * Instead, consider calling:
-     * <pre>
-     * {@code
-     * addEnricher(Enrichers.builder()
-     *         .transforming(source)
-     *         .publishing(target)
-     *         .from(producer)
-     *         .computing(transformation)
-     *         .build());
-     * }
-     * </pre>
-     * 
-     * @deprecated since 0.7.0; use {@link Enrichers.builder()}
-     */
-    @Deprecated
-    public static <U,V> SensorTransformingEnricher<U,V> 
newInstanceTransforming(Entity producer, AttributeSensor<U> source,
-            Function<U,V> transformation, AttributeSensor<V> target) {
-        return new SensorTransformingEnricher<U,V>(producer, source, target, 
transformation);
-    }
-
-    /** as {@link #newInstanceTransforming(Entity, AttributeSensor, Function, 
AttributeSensor)}
-     * using the same sensor as the source and the target */
-    public static <T> SensorTransformingEnricher<T,T> 
newInstanceTransforming(Entity producer, AttributeSensor<T> sensor,
-            Function<T,T> transformation) {
-        return newInstanceTransforming(producer, sensor, transformation, 
sensor);
-    }
-}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/a49ebc52/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherDeprecatedTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherDeprecatedTest.java
 
b/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherDeprecatedTest.java
deleted file mode 100644
index e52ff45..0000000
--- 
a/core/src/test/java/org/apache/brooklyn/enricher/stock/TransformingEnricherDeprecatedTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.enricher.stock;
-
-import java.util.Arrays;
-import java.util.concurrent.Callable;
-
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.location.SimulatedLocation;
-import org.apache.brooklyn.core.sensor.BasicAttributeSensor;
-import org.apache.brooklyn.core.test.entity.TestApplication;
-import org.apache.brooklyn.core.test.entity.TestEntity;
-import org.apache.brooklyn.test.Asserts;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Function;
-
-@SuppressWarnings("deprecation")
-public class TransformingEnricherDeprecatedTest {
-
-    public static final Logger log = 
LoggerFactory.getLogger(TransformingEnricherDeprecatedTest.class);
-            
-    private static final long TIMEOUT_MS = 10*1000;
-//    private static final long SHORT_WAIT_MS = 250;
-    
-    TestApplication app;
-    TestEntity producer;
-    AttributeSensor<Integer> intSensorA;
-    AttributeSensor<Long> target;
-
-    @BeforeMethod()
-    public void before() {
-        app = TestApplication.Factory.newManagedInstanceForTests();
-        producer = 
app.createAndManageChild(EntitySpec.create(TestEntity.class));
-        intSensorA = new BasicAttributeSensor<Integer>(Integer.class, 
"int.sensor.a");
-        target = new BasicAttributeSensor<Long>(Long.class, 
"long.sensor.target");
-        
-        app.start(Arrays.asList(new SimulatedLocation()));
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void after() {
-        if (app!=null) Entities.destroyAll(app.getManagementContext());
-    }
-    
-    @Test
-    public void testTransformingEnricher() throws InterruptedException {
-        final SensorTransformingEnricher<Integer, Long> e1 = new 
SensorTransformingEnricher<Integer,Long>(intSensorA, target, new DoubleFn());
-        
-        producer.sensors().set(intSensorA, 3);
-        //ensure previous values get picked up
-        producer.enrichers().add(e1);
-
-        Asserts.succeedsEventually(MutableMap.of("timeout", TIMEOUT_MS), new 
Callable<Object>() { 
-                @Override
-                public Object call() {
-                    Assert.assertEquals(producer.getAttribute(target), 
(Long)((long)6));
-                    return null;
-                }});
-    }
-
-    private static class DoubleFn implements Function<Integer, Long> {
-        @Override
-        public Long apply(Integer i) {
-            return ((long)i)*2;
-        }
-    }
-}

Reply via email to