You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@edgent.apache.org by dlaboss <gi...@git.apache.org> on 2016/06/30 19:20:47 UTC

[GitHub] incubator-quarks pull request #156: QUARKS-217 Promote IotDevice heart beat ...

GitHub user dlaboss opened a pull request:

    https://github.com/apache/incubator-quarks/pull/156

    QUARKS-217  Promote IotDevice heart beat for reusability

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dlaboss/incubator-quarks quarks-217-iotHeartBeat

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-quarks/pull/156.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #156
    
----
commit 16c3c03ee3f2db6f17cfa4632a5608fd5a2f7bc7
Author: Dale LaBossiere <dl...@us.ibm.com>
Date:   2016-06-30T19:17:21Z

    QUARKS-217  Promote IotDevice heart beat for reusability

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request #156: QUARKS-217 Promote IotDevice heart beat ...

Posted by dlaboss <gi...@git.apache.org>.
Github user dlaboss commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/156#discussion_r70481679
  
    --- Diff: samples/connectors/src/main/java/quarks/samples/connectors/iotf/IotfSensors.java ---
    @@ -119,20 +119,8 @@ public static void simulatedSensors(IotDevice device, boolean print) {
          * @param print true to print generated heartbeat tuples to System.out.
          */
         public static void heartBeat(IotDevice device, boolean print) {
    -        // In addition create a heart beat event to
    -        // ensure there is some immediate output and
    -        // the connection to IoTF happens as soon as possible.
    -        TStream<Date> hb = device.topology().poll(() -> new Date(), 1, TimeUnit.MINUTES);
    -        // Convert to JSON
    -        TStream<JsonObject> hbj = hb.map(d -> {
    -            JsonObject j = new  JsonObject();
    -            j.addProperty("when", d.toString());
    -            j.addProperty("hearbeat", d.getTime());
    -            return j;
    -        });
    -        if (print)
    -            hbj.print();
    -        device.events(hbj, "heartbeat", QoS.FIRE_AND_FORGET);
    +      HeartBeat.addHeartBeat(device, 1, TimeUnit.MINUTES,
    +          "heartbeat", stream -> { if (print) stream.print(); });
    --- End diff --
    
    actually it's really a stream... see the addHeartBeat() signature and javadoc.  but I see the @param for the consumer is lacking text and will add that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request #156: QUARKS-217 Promote IotDevice heart beat ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-quarks/pull/156


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request #156: QUARKS-217 Promote IotDevice heart beat ...

Posted by dlaboss <gi...@git.apache.org>.
Github user dlaboss commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/156#discussion_r70490173
  
    --- Diff: connectors/iot/src/main/java/quarks/connectors/iot/HeartBeat.java ---
    @@ -0,0 +1,83 @@
    +/*
    +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 quarks.connectors.iot;
    +
    +import java.util.Date;
    +import java.util.concurrent.TimeUnit;
    +
    +import com.google.gson.JsonObject;
    +
    +import quarks.function.Functions;
    +import quarks.topology.TStream;
    +import quarks.topology.plumbing.PlumbingStreams;
    +
    +public class HeartBeat {
    +  private HeartBeat() { };
    +  
    +  /**
    +   * Add IoT device heart beat processing to a topology.
    +   * <P>
    +   * An IoTDevice event containing heart beat information 
    +   * is periodically published to the specified {@code eventId}.
    +   * </P>
    +   * <P>
    +   * The heart beat provides clients of the IoT hub with liveness information
    +   * about the device and its connection to the hub.
    +   * </P>
    +   * <P>
    +   * The heart beat also ensures there is some immediate output so
    +   * the connection to the IoT hub happens as soon as possible.
    +   * In the case where there may not otherwise be
    +   * IoT events to publish, a heart beat ensures a connection
    +   * to the IoT hub is maintained.
    +   * </P>
    +   * <P>
    +   * The heart beat's event payload is the JSON for a JsonObject with the
    +   * heart beat's properties:
    +   * <ul>
    +   * <li>"when" : (string) {@link Date#toString()}</li>
    +   * <li>"time" : (number) {@link System#currentTimeMillis()}</li>
    +   * </ul> 
    +   * 
    +   * @param iotDevice IoT hub device
    +   * @param period the heart beat period
    +   * @param unit TimeUnit for the period
    +   * @param eventId the IotDevice eventId to use for the event
    +   */
    +  public static void addHeartBeat(IotDevice iotDevice, long period, TimeUnit unit, String eventId) {
    +    TStream<Date> hb = iotDevice.topology().poll(
    +        () -> new Date(),
    +        period, unit).tag("heartbeat");
    +    // Convert to JSON
    +    TStream<JsonObject> hbj = hb.map(date -> {
    +        JsonObject j = new  JsonObject();
    +        j.addProperty("when", date.toString());
    --- End diff --
    
    agreed!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request #156: QUARKS-217 Promote IotDevice heart beat ...

Posted by dlaboss <gi...@git.apache.org>.
Github user dlaboss commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/156#discussion_r70490355
  
    --- Diff: samples/connectors/src/main/java/quarks/samples/connectors/iotf/IotfSensors.java ---
    @@ -119,20 +119,8 @@ public static void simulatedSensors(IotDevice device, boolean print) {
          * @param print true to print generated heartbeat tuples to System.out.
          */
         public static void heartBeat(IotDevice device, boolean print) {
    -        // In addition create a heart beat event to
    -        // ensure there is some immediate output and
    -        // the connection to IoTF happens as soon as possible.
    -        TStream<Date> hb = device.topology().poll(() -> new Date(), 1, TimeUnit.MINUTES);
    -        // Convert to JSON
    -        TStream<JsonObject> hbj = hb.map(d -> {
    -            JsonObject j = new  JsonObject();
    -            j.addProperty("when", d.toString());
    -            j.addProperty("hearbeat", d.getTime());
    -            return j;
    -        });
    -        if (print)
    -            hbj.print();
    -        device.events(hbj, "heartbeat", QoS.FIRE_AND_FORGET);
    +      HeartBeat.addHeartBeat(device, 1, TimeUnit.MINUTES,
    +          "heartbeat", stream -> { if (print) stream.print(); });
    --- End diff --
    
    Actually, don't know what motivated me to express it that way. I'll simplify it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request #156: QUARKS-217 Promote IotDevice heart beat ...

Posted by ddebrunner <gi...@git.apache.org>.
Github user ddebrunner commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/156#discussion_r69611351
  
    --- Diff: samples/connectors/src/main/java/quarks/samples/connectors/iotf/IotfSensors.java ---
    @@ -119,20 +119,8 @@ public static void simulatedSensors(IotDevice device, boolean print) {
          * @param print true to print generated heartbeat tuples to System.out.
          */
         public static void heartBeat(IotDevice device, boolean print) {
    -        // In addition create a heart beat event to
    -        // ensure there is some immediate output and
    -        // the connection to IoTF happens as soon as possible.
    -        TStream<Date> hb = device.topology().poll(() -> new Date(), 1, TimeUnit.MINUTES);
    -        // Convert to JSON
    -        TStream<JsonObject> hbj = hb.map(d -> {
    -            JsonObject j = new  JsonObject();
    -            j.addProperty("when", d.toString());
    -            j.addProperty("hearbeat", d.getTime());
    -            return j;
    -        });
    -        if (print)
    -            hbj.print();
    -        device.events(hbj, "heartbeat", QoS.FIRE_AND_FORGET);
    +      HeartBeat.addHeartBeat(device, 1, TimeUnit.MINUTES,
    +          "heartbeat", stream -> { if (print) stream.print(); });
    --- End diff --
    
    Found the use of 'stream' a little confusing, since it's the tuple on the stream, not the stream itself.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request #156: QUARKS-217 Promote IotDevice heart beat ...

Posted by ddebrunner <gi...@git.apache.org>.
Github user ddebrunner commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/156#discussion_r69611096
  
    --- Diff: connectors/iot/src/main/java/quarks/connectors/iot/HeartBeat.java ---
    @@ -0,0 +1,83 @@
    +/*
    +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 quarks.connectors.iot;
    +
    +import java.util.Date;
    +import java.util.concurrent.TimeUnit;
    +
    +import com.google.gson.JsonObject;
    +
    +import quarks.function.Functions;
    +import quarks.topology.TStream;
    +import quarks.topology.plumbing.PlumbingStreams;
    +
    +public class HeartBeat {
    +  private HeartBeat() { };
    +  
    +  /**
    +   * Add IoT device heart beat processing to a topology.
    +   * <P>
    +   * An IoTDevice event containing heart beat information 
    +   * is periodically published to the specified {@code eventId}.
    +   * </P>
    +   * <P>
    +   * The heart beat provides clients of the IoT hub with liveness information
    +   * about the device and its connection to the hub.
    +   * </P>
    +   * <P>
    +   * The heart beat also ensures there is some immediate output so
    +   * the connection to the IoT hub happens as soon as possible.
    +   * In the case where there may not otherwise be
    +   * IoT events to publish, a heart beat ensures a connection
    +   * to the IoT hub is maintained.
    +   * </P>
    +   * <P>
    +   * The heart beat's event payload is the JSON for a JsonObject with the
    +   * heart beat's properties:
    +   * <ul>
    +   * <li>"when" : (string) {@link Date#toString()}</li>
    +   * <li>"time" : (number) {@link System#currentTimeMillis()}</li>
    +   * </ul> 
    +   * 
    +   * @param iotDevice IoT hub device
    +   * @param period the heart beat period
    +   * @param unit TimeUnit for the period
    +   * @param eventId the IotDevice eventId to use for the event
    +   */
    +  public static void addHeartBeat(IotDevice iotDevice, long period, TimeUnit unit, String eventId) {
    +    TStream<Date> hb = iotDevice.topology().poll(
    +        () -> new Date(),
    +        period, unit).tag("heartbeat");
    +    // Convert to JSON
    +    TStream<JsonObject> hbj = hb.map(date -> {
    +        JsonObject j = new  JsonObject();
    +        j.addProperty("when", date.toString());
    --- End diff --
    
    Might be good to have this as an ISO8601 date format.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---