Skip to content

Commit 0995e87

Browse files
authored
Merge pull request #175 from iot-dsa-v2/develop
0.73.1
2 parents f4ea6d7 + b98f612 commit 0995e87

File tree

4 files changed

+65
-62
lines changed

4 files changed

+65
-62
lines changed

build.gradle

+1-1
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.73.0'
8+
version '0.73.1'
99

1010
targetCompatibility = JavaVersion.VERSION_1_8
1111
sourceCompatibility = JavaVersion.VERSION_1_8

dslink-v2-api/src/main/java/org/iot/dsa/node/DSNode.java

+44-48
Original file line numberDiff line numberDiff line change
@@ -294,30 +294,7 @@ public DSInfo<?> add(String name, DSIObject object) {
294294
}
295295
info = new DSInfo<>(name.intern(), object);
296296
add(info);
297-
if (isRunning()) {
298-
if (argIsNode) {
299-
argAsNode.start();
300-
}
301-
}
302-
if (isStable()) {
303-
if (argIsNode) {
304-
argAsNode.stable();
305-
}
306-
//Update any existing lists and subscriptions
307-
String updatePath = info.getPath(null).toString();
308-
DSRuntime.run(() -> {
309-
DSLink link = getAncestor(DSLink.class);
310-
if (link != null) {
311-
DSLinkConnection conn = link.getConnection();
312-
if (conn != null) {
313-
DSISession session = conn.getSession();
314-
if (session != null) {
315-
session.update(updatePath);
316-
}
317-
}
318-
}
319-
});
320-
}
297+
added(info);
321298
return info;
322299
}
323300

@@ -951,18 +928,15 @@ public DSNode put(DSInfo<?> info, DSIObject object) {
951928
}
952929
if (isRunning()) {
953930
if (argIsNode) {
954-
argAsNode.start();
955-
} else {
956-
try {
957-
onChildChanged(info);
958-
} catch (Exception x) {
959-
error(getPath(), x);
960-
}
961-
if (info.isValue()) {
962-
fire(VALUE_CHANGED_EVENT, info, info.getElement());
963-
} else {
964-
fire(VALUE_CHANGED_EVENT, info, null);
965-
}
931+
added(info);
932+
}
933+
try {
934+
onChildChanged(info);
935+
} catch (Exception x) {
936+
error(getPath(), x);
937+
}
938+
if (info.isValue()) {
939+
fire(VALUE_CHANGED_EVENT, info, info.getElement());
966940
}
967941
}
968942
return this;
@@ -1003,20 +977,18 @@ public DSNode remove(DSInfo<?> info) {
1003977
}
1004978
size--;
1005979
}
1006-
if (info.isNode()) {
1007-
DSNode node = info.getNode();
1008-
if (isRunning()) {
1009-
notifyRemoved(node);
1010-
}
1011-
node.stop();
1012-
node.infoInParent = null;
1013-
}
1014980
if (isRunning()) {
1015981
try {
1016982
onChildRemoved(info);
1017983
} catch (Exception x) {
1018984
error(getPath(), x);
1019985
}
986+
if (info.isNode()) {
987+
DSNode node = info.getNode();
988+
notifyRemoved(node);
989+
node.stop();
990+
node.infoInParent = null;
991+
}
1020992
fire(CHILD_REMOVED_EVENT, info, null);
1021993
}
1022994
return this;
@@ -1030,10 +1002,9 @@ public DSNode remove(DSInfo<?> info) {
10301002
*/
10311003
public DSInfo<?> remove(String name) {
10321004
DSInfo<?> info = getInfo(name);
1033-
if (info == null) {
1034-
return info;
1005+
if (info != null) {
1006+
remove(info);
10351007
}
1036-
remove(info);
10371008
return info;
10381009
}
10391010

@@ -1546,13 +1517,38 @@ void dsInit() {
15461517
// Private Methods
15471518
///////////////////////////////////////////////////////////////////////////
15481519

1520+
private void added(DSInfo<?> info) {
1521+
boolean isNode = info.isNode();
1522+
if (isRunning() && isNode) {
1523+
info.getNode().start();
1524+
}
1525+
if (isStable()) {
1526+
if (isNode) {
1527+
info.getNode().stable();
1528+
}
1529+
//Update any existing lists and subscriptions
1530+
String updatePath = info.getPath(null).toString();
1531+
DSRuntime.run(() -> {
1532+
DSLink link = getAncestor(DSLink.class);
1533+
if (link != null) {
1534+
DSLinkConnection conn = link.getConnection();
1535+
if (conn != null) {
1536+
DSISession session = conn.getSession();
1537+
if (session != null) {
1538+
session.update(updatePath);
1539+
}
1540+
}
1541+
}
1542+
});
1543+
}
1544+
}
1545+
15491546
private void notifyRemoved(DSNode node) {
15501547
DSInfo<?> info = node.getFirstInfo();
15511548
while (info != null) {
15521549
if (info.isNode()) {
15531550
notifyRemoved(info.getNode());
15541551
}
1555-
fire(CHILD_REMOVED_EVENT, info, null);
15561552
info = info.next();
15571553
}
15581554
try {

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

+20-6
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,28 @@ public void onEvent(DSEvent event, DSNode node, DSInfo<?> child, DSIValue data)
145145
}
146146
switch (event.getEventId()) {
147147
case DSNode.CHILD_RENAMED:
148-
if (target.getTargetInfo().isNode()) {
148+
if (target.getTarget() == node) {
149149
sendRemove(data.toString());
150150
}
151-
break;
151+
//fall through to add the child
152152
case DSNode.CHILD_ADDED:
153-
if (target.getTargetInfo().isNode()) {
153+
if (target.getTarget() == node) {
154154
encodeChild(child);
155155
}
156156
break;
157157
case DSNode.CHILD_REMOVED:
158-
if (target.getTargetInfo().isNode()) {
159-
sendRemove(child.getName());
160-
} else if (target.getTargetInfo() == child) {
158+
if (target.getTargetInfo() == child) {
161159
send("$disconnectedTs", DSDateTime.now().toElement());
160+
subscription.close();
161+
subscription = null;
162+
} else if (target.getTarget() == node) {
163+
sendRemove(child.getName());
162164
}
163165
break;
164166
case DSNode.STOPPED:
165167
send("$disconnectedTs", DSDateTime.now().toElement());
168+
subscription.close();
169+
subscription = null;
166170
}
167171
}
168172

@@ -839,6 +843,16 @@ private void writeUpdates(MessageWriter writer) {
839843
break;
840844
}
841845
writer.getWriter().value(update);
846+
if (update.isList()) { //DGLux bug workaround
847+
DSList list = update.toList();
848+
if (list.size() > 1) {
849+
if (list.get(0).isString()) {
850+
if ("$disconnectedTs".equals(list.getString(0))) {
851+
break;
852+
}
853+
}
854+
}
855+
}
842856
if (responder.shouldEndMessage()) {
843857
break;
844858
}

dslink-v2/src/test/java/org/iot/dsa/dslink/AddRemoveRequesterTest.java

-7
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,6 @@ private void subDeepValue(DSLink link) {
153153
update = h.nextUpdate(5000);
154154
Assert.assertTrue(update.status == DSStatus.ok);
155155

156-
//remove the value
157-
/*
158-
link.getMain().remove("def");
159-
update = h.nextUpdate(5000);
160-
Assert.assertTrue(update.status == DSStatus.unknown);
161-
h.getStream().closeStream();
162-
*/
163156
}
164157

165158
private void subSimpleValue(DSLink link) {

0 commit comments

Comments
 (0)