Skip to content

Commit 7fa8709

Browse files
authored
0.75.0
* Add ignore equals flag to dsinfo for ignoring the putting of equals children. * Extend read timeout to fix random disconnects (timing too tight). * Close transport on stopped.
2 parents 31ed3dc + 4ee6198 commit 7fa8709

File tree

9 files changed

+123
-51
lines changed

9 files changed

+123
-51
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.74.1'
8+
version '0.75.0'
99

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class DSInfo<T extends DSIObject> implements GroupListener {
3535
static final int DECLARED = 4;
3636
static final int DEFAULT_ON_COPY = 5;
3737
static final int LOCKED = 6;
38+
static final int IGNORE_EQUALS = 7;
3839

3940
///////////////////////////////////////////////////////////////////////////
4041
// Fields
@@ -331,6 +332,23 @@ public boolean isFrozen() {
331332
return isDeclared() || isLocked();
332333
}
333334

335+
/**
336+
* False by default, set to true if you don't want equals objects to be applied and
337+
* events to be fired.
338+
*/
339+
public boolean isIgnoreEquals() {
340+
return getFlag(IGNORE_EQUALS);
341+
}
342+
343+
/**
344+
* False by default, set to true if you don't want equals objects to be applied and
345+
* events to be fired.
346+
*/
347+
public DSInfo<T> setIgnoreEquals(boolean ignore) {
348+
setFlag(IGNORE_EQUALS, ignore);
349+
return this;
350+
}
351+
334352
/**
335353
* True if the info cannot be removed or renamed.
336354
* Intended for non-default children, default children are implicitly locked.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,10 @@ public DSNode put(DSInfo<?> info, DSIObject object) {
904904
throw new IllegalArgumentException("Info parented in another node");
905905
}
906906
validateChild(object);
907+
DSIObject old = info.get();
908+
if (DSUtil.equal(object, old) && info.isIgnoreEquals()) {
909+
return this;
910+
}
907911
DSNode argAsNode = null;
908912
boolean argIsNode = isNode(object);
909913
if (argIsNode) {
@@ -913,7 +917,6 @@ public DSNode put(DSInfo<?> info, DSIObject object) {
913917
if (object instanceof DSGroup) {
914918
((DSGroup) object).setParent(this);
915919
}
916-
DSIObject old = info.get();
917920
((DSInfo<DSIObject>) info).setObject(object);
918921
if (isNode(old)) {
919922
DSNode node = toNode(old);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ public boolean isOpen() {
105105
return state.isOpen();
106106
}
107107

108+
@Override
109+
public void listComplete() {
110+
sendStreamOpen = true;
111+
enqueueResponse();
112+
}
113+
108114
/**
109115
* This is the only way to really close a list request, called only when the connection is
110116
* closed or the requester has explicitly closed it.
@@ -271,12 +277,6 @@ public void sendChildValue(final String name,
271277
enqueue(encodeName(name, cacheBuf), map);
272278
}
273279

274-
@Override
275-
public void listComplete() {
276-
sendStreamOpen = true;
277-
enqueueResponse();
278-
}
279-
280280
@Override
281281
public void sendRemove(String name) {
282282
if (!isOpen()) {

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/transport/DSTransport.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract class DSTransport extends DSNode implements DSITransport {
2626
// Class Fields
2727
///////////////////////////////////////////////////////////////////////////
2828

29-
private static final int DEFAULT_READ_TIMEOUT = 60000;
29+
private static final int DEFAULT_READ_TIMEOUT = 90000;
3030
private static final byte[] EMPTY_BYTES = new byte[0];
3131
private static final int HEX_COLS = 30;
3232
private static final String TEXT = "Text";
@@ -465,6 +465,12 @@ protected void onStarted() {
465465
getTransportLogger();
466466
}
467467

468+
@Override
469+
protected void onStopped() {
470+
close();
471+
super.onStopped();
472+
}
473+
468474
/**
469475
* Subclasses must call this when the stream is opened.
470476
*/

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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ public void test1() throws Exception {
2929
}
3030
}
3131
}, System.currentTimeMillis() + 400, 100);
32-
33-
// System.out.println("test1 now: " + System.nanoTime());
34-
// System.out.println("test1nextrun: " + tim.nextRun());
35-
3632
synchronized (lock1) {
37-
lock1.wait(1000);
33+
lock1.wait(2000);
3834
}
3935
Assert.assertTrue(runs >= 5);
4036
}
@@ -50,12 +46,8 @@ public void test2() throws Exception {
5046
}
5147
}
5248
}, 400, 100);
53-
54-
// System.out.println("test2 now: " + System.nanoTime());
55-
// System.out.println("test2nextrun: " + tim.nextRun());
56-
5749
synchronized (lock2) {
58-
lock2.wait(1000);
50+
lock2.wait(2000);
5951
}
6052
Assert.assertTrue(runsWithDelay >= 5);
6153
}
@@ -69,10 +61,6 @@ public void test3() throws Exception {
6961
lock3.notifyAll();
7062
}
7163
}, System.currentTimeMillis() + 400);
72-
73-
// System.out.println("test3 now: " + System.nanoTime());
74-
// System.out.println("test3nextrun: " + tim.nextRun());
75-
7664
synchronized (lock3) {
7765
lock3.wait(500);
7866
}
@@ -88,10 +76,6 @@ public void test4() throws Exception {
8876
lock4.notifyAll();
8977
}
9078
}, 400);
91-
92-
// System.out.println("test4 now: " + System.nanoTime());
93-
// System.out.println("test4nextrun: " + tim.nextRun());
94-
9579
synchronized (lock4) {
9680
lock4.wait(500);
9781
}
@@ -109,14 +93,14 @@ public void test5() throws Exception {
10993
}
11094
}
11195
}, 0, 100);
112-
113-
// System.out.println("test1 now: " + System.nanoTime());
114-
// System.out.println("test1nextrun: " + tim.nextRun());
115-
11696
synchronized (lock5) {
11797
lock5.wait(600);
11898
}
11999
Assert.assertTrue(runsImmed >= 5);
120100
}
121101

102+
@Test
103+
public void test6() throws Exception {
104+
}
105+
122106
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ public class NodeTest {
2525
// Methods
2626
// -------
2727

28+
@Test
29+
public void testOnChildChanged() throws Exception {
30+
DSNode root = new DSNode();
31+
MyNode child = new MyNode();
32+
root.add("child", child);
33+
root.start();
34+
Assert.assertTrue(child.isRunning());
35+
Assert.assertFalse(child.isStopped());
36+
Assert.assertTrue(child.lastChildChange == 0);
37+
long time = System.currentTimeMillis();
38+
child.setSecond(false);
39+
Assert.assertTrue(child.lastChildChange >= time);
40+
root.remove("child");
41+
Assert.assertFalse(child.isRunning());
42+
Assert.assertTrue(child.isStopped());
43+
Thread.sleep(10);
44+
time = System.currentTimeMillis();
45+
child.setSecond(true);
46+
Assert.assertFalse(child.lastChildChange >= time);
47+
}
48+
2849
@Test
2950
public void theTest() {
3051
testMine(new MyNode());
@@ -60,6 +81,7 @@ private void testMine(MyNode mine) {
6081

6182
public static class MyNode extends DSNode {
6283

84+
long lastChildChange;
6385
private DSInfo<?> second = getInfo("second");
6486

6587
public boolean isSecond() {
@@ -76,6 +98,10 @@ protected void declareDefaults() {
7698
declareDefault("second", DSBool.valueOf(true));
7799
}
78100

101+
protected void onChildChanged(DSInfo<?> child) {
102+
lastChildChange = System.currentTimeMillis();
103+
}
104+
79105
}
80106

81107

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.iot.dsa.dslink;
2+
3+
import com.acuity.iot.dsa.dslink.test.V1TestLink;
4+
import org.iot.dsa.node.DSInt;
5+
import org.iot.dsa.node.DSNode;
6+
import org.testng.Assert;
7+
import org.testng.annotations.Test;
8+
9+
public class SubscriptionTest {
10+
11+
private static boolean success = false;
12+
private V1TestLink link;
13+
14+
@Test
15+
public void theTest() throws Exception {
16+
link = new V1TestLink(new DSMainNode());
17+
Thread t = new Thread(link, "DSLink Runner");
18+
t.start();
19+
link.getConnection().waitForConnection(5000);
20+
Assert.assertTrue(link.getConnection().isConnected());
21+
22+
DSMainNode main = link.getMain();
23+
main.put("yesDuplicates", DSInt.valueOf(0));
24+
main.put("noDuplicates", DSInt.valueOf(0)).setIgnoreEquals(true);
25+
26+
main.subscribe((event, node, child, data) -> {
27+
Assert.assertTrue(child.isValue());
28+
Assert.assertTrue(child.getValue().toElement().isNumber());
29+
synchronized (SubscriptionTest.this) {
30+
success = !success;
31+
Assert.assertEquals(node, main);
32+
SubscriptionTest.this.notifyAll();
33+
}
34+
}, DSNode.VALUE_CHANGED_EVENT, null);
35+
36+
success = false;
37+
main.put("yesDuplicates", DSInt.valueOf(0));
38+
synchronized (SubscriptionTest.this) {
39+
if (!success) {
40+
SubscriptionTest.this.wait(5000);
41+
}
42+
}
43+
Assert.assertTrue(success);
44+
success = true;
45+
main.put("noDuplicates", DSInt.valueOf(0));
46+
synchronized (SubscriptionTest.this) {
47+
if (success) { //should have to wait
48+
SubscriptionTest.this.wait(3000);
49+
}
50+
}
51+
Assert.assertTrue(success);
52+
}
53+
54+
}

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
import org.iot.dsa.dslink.requester.SimpleInvokeHandler;
88
import org.iot.dsa.node.DSIObject;
99
import org.iot.dsa.node.DSInfo;
10-
import org.iot.dsa.node.DSNode;
1110
import org.testng.Assert;
1211
import org.testng.annotations.Test;
1312

1413
public class SysProfilerTest {
1514

16-
private static boolean success = false;
1715
private V1TestLink link;
1816

1917
@Test
@@ -26,7 +24,7 @@ public void theTest() throws Exception {
2624
DSIRequester requester = link.getConnection().getRequester();
2725
SimpleInvokeHandler res = (SimpleInvokeHandler) requester.invoke(
2826
"/sys/" + DSSysNode.OPEN_PROFILER, null, new SimpleInvokeHandler());
29-
res.getUpdate(2000);
27+
res.getUpdate(5000);
3028

3129
DSSysNode sys = link.get(DSLink.SYS);
3230
DSIObject profobj = sys.get(DSSysNode.PROFILER);
@@ -39,23 +37,6 @@ public void theTest() throws Exception {
3937
final ThreadNode thread = (ThreadNode) threadobj;
4038
final DSInfo<?> cpuTime = thread.getInfo("CurrentThreadCpuTime");
4139
Assert.assertTrue(cpuTime != null);
42-
success = false;
43-
thread.subscribe((event, node, child, data) -> {
44-
Assert.assertEquals(thread, node);
45-
Assert.assertEquals(cpuTime, child);
46-
Assert.assertTrue(child.isValue());
47-
Assert.assertTrue(child.getValue().toElement().isNumber());
48-
synchronized (SysProfilerTest.this) {
49-
success = true;
50-
SysProfilerTest.this.notifyAll();
51-
}
52-
}, DSNode.VALUE_CHANGED_EVENT, cpuTime);
53-
synchronized (this) {
54-
if (!success) {
55-
this.wait(6000);
56-
}
57-
}
58-
Assert.assertTrue(success);
5940
}
6041

6142
}

0 commit comments

Comments
 (0)