Search in sources :

Example 1 with HistoryReadContext

use of org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryReadContext 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);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) HistoryReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadRequest) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) HistoryReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) HistoryReadDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails) HistoryReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryReadContext) HistoryReadResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) HistoryReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResponse) Session(org.eclipse.milo.opcua.sdk.server.Session)

Aggregations

DiagnosticsContext (org.eclipse.milo.opcua.sdk.server.DiagnosticsContext)1 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)1 Session (org.eclipse.milo.opcua.sdk.server.Session)1 HistoryReadContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryReadContext)1 DiagnosticInfo (org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo)1 HistoryReadDetails (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails)1 HistoryReadRequest (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadRequest)1 HistoryReadResponse (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResponse)1 HistoryReadResult (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult)1 HistoryReadValueId (org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1