From 9414a9fe908dafa56fc23367e7b97e78c4bf42fc Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 16 Oct 2019 15:15:28 -0700 Subject: [PATCH] 0.23.0 * Fix updating subscription value for multiple requester subscriptions to the same path. * Fix updating list requests for previously non-existing nodes. * Update Jackson dependencies. * Fix configuration NPE for programmatically created links. * Add jzlib dependency. --- build.gradle | 4 +- internal/runtime_shared/build.gradle | 12 ++-- .../dsa/iot/dslink/config/Configuration.java | 3 + .../org/dsa/iot/dslink/link/Requester.java | 65 ++++++++++--------- .../methods/responses/ListResponse.java | 10 ++- .../iot/dslink/node/SubscriptionManager.java | 6 ++ 6 files changed, 61 insertions(+), 39 deletions(-) diff --git a/build.gradle b/build.gradle index e8146099..cc494d09 100755 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ subprojects { apply plugin: 'java-library' apply plugin: 'maven' - version = '0.22.3' + version = '0.23.0' sourceCompatibility = 1.7 targetCompatibility = 1.7 @@ -30,6 +30,6 @@ subprojects { } wrapper { - gradleVersion = '5.6' + gradleVersion = '5.6.2' } diff --git a/internal/runtime_shared/build.gradle b/internal/runtime_shared/build.gradle index cbfe379e..12e62c63 100644 --- a/internal/runtime_shared/build.gradle +++ b/internal/runtime_shared/build.gradle @@ -3,11 +3,13 @@ apply from: '../../bintray.gradle' description = 'Shared Runtime for the SDK' dependencies { - api 'org.bouncycastle:bcprov-jdk15on:1.62' - api 'io.netty:netty-all:4.1.38.Final' + api 'org.bouncycastle:bcprov-jdk15on:1.64' + api 'io.netty:netty-all:4.1.42.Final' + //jzlib is an optional dependency of netty, it is possible to trigger usage + implementation 'com.jcraft:jzlib:1.1.3' api 'com.beust:jcommander:1.72' - api 'org.msgpack:jackson-dataformat-msgpack:0.8.17' + api 'org.msgpack:jackson-dataformat-msgpack:0.8.18' //the following overrides the dependency in jackson-dataformat-msgpack - //and can be removed once msgpack catches up to 2.9.9.3 - api 'com.fasterxml.jackson.core:jackson-databind:2.9.9.3' + //and can be removed once msgpack catches up to 2.9.10 + api 'com.fasterxml.jackson.core:jackson-databind:2.9.10' } diff --git a/sdk/dslink/src/main/java/org/dsa/iot/dslink/config/Configuration.java b/sdk/dslink/src/main/java/org/dsa/iot/dslink/config/Configuration.java index b5a681a4..b3d823df 100755 --- a/sdk/dslink/src/main/java/org/dsa/iot/dslink/config/Configuration.java +++ b/sdk/dslink/src/main/java/org/dsa/iot/dslink/config/Configuration.java @@ -122,6 +122,9 @@ public URLInfo getAuthEndpoint() { * Get a config from the dslink.json file. */ public T getConfig(String field, T defaultVal) { + if (configs == null) { + return defaultVal; + } JsonObject param = configs.get(field); if (param == null) { return defaultVal; diff --git a/sdk/dslink/src/main/java/org/dsa/iot/dslink/link/Requester.java b/sdk/dslink/src/main/java/org/dsa/iot/dslink/link/Requester.java index 5001879e..9eab77fc 100755 --- a/sdk/dslink/src/main/java/org/dsa/iot/dslink/link/Requester.java +++ b/sdk/dslink/src/main/java/org/dsa/iot/dslink/link/Requester.java @@ -572,6 +572,7 @@ private void sendRequest(RequestWrapper wrapper, private static class HandlerAdapter implements Handler { Sub first; + SubscriptionValue lastEvent; ConcurrentLinkedQueue list = null; int qos = 0; int size; @@ -596,42 +597,48 @@ public void handle(SubscriptionValue event) { for (Sub s : list) { s.handle(event); } + lastEvent = event; } - synchronized void add(SubData data, Handler handler) { - Integer q = data.getQos(); - if (q == null) { - q = 0; - } - if (q > qos) { - this.qos = q; - } - if (first != null) { - if (first.isSameHandler(handler)) { - if (first.isQosChange(q)) { - qos = q; + void add(SubData data, Handler handler) { + Sub sub = null; + synchronized (this) { + Integer q = data.getQos(); + if (q == null) { + q = 0; + } + if (q > qos) { + this.qos = q; + } + if (first != null) { + if (first.isSameHandler(handler)) { + if (first.isQosChange(q)) { + qos = q; + } + return; } - return; } - } - if (list == null) { - list = new ConcurrentLinkedQueue<>(); - list.add(first); - first = null; - list.add(new Sub(handler, q)); - size++; - return; - } - for (Sub sub : list) { - if (sub.isSameHandler(handler)) { - if (sub.isQosChange(q)) { - updateQos(); + if (list == null) { + list = new ConcurrentLinkedQueue<>(); + list.add(first); + first = null; + } else { + for (Sub tmp : list) { + if (tmp.isSameHandler(handler)) { + if (tmp.isQosChange(q)) { + updateQos(); + } + return; + } } - return; } + size++; + sub = new Sub(handler, q); + list.add(sub); + } + if (lastEvent != null) { + sub.handle(lastEvent); } - size++; - list.add(new Sub(handler, q)); } int qos() { diff --git a/sdk/dslink/src/main/java/org/dsa/iot/dslink/methods/responses/ListResponse.java b/sdk/dslink/src/main/java/org/dsa/iot/dslink/methods/responses/ListResponse.java index 249d4130..f2edba1a 100755 --- a/sdk/dslink/src/main/java/org/dsa/iot/dslink/methods/responses/ListResponse.java +++ b/sdk/dslink/src/main/java/org/dsa/iot/dslink/methods/responses/ListResponse.java @@ -34,10 +34,9 @@ public class ListResponse extends Response { private final DSLink link; private final SubscriptionManager manager; - private final int rid; - private final Node node; + private Node node; private final String path; - + private final int rid; private final Map updates = new HashMap<>(); public ListResponse(DSLink link, SubscriptionManager manager, @@ -277,6 +276,11 @@ public void multiChildrenUpdate(List children) { link.getWriter().writeResponse(resp); } + public void nodeCreated(Node node) { + this.node = node; + link.getWriter().writeResponse(getJsonResponse(null)); + } + @Override public void populate(JsonObject in) { JsonArray updates = in.get("updates"); diff --git a/sdk/dslink/src/main/java/org/dsa/iot/dslink/node/SubscriptionManager.java b/sdk/dslink/src/main/java/org/dsa/iot/dslink/node/SubscriptionManager.java index bdad8eb1..52519fba 100755 --- a/sdk/dslink/src/main/java/org/dsa/iot/dslink/node/SubscriptionManager.java +++ b/sdk/dslink/src/main/java/org/dsa/iot/dslink/node/SubscriptionManager.java @@ -259,6 +259,12 @@ public void postChildUpdate(Node child, boolean removed) { if (resp != null) { resp.childUpdate(child, removed); } + if (!removed) { + resp = pathSubsMap.get(child.getPath()); + if (resp != null) { + resp.nodeCreated(child); + } + } } /**