use of org.eclipse.milo.opcua.sdk.client.subscriptions.ManagedDataItem.DataValueListener in project milo by eclipse.
the class ManagedSubscription method createDataItemsAsync.
/**
* Create {@link ManagedDataItem}s monitoring the Nodes and Attributes identified by {@code readValueIds}.
* <p>
* {@code consumer} will receive each item as it is created to provide an opportunity to add a
* {@link DataValueListener} before the first value change has arrived.
* <p>
* The operation results should be checked before each item is used further.
* See {@link ManagedDataItem#getStatusCode()}.
* <p>
* This call completes asynchronously.
*
* @param samplingInterval the sampling interval to request.
* @param readValueIds the {@link ReadValueId}s identifying the Nodes and Attributes.
* @param consumer a {@link Consumer} that will receive each item as it is created.
* @return a {@link CompletableFuture} that completes successfully with a List of {@link ManagedDataItem} or
* completes exceptionally if a service-level error occurs.
*/
public CompletableFuture<List<ManagedDataItem>> createDataItemsAsync(double samplingInterval, List<ReadValueId> readValueIds, Consumer<ManagedDataItem> consumer) {
final ExtensionObject filter = getDefaultDataFilter();
final UInteger queueSize = getDefaultQueueSize();
final boolean discardOldest = getDefaultDiscardOldest();
List<MonitoredItemCreateRequest> createRequests = readValueIds.stream().map(readValueId -> {
MonitoringParameters parameters = new MonitoringParameters(subscription.nextClientHandle(), samplingInterval, filter, queueSize, discardOldest);
return new MonitoredItemCreateRequest(readValueId, getDefaultMonitoringMode(), parameters);
}).collect(Collectors.toList());
CompletableFuture<List<UaMonitoredItem>> monitoredItems = subscription.createMonitoredItems(getDefaultTimestamps(), createRequests, (item, id) -> {
ManagedDataItem dataItem = createAndTrackDataItem(item);
consumer.accept(dataItem);
});
return monitoredItems.thenApply(items -> items.stream().map(item -> dataItems.get(item.getClientHandle())).filter(Objects::nonNull).collect(Collectors.toList()));
}
Aggregations