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/06/13 11:23:11 UTC
[incubator-plc4x] 02/03: added a ADSException to correlate ads
messages using the invokeId
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
commit c14ecc167b0be565454cfd21a03763c1ad960ec6
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Jun 13 13:22:00 2018 +0200
added a ADSException to correlate ads messages using the invokeId
---
.../plc4x/java/ads/protocol/Plc4x2AdsProtocol.java | 16 +++++-
.../java/ads/protocol/exception/AdsException.java | 57 ++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
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 7e2c19e..d1485bc 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
@@ -28,6 +28,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.ads.model.SymbolicAdsAddress;
+import org.apache.plc4x.java.ads.protocol.exception.AdsException;
import org.apache.plc4x.java.api.exceptions.PlcException;
import org.apache.plc4x.java.api.exceptions.PlcIoException;
import org.apache.plc4x.java.api.exceptions.PlcProtocolException;
@@ -101,7 +102,20 @@ 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") ||
+ LOGGER.trace("(-->ERR): {}", ctx, cause);
+ if (cause instanceof AdsException) {
+ Invoke invokeId = ((AdsException) cause).getInvokeId();
+ if (invokeId != null) {
+ PlcRequestContainer<PlcRequest, PlcResponse> remove = requests.remove(invokeId.getAsLong());
+ if (remove != null) {
+ remove.getResponseFuture().completeExceptionally(new PlcIoException(cause));
+ } else {
+ LOGGER.warn("Unrelated exception received {}", invokeId, cause);
+ }
+ } else {
+ super.exceptionCaught(ctx, cause);
+ }
+ } else 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";
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/exception/AdsException.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/exception/AdsException.java
new file mode 100644
index 0000000..4d21693
--- /dev/null
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/protocol/exception/AdsException.java
@@ -0,0 +1,57 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.ads.protocol.exception;
+
+import org.apache.plc4x.java.ads.api.generic.types.Invoke;
+import org.apache.plc4x.java.api.exceptions.PlcProtocolException;
+
+public class AdsException extends PlcProtocolException {
+ private final Invoke invokeId;
+
+ public AdsException(Invoke invokeId, String message) {
+ super(message);
+ this.invokeId = invokeId;
+ }
+
+ public AdsException(Invoke invokeId, String message, Throwable cause) {
+ super(message, cause);
+ this.invokeId = invokeId;
+ }
+
+ public AdsException(Invoke invokeId, Throwable cause) {
+ super(cause);
+ this.invokeId = invokeId;
+ }
+
+ public AdsException(Invoke invokeId, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ this.invokeId = invokeId;
+ }
+
+ public Invoke getInvokeId() {
+ return invokeId;
+ }
+
+ @Override
+ public String toString() {
+ return "AdsException{" +
+ "invokeId=" + invokeId +
+ "} " + super.toString();
+ }
+}
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.