@@ -121,33 +121,33 @@ public void onInit(String path, int qos, OutboundStream stream) {
121121 @ Override
122122 public void onUpdate (DSDateTime dateTime , DSElement value , DSStatus status ) {
123123 info ("Rule with sub path " + subPath + ": onUpdate called with value " + (value !=null ? value : "Null" ));
124- storedUpdate = new SubUpdate (dateTime , value , status );
124+ storedUpdate = new SubUpdate (dateTime . toString () , value . toString () , status . toString (), dateTime . timeInMillis () );
125125 if (lastUpdateTime < 0 || System .currentTimeMillis () - lastUpdateTime >= minRefreshRate ) {
126126 if (future != null ) {
127127 future .cancel ();
128128 }
129- trySendUpdate (dateTime , value , status );
129+ trySendUpdate (new SubUpdate ( dateTime . toString () , value . toString () , status . toString (), dateTime . timeInMillis ()) );
130130 }
131131 }
132132
133133 private void sendStoredUpdate () {
134134 if (storedUpdate != null ) {
135- trySendUpdate (storedUpdate . dateTime , storedUpdate . value , storedUpdate . status );
135+ trySendUpdate (storedUpdate );
136136 }
137137 }
138138
139139 private String getSubId () {
140140 return node .getId () + "_" + subPath ;
141141 }
142142
143- private void trySendUpdate (final DSDateTime dateTime , final DSElement value , final DSStatus status ) {
144- if (sendUpdate (dateTime , value , status )) {
143+ private void trySendUpdate (final SubUpdate update ) {
144+ if (sendUpdate (update )) {
145145 if (unsentInBuffer ) {
146146 unsentInBuffer = !Util .processBuffer (getSubId (), this );
147147 }
148148 } else {
149149 if (node .isBufferEnabled ()) {
150- Util .storeInBuffer (getSubId (), new SubUpdate ( dateTime , value , status ) );
150+ Util .storeInBuffer (getSubId (), update );
151151 unsentInBuffer = true ;
152152 }
153153 }
@@ -163,41 +163,42 @@ public void run() {
163163 }
164164 }
165165
166- private boolean sendUpdate (final DSDateTime dateTime , final DSElement value , final DSStatus status ) {
166+ private boolean sendUpdate (final SubUpdate update ) {
167167
168168 DSMap urlParams = urlParameters .copy ();
169169 String body = this .body ;
170170 for (String key : urlParamsWithValues ) {
171171 String pattern = urlParams .getString (key );
172172 if (Constants .PLACEHOLDER_VALUE .equals (pattern )) {
173- urlParams .put (key , value );
173+ urlParams .put (key , update . value );
174174 } else {
175- pattern = pattern .replaceAll (Constants .PLACEHOLDER_VALUE , value . toString () );
176- pattern = pattern .replaceAll (Constants .PLACEHOLDER_TS , dateTime . toString () );
177- pattern = pattern .replaceAll (Constants .PLACEHOLDER_STATUS , status . toString () );
175+ pattern = pattern .replaceAll (Constants .PLACEHOLDER_VALUE , update . value );
176+ pattern = pattern .replaceAll (Constants .PLACEHOLDER_TS , update . dateTime );
177+ pattern = pattern .replaceAll (Constants .PLACEHOLDER_STATUS , update . status );
178178 urlParams .put (key , pattern );
179179 }
180180 }
181181
182182 if (valuesInBody ) {
183- body = body .replaceAll (Constants .PLACEHOLDER_VALUE , value .toString ());
184- body = body .replaceAll (Constants .PLACEHOLDER_TS , dateTime .toString ());
185- body = body .replaceAll (Constants .PLACEHOLDER_STATUS , status .toString ());
183+ body = body .replaceAll (Constants .PLACEHOLDER_VALUE , update .value );
184+ body = body .replaceAll (Constants .PLACEHOLDER_TS , update .dateTime );
185+ body = body .replaceAll (Constants .PLACEHOLDER_STATUS , update .status );
186+ body = body .replaceAll (Constants .PLACEHOLDER_BLOCK_START , "" );
187+ body = body .replaceAll (Constants .PLACEHOLDER_BLOCK_END , "" );
186188 }
187189
188- info ("Rule with sub path " + subPath + ": sending Update with value " + (value !=null ? value : "Null" ));
190+ info ("Rule with sub path " + subPath + ": sending Update with value " + (update . value !=null ? update . value : "Null" ));
189191
190- Response resp = getWebClientProxy ().invoke (method , restUrl , urlParams , body );
191- node .responseRecieved (resp , rowNum );
192- return resp .getStatus () == 200 ;
192+ Response resp = restInvoke (urlParams , body );
193+ return resp != null && resp .getStatus () == 200 ;
193194 }
194195
195196 public Queue <SubUpdate > sendBatchUpdate (Queue <SubUpdate > updates ) {
196197 if (!batchable ) {
197198 Queue <SubUpdate > failed = new LinkedList <SubUpdate >();
198199 while (!updates .isEmpty ()) {
199200 SubUpdate update = updates .poll ();
200- if (!sendUpdate (update . dateTime , update . value , update . status )) {
201+ if (!sendUpdate (update )) {
201202 failed .add (update );
202203 }
203204 }
@@ -215,9 +216,9 @@ public Queue<SubUpdate> sendBatchUpdate(Queue<SubUpdate> updates) {
215216 while (!updates .isEmpty ()) {
216217 SubUpdate update = updates .poll ();
217218 updatesCopy .add (update );
218- String temp = block .replaceAll (Constants .PLACEHOLDER_VALUE , update .value . toString () )
219- .replaceAll (Constants .PLACEHOLDER_TS , update .dateTime . toString () )
220- .replaceAll (Constants .PLACEHOLDER_STATUS , update .status . toString () );
219+ String temp = block .replaceAll (Constants .PLACEHOLDER_VALUE , update .value )
220+ .replaceAll (Constants .PLACEHOLDER_TS , update .dateTime )
221+ .replaceAll (Constants .PLACEHOLDER_STATUS , update .status );
221222 sb .append (temp );
222223 if (!updates .isEmpty ()) {
223224 sb .append (',' );
@@ -227,16 +228,26 @@ public Queue<SubUpdate> sendBatchUpdate(Queue<SubUpdate> updates) {
227228 String body = sb .toString ();
228229 info ("Rule with sub path " + subPath + ": sending batch update" );
229230
230- Response resp = getWebClientProxy ().invoke (method , restUrl , urlParams , body );
231- node .responseRecieved (resp , rowNum );
232- if (resp .getStatus () == 200 ) {
231+ Response resp = restInvoke (urlParams , body );
232+ if (resp != null && resp .getStatus () == 200 ) {
233233 return null ;
234234 } else {
235235 return updatesCopy ;
236236 }
237237
238238 }
239239
240+ private Response restInvoke (DSMap urlParams , String body ) {
241+ Response resp = null ;
242+ try {
243+ resp = getWebClientProxy ().invoke (method , restUrl , urlParams , body );
244+ } catch (Exception e ) {
245+ warn ("" , e );
246+ }
247+ node .responseRecieved (resp , rowNum );
248+ return resp ;
249+ }
250+
240251 public void close () {
241252 if (stream != null && stream .isStreamOpen ()) {
242253 info ("Rule with sub path " + subPath + ": closing Stream" );
0 commit comments