Search in sources :

Example 1 with CreateSubscriptionRequest

use of org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionRequest 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);
}
Also used : ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) CreateSubscriptionRequest(org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionRequest) CreateSubscriptionResponse(org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionResponse)

Aggregations

UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)1 CreateSubscriptionRequest (org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionRequest)1 CreateSubscriptionResponse (org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionResponse)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1