Skip to content

Commit c33e858

Browse files
authored
Merge pull request #360 from jacomago/pvaccess-disconnects
slightly nicer disconnects handling
2 parents 38f9ed9 + e794401 commit c33e858

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ dependencies {
134134
testImplementation("org.junit.jupiter:junit-jupiter-api:5.2.0")
135135
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.2.0")
136136
testImplementation('org.awaitility:awaitility:4.2.0')
137-
implementation("org.phoebus:core-pva:5.0.0")
137+
implementation("org.phoebus:core-pva:5.0.2")
138138
runtimeOnly("org.mariadb.jdbc:mariadb-java-client:3.1.4")
139139
}
140140

src/main/org/epics/archiverappliance/engine/pv/EPICS_V4_PV.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)