use of org.eclipse.milo.opcua.stack.core.types.structured.SetMonitoringModeRequest 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);
}
}
Aggregations