Search in sources :

Example 1 with MonitoringMode

use of org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode in project milo by eclipse.

the class BatchSetMonitoringMode method setMonitoringModeAsync.

private CompletableFuture<List<SetMonitoringModeResult>> setMonitoringModeAsync(List<Map.Entry<OpcUaMonitoredItem, MonitoringMode>> itemsAndModes) {
    serviceInvocationCount.incrementAndGet();
    MonitoringMode monitoringMode = itemsAndModes.get(0).getValue();
    List<UaMonitoredItem> items = itemsAndModes.stream().map(Map.Entry::getKey).collect(Collectors.toList());
    CompletableFuture<List<SetMonitoringModeResult>> resultsFuture = subscription.setMonitoringMode(monitoringMode, items).thenApply(statusCodes -> statusCodes.stream().map(statusCode -> new SetMonitoringModeResult(StatusCode.GOOD, statusCode)).collect(Collectors.toList()));
    return resultsFuture.exceptionally(ex -> {
        StatusCode serviceResult = UaException.extractStatusCode(ex).orElse(new StatusCode(StatusCodes.Bad_UnexpectedError));
        SetMonitoringModeResult result = new SetMonitoringModeResult(serviceResult);
        return Collections.nCopies(items.size(), result);
    });
}
Also used : UaMonitoredItem(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) MonitoringMode(org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode)

Example 2 with MonitoringMode

use of org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode 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)

Example 3 with MonitoringMode

use of org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode in project milo by eclipse.

the class TriggeringExample method createMonitoredItem.

private UaMonitoredItem createMonitoredItem(UaSubscription subscription, ReadValueId readValueId, MonitoringMode monitoringMode) throws ExecutionException, InterruptedException {
    // important: client handle must be unique per item
    UInteger clientHandle = uint(clientHandles.getAndIncrement());
    MonitoringParameters parameters = new MonitoringParameters(clientHandle, 1000.0, null, uint(10), true);
    MonitoredItemCreateRequest request = new MonitoredItemCreateRequest(readValueId, monitoringMode, parameters);
    UaSubscription.ItemCreationCallback onItemCreated = (item, id) -> item.setValueConsumer(this::onSubscriptionValue);
    List<UaMonitoredItem> items = subscription.createMonitoredItems(TimestampsToReturn.Both, newArrayList(request), onItemCreated).get();
    return items.get(0);
}
Also used : MonitoringMode(org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Logger(org.slf4j.Logger) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) MonitoredItemCreateRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) UaSubscription(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) UaMonitoredItem(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) UaMonitoredItem(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem) UaSubscription(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription) MonitoredItemCreateRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters)

Aggregations

MonitoringMode (org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode)3 List (java.util.List)2 UaMonitoredItem (org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem)2 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 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 OpcUaClient (org.eclipse.milo.opcua.sdk.client.OpcUaClient)1 UaSubscription (org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription)1 MonitoredItem (org.eclipse.milo.opcua.sdk.server.api.MonitoredItem)1 BaseMonitoredItem (org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem)1 AttributeId (org.eclipse.milo.opcua.stack.core.AttributeId)1 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)1 UaException (org.eclipse.milo.opcua.stack.core.UaException)1