Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id F0AFC200CF3 for ; Wed, 13 Sep 2017 17:26:03 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id EF98F1609CD; Wed, 13 Sep 2017 15:26:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 44D2F1609C9 for ; Wed, 13 Sep 2017 17:26:03 +0200 (CEST) Received: (qmail 22517 invoked by uid 500); 13 Sep 2017 15:26:01 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 22484 invoked by uid 99); 13 Sep 2017 15:26:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Sep 2017 15:26:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E12D7F57EE; Wed, 13 Sep 2017 15:25:59 +0000 (UTC) From: Graeme-Miller To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #818: More on adjunct highlights Content-Type: text/plain Message-Id: <20170913152559.E12D7F57EE@git1-us-west.apache.org> Date: Wed, 13 Sep 2017 15:25:59 +0000 (UTC) archived-at: Wed, 13 Sep 2017 15:26:04 -0000 Github user Graeme-Miller commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/818#discussion_r138642446 --- Diff: core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java --- @@ -568,6 +570,98 @@ public void setUniqueTag(String uniqueTag) { return highlightsToReturn; } + /** Records a named highlight against this object, for persistence and API access. + * See common highlights including {@link #HIGHLIGHT_NAME_LAST_ACTION} and + * {@link #HIGHLIGHT_NAME_LAST_CONFIRMATION}. + * Also see convenience methods eg {@link #highlightOngoing(String, String)} and {@link #highlight(String, String, Task)} + * and {@link HighlightTuple}. + */ + protected void setHighlight(String name, HighlightTuple tuple) { + highlights.put(name, tuple); + } + + /** 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)); + } + /** 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)); + } + /** 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)); + } + + /** As {@link #setHighlight(String, HighlightTuple)} for {@link #HIGHLIGHT_NAME_TRIGGERS} (as ongoing). */ + protected void highlightTriggers(String description) { + highlightOngoing(HIGHLIGHT_NAME_TRIGGERS, description); + } + protected void highlightTriggers(Sensor s, Object source) { + highlightTriggers(Collections.singleton(s), Collections.singleton(source)); + } + protected void highlightTriggers(Iterable> s, Object source) { + highlightTriggers(s, (Iterable) (source instanceof Iterable ? (Iterable)source : Collections.singleton(source))); + } + protected void highlightTriggers(Sensor s, Iterable sources) { + highlightTriggers(Collections.singleton(s), sources); + } + protected void highlightTriggers(Iterable> sensors, Iterable sources) { + StringBuilder msg = new StringBuilder("Listening for "); + boolean firstWord = true; + if (sensors!=null) for (Object s: sensors) { --- End diff -- do we have a style guide for brooklyn? I have never seen someone put a for loop on the same line as an if. Seems to break with our coding conventions. ---