Search in sources :

Example 1 with DeleteSubscriptionsRequest

use of org.eclipse.milo.opcua.stack.core.types.structured.DeleteSubscriptionsRequest in project milo by eclipse.

the class SubscriptionManager method deleteSubscription.

public void deleteSubscription(ServiceRequest service) throws UaException {
    DeleteSubscriptionsRequest request = (DeleteSubscriptionsRequest) service.getRequest();
    List<UInteger> subscriptionIds = l(request.getSubscriptionIds());
    if (subscriptionIds.isEmpty()) {
        throw new UaException(StatusCodes.Bad_NothingToDo);
    }
    StatusCode[] results = new StatusCode[subscriptionIds.size()];
    for (int i = 0; i < subscriptionIds.size(); i++) {
        UInteger subscriptionId = subscriptionIds.get(i);
        Subscription subscription = subscriptions.remove(subscriptionId);
        if (subscription != null) {
            server.getSubscriptions().remove(subscription.getId());
            server.getEventBus().post(new SubscriptionDeletedEvent(subscription));
            List<BaseMonitoredItem<?>> deletedItems = subscription.deleteSubscription();
            /*
                 * Notify AddressSpaces of the items we just deleted.
                 */
            byMonitoredItemType(deletedItems, dataItems -> server.getAddressSpaceManager().onDataItemsDeleted(dataItems), eventItems -> server.getAddressSpaceManager().onEventItemsDeleted(eventItems));
            results[i] = StatusCode.GOOD;
        } else {
            results[i] = new StatusCode(StatusCodes.Bad_SubscriptionIdInvalid);
        }
    }
    ResponseHeader header = service.createResponseHeader();
    DeleteSubscriptionsResponse response = new DeleteSubscriptionsResponse(header, results, new DiagnosticInfo[0]);
    service.setResponse(response);
    while (subscriptions.isEmpty() && publishQueue.isNotEmpty()) {
        ServiceRequest publishService = publishQueue.poll();
        if (publishService != null) {
            publishService.setServiceFault(StatusCodes.Bad_NoSubscription);
        }
    }
}
Also used : ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) BaseMonitoredItem(org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem) UaException(org.eclipse.milo.opcua.stack.core.UaException) DeleteSubscriptionsResponse(org.eclipse.milo.opcua.stack.core.types.structured.DeleteSubscriptionsResponse) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) DeleteSubscriptionsRequest(org.eclipse.milo.opcua.stack.core.types.structured.DeleteSubscriptionsRequest) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)

Aggregations

BaseMonitoredItem (org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem)1 UaException (org.eclipse.milo.opcua.stack.core.UaException)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)1 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)1 DeleteSubscriptionsRequest (org.eclipse.milo.opcua.stack.core.types.structured.DeleteSubscriptionsRequest)1 DeleteSubscriptionsResponse (org.eclipse.milo.opcua.stack.core.types.structured.DeleteSubscriptionsResponse)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1 ServiceRequest (org.eclipse.milo.opcua.stack.server.services.ServiceRequest)1