1010import org .iot .dsa .util .DSException ;
1111
1212/**
13- * Abstract representation of a connection. Maintains status , provides callbacks to manage
14- * a connection lifecycle and notifies children of state changes.
13+ * Abstract representation of a connection. Maintains state , provides callbacks to manage
14+ * a lifecycle and notifies children of state changes.
1515 * <p>
1616 *
1717 * <b>Running</b>
1818 * The run method manages calling connect, disconnect and ping(). The subclass is responsible
19- * having a thread call this method, or to manage that lifecycle another way.
19+ * having a thread call this method, or to manage lifecycle another way.
2020 * <p>
2121 *
2222 * <b>Pinging</b>
2323 * ping() is only called by the run method. It is only called if the time since the last OK or
2424 * last ping (whichever is later) exceeds the ping interval. Implementations should call connOk
25- * whenever there are successful communications to avoid unnecessarily calling ping .
25+ * whenever there are successful communications to avoid unnecessarily pings .
2626 * <p>
2727 *
2828 * <b>DSIConnected</b>
29- * By default, DSConnection will notify instances of DSIConnected when the connection transitions
30- * to connected and disconnected. Subclasses could choose to notify at other times
29+ * By default, DSConnection will notify subtree instances of DSIConnected when the connection
30+ * transitions to connected and disconnected. Subclasses could choose to notify at other times.
3131 *
3232 * @author Aaron Hansen
3333 */
@@ -38,21 +38,20 @@ public abstract class DSConnection extends DSNode implements DSIStatus {
3838 ///////////////////////////////////////////////////////////////////////////
3939
4040 static final String ENABLED = "Enabled" ;
41- static final String FAIL_CAUSE = "Fail Cause " ;
41+ static final String FAILURE = "Failure " ;
4242 static final String LAST_OK = "Last OK" ;
4343 static final String LAST_FAIL = "Last Fail" ;
44- static final String STATE = "Connection State" ;
44+ static final String STATE = "State" ;
4545 static final String STATUS = "Status" ;
4646
4747 ///////////////////////////////////////////////////////////////////////////
4848 // Instance Fields
4949 ///////////////////////////////////////////////////////////////////////////
5050
5151 private DSInfo enabled = getInfo (ENABLED );
52- private DSInfo failCause = getInfo (FAIL_CAUSE );
52+ private DSInfo failure = getInfo (FAILURE );
5353 private DSInfo lastFail = getInfo (LAST_FAIL );
5454 private DSInfo lastOk = getInfo (LAST_OK );
55- private long lastPing ;
5655 private DSInfo state = getInfo (STATE );
5756 private DSInfo status = getInfo (STATUS );
5857
@@ -152,8 +151,8 @@ public synchronized void run() {
152151 protected void configFault (String msg ) {
153152 put (lastFail , DSDateTime .currentTime ());
154153 if (msg != null ) {
155- if (!failCause .getElement ().toString ().equals (msg )) {
156- put (failCause , DSString .valueOf (msg ));
154+ if (!failure .getElement ().toString ().equals (msg )) {
155+ put (failure , DSString .valueOf (msg ));
157156 }
158157 }
159158 if (!getStatus ().isFault ()) {
@@ -179,8 +178,8 @@ protected void configOk() {
179178 protected void connDown (String reason ) {
180179 put (lastFail , DSDateTime .currentTime ());
181180 if (reason != null ) {
182- if (!failCause .getElement ().toString ().equals (reason )) {
183- put (failCause , DSString .valueOf (reason ));
181+ if (!failure .getElement ().toString ().equals (reason )) {
182+ put (failure , DSString .valueOf (reason ));
184183 }
185184 }
186185 boolean notify = false ;
@@ -244,6 +243,7 @@ protected void connect() {
244243 connDown (DSException .makeMessage (e ));
245244 }
246245 } catch (Throwable x ) {
246+ put (state , DSConnectionState .DISCONNECTED );
247247 error (error () ? getPath () : null , x );
248248 configFault (DSException .makeMessage (x ));
249249 }
@@ -254,7 +254,7 @@ protected void declareDefaults() {
254254 declareDefault (ENABLED , DSBool .TRUE );
255255 declareDefault (STATUS , DSStatus .down ).setReadOnly (true ).setTransient (true );
256256 declareDefault (STATE , DSConnectionState .DISCONNECTED ).setReadOnly (true ).setTransient (true );
257- declareDefault (FAIL_CAUSE , DSString .EMPTY ).setReadOnly (true ).setTransient (true );
257+ declareDefault (FAILURE , DSString .EMPTY ).setReadOnly (true ).setTransient (true );
258258 declareDefault (LAST_OK , DSDateTime .NULL ).setReadOnly (true );
259259 declareDefault (LAST_FAIL , DSDateTime .NULL ).setReadOnly (true );
260260 }
@@ -266,7 +266,7 @@ protected void disconnect() {
266266 if (!getConnectionState ().isConnected ()) {
267267 return ;
268268 }
269- put (state , DSConnectionState .CONNECTING );
269+ put (state , DSConnectionState .DISCONNECTING );
270270 try {
271271 onDisconnect ();
272272 } catch (Throwable x ) {
0 commit comments