[
https://issues.apache.org/jira/browse/QUARKS-217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15373350#comment-15373350
]
ASF GitHub Bot commented on QUARKS-217:
---------------------------------------
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!
> promote IoT device heart beat to a connector utility
> ----------------------------------------------------
>
> Key: QUARKS-217
> URL: https://issues.apache.org/jira/browse/QUARKS-217
> Project: Quarks
> Issue Type: New Feature
> Components: Connectors
> Reporter: Dale LaBossiere
> Assignee: Dale LaBossiere
> Priority: Minor
>
> Promote the IotDevice heart beat utility present in the IotSensors sample to
> make it reusable.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)