Search in sources :

Example 1 with CallContext

use of org.eclipse.milo.opcua.sdk.server.api.services.MethodServices.CallContext in project milo by eclipse.

the class DefaultMethodServiceSet method onCall.

@Override
public void onCall(ServiceRequest service) {
    callCounter.record(service);
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();
    Session session = service.attr(ServiceAttributes.SESSION_KEY).get();
    CallRequest request = (CallRequest) service.getRequest();
    List<CallMethodRequest> methodsToCall = l(request.getMethodsToCall());
    if (methodsToCall.isEmpty()) {
        service.setServiceFault(StatusCodes.Bad_NothingToDo);
        return;
    }
    if (methodsToCall.size() > server.getConfig().getLimits().getMaxNodesPerMethodCall().longValue()) {
        service.setServiceFault(StatusCodes.Bad_TooManyOperations);
        return;
    }
    DiagnosticsContext<CallMethodRequest> diagnosticsContext = new DiagnosticsContext<>();
    CallContext context = new CallContext(server, session, diagnosticsContext);
    server.getAddressSpaceManager().call(context, methodsToCall);
    context.getFuture().thenAccept(values -> {
        ResponseHeader header = service.createResponseHeader();
        CallResponse response = new CallResponse(header, a(values, CallMethodResult.class), new DiagnosticInfo[0]);
        service.setResponse(response);
    });
}
Also used : OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) CallRequest(org.eclipse.milo.opcua.stack.core.types.structured.CallRequest) DiagnosticsContext(org.eclipse.milo.opcua.sdk.server.DiagnosticsContext) ResponseHeader(org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader) CallMethodResult(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult) CallMethodRequest(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest) CallContext(org.eclipse.milo.opcua.sdk.server.api.services.MethodServices.CallContext) CallResponse(org.eclipse.milo.opcua.stack.core.types.structured.CallResponse) 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 CallContext (org.eclipse.milo.opcua.sdk.server.api.services.MethodServices.CallContext)1 CallMethodRequest (org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest)1 CallMethodResult (org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult)1 CallRequest (org.eclipse.milo.opcua.stack.core.types.structured.CallRequest)1 CallResponse (org.eclipse.milo.opcua.stack.core.types.structured.CallResponse)1 ResponseHeader (org.eclipse.milo.opcua.stack.core.types.structured.ResponseHeader)1