You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2023/02/03 15:07:35 UTC

[plc4x] branch develop updated: fix(plc4j/examples): Improve java example (#724)

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

cdutz 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 63b77e10e0 fix(plc4j/examples): Improve java example (#724)
63b77e10e0 is described below

commit 63b77e10e07bcc7bb525f0b3c56ed153411b7bde
Author: Niels Basjes <ni...@basjes.nl>
AuthorDate: Fri Feb 3 16:07:27 2023 +0100

    fix(plc4j/examples): Improve java example (#724)
---
 .../examples/helloplc4x/read/HelloPlc4xRead.java   | 30 ++++++++++------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/plc4j/examples/hello-world-plc4x-read/src/main/java/org/apache/plc4x/java/examples/helloplc4x/read/HelloPlc4xRead.java b/plc4j/examples/hello-world-plc4x-read/src/main/java/org/apache/plc4x/java/examples/helloplc4x/read/HelloPlc4xRead.java
index 922cf3acef..ffee86084b 100644
--- a/plc4j/examples/hello-world-plc4x-read/src/main/java/org/apache/plc4x/java/examples/helloplc4x/read/HelloPlc4xRead.java
+++ b/plc4j/examples/hello-world-plc4x-read/src/main/java/org/apache/plc4x/java/examples/helloplc4x/read/HelloPlc4xRead.java
@@ -26,8 +26,6 @@ import org.apache.plc4x.java.api.types.PlcResponseCode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.concurrent.TimeUnit;
-
 public class HelloPlc4xRead {
 
     private static final Logger logger = LoggerFactory.getLogger(HelloPlc4xRead.class);
@@ -77,21 +75,21 @@ public class HelloPlc4xRead {
             //////////////////////////////////////////////////////////
             // Read asynchronously ...
             // Register a callback executed as soon as a response arrives.
-            /*logger.info("Asynchronous request ...");
-            CompletionStage<? extends PlcReadResponse> asyncResponse = readRequest.execute();
-            asyncResponse.whenComplete((readResponse, throwable) -> {
-                if (readResponse != null) {
-                    printResponse(readResponse);
-                } else {
-                    logger.error("An error occurred: " + throwable.getMessage(), throwable);
-                }
-            });*/
-
-            // Give the async request a little time...
-            TimeUnit.MILLISECONDS.sleep(1000);
-            plcConnection.close();
-            System.exit(0);
+//            logger.info("Asynchronous request ...");
+//            CompletableFuture<? extends PlcReadResponse> asyncResponse = readRequest.execute();
+//            asyncResponse.whenComplete((readResponse, throwable) -> {
+//                if (readResponse != null) {
+//                    printResponse(readResponse);
+//                } else {
+//                    logger.error("An error occurred: " + throwable.getMessage(), throwable);
+//                }
+//              });
+//
+//            // Wait until the async request has finished
+//            asyncResponse.get();
         }
+        // This is needed to avoid a known problem that an application may hang indefinitely.
+        System.exit(0);
     }
 
     private static void printResponse(PlcReadResponse response) {