Skip to content

Commit 63e3a02

Browse files
author
Aaron
committed
Remove parent node of link, fix pathing
Add DSLinkConnection.getPathInBroker methods Fix DSNode.copy
1 parent 61dbe9a commit 63e3a02

File tree

14 files changed

+220
-131
lines changed

14 files changed

+220
-131
lines changed

dslink-core/src/main/java/com/acuity/iot/dsa/dslink/protocol/message/RequestPath.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public DSInfo getInfo() {
5252
if (target == null) {
5353
getTarget();
5454
}
55+
if ((info == null) && (root == target)) {
56+
info = new RootInfo(root);
57+
}
5558
return info;
5659
}
5760

@@ -73,10 +76,10 @@ public String getPath() {
7376
return path;
7477
}
7578

76-
public DSIObject getTarget() {
77-
if (parent == null) {
78-
parent = root.getParent();
79+
public synchronized DSIObject getTarget() {
80+
if (target == null) {
7981
target = root;
82+
parent = root.getParent();
8083
info = root.getInfo();
8184
int len = names.length;
8285
if (len == 0) {
@@ -116,4 +119,10 @@ public boolean isResponder() {
116119
return target instanceof DSIResponder;
117120
}
118121

122+
private static class RootInfo extends DSInfo {
123+
RootInfo(DSNode root) {
124+
super(null, root);
125+
}
126+
}
127+
119128
}

dslink-core/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
@@ -233,7 +233,7 @@ public void run() {
233233
setPath(path.getPath());
234234
result = responder.onInvoke(this);
235235
}
236-
DSInfo info = path.getInfo();
236+
DSInfo info = path.getInfo(); //action must be child of a node
237237
if (!info.isAction()) {
238238
throw new DSRequestException("Not an action " + path.getPath());
239239
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,9 @@ public void run() {
599599
response = responder.onList(this);
600600
} else {
601601
info = path.getInfo();
602+
if (info == null) {
603+
info = new RootInfo((DSNode)path.getTarget());
604+
}
602605
if (info.isNode()) {
603606
node = info.getNode();
604607
node.subscribe(DSNode.INFO_TOPIC, null, this);
@@ -726,6 +729,12 @@ private void writeUpdates(MessageWriter writer) {
726729
// Inner Classes
727730
///////////////////////////////////////////////////////////////////////////
728731

732+
private static class RootInfo extends DSInfo {
733+
RootInfo(DSNode node) {
734+
super(null,node);
735+
}
736+
}
737+
729738
protected static class Update {
730739

731740
public boolean added;

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import org.iot.dsa.dslink.DSPermissionException;
66
import org.iot.dsa.dslink.DSRequestException;
77
import org.iot.dsa.dslink.responder.InboundSetRequest;
8-
import org.iot.dsa.node.DSElement;
9-
import org.iot.dsa.node.DSIValue;
10-
import org.iot.dsa.node.DSInfo;
11-
import org.iot.dsa.node.DSNode;
8+
import org.iot.dsa.node.*;
129
import org.iot.dsa.security.DSPermission;
1310

1411
public class DSInboundSet extends DSInboundRequest implements InboundSetRequest, Runnable {
@@ -42,19 +39,21 @@ public void run() {
4239
} else {
4340
DSNode parent = path.getParent();
4441
DSInfo info = path.getInfo();
45-
if (info.isReadOnly()) {
42+
if ((info != null) && info.isReadOnly()) {
4643
throw new DSRequestException("Not writable: " + getPath());
4744
}
4845
if (!permission.isConfig()) {
49-
if (info.isAdmin()) {
46+
if ((info != null) && info.isAdmin()) {
5047
throw new DSPermissionException("Config permission required");
5148
} else if (DSPermission.WRITE.isGreaterThan(permission)) {
5249
throw new DSPermissionException("Write permission required");
5350
}
5451
}
55-
if (info.isNode()) {
56-
info.getNode().onSet(value);
52+
DSIObject obj = path.getTarget();
53+
if (obj instanceof DSNode) {
54+
((DSNode)obj).onSet(value);
5755
} else {
56+
//since not a node, there must be a parent
5857
DSIValue current = info.getValue();
5958
if (current == null) {
6059
if (info.getDefaultObject() instanceof DSIValue) {

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
import org.iot.dsa.dslink.responder.InboundSubscribeRequest;
77
import org.iot.dsa.dslink.responder.SubscriptionCloseHandler;
88
import org.iot.dsa.io.DSIWriter;
9-
import org.iot.dsa.node.DSIStatus;
10-
import org.iot.dsa.node.DSIValue;
11-
import org.iot.dsa.node.DSInfo;
12-
import org.iot.dsa.node.DSNode;
13-
import org.iot.dsa.node.DSStatus;
9+
import org.iot.dsa.node.*;
1410
import org.iot.dsa.node.event.DSIEvent;
1511
import org.iot.dsa.node.event.DSISubscriber;
1612
import org.iot.dsa.node.event.DSTopic;
@@ -97,13 +93,14 @@ protected void init() {
9793
setPath(path.getPath());
9894
closeHandler = responder.onSubscribe(this);
9995
} else {
100-
DSInfo info = path.getInfo();
101-
if (info.isNode()) {
102-
node = info.getNode();
96+
DSIObject obj = path.getTarget();
97+
if (obj instanceof DSNode) {
98+
node = (DSNode) obj;
10399
node.subscribe(DSNode.VALUE_TOPIC, null, this);
104-
onEvent(DSNode.VALUE_TOPIC, Event.NODE_CHANGED, info.getNode(), null,
100+
onEvent(DSNode.VALUE_TOPIC, Event.NODE_CHANGED, node, null,
105101
(Object[]) null);
106102
} else {
103+
DSInfo info = path.getInfo();
107104
node = path.getParent();
108105
child = info;
109106
node.subscribe(DSNode.VALUE_TOPIC, info, this);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class DS1LinkConnection extends DSLinkConnection {
3737

3838
private DS1ConnectionInit connectionInit;
3939
private DSLink link;
40+
private String pathInBroker;
4041
private DSIReader reader;
4142
private DSTransport transport;
4243
private DS1Session session;
@@ -56,6 +57,11 @@ public void disconnect() {
5657
}
5758
}
5859

60+
@Override
61+
public String getPathInBroker() {
62+
return pathInBroker;
63+
}
64+
5965
public DSIReader getReader() {
6066
return reader;
6167
}
@@ -84,6 +90,7 @@ protected DS1ConnectionInit initializeConnection() {
8490
put(CONNECTION_INIT, init).setTransient(true);
8591
try {
8692
init.initializeConnection();
93+
pathInBroker = init.getResponse().getString("path");
8794
} catch (Exception x) {
8895
DSException.throwRuntime(x);
8996
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public void disconnect() {
9999
}
100100
}
101101

102+
@Override
103+
public String getPathInBroker() {
104+
return brokerPath.getValue().toString();
105+
}
106+
102107
private byte[] getLinkSalt() {
103108
if (linkSalt.getObject().isNull()) {
104109
byte[] tmp = new byte[32];

dslink-core/src/main/java/org/iot/dsa/dslink/DSLink.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ public static DSLink load(DSLinkConfig config) {
184184
}
185185
ret.save();
186186
}
187-
DSNode tmp = new DSNode();
188-
tmp.add(ret.getLinkName(), ret);
189187
return ret;
190188
}
191189

dslink-core/src/main/java/org/iot/dsa/dslink/DSLinkConnection.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.acuity.iot.dsa.dslink.transport.DSTransport;
55
import java.util.concurrent.ConcurrentHashMap;
66
import org.iot.dsa.node.DSNode;
7+
import org.iot.dsa.node.DSPath;
78
import org.iot.dsa.time.DSTime;
89

910
/**
@@ -92,14 +93,29 @@ protected String getLogName() {
9293
return getClass().getSimpleName();
9394
}
9495

95-
public DSSysNode getSys() {
96-
return (DSSysNode) getParent();
96+
/**
97+
* The path representing the link node in the broker.
98+
*/
99+
public abstract String getPathInBroker();
100+
101+
/**
102+
* Concatenates the path in broker with the path of the node.
103+
*/
104+
public String getPathInBroker(DSNode node) {
105+
StringBuilder buf = new StringBuilder();
106+
String localPath = DSPath.encodePath(node, buf).toString();
107+
buf.setLength(0);
108+
return DSPath.concat(getPathInBroker(), localPath, buf).toString();
97109
}
98110

99111
public abstract DSIRequester getRequester();
100112

101113
public abstract DSSession getSession();
102114

115+
public DSSysNode getSys() {
116+
return (DSSysNode) getParent();
117+
}
118+
103119
public abstract DSTransport getTransport();
104120

105121
/**
@@ -151,6 +167,7 @@ public void removeListener(Listener listener) {
151167
}
152168
}
153169

170+
154171
// Inner Classes
155172
// -------------
156173

dslink-core/src/main/java/org/iot/dsa/dslink/DSSysNode.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.acuity.iot.dsa.dslink.protocol.v2.DS2LinkConnection;
66
import org.iot.dsa.node.DSInfo;
77
import org.iot.dsa.node.DSNode;
8+
import org.iot.dsa.node.DSNull;
9+
import org.iot.dsa.node.DSString;
810
import org.iot.dsa.node.action.ActionInvocation;
911
import org.iot.dsa.node.action.ActionResult;
1012
import org.iot.dsa.node.action.DSAction;
@@ -17,18 +19,18 @@
1719
*/
1820
public class DSSysNode extends DSNode {
1921

20-
static final String CONNECTION = "connection";
21-
static final String SAVE = "save";
22-
static final String STOP = "stop";
23-
static final String PROFILER = "profiler";
22+
static final String CONNECTION = "Connection";
23+
static final String SAVE = "Save";
24+
static final String STOP = "Stop";
25+
static final String PROFILER = "Profiler";
2426

2527
private DSInfo connection = getInfo(CONNECTION);
2628
private DSInfo save = getInfo(SAVE);
2729
private DSInfo stop = getInfo(STOP);
2830

2931
@Override
3032
protected void declareDefaults() {
31-
declareDefault(CONNECTION, new DSNode()).setTransient(true);
33+
declareDefault(CONNECTION, DSNull.NULL).setTransient(true);
3234
declareDefault(SAVE, DSAction.DEFAULT);
3335
declareDefault(STOP, DSAction.DEFAULT);
3436
declareDefault(PROFILER, new ProfilerNode()).setTransient(true);
@@ -62,6 +64,8 @@ void init() {
6264
}
6365
fine(fine() ? "Connection type: " + conn.getClass().getName() : null);
6466
put(connection, conn);
67+
DSInfo info = getInfo(CONNECTION);
68+
System.out.println(info == connection);
6569
} catch (Exception x) {
6670
DSException.throwRuntime(x);
6771
}

0 commit comments

Comments
 (0)