brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [16/31] git commit: include job information in the toString for tasks that don't have a display name, and don't set the display name to tasks, and give jobs useful toStrings in many places
Date Tue, 29 Jul 2014 19:32:11 GMT
include job information in the toString for tasks that don't have a display name, and don't
set the display name to tasks, and give jobs useful toStrings in many places


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

Branch: refs/heads/master
Commit: 40b63e214dd9fd5abb8277e2f1beb6e64cdbc65e
Parents: d755ab4
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Jul 23 17:44:05 2014 -0700
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Jul 29 10:42:08 2014 -0400

----------------------------------------------------------------------
 .../internal/LocalSubscriptionManager.java      |  4 ++
 .../util/task/BasicExecutionManager.java        |  2 +-
 .../main/java/brooklyn/util/task/BasicTask.java | 14 +++----
 .../util/task/DynamicSequentialTask.java        |  2 +-
 .../util/task/SingleThreadedScheduler.java      | 12 +++---
 .../brooklyn/util/javalang/RunnableAdapter.java | 44 ++++++++++++++++++++
 .../java/brooklyn/util/GroovyJavaMethods.groovy |  5 ++-
 7 files changed, 66 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40b63e21/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
b/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
index a1d084a..0bd8578 100644
--- a/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
+++ b/core/src/main/java/brooklyn/management/internal/LocalSubscriptionManager.java
@@ -180,6 +180,10 @@ public class LocalSubscriptionManager extends AbstractSubscriptionManager
{
                     continue;
                 final Subscription sAtClosureCreation = s;
                 em.submit(mapOf("tag", s.subscriberExecutionManagerTag), new Runnable() {
+                    @Override
+                    public String toString() {
+                        return "LSM.publish("+event+")";
+                    }
                     public void run() {
                         sAtClosureCreation.listener.onEvent(event);
                     }});

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40b63e21/core/src/main/java/brooklyn/util/task/BasicExecutionManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/task/BasicExecutionManager.java b/core/src/main/java/brooklyn/util/task/BasicExecutionManager.java
index 1a89501..18858ee 100644
--- a/core/src/main/java/brooklyn/util/task/BasicExecutionManager.java
+++ b/core/src/main/java/brooklyn/util/task/BasicExecutionManager.java
@@ -412,7 +412,7 @@ public class BasicExecutionManager implements ExecutionManager {
             }
             @Override
             public String toString() {
-                return "BasicExecutionManager.submitNewTask.Callable["+task+","+flags+"]";
+                return "BEM.call("+task+","+flags+")";
             }
         };
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40b63e21/core/src/main/java/brooklyn/util/task/BasicTask.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/task/BasicTask.java b/core/src/main/java/brooklyn/util/task/BasicTask.java
index 8337edf..2e0da38 100644
--- a/core/src/main/java/brooklyn/util/task/BasicTask.java
+++ b/core/src/main/java/brooklyn/util/task/BasicTask.java
@@ -20,7 +20,6 @@ package brooklyn.util.task;
 
 import static brooklyn.util.JavaGroovyEquivalents.asString;
 import static brooklyn.util.JavaGroovyEquivalents.elvisString;
-import static brooklyn.util.JavaGroovyEquivalents.join;
 import groovy.lang.Closure;
 
 import java.io.PrintWriter;
@@ -117,8 +116,7 @@ public class BasicTask<T> implements TaskInternal<T> {
 
         description = elvisString(flags.remove("description"), "");
         String d = asString(flags.remove("displayName"));
-        if (d==null) d = join(tags, "-");
-        displayName = d;
+        displayName = (d==null ? "" : d);
     }
 
     public BasicTask(Runnable job) { this(GroovyJavaMethods.<T>callableFromRunnable(job));
}
@@ -144,10 +142,12 @@ public class BasicTask<T> implements TaskInternal<T> {
     }
 
     @Override
-    public String toString() { 
-        return "Task["+(displayName!=null && displayName.length()>0?displayName+
-                (tags!=null && !tags.isEmpty()?"":";")+" ":"")+
-                (tags!=null && !tags.isEmpty()?tags+"; ":"")+getId()+"]";
+    public String toString() {
+        // give display name plus id, or job and tags plus id; some jobs have been extended
to include nice tostrings 
+        return "Task["+(Strings.isNonEmpty(displayName) ? displayName : 
+                job + 
+                (tags!=null && !tags.isEmpty() ? ";"+tags : "")) +
+                ":"+getId()+"]";
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40b63e21/core/src/main/java/brooklyn/util/task/DynamicSequentialTask.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/task/DynamicSequentialTask.java b/core/src/main/java/brooklyn/util/task/DynamicSequentialTask.java
index 15ccb14..a17ffbe 100644
--- a/core/src/main/java/brooklyn/util/task/DynamicSequentialTask.java
+++ b/core/src/main/java/brooklyn/util/task/DynamicSequentialTask.java
@@ -367,7 +367,7 @@ public class DynamicSequentialTask<T> extends BasicTask<T>
implements HasTaskChi
         
         @Override
         public String toString() {
-            return "DstJob:"+DynamicSequentialTask.this;
+            return "DstJob:"+DynamicSequentialTask.this.getId();
         }
 
         /** waits for this job to complete, or the given time to elapse */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40b63e21/core/src/main/java/brooklyn/util/task/SingleThreadedScheduler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/task/SingleThreadedScheduler.java b/core/src/main/java/brooklyn/util/task/SingleThreadedScheduler.java
index 4c28369..420002f 100644
--- a/core/src/main/java/brooklyn/util/task/SingleThreadedScheduler.java
+++ b/core/src/main/java/brooklyn/util/task/SingleThreadedScheduler.java
@@ -76,12 +76,7 @@ public class SingleThreadedScheduler implements TaskScheduler, CanSetName
{
             return executeNow(c);
         } else {
             WrappingFuture<T> f = new WrappingFuture<T>();
-            order.add(new QueuedSubmission<T>(c, f) {
-                @Override
-                public String toString() {
-                    return "QueuedSubmission["+c+"]";
-                }
-            });
+            order.add(new QueuedSubmission<T>(c, f));
             int size = order.size();
             if (size>0 && (size == 50 || (size<=500 && (size%100)==0)
|| (size%1000)==0) && size!=lastSizeWarn) {
                 LOG.warn("{} is backing up, {} tasks queued", this, size);
@@ -133,6 +128,11 @@ public class SingleThreadedScheduler implements TaskScheduler, CanSetName
{
             this.c = c;
             this.f = f;
         }
+        
+        @Override
+        public String toString() {
+            return "QueuedSubmission["+c+"]@"+Integer.toHexString(System.identityHashCode(this));
+        }
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40b63e21/utils/common/src/main/java/brooklyn/util/javalang/RunnableAdapter.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/javalang/RunnableAdapter.java b/utils/common/src/main/java/brooklyn/util/javalang/RunnableAdapter.java
new file mode 100644
index 0000000..d61e84b
--- /dev/null
+++ b/utils/common/src/main/java/brooklyn/util/javalang/RunnableAdapter.java
@@ -0,0 +1,44 @@
+/*
+ * 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 brooklyn.util.javalang;
+
+import java.util.concurrent.Callable;
+
+public class RunnableAdapter<T> implements Callable<T> {
+    final Runnable task;
+    final T result;
+    
+    public RunnableAdapter(Runnable task, T result) {
+        this.task = task;
+        this.result = result;
+    }
+    
+    public T call() {
+        task.run();
+        return result;
+    }
+    
+    @Override
+    public String toString() {
+        if (result!=null)
+            return "RunnableAdapter["+task+(result!=null ? "->"+result : "")+"]";
+        else
+            return ""+task;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40b63e21/utils/groovy/src/main/java/brooklyn/util/GroovyJavaMethods.groovy
----------------------------------------------------------------------
diff --git a/utils/groovy/src/main/java/brooklyn/util/GroovyJavaMethods.groovy b/utils/groovy/src/main/java/brooklyn/util/GroovyJavaMethods.groovy
index 5867bda..c34f72d 100644
--- a/utils/groovy/src/main/java/brooklyn/util/GroovyJavaMethods.groovy
+++ b/utils/groovy/src/main/java/brooklyn/util/GroovyJavaMethods.groovy
@@ -21,7 +21,8 @@ package brooklyn.util;
 import static brooklyn.util.GroovyJavaMethods.truth
 
 import java.util.concurrent.Callable
-import java.util.concurrent.Executors
+
+import brooklyn.util.javalang.RunnableAdapter
 
 import com.google.common.base.Function
 import com.google.common.base.Predicate
@@ -53,7 +54,7 @@ public class GroovyJavaMethods {
     }
 
     public static <T> Callable<T> callableFromRunnable(final Runnable job) {
-        return (job in Callable) ? callableFromClosure(job) : Executors.callable(job);
+        return (job in Callable) ? callableFromClosure(job) : new RunnableAdapter<Object>(job,
null);
     }
 
     public static <T> Predicate<T> predicateFromClosure(final Closure<Boolean>
job) {


Mime
View raw message