Skip to content

Commit 7375b70

Browse files
authored
0.58.0
* Requester subscription interface changes. * Fix subscription bug caused by changing paths for DSIResponder.
2 parents d163d93 + f13a9b8 commit 7375b70

23 files changed

+250
-124
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ subprojects {
55
apply plugin: 'maven'
66

77
group 'org.iot-dsa'
8-
version '0.57.0'
8+
version '0.58.0'
99

1010
sourceCompatibility = 1.8
1111
targetCompatibility = 1.8

dslink-v2-poc/src/main/java/org/iot/dsa/dslink/poc/MainNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Collection;
44
import org.iot.dsa.DSRuntime;
55
import org.iot.dsa.dslink.DSMainNode;
6+
import org.iot.dsa.dslink.requester.SimpleListHandler;
67
import org.iot.dsa.node.DSBool;
78
import org.iot.dsa.node.DSDouble;
89
import org.iot.dsa.node.DSElement;

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/requester/DSOutboundListStub.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ public boolean isStreamOpen() {
158158
}
159159
}
160160

161+
@Override
162+
public DSIValue getParams() {
163+
return null;
164+
}
165+
166+
@Override
167+
public String getPath() {
168+
return DSOutboundListStub.this.getPath();
169+
}
170+
171+
@Override
172+
public OutboundStream getStream() {
173+
throw new IllegalStateException("This should not have been called");
174+
}
175+
161176
@Override
162177
public void onClose() {
163178
for (OutboundListHandler h : handlers) {

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/requester/DSOutboundStub.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.iot.dsa.node.DSMap;
99

1010
/**
11-
* All stubs manage the lifecycle of a request and are also the outbound stream passed back to the
11+
* All stubs manage the lifecycle of a request and are also the OutboundStream passed back to the
1212
* requester.
1313
*
1414
* @author Daniel Shapiro, Aaron Hansen
@@ -59,10 +59,12 @@ public DSSession getSession() {
5959
}
6060

6161
public void handleClose() {
62-
if (!open) {
63-
return;
62+
synchronized (this) {
63+
if (!open) {
64+
return;
65+
}
66+
open = false;
6467
}
65-
open = false;
6668
try {
6769
getHandler().onClose();
6870
} catch (Exception x) {

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/requester/DSOutboundSubscribeStub.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import org.iot.dsa.dslink.requester.OutboundStream;
44
import org.iot.dsa.dslink.requester.OutboundSubscribeHandler;
55
import org.iot.dsa.node.DSElement;
6+
import org.iot.dsa.node.DSIValue;
7+
import org.iot.dsa.node.DSLong;
68
import org.iot.dsa.node.DSStatus;
79
import org.iot.dsa.time.DSDateTime;
810

911
/**
1012
* Manages the lifecycle of a single subscription and is also the outbound stream passed to the
1113
* requester.
1214
* <p>
13-
* <p>
14-
* <p>
1515
* There can be multiple subscriptions to a single path. They are all contained in a
1616
* DSOutboundSubscription object.
1717
*
@@ -22,13 +22,17 @@ class DSOutboundSubscribeStub implements OutboundStream {
2222
private DSOutboundSubscribeStub next; //linked list in subscription object
2323
private boolean open = true;
2424
private String path;
25-
private int qos = 0;
25+
private DSIValue qos;
2626
private OutboundSubscribeHandler request;
2727
private DSOutboundSubscription sub;
2828

29-
public DSOutboundSubscribeStub(String path, int qos, OutboundSubscribeHandler request) {
29+
public DSOutboundSubscribeStub(String path, DSIValue qos, OutboundSubscribeHandler request) {
3030
this.path = path;
31-
this.qos = qos;
31+
if (qos == null) {
32+
this.qos = DSLong.valueOf(0);
33+
} else {
34+
this.qos = qos;
35+
}
3236
this.request = request;
3337
}
3438

@@ -57,7 +61,7 @@ public String getPath() {
5761
}
5862

5963
public int getQos() {
60-
return qos;
64+
return qos.toElement().toInt();
6165
}
6266

6367
@Override
@@ -77,7 +81,7 @@ public void update(DSDateTime ts, DSElement value, DSStatus status) {
7781
}
7882

7983
/**
80-
* The next stub in the parents stubs object.
84+
* The next stub in the parent stubs object.
8185
*/
8286
void setNext(DSOutboundSubscribeStub next) {
8387
this.next = next;

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/requester/DSOutboundSubscriptions.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.iot.dsa.io.DSIWriter;
1414
import org.iot.dsa.logging.DSLogger;
1515
import org.iot.dsa.node.DSElement;
16+
import org.iot.dsa.node.DSIValue;
1617
import org.iot.dsa.node.DSLong;
1718
import org.iot.dsa.node.DSNull;
1819
import org.iot.dsa.node.DSStatus;
@@ -265,7 +266,7 @@ void sendSubscribe(DSOutboundSubscription sub) {
265266
/**
266267
* Create or update a subscription.
267268
*/
268-
OutboundSubscribeHandler subscribe(String path, int qos, OutboundSubscribeHandler req) {
269+
OutboundSubscribeHandler subscribe(String path, DSIValue qos, OutboundSubscribeHandler req) {
269270
trace(trace() ? String.format("Subscribe (qos=%s) %s", qos, path) : null);
270271
DSOutboundSubscribeStub stub = new DSOutboundSubscribeStub(path, qos, req);
271272
DSOutboundSubscription sub = null;
@@ -277,7 +278,7 @@ OutboundSubscribeHandler subscribe(String path, int qos, OutboundSubscribeHandle
277278
}
278279
}
279280
try {
280-
req.onInit(path, DSLong.valueOf(sub.getQos()), stub);
281+
req.onInit(path, qos, stub);
281282
} catch (Exception x) {
282283
error(path, x);
283284
}

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/requester/DSRequester.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.iot.dsa.dslink.requester.OutboundStream;
1717
import org.iot.dsa.dslink.requester.OutboundSubscribeHandler;
1818
import org.iot.dsa.node.DSIValue;
19+
import org.iot.dsa.node.DSLong;
1920
import org.iot.dsa.node.DSMap;
2021
import org.iot.dsa.node.DSNode;
2122

@@ -131,7 +132,7 @@ public OutboundRequestHandler set(String path, DSIValue value, OutboundRequestHa
131132
}
132133

133134
@Override
134-
public OutboundSubscribeHandler subscribe(String path, int qos, OutboundSubscribeHandler req) {
135+
public OutboundSubscribeHandler subscribe(String path, DSIValue qos, OutboundSubscribeHandler req) {
135136
return subscriptions.subscribe(path, qos, req);
136137
}
137138

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/responder/DSInboundList.java

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.acuity.iot.dsa.dslink.protocol.message.DSTarget;
66
import com.acuity.iot.dsa.dslink.protocol.message.MessageWriter;
77
import com.acuity.iot.dsa.dslink.protocol.message.OutboundMessage;
8+
import java.io.UnsupportedEncodingException;
9+
import java.net.URLEncoder;
810
import java.util.Iterator;
911
import org.iot.dsa.DSRuntime;
1012
import org.iot.dsa.dslink.DSIResponder;
@@ -21,13 +23,15 @@
2123
import org.iot.dsa.node.DSMetadata;
2224
import org.iot.dsa.node.DSNode;
2325
import org.iot.dsa.node.DSPath;
26+
import org.iot.dsa.node.DSString;
2427
import org.iot.dsa.node.DSValueType;
2528
import org.iot.dsa.node.action.ActionSpec;
2629
import org.iot.dsa.node.action.DSAction;
2730
import org.iot.dsa.node.event.DSEvent;
2831
import org.iot.dsa.node.event.DSISubscriber;
2932
import org.iot.dsa.node.event.DSISubscription;
3033
import org.iot.dsa.security.DSPermission;
34+
import org.iot.dsa.util.DSException;
3135

3236
/**
3337
* List implementation for a responder.
@@ -148,7 +152,7 @@ public void onClose(Integer requestId) {
148152

149153
@Override
150154
public void onClosed(DSISubscription subscription) {
151-
subscription = null;
155+
this.subscription = null;
152156
close();
153157
}
154158

@@ -649,45 +653,51 @@ private void enqueueResponse() {
649653
* Properly formats boolean and enum ranges for v1 and v2.
650654
*/
651655
private void fixRangeTypes(DSMap arg) {
652-
String type = arg.getString(DSMetadata.TYPE);
653-
if ("bool".equals(type)) {
654-
DSList range = (DSList) arg.remove(DSMetadata.BOOLEAN_RANGE);
655-
if ((range == null) || (range.size() != 2)) {
656-
return;
657-
} else {
656+
try {
657+
String type = arg.getString(DSMetadata.TYPE);
658+
if ("bool".equals(type)) {
659+
DSList range = (DSList) arg.remove(DSMetadata.BOOLEAN_RANGE);
660+
if ((range == null) || (range.size() != 2)) {
661+
return;
662+
} else {
663+
String utf8 = DSString.UTF8.toString();
664+
cacheBuf.setLength(0);
665+
cacheBuf.append(type);
666+
cacheBuf.append('[');
667+
cacheBuf.append(URLEncoder.encode(range.get(0).toString(), utf8));
668+
cacheBuf.append(',');
669+
cacheBuf.append(URLEncoder.encode(range.get(1).toString(), utf8));
670+
cacheBuf.append(']');
671+
if (getResponder().isV1()) {
672+
arg.put(DSMetadata.TYPE, cacheBuf.toString());
673+
} else {
674+
arg.put(DSMetadata.EDITOR, cacheBuf.toString());
675+
}
676+
}
677+
} else if ("enum".equals(type) || "string".equals(type)) {
678+
DSList range = (DSList) arg.remove(DSMetadata.ENUM_RANGE);
679+
if (range == null) {
680+
return;
681+
}
658682
cacheBuf.setLength(0);
659-
cacheBuf.append(type);
683+
cacheBuf.append("enum");
660684
cacheBuf.append('[');
661-
cacheBuf.append(range.get(0).toString());
662-
cacheBuf.append(',');
663-
cacheBuf.append(range.get(1).toString());
685+
String utf8 = DSString.UTF8.toString();
686+
for (int i = 0, len = range.size(); i < len; i++) {
687+
if (i > 0) {
688+
cacheBuf.append(',');
689+
}
690+
cacheBuf.append(URLEncoder.encode(range.get(i).toString(), utf8));
691+
}
664692
cacheBuf.append(']');
665693
if (getResponder().isV1()) {
666694
arg.put(DSMetadata.TYPE, cacheBuf.toString());
667695
} else {
668696
arg.put(DSMetadata.EDITOR, cacheBuf.toString());
669697
}
670698
}
671-
} else if ("enum".equals(type) || "string".equals(type)) {
672-
DSList range = (DSList) arg.remove(DSMetadata.ENUM_RANGE);
673-
if (range == null) {
674-
return;
675-
}
676-
cacheBuf.setLength(0);
677-
cacheBuf.append("enum");
678-
cacheBuf.append('[');
679-
for (int i = 0, len = range.size(); i < len; i++) {
680-
if (i > 0) {
681-
cacheBuf.append(',');
682-
}
683-
cacheBuf.append(range.get(i).toString());
684-
}
685-
cacheBuf.append(']');
686-
if (getResponder().isV1()) {
687-
arg.put(DSMetadata.TYPE, cacheBuf.toString());
688-
} else {
689-
arg.put(DSMetadata.EDITOR, cacheBuf.toString());
690-
}
699+
} catch (UnsupportedEncodingException x) {
700+
DSException.throwRuntime(x);
691701
}
692702
}
693703

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/responder/DSInboundRequest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,50 @@ public abstract class DSInboundRequest extends DSLogger implements InboundReques
2626
// Methods in alphabetical order
2727
///////////////////////////////////////////////////////////////////////////
2828

29-
public DSLink getLink() {
29+
public final DSLink getLink() {
3030
if (link == null) {
3131
link = responder.getLink();
3232
}
3333
return link;
3434
}
3535

36-
public String getPath() {
36+
public final String getPath() {
3737
return path;
3838
}
3939

40-
public Integer getRequestId() {
40+
public final Integer getRequestId() {
4141
return requestId;
4242
}
4343

44-
public DSResponder getResponder() {
44+
public final DSResponder getResponder() {
4545
return responder;
4646
}
4747

48-
public DSSession getSession() {
48+
public final DSSession getSession() {
4949
return session;
5050
}
5151

52-
public DSInboundRequest setLink(DSLink link) {
52+
public final DSInboundRequest setLink(DSLink link) {
5353
this.link = link;
5454
return this;
5555
}
5656

57-
public DSInboundRequest setPath(String path) {
57+
public final DSInboundRequest setPath(String path) {
5858
this.path = path;
5959
return this;
6060
}
6161

62-
public DSInboundRequest setRequestId(Integer requestId) {
62+
public final DSInboundRequest setRequestId(Integer requestId) {
6363
this.requestId = requestId;
6464
return this;
6565
}
6666

67-
public DSInboundRequest setResponder(DSResponder responder) {
67+
public final DSInboundRequest setResponder(DSResponder responder) {
6868
this.responder = responder;
6969
return this;
7070
}
7171

72-
public DSInboundRequest setSession(DSSession session) {
72+
public final DSInboundRequest setSession(DSSession session) {
7373
this.session = session;
7474
return this;
7575
}

0 commit comments

Comments
 (0)