sruehl commented on a change in pull request #14: WIP: Api Refactoring
URL: https://github.com/apache/incubator-plc4x/pull/14#discussion_r213965185
##########
File path:
integrations/apache-camel/src/main/java/org/apache/plc4x/camel/Plc4XConsumer.java
##########
@@ -84,22 +79,29 @@ public void setExceptionHandler(ExceptionHandler
exceptionHandler) {
}
@Override
- protected void doStart() throws InterruptedException, ExecutionException,
TimeoutException {
- PlcSubscriptionRequest request = new PlcSubscriptionRequest();
- @SuppressWarnings("unchecked")
- SubscriptionRequestCyclicItem subscriptionRequestCyclicItem = new
SubscriptionRequestCyclicItem(dataType, address, TimeUnit.SECONDS, 3, this);
- request.addItem(subscriptionRequestCyclicItem);
+ protected void doStart() throws InterruptedException, ExecutionException,
TimeoutException, PlcException {
+ PlcSubscriber plcSubscriber =
plcConnection.getSubscriber().orElseThrow(
+ () -> new PlcException("Connection doesn't support
subscriptions."));
+ // TODO: Is it correct to only support one field?
+ PlcSubscriptionRequest request =
plcSubscriber.subscriptionRequestBuilder()
+ .addCyclicField("default", fieldQuery, Duration.of(3,
ChronoUnit.SECONDS)).build();
CompletableFuture<PlcSubscriptionResponse> subscriptionFuture =
getSubscriber().subscribe(request);
subscriptionResponse = subscriptionFuture.get(5, TimeUnit.SECONDS);
}
@Override
- protected void doStop() {
- PlcUnsubscriptionRequest request = new PlcUnsubscriptionRequest();
- subscriptionResponse.getResponseItems().stream()
- .map(SubscriptionResponseItem::getSubscriptionHandle)
- .map(UnsubscriptionRequestItem::new)
- .forEach(request::addItem);
+ protected void doStop() throws InterruptedException, ExecutionException,
TimeoutException, PlcException {
+ PlcSubscriber plcSubscriber =
plcConnection.getSubscriber().orElseThrow(
+ () -> new PlcException("Connection doesn't support
subscriptions."));
+ PlcUnsubscriptionRequest.Builder builder =
plcSubscriber.unsubscriptionRequestBuilder();
+ // For every field we subscribed for, now unsubscribe.
+ subscriptionResponse.getFieldNames().forEach(fieldName -> {
Review comment:
maybe this can be moved into the unsubscription builder so we don't repeat
that code everywhere.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services