You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2019/11/07 14:02:29 UTC
[plc4x] branch develop updated: [AB-ETH] Improved close() for
AB-ETH and added Logging.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new f9aeafc [AB-ETH] Improved close() for AB-ETH and added Logging.
f9aeafc is described below
commit f9aeafcc846b00222a4832a8bf0d05c5809a3829
Author: julian <j....@pragmaticminds.de>
AuthorDate: Thu Nov 7 14:59:51 2019 +0100
[AB-ETH] Improved close() for AB-ETH and added Logging.
---
.../java/abeth/connection/AbEthPlcConnection.java | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/plc4j/drivers/ab-eth/src/main/java/org/apache/plc4x/java/abeth/connection/AbEthPlcConnection.java b/plc4j/drivers/ab-eth/src/main/java/org/apache/plc4x/java/abeth/connection/AbEthPlcConnection.java
index 8674262..11311c0 100644
--- a/plc4j/drivers/ab-eth/src/main/java/org/apache/plc4x/java/abeth/connection/AbEthPlcConnection.java
+++ b/plc4j/drivers/ab-eth/src/main/java/org/apache/plc4x/java/abeth/connection/AbEthPlcConnection.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.plc4x.java.abeth.model.AbEthField;
import org.apache.plc4x.java.abeth.protocol.AbEthProtocol;
import org.apache.plc4x.java.abeth.protocol.Plc4xAbEthProtocol;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.apache.plc4x.java.api.messages.PlcReadResponse;
@@ -116,6 +117,29 @@ public class AbEthPlcConnection extends NettyPlcConnection implements PlcReader
}
@Override
+ public void close() {
+ logger.debug("Closing PlcConnection...");
+ // Close the channel gracefully
+ if ((channel != null) && channel.isOpen()) {
+ logger.debug("Channel is still connected, Closing channel...");
+ // Close the channel
+ channel.close();
+
+ // Do some additional cleanup operations ...
+ // In normal operation, the channels event loop has a parent, however when running with
+ // the embedded channel for unit tests, parent is null.
+ if (channel.eventLoop().parent() != null) {
+ logger.trace("Shutting down EventLoop gracefully...");
+ channel.eventLoop().parent().shutdownGracefully();
+ logger.trace("Eventloop is shutted down");
+ }
+ }
+ // Dereference
+ channel = null;
+ connected = false;
+ }
+
+ @Override
public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
InternalPlcReadRequest internalReadRequest = checkInternal(readRequest, InternalPlcReadRequest.class);
CompletableFuture<InternalPlcReadResponse> future = new CompletableFuture<>();