@@ -134,6 +134,12 @@ private void fireDisconnected() {
134134 listener .pvDisconnected (this );
135135 }
136136 }
137+ /** Notify all listeners. */
138+ private void fireConnected () {
139+ for (final PVListener listener : listeners ) {
140+ listener .pvConnected (this );
141+ }
142+ }
137143
138144 /** Notify all listeners. */
139145 private void fireValueUpdate (DBRTimeEvent ev ) {
@@ -218,21 +224,17 @@ public void getLowLevelChannelInfo(List<Map<String, String>> statuses) {
218224 @ Override
219225 public void channelStateChanged (PVAChannel channel , ClientChannelState clientChannelState ) {
220226
221- logger .info ("channelStateChanged:" + clientChannelState + " " + channel . getName () );
227+ logger .info (channel . getName () + " channelStateChanged: " + clientChannelState );
222228 if (clientChannelState == ClientChannelState .CONNECTED ) {
223229 this .scheduleCommand (this ::handleConnected );
224230 } else if (connected ) {
225- this .scheduleCommand (() -> {
226- state = PVConnectionState .Disconnected ;
227- connected = false ;
228- unsubscribe ();
229- fireDisconnected ();
230- });
231+ this .scheduleCommand (this ::handleDisconnected );
231232 }
232233 }
233234
235+
234236 private void setupDBRType (PVAStructure data ) {
235- logger .info ("Construct the fieldValuesCache for PV " + this .getName ());
237+ logger .debug ("Construct the fieldValuesCache for PV " + this .getName ());
236238 boolean excludeV4Changes = true ;
237239 this .fieldValuesCache = new FieldValuesCache (data , excludeV4Changes );
238240 this .timeStampBits = this .fieldValuesCache .getTimeStampBits ();
@@ -245,18 +247,18 @@ private void setupDBRType(PVAStructure data) {
245247
246248 if (archDBRType == null || con == null ) {
247249 String structureID = data .formatType ();
248- logger .info ("Type from structure in monitorConnect is " + structureID );
250+ logger .debug ("Type from structure in monitorConnect is " + structureID );
249251
250252 PVAData valueField = data .get ("value" );
251253 if (valueField == null ) {
252254 archDBRType = ArchDBRTypes .DBR_V4_GENERIC_BYTES ;
253255 } else {
254- logger .info ("Value field in monitorConnect is of type " + valueField .getType ());
256+ logger .debug ("Value field in monitorConnect is of type " + valueField .getType ());
255257 archDBRType = determineDBRType (structureID , valueField .getType (), valueField .formatType ());
256258 }
257259
258260 con = configservice .getArchiverTypeSystem ().getV4Constructor (archDBRType );
259- logger .info ("Determined ArchDBRTypes for " + this .name + " as " + archDBRType );
261+ logger .debug ("Determined ArchDBRTypes for " + this .name + " as " + archDBRType );
260262 }
261263 }
262264
@@ -288,8 +290,8 @@ public void handleMonitor(PVAChannel channel, BitSet changes, BitSet overruns, P
288290 logger .debug ("handleMonitor: {}" , data );
289291 if (data == null ) {
290292 logger .warn ("Server ends subscription for " + this .name );
291- unsubscribe ( );
292- fireDisconnected () ;
293+ this . scheduleCommand ( this :: handleDisconnected );
294+ return ;
293295 }
294296
295297 state = PVConnectionState .GotMonitor ;
@@ -335,7 +337,7 @@ private void scheduleCommand(final Runnable command) {
335337 }
336338
337339 private void connect () {
338- logger .info ("Connecting to PV " + this .name );
340+ logger .debug ("Connecting to PV " + this .name );
339341 this .scheduleCommand (new Runnable () {
340342 @ Override
341343 public void run () {
@@ -373,13 +375,11 @@ private void handleConnected() {
373375
374376 state = PVConnectionState .Connected ;
375377
376- for (final PVListener listener : listeners ) {
377- listener .pvConnected (this );
378- }
378+ fireConnected ();
379379
380380 if (!running ) {
381- connected = true ;
382381 synchronized (this ) {
382+ connected = true ;
383383 this .notifyAll ();
384384 }
385385 return ;
@@ -406,6 +406,17 @@ private void disconnect() {
406406 fireDisconnected ();
407407 }
408408
409+ private void handleDisconnected () {
410+ if (state == PVConnectionState .Disconnected ) return ;
411+ state = PVConnectionState .Disconnected ;
412+ synchronized (this ) {
413+ connected = false ;
414+ }
415+
416+ unsubscribe ();
417+ fireDisconnected ();
418+ }
419+
409420 /** Subscribe for value updates. */
410421 private void subscribe () {
411422 synchronized (this ) {
0 commit comments