Skip to content

Commit 6014e15

Browse files
authored
0.64.0
- Log name changes. - Log message changes.
2 parents f23262f + a9a4c53 commit 6014e15

File tree

24 files changed

+155
-102
lines changed

24 files changed

+155
-102
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![](https://jitpack.io/v/iot-dsa-v2/sdk-dslink-java-v2.svg)](https://jitpack.io/#iot-dsa-v2/sdk-dslink-java-v2)
33

44
* [Documentation](https://github.com/iot-dsa-v2/sdk-dslink-java-v2/wiki)
5-
* [Javadoc](https://jitpack.io/com/github/iot-dsa-v2/sdk-dslink-java-v2/dslink-v2/master-SNAPSHOT/javadoc/)
5+
* [Javadoc](https://jitpack.io/com/github/iot-dsa-v2/sdk-dslink-java-v2/dslink-v2-api/master-SNAPSHOT/javadoc/)
66
* Java 8+
77

88

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.63.0'
8+
version '0.64.0'
99

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected boolean canConnect() {
9494
configOk();
9595
return true;
9696
} catch (Throwable x) {
97-
error(error() ? getPath() : null, x);
97+
debug(debug() ? getPath() : null, x);
9898
configFault(DSException.makeMessage(x));
9999
}
100100
return false;

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public void connDown(String reason) {
9696
put(stateTime, DSDateTime.now());
9797
notifyConnectedDescendants(this, this);
9898
super.connDown(reason);
99+
info("Disconnected");
99100
try {
100101
onDisconnected();
101102
} catch (Exception x) {
@@ -127,6 +128,7 @@ public void connOk() {
127128
put(stateTime, DSDateTime.valueOf(now));
128129
notifyConnectedDescendants(this, this);
129130
super.connOk();
131+
info("Connected");
130132
try {
131133
onConnected();
132134
} catch (Exception x) {
@@ -147,21 +149,18 @@ public void connect() {
147149
debug(debug() ? "Not disconnected, ignoring connect()" : null);
148150
return;
149151
}
152+
if (!isEnabled() || !canConnect()) {
153+
return;
154+
}
150155
debug(debug() ? "Connect" : null);
151156
put(state, DSConnectionState.CONNECTING);
152157
put(stateTime, DSDateTime.now());
153158
notifyConnectedDescendants(this, this);
154-
if (isEnabled() && canConnect()) {
155-
try {
156-
doConnect();
157-
} catch (Throwable e) {
158-
error(error() ? getPath() : null, e);
159-
connDown(DSException.makeMessage(e));
160-
}
161-
} else {
162-
put(state, DSConnectionState.DISCONNECTED);
163-
put(stateTime, DSDateTime.now());
164-
notifyConnectedDescendants(this, this);
159+
try {
160+
doConnect();
161+
} catch (Throwable e) {
162+
error(error() ? getPath() : null, e);
163+
connDown(DSException.makeMessage(e));
165164
}
166165
}
167166

@@ -170,7 +169,9 @@ public void connect() {
170169
* respective callbacks.
171170
*/
172171
public void disconnect() {
173-
debug(debug() ? "Disconnect" : null);
172+
if (getConnectionState().isDisconnected()) {
173+
return;
174+
}
174175
put(state, DSConnectionState.DISCONNECTING);
175176
put(stateTime, DSDateTime.now());
176177
notifyConnectedDescendants(this, this);
@@ -184,6 +185,7 @@ public void disconnect() {
184185
notifyConnectedDescendants(this, this);
185186
down = true;
186187
updateStatus(null);
188+
info("Disconnected");
187189
try {
188190
onDisconnected();
189191
} catch (Exception x) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* All connection based links should use DSConnection or DSBaseConnection (rarely).
3+
*
4+
* @author Aaron Hansen
5+
*/
6+
package org.iot.dsa.conn;
7+

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.iot.dsa.io.DSIReader;
99
import org.iot.dsa.io.NodeDecoder;
1010
import org.iot.dsa.io.json.Json;
11-
import org.iot.dsa.logging.DSLogHandler;
11+
import org.iot.dsa.logging.DSLogger;
1212
import org.iot.dsa.node.DSNode;
1313
import org.iot.dsa.node.DSPath;
1414
import org.iot.dsa.node.DSString;
@@ -115,18 +115,16 @@ public String getPathInBroker(DSNode node) {
115115
* @param config Configuration options
116116
*/
117117
public static DSLink load(DSLinkOptions config) {
118-
Logger logger = Logger.getLogger("");
119118
DSLink ret = null;
120119
File nodes = config.getNodesFile();
121120
if (nodes.exists()) {
122-
logger.info("Loading node database " + nodes.getAbsolutePath());
123121
long time = System.currentTimeMillis();
124122
DSIReader reader = Json.reader(nodes);
125123
ret = (DSLink) NodeDecoder.decode(reader);
126124
reader.close();
127125
ret.init(config);
128126
time = System.currentTimeMillis() - time;
129-
ret.info("Node database loaded: " + time + "ms");
127+
ret.info("Database loaded: " + time + "ms");
130128
} else {
131129
String type = config.getConfig("linkType", null);
132130
if (type == null) {
@@ -135,7 +133,7 @@ public static DSLink load(DSLinkOptions config) {
135133
} else {
136134
ret = (DSLink) DSUtil.newInstance(type);
137135
}
138-
ret.info("Creating new node database...");
136+
ret.debug("Creating new node database...");
139137
ret.init(config);
140138
}
141139
return ret;
@@ -170,27 +168,25 @@ public void run() {
170168
Class clazz = DSLink.class;
171169
try {
172170
URL src = clazz.getProtectionDomain().getCodeSource().getLocation();
173-
info(info() ? src : null);
171+
info(src);
174172
} catch (Throwable t) {
175-
debug("Reporting source of DSLink.class", t);
173+
debug(null, t);
176174
}
177175
Runtime.getRuntime().addShutdownHook(new Thread() {
178176
public void run() {
179-
info("Running shutdown hook");
180177
shutdown();
181178
}
182179
});
183-
info(info() ? "Starting nodes" : null);
184180
start();
185-
long stableDelay = options.getConfig(DSLinkOptions.CFG_STABLE_DELAY, 5000l);
181+
long stableDelay = options.getConfig(DSLinkOptions.CFG_STABLE_DELAY, 2000l);
186182
try {
187183
Thread.sleep(stableDelay);
188184
} catch (Exception x) {
189-
debug("Interrupted stable delay", x);
185+
debug(null, x);
190186
}
191187
try {
192-
info(info() ? "Stabilizing nodes" : null);
193188
stable();
189+
info("Running");
194190
while (isRunning()) {
195191
synchronized (this) {
196192
try {
@@ -257,7 +253,7 @@ protected String getMainName() {
257253
*/
258254
protected DSLink init(DSLinkOptions config) {
259255
this.options = config;
260-
DSLogHandler.setRootLevel(config.getLogLevel());
256+
DSLogger.DSA.setLevel(config.getLogLevel());
261257
name = config.getLinkName();
262258
return this;
263259
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Thread-safe Base64 encoder and decoder. This only exists because we had to be compatible with
99
* Java 6. The one benefit of this is that is can decode url safe and unsafe without prior
1010
* knowledge of the encoding.
11+
*
12+
* @author Aaron Hansen
1113
*/
1214
public class DSBase64 {
1315

@@ -33,7 +35,7 @@ public class DSBase64 {
3335
///////////////////////////////////////////////////////////
3436

3537
/**
36-
* Decodes a base 64 encoded string. Will decodeKeys both url safe and unsafe.
38+
* Decodes a base 64 encoded string. Will decode both url safe and unsafe.
3739
*
3840
* @param str Most not be null.
3941
* @return Never null.

dslink-v2-api/src/main/java/org/iot/dsa/io/package-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
* Node serialization and streaming abstraction for JSON and MsgPack.
2+
* Node serialization and a streaming abstraction for JSON and MsgPack that uses the
3+
* DSElement types.
34
*
45
* @author Aaron Hansen
56
*/

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class DSLogHandler extends Handler {
3232
private StringBuilder builder = new StringBuilder();
3333
private LogHandlerThread logHandlerThread;
3434
private int maxQueueSize = 2500;
35+
3536
///////////////////////////////////////////////////////////////////////////
3637
// Instance Fields
3738
///////////////////////////////////////////////////////////////////////////
@@ -91,6 +92,15 @@ public static Level getRootLevel() {
9192
return Logger.getLogger("").getLevel();
9293
}
9394

95+
/**
96+
* Installs the root handler.
97+
*/
98+
public static void init() {
99+
if (root == null) {
100+
root = Logger.getLogger("");
101+
}
102+
}
103+
94104
/**
95105
* Enqueues the record for the write thread.
96106
*/
@@ -172,11 +182,6 @@ public static void setRootLevel(Level level) {
172182
root = Logger.getLogger("");
173183
}
174184
root.setLevel(level);
175-
/*
176-
for (Handler h : root.getHandlers()) {
177-
h.setLevel(level);
178-
}
179-
*/
180185
}
181186

182187
/**
@@ -387,14 +392,16 @@ record = null;
387392
///////////////////////////////////////////////////////////////////////////
388393

389394
static {
390-
Logger rootLogger = Logger.getLogger("");
391-
rootLevel = rootLogger.getLevel();
392-
for (Handler handler : rootLogger.getHandlers()) {
393-
rootLogger.removeHandler(handler);
395+
if (root == null) {
396+
root = Logger.getLogger("");
397+
}
398+
rootLevel = root.getLevel();
399+
for (Handler handler : root.getHandlers()) {
400+
root.removeHandler(handler);
394401
}
395402
DSLogHandler async = new DSLogHandler();
396403
async.setLevel(rootLevel);
397-
rootLogger.addHandler(async);
404+
root.addHandler(async);
398405
StringWriter sw = new StringWriter();
399406
PrintWriter pw = new PrintWriter(sw);
400407
pw.println();

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class DSLogger {
6060
public static final Level error = Level.SEVERE;
6161
public static final Level off = Level.OFF;
6262

63+
public static final Logger DSA = Logger.getLogger("dsa");
64+
6365
/////////////////////////////////////////////////////////////////
6466
// Instance Fields
6567
/////////////////////////////////////////////////////////////////
@@ -149,6 +151,16 @@ public void error(Supplier<String> msg) {
149151
}
150152
}
151153

154+
/**
155+
* Override point, returns the console logger by default.
156+
*/
157+
public Logger getLogger() {
158+
if (logger == null) {
159+
logger = Logger.getLogger(getLogName());
160+
}
161+
return logger;
162+
}
163+
152164
/**
153165
* True if the level is loggable.
154166
*/
@@ -280,17 +292,7 @@ public void warn(Supplier<String> msg) {
280292
* Override point, returns the simple class name by default.
281293
*/
282294
protected String getLogName() {
283-
return getClass().getSimpleName();
284-
}
285-
286-
/**
287-
* Override point, returns the console logger by default.
288-
*/
289-
protected Logger getLogger() {
290-
if (logger == null) {
291-
logger = Logger.getLogger(getLogName());
292-
}
293-
return logger;
295+
return "dsa";
294296
}
295297

296298
protected void setLogger(Logger logger) {
@@ -308,5 +310,13 @@ private String string(Object obj) {
308310
return obj.toString();
309311
}
310312

313+
/////////////////////////////////////////////////////////////////
314+
// Initialization
315+
/////////////////////////////////////////////////////////////////
316+
317+
static {
318+
DSLogHandler.init();
319+
}
320+
311321

312322
}

0 commit comments

Comments
 (0)