Skip to content

Commit 463c077

Browse files
authored
0.41.0
* Table package. * ActionResults refactor.
2 parents 7ba4131 + 9fbe027 commit 463c077

File tree

18 files changed

+222
-100
lines changed

18 files changed

+222
-100
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@
2828
**nodes*.zip
2929
**test.json
3030
**/*.log.*.zip
31+
/dslink-v2/dslink.jks
32+
/dslink-v2-poc/dslink.jks

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.40.0'
8+
version '0.41.0'
99

1010
sourceCompatibility = 1.6
1111
targetCompatibility = 1.6

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

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.iot.dsa.dslink.DSRequestException;
1313
import org.iot.dsa.dslink.responder.InboundInvokeRequest;
1414
import org.iot.dsa.io.DSIWriter;
15-
import org.iot.dsa.node.DSIValue;
1615
import org.iot.dsa.node.DSInfo;
1716
import org.iot.dsa.node.DSList;
1817
import org.iot.dsa.node.DSMap;
@@ -22,6 +21,8 @@
2221
import org.iot.dsa.node.action.ActionValues;
2322
import org.iot.dsa.node.action.DSAbstractAction;
2423
import org.iot.dsa.security.DSPermission;
24+
import org.iot.dsa.table.DSIRow;
25+
import org.iot.dsa.table.DSIRowCursor;
2526

2627
/**
2728
* Invoke implementation for a responder.
@@ -177,6 +178,11 @@ public void run() {
177178
}
178179
}
179180
DSAbstractAction action = info.getAction();
181+
//todo
182+
/*
183+
If action is table action wrap dsicursor
184+
If action is values action...
185+
*/
180186
result = action.invoke(info, this);
181187
} catch (Exception x) {
182188
error(getPath(), x);
@@ -356,30 +362,31 @@ private boolean isClosePending() {
356362

357363
private void writeColumns(MessageWriter writer) {
358364
DSIWriter out = writer.getWriter();
359-
if (result instanceof ActionValues) {
360-
out.key("columns").beginList();
361-
Iterator<DSMap> it = result.getAction().getValueResults();
362-
if (it != null) {
363-
while (it.hasNext()) {
364-
out.value(it.next());
365-
}
366-
}
367-
out.endList();
368-
} else if (result instanceof ActionTable) {
365+
if (result instanceof ActionTable) {
369366
ActionSpec action = result.getAction();
370367
out.key("meta")
371368
.beginMap()
372369
.key("mode").value(action.getResultType().isStream() ? "stream" : "append")
373370
.key("meta").beginMap().endMap()
374371
.endMap();
375372
out.key("columns").beginList();
376-
Iterator<DSMap> iterator = ((ActionTable) result).getColumns();
377-
if (iterator != null) {
378-
while (iterator.hasNext()) {
379-
out.value(iterator.next());
380-
}
373+
ActionTable tbl = (ActionTable) result;
374+
DSMap col = new DSMap();
375+
for (int i = 0, len = tbl.getColumnCount(); i < len; i++) {
376+
tbl.getMetadata(i, col.clear());
377+
out.value(col);
381378
}
382379
out.endList();
380+
} else if (result instanceof ActionValues) {
381+
out.key("columns").beginList();
382+
ActionValues vals = (ActionValues) result;
383+
DSMap col = new DSMap();
384+
for (int i = 0, len = vals.getColumnCount(); i < len; i++) {
385+
vals.getMetadata(i, col.clear());
386+
out.value(col);
387+
}
388+
out.endList();
389+
383390
} else {
384391
out.key("columns").beginList().endList();
385392
}
@@ -389,29 +396,30 @@ private void writeInitialResults(MessageWriter writer) {
389396
DSIWriter out = writer.getWriter();
390397
state = STATE_ROWS;
391398
out.key(getRowsName()).beginList();
392-
if (result instanceof ActionValues) {
393-
out.beginList();
394-
Iterator<DSIValue> values = ((ActionValues) result).getValues();
395-
if (values != null) {
396-
while (values.hasNext()) {
397-
DSIValue val = values.next();
398-
out.value(val.toElement());
399-
}
400-
}
401-
out.endList();
402-
} else if (result instanceof ActionTable) {
403-
if (rows == null) {
404-
rows = ((ActionTable) result).getRows();
405-
}
399+
if (result instanceof DSIRowCursor) {
406400
DSResponder session = getResponder();
407-
while (rows.hasNext()) {
408-
out.value(rows.next());
401+
DSIRowCursor cur = (DSIRowCursor) result;
402+
int cols = cur.getColumnCount();
403+
while (cur.next()) {
404+
out.beginList();
405+
for (int i = 0; i < cols; i++) {
406+
out.value(cur.getValue(i).toElement());
407+
}
408+
out.endList();
409409
if (session.shouldEndMessage()) {
410410
out.endList();
411411
enqueueResponse();
412412
return;
413413
}
414414
}
415+
} else if (result instanceof DSIRow) {
416+
DSIRow row = (DSIRow) result;
417+
int cols = row.getColumnCount();
418+
out.beginList();
419+
for (int i = 0; i < cols; i++) {
420+
out.value(row.getValue(i).toElement());
421+
}
422+
out.endList();
415423
}
416424
out.endList();
417425
if ((result == null) || !result.getAction().getResultType().isOpen() || !stream) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,11 @@ private void encodeTargetAction(ApiObject object, MessageWriter writer) {
511511
}
512512
if (action.getResultType().isValues()) {
513513
e = cacheMap.remove("$columns");
514-
if (e == null) {
514+
if (e != null) {
515+
encode("$columns", e, writer);
516+
} else {
515517
DSList list = new DSList();
516-
Iterator<DSMap> cols = action.getValueResults();
518+
Iterator<DSMap> cols = action.getValueMetadata();
517519
if (cols != null) {
518520
DSMap param;
519521
while (cols.hasNext()) {
@@ -529,8 +531,6 @@ private void encodeTargetAction(ApiObject object, MessageWriter writer) {
529531
}
530532
}
531533
encode("$columns", list, writer);
532-
} else {
533-
encode("$columns", e, writer);
534534
}
535535
}
536536
e = cacheMap.remove("$result");

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/sys/logging/StreamableLogNode.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.acuity.iot.dsa.dslink.sys.logging;
22

33
import java.util.Collections;
4-
import java.util.Iterator;
54
import java.util.List;
65
import java.util.logging.Handler;
76
import java.util.logging.LogRecord;
87
import java.util.logging.Logger;
98
import org.iot.dsa.logging.DSLogHandler;
9+
import org.iot.dsa.node.DSIValue;
1010
import org.iot.dsa.node.DSInfo;
1111
import org.iot.dsa.node.DSList;
1212
import org.iot.dsa.node.DSMap;
@@ -62,7 +62,7 @@ protected void write(LogRecord record) {
6262
}
6363
};
6464
loggerObj.addHandler(handler);
65-
DSMap col = new DSMetadata().setName("Record").setType(DSValueType.STRING).getMap();
65+
final DSMap col = new DSMetadata().setName("Record").setType(DSValueType.STRING).getMap();
6666
final List<DSMap> columns = Collections.singletonList(col);
6767

6868
return new ActionTable() {
@@ -73,14 +73,23 @@ public ActionSpec getAction() {
7373
}
7474

7575
@Override
76-
public Iterator<DSMap> getColumns() {
77-
return columns.iterator();
76+
public int getColumnCount() {
77+
return columns.size();
7878
}
7979

8080
@Override
81-
public Iterator<DSList> getRows() {
82-
List<DSList> empty = Collections.emptyList();
83-
return empty.iterator();
81+
public void getMetadata(int col, DSMap bucket) {
82+
bucket.putAll(columns.get(col));
83+
}
84+
85+
@Override
86+
public DSIValue getValue(int col) {
87+
return null;
88+
}
89+
90+
@Override
91+
public boolean next() {
92+
return false;
8493
}
8594

8695
@Override

dslink-v2/src/main/java/com/acuity/iot/dsa/dslink/sys/profiler/ThreadNode.java

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,26 @@
33
import java.lang.management.ManagementFactory;
44
import java.lang.management.ThreadInfo;
55
import java.lang.management.ThreadMXBean;
6-
import java.util.*;
6+
import java.util.ArrayList;
7+
import java.util.Collections;
8+
import java.util.HashMap;
9+
import java.util.HashSet;
10+
import java.util.List;
11+
import java.util.Map;
12+
import java.util.Set;
713
import org.iot.dsa.node.DSIValue;
814
import org.iot.dsa.node.DSInfo;
915
import org.iot.dsa.node.DSList;
1016
import org.iot.dsa.node.DSMap;
1117
import org.iot.dsa.node.DSString;
1218
import org.iot.dsa.node.DSValueType;
13-
import org.iot.dsa.node.action.*;
19+
import org.iot.dsa.node.action.ActionInvocation;
20+
import org.iot.dsa.node.action.ActionResult;
21+
import org.iot.dsa.node.action.ActionSpec;
1422
import org.iot.dsa.node.action.ActionSpec.ResultType;
23+
import org.iot.dsa.node.action.ActionValues;
24+
import org.iot.dsa.node.action.DSAbstractAction;
25+
import org.iot.dsa.node.action.DSActionValues;
1526

1627
public class ThreadNode extends MXBeanNode {
1728

@@ -48,20 +59,23 @@ public void prepareParameter(DSInfo info, DSMap parameter) {
4859
act.setResultType(ResultType.VALUES);
4960
act.addValueResult("Result", DSValueType.STRING);
5061
declareDefault("Find Monitor Deadlocked Threads", act);
51-
62+
5263
act = new DSAbstractAction() {
53-
64+
5465
@Override
5566
public void prepareParameter(DSInfo info, DSMap parameter) {
5667
}
57-
68+
5869
@Override
5970
public ActionResult invoke(DSInfo info, ActionInvocation invocation) {
60-
return ((ThreadNode) info.getParent()).getThreadDump(info, invocation.getParameters());
71+
return ((ThreadNode) info.getParent())
72+
.getThreadDump(info, invocation.getParameters());
6173
}
6274
};
63-
act.addParameter("Dump Locked Monitors", DSValueType.BOOL, "If true, dump all locked monitors");
64-
act.addParameter("Dump Locked Synschronizers", DSValueType.BOOL, "If true, dump all locked ownable synchronizers");
75+
act.addParameter("Dump Locked Monitors", DSValueType.BOOL,
76+
"If true, dump all locked monitors");
77+
act.addParameter("Dump Locked Synschronizers", DSValueType.BOOL,
78+
"If true, dump all locked ownable synchronizers");
6579
act.addValueResult("Thread Dump", DSValueType.STRING).setEditor("textarea");
6680
act.setResultType(ResultType.VALUES);
6781
declareDefault("Get Thread Dump", act);
@@ -109,8 +123,18 @@ public ActionSpec getAction() {
109123
}
110124

111125
@Override
112-
public Iterator<DSIValue> getValues() {
113-
return values.iterator();
126+
public int getColumnCount() {
127+
return values.size();
128+
}
129+
130+
@Override
131+
public void getMetadata(int idx, DSMap bucket) {
132+
bucket.putAll(action.getValueResult(idx));
133+
}
134+
135+
@Override
136+
public DSIValue getValue(int idx) {
137+
return values.get(idx);
114138
}
115139
};
116140
}
@@ -129,7 +153,7 @@ public void refreshImpl() {
129153
}
130154
putProp("AllThreadIds", l);
131155
ThreadInfo[] infos = mxbean.getThreadInfo(ids, false, false);
132-
Set<Long> prevIds = new HashSet<Long>(infoNodes.keySet());
156+
Set<Long> prevIds = new HashSet<Long>(infoNodes.keySet());
133157
for (ThreadInfo info : infos) {
134158
long id = info.getThreadId();
135159
prevIds.remove(id);
@@ -143,7 +167,7 @@ public void refreshImpl() {
143167
}
144168
infoNode.update(info, mxbean.getThreadCpuTime(id), mxbean.getThreadUserTime(id));
145169
}
146-
for (long id: prevIds) {
170+
for (long id : prevIds) {
147171
ThreadInfoNode infoNode = infoNodes.get(id);
148172
ThreadInfo info = mxbean.getThreadInfo(id);
149173
if (infoNode != null && info != null) {
@@ -154,7 +178,7 @@ public void refreshImpl() {
154178
remove(removed.getInfo());
155179
}
156180
}
157-
181+
158182
}
159183
}
160184

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,12 @@ public DSMap put(String key, Throwable val) {
439439
* @return This
440440
*/
441441
public DSMap putAll(DSMap toAdd) {
442-
Entry e = toAdd.firstEntry();
443-
while (e != null) {
444-
put(e.getKey(), e.getValue().copy());
442+
if (toAdd != null) {
443+
Entry e = toAdd.firstEntry();
444+
while (e != null) {
445+
put(e.getKey(), e.getValue().copy());
446+
e = e.next();
447+
}
445448
}
446449
return this;
447450
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ public Iterator<DSInfo> iterateNodes() {
647647
}
648648

649649
/**
650-
* Returns an info iterator of child DSIValues.
650+
* Returns an info iterator of child values.
651651
*/
652652
public Iterator<DSInfo> iterateValues() {
653653
return new ValueIterator();

dslink-v2/src/main/java/org/iot/dsa/node/action/ActionInvocation.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import org.iot.dsa.security.DSPermission;
66

77
/**
8-
* Encapsulates the details of an action invocation and provides the mechanism for updating and open
8+
* Encapsulates the details of an action invocation and provides the mechanism for updating an open
99
* stream.
10-
* <p>
11-
* The action
1210
*
1311
* @author Aaron Hansen
1412
*/
@@ -25,7 +23,7 @@ public interface ActionInvocation {
2523
public void close();
2624

2725
/**
28-
* Close and send and error. For use with streams and open tables, will have no effect if the
26+
* Close and send an error. For use with streams and open tables, will have no effect if the
2927
* stream is already closed.
3028
*/
3129
public void close(Exception reason);

0 commit comments

Comments
 (0)