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 2018/08/28 10:09:29 UTC
[incubator-plc4x] branch feature/api-redesign-chris-c updated: API
Redesign
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/api-redesign-chris-c
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/feature/api-redesign-chris-c by this push:
new 61c9e68 API Redesign
61c9e68 is described below
commit 61c9e689be36599d26fb8e0159fafe81bf6b724b
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Aug 28 12:09:15 2018 +0200
API Redesign
Yes it will break the branches build ... I know that ... currently only the API and the hello-plc4x modules are adjusted to the latest changes
I want to make these changes available to others to allow discussing them ...
---
examples/hello-plc4x/pom.xml | 112 ++++++++++++++++
.../plc4x/java/examples/helloplc4x/HelloPlc4x.java | 100 ++++++++++++++
.../hello-plc4x/src/main/resources/logback.xml | 36 +++++
examples/pom.xml | 3 +-
.../java/api/connection/PlcProprietarySender.java | 41 ------
.../plc4x/java/api/connection/PlcReader.java | 19 +--
.../plc4x/java/api/connection/PlcSubscriber.java | 4 +
.../plc4x/java/api/connection/PlcWriter.java | 18 +--
...nRequestEventItem.java => PlcFieldRequest.java} | 22 +--
...hangeOfStateItem.java => PlcFieldResponse.java} | 28 ++--
...ProtocolMessage.java => PlcMessageBuilder.java} | 7 +-
.../java/api/messages/PlcProprietaryRequest.java | 78 -----------
.../java/api/messages/PlcProprietaryResponse.java | 77 -----------
.../java/api/messages/PlcProtocolMessage.java | 3 +-
.../plc4x/java/api/messages/PlcReadRequest.java | 97 +-------------
.../plc4x/java/api/messages/PlcReadResponse.java | 83 ++++++++----
.../apache/plc4x/java/api/messages/PlcRequest.java | 101 +-------------
.../plc4x/java/api/messages/PlcResponse.java | 87 +-----------
.../java/api/messages/PlcSubscriptionEvent.java | 42 +-----
.../java/api/messages/PlcSubscriptionRequest.java | 59 +--------
.../java/api/messages/PlcSubscriptionResponse.java | 17 +--
.../api/messages/PlcUnsubscriptionRequest.java | 147 +++++----------------
.../api/messages/PlcUnsubscriptionResponse.java | 18 ++-
.../plc4x/java/api/messages/PlcWriteRequest.java | 100 ++++----------
.../plc4x/java/api/messages/PlcWriteResponse.java | 26 +---
.../api/messages/items/PlcReadRequestItem.java | 82 ------------
.../api/messages/items/PlcReadResponseItem.java | 84 ------------
.../api/messages/items/PlcWriteRequestItem.java | 73 ----------
.../api/messages/items/PlcWriteResponseItem.java | 33 -----
.../plc4x/java/api/messages/items/RequestItem.java | 78 -----------
.../java/api/messages/items/ResponseItem.java | 72 ----------
.../api/messages/items/SubscriptionEventItem.java | 76 -----------
.../items/SubscriptionRequestCyclicItem.java | 75 -----------
.../messages/items/SubscriptionRequestItem.java | 74 -----------
.../messages/items/SubscriptionResponseItem.java | 65 ---------
.../messages/items/UnsubscriptionRequestItem.java | 62 ---------
.../messages/specific/TypeSafePlcReadRequest.java | 127 ------------------
.../messages/specific/TypeSafePlcReadResponse.java | 107 ---------------
.../messages/specific/TypeSafePlcWriteRequest.java | 114 ----------------
.../specific/TypeSafePlcWriteResponse.java | 83 ------------
.../plc4x/java/api/types/PlcResponseCode.java | 3 +-
.../api/{model => types}/PlcSubscriptionType.java | 2 +-
.../ads/connection/AdsAbstractPlcConnection.java | 1 -
.../apache/plc4x/java/ads/adslib/AmsRequest.java | 1 -
.../apache/plc4x/java/ads/adslib/AmsRouter.java | 2 -
.../ads/connection/AdsTcpPlcConnectionTests.java | 2 -
46 files changed, 439 insertions(+), 2102 deletions(-)
diff --git a/examples/hello-plc4x/pom.xml b/examples/hello-plc4x/pom.xml
new file mode 100644
index 0000000..96d66b6
--- /dev/null
+++ b/examples/hello-plc4x/pom.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.plc4x.examples</groupId>
+ <artifactId>examples</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>hello-plc4x</artifactId>
+ <name>Examples: Hello PLC4X</name>
+ <description>Hello world application for PLC4X.</description>
+
+ <properties>
+ <app.main.class>org.apache.plc4x.java.examples.helloplc4x.HelloPlc4x</app.main.class>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>apache-edgent</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.edgent</groupId>
+ <artifactId>edgent-api-function</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.edgent</groupId>
+ <artifactId>edgent-api-topology</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.edgent</groupId>
+ <artifactId>edgent-providers-direct</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+
+ <!-- Elasticsearch dependencies -->
+ <dependency>
+ <groupId>org.elasticsearch</groupId>
+ <artifactId>elasticsearch</artifactId>
+ <version>6.2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.elasticsearch.plugin</groupId>
+ <artifactId>transport-netty4-client</artifactId>
+ <version>6.2.4</version>
+ </dependency>
+
+ <!-- Required driver implementation -->
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-protocol-s7</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>log4j-over-slf4j</artifactId>
+ <version>1.7.25</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <configuration>
+ <usedDependencies>
+ <usedDependency>org.apache.plc4x:plc4j-protocol-s7</usedDependency>
+ <usedDependency>org.slf4j:log4j-over-slf4j</usedDependency>
+ </usedDependencies>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/examples/hello-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloPlc4x.java b/examples/hello-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloPlc4x.java
new file mode 100644
index 0000000..1d015b3
--- /dev/null
+++ b/examples/hello-plc4x/src/main/java/org/apache/plc4x/java/examples/helloplc4x/HelloPlc4x.java
@@ -0,0 +1,100 @@
+/*
+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.examples.helloplc4x;
+
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.connection.PlcConnection;
+import org.apache.plc4x.java.api.connection.PlcReader;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
+public class HelloPlc4x {
+
+ private static final Logger logger = LoggerFactory.getLogger(HelloPlc4x.class);
+
+ /**
+ * Example code do demonstrate using PLC4X.
+ *
+ * @param args ignored.
+ */
+ @SuppressWarnings("unchecked")
+ public static void main(String[] args) {
+ if(args.length < 2) {
+ System.out.println("Usage: HelloPlc4x {connection-string} {address-string}+");
+ System.out.println("Example: HelloPlc4x s7://10.10.64.30/1/1 %I0.0:BOOLEAN %DB1.DBX38:BYTE");
+ return;
+ }
+
+ // Establish a connection to the plc using the url provided as first argument
+ try (PlcConnection plcConnection = new PlcDriverManager().getConnection(args[0])) {
+
+ Optional<PlcReader> reader = plcConnection.getReader();
+
+ // Check if this connection support reading of data.
+ if (reader.isPresent()) {
+ PlcReader plcReader = reader.get();
+
+ // Create a new read request:
+ // - Give the single item requested the alias name "value"
+ PlcReadRequest.Builder builder = plcReader.readRequestBuilder();
+ for(int i = 1; i < args.length; i++) {
+ builder.addItem("value-" + i, args[i]);
+ }
+ PlcReadRequest plcReadRequest = builder.build();
+
+ //////////////////////////////////////////////////////////
+ // Read synchronously ...
+ // NOTICE: the ".get()" immediately lets this thread pause till
+ // the response is processed and available.
+ PlcReadResponse syncResponse = plcReader.read(plcReadRequest).get();
+ // Simply iterating over the field names returned in the response.
+ for (String fieldName : syncResponse.getFieldNames()) {
+ System.out.println("Value[" + fieldName + "]: " + syncResponse.getObject(fieldName));
+ }
+
+ //////////////////////////////////////////////////////////
+ // Read asynchronously ...
+ // Register a callback executed as soon as a response arives.
+ CompletableFuture<PlcReadResponse> asyncResponse = plcReader.read(plcReadRequest);
+ asyncResponse.whenComplete((readResponse, throwable) -> {
+ if(readResponse != null) {
+ // Directly asking for fields by name.
+ for(int i = 1; i < args.length; i++) {
+ System.out.println("Value[value-" + i + "]: " + syncResponse.getObject("value-" + i));
+ }
+ } else {
+ logger.error("An error occurred", throwable);
+ }
+ });
+ } else {
+ logger.info("This connection doesn't support reading.");
+ }
+ }
+ // Catch any exception or the application won't be able to finish if something goes wrong.
+ catch (Exception e) {
+ logger.error("An error occurred", e);
+ }
+ }
+
+}
diff --git a/examples/hello-plc4x/src/main/resources/logback.xml b/examples/hello-plc4x/src/main/resources/logback.xml
new file mode 100644
index 0000000..27d40c0
--- /dev/null
+++ b/examples/hello-plc4x/src/main/resources/logback.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<configuration xmlns="http://ch.qos.logback/xml/ns/logback"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://ch.qos.logback/xml/ns/logback https://raw.githubusercontent.com/enricopulatzo/logback-XSD/master/src/main/xsd/logback.xsd">
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+</configuration>
\ No newline at end of file
diff --git a/examples/pom.xml b/examples/pom.xml
index 5e63794..e0185ca 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -36,12 +36,13 @@
<description>Parent of all application example modules.</description>
<modules>
+ <module>azure</module>
<module>dummy-driver</module>
+ <module>hello-plc4x</module>
<module>iot-factory</module>
<module>iotree</module>
<module>kafka-bridge</module>
<module>plclogger</module>
- <module>azure</module>
</modules>
<dependencyManagement>
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcProprietarySender.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcProprietarySender.java
deleted file mode 100644
index b24493e..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcProprietarySender.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- 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.api.connection;
-
-import org.apache.plc4x.java.api.messages.PlcProprietaryRequest;
-import org.apache.plc4x.java.api.messages.PlcProprietaryResponse;
-
-import java.util.concurrent.CompletableFuture;
-
-/**
- * Interface implemented by all PlcConnections that are able to send custom commands to resources.
- */
-@FunctionalInterface
-public interface PlcProprietarySender {
-
- /**
- * Sends a given custom request to a PLC.
- *
- * @param request request to be send.
- * @param <T> the request type
- * @param <R> the response type
- * @return a {@link CompletableFuture} giving async access to the response of the send operation.
- */
- <T, R> CompletableFuture<PlcProprietaryResponse<R>> send(PlcProprietaryRequest<T> request);
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcReader.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcReader.java
index b8b1b8c..0c5373a 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcReader.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcReader.java
@@ -20,16 +20,12 @@ package org.apache.plc4x.java.api.connection;
import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.apache.plc4x.java.api.messages.PlcReadResponse;
-import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadRequest;
-import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadResponse;
-import java.util.Objects;
import java.util.concurrent.CompletableFuture;
/**
* Interface implemented by all PlcConnections that are able to read from remote resources.
*/
-@FunctionalInterface
public interface PlcReader {
/**
@@ -38,19 +34,8 @@ public interface PlcReader {
* @param readRequest object describing the type and location of the value.
* @return a {@link CompletableFuture} giving async access to the returned value.
*/
- CompletableFuture<? extends PlcReadResponse> read(PlcReadRequest readRequest);
+ CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest);
- /**
- * Reads a requested value from a PLC.
- *
- * @param readRequest object describing the type and location of the value.
- * @param <T> type that is being requested.
- * @return a {@link CompletableFuture} giving async access to the returned value.
- */
- default <T> CompletableFuture<TypeSafePlcReadResponse<T>> read(TypeSafePlcReadRequest<T> readRequest) {
- Objects.requireNonNull(readRequest, "Read request must not be null");
- return read((PlcReadRequest) readRequest)
- .thenApply(readResponse -> TypeSafePlcReadResponse.of(readResponse, readRequest.getDataType()));
- }
+ PlcReadRequest.Builder readRequestBuilder();
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcSubscriber.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcSubscriber.java
index 656a83e..a46126d 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcSubscriber.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcSubscriber.java
@@ -44,4 +44,8 @@ public interface PlcSubscriber {
*/
CompletableFuture<PlcUnsubscriptionResponse> unsubscribe(PlcUnsubscriptionRequest unsubscriptionRequest);
+ PlcMessageBuilder<PlcSubscriptionRequest> subsciptionRequestBuilder();
+
+ PlcMessageBuilder<PlcUnsubscriptionRequest> unsubsciptionRequestBuilder();
+
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcWriter.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcWriter.java
index 3307d51..df31bdd 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcWriter.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/connection/PlcWriter.java
@@ -18,19 +18,15 @@ under the License.
*/
package org.apache.plc4x.java.api.connection;
-
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.apache.plc4x.java.api.messages.PlcWriteRequest;
import org.apache.plc4x.java.api.messages.PlcWriteResponse;
-import org.apache.plc4x.java.api.messages.specific.TypeSafePlcWriteRequest;
-import org.apache.plc4x.java.api.messages.specific.TypeSafePlcWriteResponse;
-import java.util.Objects;
import java.util.concurrent.CompletableFuture;
/**
* Interface implemented by all PlcConnections that are able to write to remote resources.
*/
-@FunctionalInterface
public interface PlcWriter {
/**
@@ -41,16 +37,6 @@ public interface PlcWriter {
*/
CompletableFuture<? extends PlcWriteResponse> write(PlcWriteRequest writeRequest);
- /**
- * Writes a given value to a PLC.
- *
- * @param writeRequest object describing the type, location and value that whould be written.
- * @param <T> type that is being requested.
- * @return a {@link CompletableFuture} giving async access to the response of the write operation.
- */
- default <T> CompletableFuture<TypeSafePlcWriteResponse<T>> write(TypeSafePlcWriteRequest<T> writeRequest) {
- Objects.requireNonNull(writeRequest, "write request must not be null");
- return write((PlcWriteRequest) writeRequest).thenApply(TypeSafePlcWriteResponse::of);
- }
+ PlcReadRequest.Builder writeRequestBuilder();
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestEventItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldRequest.java
similarity index 59%
rename from plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestEventItem.java
rename to plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldRequest.java
index e9278bc..f9bd49b 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestEventItem.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldRequest.java
@@ -16,21 +16,21 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-package org.apache.plc4x.java.api.messages.items;
+package org.apache.plc4x.java.api.messages;
import org.apache.plc4x.java.api.model.PlcField;
-import org.apache.plc4x.java.api.model.PlcSubscriptionType;
-import java.util.function.Consumer;
+import java.util.Collection;
+import java.util.Map;
+
+public interface PlcFieldRequest extends PlcRequest {
+
+ Map<String, PlcField> getFields();
+
+ Collection<String> getFieldNames();
+
+ PlcField getField(String name);
-public class SubscriptionRequestEventItem<T> extends SubscriptionRequestItem<T> {
- public SubscriptionRequestEventItem(Class<T> dataType, PlcField field, Consumer<SubscriptionEventItem<T>> consumer) {
- super(dataType, field, PlcSubscriptionType.EVENT, consumer);
- }
- @Override
- public String toString() {
- return "SubscriptionRequestEventItem{} " + super.toString();
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestChangeOfStateItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldResponse.java
similarity index 58%
rename from plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestChangeOfStateItem.java
rename to plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldResponse.java
index 7cd9050..27d56ab 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestChangeOfStateItem.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcFieldResponse.java
@@ -16,21 +16,27 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-package org.apache.plc4x.java.api.messages.items;
+package org.apache.plc4x.java.api.messages;
import org.apache.plc4x.java.api.model.PlcField;
-import org.apache.plc4x.java.api.model.PlcSubscriptionType;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
-import java.util.function.Consumer;
+import java.util.Collection;
+import java.util.Map;
-public class SubscriptionRequestChangeOfStateItem<T> extends SubscriptionRequestItem<T> {
+/**
+ * Base type for all response messages sent as response for a prior request
+ * from a plc to the plc4x system.
+ * @param <REQUEST_TYPE>
+ */
+public interface PlcFieldResponse<REQUEST_TYPE extends PlcFieldRequest> extends PlcResponse<REQUEST_TYPE> {
- public SubscriptionRequestChangeOfStateItem(Class<T> datatype, PlcField field, Consumer<SubscriptionEventItem<T>> consumer) {
- super(datatype, field, PlcSubscriptionType.CHANGE_OF_STATE, consumer);
- }
+ Map<String, PlcField> getFields();
+
+ Collection<String> getFieldNames();
+
+ PlcField getField(String name);
+
+ PlcResponseCode getResponseCode(String name);
- @Override
- public String toString() {
- return "SubscriptionRequestChangeOfStateItem{} " + super.toString();
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProtocolMessage.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcMessageBuilder.java
similarity index 86%
copy from plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProtocolMessage.java
copy to plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcMessageBuilder.java
index b6f51ac..fd2d20e 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProtocolMessage.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcMessageBuilder.java
@@ -1,4 +1,4 @@
-package org.apache.plc4x.java.api.messages;/*
+/*
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
@@ -16,9 +16,10 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
+package org.apache.plc4x.java.api.messages;
-public interface PlcProtocolMessage {
+public interface PlcMessageBuilder<T> {
- PlcProtocolMessage getParent();
+ T build();
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProprietaryRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProprietaryRequest.java
deleted file mode 100644
index 28f172f..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProprietaryRequest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- 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.api.messages;
-
-import org.apache.plc4x.java.api.messages.items.RequestItem;
-import org.apache.plc4x.java.api.model.PlcField;
-
-import java.util.Objects;
-
-/**
- * This request can be used to pass proprietary protocol specific messages to the underlying layers.
- *
- * @param <CUSTOM_REQUEST> request
- */
-public class PlcProprietaryRequest<CUSTOM_REQUEST> extends PlcRequest<PlcProprietaryRequest.DummyRequestItem> {
-
- private final CUSTOM_REQUEST request;
-
- public PlcProprietaryRequest(CUSTOM_REQUEST request) {
- this.request = request;
- }
-
- public CUSTOM_REQUEST getRequest() {
- return request;
- }
-
- protected static class DummyRequestItem extends RequestItem<Void> {
-
- public DummyRequestItem() {
- super(Void.class, new PlcField() {
- });
- }
- }
-
- @Override
- public String toString() {
- return "PlcProprietaryRequest{" +
- "request=" + request +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PlcProprietaryRequest)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- PlcProprietaryRequest<?> that = (PlcProprietaryRequest<?>) o;
- return Objects.equals(request, that.request);
- }
-
- @Override
- public int hashCode() {
-
- return Objects.hash(super.hashCode(), request);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProprietaryResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProprietaryResponse.java
deleted file mode 100644
index 08bb6b1..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProprietaryResponse.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- 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.api.messages;
-
-import org.apache.plc4x.java.api.messages.items.ResponseItem;
-import org.apache.plc4x.java.api.types.PlcResponseCode;
-
-import java.util.Collections;
-import java.util.Objects;
-
-/**
- * This response can be used to pass proprietary protocol specific messages from the underlying layers.
- */
-public class PlcProprietaryResponse<CUSTOM_RESPONSE> extends PlcResponse<PlcProprietaryRequest, PlcProprietaryResponse.DummyResponseItem, PlcProprietaryRequest.DummyRequestItem> {
-
- private final CUSTOM_RESPONSE response;
-
- public PlcProprietaryResponse(PlcProprietaryRequest request, CUSTOM_RESPONSE response) {
- super(request, Collections.emptyList());
- this.response = response;
- }
-
- public CUSTOM_RESPONSE getResponse() {
- return response;
- }
-
- protected static class DummyResponseItem extends ResponseItem<PlcProprietaryRequest.DummyRequestItem> {
-
- public DummyResponseItem() {
- super(new PlcProprietaryRequest.DummyRequestItem(), PlcResponseCode.OK);
- }
- }
-
- @Override
- public String toString() {
- return "PlcProprietaryResponse{" +
- "response=" + response +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PlcProprietaryResponse)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- PlcProprietaryResponse<?> that = (PlcProprietaryResponse<?>) o;
- return Objects.equals(response, that.response);
- }
-
- @Override
- public int hashCode() {
-
- return Objects.hash(super.hashCode(), response);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProtocolMessage.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProtocolMessage.java
index b6f51ac..4c428d5 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProtocolMessage.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcProtocolMessage.java
@@ -1,4 +1,4 @@
-package org.apache.plc4x.java.api.messages;/*
+/*
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
@@ -16,6 +16,7 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
+package org.apache.plc4x.java.api.messages;
public interface PlcProtocolMessage {
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
index d0de9e5..af9d29d 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadRequest.java
@@ -18,105 +18,16 @@ under the License.
*/
package org.apache.plc4x.java.api.messages;
-import org.apache.plc4x.java.api.messages.items.PlcReadRequestItem;
-import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadRequest;
-import org.apache.plc4x.java.api.model.PlcField;
-
-import java.util.List;
-import java.util.Objects;
-
/**
* Request to read one or more values from a plc.
- * The {@link PlcReadRequest} is a container for one or more {@link PlcReadRequestItem}s that are contained.
- * <p>
- * By default this is NOT typesafe as it can contain {@link PlcReadRequestItem}s for different types.
- * If there are only {@link PlcReadRequestItem}s of the same type one can use the {@link TypeSafePlcReadRequest} to enforce
- * type safety.
- * <p>
- * Provides a builder for object construction through {@link PlcReadRequest#builder()}.
- *
- * @see TypeSafePlcReadRequest
*/
-public class PlcReadRequest extends PlcRequest<PlcReadRequestItem<?>> {
-
- public PlcReadRequest() {
- // Exists for construction of inherited classes
- }
-
- public PlcReadRequest(PlcReadRequestItem<?> requestItem) {
- addItem(requestItem);
- }
-
- public PlcReadRequest(Class<?> dataType, PlcField field) {
- addItem(new PlcReadRequestItem<>(dataType, field));
- }
-
- public PlcReadRequest(Class<?> dataType, PlcField field, int size) {
- Objects.requireNonNull(dataType, "Data type must not be null");
- Objects.requireNonNull(field, "PlcField must not be null");
- addItem(new PlcReadRequestItem<>(dataType, field, size));
- }
+public interface PlcReadRequest extends PlcFieldRequest {
- public PlcReadRequest(List<PlcReadRequestItem<?>> requestItems) {
- super(requestItems);
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder extends PlcRequest.Builder<PlcReadRequestItem<?>> {
-
- public final Builder addItem(Class<?> dataType, PlcField field) {
- checkType(dataType);
- requests.add(new PlcReadRequestItem<>(dataType, field));
- return this;
- }
-
- public final Builder addItem(Class<?> dataType, PlcField field, int size) {
- checkType(dataType);
- requests.add(new PlcReadRequestItem<>(dataType, field, size));
- return this;
- }
-
- public final Builder addItem(PlcReadRequestItem readRequestItem) {
- checkType(readRequestItem.getDatatype());
- requests.add(readRequestItem);
- return this;
- }
-
- public final PlcReadRequest build() {
- if (requests.isEmpty()) {
- throw new IllegalStateException("No requests added");
- }
- PlcReadRequest plcReadRequest;
- if (mixed) {
- plcReadRequest = new PlcReadRequest();
- } else {
- plcReadRequest = new TypeSafePlcReadRequest<>(firstType);
- }
- for (PlcReadRequestItem request : requests) {
- plcReadRequest.addItem(request);
- }
- return plcReadRequest;
- }
-
- @SuppressWarnings("unchecked")
- public final <T> TypeSafePlcReadRequest<T> build(Class<T> type) {
- if (firstType != type) {
- throw new ClassCastException("Incompatible type " + type + ". Required " + firstType);
- }
- if (mixed) {
- throw new IllegalStateException("Mixed types contained");
- }
- return (TypeSafePlcReadRequest<T>) build();
- }
+ PlcMessageBuilder<PlcReadRequest> builder();
+ interface Builder extends PlcMessageBuilder<PlcReadRequest> {
+ Builder addItem(String name, String fieldQuery);
}
- @Override
- public String toString() {
- return "PlcReadRequest{} " + super.toString();
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
index d769c0f..5bcd731 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcReadResponse.java
@@ -18,40 +18,67 @@ under the License.
*/
package org.apache.plc4x.java.api.messages;
-import org.apache.plc4x.java.api.messages.items.PlcReadRequestItem;
-import org.apache.plc4x.java.api.messages.items.PlcReadResponseItem;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
/**
* Response to a {@link PlcReadRequest}.
- * Contains the values read from the PLC but untyped.
- * <p>
- * Values are extracted using the {@link PlcReadRequestItem}s that were send in the read request.
- * <p>
- * If only a variables of one type are requested it is better to use
- * {@link org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadRequest} which leads to a
- * {@link org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadResponse}.
*/
-public class PlcReadResponse extends PlcResponse<PlcReadRequest, PlcReadResponseItem<?>, PlcReadRequestItem<?>> {
+public interface PlcReadResponse extends PlcFieldResponse<PlcReadRequest> {
+
+ int getNumValues(String name);
+
+ boolean isRaw(String name);
+ byte[] getRaw(String name);
+ byte[] getRaw(String name, int index);
+
+ boolean isObject(String name);
+ Object getObject(String name);
+ Object getObject(String name, int index);
+
+ boolean isBoolean(String name);
+ Boolean getBoolean(String name);
+ Boolean getBoolean(String name, int index);
+
+ boolean isByte(String name);
+ Byte getByte(String name);
+ Byte getByte(String name, int index);
+
+ boolean isShort(String name);
+ Short getShort(String name);
+ Short getShort(String name, int index);
+
+ boolean isInteger(String name);
+ Integer getInteger(String name);
+ Integer getInteger(String name, int index);
+
+ boolean isLong(String name);
+ Long getLong(String name);
+ Long getLong(String name, int index);
+
+ boolean isFloat(String name);
+ Float getFloat(String name);
+ Float getFloat(String name, int index);
+
+ boolean isDouble(String name);
+ Double getDouble(String name);
+ Double getDouble(String name, int index);
+
+ boolean isString(String name);
+ String getString(String name);
+ String getString(String name, int index);
- public PlcReadResponse(PlcReadRequest request, PlcReadResponseItem<?> responseItems) {
- super(request, Collections.singletonList(responseItems));
- }
+ boolean isTime(String name);
+ LocalTime getTime(String name);
+ LocalTime getTime(String name, int index);
- public PlcReadResponse(PlcReadRequest request, List<? extends PlcReadResponseItem<?>> responseItems) {
- super(request, responseItems);
- }
+ boolean isDate(String name);
+ LocalDate getDate(String name);
+ LocalDate getDate(String name, int index);
- @SuppressWarnings("unchecked")
- public <T> Optional<PlcReadResponseItem<T>> getValue(PlcReadRequestItem<T> item) {
- return (Optional) super.getValue(item);
- }
+ boolean isDateTime(String name);
+ LocalDateTime getDateTime(String name);
+ LocalDateTime getDateTime(String name, int index);
- @Override
- public String toString() {
- return "PlcReadResponse{} " + super.toString();
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java
index b2d3f4f..f2367f9 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcRequest.java
@@ -18,108 +18,9 @@ under the License.
*/
package org.apache.plc4x.java.api.messages;
-import org.apache.plc4x.java.api.messages.items.RequestItem;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-
/**
* Base type for all messages sent from the plc4x system to a connected plc.
- * @param <REQUEST_ITEM>
*/
-public abstract class PlcRequest<REQUEST_ITEM extends RequestItem> implements PlcMessage {
-
- protected final List<REQUEST_ITEM> requestItems;
-
- public PlcRequest() {
- this.requestItems = new LinkedList<>();
- }
-
- public PlcRequest(List<REQUEST_ITEM> requestItems) {
- Objects.requireNonNull(requestItems, "Request items must not be null");
- this.requestItems = requestItems;
- }
-
- public void addItem(REQUEST_ITEM requestItem) {
- Objects.requireNonNull(requestItem, "Request item must not be null");
- getRequestItems().add(requestItem);
- }
-
- public List<REQUEST_ITEM> getRequestItems() {
- return requestItems;
- }
-
- public Optional<? extends REQUEST_ITEM> getRequestItem() {
- if (isMultiValue()) {
- throw new IllegalStateException("Too many items " + getNumberOfItems());
- }
- if (isEmpty()) {
- return Optional.empty();
- }
- return Optional.of(getRequestItems().get(0));
- }
-
- public void setRequestItem(REQUEST_ITEM requestItem) {
- if (isMultiValue()) {
- throw new IllegalStateException("Too many items " + getNumberOfItems());
- }
- addItem(requestItem);
- }
-
- public int getNumberOfItems() {
- return getRequestItems().size();
- }
-
- public boolean isMultiValue() {
- return getNumberOfItems() > 1;
- }
-
- public boolean isEmpty() {
- return getNumberOfItems() < 1;
- }
-
- public abstract static class Builder<REQUEST_ITEM> {
-
- Class<?> firstType;
-
- boolean mixed = false;
-
- List<REQUEST_ITEM> requests = new LinkedList<>();
-
- void checkType(Class dataType) {
- if (firstType == null) {
- firstType = dataType;
- }
- if (firstType != dataType) {
- mixed = true;
- }
- }
- }
-
- @Override
- public String toString() {
- return "PlcRequest{" +
- "eventItems=" + requestItems +
- '}';
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PlcRequest)) {
- return false;
- }
- PlcRequest<?> that = (PlcRequest<?>) o;
- return Objects.equals(requestItems, that.requestItems);
- }
-
- @Override
- public int hashCode() {
+public interface PlcRequest extends PlcMessage {
- return Objects.hash(requestItems);
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcResponse.java
index 575ca7b..ea64e47 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcResponse.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcResponse.java
@@ -18,94 +18,13 @@ under the License.
*/
package org.apache.plc4x.java.api.messages;
-import org.apache.plc4x.java.api.messages.items.RequestItem;
-import org.apache.plc4x.java.api.messages.items.ResponseItem;
-
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-
/**
* Base type for all response messages sent as response for a prior request
* from a plc to the plc4x system.
- * @param <REQUEST>
- * @param <RESPONSE_ITEM>
- * @param <REQUEST_ITEM>
+ * @param <REQUEST_TYPE>
*/
-public abstract class PlcResponse<REQUEST extends PlcRequest, RESPONSE_ITEM extends ResponseItem, REQUEST_ITEM extends RequestItem> implements PlcMessage {
-
- private final REQUEST request;
-
- private final List<? extends RESPONSE_ITEM> responseItems;
-
- public PlcResponse(REQUEST request, List<? extends RESPONSE_ITEM> responseItems) {
- Objects.requireNonNull(request, "Request must not be null");
- Objects.requireNonNull(responseItems, "Response items must not be null");
- this.request = request;
- this.responseItems = responseItems;
- }
-
- public REQUEST getRequest() {
- return request;
- }
-
- public List<? extends RESPONSE_ITEM> getResponseItems() {
- return responseItems;
- }
-
- public Optional<? extends RESPONSE_ITEM> getResponseItem() {
- if (isMultiValue()) {
- throw new IllegalStateException("Too many items " + getNumberOfItems());
- }
- if (isEmpty()) {
- return Optional.empty();
- }
- return Optional.of(getResponseItems().get(0));
- }
-
- public int getNumberOfItems() {
- return getResponseItems().size();
- }
-
- public boolean isMultiValue() {
- return getNumberOfItems() > 1;
- }
-
- public boolean isEmpty() {
- return getNumberOfItems() < 1;
- }
-
- public Optional<RESPONSE_ITEM> getValue(REQUEST_ITEM item) {
- return getResponseItems().stream()
- .filter(x -> x.getRequestItem().equals(item))
- .map(e -> (RESPONSE_ITEM) e)
- .findAny();
- }
-
- @Override
- public String toString() {
- return "PlcResponse{" +
- "request=" + request +
- ", responseItems=" + responseItems +
- '}';
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PlcResponse)) {
- return false;
- }
- PlcResponse<?, ?, ?> that = (PlcResponse<?, ?, ?>) o;
- return Objects.equals(request, that.request) &&
- Objects.equals(responseItems, that.responseItems);
- }
+public interface PlcResponse<REQUEST_TYPE extends PlcRequest> extends PlcMessage {
- @Override
- public int hashCode() {
+ REQUEST_TYPE getRequest();
- return Objects.hash(request, responseItems);
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionEvent.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionEvent.java
index 6c2cfe7..30535be 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionEvent.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionEvent.java
@@ -1,10 +1,3 @@
-package org.apache.plc4x.java.api.messages;
-
-import org.apache.plc4x.java.api.messages.items.SubscriptionEventItem;
-
-import java.util.List;
-import java.util.Objects;
-
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -23,39 +16,8 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-public class PlcSubscriptionEvent {
-
- protected final List<SubscriptionEventItem<?>> eventItems;
-
- public PlcSubscriptionEvent(List<SubscriptionEventItem<?>> eventItems) {
- this.eventItems = eventItems;
- }
-
- public List<SubscriptionEventItem<?>> getEventItems() {
- return eventItems;
- }
-
- @Override
- public String toString() {
- return "PlcSubscriptionEvent{" +
- "eventItems=" + eventItems +
- '}';
- }
+package org.apache.plc4x.java.api.messages;
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PlcSubscriptionEvent)) {
- return false;
- }
- PlcSubscriptionEvent that = (PlcSubscriptionEvent) o;
- return Objects.equals(eventItems, that.eventItems);
- }
+public interface PlcSubscriptionEvent {
- @Override
- public int hashCode() {
- return Objects.hash(eventItems);
- }
}
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 202f0a7..4a501ab 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
@@ -1,4 +1,3 @@
-package org.apache.plc4x.java.api.messages;
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -17,62 +16,10 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
+package org.apache.plc4x.java.api.messages;
-import org.apache.plc4x.java.api.messages.items.*;
-import org.apache.plc4x.java.api.model.PlcField;
-
-import java.util.concurrent.TimeUnit;
-import java.util.function.Consumer;
-
-public class PlcSubscriptionRequest extends PlcRequest<SubscriptionRequestItem<?>> {
-
- public static PlcSubscriptionRequest.Builder builder() {
- return new PlcSubscriptionRequest.Builder();
- }
-
- public static class Builder extends PlcRequest.Builder<SubscriptionRequestItem> {
-
- public final <T> Builder addChangeOfStateItem(Class<T> dataType, PlcField field, Consumer<SubscriptionEventItem<T>> consumer) {
- // As we don't get a list as response rather we have individual consumers we don't need type checking here.
- //checkType(dataType);
- requests.add(new SubscriptionRequestChangeOfStateItem<>(dataType, field, consumer));
- return this;
- }
-
- public final <T> Builder addCyclicItem(Class<T> dataType, PlcField field, Consumer<SubscriptionEventItem<T>> consumer, TimeUnit timeUnit, int period) {
- // As we don't get a list as response rather we have individual consumers we don't need type checking here.
- //checkType(dataType);
- requests.add(new SubscriptionRequestCyclicItem<>(dataType, field, timeUnit, period, consumer));
- return this;
- }
-
- public final <T> Builder addEventItem(Class<T> dataType, PlcField field, Consumer<SubscriptionEventItem<T>> consumer) {
- // As we don't get a list as response rather we have individual consumers we don't need type checking here.
- //checkType(dataType);
- requests.add(new SubscriptionRequestEventItem<>(dataType, field, consumer));
- return this;
- }
-
- public final Builder addItem(SubscriptionRequestItem subscriptionRequestItem) {
- requests.add(subscriptionRequestItem);
- return this;
- }
-
- public final PlcSubscriptionRequest build() {
- if (requests.isEmpty()) {
- throw new IllegalStateException("No requests added");
- }
- PlcSubscriptionRequest plcSubscriptionRequest = new PlcSubscriptionRequest();
- for (SubscriptionRequestItem request : requests) {
- plcSubscriptionRequest.addItem(request);
- }
- return plcSubscriptionRequest;
- }
+public interface PlcSubscriptionRequest extends PlcFieldRequest {
- }
+ PlcMessageBuilder<PlcSubscriptionRequest> builder();
- @Override
- public String toString() {
- return "PlcSubscriptionRequest{} " + super.toString();
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionResponse.java
index a516b74..effb1d3 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionResponse.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionResponse.java
@@ -1,4 +1,3 @@
-package org.apache.plc4x.java.api.messages;
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -17,20 +16,8 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
+package org.apache.plc4x.java.api.messages;
-import org.apache.plc4x.java.api.messages.items.SubscriptionRequestItem;
-import org.apache.plc4x.java.api.messages.items.SubscriptionResponseItem;
-
-import java.util.List;
-
-public class PlcSubscriptionResponse extends PlcResponse<PlcSubscriptionRequest, SubscriptionResponseItem<?>, SubscriptionRequestItem<?>> {
-
- public PlcSubscriptionResponse(PlcSubscriptionRequest request, List<SubscriptionResponseItem<?>> subscriptionResponseItems) {
- super(request, subscriptionResponseItems);
- }
+public interface PlcSubscriptionResponse extends PlcFieldResponse<PlcSubscriptionRequest> {
- @Override
- public String toString() {
- return "PlcSubscriptionResponse{} " + super.toString();
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcUnsubscriptionRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcUnsubscriptionRequest.java
index 13198fb..e8171f1 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcUnsubscriptionRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcUnsubscriptionRequest.java
@@ -18,117 +18,42 @@ under the License.
*/
package org.apache.plc4x.java.api.messages;
-import org.apache.plc4x.java.api.messages.items.SubscriptionResponseItem;
-import org.apache.plc4x.java.api.messages.items.UnsubscriptionRequestItem;
-import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
-
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-public class PlcUnsubscriptionRequest implements PlcMessage {
-
- protected final List<UnsubscriptionRequestItem> requestItems;
-
- public PlcUnsubscriptionRequest() {
- this.requestItems = new LinkedList<>();
- }
-
- public PlcUnsubscriptionRequest(List<UnsubscriptionRequestItem> requestItems) {
- Objects.requireNonNull(requestItems, "Request items must not be null");
- this.requestItems = requestItems;
- }
-
- public void addItem(UnsubscriptionRequestItem unsubscriptionRequestItem) {
- Objects.requireNonNull(unsubscriptionRequestItem, "Request item must not be null");
- getRequestItems().add(unsubscriptionRequestItem);
- }
-
- public List<UnsubscriptionRequestItem> getRequestItems() {
- return requestItems;
- }
-
- public int getNumberOfItems() {
- return getRequestItems().size();
- }
-
- public static PlcUnsubscriptionRequest.Builder builder() {
- return new PlcUnsubscriptionRequest.Builder();
- }
-
- public static class Builder extends PlcRequest.Builder<UnsubscriptionRequestItem> {
-
- public final Builder addHandle(PlcSubscriptionHandle subscriptionHandle) {
- requests.add(new UnsubscriptionRequestItem(subscriptionHandle));
- return this;
- }
-
- public final Builder addHandle(PlcSubscriptionHandle... subscriptionHandles) {
- requests.addAll(Arrays.stream(subscriptionHandles).map(UnsubscriptionRequestItem::new).collect(Collectors.toList()));
- return this;
- }
-
- public final Builder addHandle(List<PlcSubscriptionHandle> subscriptionHandles) {
- requests.addAll(subscriptionHandles.stream().map(UnsubscriptionRequestItem::new).collect(Collectors.toList()));
- return this;
- }
-
- public final Builder addHandle(SubscriptionResponseItem subscriptionResponseItem) {
- requests.add(new UnsubscriptionRequestItem(subscriptionResponseItem.getSubscriptionHandle()));
- return this;
- }
-
- public final Builder addItem(UnsubscriptionRequestItem unsubscriptionRequestItem) {
- requests.add(unsubscriptionRequestItem);
- return this;
- }
-
- public final Builder addItem(UnsubscriptionRequestItem... unsubscriptionRequestItems) {
- requests.addAll(Arrays.asList(unsubscriptionRequestItems));
- return this;
- }
-
- public final Builder addItem(List<UnsubscriptionRequestItem> unsubscriptionRequestItems) {
- requests.addAll(unsubscriptionRequestItems);
- return this;
- }
-
- public final PlcUnsubscriptionRequest build() {
- if (requests.isEmpty()) {
- throw new IllegalStateException("No requests added");
- }
- PlcUnsubscriptionRequest plcUnsubscriptionRequest = new PlcUnsubscriptionRequest();
- for (UnsubscriptionRequestItem request : requests) {
- plcUnsubscriptionRequest.addItem(request);
- }
- return plcUnsubscriptionRequest;
- }
-
- }
-
- @Override
- public String toString() {
- return "PlcUnsubscriptionRequest{" +
- "requestItems=" + requestItems +
- '}';
+import java.time.Duration;
+
+public interface PlcUnsubscriptionRequest extends PlcFieldRequest {
+
+ interface Builder extends PlcMessageBuilder<PlcUnsubscriptionRequest> {
+ /**
+ * Adds a new field to the to be constructed request which should be polled cyclically.
+ *
+ * @param name alias of the field.
+ * @param fieldQuery field query string for accessing the field.
+ * @param pollingInterval interval, in which the field should be polled.
+ * @return
+ */
+ PlcReadRequest.Builder addCyclicField(String name, String 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.
+ *
+ * @param name alias of the field.
+ * @param fieldQuery field query string for accessing the field.
+ * @return
+ */
+ PlcReadRequest.Builder addChangeOfStateField(String name, String fieldQuery);
+
+ /**
+ * Adds a new subscription to the to be constructed request which should be updated
+ * as soon as an event occurs.
+ *
+ * REMARK: We will have to see if this signature is correct as soon as we start using this type of subscription.
+ *
+ * @param name alias of the field.
+ * @param fieldQuery field query string for accessing the field.
+ * @return
+ */
+ PlcReadRequest.Builder addEventField(String name, String fieldQuery);
}
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PlcUnsubscriptionRequest)) {
- return false;
- }
- PlcUnsubscriptionRequest that = (PlcUnsubscriptionRequest) o;
- return Objects.equals(requestItems, that.requestItems);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(requestItems);
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcUnsubscriptionResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcUnsubscriptionResponse.java
index 7c56268..754f66f 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcUnsubscriptionResponse.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcUnsubscriptionResponse.java
@@ -1,4 +1,3 @@
-package org.apache.plc4x.java.api.messages;
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -17,10 +16,19 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
-public class PlcUnsubscriptionResponse implements PlcMessage {
+package org.apache.plc4x.java.api.messages;
- @Override
- public String toString() {
- return "PlcUnsubscriptionResponse{}";
+public interface PlcUnsubscriptionResponse extends PlcFieldResponse<PlcUnsubscriptionRequest> {
+
+ interface Builder extends PlcMessageBuilder<PlcUnsubscriptionResponse> {
+ /**
+ * Adds a new field to the to be constructed request which should cancel a previously
+ * created subscription.
+ *
+ * @param name alias of the field.
+ * @return
+ */
+ PlcReadRequest.Builder addField(String name);
}
+
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java
index 5651da9..4017c9d 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteRequest.java
@@ -18,91 +18,39 @@ under the License.
*/
package org.apache.plc4x.java.api.messages;
-import org.apache.plc4x.java.api.messages.items.PlcWriteRequestItem;
-import org.apache.plc4x.java.api.messages.specific.TypeSafePlcWriteRequest;
-import org.apache.plc4x.java.api.model.PlcField;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
-import java.util.List;
-import java.util.Objects;
+public interface PlcWriteRequest extends PlcFieldRequest {
-public class PlcWriteRequest extends PlcRequest<PlcWriteRequestItem<?>> {
+ interface Builder extends PlcMessageBuilder<PlcWriteRequest> {
- public PlcWriteRequest() {
- }
+ /* NOT Quite sure about these two ...
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, byte[]... values);
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, Object... values);*/
- public PlcWriteRequest(PlcWriteRequestItem<?> requestItem) {
- addItem(requestItem);
- }
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, Boolean... values);
- @SafeVarargs
- public <T> PlcWriteRequest(Class<T> dataType, PlcField field, T... values) {
- Objects.requireNonNull(dataType, "Data type must not be null");
- Objects.requireNonNull(field, "PlcField must not be null");
- addItem(new PlcWriteRequestItem<>(dataType, field, values));
- }
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, Byte... values);
- public PlcWriteRequest(List<PlcWriteRequestItem<?>> requestItems) {
- super(requestItems);
- }
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, Short... values);
- public static PlcWriteRequest.Builder builder() {
- return new Builder();
- }
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, Integer... values);
- public static class Builder extends PlcRequest.Builder<PlcWriteRequestItem<?>> {
-
- @SuppressWarnings("unchecked")
- public <T> PlcWriteRequest.Builder addItem(PlcField field, T value) {
- Objects.requireNonNull(value);
- checkType(value.getClass());
- requests.add(new PlcWriteRequestItem<>((Class<T>) value.getClass(), field, (T) value));
- return this;
- }
-
- @SafeVarargs
- public final <T> PlcWriteRequest.Builder addItem(Class<T> dataType, PlcField field, T... values) {
- checkType(dataType);
- requests.add(new PlcWriteRequestItem<>(dataType, field, values));
- return this;
- }
-
- public final PlcWriteRequest.Builder addItem(PlcWriteRequestItem<?> writeRequestItem) {
- checkType(writeRequestItem.getDatatype());
- requests.add(writeRequestItem);
- return this;
- }
-
- public final PlcWriteRequest build() {
- if (requests.isEmpty()) {
- throw new IllegalStateException("No requests added");
- }
- PlcWriteRequest plcWriteRequest;
- if (mixed) {
- plcWriteRequest = new PlcWriteRequest();
- } else {
- plcWriteRequest = new TypeSafePlcWriteRequest<>(firstType);
- }
- for (PlcWriteRequestItem request : requests) {
- plcWriteRequest.addItem(request);
- }
- return plcWriteRequest;
- }
-
- @SuppressWarnings("unchecked")
- public final <T> TypeSafePlcWriteRequest<T> build(Class<T> type) {
- if (firstType != type) {
- throw new ClassCastException("Incompatible type " + type + ". Required " + firstType);
- }
- if (mixed) {
- throw new IllegalStateException("Mixed types contained");
- }
- return (TypeSafePlcWriteRequest<T>) build();
- }
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, Long... values);
- }
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, Float... values);
- @Override
- public String toString() {
- return "PlcWriteRequest{} " + super.toString();
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, Double... values);
+
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, String... values);
+
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, LocalTime... values);
+
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, LocalDate... values);
+
+ PlcReadRequest.Builder addItem(String name, String fieldQuery, LocalDateTime... values);
}
+
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteResponse.java
index 1950fab..a41b650 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteResponse.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcWriteResponse.java
@@ -18,30 +18,6 @@ under the License.
*/
package org.apache.plc4x.java.api.messages;
-import org.apache.plc4x.java.api.messages.items.PlcWriteRequestItem;
-import org.apache.plc4x.java.api.messages.items.PlcWriteResponseItem;
+public interface PlcWriteResponse extends PlcFieldResponse<PlcWriteRequest> {
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-public class PlcWriteResponse extends PlcResponse<PlcWriteRequest, PlcWriteResponseItem<?>, PlcWriteRequestItem<?>> {
-
- public PlcWriteResponse(PlcWriteRequest request, PlcWriteResponseItem<?> responseItem) {
- super(request, Collections.singletonList(responseItem));
- }
-
- public PlcWriteResponse(PlcWriteRequest request, List<? extends PlcWriteResponseItem<?>> responseItems) {
- super(request, responseItems);
- }
-
- @SuppressWarnings("unchecked")
- public <T> Optional<PlcWriteResponseItem<T>> getValue(PlcWriteRequestItem<T> item) {
- return (Optional) super.getValue(item);
- }
-
- @Override
- public String toString() {
- return "PlcWriteResponse{} " + super.toString();
- }
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcReadRequestItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcReadRequestItem.java
deleted file mode 100644
index dc49a3f..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcReadRequestItem.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- 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.api.messages.items;
-
-import org.apache.plc4x.java.api.model.PlcField;
-
-import java.util.Objects;
-
-/**
- * Encapsulats one {@link RequestItem} that could be read multiple times, i.e., from the given PlcField on
- * {@link PlcReadRequestItem#size} number of Items with equal datatype are read.
- *
- * Thus,
- * <pre>
- * new PlcReadRequestItem(Int.class, adress, 5)
- * </pre>
- * basically reads 5 consecutive integers starting at the given {@link PlcField}.
- *
- * @param <T> Generic Type of expected Datatype.
- */
-public class PlcReadRequestItem<T> extends RequestItem<T> {
-
- private final int size;
-
- public PlcReadRequestItem(Class<T> datatype, PlcField field) {
- super(datatype, field);
- this.size = 1;
- }
-
- public PlcReadRequestItem(Class<T> datatype, PlcField field, int size) {
- super(datatype, field);
- this.size = size;
- }
-
- public int getSize() {
- return size;
- }
-
- @Override
- public String toString() {
- return "PlcReadRequestItem{" +
- "size=" + size +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PlcReadRequestItem)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- PlcReadRequestItem<?> that = (PlcReadRequestItem<?>) o;
- return size == that.size;
- }
-
- @Override
- public int hashCode() {
-
- return Objects.hash(super.hashCode(), size);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcReadResponseItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcReadResponseItem.java
deleted file mode 100644
index 4034e7b..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcReadResponseItem.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- 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.api.messages.items;
-
-import org.apache.plc4x.java.api.types.PlcResponseCode;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Response to a {@link PlcReadRequestItem}.
- * Can contain a list of values if the size in {@link PlcReadRequestItem} is larger zero.
- *
- * @param <T>
- */
-public class PlcReadResponseItem<T> extends ResponseItem<PlcReadRequestItem<T>> {
-
- private final List<T> values;
-
- public PlcReadResponseItem(PlcReadRequestItem<T> requestItem, PlcResponseCode responseCode, List<T> values) {
- super(requestItem, responseCode);
- Objects.requireNonNull(values, "Values must not be null");
- for (T value : values) {
- if (!requestItem.getDatatype().isAssignableFrom(value.getClass())) {
- throw new IllegalArgumentException("Datatype of " + value + " doesn't match required datatype of " + requestItem.getDatatype());
- }
- }
- this.values = values;
- }
-
- @SafeVarargs
- public PlcReadResponseItem(PlcReadRequestItem<T> requestItem, PlcResponseCode responseCode, T... values) {
- this(requestItem, responseCode, Arrays.asList(values));
- }
-
- public List<T> getValues() {
- return values;
- }
-
- @Override
- public String toString() {
- return "PlcReadResponseItem{" +
- "values=" + values +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PlcReadResponseItem)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- PlcReadResponseItem<?> that = (PlcReadResponseItem<?>) o;
- return Objects.equals(values, that.values);
- }
-
- @Override
- public int hashCode() {
-
- return Objects.hash(super.hashCode(), values);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcWriteRequestItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcWriteRequestItem.java
deleted file mode 100644
index 5a8e35e..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcWriteRequestItem.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- 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.api.messages.items;
-
-import org.apache.plc4x.java.api.model.PlcField;
-
-import java.util.*;
-
-public class PlcWriteRequestItem<T> extends RequestItem<T> {
-
- private final List<T> values;
-
- @SafeVarargs
- public PlcWriteRequestItem(Class<T> dataType, PlcField field, T... values) {
- super(dataType, field);
- Objects.requireNonNull(values, "Values must not be null");
- List<T> checkedList = Collections.checkedList(new ArrayList<>(), dataType);
- checkedList.addAll(Arrays.asList(values));
- this.values = checkedList;
- }
-
- public List<T> getValues() {
- return values;
- }
-
- public int getSize() {
- return values.size();
- }
-
- @Override
- public String toString() {
- return "PlcWriteRequestItem{" +
- "values=" + values +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PlcWriteRequestItem)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- PlcWriteRequestItem<?> that = (PlcWriteRequestItem<?>) o;
- return Objects.equals(values, that.values);
- }
-
- @Override
- public int hashCode() {
-
- return Objects.hash(super.hashCode(), values);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcWriteResponseItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcWriteResponseItem.java
deleted file mode 100644
index 3cf0e9d..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/PlcWriteResponseItem.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- 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.api.messages.items;
-
-import org.apache.plc4x.java.api.types.PlcResponseCode;
-
-public class PlcWriteResponseItem<T> extends ResponseItem<PlcWriteRequestItem<T>> {
-
- public PlcWriteResponseItem(PlcWriteRequestItem<T> requestItem, PlcResponseCode responseCode) {
- super(requestItem, responseCode);
- }
-
- @Override
- public String toString() {
- return "PlcWriteResponseItem{} " + super.toString();
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/RequestItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/RequestItem.java
deleted file mode 100644
index 660fa20..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/RequestItem.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- 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.api.messages.items;
-
-import org.apache.plc4x.java.api.model.PlcField;
-
-import java.util.Objects;
-
-/**
- * Wrapper Object to encapsulate an {@link PlcField} and the expected datatype as {@link Class}.
- *
- * @param <DATA_TYPE> Generic Type of data at field
- */
-public abstract class RequestItem<DATA_TYPE> {
-
- private final Class<DATA_TYPE> datatype;
-
- private final PlcField field;
-
- public RequestItem(Class<DATA_TYPE> datatype, PlcField field) {
- Objects.requireNonNull(datatype, "Data type must not be null");
- Objects.requireNonNull(field, "PlcField type must not be null");
- this.datatype = datatype;
- this.field = field;
- }
-
- public Class<DATA_TYPE> getDatatype() {
- return datatype;
- }
-
- public PlcField getField() {
- return field;
- }
-
- @Override
- public String toString() {
- return "RequestItem{" +
- "datatype=" + datatype +
- ", field=" + field +
- '}';
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof RequestItem)) {
- return false;
- }
- RequestItem<?> that = (RequestItem<?>) o;
- return Objects.equals(datatype, that.datatype) &&
- Objects.equals(field, that.field);
- }
-
- @Override
- public int hashCode() {
-
- return Objects.hash(datatype, field);
- }
-
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ResponseItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ResponseItem.java
deleted file mode 100644
index 28d1c96..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/ResponseItem.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- 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.api.messages.items;
-
-import org.apache.plc4x.java.api.types.PlcResponseCode;
-
-import java.util.Objects;
-
-public abstract class ResponseItem<REQUEST_ITEM extends RequestItem> {
-
- private final REQUEST_ITEM requestItem;
-
- private final PlcResponseCode responseCode;
-
- public ResponseItem(REQUEST_ITEM requestItem, PlcResponseCode responseCode) {
- Objects.requireNonNull(requestItem,"Request item must not be null");
- Objects.requireNonNull(responseCode,"Response code must not be null");
- this.requestItem = requestItem;
- this.responseCode = responseCode;
- }
-
- public REQUEST_ITEM getRequestItem() {
- return requestItem;
- }
-
- public PlcResponseCode getResponseCode() {
- return responseCode;
- }
-
- @Override
- public String toString() {
- return "ResponseItem{" +
- "requestItem=" + requestItem +
- ", responseCode=" + responseCode +
- '}';
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof ResponseItem)) {
- return false;
- }
- ResponseItem<?> that = (ResponseItem<?>) o;
- return Objects.equals(requestItem, that.requestItem) &&
- responseCode == that.responseCode;
- }
-
- @Override
- public int hashCode() {
-
- return Objects.hash(requestItem, responseCode);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionEventItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionEventItem.java
deleted file mode 100644
index 5142d9a..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionEventItem.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- 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.api.messages.items;
-
-import java.util.Calendar;
-import java.util.List;
-import java.util.Objects;
-
-public class SubscriptionEventItem<T> {
-
- private final SubscriptionRequestItem<T> subscriptionRequestItem;
- private final Calendar timestamp;
- private final List<T> values;
-
- public SubscriptionEventItem(SubscriptionRequestItem<T> subscriptionRequestItem, Calendar timestamp, List<T> values) {
- this.subscriptionRequestItem = subscriptionRequestItem;
- this.timestamp = timestamp;
- this.values = values;
- }
-
- public SubscriptionRequestItem<T> getSubscriptionRequestItem() {
- return subscriptionRequestItem;
- }
-
- public Calendar getTimestamp() {
- return timestamp;
- }
-
- public List<T> getValues() {
- return values;
- }
-
- @Override
- public String toString() {
- return "SubscriptionEventItem{" +
- "subscriptionRequestItem=" + subscriptionRequestItem +
- ", timestamp=" + timestamp +
- ", values=" + values +
- '}';
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof SubscriptionEventItem)) {
- return false;
- }
- SubscriptionEventItem<?> that = (SubscriptionEventItem<?>) o;
- return Objects.equals(subscriptionRequestItem, that.subscriptionRequestItem) &&
- Objects.equals(timestamp, that.timestamp) &&
- Objects.equals(values, that.values);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(subscriptionRequestItem, timestamp, values);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestCyclicItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestCyclicItem.java
deleted file mode 100644
index 5926c1c..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestCyclicItem.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
-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.api.messages.items;
-
-import org.apache.plc4x.java.api.model.PlcField;
-import org.apache.plc4x.java.api.model.PlcSubscriptionType;
-
-import java.util.Objects;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Consumer;
-
-public class SubscriptionRequestCyclicItem<T> extends SubscriptionRequestItem<T> {
-
- private final TimeUnit timeUnit;
- private final int period;
-
- public SubscriptionRequestCyclicItem(Class<T> dataType, PlcField field, TimeUnit timeUnit, int period, Consumer<SubscriptionEventItem<T>> consumer) {
- super(dataType, field, PlcSubscriptionType.CYCLIC, consumer);
- this.timeUnit = timeUnit;
- this.period = period;
- }
-
- public TimeUnit getTimeUnit() {
- return timeUnit;
- }
-
- public int getPeriod() {
- return period;
- }
-
- @Override
- public String toString() {
- return "SubscriptionRequestCyclicItem{" +
- "timeUnit=" + timeUnit +
- ", period=" + period +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof SubscriptionRequestCyclicItem)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- SubscriptionRequestCyclicItem that = (SubscriptionRequestCyclicItem) o;
- return period == that.period &&
- timeUnit == that.timeUnit;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), timeUnit, period);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestItem.java
deleted file mode 100644
index 7893a30..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionRequestItem.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- 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.api.messages.items;
-
-import org.apache.plc4x.java.api.model.PlcField;
-import org.apache.plc4x.java.api.model.PlcSubscriptionType;
-
-import java.util.Objects;
-import java.util.function.Consumer;
-
-public abstract class SubscriptionRequestItem<T> extends RequestItem<T> {
-
- private final PlcSubscriptionType subscriptionType;
- private final Consumer<SubscriptionEventItem<T>> consumer;
-
- public SubscriptionRequestItem(Class<T> datatype, PlcField field, PlcSubscriptionType subscriptionType, Consumer<SubscriptionEventItem<T>> consumer) {
- super(datatype, field);
- this.subscriptionType = subscriptionType;
- this.consumer = consumer;
- }
-
- public PlcSubscriptionType getSubscriptionType() {
- return subscriptionType;
- }
-
- public Consumer<SubscriptionEventItem<T>> getConsumer() {
- return consumer;
- }
-
- @Override
- public String toString() {
- return "SubscriptionRequestItem{" +
- "subscriptionType=" + subscriptionType +
- ", consumer=" + consumer +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof SubscriptionRequestItem)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- SubscriptionRequestItem<?> that = (SubscriptionRequestItem<?>) o;
- return subscriptionType == that.subscriptionType &&
- Objects.equals(consumer, that.consumer);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), subscriptionType, consumer);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionResponseItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionResponseItem.java
deleted file mode 100644
index 2ca30c2..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/SubscriptionResponseItem.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- 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.api.messages.items;
-
-import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
-import org.apache.plc4x.java.api.types.PlcResponseCode;
-
-import java.util.Objects;
-
-public class SubscriptionResponseItem<T> extends ResponseItem<SubscriptionRequestItem<T>> {
-
- private PlcSubscriptionHandle subscriptionHandle;
-
- public SubscriptionResponseItem(SubscriptionRequestItem<T> requestItem, PlcSubscriptionHandle subscriptionHandle, PlcResponseCode responseCode) {
- super(requestItem, responseCode);
- this.subscriptionHandle = subscriptionHandle;
- }
-
- public PlcSubscriptionHandle getSubscriptionHandle() {
- return subscriptionHandle;
- }
-
- @Override
- public String toString() {
- return "SubscriptionResponseItem{" +
- "subscriptionHandle=" + subscriptionHandle +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof SubscriptionResponseItem)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- SubscriptionResponseItem<?> that = (SubscriptionResponseItem<?>) o;
- return Objects.equals(subscriptionHandle, that.subscriptionHandle);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(super.hashCode(), subscriptionHandle);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/UnsubscriptionRequestItem.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/UnsubscriptionRequestItem.java
deleted file mode 100644
index 9532a57..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/items/UnsubscriptionRequestItem.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- 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.api.messages.items;
-
-import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
-
-import java.util.Objects;
-
-public class UnsubscriptionRequestItem {
-
- private PlcSubscriptionHandle subscriptionHandle;
-
- public UnsubscriptionRequestItem(PlcSubscriptionHandle subscriptionHandle) {
- Objects.requireNonNull(subscriptionHandle, "PlcSubscriptionHandle must not be null");
- this.subscriptionHandle = subscriptionHandle;
- }
-
- public PlcSubscriptionHandle getSubscriptionHandle() {
- return subscriptionHandle;
- }
-
- @Override
- public String toString() {
- return "UnsubscriptionRequestItem{" +
- "subscriptionHandle=" + subscriptionHandle +
- '}';
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof UnsubscriptionRequestItem)) {
- return false;
- }
- UnsubscriptionRequestItem that = (UnsubscriptionRequestItem) o;
- return Objects.equals(subscriptionHandle, that.subscriptionHandle);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(subscriptionHandle);
- }
-
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadRequest.java
deleted file mode 100644
index 9dc4c2e..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadRequest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
-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.api.messages.specific;
-
-import org.apache.plc4x.java.api.messages.PlcReadRequest;
-import org.apache.plc4x.java.api.messages.items.PlcReadRequestItem;
-import org.apache.plc4x.java.api.model.PlcField;
-
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-
-/**
- * Type safe wrapper for {@link PlcReadRequest}.
- * Can be used if requesting only values from the same type.
- *
- * Can be constructed using the {@link PlcReadRequest#builder()} method.
- *
- * @param <T> Type of the {@link Class} of requested values
- */
-public class TypeSafePlcReadRequest<T> extends PlcReadRequest {
-
- private final Class<T> dataType;
-
- public TypeSafePlcReadRequest(Class<T> dataType) {
- Objects.requireNonNull(dataType, "data type must not be null");
- this.dataType = dataType;
- }
-
- public TypeSafePlcReadRequest(Class<T> dataType, PlcReadRequest plcReadRequest) {
- this(dataType);
- Objects.requireNonNull(plcReadRequest, "plc read request must not be null");
- Objects.requireNonNull(plcReadRequest.getRequestItems(), "plc read request item on " + plcReadRequest + " must not be null");
- for (PlcReadRequestItem<?> readRequestItem : plcReadRequest.getRequestItems()) {
- addItem(readRequestItem);
- }
- }
-
- public TypeSafePlcReadRequest(Class<T> dataType, PlcField field) {
- this(dataType);
- Objects.requireNonNull(field, "Field must not be null");
- addItem(new PlcReadRequestItem<>(dataType, field));
- }
-
- public TypeSafePlcReadRequest(Class<T> dataType, PlcField field, int size) {
- this(dataType);
- Objects.requireNonNull(field, "Field must not be null");
- addItem(new PlcReadRequestItem<>(dataType, field, size));
- }
-
- @SafeVarargs
- public TypeSafePlcReadRequest(Class<T> dataType, PlcReadRequestItem<T>... requestItems) {
- this(dataType);
- Objects.requireNonNull(requestItems, "Read request items must not be null");
- for (PlcReadRequestItem<T> readRequestItem : requestItems) {
- addItem(readRequestItem);
- }
- }
-
- @Override
- public void addItem(PlcReadRequestItem<?> readRequestItem) {
- Objects.requireNonNull(readRequestItem, "Read request item must not be null");
- if (readRequestItem.getDatatype() != dataType) {
- throw new IllegalArgumentException("Unexpected data type " + readRequestItem.getDatatype() + " on readRequestItem. Expected " + dataType);
- }
- super.addItem(readRequestItem);
- }
-
- @SuppressWarnings("unchecked")
- public List<PlcReadRequestItem<T>> getCheckedReadRequestItems() {
- return (List) getRequestItems();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Optional<PlcReadRequestItem<T>> getRequestItem() {
- return (Optional<PlcReadRequestItem<T>>) super.getRequestItem();
- }
-
- public Class<T> getDataType() {
- return dataType;
- }
-
- @Override
- public String toString() {
- return "TypeSafePlcReadRequest{" +
- "dataType=" + dataType +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof TypeSafePlcReadRequest)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- TypeSafePlcReadRequest<?> that = (TypeSafePlcReadRequest<?>) o;
- return Objects.equals(dataType, that.dataType);
- }
-
- @Override
- public int hashCode() {
-
- return Objects.hash(super.hashCode(), dataType);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java
deleted file mode 100644
index 346fe41..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
-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.api.messages.specific;
-
-import org.apache.plc4x.java.api.messages.PlcReadResponse;
-import org.apache.plc4x.java.api.messages.items.PlcReadResponseItem;
-
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-
-public class TypeSafePlcReadResponse<T> extends PlcReadResponse {
-
- public TypeSafePlcReadResponse(TypeSafePlcReadRequest<T> request, PlcReadResponseItem<T> responseItem) {
- super(request, responseItem);
- Objects.requireNonNull(request, "Request must not be null");
- checkList(responseItem.getValues(), request.getDataType());
- }
-
- public TypeSafePlcReadResponse(TypeSafePlcReadRequest<T> request, List<PlcReadResponseItem<T>> responseItems) {
- super(request, responseItems);
- Objects.requireNonNull(responseItems, "Request items on " + request + " must not be null");
- for (PlcReadResponseItem<T> responseItem : responseItems) {
- checkList(responseItem.getValues(), request.getDataType());
- }
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public TypeSafePlcReadRequest<T> getRequest() {
- return (TypeSafePlcReadRequest<T>) super.getRequest();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public List<? extends PlcReadResponseItem<T>> getResponseItems() {
- return (List<? extends PlcReadResponseItem<T>>) super.getResponseItems();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Optional<PlcReadResponseItem<T>> getResponseItem() {
- return (Optional<PlcReadResponseItem<T>>) super.getResponseItem();
- }
-
- public static <T> TypeSafePlcReadResponse<T> of(PlcReadResponse plcReadResponse, Class<T> clazz) {
- Objects.requireNonNull(plcReadResponse, "PlcReadResponse must not be null");
- Objects.requireNonNull(clazz, "Class must not be null");
- if (plcReadResponse instanceof TypeSafePlcReadResponse) {
- @SuppressWarnings("unchecked")
- TypeSafePlcReadResponse<T> typeSafePlcReadResponse = (TypeSafePlcReadResponse<T>) plcReadResponse;
- Class type = typeSafePlcReadResponse.getRequest().getDataType();
- if (type != clazz) {
- throw new IllegalArgumentException("Expected type " + clazz + " doesn't match found type " + type);
- }
- return typeSafePlcReadResponse;
- }
- @SuppressWarnings("unchecked")
- List<PlcReadResponseItem<T>> responseItems = (List<PlcReadResponseItem<T>>) plcReadResponse.getResponseItems();
- Objects.requireNonNull(responseItems, "Response items on " + plcReadResponse + " must not be null");
- if (plcReadResponse.getRequest() instanceof TypeSafePlcReadRequest) {
- @SuppressWarnings("unchecked")
- TypeSafePlcReadRequest<T> typeSafePlcReadRequest = (TypeSafePlcReadRequest<T>) plcReadResponse.getRequest();
- Class type = typeSafePlcReadRequest.getDataType();
- if (type != clazz) {
- throw new IllegalArgumentException("Expected type " + clazz + " doesn't match found type " + type);
- }
- return new TypeSafePlcReadResponse<>(typeSafePlcReadRequest, responseItems);
- }
- for (PlcReadResponseItem<?> responseItem : responseItems) {
- checkList(responseItem.getValues(), clazz);
- }
- TypeSafePlcReadRequest<T> request = new TypeSafePlcReadRequest<>(clazz, plcReadResponse.getRequest());
- return new TypeSafePlcReadResponse<>(request, responseItems);
- }
-
- private static void checkList(List<?> list, Class<?> type) {
- Objects.requireNonNull(list, "List must not be null");
- Objects.requireNonNull(type, "Type must not be null");
- for (Object o : list) {
- if (!type.isAssignableFrom(o.getClass())) {
- throw new IllegalArgumentException("Unexpected data type " + o.getClass() + " on readRequestItem. Expected " + type);
- }
- }
- }
-
- @Override
- public String toString() {
- return "TypeSafePlcReadResponse{} " + super.toString();
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java
deleted file mode 100644
index d15006c..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteRequest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
-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.api.messages.specific;
-
-import org.apache.plc4x.java.api.messages.PlcWriteRequest;
-import org.apache.plc4x.java.api.messages.items.PlcWriteRequestItem;
-import org.apache.plc4x.java.api.model.PlcField;
-
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-
-public class TypeSafePlcWriteRequest<T> extends PlcWriteRequest {
-
- private final Class<T> dataType;
-
- public TypeSafePlcWriteRequest(Class<T> dataType) {
- Objects.requireNonNull(dataType, "Data type must not be null");
- this.dataType = dataType;
- }
-
- public TypeSafePlcWriteRequest(Class<T> dataType, PlcWriteRequest plcWriteRequest) {
- this(dataType);
- Objects.requireNonNull(plcWriteRequest, "PLC write request must not be null");
- Objects.requireNonNull(plcWriteRequest.getRequestItems(), "plc write request item on " + plcWriteRequest + " must not be null");
- for (PlcWriteRequestItem<?> WriteRequestItem : plcWriteRequest.getRequestItems()) {
- addItem(WriteRequestItem);
- }
- }
-
- @SafeVarargs
- public TypeSafePlcWriteRequest(Class<T> dataType, PlcField field, T... values) {
- this(dataType);
- Objects.requireNonNull(field, "Field must not be null");
- addItem(new PlcWriteRequestItem<>(dataType, field, values));
- }
-
- @SafeVarargs
- public TypeSafePlcWriteRequest(Class<T> dataType, PlcWriteRequestItem<T>... requestItems) {
- this(dataType);
- Objects.requireNonNull(requestItems, "Request item must not be null");
- for (PlcWriteRequestItem<T> requestItem : requestItems) {
- getRequestItems().add(requestItem);
- }
- }
-
- @Override
- public void addItem(PlcWriteRequestItem<?> writeRequestItem) {
- Objects.requireNonNull(writeRequestItem, "Write request item must not be null");
- if (writeRequestItem.getDatatype() != dataType) {
- throw new IllegalArgumentException("Incompatible dataType " + writeRequestItem.getDatatype());
- }
- super.addItem(writeRequestItem);
- }
-
- @SuppressWarnings("unchecked")
- public List<PlcWriteRequestItem<T>> getCheckedRequestItems() {
- return (List) getRequestItems();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Optional<PlcWriteRequestItem<T>> getRequestItem() {
- return (Optional<PlcWriteRequestItem<T>>) super.getRequestItem();
- }
-
- public Class<T> getDataType() {
- return dataType;
- }
-
- @Override
- public String toString() {
- return "TypeSafePlcWriteRequest{" +
- "dataType=" + dataType +
- "} " + super.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof TypeSafePlcWriteRequest)) {
- return false;
- }
- if (!super.equals(o)) {
- return false;
- }
- TypeSafePlcWriteRequest<?> that = (TypeSafePlcWriteRequest<?>) o;
- return Objects.equals(dataType, that.dataType);
- }
-
- @Override
- public int hashCode() {
-
- return Objects.hash(super.hashCode(), dataType);
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteResponse.java
deleted file mode 100644
index 6944b66..0000000
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcWriteResponse.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
-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.api.messages.specific;
-
-import java.util.List;
-import java.util.Optional;
-
-import org.apache.plc4x.java.api.messages.PlcWriteResponse;
-import org.apache.plc4x.java.api.messages.items.PlcWriteResponseItem;
-
-public class TypeSafePlcWriteResponse<T> extends PlcWriteResponse {
-
- public TypeSafePlcWriteResponse(TypeSafePlcWriteRequest<T> request, PlcWriteResponseItem<T> responseItem) {
- super(request, responseItem);
- }
-
- public TypeSafePlcWriteResponse(TypeSafePlcWriteRequest<T> request, List<PlcWriteResponseItem<T>> responseItems) {
- super(request, responseItems);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public TypeSafePlcWriteRequest<T> getRequest() {
- return (TypeSafePlcWriteRequest<T>) super.getRequest();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public List<? extends PlcWriteResponseItem<T>> getResponseItems() {
- return (List<PlcWriteResponseItem<T>>) super.getResponseItems();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Optional<PlcWriteResponseItem<T>> getResponseItem() {
- return (Optional<PlcWriteResponseItem<T>>) super.getResponseItem();
- }
-
- @SuppressWarnings("unchecked")
- public static <T> TypeSafePlcWriteResponse<T> of(PlcWriteResponse plcWriteResponse) {
- if (plcWriteResponse instanceof TypeSafePlcWriteResponse) {
- return (TypeSafePlcWriteResponse) plcWriteResponse;
- }
- if (plcWriteResponse.getRequest() instanceof TypeSafePlcWriteRequest) {
- return new TypeSafePlcWriteResponse((TypeSafePlcWriteRequest) plcWriteResponse.getRequest(), plcWriteResponse.getResponseItems());
- }
- Class<?> referenceType = null;
- for (PlcWriteResponseItem<?> writeResponseItem : plcWriteResponse.getResponseItems()) {
- Class<?> foundDataType = writeResponseItem.getRequestItem().getDatatype();
- if (referenceType == null) {
- referenceType = foundDataType;
- }
- if (referenceType != foundDataType) {
- throw new IllegalArgumentException("invalid types found " + foundDataType + ". Required " + referenceType);
- }
- }
- if (referenceType == null) {
- referenceType = Object.class;
- }
- return new TypeSafePlcWriteResponse(new TypeSafePlcWriteRequest(referenceType, plcWriteResponse.getRequest()), plcWriteResponse.getResponseItems());
- }
-
- @Override
- public String toString() {
- return "TypeSafePlcWriteResponse{} " + super.toString();
- }
-}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/types/PlcResponseCode.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/types/PlcResponseCode.java
index 0bb1364..2539a0b 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/types/PlcResponseCode.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/types/PlcResponseCode.java
@@ -22,5 +22,6 @@ public enum PlcResponseCode {
OK,
NOT_FOUND,
INVALID_ADDRESS,
- INTERNAL_ERROR
+ INTERNAL_ERROR,
+ RESPONSE_PENDING
}
diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcSubscriptionType.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/types/PlcSubscriptionType.java
similarity index 96%
rename from plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcSubscriptionType.java
rename to plc4j/api/src/main/java/org/apache/plc4x/java/api/types/PlcSubscriptionType.java
index fdd1ec1..4b0d972 100644
--- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcSubscriptionType.java
+++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/types/PlcSubscriptionType.java
@@ -1,4 +1,3 @@
-package org.apache.plc4x.java.api.model;
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -17,6 +16,7 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
+package org.apache.plc4x.java.api.types;
/**
* {@link PlcSubscriptionType} specifies the nature of the subscription.
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsAbstractPlcConnection.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsAbstractPlcConnection.java
index 41a8ef9..585c90f 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsAbstractPlcConnection.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/connection/AdsAbstractPlcConnection.java
@@ -30,7 +30,6 @@ 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.AdsField;
import org.apache.plc4x.java.ads.model.SymbolicAdsField;
-import org.apache.plc4x.java.api.connection.PlcProprietarySender;
import org.apache.plc4x.java.api.connection.PlcReader;
import org.apache.plc4x.java.api.connection.PlcWriter;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRequest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRequest.java
index c31e978..62ff802 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRequest.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRequest.java
@@ -19,7 +19,6 @@
package org.apache.plc4x.java.ads.adslib;
import org.apache.plc4x.java.ads.api.generic.AmsPacket;
-import org.apache.plc4x.java.api.messages.PlcProprietaryRequest;
import java.util.concurrent.CompletableFuture;
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRouter.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRouter.java
index 06786af..7b63bf2 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRouter.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/adslib/AmsRouter.java
@@ -29,8 +29,6 @@ import org.apache.plc4x.java.ads.api.generic.types.AmsPort;
import org.apache.plc4x.java.ads.connection.AdsTcpPlcConnection;
import org.apache.plc4x.java.ads.protocol.Plc4x2AdsProtocol;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-import org.apache.plc4x.java.api.messages.PlcProprietaryRequest;
-import org.apache.plc4x.java.api.messages.PlcProprietaryResponse;
import java.io.IOException;
import java.net.*;
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnectionTests.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnectionTests.java
index 02bd164..19a1f45 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnectionTests.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/connection/AdsTcpPlcConnectionTests.java
@@ -30,8 +30,6 @@ import org.apache.plc4x.java.ads.model.AdsField;
import org.apache.plc4x.java.ads.model.SymbolicAdsField;
import org.apache.plc4x.java.ads.protocol.Plc4x2AdsProtocol;
import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
-import org.apache.plc4x.java.api.messages.PlcProprietaryRequest;
-import org.apache.plc4x.java.api.messages.PlcProprietaryResponse;
import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest;
import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse;
import org.apache.plc4x.java.api.messages.items.SubscriptionEventItem;