diff --git a/.mvn/jvm.config b/.mvn/jvm.config index e2a50e08349..5bd05c1cb68 100644 --- a/.mvn/jvm.config +++ b/.mvn/jvm.config @@ -1 +1 @@ ---add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ No newline at end of file +-XX:+EnableDynamicAgentLoading --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ No newline at end of file diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/PlcConnection.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/PlcConnection.java index 116cc25890e..af8ce2fffb9 100644 --- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/PlcConnection.java +++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/PlcConnection.java @@ -56,10 +56,7 @@ public interface PlcConnection extends AutoCloseable { * * @throws PlcRuntimeException If the string cannot be parsed */ - @Deprecated - default PlcTag parseTagAddress(String tagAddress) throws PlcInvalidTagException { - throw new PlcRuntimeException("Parse method is not implemented for this connection / driver"); - } + PlcTag parseTagAddress(String tagAddress) throws PlcInvalidTagException; /** * Provides connection metadata. diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionTagRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationEventRequest.java similarity index 58% rename from plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionTagRequest.java rename to plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationEventRequest.java index 323fa83679e..5f9fb1e1dc6 100644 --- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionTagRequest.java +++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationEventRequest.java @@ -18,27 +18,13 @@ */ package org.apache.plc4x.java.api.messages; -import org.apache.plc4x.java.api.model.PlcSubscriptionTag; +import java.time.Instant; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; +public interface PlcPublicationEventRequest extends PlcWriteRequest { -public interface PlcSubscriptionTagRequest extends PlcRequest { - - @Override - CompletableFuture execute(); - - int getNumberOfTags(); - - LinkedHashSet getTagNames(); - - PlcSubscriptionTag getTag(String name); - - List getTags(); - - Map>> getPreRegisteredConsumers(); + /** + * @return the timestamp at which this event occurred. + */ + Instant getTimestamp(); } diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationEventResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationEventResponse.java new file mode 100644 index 00000000000..536c3c4f920 --- /dev/null +++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationEventResponse.java @@ -0,0 +1,23 @@ +/* + * 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 + * + * https://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; + +public interface PlcPublicationEventResponse extends PlcWriteResponse { + +} diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationRequest.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationRequest.java new file mode 100644 index 00000000000..5eca71f8d34 --- /dev/null +++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationRequest.java @@ -0,0 +1,96 @@ +/* + * 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 + * + * https://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.model.PlcPublicationTag; +import org.apache.plc4x.java.api.model.PlcTag; +import org.apache.plc4x.java.api.value.PlcValue; + +import java.time.Duration; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public interface PlcPublicationRequest extends PlcRequest { + + @Override + CompletableFuture execute(); + + int getNumberOfTags(); + + LinkedHashSet getTagNames(); + + PlcPublicationTag getTag(String name); + + List getTags(); + + interface Builder extends PlcRequestBuilder { + + @Override + PlcPublicationRequest build(); + + /** + * Adds a new tag to the to be constructed request which should be published cyclically. + * In this case will the driver regularly publish the given value, if it has changed or not. + * + * @param name alias of the tag. + * @param tagAddress tag address string for accessing the tag. + * @param publicationInterval interval, in which the tag should be published. + * @param initialValue initial value of the tag + * @return builder. + */ + PlcPublicationRequest.Builder addCyclicTagAddress(String name, String tagAddress, Duration publicationInterval, PlcValue initialValue); + + /** + * Adds a new tag to the to be constructed request which should be published cyclically. + * In this case will the driver regularly publish the given value, if it has changed or not. + * + * @param name alias of the tag. + * @param tag tag instance for accessing the tag. + * @param publicationInterval interval, in which the tag should be published. + * @param initialValue initial value of the tag + * @return builder. + */ + PlcPublicationRequest.Builder addCyclicTag(String name, PlcTag tag, Duration publicationInterval, PlcValue initialValue); + + /** + * Adds a new tag to the to be constructed request which should be published as soon as + * a value changes locally. + * + * @param name alias of the tag. + * @param tagAddress tag address string for accessing the tag. + * @param initialValue initial value of the tag + * @return builder. + */ + PlcPublicationRequest.Builder addChangeOfStateTagAddress(String name, String tagAddress, PlcValue initialValue); + + /** + * Adds a new tag to the to be constructed request which should be published as soon as + * a value changes locally. + * + * @param name alias of the tag. + * @param tag tag instance for accessing the tag. + * @param initialValue initial value of the tag + * @return builder. + */ + PlcPublicationRequest.Builder addChangeOfStateTag(String name, PlcTag tag, PlcValue initialValue); + + } + +} diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionTagResponse.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationResponse.java similarity index 75% rename from plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionTagResponse.java rename to plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationResponse.java index 52d1d0cdf58..9bb587d9f0e 100644 --- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionTagResponse.java +++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcPublicationResponse.java @@ -18,24 +18,21 @@ */ package org.apache.plc4x.java.api.messages; -import org.apache.plc4x.java.api.model.PlcSubscriptionTag; +import org.apache.plc4x.java.api.model.PlcPublicationTag; import org.apache.plc4x.java.api.types.PlcResponseCode; import java.util.Collection; -/** - * Base type for all response messages sent as response for a prior request - * from a plc to the plc4x system. - */ -public interface PlcSubscriptionTagResponse extends PlcResponse { +public interface PlcPublicationResponse extends PlcResponse { @Override - PlcSubscriptionTagRequest getRequest(); + PlcPublicationRequest getRequest(); Collection getTagNames(); - PlcSubscriptionTag getTag(String name); + PlcPublicationTag getTag(String name); PlcResponseCode getResponseCode(String name); + } 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 0573e2b13c0..7afe61844eb 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 @@ -24,5 +24,7 @@ * Base type for all messages sent from the plc4x system to a connected plc. */ public interface PlcRequest extends PlcMessage { + CompletableFuture execute(); + } 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 a87a14696c8..7959cae782f 100644 --- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionRequest.java +++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcSubscriptionRequest.java @@ -18,18 +18,32 @@ */ package org.apache.plc4x.java.api.messages; -import org.apache.plc4x.java.api.model.PlcConsumerRegistration; +import org.apache.plc4x.java.api.model.PlcSubscriptionTag; import org.apache.plc4x.java.api.model.PlcTag; import java.time.Duration; +import java.util.LinkedHashSet; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; -public interface PlcSubscriptionRequest extends PlcSubscriptionTagRequest { +public interface PlcSubscriptionRequest extends PlcRequest { @Override CompletableFuture execute(); + CompletableFuture executeWithConsumer(Consumer subscriptionConsumer); + + int getNumberOfTags(); + + LinkedHashSet getTagNames(); + + PlcSubscriptionTag getTag(String name); + + List getTags(); + + List> getConsumers(); + interface Builder extends PlcRequestBuilder { @Override @@ -99,18 +113,6 @@ interface Builder extends PlcRequestBuilder { */ PlcSubscriptionRequest.Builder addEventTag(String name, PlcTag tag); - /** - * Convenience method which attaches the {@link Consumer} directly to the handles once the - * requests succeeds. - * Note: opposed to register on the {@link org.apache.plc4x.java.api.model.PlcSubscriptionHandle} directly you - * won't retrieve a {@link PlcConsumerRegistration} which is useful to cancel registrations. - * - * @param name alias of the tag. - * @param preRegisteredConsumer {@link Consumer} to be attached - * @return builder. - */ - PlcSubscriptionRequest.Builder addPreRegisteredConsumer(String name, Consumer preRegisteredConsumer); - } } 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 3aa32a21a42..9eb7a28f94f 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 @@ -18,26 +18,25 @@ */ package org.apache.plc4x.java.api.messages; -import org.apache.plc4x.java.api.model.PlcSubscriptionHandle; +import org.apache.plc4x.java.api.model.PlcSubscriptionTag; +import org.apache.plc4x.java.api.types.PlcResponseCode; import java.util.Collection; +import java.util.function.Consumer; -public interface PlcSubscriptionResponse extends PlcSubscriptionTagResponse { +public interface PlcSubscriptionResponse extends PlcResponse { @Override PlcSubscriptionRequest getRequest(); - /** - * Returns a {@link PlcSubscriptionHandle} associated with a {@code name} from {@link PlcSubscriptionRequest#getTag(String)} - * - * @param name the tag name which a {@link PlcSubscriptionHandle} is required to - * @return a {@link PlcSubscriptionHandle} - */ - PlcSubscriptionHandle getSubscriptionHandle(String name); - - /** - * @return all {@link PlcSubscriptionHandle}s - */ - Collection getSubscriptionHandles(); + PlcUnsubscriptionRequest getUnsubscriptionRequest(); + + Collection getTagNames(); + + PlcSubscriptionTag getTag(String name); + + PlcResponseCode getResponseCode(String name); + + void registerConsumer(Consumer subscriptionConsumer); } 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 cb4a77856c4..0a060b09f42 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,45 +18,11 @@ */ package org.apache.plc4x.java.api.messages; -import org.apache.plc4x.java.api.model.PlcSubscriptionHandle; - -import java.util.Collection; -import java.util.List; import java.util.concurrent.CompletableFuture; public interface PlcUnsubscriptionRequest extends PlcRequest { - List getSubscriptionHandles(); - @Override CompletableFuture execute(); - interface Builder extends PlcRequestBuilder { - - @Override - PlcUnsubscriptionRequest build(); - - /** - * {@link PlcSubscriptionHandle} that should be removed from the subscription - * - * @param plcSubscriptionHandle {@link PlcSubscriptionHandle} to be removed - */ - PlcUnsubscriptionRequest.Builder addHandles(PlcSubscriptionHandle plcSubscriptionHandle); - - /** - * {@link PlcSubscriptionHandle}s that should be removed from the subscription - * - * @param plcSubscriptionHandle1 {@link PlcSubscriptionHandle} to be removed - * @param plcSubscriptionHandles {@link PlcSubscriptionHandle} to be removed - */ - PlcUnsubscriptionRequest.Builder addHandles(PlcSubscriptionHandle plcSubscriptionHandle1, PlcSubscriptionHandle... plcSubscriptionHandles); - - /** - * {@link PlcSubscriptionHandle}s that should be removed from the subscription - * - * @param plcSubscriptionHandle {@link PlcSubscriptionHandle} to be removed - */ - PlcUnsubscriptionRequest.Builder addHandles(Collection plcSubscriptionHandle); - } - } diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcSubscriptionHandle.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcPublicationHandle.java similarity index 59% rename from plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcSubscriptionHandle.java rename to plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcPublicationHandle.java index 0a77daee66a..c17e72b33e7 100644 --- a/plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcSubscriptionHandle.java +++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcPublicationHandle.java @@ -18,27 +18,26 @@ */ package org.apache.plc4x.java.api.model; +import org.apache.plc4x.java.api.messages.PlcPublicationEventRequest; +import org.apache.plc4x.java.api.messages.PlcPublicationEventResponse; import org.apache.plc4x.java.api.messages.PlcSubscriptionEvent; import java.util.function.Consumer; /** - * When subscribing to remote resources, depending on the used protocol - * different data is used to identify a subscription. This interface is + * When publishing data to remote resources, depending on the used protocol + * different data is used to identify a publication. This interface is * to be implemented in the individual Driver implementations to contain - * all information needed to pull or unsubscribe any form of subscription. - *

- * For every subscribed item, a separate {@link PlcSubscriptionHandle} object is - * returned in order to allow fine granular un-subscriptions. + * all information needed to publish data or to unsubscribe any form of publication. */ -public interface PlcSubscriptionHandle { +public interface PlcPublicationHandle { /** - * Registers a given consumer for the events emitted by the current subscription handle. + * Allows publishing events to the registered consumer.. * - * @param consumer consumer - * @return consumer registration + * @param publicationEvent publication event containing the data we want to publish. + * @return PlcPublicationEventResponse response of the publication. */ - PlcConsumerRegistration register(Consumer consumer); + PlcPublicationEventResponse publish(PlcPublicationEventRequest publicationEvent); } diff --git a/plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcPublicationTag.java b/plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcPublicationTag.java new file mode 100644 index 00000000000..192295ed8be --- /dev/null +++ b/plc4j/api/src/main/java/org/apache/plc4x/java/api/model/PlcPublicationTag.java @@ -0,0 +1,24 @@ +/* + * 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 + * + * https://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.model; + + +public interface PlcPublicationTag extends PlcTag { + +} diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/S7PlcSubscriptionRequest.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/S7PlcSubscriptionRequest.java index a0c06cb6cfe..a3a0460d894 100644 --- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/S7PlcSubscriptionRequest.java +++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/S7PlcSubscriptionRequest.java @@ -61,7 +61,7 @@ public S7PlcSubscriptionRequest(PlcSubscriber subscriber, } @Override - public CompletableFuture execute() { + public CompletableFuture execute(Consumer subscriptionConsumer) { return subscriber.subscribe(this); } diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionRequest.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionRequest.java index 7264b78209a..534a7a5db00 100644 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionRequest.java +++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionRequest.java @@ -54,7 +54,7 @@ public DefaultPlcSubscriptionRequest(PlcSubscriber subscriber, } @Override - public CompletableFuture execute() { + public CompletableFuture execute(Consumer subscriptionConsumer) { return subscriber.subscribe(this); } diff --git a/plc4j/tools/connection-cache/src/main/java/org/apache/plc4x/java/utils/cache/LeasedPlcConnection.java b/plc4j/tools/connection-cache/src/main/java/org/apache/plc4x/java/utils/cache/LeasedPlcConnection.java index d400e386d81..4edde2a6b77 100644 --- a/plc4j/tools/connection-cache/src/main/java/org/apache/plc4x/java/utils/cache/LeasedPlcConnection.java +++ b/plc4j/tools/connection-cache/src/main/java/org/apache/plc4x/java/utils/cache/LeasedPlcConnection.java @@ -265,7 +265,7 @@ public PlcSubscriptionRequest build() { PlcSubscriptionRequest innerPlcSubscriptionRequest = innerBuilder.build(); return new PlcSubscriptionRequest() { @Override - public CompletableFuture execute() { + public CompletableFuture execute(Consumer subscriptionConsumer) { CompletableFuture future = innerPlcSubscriptionRequest.execute(); final CompletableFuture responseFuture = new CompletableFuture<>(); future.handle((plcSubscriptionResponse, throwable)->{