edgent-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlaboss <...@git.apache.org>
Subject [GitHub] incubator-quarks pull request #156: QUARKS-217 Promote IotDevice heart beat ...
Date Tue, 12 Jul 2016 18:08:00 GMT
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.
---

Mime
View raw message