@@ -35,40 +35,40 @@ Key objectives of this SDK:
3535These are the major steps you'll take when creating a link:
3636
37371 . Copy example link.
38- 2 . Create nodes.
38+ 2 . Create application nodes.
3939
4040## Copy Example Link
4141
4242Copy the
4343[ dslink-java-v2-example] ( https://github.com/iot-dsa-v2/dslink-java-v2-example )
4444project to create a new repository. It's README provides
45- further instructions for customization.
45+ detailed instructions for customization.
4646
4747The example link is a very simple but fully functioning link with a single root node. It is
4848recommended you get that running within a broker before continuing with this documentation.
4949
50- ## Create Nodes
50+ ## Create Application Nodes
5151
5252Nodes are where application specific logic is bound to the link architecture. Node developers
5353will use various lifecycle callbacks to trigger their logic.
5454
55- First you must create a root node. It is the hook for the rest of your functionality. The
56- convention is to name it MainNode, but make sure it is in a unique package so that multiple links
55+ First you must create a root application node. It is the hook for the rest of your functionality.
56+ The convention is to name it MainNode, but make sure it is in a unique package so that multiple links
5757can be run in the same process.
5858
5959Then you will probably create additional nodes that will be descendants in the tree rooted by your
60- root node.
60+ main node.
6161
6262### Main Node
6363
64- All links require a single root node and it must subclass
64+ All links require a single root data node and it must subclass
6565[ org.iot.dsa.dslink.DSMainNode] ( https://iot-dsa-v2.github.io/sdk-dslink-java-v2/javadoc/index.html?org/iot/dsa/dslink/DSMainNode.html ) .
6666The convention is to name the class MainNode but the package must be unique from any other
67- MainNodes so that multiple links can be run in the same process.
67+ MainNodes (other links) so that multiple links can be run in the same process.
6868
69- When a link launches the first time, the type of the root node is looked up ** dslink.json** .
70- The config _ mainType _ must store the fully qualified class name of the root node. After the first
71- launch, the configuration database is serialized and the _ mainType _ config will longer have an
69+ When a link launches the first time, the type of the main node is looked up ** dslink.json** .
70+ The config _ handler_class _ must store the fully qualified class name of the root node. After the first
71+ launch, the configuration database is serialized and the _ handler_class _ config will longer have an
7272impact.
7373
7474### Additional Nodes
@@ -89,8 +89,11 @@ instantiated when deserializing the configuration database.
8989
9090### Defaults
9191
92- Every subtype of DSNode has a private default instance, all other instances are copies of the
93- default instance. This is why you should never perform application logic unless
92+ Every subclass of DSNode has a private default instance, all other instances are copies of the
93+ default instance. It is an instanced based inheritance scheme that will allow subtypes to remove or
94+ reorder 'fields' declared in super classes.
95+
96+ Since there is a default instance in memory, You should never perform application logic unless
9497triggered by a callback and your node is running (started or stable).
9598
9699If a DSNode subtype needs to have specific child nodes or values (most will), it should override
@@ -138,7 +141,7 @@ When a link is stopped, an attempt to stop the tree will be made, but it cannot
138141
139142** Started**
140143
141- After the node tree is fully deserialized it will be started. A nodes onStart method will be
144+ After the node tree is fully deserialized it will be started. A node's onStart method will be
142145called after all of its child nodes have been started. The only guarantee is that all child
143146nodes have been started.
144147
@@ -147,15 +150,15 @@ Nodes will also started when they are added to an already running parent node.
147150** Stable**
148151
149152Stable is called after the entire tree has been started. The first time the node tree is loaded,
150- there is a stable delay of 5 seconds. This is configurable as ** stableDelay ** in _ dslink.json _ .
153+ there is a stable delay of 5 seconds.
151154
152155Nodes added to an already stable parent will have onStart and onStable called immediately.
153156
154157When in doubt of whether to use onStarted or onStable, use onStable.
155158
156- ** Other Callbacks**
159+ ** Callbacks**
157160
158- When a node is stable, there are several other callbacks for various state changes. All callbacks
161+ When a node is stable, there are several callbacks for various state changes. All callbacks
159162begin with ** on** such as _ onChildAdded()_ . See the
160163[ DSNode Javadoc] ( https://iot-dsa-v2.github.io/sdk-dslink-java-v2/javadoc/index.html?org/iot/dsa/node/DSNode.html )
161164for a complete list.
@@ -178,10 +181,11 @@ there are multiple subscribers, this is only called when the last one unsubscrib
178181Values mostly represent leaf members of the node tree. There are two types of values:
179182
1801831 . [ org.io.dsa.node.DSElement] ( https://iot-dsa-v2.github.io/sdk-dslink-java-v2/javadoc/index.html?org/iot/dsa/node/DSElement.html ) -
181- These map to the JSON type system and represent leaf members of the node tree.
184+ These are the primitives that mostly map to the JSON type system and will be leaf members of the tree.
1821852 . [ org.io.dsa.node.DSIValue] ( https://iot-dsa-v2.github.io/sdk-dslink-java-v2/javadoc/index.html?org/iot/dsa/node/DSIValue.html ) -
183- These don't have to map to the JSON type system, and it is possible for nodes to implement this
184- interface. This allows for values with children.
186+ These have to be able to convert to DSElements, but they carry additional meaning such as timestamp.
187+ Nodes can implement this to have both a value and children. DSValueNode is a convenience abstract
188+ class for this purpose.
185189
186190The node model encourages values to be immutable and singletons. This is for efficiency, the same
187191value instance (e.g. DSBoolean.TRUE) can be stored in many nodes.
@@ -192,7 +196,7 @@ a value.
192196
193197### Actions
194198
195- Actions allow allow responders to expose functionality that can't be modeled as values.
199+ Actions allow allow responders to expose functionality in DSA that can't be modeled as values.
196200
197201Add actions to your node using
198202[ org.iot.dsa.node.action.DSAction] ( https://iot-dsa-v2.github.io/sdk-dslink-java-v2/javadoc/index.html?org/iot/dsa/node/action/DSAction.html ) .
@@ -222,6 +226,9 @@ Override DSNode.onInvoke to handle invocations.
222226 }
223227```
224228
229+ DSAction can be subclassed. Actions should also be singleton instances for efficiency. For
230+ parameter-less actions that have no return value, use the DSAction.DEFAULT instance.
231+
225232### DSInfo
226233
227234All node children have corresponding DSInfo instances. This type serves serves two purposes:
@@ -287,18 +294,22 @@ To simplify configuring metadata, use the utility class
287294
288295Use [ org.iot.dsa.DSRuntime] ( https://iot-dsa-v2.github.io/sdk-dslink-java-v2/javadoc/index.html?org/iot/dsa/DSRuntime.html ) .
289296
290- Create your own threads for long lived activities and make them daemon as well.
297+ Please avoid using Java executors if possible. In the future we will probably monitor DSRuntime
298+ to help determine when a system is becoming overloaded.
299+
300+ Creating your own threads for long lived activities is perfectly acceptable but not necessary.
291301
292302## Logging
293303
294304Use Java Util Logging (JUL). A high performance async logger is automatically installed as the
295- root logger and it also manages backups.
305+ root logger.
296306
297307Most types subclass
298308[ org.iot.dsa.logging.DSLogger] ( https://iot-dsa-v2.github.io/sdk-dslink-java-v2/javadoc/index.html?org/iot/dsa/logging/DSLogger.html )
299309as a convenience.
300310
301- Without DSLogger:
311+ The most efficient logging will not submit a log message if the level isn't enabled. This is
312+ how it is normally achieved with JUL:
302313
303314``` java
304315 if (myLogger. isLoggable(Level . FINE )) {
@@ -307,20 +318,26 @@ Without DSLogger:
307318```
308319
309320
310- With DSLogger
321+ DSLogger enables the same but with more concise syntax:
311322
312323``` java
313324 fine(fine() ? someMessage() : null );
314325```
315326
316327
328+ DSA has it's own log levels (there can be links in many different languages). All standard
329+ Java log level are mapped into it, but try to use the DSA levels:
330+
317331<b >Level Guidelines</b >
318332
319- - finest = verbose or trace
320- - finer = debug
321- - fine = minor and/or frequent event
322- - config = configuration info
323- - info = major and infrequent event
324- - warn = unusual and infrequent, not critical
325- - severe = critical / fatal error or event
333+ DSA Level = Java Level
334+
335+ - trace = Level.FINEST;
336+ - debug = Level.FINER;
337+ - fine = Level.FINE;
338+ - warn = custom
339+ - info = Level.INFO;
340+ - error = Level.WARNING;
341+ - admin = custom
342+ - fatal = Level.SEVERE;
326343
0 commit comments