Skip to content

Commit 8f0e4c3

Browse files
authored
0.69.0
* Action Refactor
2 parents 891a4fd + 63ccdb9 commit 8f0e4c3

Some content is hidden

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

58 files changed

+1268
-2132
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.68.0'
8+
version '0.69.0'
99

1010
targetCompatibility = JavaVersion.VERSION_1_8
1111
sourceCompatibility = JavaVersion.VERSION_1_8
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package org.iot.dsa.dslink;
2+
3+
import org.iot.dsa.node.DSMap;
4+
import org.iot.dsa.security.DSPermission;
5+
6+
/**
7+
* Defines an invokable node in the DSA model.
8+
*
9+
* @author Aaron Hansen
10+
*/
11+
public interface Action {
12+
13+
/**
14+
* Only needed for a VALUES type actions, and optional even then.
15+
*/
16+
public default int getColumnCount() {
17+
return 0;
18+
}
19+
20+
/**
21+
* Add the metadata for the column at the given index to the bucket. Only called before the
22+
* action invocation. Throws an IllegalStateException by default.
23+
*/
24+
public default void getColumnMetadata(int idx, DSMap bucket) {
25+
throw new IllegalStateException("Method not overridden");
26+
}
27+
28+
/**
29+
* Return 0 or less if there are no parameters. Returns 0 by default.
30+
*/
31+
public default int getParameterCount() {
32+
return 0;
33+
}
34+
35+
/**
36+
* Add the metadata for the parameter at the given index to the bucket. Throws an
37+
* IllegalStateException by default.
38+
*/
39+
public default void getParameterMetadata(int idx, DSMap bucket) {
40+
throw new IllegalStateException("Method not overridden");
41+
}
42+
43+
/**
44+
* Minimum permission level required to invoke, returns WRITE by default.
45+
*/
46+
public default DSPermission getPermission() {
47+
return DSPermission.WRITE;
48+
}
49+
50+
/**
51+
* What the action returns, returns VOID by default.
52+
*/
53+
public default ResultsType getResultsType() {
54+
return ResultsType.VOID;
55+
}
56+
57+
/**
58+
* Defines what the action returns.
59+
*/
60+
public enum ResultsType {
61+
62+
/**
63+
* A stream of rows. Clients can choose to trim rows for memory management.
64+
*/
65+
STREAM("stream"),
66+
67+
/**
68+
* A finite sized table whose stream is closed when the row cursor is complete.
69+
*/
70+
TABLE("table"),
71+
72+
/**
73+
* A single row of values.
74+
*/
75+
VALUES("values"),
76+
77+
/**
78+
* No return value.
79+
*/
80+
VOID("");
81+
82+
private String display;
83+
84+
ResultsType(String display) {
85+
this.display = display;
86+
}
87+
88+
public boolean isStream() {
89+
return this == STREAM;
90+
}
91+
92+
public boolean isTable() {
93+
return this == TABLE;
94+
}
95+
96+
public boolean isValues() {
97+
return this == VALUES;
98+
}
99+
100+
public boolean isVoid() {
101+
return this == VOID;
102+
}
103+
104+
public String toString() {
105+
return display;
106+
}
107+
108+
} //ResultType
109+
110+
}
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 org.iot.dsa.node.DSElement;
4+
import org.iot.dsa.node.DSMap;
5+
import org.iot.dsa.security.DSPermission;
6+
7+
/**
8+
* Encapsulates the details of an action invocation and provides the mechanism for updating an open
9+
* stream.
10+
*
11+
* @author Aaron Hansen
12+
*/
13+
public interface ActionRequest {
14+
15+
/**
16+
* For use with streams and open tables, will have no effect if the stream is already closed.
17+
*/
18+
public void close();
19+
20+
/**
21+
* Close and send an error. For use with streams and open tables, will have no effect if the
22+
* stream is already closed.
23+
*/
24+
public void close(Exception reason);
25+
26+
/**
27+
* This needs to be called when there are more results after ActionsResults.next()
28+
* returns false.
29+
*/
30+
public void enqueueResults();
31+
32+
/**
33+
* The parameters supplied by the invoker, or null.
34+
*/
35+
public DSMap getParameters();
36+
37+
/**
38+
* A convenience for getting a single parameter out of the parameters map.
39+
*/
40+
public default DSElement getParameter(String key) {
41+
return getParameters().get(key);
42+
}
43+
44+
/**
45+
* The permission level of the invoker.
46+
*/
47+
public DSPermission getPermission();
48+
49+
/**
50+
* Whether or not response is still open.
51+
*/
52+
public boolean isOpen();
53+
54+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.iot.dsa.dslink;
2+
3+
import org.iot.dsa.dslink.Action.ResultsType;
4+
import org.iot.dsa.node.DSList;
5+
import org.iot.dsa.node.DSMap;
6+
7+
/**
8+
* The results of an action request. This is implemented as a cursor for all result types.
9+
* The implementation can return false from next() and resume later. After returning
10+
* false from next(), the implementation must call ActionRequest.close() or
11+
* ActionRequest.enqueueResults().
12+
* <p>
13+
* If the result type is VALUES, next() will only be called once. The implementation does not
14+
* need to call any other methods on ActionRequest.
15+
*
16+
* @author Aaron Hansen
17+
*/
18+
public interface ActionResults {
19+
20+
/**
21+
* Unless the result type is void, this should return a value greater than zero.
22+
*/
23+
public int getColumnCount();
24+
25+
/**
26+
* Only needed if the column count is greater than 0. Throws an IllegalStateException by
27+
* default.
28+
*/
29+
public void getColumnMetadata(int idx, DSMap bucket);
30+
31+
/**
32+
* The implementation should add the values of the current result set to the given bucket. The
33+
* bucket may be reused across calls, the implementation should not cache references to it.
34+
*/
35+
public void getResults(DSList bucket);
36+
37+
/**
38+
* Determines how the results should be used.
39+
*/
40+
public ResultsType getResultsType();
41+
42+
/**
43+
* Initially, this cursor must be positioned before the first set of results. Return true to
44+
* advance the next set of results. The implementation is responsible for calling
45+
* DIActionRequest.enqueueResults() or DIActionRequest.close(). This will only
46+
* be called once for a result type of VALUES.
47+
*/
48+
public boolean next();
49+
50+
/**
51+
* Always called, does nothing by default.
52+
*/
53+
public default void onClose() {
54+
}
55+
56+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.iot.dsa.dslink.responder.InboundSubscribeRequest;
77
import org.iot.dsa.dslink.responder.OutboundListResponse;
88
import org.iot.dsa.dslink.responder.SubscriptionCloseHandler;
9-
import org.iot.dsa.node.action.ActionResult;
109

1110
/**
1211
* Interface for nodes in the node tree to manually handle requests. The first implementation
@@ -33,7 +32,7 @@ public interface DSIResponder {
3332
* @return The initial response and close notification mechanism, can be null if the if the
3433
* result type is void.
3534
*/
36-
public ActionResult onInvoke(InboundInvokeRequest request);
35+
public ActionResults onInvoke(InboundInvokeRequest request);
3736

3837
/**
3938
* The implementation should quickly create an object for responding to the request, but do no

dslink-v2-api/src/main/java/org/iot/dsa/dslink/requester/SimpleInvokeHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ public class SimpleInvokeHandler extends AbstractInvokeHandler {
1818
// Instance Fields
1919
///////////////////////////////////////////////////////////////////////////
2020

21-
private boolean closed = false;
2221
private DSList columns;
23-
private RuntimeException error;
2422
private Mode mode;
2523
private DSMap tableMeta;
2624
private ArrayList<DSList> updates;
@@ -79,7 +77,7 @@ public DSList getUpdate(long timeout) {
7977
timeout = end - System.currentTimeMillis();
8078
}
8179
if (isError()) {
82-
throw error;
80+
throw getError();
8381
}
8482
if (hasUpdates()) {
8583
return updates.remove(0);

dslink-v2-api/src/main/java/org/iot/dsa/dslink/responder/ApiObject.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.iot.dsa.dslink.responder;
22

33
import java.util.Iterator;
4+
import org.iot.dsa.dslink.Action;
45
import org.iot.dsa.node.DSMap;
5-
import org.iot.dsa.node.action.ActionSpec;
66

77
/**
88
* Can be a node, value or an action.
@@ -14,7 +14,7 @@ public interface ApiObject {
1414
/**
1515
* The action, should only be called if isAction() returns true.
1616
*/
17-
public ActionSpec getAction();
17+
public Action getAction();
1818

1919
/**
2020
* Return the object representing the child with the given name.
@@ -28,23 +28,13 @@ public interface ApiObject {
2828

2929
public void getMetadata(DSMap bucket);
3030

31-
/**
32-
* The display name.
33-
public String getName();
34-
*/
35-
36-
/**
37-
* Value of the object, should only be called if isValue() returns true.
38-
public DSIValue getValue();
39-
*/
40-
4131
/**
4232
* True if the object is an action.
4333
*/
4434
public boolean isAction();
4535

4636
/**
47-
* Whether or not this object requires configuration permission to read/write.
37+
* Whether or not this object requires admin permission to read/write.
4838
*/
4939
public boolean isAdmin();
5040

@@ -59,7 +49,7 @@ public interface ApiObject {
5949
public boolean isReadOnly();
6050

6151
/**
62-
* True if getValue() can be called.
52+
* True if the object is a value.
6353
*/
6454
public boolean isValue();
6555

dslink-v2-api/src/main/java/org/iot/dsa/dslink/responder/InboundInvokeRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package org.iot.dsa.dslink.responder;
22

33
import org.iot.dsa.node.DSMap;
4-
import org.iot.dsa.node.action.ActionInvocation;
4+
import org.iot.dsa.node.action.DSIActionRequest;
55

66
/**
77
* See ActionInvocation for the real meat.
88
*
99
* @author Aaron Hansen
10-
* @see ActionInvocation
10+
* @see DSIActionRequest
1111
*/
12-
public interface InboundInvokeRequest extends InboundRequest, ActionInvocation {
12+
public interface InboundInvokeRequest extends InboundRequest, DSIActionRequest {
1313

1414
/**
1515
* The parameters supplied by the invoker, or null.

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66
import org.iot.dsa.dslink.responder.ApiObject;
77
import org.iot.dsa.node.action.DSAction;
8+
import org.iot.dsa.node.action.DSIAction;
89
import org.iot.dsa.node.action.DSISetAction;
910
import org.iot.dsa.util.DSUtil;
1011

@@ -148,8 +149,8 @@ public T get() {
148149
}
149150

150151
@Override
151-
public DSAction getAction() {
152-
return (DSAction) get();
152+
public DSIAction getAction() {
153+
return (DSIAction) get();
153154
}
154155

155156
@Override
@@ -362,7 +363,7 @@ public void modified(DSGroup map) {
362363
/**
363364
* The next info in the parent node, or null.
364365
*/
365-
public DSInfo next() {
366+
public DSInfo<?> next() {
366367
return next;
367368
}
368369

@@ -432,7 +433,7 @@ public DSInfo<T> setAdmin(boolean admin) {
432433
}
433434

434435
/**
435-
* False by default, set to true to reset the target to it's default when the encapsulated node
436+
* False by default, set to true to reset the target to it's default when the parent node
436437
* is copied.
437438
*/
438439
public DSInfo<T> setDefaultOnCopy(boolean defaultOnCopy) {
@@ -569,6 +570,12 @@ DSInfo<T> setName(String arg) {
569570
}
570571

571572
DSInfo<T> setObject(T arg) {
573+
if (isDeclared()) {
574+
if (!getDefaultObject().getClass().isInstance(arg)) {
575+
throw new IllegalArgumentException(arg + " not an instanceof the declared type " +
576+
getDefaultObject().getClass().getName());
577+
}
578+
}
572579
this.object = arg;
573580
return this;
574581
}

0 commit comments

Comments
 (0)