brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [10/35] brooklyn-server git commit: tidy BasicExecutionManagement constructors
Date Tue, 03 Oct 2017 14:23:47 GMT
tidy BasicExecutionManagement constructors


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

Branch: refs/heads/master
Commit: c1f78bb2ba82504b2f0bfc1aa4831564d1f314b4
Parents: a341cce
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Sep 15 09:21:29 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Sep 15 10:29:09 2017 +0100

----------------------------------------------------------------------
 .../internal/AbstractManagementContext.java     |  5 ++--
 .../util/core/task/BasicExecutionContext.java   | 26 +++++++++++++++-----
 .../brooklyn/util/collections/MutableSet.java   | 14 ++++++++++-
 3 files changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c1f78bb2/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
index 322d60e..52eed44 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
@@ -72,7 +72,6 @@ import org.apache.brooklyn.core.mgmt.ha.HighAvailabilityManagerImpl;
 import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl;
 import org.apache.brooklyn.core.typereg.BasicBrooklynTypeRegistry;
 import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.core.task.BasicExecutionContext;
@@ -237,7 +236,7 @@ public abstract class AbstractManagementContext implements ManagementContextInte
                     BrooklynTaskTags.tagForContextEntity(e),
                     this
             );
-            return new BasicExecutionContext(MutableMap.of("tags", tags), getExecutionManager());
+            return new BasicExecutionContext(getExecutionManager(), tags);
         } else {
             return ((EntityInternal)e).getExecutionContext();
         }
@@ -250,7 +249,7 @@ public abstract class AbstractManagementContext implements ManagementContextInte
                 this,
                 BrooklynTaskTags.BROOKLYN_SERVER_TASK_TAG
         );
-        return new BasicExecutionContext(MutableMap.of("tags", tags), getExecutionManager());
+        return new BasicExecutionContext(getExecutionManager(), tags);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c1f78bb2/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionContext.java
b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionContext.java
index 547ae24..73baef2 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionContext.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/task/BasicExecutionContext.java
@@ -21,7 +21,6 @@ package org.apache.brooklyn.util.core.task;
 import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
@@ -45,6 +44,7 @@ import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags.WrappedEntity;
 import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
 import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.task.ImmediateSupplier.ImmediateUnsupportedException;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
@@ -73,23 +73,37 @@ public class BasicExecutionContext extends AbstractExecutionContext {
     final Set<Object> tags = new LinkedHashSet<Object>();
 
     public BasicExecutionContext(ExecutionManager executionManager) {
-        this(Collections.emptyMap(), executionManager);
+        this(executionManager, null);
     }
     
     /**
+     * As {@link #BasicExecutionContext(ExecutionManager, Iterable)} but taking a flags map.
      * Supported flags are {@code tag} and {@code tags}
      * 
      * @see ExecutionManager#submit(Map, TaskAdaptable)
+     * @deprecated since 0.12.0 use {@link #BasicExecutionContext(ExecutionManager, Iterable)}
      */
+    @Deprecated
     public BasicExecutionContext(Map<?, ?> flags, ExecutionManager executionManager)
{
+        this(executionManager, MutableSet.of().put(flags.remove("tag")).putAll((Iterable<?>)flags.remove("tag")));
+        if (!flags.isEmpty()) {
+            log.warn("Unexpected flags passed to execution context ("+tags+"): "+flags,
+                new Throwable("Trace for unexpected flags passed to execution context"));
+        }
+    }
+    
+    /**
+     * Creates an execution context which wraps {@link ExecutionManager}
+     * adding the given tags to all tasks submitted through this context.
+     */
+    public BasicExecutionContext(ExecutionManager executionManager, Iterable<Object>
tagsForThisContext) {
         this.executionManager = executionManager;
+        if (tagsForThisContext!=null) Iterables.addAll(tags, tagsForThisContext);
 
-        if (flags.get("tag") != null) tags.add(flags.remove("tag"));
-        if (flags.containsKey("tags")) tags.addAll((Collection<?>)flags.remove("tags"));
-
-        // FIXME brooklyn-specific check, just for sanity
+        // brooklyn-specific check, just for sanity
         // the context tag should always be a non-proxy entity, because that is what is passed
to effector tasks
         // which may require access to internal methods
+        // (could remove this check if generalizing; it has been here for a long time and
the problem seems gone)
         for (Object tag: tags) {
             if (tag instanceof BrooklynTaskTags.WrappedEntity) {
                 if (Proxy.isProxyClass(((WrappedEntity)tag).entity.getClass())) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c1f78bb2/utils/common/src/main/java/org/apache/brooklyn/util/collections/MutableSet.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/collections/MutableSet.java
b/utils/common/src/main/java/org/apache/brooklyn/util/collections/MutableSet.java
index bcadf33..1049304 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/collections/MutableSet.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/collections/MutableSet.java
@@ -213,7 +213,19 @@ public class MutableSet<V> extends LinkedHashSet<V> {
         if (setToAdd!=null) addAll(setToAdd);
         return this;
     }
-    
+
+    /** as {@link #add(V)} but fluent style */
+    public MutableSet<V> put(V e) {
+        add(e);
+        return this;
+    }
+
+    /** as {@link #addIfNotNull(V)} but fluent style */
+    public MutableSet<V> putIfNotNull(V e) {
+        if (e!=null) add(e);
+        return this;
+    }
+
     public boolean removeIfNotNull(V item) {
         if (item==null) return false;
         return remove(item);


Mime
View raw message