Search in sources :

Example 1 with DeleteMonitoredItemsRequest

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

the class SubscriptionManager method deleteMonitoredItems.

public void deleteMonitoredItems(ServiceRequest service) throws UaException {
    DeleteMonitoredItemsRequest request = (DeleteMonitoredItemsRequest) service.getRequest();
    UInteger subscriptionId = request.getSubscriptionId();
    Subscription subscription = subscriptions.get(subscriptionId);
    List<UInteger> itemsToDelete = l(request.getMonitoredItemIds());
    if (subscription == null) {
        throw new UaException(StatusCodes.Bad_SubscriptionIdInvalid);
    }
    if (itemsToDelete.isEmpty()) {
        throw new UaException(StatusCodes.Bad_NothingToDo);
    }
    StatusCode[] deleteResults = new StatusCode[itemsToDelete.size()];
    List<BaseMonitoredItem<?>> deletedItems = newArrayListWithCapacity(itemsToDelete.size());
    synchronized (subscription) {
        for (int i = 0; i < itemsToDelete.size(); i++) {
            UInteger itemId = itemsToDelete.get(i);
            BaseMonitoredItem<?> item = subscription.getMonitoredItems().get(itemId);
            if (item == null) {
                deleteResults[i] = new StatusCode(StatusCodes.Bad_MonitoredItemIdInvalid);
            } else {
                deletedItems.add(item);
                deleteResults[i] = StatusCode.GOOD;
            }
        }
        subscription.removeMonitoredItems(deletedItems);
    }
    /*
         * Notify AddressSpaces of the items that have been deleted.
         */
    byMonitoredItemType(deletedItems, dataItems -> server.getAddressSpaceManager().onDataItemsDeleted(dataItems), eventItems -> server.getAddressSpaceManager().onEventItemsDeleted(eventItems));
    /*
         * Build and return results.
         */
    ResponseHeader header = service.createResponseHeader();
    DeleteMonitoredItemsResponse response = new DeleteMonitoredItemsResponse(header, deleteResults, new DiagnosticInfo[0]);
    service.setResponse(response);
}
Also used : DeleteMonitoredItemsResponse(org.eclipse.milo.opcua.stack.core.types.structured.DeleteMonitoredItemsResponse) 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) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) DeleteMonitoredItemsRequest(org.eclipse.milo.opcua.stack.core.types.structured.DeleteMonitoredItemsRequest) 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 DeleteMonitoredItemsRequest (org.eclipse.milo.opcua.stack.core.types.structured.DeleteMonitoredItemsRequest)1 DeleteMonitoredItemsResponse (org.eclipse.milo.opcua.stack.core.types.structured.DeleteMonitoredItemsResponse)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1