You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2021/01/08 11:52:51 UTC

[plc4x] branch feature/native_opua_client updated: Add future for close method. Still working on it.

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

hutcheb pushed a commit to branch feature/native_opua_client
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/feature/native_opua_client by this push:
     new 0361e7e  Add future for close method. Still working on it.
0361e7e is described below

commit 0361e7e8ac223c57ffc34b77c45f2d80bd60a198
Author: hutcheb <be...@gmail.com>
AuthorDate: Fri Jan 8 06:51:42 2021 -0500

    Add future for close method. Still working on it.
---
 .../plc4x/java/opcua/protocol/OpcuaProtocolLogic.java  | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
index db8c5d7..f05e906 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaProtocolLogic.java
@@ -67,6 +67,7 @@ import java.time.Duration;
 import java.math.BigInteger;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
 import java.util.stream.IntStream;
@@ -125,6 +126,11 @@ public class OpcuaProtocolLogic extends Plc4xProtocolBase<OpcuaAPU> implements H
     }
 
     @Override
+    public void onDisconnect(ConversationContext<OpcuaAPU> context) {
+
+    }
+
+    @Override
     public void close(ConversationContext<OpcuaAPU> context) {
         int transactionId = transactionIdentifierGenerator.getAndIncrement();
         if(transactionIdentifierGenerator.get() == 0xFFFF) {
@@ -162,13 +168,22 @@ public class OpcuaProtocolLogic extends Plc4xProtocolBase<OpcuaAPU> implements H
             transactionId,
             closeSessionRequest);
 
+        CompletableFuture<Boolean> voidCompletableFuture = new CompletableFuture<>();
+
         context.sendRequest(new OpcuaAPU(messageRequest))
             .expectResponse(OpcuaAPU.class, REQUEST_TIMEOUT)
             .check(p -> p.getMessage() instanceof OpcuaMessageResponse)
             .unwrap(p -> (OpcuaMessageResponse) p.getMessage())
             .handle(opcuaMessageResponse -> {
-                LOGGER.debug("Got Close Session Response Connection Response");
+                LOGGER.info("Got Close Session Response Connection Response");
+                voidCompletableFuture.complete(true);
             });
+
+        try {
+            voidCompletableFuture.get(REQUEST_TIMEOUT_LONG, TimeUnit.MILLISECONDS);
+        } catch (Exception e) {
+            LOGGER.debug("Timeout while waiting for session to close");
+        }
     }
 
     @Override
@@ -648,6 +663,7 @@ public class OpcuaProtocolLogic extends Plc4xProtocolBase<OpcuaAPU> implements H
 
     @Override
     protected void decode(ConversationContext<OpcuaAPU> context, OpcuaAPU msg) throws Exception {
+        LOGGER.info("Error while reading value from OPC UA server error code 11");
         super.decode(context, msg);
     }