Skip to content

Commit acfc0d5

Browse files
committed
1.1.3
sdk update
1 parent 80b7651 commit acfc0d5

File tree

5 files changed

+43
-39
lines changed

5 files changed

+43
-39
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies {
2626
//implementation 'org.iot-dsa:dslink-v2-websocket:+' //for a locally installed sdk
2727
implementation 'com.github.iot-dsa-v2.sdk-dslink-java-v2:dslink-v2-websocket:+'
2828
implementation 'commons-logging:commons-logging:+'
29-
implementation 'org.apache.commons:commons-lang3:3.6'
29+
implementation 'org.apache.commons:commons-lang3:3.8.1'
3030
implementation 'commons-io:commons-io:2.6'
3131
implementation 'com.squareup.okhttp3:okhttp:3.14.0'
3232
//implementation 'org.apache.cxf:cxf-rt-rs-security-oauth2:3.1.7'

dslink.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dslink-java-v2-restadapter",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "Java DSA to REST adpater DSLink",
55
"main": "bin/dslink-java-v2-restadapter",
66
"configs": {

src/main/java/org/iot/dsa/dslink/restadapter/MainNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ protected void declareDefaults() {
8080
@Override
8181
protected void onStarted() {
8282
instance = this;
83-
getLink().getUpstream().subscribe(new DSEventFilter(
83+
getLink().getConnection().subscribe(new DSEventFilter(
8484
((event, node, child, data) -> MainNode.setRequester(
85-
getLink().getUpstream().getRequester())),
85+
getLink().getConnection().getRequester())),
8686
DSLinkConnection.CONNECTED_EVENT,
8787
null));
8888
}

src/main/java/org/iot/dsa/dslink/restadapter/SubscriptionRule.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@
77
import org.iot.dsa.DSRuntime;
88
import org.iot.dsa.DSRuntime.Timer;
99
import org.iot.dsa.dslink.DSIRequester;
10+
import org.iot.dsa.dslink.requester.AbstractSubscribeHandler;
1011
import org.iot.dsa.dslink.requester.ErrorType;
1112
import org.iot.dsa.dslink.requester.OutboundStream;
12-
import org.iot.dsa.dslink.requester.OutboundSubscribeHandler;
13-
import org.iot.dsa.logging.DSLogger;
1413
import org.iot.dsa.node.DSElement;
1514
import org.iot.dsa.node.DSIValue;
15+
import org.iot.dsa.node.DSLong;
1616
import org.iot.dsa.node.DSMap;
1717
import org.iot.dsa.node.DSMap.Entry;
1818
import org.iot.dsa.node.DSStatus;
1919
import org.iot.dsa.time.DSDateTime;
20-
import org.iot.dsa.util.DSException;
2120
import okhttp3.Response;
2221

23-
public class SubscriptionRule extends DSLogger implements OutboundSubscribeHandler, UpdateSender {
22+
public class SubscriptionRule extends AbstractSubscribeHandler implements UpdateSender {
2423

2524
private AbstractRuleNode node;
26-
private OutboundStream stream;
25+
//private OutboundStream stream;
2726
private long lastUpdateTime = -1;
2827
private Timer future = null;
2928
private SubUpdate storedUpdate;
@@ -66,7 +65,7 @@ public void run() {
6665
private void init() {
6766
DSIRequester requester = MainNode.getRequester();
6867
int qos = 0;
69-
requester.subscribe(this.subPath, qos, this);
68+
requester.subscribe(this.subPath, DSLong.valueOf(qos), this);
7069
}
7170

7271
private void learnPattern() {
@@ -103,25 +102,28 @@ private void learnPattern() {
103102

104103
@Override
105104
public void onClose() {
106-
info("Rule with sub path " + subPath + ": onClose called");
107-
close();
105+
super.onClose();
106+
node.info("Rule with sub path " + subPath + ": onClose called");
107+
// close();
108108
}
109109

110110
@Override
111111
public void onError(ErrorType type, String msg) {
112-
info("Rule with sub path " + subPath + ": onError called with msg " + msg);
113-
DSException.throwRuntime(new RuntimeException(msg));
112+
super.onError(type, msg);
113+
node.info("Rule with sub path " + subPath + ": onError called with msg " + msg);
114+
// DSException.throwRuntime(new RuntimeException(msg));
114115
}
115116

116117
@Override
117118
public void onInit(String path, DSIValue qos, OutboundStream stream) {
118-
info("Rule with sub path " + subPath + ": onInit called");
119-
this.stream = stream;
119+
super.onInit(path, qos, stream);
120+
node.info("Rule with sub path " + subPath + ": onInit called");
121+
//this.stream = stream;
120122
}
121123

122124
@Override
123125
public void onUpdate(DSDateTime dateTime, DSElement value, DSStatus status) {
124-
info("Rule with sub path " + subPath + ": onUpdate called with value " + (value!=null ? value : "Null"));
126+
node.info("Rule with sub path " + subPath + ": onUpdate called with value " + (value!=null ? value : "Null"));
125127
storedUpdate = new SubUpdate(dateTime.toString(), value.toString(), status.toString(), dateTime.timeInMillis());
126128
if (lastUpdateTime < 0 || System.currentTimeMillis() - lastUpdateTime >= minRefreshRate) {
127129
if (future != null) {
@@ -188,7 +190,7 @@ private boolean sendUpdate(final SubUpdate update) {
188190
body = body.replaceAll(Constants.PLACEHOLDER_BLOCK_END, "");
189191
}
190192

191-
info("Rule with sub path " + subPath + ": sending Update with value " + (update.value!=null ? update.value : "Null"));
193+
node.info("Rule with sub path " + subPath + ": sending Update with value " + (update.value!=null ? update.value : "Null"));
192194

193195
Response resp = restInvoke(urlParams, body);
194196
return resp != null && resp.code() == 200;
@@ -227,7 +229,7 @@ public Queue<SubUpdate> sendBatchUpdate(Queue<SubUpdate> updates) {
227229
}
228230
sb.append(suffix);
229231
String body = sb.toString();
230-
info("Rule with sub path " + subPath + ": sending batch update");
232+
node.info("Rule with sub path " + subPath + ": sending batch update");
231233

232234
Response resp = restInvoke(urlParams, body);
233235
if (resp != null && resp.code() == 200) {
@@ -243,16 +245,16 @@ private Response restInvoke(DSMap urlParams, String body) {
243245
try {
244246
resp = getWebClientProxy().invoke(method, restUrl, urlParams, body);
245247
} catch (Exception e) {
246-
warn("", e);
248+
node.warn("", e);
247249
}
248250
node.responseRecieved(resp, rowNum);
249251
return resp;
250252
}
251253

252254
public void close() {
253-
if (stream != null && stream.isStreamOpen()) {
254-
info("Rule with sub path " + subPath + ": closing Stream");
255-
stream.closeStream();
255+
if (!isClosed() && getStream() != null) {
256+
node.info("Rule with sub path " + subPath + ": closing Stream");
257+
getStream().closeStream();
256258
}
257259
}
258260

src/main/java/org/iot/dsa/dslink/restadapter/TestSubscriptionRule.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
import org.iot.dsa.DSRuntime;
44
import org.iot.dsa.dslink.DSIRequester;
5+
import org.iot.dsa.dslink.requester.AbstractSubscribeHandler;
56
import org.iot.dsa.dslink.requester.ErrorType;
67
import org.iot.dsa.dslink.requester.OutboundStream;
78
import org.iot.dsa.dslink.requester.OutboundSubscribeHandler;
8-
import org.iot.dsa.logging.DSLogger;
99
import org.iot.dsa.node.DSElement;
1010
import org.iot.dsa.node.DSIValue;
11+
import org.iot.dsa.node.DSLong;
1112
import org.iot.dsa.node.DSStatus;
1213
import org.iot.dsa.time.DSDateTime;
13-
import org.iot.dsa.util.DSException;
1414

15-
public class TestSubscriptionRule extends DSLogger implements OutboundSubscribeHandler {
15+
public class TestSubscriptionRule extends AbstractSubscribeHandler implements OutboundSubscribeHandler {
1616

1717
private String subpath;
1818
private TestRuleNode node;
19-
private OutboundStream stream;
19+
// private OutboundStream stream;
2020

2121
public TestSubscriptionRule(TestRuleNode testRuleNode, String subpath) {
2222
this.subpath = subpath;
@@ -32,38 +32,40 @@ public void run() {
3232
protected void init() {
3333
DSIRequester requester = MainNode.getRequester();
3434
int qos = 0;
35-
requester.subscribe(this.subpath, qos, this);
35+
requester.subscribe(this.subpath, DSLong.valueOf(qos), this);
3636

3737
}
3838

3939
@Override
4040
public void onClose() {
41-
info("Test Rule with sub path " + subpath + ": onClose called");
42-
close();
41+
super.onClose();
42+
node.info("Test Rule with sub path " + subpath + ": onClose called");
43+
// close();
4344
}
4445

4546
@Override
4647
public void onError(ErrorType type, String msg) {
47-
info("Test Rule with sub path " + subpath + ": onError called with msg " + msg);
48-
DSException.throwRuntime(new RuntimeException(msg));
48+
super.onError(type, msg);
49+
node.info("Test Rule with sub path " + subpath + ": onError called with msg " + msg);
50+
// DSException.throwRuntime(new RuntimeException(msg));
4951
}
5052

5153
@Override
5254
public void onInit(String path, DSIValue qos, OutboundStream stream) {
53-
info("Test Rule with sub path " + subpath + ": onInit called");
54-
this.stream = stream;
55+
super.onInit(path, qos, stream);
56+
node.info("Test Rule with sub path " + subpath + ": onInit called");
57+
// this.stream = stream;
5558
}
5659

5760
@Override
5861
public void onUpdate(DSDateTime dateTime, DSElement value, DSStatus status) {
59-
info("Test Rule with sub path " + subpath + ": onUpdate called with value " + (value!=null ? value : "Null"));
60-
62+
node.info("Test Rule with sub path " + subpath + ": onUpdate called with value " + (value!=null ? value : "Null"));
6163
}
6264

6365
public void close() {
64-
if (stream != null && stream.isStreamOpen()) {
65-
info("Test Rule with sub path " + subpath + ": closing Stream");
66-
stream.closeStream();
66+
if (!isClosed() && getStream() != null) {
67+
node.info("Test Rule with sub path " + subpath + ": closing Stream");
68+
getStream().closeStream();
6769
}
6870
}
6971

0 commit comments

Comments
 (0)