You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2017/09/16 01:52:04 UTC
[5/7] brooklyn-server git commit: tidy trigger text gen and javadoc
as per PR comments
tidy trigger text gen and javadoc as per PR comments
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/5be75f4b
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/5be75f4b
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/5be75f4b
Branch: refs/heads/master
Commit: 5be75f4b52f77e4f0fcefe8eaebe2adf2da720f8
Parents: 5ae9a1b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Thu Sep 14 08:40:12 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Thu Sep 14 08:40:12 2017 +0100
----------------------------------------------------------------------
.../core/objs/AbstractEntityAdjunct.java | 60 ++++++++++----------
1 file changed, 29 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5be75f4b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
index c157988..7ed58f0 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
@@ -28,6 +28,8 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import javax.annotation.Nullable;
@@ -65,6 +67,7 @@ import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
@@ -582,62 +585,57 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject imple
/** As {@link #setHighlight(String, HighlightTuple)}, convenience for recording an item which is intended to be ongoing. */
protected void highlightOngoing(String name, String description) {
- highlights.put(name, new HighlightTuple(description, 0, null));
+ setHighlight(name, new HighlightTuple(description, 0, null));
}
/** As {@link #setHighlight(String, HighlightTuple)}, convenience for recording an item with the current time. */
protected void highlightNow(String name, String description) {
- highlights.put(name, new HighlightTuple(description, System.currentTimeMillis(), null));
+ setHighlight(name, new HighlightTuple(description, System.currentTimeMillis(), null));
}
/** As {@link #setHighlight(String, HighlightTuple)}, convenience for recording an item with the current time and given task. */
protected void highlight(String name, String description, @Nullable Task<?> t) {
- highlights.put(name, new HighlightTuple(description, System.currentTimeMillis(), t!=null ? t.getId() : null));
+ setHighlight(name, new HighlightTuple(description, System.currentTimeMillis(), t!=null ? t.getId() : null));
}
/** As {@link #setHighlight(String, HighlightTuple)} for {@link #HIGHLIGHT_NAME_TRIGGERS} (as ongoing). */
protected void highlightTriggers(String description) {
highlightOngoing(HIGHLIGHT_NAME_TRIGGERS, description);
}
+ /** As {@link #highlightTriggers(String)} but convenience to generate a message given a sensor and source (entity or string description) */
protected <T> void highlightTriggers(Sensor<?> s, Object source) {
highlightTriggers(Collections.singleton(s), Collections.singleton(source));
}
+ /** As {@link #highlightTriggers(String)} but convenience to generate a message given a list of sensors and source (entity or string description) */
protected <T> void highlightTriggers(Iterable<? extends Sensor<? extends T>> s, Object source) {
highlightTriggers(s, (Iterable<?>) (source instanceof Iterable ? (Iterable<?>)source : Collections.singleton(source)));
}
+ /** As {@link #highlightTriggers(String)} but convenience to generate a message given a sensor and list of sources (entity or string description) */
protected <U> void highlightTriggers(Sensor<?> s, Iterable<U> sources) {
highlightTriggers(Collections.singleton(s), sources);
}
+ /** As {@link #highlightTriggers(String)} but convenience to generate a message given a list of sensors and list of sources (entity or string description) */
protected <T,U> void highlightTriggers(Iterable<? extends Sensor<? extends T>> sensors, Iterable<U> sources) {
StringBuilder msg = new StringBuilder("Listening for ");
- boolean firstWord = true;
- if (sensors!=null) for (Object s: sensors) {
- if (s==null) continue;
- if (!firstWord) { msg.append(", "); } else { firstWord = false; }
- // s is normally a sensor but forgive other things if caller cheated generics
- msg.append(s instanceof Sensor ? ((Sensor<?>)s).getName() : s.toString());
- }
- if (firstWord) msg.append("<nothing>");
-
- firstWord = true;
- boolean selfWasFirst = false;
- if (sources!=null) for (Object s: sources) {
- if (s==null) continue;
- if (!firstWord) {
- msg.append(", ");
- } else {
- if (s.equals(getEntity())) {
- // don't log self unless there is another
- selfWasFirst = true;
- continue;
- }
- msg.append(" on ");
- if (selfWasFirst) {
- msg.append("self, ");
- }
- firstWord = false;
+
+ if (sensors==null || Iterables.isEmpty(sensors)) {
+ msg.append("<nothing>");
+ } else {
+ String sensorsText = StreamSupport.stream(sensors.spliterator(), false)
+ .filter(s -> s != null)
+ .map(s -> (s instanceof Sensor ? ((Sensor<?>) s).getName() : s.toString()))
+ .collect(Collectors.joining(", "));
+ msg.append(sensorsText);
+ }
+
+ if (sources!=null && !Iterables.isEmpty(sources)) {
+ String sourcesText = StreamSupport.stream(sources.spliterator(), false)
+ .filter(s -> s != null)
+ .map(s -> (s.equals(getEntity()) ? "self" : s.toString()))
+ .collect(Collectors.joining(", "));
+ if (!"self".equals(sourcesText)) {
+ msg.append(" on ").append(sourcesText);
}
- if (s.equals(getEntity())) msg.append("self");
- else msg.append(""+s);
}
+
highlightTriggers(msg.toString());
}