You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/07/24 07:17:18 UTC

[1/3] incubator-brooklyn git commit: Add EntityDynamicType.removeEffector(Effector)

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 371009293 -> c5536105e


Add EntityDynamicType.removeEffector(Effector)


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

Branch: refs/heads/master
Commit: 42d245355e09b341f95730471be4a0bb1e8c15b4
Parents: 3e36892
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Mon Jul 20 12:09:23 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Mon Jul 20 12:09:23 2015 +0100

----------------------------------------------------------------------
 .../entity/basic/EntityDynamicType.java         | 25 +++++++++-
 .../entity/basic/DynamicEntityTest.java         | 52 +++++++++-----------
 2 files changed, 47 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42d24535/core/src/main/java/brooklyn/entity/basic/EntityDynamicType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/EntityDynamicType.java b/core/src/main/java/brooklyn/entity/basic/EntityDynamicType.java
index 14500d3..c4a455b 100644
--- a/core/src/main/java/brooklyn/entity/basic/EntityDynamicType.java
+++ b/core/src/main/java/brooklyn/entity/basic/EntityDynamicType.java
@@ -130,17 +130,38 @@ public class EntityDynamicType extends BrooklynDynamicType<Entity, AbstractEntit
             instance.emit(AbstractEntity.EFFECTOR_ADDED, newEffector.getName());
     }
 
-    /** Adds an effector with an explicit body */
+    /**
+     * Adds an effector with an explicit body to this entity.
+     */
     @Beta
     public <T> void addEffector(Effector<T> effector, EffectorTaskFactory<T> body) {
         addEffector(new EffectorAndBody<T>(effector, body));
     }
-    /** Adds an effector with an explicit body */
+
+    /**
+     * Adds an effector with an explicit body to this entity.
+     */
     @Beta
     public <T> void addEffector(Effector<T> effector, EffectorBody<T> body) {
         addEffector(effector, new EffectorBodyTaskFactory<T>(body));
     }
 
+    /**
+     * Removes the given {@link Effector} from this entity.
+     * <p>
+     * Note that if the argument is an instance of {@link EffectorWithBody} it will
+     * still be possible to invoke the effector on the entity by calling
+     * <code>entity.invoke(effector, argumentsMap)</code>.
+     */
+    @Beta
+    public void removeEffector(Effector<?> effector) {
+        Effector<?> removed = effectors.remove(effector.getName());
+        invalidateSnapshot();
+        if (removed != null) {
+            instance.emit(AbstractEntity.EFFECTOR_REMOVED, removed.getName());
+        }
+    }
+
     // --------------------------------------------------
     
     /**

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/42d24535/core/src/test/java/brooklyn/entity/basic/DynamicEntityTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/DynamicEntityTest.java b/core/src/test/java/brooklyn/entity/basic/DynamicEntityTest.java
index 1b5928d..221e0c2 100644
--- a/core/src/test/java/brooklyn/entity/basic/DynamicEntityTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/DynamicEntityTest.java
@@ -18,45 +18,41 @@
  */
 package brooklyn.entity.basic;
 
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+
 import org.testng.annotations.Test;
 
-import brooklyn.entity.Application;
+import brooklyn.entity.BrooklynAppUnitTestSupport;
 import brooklyn.entity.effector.EffectorTaskTest;
 import brooklyn.entity.proxying.EntityInitializer;
 import brooklyn.entity.proxying.EntitySpec;
-import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.test.entity.TestEntity;
 import brooklyn.util.collections.MutableMap;
 
-public class DynamicEntityTest {
+public class DynamicEntityTest extends BrooklynAppUnitTestSupport {
 
-    Application app;
-    
-    @BeforeMethod(alwaysRun=true)
-    public void setup() throws Exception {
-        app = ApplicationBuilder.newManagedApp(EntitySpec.create(BasicApplication.class), LocalManagementContextForTests.newInstance());
-    }
-    
-    @AfterMethod(alwaysRun=true)
-    public void tearDown() throws Exception {
-        if (app != null) Entities.destroyAll(app.getManagementContext());
+    @Test
+    public void testEffectorAddedDuringInit() {
+        BasicEntity entity = app.createAndManageChild(EntitySpec.create(BasicEntity.class)
+                .addInitializer(new EntityInitializer() {
+                    public void apply(EntityLocal entity) {
+                        ((EntityInternal) entity).getMutableEntityType().addEffector(EffectorTaskTest.DOUBLE_1);
+                    }
+                }));
+        assertEquals(entity.invoke(EffectorTaskTest.DOUBLE_BODYLESS, MutableMap.of("numberToDouble", 5)).getUnchecked(), (Integer) 10);
     }
 
     @Test
-    public void testEffectorAddedDuringInit() {
-        BasicEntity entity = app.addChild(EntitySpec.create(BasicEntity.class)
-            .addInitializer(new EntityInitializer() {
-                public void apply(EntityLocal entity) {
-                    ((EntityInternal)entity).getMutableEntityType().addEffector(EffectorTaskTest.DOUBLE_1);
-                }
-            }));
-        // TODO why doesn't the call to addChild above automatically manage the child (now that we use specs for creation) ?
-        // (if there is a good reason, put it in addChild!)
-        Entities.manage(entity);
-        
-        Assert.assertEquals(entity.invoke(EffectorTaskTest.DOUBLE_BODYLESS, MutableMap.of("numberToDouble", 5)).getUnchecked(), (Integer)10);
+    public void testEffectorRemovedDuringInit() {
+        TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
+                .addInitializer(new EntityInitializer() {
+                    @Override
+                    public void apply(EntityLocal entity) {
+                        ((EntityInternal) entity).getMutableEntityType().removeEffector(TestEntity.IDENTITY_EFFECTOR);
+                    }
+                }));
+        assertFalse(entity.getMutableEntityType().getEffectors().containsKey(TestEntity.IDENTITY_EFFECTOR.getName()));
     }
     
 }


[3/3] incubator-brooklyn git commit: This closes #749

Posted by al...@apache.org.
This closes #749


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

Branch: refs/heads/master
Commit: c5536105e5f108844773c5e66dd4800febc892d2
Parents: 3710092 73fc000
Author: Aled Sage <al...@gmail.com>
Authored: Thu Jul 23 22:17:04 2015 -0700
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Jul 23 22:17:04 2015 -0700

----------------------------------------------------------------------
 .../entity/basic/EntityDynamicType.java         | 25 +++++++++-
 .../brooklyn/entity/effector/Effectors.java     | 15 +++---
 .../entity/basic/DynamicEntityTest.java         | 52 +++++++++-----------
 3 files changed, 56 insertions(+), 36 deletions(-)
----------------------------------------------------------------------



[2/3] incubator-brooklyn git commit: Simplify log message

Posted by al...@apache.org.
Simplify log message

I think


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

Branch: refs/heads/master
Commit: 73fc000990754d37d748d012652b35e10bb494a0
Parents: 42d2453
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Mon Jul 20 12:09:43 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Mon Jul 20 12:09:43 2015 +0100

----------------------------------------------------------------------
 .../java/brooklyn/entity/effector/Effectors.java     | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/73fc0009/core/src/main/java/brooklyn/entity/effector/Effectors.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/effector/Effectors.java b/core/src/main/java/brooklyn/entity/effector/Effectors.java
index 5d89e56..4039e67 100644
--- a/core/src/main/java/brooklyn/entity/effector/Effectors.java
+++ b/core/src/main/java/brooklyn/entity/effector/Effectors.java
@@ -135,12 +135,15 @@ public class Effectors {
     public static <T> TaskAdaptable<T> invocation(Entity entity, Effector<T> eff, @Nullable Map<?,?> parameters) {
         @SuppressWarnings("unchecked")
         Effector<T> eff2 = (Effector<T>) ((EntityInternal)entity).getEffector(eff.getName());
-        if (log.isTraceEnabled())
-            log.trace("invoking "+eff+"/"+
-                (eff instanceof EffectorWithBody<?> ? ((EffectorWithBody<?>)eff).getBody() : "bodyless")+
-                " on entity " + entity+" "+
-                (eff2==eff ? "" : " (actually "+eff2+"/"+
-                        (eff2 instanceof EffectorWithBody<?> ? ((EffectorWithBody<?>)eff2).getBody() : "bodyless")+")"));
+        if (log.isTraceEnabled()) {
+            Object eff1Body = (eff instanceof EffectorWithBody<?> ? ((EffectorWithBody<?>) eff).getBody() : "bodyless");
+            String message = String.format("Invoking %s/%s on entity %s", eff, eff1Body, entity);
+            if (eff != eff2) {
+                Object eff2Body = (eff2 instanceof EffectorWithBody<?> ? ((EffectorWithBody<?>) eff2).getBody() : "bodyless");
+                message += String.format(" (actually %s/%s)", eff2, eff2Body);
+            }
+            log.trace(message);
+        }
         if (eff2 != null) {
             if (eff2 != eff) {
                 if (eff2 instanceof EffectorWithBody) {