use of org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionResponse in project milo by eclipse.
the class SubscriptionManager method createSubscription.
public void createSubscription(ServiceRequest service) {
CreateSubscriptionRequest request = (CreateSubscriptionRequest) service.getRequest();
UInteger subscriptionId = nextSubscriptionId();
Subscription subscription = new Subscription(this, subscriptionId, request.getRequestedPublishingInterval(), request.getRequestedMaxKeepAliveCount().longValue(), request.getRequestedLifetimeCount().longValue(), request.getMaxNotificationsPerPublish().longValue(), request.getPublishingEnabled(), request.getPriority().intValue());
subscriptions.put(subscriptionId, subscription);
server.getSubscriptions().put(subscriptionId, subscription);
server.getDiagnosticsSummary().getCumulatedSubscriptionCount().increment();
server.getEventBus().post(new SubscriptionCreatedEvent(subscription));
subscription.setStateListener((s, ps, cs) -> {
if (cs == State.Closed) {
subscriptions.remove(s.getId());
server.getSubscriptions().remove(s.getId());
server.getEventBus().post(new SubscriptionDeletedEvent(subscription));
}
});
subscription.startPublishingTimer();
ResponseHeader header = service.createResponseHeader();
CreateSubscriptionResponse response = new CreateSubscriptionResponse(header, subscriptionId, subscription.getPublishingInterval(), uint(subscription.getLifetimeCount()), uint(subscription.getMaxKeepAliveCount()));
service.setResponse(response);
}
use of org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionResponse 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