[Minor] Fixed shutdown NPEs

This commit is contained in:
Robert von Burg 2022-05-03 08:52:40 +02:00
parent cacd917e5c
commit a3a67278e5
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
2 changed files with 10 additions and 8 deletions

View File

@ -150,7 +150,8 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
getContainer().getPrivilegeHandler().invalidate(this.ctx.getCertificate());
this.run = false;
this.messageSenderTask.cancel(true);
if (this.messageSenderTask != null)
this.messageSenderTask.cancel(true);
super.stop();
}
@ -275,8 +276,8 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
return;
}
try (StrolchTransaction tx = openTx(validateCtx().getCertificate(), getCallerMethod(), false)
.silentThreshold(SILENT_THRESHOLD, MILLISECONDS)) {
try (StrolchTransaction tx = openTx(validateCtx().getCertificate(), getCallerMethod(), false).silentThreshold(
SILENT_THRESHOLD, MILLISECONDS)) {
tx.lock(Resource.locatorFor(TYPE_PLC_ADDRESS, addressId));
Resource addressRes = tx.getResourceBy(TYPE_PLC_ADDRESS, addressId, true);
@ -305,8 +306,8 @@ public class DefaultPlcHandler extends StrolchComponent implements PlcHandler, P
if (this.verbose)
s = nanoTime();
try (StrolchTransaction tx = openTx(validateCtx().getCertificate(), getCallerMethod(), false)
.silentThreshold(SILENT_THRESHOLD, MILLISECONDS)) {
try (StrolchTransaction tx = openTx(validateCtx().getCertificate(), getCallerMethod(), false).silentThreshold(
SILENT_THRESHOLD, MILLISECONDS)) {
tx.lock(Resource.locatorFor(TYPE_PLC_CONNECTION, plcConnection.getId()));
Resource connection = tx.getResourceBy(TYPE_PLC_CONNECTION, plcConnection.getId());
updateConnectionState(tx, connection, plcConnection);

View File

@ -120,7 +120,8 @@ public class PlcGwClientHandler extends StrolchComponent implements GlobalPlcLis
this.run = false;
this.authenticated = false;
this.messageSenderTask.cancel(false);
if (this.messageSenderTask != null)
this.messageSenderTask.cancel(false);
notifyPlcConnectionState(ConnectionState.Disconnected);
@ -212,8 +213,8 @@ public class PlcGwClientHandler extends StrolchComponent implements GlobalPlcLis
// schedule the heart beat timer
if (this.serverConnectFuture != null)
this.serverConnectFuture.cancel(true);
this.serverConnectFuture = getScheduledExecutor("Server")
.scheduleWithFixedDelay(this::pingServer, PING_DELAY, PING_DELAY, TimeUnit.SECONDS);
this.serverConnectFuture = getScheduledExecutor("Server").scheduleWithFixedDelay(this::pingServer, PING_DELAY,
PING_DELAY, TimeUnit.SECONDS);
}
private void closeBrokenGwSessionUpdateState(String closeReason, String connectionStateMsg) {