Skip to content

Commit 0f473ce

Browse files
authored
0.52.0
- Remove isEqual from DSIObject. - Refactor DSLink for in process links. - Move upstream connection from the sys node to upstream on the link. - Add home directory to DSLinkOptions. - Add DSNode.getRootNode. - DSConnection was broken by changes to DSStatusNode. - Moved getPathInBroker to DSLink.
2 parents fd1c27c + 99d3b4c commit 0f473ce

File tree

76 files changed

+468
-545
lines changed

Some content is hidden

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

76 files changed

+468
-545
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
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.51.0'
8+
version '0.52.0'
99

1010
sourceCompatibility = 1.8
1111
targetCompatibility = 1.8
@@ -45,5 +45,5 @@ allprojects {
4545
}
4646

4747
wrapper {
48-
gradleVersion = '5.0'
48+
gradleVersion = '5.2'
4949
}

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/DSUpstreamConnection.java renamed to dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/DSBrokerConnection.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
package com.acuity.iot.dsa.dslink.protocol;
22

3-
import com.acuity.iot.dsa.dslink.transport.DSTransport;
4-
import org.iot.dsa.conn.DSConnection;
5-
import org.iot.dsa.dslink.DSIRequester;
6-
import org.iot.dsa.dslink.DSLink;
7-
import org.iot.dsa.dslink.DSLinkConnection;
8-
import org.iot.dsa.dslink.DSSysNode;
93
import org.iot.dsa.node.DSInfo;
10-
import org.iot.dsa.node.DSNode;
11-
import org.iot.dsa.node.DSPath;
124
import org.iot.dsa.node.DSString;
135
import org.iot.dsa.node.action.ActionInvocation;
146
import org.iot.dsa.node.action.ActionResult;
@@ -19,7 +11,7 @@
1911
*
2012
* @author Aaron Hansen
2113
*/
22-
public abstract class DSUpstreamConnection extends DSLinkConnection {
14+
public abstract class DSBrokerConnection extends DSTransportConnection {
2315

2416
///////////////////////////////////////////////////////////////////////////
2517
// Class Fields
@@ -46,16 +38,6 @@ public String getPathInBroker() {
4638
return brokerPath.getElement().toString();
4739
}
4840

49-
/**
50-
* Concatenates the path in broker with the path of the node.
51-
*/
52-
public String getPathInBroker(DSNode node) {
53-
StringBuilder buf = new StringBuilder();
54-
String localPath = DSPath.encodePath(node, buf).toString();
55-
buf.setLength(0);
56-
return DSPath.concat(getPathInBroker(), localPath, buf).toString();
57-
}
58-
5941
///////////////////////////////////////////////////////////////////////////
6042
// Protected Methods
6143
///////////////////////////////////////////////////////////////////////////
@@ -68,16 +50,12 @@ protected void declareDefaults() {
6850
declareDefault(RECONNECT, new DSAction.Parameterless() {
6951
@Override
7052
public ActionResult invoke(DSInfo target, ActionInvocation invocation) {
71-
((DSUpstreamConnection) target.get()).disconnect();
53+
((DSBrokerConnection) target.get()).disconnect();
7254
return null;
7355
}
7456
});
7557
}
7658

77-
protected DSSysNode getSys() {
78-
return (DSSysNode) getParent();
79-
}
80-
8159
/**
8260
* Creates and starts a thread for running the connection lifecycle.
8361
*/

dslink-v2/src/main/java/org/iot/dsa/security/DSKeys.java renamed to dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/protocol/DSKeys.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.iot.dsa.security;
1+
package com.acuity.iot.dsa.dslink.protocol;
22

33
import com.acuity.iot.dsa.dslink.io.DSBase64;
44
import java.io.ByteArrayOutputStream;
@@ -415,7 +415,7 @@ private static byte[] toUnsignedByteArray(BigInteger arg) {
415415
///////////////////////////////////////////////////////////////////////////
416416

417417
/**
418-
* Signs bytes. Call the update one or more times. Call getSignature when finished. This
418+
* Signs bytes. Call update one or more times. Call getSignature when finished. This
419419
* object is not thread safe, but can be reused by calling reset to being a new signature.
420420
*/
421421
public class Signer {
@@ -563,8 +563,4 @@ public boolean validate(String base64signature) {
563563
}
564564
}
565565

566-
///////////////////////////////////////////////////////////////////////////
567-
// Initialization
568-
///////////////////////////////////////////////////////////////////////////
569-
570-
} //class
566+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package com.acuity.iot.dsa.dslink.protocol;
2+
3+
import com.acuity.iot.dsa.dslink.protocol.v1.DS1LinkConnection;
4+
import com.acuity.iot.dsa.dslink.protocol.v2.DS2LinkConnection;
5+
import org.iot.dsa.dslink.DSLink;
6+
import org.iot.dsa.dslink.DSLinkConnection;
7+
import org.iot.dsa.dslink.DSLinkOptions;
8+
import org.iot.dsa.dslink.DSMainNode;
9+
import org.iot.dsa.dslink.DSSysNode;
10+
import org.iot.dsa.node.DSInfo;
11+
import org.iot.dsa.node.DSNode;
12+
import org.iot.dsa.util.DSUtil;
13+
14+
/**
15+
* Link implementation for standalone v1 and v2 links.
16+
*
17+
* @author Aaron Hansen
18+
*/
19+
public class DSRootLink extends DSLink {
20+
21+
///////////////////////////////////////////////////////////////////////////
22+
// Class Fields
23+
///////////////////////////////////////////////////////////////////////////
24+
25+
///////////////////////////////////////////////////////////////////////////
26+
// Instance Fields
27+
///////////////////////////////////////////////////////////////////////////
28+
29+
private String dsId;
30+
private DSKeys keys;
31+
private DSInfo main;
32+
private DSInfo sys = getInfo(SYS);
33+
private DSInfo upstream;
34+
35+
///////////////////////////////////////////////////////////////////////////
36+
// Constructors
37+
///////////////////////////////////////////////////////////////////////////
38+
39+
///////////////////////////////////////////////////////////////////////////
40+
// Public Methods
41+
///////////////////////////////////////////////////////////////////////////
42+
43+
/**
44+
* Returns the unique id of the connection. This is the link name + '-' + the hash of the
45+
* public key in base64.
46+
*
47+
* @return Never null, and url safe.
48+
*/
49+
public String getDsId() {
50+
if (dsId == null) {
51+
StringBuilder buf = new StringBuilder();
52+
buf.append(getLinkName());
53+
buf.append('-');
54+
buf.append(getKeys().encodePublicHashDsId());
55+
dsId = buf.toString();
56+
}
57+
return dsId;
58+
}
59+
60+
/**
61+
* Public / private keys of the link, used to prove identity with brokers.
62+
*/
63+
public DSKeys getKeys() {
64+
return keys;
65+
}
66+
67+
@Override
68+
public DSMainNode getMain() {
69+
return (DSMainNode) main.getNode();
70+
}
71+
72+
public DSSysNode getSys() {
73+
return (DSSysNode) sys.get();
74+
}
75+
76+
@Override
77+
public DSLinkConnection getUpstream() {
78+
return (DSLinkConnection) upstream.get();
79+
}
80+
81+
///////////////////////////////////////////////////////////////////////////
82+
// Protected Methods
83+
///////////////////////////////////////////////////////////////////////////
84+
85+
@Override
86+
protected void declareDefaults() {
87+
super.declareDefaults();
88+
declareDefault(SYS, new DSSysNode(), "Services common to all links.").setAdmin(true);
89+
}
90+
91+
@Override
92+
protected DSLink init(DSLinkOptions config) {
93+
super.init(config);
94+
keys = config.getKeys();
95+
main = getInfo(MAIN);
96+
if (main == null) {
97+
String type = getOptions().getMainType();
98+
if (type != null) {
99+
debug("Main node type: " + type);
100+
DSNode node = (DSNode) DSUtil.newInstance(type);
101+
main = put(MAIN, node);
102+
}
103+
}
104+
String ver = config.getDsaVersion();
105+
DSLinkConnection conn;
106+
String type = config.getConfig(DSLinkOptions.CFG_CONNECTION_TYPE, null);
107+
if (type != null) {
108+
conn = (DSLinkConnection) DSUtil.newInstance(type);
109+
} else if (ver.startsWith("1")) {
110+
conn = new DS1LinkConnection();
111+
} else { //2
112+
conn = new DS2LinkConnection();
113+
}
114+
debug(debug() ? "Connection type: " + conn.getClass().getName() : null);
115+
upstream = put(UPSTREAM, conn);
116+
upstream.setTransient(true);
117+
return this;
118+
}
119+
120+
///////////////////////////////////////////////////////////////////////////
121+
// Package / Private Methods
122+
///////////////////////////////////////////////////////////////////////////
123+
124+
///////////////////////////////////////////////////////////////////////////
125+
// Inner Classes
126+
///////////////////////////////////////////////////////////////////////////
127+
128+
///////////////////////////////////////////////////////////////////////////
129+
// Initialization
130+
///////////////////////////////////////////////////////////////////////////
131+
132+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public abstract class DSSession extends DSNode implements DSIConnected {
4343
private int ackRequired = 0;
4444
private int ackToSend = -1;
4545
private boolean connected = false;
46-
private DSLinkConnection connection;
46+
private DSTransportConnection connection;
4747
private long lastTimeRecv;
4848
private long lastTimeSend;
4949
private int messageId = 0;
@@ -62,7 +62,7 @@ public DSSession() {
6262
}
6363

6464
public DSSession(DSLinkConnection connection) {
65-
this.connection = connection;
65+
this.connection = (DSTransportConnection) connection;
6666
}
6767

6868
///////////////////////////////////////////////////////////////////////////
@@ -124,7 +124,7 @@ public int getMessageId() {
124124
public abstract DSResponder getResponder();
125125

126126
public DSTransport getTransport() {
127-
return getConnection().getTransport();
127+
return connection.getTransport();
128128
}
129129

130130
public boolean isRequesterAllowed() {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.acuity.iot.dsa.dslink.protocol;
2+
3+
import com.acuity.iot.dsa.dslink.transport.DSTransport;
4+
import org.iot.dsa.dslink.DSLinkConnection;
5+
6+
/**
7+
* The sole purpose of this class is to keep the transport out of the public api.
8+
*
9+
* @author Aaron Hansen
10+
*/
11+
public abstract class DSTransportConnection extends DSLinkConnection {
12+
13+
public abstract DSTransport getTransport();
14+
15+
@Override
16+
protected void doDisconnect() {
17+
try {
18+
DSTransport t = getTransport();
19+
if ((t != null) && t.isOpen()) {
20+
t.close();
21+
}
22+
} catch (Exception x) {
23+
error(getPath(), x);
24+
}
25+
}
26+
27+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void replace(int index, int len, DSList... rows) {
151151
*/
152152
public void run() {
153153
try {
154-
DSTarget path = new DSTarget(getPath(), getLink());
154+
DSTarget path = new DSTarget(getPath(), getLink().getRootNode());
155155
if (path.isResponder()) {
156156
DSIResponder responder = (DSIResponder) path.getTarget();
157157
setPath(path.getPath());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void onEvent(DSEvent event, DSNode node, DSInfo child, DSIValue data) {
171171
@Override
172172
public void run() {
173173
try {
174-
target = new DSTarget(getPath(), getLink());
174+
target = new DSTarget(getPath(), getLink().getRootNode());
175175
if (target.isResponder()) {
176176
DSIResponder responder = (DSIResponder) target.getTarget();
177177
setPath(target.getPath());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public DSElement getValue() {
3535
@Override
3636
public void run() {
3737
try {
38-
DSTarget path = new DSTarget(getPath(), getLink());
38+
DSTarget path = new DSTarget(getPath(), getLink().getRootNode());
3939
if (path.isResponder()) {
4040
DSIResponder responder = (DSIResponder) path.getTarget();
4141
setPath(path.getPath());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ protected synchronized Update dequeue() {
211211
}
212212

213213
protected void init() {
214-
DSTarget path = new DSTarget(getPath(), getLink());
214+
DSTarget path = new DSTarget(getPath(), getLink().getRootNode());
215215
if (path.isResponder()) {
216216
DSIResponder responder = (DSIResponder) path.getTarget();
217217
setPath(path.getPath());

0 commit comments

Comments
 (0)