Search in sources :

Example 1 with SetMonitoringModeResponse

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

the class OpcUaSubscription method setMonitoringMode.

@Override
public CompletableFuture<List<StatusCode>> setMonitoringMode(MonitoringMode monitoringMode, List<UaMonitoredItem> items) {
    List<UInteger> monitoredItemIds = items.stream().map(UaMonitoredItem::getMonitoredItemId).collect(Collectors.toList());
    CompletableFuture<SetMonitoringModeResponse> future = client.setMonitoringMode(subscriptionId, monitoringMode, monitoredItemIds);
    return future.thenApply(response -> {
        List<StatusCode> results = l(response.getResults());
        for (int i = 0; i < monitoredItemIds.size(); i++) {
            UInteger id = monitoredItemIds.get(i);
            OpcUaMonitoredItem item = itemsByServerHandle.get(id);
            StatusCode result = results.get(i);
            if (result.isGood() && item != null) {
                item.setMonitoringMode(monitoringMode);
            }
        }
        return results;
    });
}
Also used : SetMonitoringModeResponse(org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeResponse) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)

Example 2 with SetMonitoringModeResponse

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

the class SubscriptionManager method setMonitoringMode.

public void setMonitoringMode(ServiceRequest service) {
    SetMonitoringModeRequest request = (SetMonitoringModeRequest) service.getRequest();
    UInteger subscriptionId = request.getSubscriptionId();
    try {
        Subscription subscription = subscriptions.get(subscriptionId);
        List<UInteger> itemsToModify = l(request.getMonitoredItemIds());
        if (subscription == null) {
            throw new UaException(StatusCodes.Bad_SubscriptionIdInvalid);
        }
        if (itemsToModify.isEmpty()) {
            throw new UaException(StatusCodes.Bad_NothingToDo);
        }
        /*
             * Set MonitoringMode on each monitored item, if it exists.
             */
        MonitoringMode monitoringMode = request.getMonitoringMode();
        StatusCode[] results = new StatusCode[itemsToModify.size()];
        List<MonitoredItem> modified = newArrayListWithCapacity(itemsToModify.size());
        for (int i = 0; i < itemsToModify.size(); i++) {
            UInteger itemId = itemsToModify.get(i);
            BaseMonitoredItem<?> item = subscription.getMonitoredItems().get(itemId);
            if (item != null) {
                item.setMonitoringMode(monitoringMode);
                modified.add(item);
                results[i] = StatusCode.GOOD;
            } else {
                results[i] = new StatusCode(StatusCodes.Bad_MonitoredItemIdInvalid);
            }
        }
        /*
             * Notify AddressSpace of the items whose MonitoringMode has been modified.
             */
        server.getAddressSpaceManager().onMonitoringModeChanged(modified);
        /*
             * Build and return results.
             */
        ResponseHeader header = service.createResponseHeader();
        SetMonitoringModeResponse response = new SetMonitoringModeResponse(header, results, new DiagnosticInfo[0]);
        service.setResponse(response);
    } catch (UaException e) {
        service.setServiceFault(e);
    }
}
Also used : ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) SetMonitoringModeResponse(org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeResponse) UaException(org.eclipse.milo.opcua.stack.core.UaException) SetMonitoringModeRequest(org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeRequest) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) MonitoredItem(org.eclipse.milo.opcua.sdk.server.api.MonitoredItem) BaseMonitoredItem(org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) MonitoringMode(org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode)

Aggregations

StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)2 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)2 Unsigned.uint (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint)2 SetMonitoringModeResponse (org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeResponse)2 MonitoredItem (org.eclipse.milo.opcua.sdk.server.api.MonitoredItem)1 BaseMonitoredItem (org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem)1 UaException (org.eclipse.milo.opcua.stack.core.UaException)1 MonitoringMode (org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1 SetMonitoringModeRequest (org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeRequest)1