Search in sources :

Example 1 with HistoryUpdateContext

use of org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryUpdateContext in project milo by eclipse.

the class DefaultAttributeHistoryServiceSet method onHistoryUpdate.

@Override
public void onHistoryUpdate(ServiceRequest service) {
    historyUpdateMetric.record(service);
    HistoryUpdateRequest request = (HistoryUpdateRequest) service.getRequest();
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    List<HistoryUpdateDetails> historyUpdateDetailsList = l(request.getHistoryUpdateDetails()).stream().map(e -> (HistoryUpdateDetails) e.decode(server.getSerializationContext())).collect(Collectors.toList());
    if (historyUpdateDetailsList.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (historyUpdateDetailsList.size() > server.getConfig().getLimits().getMaxNodesPerWrite().intValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    DiagnosticsContext<HistoryUpdateDetails> diagnosticsContext = new DiagnosticsContext<>();
    HistoryUpdateContext context = new HistoryUpdateContext(server, session, diagnosticsContext);
    server.getAddressSpaceManager().historyUpdate(context, historyUpdateDetailsList);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        DiagnosticInfo[] diagnosticInfos = diagnosticsContext.getDiagnosticInfos(historyUpdateDetailsList);
        HistoryUpdateResponse response = new HistoryUpdateResponse(header, a(values, HistoryUpdateResult.class), diagnosticInfos);
        service.setResponse(response);
    });
}
Also used : StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) HistoryReadRequest(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadRequest) HistoryUpdateResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResponse) HistoryUpdateDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateDetails) Collectors(java.util.stream.Collectors) Session(org.eclipse.milo.opcua.sdk.server.Session) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) HistoryReadContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryReadContext) ConversionUtil.a(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.a) HistoryUpdateContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryUpdateContext) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) List(java.util.List) ServiceRequest(org.eclipse.milo.opcua.stack.server.services.ServiceRequest) HistoryReadResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult) ConversionUtil.l(org.eclipse.milo.opcua.stack.core.util.ConversionUtil.l) HistoryUpdateRequest(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateRequest) HistoryUpdateResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResult) AttributeHistoryServiceSet(org.eclipse.milo.opcua.stack.server.services.AttributeHistoryServiceSet) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) HistoryReadDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) HistoryReadResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResponse) HistoryReadValueId(org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) HistoryUpdateRequest(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateRequest) DiagnosticInfo(org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo) HistoryUpdateResponse(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResponse) HistoryUpdateResult(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResult) HistoryUpdateContext(org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryUpdateContext) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) HistoryUpdateDetails(org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateDetails) Session(org.eclipse.milo.opcua.sdk.server.Session)

Aggregations

List (java.util.List)1 Collectors (java.util.stream.Collectors)1 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 HistoryUpdateContext (org.eclipse.milo.opcua.sdk.server.api.services.AttributeHistoryServices.HistoryUpdateContext)1 StatusCodes (org.eclipse.milo.opcua.stack.core.StatusCodes)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 HistoryUpdateDetails (org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateDetails)1 HistoryUpdateRequest (org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateRequest)1 HistoryUpdateResponse (org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResponse)1 HistoryUpdateResult (org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResult)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1 ConversionUtil.a (org.eclipse.milo.opcua.stack.core.util.ConversionUtil.a)1