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);
});
}
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);
}
});
}
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);
});
}
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);
}
});
}
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);
}
});
}
Aggregations