use of org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadRequest in project milo by eclipse.
the class DefaultAttributeHistoryServiceSet method onHistoryRead.
@Override
public void onHistoryRead(ServiceRequest service) {
historyReadMetric.record(service);
HistoryReadRequest request = (HistoryReadRequest) service.getRequest();
OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
List<HistoryReadValueId> nodesToRead = l(request.getNodesToRead());
if (nodesToRead.isEmpty()) {
service.setServiceFault(StatusCodes.Bad_NothingToDo);
return;
}
if (nodesToRead.size() > server.getConfig().getLimits().getMaxNodesPerRead().longValue()) {
service.setServiceFault(StatusCodes.Bad_TooManyOperations);
return;
}
if (request.getTimestampsToReturn() == null) {
service.setServiceFault(StatusCodes.Bad_TimestampsToReturnInvalid);
return;
}
DiagnosticsContext<HistoryReadValueId> diagnosticsContext = new DiagnosticsContext<>();
HistoryReadContext context = new HistoryReadContext(server, session, diagnosticsContext);
HistoryReadDetails details = (HistoryReadDetails) request.getHistoryReadDetails().decode(server.getSerializationContext());
server.getAddressSpaceManager().historyRead(context, details, request.getTimestampsToReturn(), nodesToRead);
context.getFuture().thenAccept(values -> {
ResponseHeader header = service.createResponseHeader();
DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(nodesToRead);
HistoryReadResponse response = new HistoryReadResponse(header, a(values, HistoryReadResult.class), diagnosticInfos);
service.setResponse(response);
});
}
Aggregations