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/08/07 11:06:10 UTC

[plc4x] branch fix-netty-usage updated (7f06579 -> fb4b41c)

This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a change to branch fix-netty-usage
in repository https://gitbox.apache.org/repos/asf/plc4x.git.


    from 7f06579  Fixes some Netty Usages to make PLC4X more robust.
     new 374f958  Slight rework.
     new fb4b41c  Added support for read and write requests.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../plc4x/java/s7/connection/S7PlcConnection.java  | 28 ++++++++++++++--------
 1 file changed, 18 insertions(+), 10 deletions(-)


[plc4x] 02/02: Added support for read and write requests.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch fix-netty-usage
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit fb4b41cd21b0ac28ff97458f98d02f01ab3277de
Author: julian <j....@pragmaticminds.de>
AuthorDate: Wed Aug 7 13:06:00 2019 +0200

    Added support for read and write requests.
---
 .../plc4x/java/s7/connection/S7PlcConnection.java  | 29 ++++++++++++----------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
index 5c63d12..e83d803 100644
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
+++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
@@ -292,17 +292,7 @@ public class S7PlcConnection extends NettyPlcConnection implements PlcReader, Pl
         CompletableFuture<InternalPlcReadResponse> future = new CompletableFuture<>();
         PlcRequestContainer<InternalPlcReadRequest, InternalPlcReadResponse> container =
             new PlcRequestContainer<>(internalReadRequest, future);
-        GenericFutureListener<Future<? super Void>> closeListener = f -> {
-            future.completeExceptionally(new PlcRuntimeException("Connection was unexpectedly closed during read. This is most likely due to a problem in the connection layer."));
-        };
-        channel.closeFuture().addListener(closeListener);
-        channel.writeAndFlush(container).addListener(f -> {
-            if (!f.isSuccess()) {
-                future.completeExceptionally(f.cause());
-            }
-            // Remove the close listener, as it completed
-            channel.closeFuture().removeListener(closeListener);
-        });
+        sendRequest(future, container);
         return future
             .thenApply(PlcReadResponse.class::cast);
     }
@@ -313,13 +303,26 @@ public class S7PlcConnection extends NettyPlcConnection implements PlcReader, Pl
         CompletableFuture<InternalPlcWriteResponse> future = new CompletableFuture<>();
         PlcRequestContainer<InternalPlcWriteRequest, InternalPlcWriteResponse> container =
             new PlcRequestContainer<>(internalWriteRequest, future);
+        sendRequest(future, container);
+        return future
+            .thenApply(PlcWriteResponse.class::cast);
+    }
+
+    /**
+     * Sends the request to the netty channel in a robust manner.
+     */
+    private void sendRequest(CompletableFuture<?> future, PlcRequestContainer<?, ?> container) {
+        GenericFutureListener<Future<? super Void>> closeListener = f -> {
+            future.completeExceptionally(new PlcRuntimeException("Connection was unexpectedly closed during read. This is most likely due to a problem in the connection layer."));
+        };
+        channel.closeFuture().addListener(closeListener);
         channel.writeAndFlush(container).addListener(f -> {
             if (!f.isSuccess()) {
                 future.completeExceptionally(f.cause());
             }
+            // Remove the close listener, as it completed
+            channel.closeFuture().removeListener(closeListener);
         });
-        return future
-            .thenApply(PlcWriteResponse.class::cast);
     }
 
 }


[plc4x] 01/02: Slight rework.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch fix-netty-usage
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 374f958133a054b23e2eaa69ef6e4809bcaf883c
Author: julian <j....@pragmaticminds.de>
AuthorDate: Wed Aug 7 12:59:30 2019 +0200

    Slight rework.
---
 .../org/apache/plc4x/java/s7/connection/S7PlcConnection.java  | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
index 2e56004..5c63d12 100644
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
+++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
@@ -20,6 +20,8 @@ package org.apache.plc4x.java.s7.connection;
 
 import io.netty.buffer.Unpooled;
 import io.netty.channel.*;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GenericFutureListener;
 import org.apache.commons.configuration2.Configuration;
 import org.apache.commons.configuration2.SystemConfiguration;
 import org.apache.commons.lang3.StringUtils;
@@ -290,13 +292,16 @@ public class S7PlcConnection extends NettyPlcConnection implements PlcReader, Pl
         CompletableFuture<InternalPlcReadResponse> future = new CompletableFuture<>();
         PlcRequestContainer<InternalPlcReadRequest, InternalPlcReadResponse> container =
             new PlcRequestContainer<>(internalReadRequest, future);
+        GenericFutureListener<Future<? super Void>> closeListener = f -> {
+            future.completeExceptionally(new PlcRuntimeException("Connection was unexpectedly closed during read. This is most likely due to a problem in the connection layer."));
+        };
+        channel.closeFuture().addListener(closeListener);
         channel.writeAndFlush(container).addListener(f -> {
             if (!f.isSuccess()) {
                 future.completeExceptionally(f.cause());
             }
-        });
-        channel.closeFuture().addListener(f -> {
-            future.completeExceptionally(new PlcRuntimeException("Connection was unexpectedly closed during read. This is most likely due to a problem in the connection layer."));
+            // Remove the close listener, as it completed
+            channel.closeFuture().removeListener(closeListener);
         });
         return future
             .thenApply(PlcReadResponse.class::cast);