use of org.eclipse.milo.opcua.stack.core.types.structured.ModifyMonitoredItemsResponse 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.ModifyMonitoredItemsResponse in project milo by eclipse.
the class OpcUaSubscription method modifyMonitoredItems.
@Override
public CompletableFuture<List<StatusCode>> modifyMonitoredItems(TimestampsToReturn timestampsToReturn, List<MonitoredItemModifyRequest> itemsToModify) {
CompletableFuture<ModifyMonitoredItemsResponse> future = client.modifyMonitoredItems(subscriptionId, timestampsToReturn, itemsToModify);
return future.thenApply(response -> {
List<StatusCode> statusCodes = newArrayList();
List<MonitoredItemModifyResult> results = l(response.getResults());
for (int i = 0; i < results.size(); i++) {
MonitoredItemModifyRequest request = itemsToModify.get(i);
MonitoredItemModifyResult result = results.get(i);
StatusCode statusCode = result.getStatusCode();
OpcUaMonitoredItem item = itemsByServerHandle.get(request.getMonitoredItemId());
if (item != null) {
item.setStatusCode(statusCode);
if (statusCode.isGood()) {
item.setTimestamps(timestampsToReturn);
item.setRevisedSamplingInterval(result.getRevisedSamplingInterval());
item.setRevisedQueueSize(result.getRevisedQueueSize());
item.setFilterResult(result.getFilterResult());
item.setDiscardOldest(request.getRequestedParameters().getDiscardOldest());
item.setRequestedFilter(request.getRequestedParameters().getFilter());
item.setRequestedSamplingInterval(request.getRequestedParameters().getSamplingInterval());
item.setRequestedQueueSize(request.getRequestedParameters().getQueueSize());
}
}
statusCodes.add(statusCode);
}
return statusCodes;
});
}
Aggregations