You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/04/19 12:23:53 UTC
[incubator-plc4x] branch master updated: handle connection reset in
ADS protocol
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/master by this push:
new 146265b handle connection reset in ADS protocol
146265b is described below
commit 146265be555e6238095336d82f540246e967c5cc
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Apr 19 14:23:48 2018 +0200
handle connection reset in ADS protocol
---
.../plc4x/java/ads/protocol/Plc4x2AdsProtocol.java | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Plc4x2AdsProtocol.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Plc4x2AdsProtocol.java
index d20b78a..7d7c4fe 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Plc4x2AdsProtocol.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/Plc4x2AdsProtocol.java
@@ -31,6 +31,7 @@ import org.apache.plc4x.java.ads.api.generic.types.AmsPort;
import org.apache.plc4x.java.ads.api.generic.types.Invoke;
import org.apache.plc4x.java.ads.model.AdsAddress;
import org.apache.plc4x.java.api.exceptions.PlcException;
+import org.apache.plc4x.java.api.exceptions.PlcIoException;
import org.apache.plc4x.java.api.exceptions.PlcProtocolException;
import org.apache.plc4x.java.api.messages.*;
import org.apache.plc4x.java.api.messages.items.ReadRequestItem;
@@ -46,6 +47,7 @@ import org.apache.plc4x.java.api.types.ResponseCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@@ -86,6 +88,24 @@ public class Plc4x2AdsProtocol extends MessageToMessageCodec<AmsPacket, PlcReque
}
}
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ if((cause instanceof IOException) && (cause.getMessage().contains("Connection reset by peer") ||
+ cause.getMessage().contains("Operation timed out"))) {
+ String reason = cause.getMessage().contains("Connection reset by peer") ?
+ "Connection terminated unexpectedly" : "Remote host not responding";
+ if (!requests.isEmpty()) {
+ // If the connection is hung up, all still pending requests can be closed.
+ for (PlcRequestContainer requestContainer : requests.values()) {
+ requestContainer.getResponseFuture().completeExceptionally(new PlcIoException(reason));
+ }
+ // Clear the list
+ requests.clear();
+ }
+ } else {
+ super.exceptionCaught(ctx, cause);
+ }
+ }
private void encodeWriteRequest(PlcRequestContainer<PlcRequest, PlcResponse> msg, List<Object> out) throws PlcException {
PlcWriteRequest writeRequest = (PlcWriteRequest) msg.getRequest();
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.