You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by ld...@apache.org on 2020/11/03 21:55:48 UTC

[plc4x] branch issue/PLC4X-252 updated (2fdd248 -> bfe7b16)

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

ldywicki pushed a change to branch issue/PLC4X-252
in repository https://gitbox.apache.org/repos/asf/plc4x.git.


 discard 2fdd248  PLC4X-252 Support passing of PlcField in read/write builders.
     new bfe7b16  PLC4X-252 Support passing of PlcField in subscription builder.

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (2fdd248)
            \
             N -- N -- N   refs/heads/issue/PLC4X-252 (bfe7b16)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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] 01/01: PLC4X-252 Support passing of PlcField in subscription builder.

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

ldywicki pushed a commit to branch issue/PLC4X-252
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit bfe7b16063799c36ecea542522291c55530b1af1
Author: Ɓukasz Dywicki <lu...@code-house.org>
AuthorDate: Thu Oct 22 13:42:36 2020 +0200

    PLC4X-252 Support passing of PlcField in subscription builder.
---
 .../java/api/messages/PlcSubscriptionRequest.java  | 17 ++++++++++
 .../messages/DefaultPlcSubscriptionRequest.java    | 36 +++++++++++++++++-----
 2 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionRequest.java
index 0b53e85..4fe6c25 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionRequest.java
@@ -18,6 +18,8 @@
  */
 package org.apache.plc4x.java.api.messages;
 
+import org.apache.plc4x.java.api.model.PlcField;
+
 import java.time.Duration;
 import java.util.concurrent.CompletableFuture;
 
@@ -42,6 +44,11 @@ public interface PlcSubscriptionRequest extends PlcFieldRequest {
         PlcSubscriptionRequest.Builder addCyclicField(String name, String fieldQuery, Duration pollingInterval);
 
         /**
+         * @see #addCyclicField(String, String, Duration)
+         */
+        PlcSubscriptionRequest.Builder addCyclicField(String name, PlcField fieldQuery, Duration pollingInterval);
+
+        /**
          * Adds a new field to the to be constructed request which should be updated as soon as
          * a value changes in the PLC.
          *
@@ -52,6 +59,11 @@ public interface PlcSubscriptionRequest extends PlcFieldRequest {
         PlcSubscriptionRequest.Builder addChangeOfStateField(String name, String fieldQuery);
 
         /**
+         * @see #addChangeOfStateField(String, String)
+         */
+        PlcSubscriptionRequest.Builder addChangeOfStateField(String name, PlcField fieldQuery);
+
+        /**
          * Adds a new subscription to the to be constructed request which should be updated
          * as soon as an event occurs.
          * <p>
@@ -62,6 +74,11 @@ public interface PlcSubscriptionRequest extends PlcFieldRequest {
          * @return builder.
          */
         PlcSubscriptionRequest.Builder addEventField(String name, String fieldQuery);
+
+        /**
+         * @see #addEventField(String, String)
+         */
+        PlcSubscriptionRequest.Builder addEventField(String name, PlcField fieldQuery);
     }
 
 }
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionRequest.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionRequest.java
index f4ba364..01db7d4 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionRequest.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionRequest.java
@@ -34,6 +34,7 @@ import org.apache.plc4x.java.spi.model.SubscriptionPlcField;
 import java.time.Duration;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
 @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
@@ -131,13 +132,25 @@ public class DefaultPlcSubscriptionRequest implements InternalPlcSubscriptionReq
 
         @Override
         public PlcSubscriptionRequest.Builder addCyclicField(String name, String fieldQuery, Duration pollingInterval) {
-            fields.put(name, new BuilderItem(fieldQuery, PlcSubscriptionType.CYCLIC, pollingInterval));
+            fields.put(name, new BuilderItem(() -> fieldHandler.createField(fieldQuery), PlcSubscriptionType.CYCLIC, pollingInterval));
+            return this;
+        }
+
+        @Override
+        public PlcSubscriptionRequest.Builder addCyclicField(String name, PlcField fieldQuery, Duration pollingInterval) {
+            fields.put(name, new BuilderItem(() -> fieldQuery, PlcSubscriptionType.CYCLIC, pollingInterval));
             return this;
         }
 
         @Override
         public PlcSubscriptionRequest.Builder addChangeOfStateField(String name, String fieldQuery) {
-            fields.put(name, new BuilderItem(fieldQuery, PlcSubscriptionType.CHANGE_OF_STATE));
+            fields.put(name, new BuilderItem(() -> fieldHandler.createField(fieldQuery), PlcSubscriptionType.CHANGE_OF_STATE));
+            return this;
+        }
+
+        @Override
+        public PlcSubscriptionRequest.Builder addChangeOfStateField(String name, PlcField fieldQuery) {
+            fields.put(name, new BuilderItem(() -> fieldQuery, PlcSubscriptionType.CHANGE_OF_STATE));
             return this;
         }
 
@@ -146,7 +159,16 @@ public class DefaultPlcSubscriptionRequest implements InternalPlcSubscriptionReq
             if (fields.containsKey(name)) {
                 throw new PlcRuntimeException("Duplicate field definition '" + name + "'");
             }
-            fields.put(name, new BuilderItem(fieldQuery, PlcSubscriptionType.EVENT));
+            fields.put(name, new BuilderItem(() -> fieldHandler.createField(fieldQuery), PlcSubscriptionType.EVENT));
+            return this;
+        }
+
+        @Override
+        public PlcSubscriptionRequest.Builder addEventField(String name, PlcField fieldQuery) {
+            if (fields.containsKey(name)) {
+                throw new PlcRuntimeException("Duplicate field definition '" + name + "'");
+            }
+            fields.put(name, new BuilderItem(() -> fieldQuery, PlcSubscriptionType.EVENT));
             return this;
         }
 
@@ -155,22 +177,22 @@ public class DefaultPlcSubscriptionRequest implements InternalPlcSubscriptionReq
             LinkedHashMap<String, SubscriptionPlcField> parsedFields = new LinkedHashMap<>();
 
             fields.forEach((name, builderItem) -> {
-                PlcField parsedField = fieldHandler.createField(builderItem.fieldQuery);
+                PlcField parsedField = builderItem.fieldQuery.get();
                 parsedFields.put(name, new SubscriptionPlcField(builderItem.plcSubscriptionType, parsedField, builderItem.duration));
             });
             return new DefaultPlcSubscriptionRequest(subscriber, parsedFields);
         }
 
         private static class BuilderItem {
-            private final String fieldQuery;
+            private final Supplier<PlcField> fieldQuery;
             private final PlcSubscriptionType plcSubscriptionType;
             private final Duration duration;
 
-            private BuilderItem(String fieldQuery, PlcSubscriptionType plcSubscriptionType) {
+            private BuilderItem(Supplier<PlcField> fieldQuery, PlcSubscriptionType plcSubscriptionType) {
                 this(fieldQuery, plcSubscriptionType, null);
             }
 
-            private BuilderItem(String fieldQuery, PlcSubscriptionType plcSubscriptionType, Duration duration) {
+            private BuilderItem(Supplier<PlcField> fieldQuery, PlcSubscriptionType plcSubscriptionType, Duration duration) {
                 this.fieldQuery = fieldQuery;
                 this.plcSubscriptionType = plcSubscriptionType;
                 this.duration = duration;