use of org.eclipse.milo.opcua.stack.core.types.structured.ModifySubscriptionResponse in project milo by eclipse.
the class SubscriptionManager method modifySubscription.
public void modifySubscription(ServiceRequest service) throws UaException {
ModifySubscriptionRequest request = (ModifySubscriptionRequest) service.getRequest();
UInteger subscriptionId = request.getSubscriptionId();
Subscription subscription = subscriptions.get(subscriptionId);
if (subscription == null) {
throw new UaException(StatusCodes.Bad_SubscriptionIdInvalid);
}
subscription.modifySubscription(request);
ResponseHeader header = service.createResponseHeader();
ModifySubscriptionResponse response = new ModifySubscriptionResponse(header, subscription.getPublishingInterval(), uint(subscription.getLifetimeCount()), uint(subscription.getMaxKeepAliveCount()));
service.setResponse(response);
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ModifySubscriptionResponse in project milo by eclipse.
the class OpcUaSubscriptionManager method modifySubscription.
@Override
public CompletableFuture<UaSubscription> modifySubscription(UInteger subscriptionId, double requestedPublishingInterval, BiFunction<Double, UInteger, UInteger> getLifetimeCount, Function<Double, UInteger> getMaxKeepAliveCount, UInteger maxNotificationsPerPublish, UByte priority) {
OpcUaSubscription subscription = subscriptions.get(subscriptionId);
if (subscription == null) {
return failedUaFuture(StatusCodes.Bad_SubscriptionIdInvalid);
}
UInteger requestedMaxKeepAliveCount = getMaxKeepAliveCount.apply(requestedPublishingInterval);
UInteger requestedLifetimeCount = getLifetimeCount.apply(requestedPublishingInterval, requestedMaxKeepAliveCount);
CompletableFuture<ModifySubscriptionResponse> future = client.modifySubscription(subscriptionId, requestedPublishingInterval, requestedLifetimeCount, requestedMaxKeepAliveCount, maxNotificationsPerPublish, priority);
return future.thenCompose(response -> {
subscription.setRequestedPublishingInterval(requestedPublishingInterval);
subscription.setRequestedLifetimeCount(requestedLifetimeCount);
subscription.setRequestedMaxKeepAliveCount(requestedMaxKeepAliveCount);
subscription.setRevisedPublishingInterval(response.getRevisedPublishingInterval());
subscription.setRevisedLifetimeCount(response.getRevisedLifetimeCount());
subscription.setRevisedMaxKeepAliveCount(response.getRevisedMaxKeepAliveCount());
subscription.setMaxNotificationsPerPublish(maxNotificationsPerPublish);
subscription.setPriority(priority);
double revisedPublishingInterval = response.getRevisedPublishingInterval();
UInteger newMaxKeepAliveCount = getMaxKeepAliveCount.apply(revisedPublishingInterval);
if (requestedPublishingInterval != revisedPublishingInterval && !requestedMaxKeepAliveCount.equals(newMaxKeepAliveCount)) {
UInteger newLifetimeCount = getLifetimeCount.apply(revisedPublishingInterval, newMaxKeepAliveCount);
CompletableFuture<ModifySubscriptionResponse> modifyFuture = client.modifySubscription(subscriptionId, revisedPublishingInterval, newLifetimeCount, newMaxKeepAliveCount, maxNotificationsPerPublish, priority);
return modifyFuture.thenApply(modifyResponse -> {
subscription.setRequestedLifetimeCount(newLifetimeCount);
subscription.setRequestedMaxKeepAliveCount(newMaxKeepAliveCount);
subscription.setRevisedPublishingInterval(modifyResponse.getRevisedPublishingInterval());
subscription.setRevisedLifetimeCount(modifyResponse.getRevisedLifetimeCount());
subscription.setRevisedMaxKeepAliveCount(modifyResponse.getRevisedMaxKeepAliveCount());
WatchdogTimer watchdogTimer = watchdogTimers.remove(subscriptionId);
if (watchdogTimer != null)
watchdogTimer.kick();
maybeSendPublishRequests();
return subscription;
});
} else {
WatchdogTimer watchdogTimer = watchdogTimers.remove(subscriptionId);
if (watchdogTimer != null)
watchdogTimer.kick();
maybeSendPublishRequests();
return completedFuture(subscription);
}
});
}
use of org.eclipse.milo.opcua.stack.core.types.structured.ModifySubscriptionResponse in project milo by eclipse.
the class OpcUaSubscriptionManager method createSubscription.
@Override
public CompletableFuture<UaSubscription> createSubscription(double requestedPublishingInterval, BiFunction<Double, UInteger, UInteger> getLifetimeCount, Function<Double, UInteger> getMaxKeepAliveCount, UInteger maxNotificationsPerPublish, boolean publishingEnabled, UByte priority) {
UInteger requestedMaxKeepAliveCount = getMaxKeepAliveCount.apply(requestedPublishingInterval);
UInteger requestedLifetimeCount = getLifetimeCount.apply(requestedPublishingInterval, requestedMaxKeepAliveCount);
CompletableFuture<CreateSubscriptionResponse> future = client.createSubscription(requestedPublishingInterval, requestedLifetimeCount, requestedMaxKeepAliveCount, maxNotificationsPerPublish, publishingEnabled, priority);
return future.thenCompose(response -> {
OpcUaSubscription subscription = new OpcUaSubscription(client, response.getSubscriptionId(), response.getRevisedPublishingInterval(), response.getRevisedLifetimeCount(), response.getRevisedMaxKeepAliveCount(), maxNotificationsPerPublish, publishingEnabled, priority);
subscription.setRequestedPublishingInterval(requestedPublishingInterval);
subscription.setRequestedLifetimeCount(requestedLifetimeCount);
subscription.setRequestedMaxKeepAliveCount(requestedMaxKeepAliveCount);
double revisedPublishingInterval = response.getRevisedPublishingInterval();
UInteger newMaxKeepAliveCount = getMaxKeepAliveCount.apply(revisedPublishingInterval);
if (requestedPublishingInterval != revisedPublishingInterval && !requestedMaxKeepAliveCount.equals(newMaxKeepAliveCount)) {
UInteger newLifetimeCount = getLifetimeCount.apply(revisedPublishingInterval, newMaxKeepAliveCount);
CompletableFuture<ModifySubscriptionResponse> modifyFuture = client.modifySubscription(response.getSubscriptionId(), revisedPublishingInterval, newLifetimeCount, newMaxKeepAliveCount, maxNotificationsPerPublish, priority);
return modifyFuture.thenApply(modifyResponse -> {
subscription.setRequestedLifetimeCount(newLifetimeCount);
subscription.setRequestedMaxKeepAliveCount(newMaxKeepAliveCount);
subscription.setRevisedPublishingInterval(modifyResponse.getRevisedPublishingInterval());
subscription.setRevisedLifetimeCount(modifyResponse.getRevisedLifetimeCount());
subscription.setRevisedMaxKeepAliveCount(modifyResponse.getRevisedMaxKeepAliveCount());
subscriptions.put(subscription.getSubscriptionId(), subscription);
WatchdogTimer watchdogTimer = new WatchdogTimer(subscription);
watchdogTimers.put(subscription.getSubscriptionId(), watchdogTimer);
watchdogTimer.kick();
maybeSendPublishRequests();
return subscription;
});
} else {
subscriptions.put(subscription.getSubscriptionId(), subscription);
WatchdogTimer watchdogTimer = new WatchdogTimer(subscription);
watchdogTimers.put(subscription.getSubscriptionId(), watchdogTimer);
watchdogTimer.kick();
maybeSendPublishRequests();
return completedFuture(subscription);
}
});
}
Aggregations