Skip to content

Commit

Permalink
fix: Updated the subscription API to match the changes of the others (#…
Browse files Browse the repository at this point in the history
…1803)

* fix: Updated the subscription API to match the changes of the Read- and Write-API. Also replaced the single-item handlers with an all items handler.

* fix: Made the serial channel more robust against NPEs.

* refactor: Updated the way consumers are registered in subscription requests.

* docs: Updated the RELEASE_NOTES about the changed subscription API.

* chore: Update knx manufacturer ids.

* fix: Update the handling of PlcValues in the simulated driver.
  • Loading branch information
chrisdutz authored Oct 10, 2024
1 parent 667ad1f commit d4f089f
Show file tree
Hide file tree
Showing 34 changed files with 561 additions and 245 deletions.
18 changes: 12 additions & 6 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ Incompatible changes
efficient PlcRawByteArray type is used, that gives users
direct access to the bytes returned from the PLC instead of
a list of PlcValues.
- The builders for read- and write-requests now process tags
and values on a per-field level. If one field has an invalid
address it will now only fail the one item related to that.
Same applies to values. Only the tag who's value was invalid
will be considered failed and no longer an exception should
be thrown.
- The builders for read-, write- ans subscription.requests now
process tags and values on a per-field level. If one field
has an invalid address it will now only fail the one item
related to that. Same applies to values. Only the tag who's
value was invalid will be considered failed and no longer an
exception should be thrown.
- Subscription-requests now allow registering a handler for
all fields in the subscription.
- The addPreRegisteredConsumer method was removed and versions
of the "addXYZ" methods were added, that allow providing
individual consumers for each tag.


Bug Fixes
---------
Expand Down
26 changes: 21 additions & 5 deletions plc4go/protocols/knxnetip/readwrite/model/KnxManufacturer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.plc4x.java.api.messages;

import org.apache.plc4x.java.api.model.PlcConsumerRegistration;
import org.apache.plc4x.java.api.model.PlcTag;

import java.time.Duration;
Expand All @@ -35,6 +34,14 @@ interface Builder extends PlcRequestBuilder {
@Override
PlcSubscriptionRequest build();

/**
* Define the consumer that will be receiving subscription events for all tags of this request.
*
* @param consumer Consumer
* @return builder.
*/
PlcSubscriptionRequest.Builder setConsumer(Consumer<PlcSubscriptionEvent> consumer);

/**
* Adds a new tag to the to be constructed request which should be polled cyclically.
*
Expand All @@ -45,6 +52,17 @@ interface Builder extends PlcRequestBuilder {
*/
PlcSubscriptionRequest.Builder addCyclicTagAddress(String name, String tagAddress, Duration pollingInterval);

/**
* Adds a new tag to the to be constructed request which should be polled cyclically.
*
* @param name alias of the tag.
* @param tagAddress tag address string for accessing the tag.
* @param pollingInterval interval, in which the tag should be polled.
* @param consumer consumer for receiving update events for a given tag only.
* @return builder.
*/
PlcSubscriptionRequest.Builder addCyclicTagAddress(String name, String tagAddress, Duration pollingInterval, Consumer<PlcSubscriptionEvent> consumer);

/**
* Adds a new tag to the to be constructed request which should be polled cyclically.
*
Expand All @@ -55,6 +73,17 @@ interface Builder extends PlcRequestBuilder {
*/
PlcSubscriptionRequest.Builder addCyclicTag(String name, PlcTag tag, Duration pollingInterval);

/**
* Adds a new tag to the to be constructed request which should be polled cyclically.
*
* @param name alias of the tag.
* @param tag tag instance for accessing the tag.
* @param pollingInterval interval, in which the tag should be polled.
* @param consumer consumer for receiving update events for a given tag only.
* @return builder.
*/
PlcSubscriptionRequest.Builder addCyclicTag(String name, PlcTag tag, Duration pollingInterval, Consumer<PlcSubscriptionEvent> consumer);

/**
* Adds a new tag to the to be constructed request which should be updated as soon as
* a value changes in the PLC.
Expand All @@ -65,6 +94,17 @@ interface Builder extends PlcRequestBuilder {
*/
PlcSubscriptionRequest.Builder addChangeOfStateTagAddress(String name, String tagAddress);

/**
* Adds a new tag to the to be constructed request which should be updated as soon as
* a value changes in the PLC.
*
* @param name alias of the tag.
* @param tagAddress tag address string for accessing the tag.
* @param consumer consumer for receiving update events for a given tag only.
* @return builder.
*/
PlcSubscriptionRequest.Builder addChangeOfStateTagAddress(String name, String tagAddress, Consumer<PlcSubscriptionEvent> consumer);

/**
* Adds a new tag to the to be constructed request which should be updated as soon as
* a value changes in the PLC.
Expand All @@ -75,6 +115,17 @@ interface Builder extends PlcRequestBuilder {
*/
PlcSubscriptionRequest.Builder addChangeOfStateTag(String name, PlcTag tag);

/**
* Adds a new tag to the to be constructed request which should be updated as soon as
* a value changes in the PLC.
*
* @param name alias of the tag.
* @param tag tag instance for accessing the tag.
* @param consumer consumer for receiving update events for a given tag only.
* @return builder.
*/
PlcSubscriptionRequest.Builder addChangeOfStateTag(String name, PlcTag tag, Consumer<PlcSubscriptionEvent> consumer);

/**
* Adds a new subscription to the to be constructed request which should be updated
* as soon as an event occurs.
Expand All @@ -87,6 +138,19 @@ interface Builder extends PlcRequestBuilder {
*/
PlcSubscriptionRequest.Builder addEventTagAddress(String name, String tagAddress);

/**
* Adds a new subscription to the to be constructed request which should be updated
* as soon as an event occurs.
* <p>
* 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 tag.
* @param tagAddress tag address string for accessing the tag.
* @param consumer consumer for receiving update events for a given tag only.
* @return builder.
*/
PlcSubscriptionRequest.Builder addEventTagAddress(String name, String tagAddress, Consumer<PlcSubscriptionEvent> consumer);

/**
* Adds a new subscription to the to be constructed request which should be updated
* as soon as an event occurs.
Expand All @@ -100,16 +164,17 @@ interface Builder extends PlcRequestBuilder {
PlcSubscriptionRequest.Builder addEventTag(String name, PlcTag tag);

/**
* Convenience method which attaches the {@link Consumer<PlcSubscriptionEvent>} 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.
* Adds a new subscription to the to be constructed request which should be updated
* as soon as an event occurs.
* <p>
* 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 tag.
* @param preRegisteredConsumer {@link Consumer<PlcSubscriptionEvent>} to be attached
* @param name alias of the tag.
* @param tag tag instance for accessing the tag.
* @param consumer consumer for receiving update events for a given tag only.
* @return builder.
*/
PlcSubscriptionRequest.Builder addPreRegisteredConsumer(String name, Consumer<PlcSubscriptionEvent> preRegisteredConsumer);
PlcSubscriptionRequest.Builder addEventTag(String name, PlcTag tag, Consumer<PlcSubscriptionEvent> consumer);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
package org.apache.plc4x.java.api.messages;

import org.apache.plc4x.java.api.model.PlcSubscriptionTag;
import org.apache.plc4x.java.api.types.PlcResponseCode;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

Expand All @@ -35,10 +35,14 @@ public interface PlcSubscriptionTagRequest extends PlcRequest {

LinkedHashSet<String> getTagNames();

PlcResponseCode getTagResponseCode(String tagName);

PlcSubscriptionTag getTag(String name);

List<PlcSubscriptionTag> getTags();

Map<String, List<Consumer<PlcSubscriptionEvent>>> getPreRegisteredConsumers();
Consumer<PlcSubscriptionEvent> getConsumer();

Consumer<PlcSubscriptionEvent> getTagConsumer(String name);

}
Loading

0 comments on commit d4f089f

Please sign in to comment.