Search in sources :

Example 1 with MonitoredItemModifyRequest

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

the class SubscriptionManager method modifyMonitoredItems.

public void modifyMonitoredItems(ServiceRequest service) throws UaException {
    ModifyMonitoredItemsRequest request = (ModifyMonitoredItemsRequest) service.getRequest();
    UInteger subscriptionId = request.getSubscriptionId();
    Subscription subscription = subscriptions.get(subscriptionId);
    TimestampsToReturn timestamps = request.getTimestampsToReturn();
    List<MonitoredItemModifyRequest> itemsToModify = l(request.getItemsToModify());
    if (subscription == null) {
        throw new UaException(StatusCodes.Bad_SubscriptionIdInvalid);
    }
    if (timestamps == null) {
        throw new UaException(StatusCodes.Bad_TimestampsToReturnInvalid);
    }
    if (itemsToModify.isEmpty()) {
        throw new UaException(StatusCodes.Bad_NothingToDo);
    }
    List<NodeId> distinctNodeIds = itemsToModify.stream().map(item -> {
        UInteger itemId = item.getMonitoredItemId();
        BaseMonitoredItem<?> monitoredItem = subscription.getMonitoredItems().get(itemId);
        return monitoredItem != null ? monitoredItem.getReadValueId().getNodeId() : NodeId.NULL_VALUE;
    }).filter(NodeId::isNotNull).distinct().collect(toList());
    CompletableFuture<Map<NodeId, AttributeGroup>> attributesFuture = readMonitoringAttributes(distinctNodeIds);
    attributesFuture.thenAccept(attributeGroups -> {
        MonitoredItemModifyResult[] modifyResults = new MonitoredItemModifyResult[itemsToModify.size()];
        List<BaseMonitoredItem<?>> monitoredItems = new ArrayList<>();
        for (int i = 0; i < itemsToModify.size(); i++) {
            MonitoredItemModifyRequest modifyRequest = itemsToModify.get(i);
            try {
                BaseMonitoredItem<?> monitoredItem = modifyMonitoredItem(modifyRequest, timestamps, subscription, attributeGroups);
                monitoredItems.add(monitoredItem);
                modifyResults[i] = new MonitoredItemModifyResult(StatusCode.GOOD, monitoredItem.getSamplingInterval(), uint(monitoredItem.getQueueSize()), monitoredItem.getFilterResult());
            } catch (UaException e) {
                modifyResults[i] = new MonitoredItemModifyResult(e.getStatusCode(), 0.0, UInteger.MIN, null);
            }
        }
        subscription.resetLifetimeCounter();
        /*
             * Notify AddressSpaces of the items we just modified.
             */
        byMonitoredItemType(monitoredItems, dataItems -> server.getAddressSpaceManager().onDataItemsModified(dataItems), eventItems -> server.getAddressSpaceManager().onEventItemsModified(eventItems));
        /*
             * AddressSpaces have been notified; send response.
             */
        ResponseHeader header = service.createResponseHeader();
        ModifyMonitoredItemsResponse response = new ModifyMonitoredItemsResponse(header, modifyResults, new DiagnosticInfo[0]);
        service.setResponse(response);
    });
}
Also used : AttributeKey(io.netty.util.AttributeKey) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) ReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeServices.ReadContext) DeadbandType(org.eclipse.milo.opcua.stack.core.types.enumerated.DeadbandType) DataItem(org.eclipse.milo.opcua.sdk.server.api.DataItem) LoggerFactory(org.slf4j.LoggerFactory) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) PublishRequest(org.eclipse.milo.opcua.stack.core.types.structured.PublishRequest) MonitoredItemCreateRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) Map(java.util.Map) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) CreateSubscriptionResponse(org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionResponse) ModifySubscriptionRequest(org.eclipse.milo.opcua.stack.core.types.structured.ModifySubscriptionRequest) EnumSet(java.util.EnumSet) Reference(org.eclipse.milo.opcua.sdk.core.Reference) EventItem(org.eclipse.milo.opcua.sdk.server.api.EventItem) DataChangeFilter(org.eclipse.milo.opcua.stack.core.types.structured.DataChangeFilter) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) ModifyMonitoredItemsRequest(org.eclipse.milo.opcua.stack.core.types.structured.ModifyMonitoredItemsRequest) NumericRange(org.eclipse.milo.opcua.sdk.core.NumericRange) MonitoringFilter(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringFilter) RepublishResponse(org.eclipse.milo.opcua.stack.core.types.structured.RepublishResponse) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) SetPublishingModeResponse(org.eclipse.milo.opcua.stack.core.types.structured.SetPublishingModeResponse) SubscriptionAcknowledgement(org.eclipse.milo.opcua.stack.core.types.structured.SubscriptionAcknowledgement) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SetMonitoringModeRequest(org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeRequest) Stream(java.util.stream.Stream) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) StreamUtil.opt2stream(org.eclipse.milo.opcua.sdk.core.util.StreamUtil.opt2stream) DeleteSubscriptionsResponse(org.eclipse.milo.opcua.stack.core.types.structured.DeleteSubscriptionsResponse) CreateSubscriptionRequest(org.eclipse.milo.opcua.stack.core.types.structured.CreateSubscriptionRequest) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) MonitoringMode(org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode) State(org.eclipse.milo.opcua.sdk.server.subscriptions.Subscription.State) SetMonitoringModeResponse(org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeResponse) EventFilter(org.eclipse.milo.opcua.stack.core.types.structured.EventFilter) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) NotificationMessage(org.eclipse.milo.opcua.stack.core.types.structured.NotificationMessage) MonitoredEventItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredEventItem) CreateMonitoredItemsResponse(org.eclipse.milo.opcua.stack.core.types.structured.CreateMonitoredItemsResponse) RepublishRequest(org.eclipse.milo.opcua.stack.core.types.structured.RepublishRequest) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ModifyMonitoredItemsResponse(org.eclipse.milo.opcua.stack.core.types.structured.ModifyMonitoredItemsResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Session(org.eclipse.milo.opcua.sdk.server.Session) ArrayList(java.util.ArrayList) AccessLevel(org.eclipse.milo.opcua.sdk.core.AccessLevel) Lists(com.google.common.collect.Lists) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) DeleteSubscriptionsRequest(org.eclipse.milo.opcua.stack.core.types.structured.DeleteSubscriptionsRequest) SetTriggeringResponse(org.eclipse.milo.opcua.stack.core.types.structured.SetTriggeringResponse) DeleteMonitoredItemsRequest(org.eclipse.milo.opcua.stack.core.types.structured.DeleteMonitoredItemsRequest) DeleteMonitoredItemsResponse(org.eclipse.milo.opcua.stack.core.types.structured.DeleteMonitoredItemsResponse) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Logger(org.slf4j.Logger) Lists.newArrayListWithCapacity(com.google.common.collect.Lists.newArrayListWithCapacity) Iterator(java.util.Iterator) MonitoredDataItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredDataItem) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) MonitoredItemModifyResult(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyResult) UaSerializationException(org.eclipse.milo.opcua.stack.core.UaSerializationException) SetTriggeringRequest(org.eclipse.milo.opcua.stack.core.types.structured.SetTriggeringRequest) Maps(com.google.common.collect.Maps) Unsigned.ubyte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte) MonitoredItemCreateResult(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateResult) Consumer(java.util.function.Consumer) MonitoredItem(org.eclipse.milo.opcua.sdk.server.api.MonitoredItem) CreateMonitoredItemsRequest(org.eclipse.milo.opcua.stack.core.types.structured.CreateMonitoredItemsRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) BaseMonitoredItem(org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem) SetPublishingModeRequest(org.eclipse.milo.opcua.stack.core.types.structured.SetPublishingModeRequest) Collectors.toList(java.util.stream.Collectors.toList) ModifySubscriptionResponse(org.eclipse.milo.opcua.stack.core.types.structured.ModifySubscriptionResponse) UaException(org.eclipse.milo.opcua.stack.core.UaException) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) BaseMonitoredItem(org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem) MonitoredItemModifyResult(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyResult) UaException(org.eclipse.milo.opcua.stack.core.UaException) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) ArrayList(java.util.ArrayList) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) ModifyMonitoredItemsRequest(org.eclipse.milo.opcua.stack.core.types.structured.ModifyMonitoredItemsRequest) ModifyMonitoredItemsResponse(org.eclipse.milo.opcua.stack.core.types.structured.ModifyMonitoredItemsResponse) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with MonitoredItemModifyRequest

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

the class ManagedItem method setTimestampsToReturnAsync.

/**
 * Set a new {@link TimestampsToReturn} parameter on this item.
 * <p>
 * This call completes asynchronously.
 *
 * @param timestamps a new {@link TimestampsToReturn} parameter.
 * @return a {@link CompletableFuture} that completes successfully if the item was modified and completes
 * exceptionally if an operation- or service-level error occurs.
 */
public CompletableFuture<Unit> setTimestampsToReturnAsync(TimestampsToReturn timestamps) {
    MonitoringParameters parameters = new MonitoringParameters(monitoredItem.getClientHandle(), monitoredItem.getRevisedSamplingInterval(), monitoredItem.getMonitoringFilter(), monitoredItem.getRevisedQueueSize(), monitoredItem.getDiscardOldest());
    MonitoredItemModifyRequest modifyRequest = new MonitoredItemModifyRequest(monitoredItem.getMonitoredItemId(), parameters);
    CompletableFuture<List<StatusCode>> future = subscription.getSubscription().modifyMonitoredItems(timestamps, singletonList(modifyRequest));
    return future.thenApply(statusCodes -> statusCodes.get(0)).thenCompose(statusCode -> {
        if (statusCode.isGood()) {
            return completedFuture(Unit.VALUE);
        } else {
            return failedUaFuture(statusCode);
        }
    });
}
Also used : MonitoringMode(org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) ModifyMonitoredItemResult(org.eclipse.milo.opcua.sdk.client.subscriptions.BatchModifyMonitoredItems.ModifyMonitoredItemResult) SetMonitoringModeResult(org.eclipse.milo.opcua.sdk.client.subscriptions.BatchSetMonitoringMode.SetMonitoringModeResult) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CompletableFuture(java.util.concurrent.CompletableFuture) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) Collections.singletonList(java.util.Collections.singletonList) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Unit(org.eclipse.milo.opcua.stack.core.util.Unit) UaException(org.eclipse.milo.opcua.stack.core.UaException) Optional(java.util.Optional) UaMonitoredItem(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List)

Example 3 with MonitoredItemModifyRequest

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

the class BatchModifyMonitoredItems method executeAsync.

private CompletableFuture<List<ModifyMonitoredItemResult>> executeAsync(UInteger operationLimit) {
    List<BatchModifyParameters> allMonitoringParameters = buildersByItem.values().stream().map(BatchModifyParametersBuilder::build).collect(Collectors.toList());
    CompletableFuture<List<ModifyMonitoredItemResult>> resultsFuture = GroupMapCollate.groupMapCollate(allMonitoringParameters, parametersItem -> parametersItem.timestamps, (TimestampsToReturn timestampsKey) -> parameterGroup -> {
        List<MonitoredItemModifyRequest> itemsToModify = parameterGroup.stream().map(parameters -> new MonitoredItemModifyRequest(parameters.item.getMonitoredItemId(), new MonitoringParameters(parameters.clientHandle, parameters.samplingInterval, parameters.filter, parameters.queueSize, parameters.discardOldest))).collect(Collectors.toList());
        List<CompletableFuture<List<ModifyMonitoredItemResult>>> partitionFutures = Lists.partition(itemsToModify, operationLimit.intValue()).stream().map(partition -> modifyItemsAsync(timestampsKey, partition)).collect(Collectors.toList());
        return FutureUtils.flatSequence(partitionFutures);
    });
    return resultsFuture.thenCompose(results -> {
        List<OpcUaMonitoredItem> items = new ArrayList<>(buildersByItem.keySet());
        assert items.size() == results.size();
        for (int i = 0; i < items.size(); i++) {
            OpcUaMonitoredItem item = items.get(i);
            ModifyMonitoredItemResult result = results.get(i);
            List<CompletableFuture<ModifyMonitoredItemResult>> futures;
            synchronized (futuresByItem) {
                futures = new ArrayList<>(futuresByItem.get(item));
            }
            futures.forEach(f -> f.complete(result));
        }
        return FutureUtils.sequence(resultFutures);
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) ListMultimap(com.google.common.collect.ListMultimap) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) CompletableFuture(java.util.concurrent.CompletableFuture) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) GroupMapCollate(org.eclipse.milo.opcua.sdk.core.util.GroupMapCollate) ArrayList(java.util.ArrayList) Multimaps(com.google.common.collect.Multimaps) LinkedHashMap(java.util.LinkedHashMap) Lists(com.google.common.collect.Lists) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) AttributeId(org.eclipse.milo.opcua.stack.core.AttributeId) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) FutureUtils(org.eclipse.milo.opcua.stack.core.util.FutureUtils) UaException(org.eclipse.milo.opcua.stack.core.UaException) Optional(java.util.Optional) UaVariableNode(org.eclipse.milo.opcua.sdk.client.nodes.UaVariableNode) Collections(java.util.Collections) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) ArrayList(java.util.ArrayList) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) List(java.util.List) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters)

Example 4 with MonitoredItemModifyRequest

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

the class ManagedDataItem method setSamplingIntervalAsync.

/**
 * Request a new sampling interval for this item.
 * <p>
 * This call completes asynchronously.
 *
 * @param samplingInterval the new sampling interval to request.
 * @return a {@link CompletableFuture} that completes successfully with the new sampling interval, possibly revised
 * by the server, or completes exceptionally if an operation- or service-level error occurs.
 */
public CompletableFuture<Double> setSamplingIntervalAsync(double samplingInterval) {
    MonitoringParameters parameters = new MonitoringParameters(monitoredItem.getClientHandle(), samplingInterval, monitoredItem.getMonitoringFilter(), // size if it was revised from the original
    monitoredItem.getRevisedQueueSize(), monitoredItem.getDiscardOldest());
    MonitoredItemModifyRequest modifyRequest = new MonitoredItemModifyRequest(monitoredItem.getMonitoredItemId(), parameters);
    CompletableFuture<List<StatusCode>> future = subscription.getSubscription().modifyMonitoredItems(subscription.getDefaultTimestamps(), singletonList(modifyRequest));
    return future.thenApply(statusCodes -> statusCodes.get(0)).thenCompose(statusCode -> {
        if (statusCode.isGood()) {
            return completedFuture(monitoredItem.getRevisedSamplingInterval());
        } else {
            return failedUaFuture(statusCode);
        }
    });
}
Also used : MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) ModifyMonitoredItemResult(org.eclipse.milo.opcua.sdk.client.subscriptions.BatchModifyMonitoredItems.ModifyMonitoredItemResult) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CompletableFuture(java.util.concurrent.CompletableFuture) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) Collections.singletonList(java.util.Collections.singletonList) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) List(java.util.List) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Unit(org.eclipse.milo.opcua.stack.core.util.Unit) UaException(org.eclipse.milo.opcua.stack.core.UaException) Optional(java.util.Optional) UaMonitoredItem(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 5 with MonitoredItemModifyRequest

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

the class ManagedItem method setQueueSizeAsync.

/**
 * Request a new queue size for this item.
 * <p>
 * This call completes asynchronously.
 *
 * @param queueSize the new queue size to request.
 * @return a {@link CompletableFuture} that completes successfully with the new queue size, possibly revised by the
 * server, or completes exceptionally if an operation- or service-level error occurs.
 */
public CompletableFuture<UInteger> setQueueSizeAsync(UInteger queueSize) {
    MonitoringParameters parameters = new MonitoringParameters(monitoredItem.getClientHandle(), monitoredItem.getRevisedSamplingInterval(), monitoredItem.getMonitoringFilter(), queueSize, monitoredItem.getDiscardOldest());
    MonitoredItemModifyRequest modifyRequest = new MonitoredItemModifyRequest(monitoredItem.getMonitoredItemId(), parameters);
    CompletableFuture<List<StatusCode>> future = subscription.getSubscription().modifyMonitoredItems(monitoredItem.getTimestamps(), singletonList(modifyRequest));
    return future.thenApply(statusCodes -> statusCodes.get(0)).thenCompose(statusCode -> {
        if (statusCode.isGood()) {
            return completedFuture(monitoredItem.getRevisedQueueSize());
        } else {
            return failedUaFuture(statusCode);
        }
    });
}
Also used : MonitoringMode(org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) ModifyMonitoredItemResult(org.eclipse.milo.opcua.sdk.client.subscriptions.BatchModifyMonitoredItems.ModifyMonitoredItemResult) SetMonitoringModeResult(org.eclipse.milo.opcua.sdk.client.subscriptions.BatchSetMonitoringMode.SetMonitoringModeResult) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) TimestampsToReturn(org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) FutureUtils.failedUaFuture(org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture) OpcUaClient(org.eclipse.milo.opcua.sdk.client.OpcUaClient) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) CompletableFuture(java.util.concurrent.CompletableFuture) ReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId) Collections.singletonList(java.util.Collections.singletonList) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode) Unit(org.eclipse.milo.opcua.stack.core.util.Unit) UaException(org.eclipse.milo.opcua.stack.core.UaException) Optional(java.util.Optional) UaMonitoredItem(org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem) MonitoredItemModifyRequest(org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest) MonitoringParameters(org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List)

Aggregations

StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)7 MonitoredItemModifyRequest (org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemModifyRequest)7 List (java.util.List)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)6 UaException (org.eclipse.milo.opcua.stack.core.UaException)6 MonitoringParameters (org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters)6 Optional (java.util.Optional)5 ExecutionException (java.util.concurrent.ExecutionException)5 OpcUaClient (org.eclipse.milo.opcua.sdk.client.OpcUaClient)5 UInteger (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger)5 TimestampsToReturn (org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn)5 ReadValueId (org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId)5 Collections.singletonList (java.util.Collections.singletonList)4 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)4 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)4 MonitoringMode (org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode)4 Consumer (java.util.function.Consumer)3 UaMonitoredItem (org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem)3 ModifyMonitoredItemResult (org.eclipse.milo.opcua.sdk.client.subscriptions.BatchModifyMonitoredItems.ModifyMonitoredItemResult)3