Skip to content

Commit 7303700

Browse files
authored
0.46.0
* Refactor action api. * Refactor topic api. * JDK 1.8. * DSLinkConfig->DSLinkOptions and many changes.
2 parents 3621701 + f61f617 commit 7303700

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+699
-612
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ subprojects {
55
apply plugin: 'maven'
66

77
group 'org.iot-dsa'
8-
version '0.45.0'
8+
version '0.46.0'
99

10-
sourceCompatibility = 1.6
11-
targetCompatibility = 1.6
10+
sourceCompatibility = 1.8
11+
targetCompatibility = 1.8
1212

1313
repositories {
1414
mavenLocal()

dslink-v2-poc/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apply plugin: 'java'
22
apply plugin: 'application'
33

4-
sourceCompatibility = 1.6
5-
targetCompatibility = 1.6
4+
sourceCompatibility = 1.8
5+
targetCompatibility = 1.8
66
group 'org.iot-dsa'
77
mainClassName = 'org.iot.dsa.dslink.DSLink'
88

dslink-v2-poc/dslink.json

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,47 @@
55
"description": "Testing Link",
66
"main": "bin/dslink-java-v2-poc",
77
"configs": {
8-
"handler_class": {
8+
"handler_class_old": {
9+
"type": "string",
10+
"value": "org.iot.dsa.dslink.poc.MainNode"
11+
},
12+
"main-node": {
13+
"help": "Class name of the main node.",
914
"type": "string",
1015
"value": "org.iot.dsa.dslink.poc.MainNode"
1116
},
1217
"log": {
13-
"desc": "all, trace, debug, warn, info, error, admin, fatal, none",
18+
"help": "all, trace, debug, info, warn, error, off",
1419
"type": "enum",
15-
"value": "info"
20+
"value": "debug"
21+
},
22+
"msgpack": {
23+
"help": "Whether or not to use msgpack. Useful for debugging.",
24+
"type": "bool",
25+
"value": false
26+
},
27+
"broker": {
28+
"help": "Only set if running the link standalone.",
29+
"type": "url",
30+
"value": null
31+
},
32+
"key": {
33+
"help": "Public/private key pair used by the link.",
34+
"type": "path",
35+
"value": null
36+
},
37+
"name": {
38+
"help": "Overrides the name above.",
39+
"type": "string",
40+
"value": null
41+
},
42+
"nodes": {
43+
"help": "Path to the node configuration database file.",
44+
"type": "path",
45+
"value": null
1646
},
1747
"token": {
18-
"desc": "Authentication token for the broker.",
48+
"help": "Authentication token for the broker.",
1949
"type": "string",
2050
"value": null
2151
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ protected void declareDefaults() {
5656
declareDefault("Test", DSAction.DEFAULT);
5757
action = new DSAction();
5858
action.setResultType(ActionSpec.ResultType.VALUES);
59-
action.addValueResult("bool", DSBool.TRUE);
60-
action.addValueResult("long", DSLong.valueOf(0));
59+
action.addColumnMetadata("bool", DSBool.TRUE);
60+
action.addColumnMetadata("long", DSLong.valueOf(0));
6161
declareDefault("Values Action", action);
6262
//declareDefault("T./,;'<>?:\"[%]{/}bc", DSString.valueOf("abc")).setTransient(true);
6363
//notice the missing chars from above, dglux gets funky with the chars: <>?:\"

dslink-v2/src/main/java/org/iot/dsa/io/DSBase64.java renamed to dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/io/DSBase64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.iot.dsa.io;
1+
package com.acuity.iot.dsa.dslink.io;
22

33
import java.io.ByteArrayOutputStream;
44
import java.util.Arrays;

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

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void run() {
179179
}
180180
if (info.isNode()) {
181181
node = info.getNode();
182-
node.subscribe(DSNode.INFO_TOPIC, null, this);
182+
node.subscribe(DSNode.INFO_TOPIC, null, null, this);
183183
}
184184
response = this;
185185
}
@@ -490,20 +490,14 @@ private void encodeTargetAction(ApiObject object, MessageWriter writer) {
490490
e = cacheMap.remove("$params");
491491
if (e == null) {
492492
DSList list = new DSList();
493-
Iterator<DSMap> params = action.getParameters();
494-
if (params != null) {
495-
DSMap param;
496-
while (params.hasNext()) {
497-
param = params.next();
498-
if (dsAction != null) {
499-
dsAction.prepareParameter(info, param);
500-
}
501-
if (param.hasParent()) {
502-
param = param.copy();
503-
}
504-
fixRangeTypes(param);
505-
list.add(param);
493+
for (int i = 0, len = action.getParameterCount(); i < len; i++) {
494+
DSMap param = new DSMap();
495+
action.getParameterMetadata(i, param);
496+
if (dsAction != null) {
497+
dsAction.prepareParameter(info, param);
506498
}
499+
fixRangeTypes(param);
500+
list.add(param);
507501
}
508502
encode("$params", list, writer);
509503
} else {
@@ -513,22 +507,13 @@ private void encodeTargetAction(ApiObject object, MessageWriter writer) {
513507
e = cacheMap.remove("$columns");
514508
if (e != null) {
515509
encode("$columns", e, writer);
516-
} else {
510+
} else if (action.getColumnCount() > 0) {
517511
DSList list = new DSList();
518-
Iterator<DSMap> cols = action.getValueMetadata();
519-
if (cols != null) {
520-
DSMap param;
521-
while (cols.hasNext()) {
522-
param = cols.next();
523-
if (dsAction != null) {
524-
dsAction.prepareParameter(info, param);
525-
}
526-
if (param.hasParent()) {
527-
param = param.copy();
528-
}
529-
fixRangeTypes(param);
530-
list.add(param);
531-
}
512+
for (int i = 0, len = action.getColumnCount(); i < len; i++) {
513+
DSMap col = new DSMap();
514+
action.getColumnMetadata(i, col);
515+
fixRangeTypes(col);
516+
list.add(col);
532517
}
533518
encode("$columns", list, writer);
534519
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import org.iot.dsa.node.DSStatus;
1616
import org.iot.dsa.node.event.DSIEvent;
1717
import org.iot.dsa.node.event.DSISubscriber;
18-
import org.iot.dsa.node.event.DSInfoTopic;
1918
import org.iot.dsa.node.event.DSTopic;
20-
import org.iot.dsa.node.event.DSValueTopic;
2119
import org.iot.dsa.time.DSTime;
2220

2321
/**
@@ -220,13 +218,13 @@ protected void init() {
220218
DSIObject obj = path.getTarget();
221219
if (obj instanceof DSNode) {
222220
node = (DSNode) obj;
223-
node.subscribe(DSNode.VALUE_TOPIC, null, this);
221+
node.subscribe(DSNode.VALUE_TOPIC, null, null, this);
224222
onEvent(node, null, DSNode.VALUE_TOPIC);
225223
} else {
226224
DSInfo info = path.getInfo();
227225
node = path.getParent();
228226
child = info;
229-
node.subscribe(DSNode.VALUE_TOPIC, info, this);
227+
node.subscribe(DSNode.VALUE_TOPIC, info, null, this);
230228
onEvent(node, info, DSNode.VALUE_TOPIC);
231229
}
232230
}

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/v1/DS1ConnectionInit.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import java.net.URL;
88
import java.security.MessageDigest;
99
import org.iot.dsa.dslink.DSLink;
10-
import org.iot.dsa.dslink.DSLinkConfig;
11-
import org.iot.dsa.io.DSBase64;
10+
import org.iot.dsa.dslink.DSLinkOptions;
11+
import com.acuity.iot.dsa.dslink.io.DSBase64;
1212
import org.iot.dsa.io.json.JsonReader;
1313
import org.iot.dsa.io.json.JsonWriter;
1414
import org.iot.dsa.node.DSList;
@@ -29,8 +29,6 @@ public class DS1ConnectionInit extends DSNode {
2929
///////////////////////////////////////////////////////////////////////////
3030

3131
private static final String DSA_VERSION = "1.1.2";
32-
//private static final String[] SUPPORTED_FORMATS = new String[]{"msgpack", "json"};
33-
private static final String[] SUPPORTED_FORMATS = new String[]{"json"};
3432

3533
private String BROKER_REQ = "Broker Request";
3634
private String BROKER_RES = "Broker Response";
@@ -53,8 +51,8 @@ public class DS1ConnectionInit extends DSNode {
5351
protected void onStarted() {
5452
this.connection = (DS1LinkConnection) getParent();
5553
this.link = connection.getLink();
56-
this.authToken = link.getConfig().getToken();
57-
this.brokerUri = link.getConfig().getBrokerUri();
54+
this.authToken = link.getOptions().getToken();
55+
this.brokerUri = link.getOptions().getBrokerUri();
5856
}
5957

6058
///////////////////////////////////////////////////////////////////////////
@@ -135,8 +133,8 @@ void initializeConnection() throws Exception {
135133
/**
136134
* Adds dsId and maybe authToken parameters to the query string.
137135
*
138-
* @see DSLinkConfig#getBrokerUri()
139-
* @see DSLinkConfig#getToken()
136+
* @see DSLinkOptions#getBrokerUri()
137+
* @see DSLinkOptions#getToken()
140138
*/
141139
String makeBrokerUrl() {
142140
StringBuilder builder = new StringBuilder();
@@ -264,9 +262,10 @@ void writeConnectionRequest(HttpURLConnection conn) throws Exception {
264262
map.put("linkData", new DSMap());
265263
map.put("version", DSA_VERSION);
266264
DSList list = map.putList("formats");
267-
for (String format : SUPPORTED_FORMATS) {
268-
list.add(format);
265+
if (link.getOptions().getMsgpack()) {
266+
list.add("msgpack");
269267
}
268+
list.add("json");
270269
map.put("enableWebSocketCompression", false);
271270
put(BROKER_REQ, map).setReadOnly(true);
272271
trace(trace() ? map.toString() : null);

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/v1/DS1LinkConnection.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.acuity.iot.dsa.dslink.transport.DSTextTransport;
77
import com.acuity.iot.dsa.dslink.transport.DSTransport;
88
import org.iot.dsa.dslink.DSIRequester;
9-
import org.iot.dsa.dslink.DSLinkConfig;
9+
import org.iot.dsa.dslink.DSLinkOptions;
1010
import org.iot.dsa.dslink.DSLinkConnection;
1111
import org.iot.dsa.io.DSIReader;
1212
import org.iot.dsa.io.DSIWriter;
@@ -99,7 +99,7 @@ protected void checkConfig() {
9999
protected DS1ConnectionInit initializeConnection() {
100100
DS1ConnectionInit init = new DS1ConnectionInit();
101101
put(CONNECTION_INIT, init).setTransient(true);
102-
put(BROKER_URI, getLink().getConfig().getBrokerUri());
102+
put(BROKER_URI, getLink().getOptions().getBrokerUri());
103103
try {
104104
init.initializeConnection();
105105
setPathInBroker(init.getResponse().getString("path"));
@@ -121,8 +121,8 @@ protected DSTransport makeTransport(DS1ConnectionInit init) {
121121
}
122122
DSTransport transport = null;
123123
try {
124-
String type = getLink().getConfig().getConfig(
125-
DSLinkConfig.CFG_WS_TRANSPORT_FACTORY,
124+
String type = getLink().getOptions().getConfig(
125+
DSLinkOptions.CFG_WS_TRANSPORT_FACTORY,
126126
"org.iot.dsa.dslink.websocket.StandaloneTransportFactory");
127127
factory = (DSTransport.Factory) Class.forName(type).newInstance();
128128
String format = init.getResponse().getString("format");
@@ -140,8 +140,8 @@ protected DSTransport makeTransport(DS1ConnectionInit init) {
140140
debug(debug() ? "Connection URL = " + uri : null);
141141
transport.setConnectionUrl(uri);
142142
transport.setConnection(this);
143-
transport.setReadTimeout(getLink().getConfig().getConfig(
144-
DSLinkConfig.CFG_READ_TIMEOUT, 60000));
143+
transport.setReadTimeout(getLink().getOptions().getConfig(
144+
DSLinkOptions.CFG_READ_TIMEOUT, 60000));
145145
setTransport(transport);
146146
debug(debug() ? "Transport type: " + transport.getClass().getName() : null);
147147
return transport;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.security.SecureRandom;
1515
import org.iot.dsa.dslink.DSIRequester;
1616
import org.iot.dsa.dslink.DSLink;
17-
import org.iot.dsa.dslink.DSLinkConfig;
17+
import org.iot.dsa.dslink.DSLinkOptions;
1818
import org.iot.dsa.dslink.DSLinkConnection;
1919
import org.iot.dsa.dslink.DSPermissionException;
2020
import org.iot.dsa.node.DSBytes;
@@ -114,12 +114,12 @@ protected void checkConfig() {
114114
*/
115115
protected DSBinaryTransport makeTransport() {
116116
DSTransport.Factory factory = null;
117-
String uri = getLink().getConfig().getBrokerUri();
117+
String uri = getLink().getOptions().getBrokerUri();
118118
transport = null;
119119
if (uri.startsWith("ws")) {
120120
try {
121-
String type = getLink().getConfig().getConfig(
122-
DSLinkConfig.CFG_WS_TRANSPORT_FACTORY,
121+
String type = getLink().getOptions().getConfig(
122+
DSLinkOptions.CFG_WS_TRANSPORT_FACTORY,
123123
"org.iot.dsa.dslink.websocket.StandaloneTransportFactory");
124124
factory = (DSTransport.Factory) Class.forName(type).newInstance();
125125
transport = factory.makeBinaryTransport(this);
@@ -261,7 +261,7 @@ private void sendF2() {
261261
DS2MessageWriter writer = new DS2MessageWriter();
262262
writer.setMethod(0xf2);
263263
DSByteBuffer buffer = writer.getBody();
264-
String token = getLink().getConfig().getToken();
264+
String token = getLink().getOptions().getToken();
265265
if (token == null) {
266266
token = "";
267267
}

0 commit comments

Comments
 (0)