You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dl...@apache.org on 2016/03/14 18:59:35 UTC
[1/2] incubator-quarks git commit: Use new IotDevice constants
Repository: incubator-quarks
Updated Branches:
refs/heads/master c600e975f -> 3bec70e7e
Use new IotDevice constants
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/96b9ef1b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/96b9ef1b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/96b9ef1b
Branch: refs/heads/master
Commit: 96b9ef1bdb9d9854924f352394fb8703521523ff
Parents: c9af34f
Author: Dale LaBossiere <dl...@us.ibm.com>
Authored: Mon Mar 14 10:40:51 2016 -0400
Committer: Dale LaBossiere <dl...@us.ibm.com>
Committed: Mon Mar 14 13:16:09 2016 -0400
----------------------------------------------------------------------
.../java/quarks/connectors/mqtt/iot/MqttDevice.java | 16 ++++++++--------
.../samples/apps/mqtt/AbstractMqttApplication.java | 4 +++-
2 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/96b9ef1b/connectors/mqtt/src/main/java/quarks/connectors/mqtt/iot/MqttDevice.java
----------------------------------------------------------------------
diff --git a/connectors/mqtt/src/main/java/quarks/connectors/mqtt/iot/MqttDevice.java b/connectors/mqtt/src/main/java/quarks/connectors/mqtt/iot/MqttDevice.java
index e0e99aa..7a9d1f7 100644
--- a/connectors/mqtt/src/main/java/quarks/connectors/mqtt/iot/MqttDevice.java
+++ b/connectors/mqtt/src/main/java/quarks/connectors/mqtt/iot/MqttDevice.java
@@ -75,12 +75,12 @@ import quarks.topology.json.JsonFunctions;
*
* // publish JSON "status" device event tuples every hour
* TStream<JsonObject> myStatusEvents = t.poll(myGetStatusAsJson(), 1, TimeUnit.HOURS);
- * mqttDevice.events(myJsonEvents, "status", QoS.FIRE_AND_FORGET);
+ * mqttDevice.events(myStatusEvents, "status", QoS.FIRE_AND_FORGET);
*
* // handle a device command. In this example the payload is expected
* // to be JSON and have a "value" property containing the new threshold.
* mqttDevice.command("setSensorThreshold")
- * .sink(json -> setSensorThreshold(json.get("payload").getAsJsonObject().get("value").getAsString());
+ * .sink(json -> setSensorThreshold(json.get(CMD_PAYLOAD).getAsJsonObject().get("value").getAsString());
* }</pre>
*/
public class MqttDevice implements IotDevice {
@@ -215,7 +215,7 @@ public class MqttDevice implements IotDevice {
if (commands.length != 0) {
Set<String> uniqueCommands = new HashSet<>();
uniqueCommands.addAll(Arrays.asList(commands));
- all = all.filter(jo -> uniqueCommands.contains(jo.get("command").getAsString()));
+ all = all.filter(jo -> uniqueCommands.contains(jo.get(CMD_ID).getAsString()));
}
return all;
@@ -227,15 +227,15 @@ public class MqttDevice implements IotDevice {
commandStream = connector.subscribe(topicFilter, commandQoS,
(topic, payload) -> {
JsonObject jo = new JsonObject();
- jo.addProperty("command", extractCmd(topic));
- jo.addProperty("tsms", System.currentTimeMillis());
+ jo.addProperty(CMD_ID, extractCmd(topic));
+ jo.addProperty(CMD_TS, System.currentTimeMillis());
String fmt = extractCmdFmt(topic);
- jo.addProperty("format", fmt);
+ jo.addProperty(CMD_FORMAT, fmt);
if ("json".equals(fmt)) {
- jo.add("payload", JsonFunctions.fromBytes().apply(payload));
+ jo.add(CMD_PAYLOAD, JsonFunctions.fromBytes().apply(payload));
}
else {
- jo.addProperty("payload", new String(payload, StandardCharsets.UTF_8));
+ jo.addProperty(CMD_PAYLOAD, new String(payload, StandardCharsets.UTF_8));
}
return jo;
});
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/96b9ef1b/samples/apps/src/main/java/quarks/samples/apps/mqtt/AbstractMqttApplication.java
----------------------------------------------------------------------
diff --git a/samples/apps/src/main/java/quarks/samples/apps/mqtt/AbstractMqttApplication.java b/samples/apps/src/main/java/quarks/samples/apps/mqtt/AbstractMqttApplication.java
index 5a88abf..5d71ad9 100644
--- a/samples/apps/src/main/java/quarks/samples/apps/mqtt/AbstractMqttApplication.java
+++ b/samples/apps/src/main/java/quarks/samples/apps/mqtt/AbstractMqttApplication.java
@@ -4,6 +4,8 @@
*/
package quarks.samples.apps.mqtt;
+import static quarks.connectors.iot.IotDevice.CMD_PAYLOAD;
+
import java.util.Arrays;
import com.google.gson.JsonObject;
@@ -99,7 +101,7 @@ public abstract class AbstractMqttApplication extends AbstractApplication {
* @return the command's argument value
*/
public String getCommandValueString(JsonObject jo) {
- return jo.get("payload").getAsJsonObject().get("value").getAsString();
+ return jo.get(CMD_PAYLOAD).getAsJsonObject().get("value").getAsString();
}
}
[2/2] incubator-quarks git commit: Merge branch 'pr-8'
Posted by dl...@apache.org.
Merge branch 'pr-8'
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/3bec70e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/3bec70e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/3bec70e7
Branch: refs/heads/master
Commit: 3bec70e7e4c60d15ae0d353054bc666166bcd9ee
Parents: c600e97 96b9ef1
Author: Dale LaBossiere <dl...@us.ibm.com>
Authored: Mon Mar 14 13:58:44 2016 -0400
Committer: Dale LaBossiere <dl...@us.ibm.com>
Committed: Mon Mar 14 13:58:44 2016 -0400
----------------------------------------------------------------------
.../java/quarks/connectors/mqtt/iot/MqttDevice.java | 16 ++++++++--------
.../samples/apps/mqtt/AbstractMqttApplication.java | 4 +++-
2 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------