11package com .acuity .iot .dsa .dslink .protocol ;
22
3+ import org .iot .dsa .dslink .DSLinkConnection ;
34import org .iot .dsa .node .DSInfo ;
45import org .iot .dsa .node .DSString ;
56import org .iot .dsa .node .action .ActionInvocation ;
67import org .iot .dsa .node .action .ActionResult ;
78import org .iot .dsa .node .action .DSAction ;
9+ import org .iot .dsa .util .DSException ;
810
911/**
1012 * Represents an upstream connection to a broker.
1113 *
1214 * @author Aaron Hansen
1315 */
14- public abstract class DSBrokerConnection extends DSTransportConnection {
16+ public abstract class DSBrokerConnection extends DSLinkConnection {
1517
1618 ///////////////////////////////////////////////////////////////////////////
1719 // Class Fields
1820 ///////////////////////////////////////////////////////////////////////////
1921
20- protected static final String BROKER_URI = "Broker URI" ;
22+
23+ protected static final String BROKER_ID = "Broker ID" ;
24+ protected static final String BROKER_FORMAT = "Broker Format" ;
2125 protected static final String BROKER_PATH = "Path In Broker" ;
26+ protected static final String BROKER_PUB_KEY = "Broker Public Key" ;
27+ protected static final String BROKER_SALT = "Broker Salt" ;
28+ protected static final String BROKER_URI = "Broker URI" ;
29+ protected static final String BROKER_VERSION = "Broker Version" ;
2230 protected static final String RECONNECT = "Reconnect" ;
2331
2432 ///////////////////////////////////////////////////////////////////////////
2533 // Instance Fields
2634 ///////////////////////////////////////////////////////////////////////////
2735
36+ private DSInfo brokerDsId = getInfo (BROKER_ID );
37+ private DSInfo brokerFormat = getInfo (BROKER_FORMAT );
2838 private DSInfo brokerPath = getInfo (BROKER_PATH );
39+ private DSInfo brokerPubKey = getInfo (BROKER_PUB_KEY );
40+ private DSInfo brokerSalt = getInfo (BROKER_SALT );
41+ private DSInfo brokerUri = getInfo (BROKER_URI );
42+ private DSInfo brokerVersion = getInfo (BROKER_VERSION );
2943
3044 ///////////////////////////////////////////////////////////////////////////
3145 // Public Methods
@@ -38,15 +52,27 @@ public String getPathInBroker() {
3852 return brokerPath .getElement ().toString ();
3953 }
4054
55+ /**
56+ * For the sessions to update
57+ */
58+ public void setBrokerSalt (String arg ) {
59+ put (brokerSalt , DSString .valueOf (arg ));
60+ }
61+
4162 ///////////////////////////////////////////////////////////////////////////
4263 // Protected Methods
4364 ///////////////////////////////////////////////////////////////////////////
4465
4566 @ Override
4667 protected void declareDefaults () {
4768 super .declareDefaults ();
48- declareDefault (BROKER_URI , DSString .NULL ).setTransient (true ).setReadOnly (true );
69+ declareDefault (BROKER_ID , DSString .NULL ).setTransient (true ).setReadOnly (true );
70+ declareDefault (BROKER_FORMAT , DSString .NULL ).setTransient (true ).setReadOnly (true );
4971 declareDefault (BROKER_PATH , DSString .NULL ).setTransient (true ).setReadOnly (true );
72+ declareDefault (BROKER_PUB_KEY , DSString .NULL ).setTransient (true ).setReadOnly (true );
73+ declareDefault (BROKER_SALT , DSString .NULL ).setTransient (true ).setReadOnly (true );
74+ declareDefault (BROKER_URI , DSString .NULL ).setTransient (true ).setReadOnly (true );
75+ declareDefault (BROKER_VERSION , DSString .NULL ).setTransient (true ).setReadOnly (true );
5076 declareDefault (RECONNECT , new DSAction .Parameterless () {
5177 @ Override
5278 public ActionResult invoke (DSInfo target , ActionInvocation invocation ) {
@@ -56,6 +82,43 @@ public ActionResult invoke(DSInfo target, ActionInvocation invocation) {
5682 });
5783 }
5884
85+ @ Override
86+ protected void doConnect () {
87+ try {
88+ initializeConnection ();
89+ getTransport ().open ();
90+ connOk ();
91+ } catch (Exception x ) {
92+ connDown (DSException .makeMessage (x ));
93+ }
94+ }
95+
96+ protected String getBrokerFormat () {
97+ return brokerFormat .get ().toString ();
98+ }
99+
100+ protected String getBrokerId () {
101+ return brokerDsId .get ().toString ();
102+ }
103+
104+ protected String getBrokerKey () {
105+ return brokerPubKey .get ().toString ();
106+ }
107+
108+ protected String getBrokerSalt () {
109+ return brokerSalt .get ().toString ();
110+ }
111+
112+ protected String getBrokerUri () {
113+ return brokerUri .get ().toString ();
114+ }
115+
116+ protected String getBrokerVersion () {
117+ return brokerVersion .get ().toString ();
118+ }
119+
120+ protected abstract void initializeConnection ();
121+
59122 /**
60123 * Creates and starts a thread for running the connection lifecycle.
61124 */
@@ -67,6 +130,26 @@ protected void onStable() {
67130 t .start ();
68131 }
69132
133+ protected void setBrokerFormat (String arg ) {
134+ put (brokerFormat , DSString .valueOf (arg ));
135+ }
136+
137+ protected void setBrokerId (String arg ) {
138+ put (brokerDsId , DSString .valueOf (arg ));
139+ }
140+
141+ protected void setBrokerKey (String arg ) {
142+ put (brokerPubKey , DSString .valueOf (arg ));
143+ }
144+
145+ protected void setBrokerUri (String arg ) {
146+ put (brokerUri , DSString .valueOf (arg ));
147+ }
148+
149+ protected void setBrokerVersion (String arg ) {
150+ put (brokerVersion , DSString .valueOf (arg ));
151+ }
152+
70153 protected void setPathInBroker (String path ) {
71154 put (brokerPath , DSString .valueOf (path ));
72155 }
0 commit comments