Search in sources :

Example 6 with CallMethodRequest

use of org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest in project milo by eclipse.

the class ManagedAddressSpace method call.

/**
 * Invoke one or more methods belonging to this {@link MethodServices}.
 *
 * @param context  the {@link CallContext}.
 * @param requests The {@link CallMethodRequest}s for the methods to invoke.
 */
@Override
public void call(CallContext context, List<CallMethodRequest> requests) {
    List<CallMethodResult> results = Lists.newArrayListWithCapacity(requests.size());
    for (CallMethodRequest request : requests) {
        MethodInvocationHandler handler = getInvocationHandler(request.getObjectId(), request.getMethodId()).orElse(MethodInvocationHandler.NODE_ID_UNKNOWN);
        try {
            results.add(handler.invoke(context, request));
        } catch (Throwable t) {
            LoggerFactory.getLogger(getClass()).error("Uncaught Throwable invoking method handler for methodId={}.", request.getMethodId(), t);
            results.add(new CallMethodResult(new StatusCode(StatusCodes.Bad_InternalError), new StatusCode[0], new DiagnosticInfo[0], new Variant[0]));
        }
    }
    context.success(results);
}
Also used : CallMethodResult(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult) MethodInvocationHandler(org.eclipse.milo.opcua.sdk.server.api.methods.MethodInvocationHandler) CallMethodRequest(org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest) StatusCode(org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)

Example 7 with CallMethodRequest

use of org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest 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

CallMethodRequest (org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest)7 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)5 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)5 CallMethodResult (org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult)5 UaException (org.eclipse.milo.opcua.stack.core.UaException)3 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)3 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)2 Session (org.eclipse.milo.opcua.sdk.server.Session)2 ServiceContext (de.fraunhofer.iosb.ilt.faaast.service.ServiceContext)1 AssetConnection (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnection)1 AssetConnectionException (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionException)1 AssetOperationProvider (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider)1 AssetSubscriptionProvider (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetSubscriptionProvider)1 AssetValueProvider (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetValueProvider)1 NewDataListener (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.NewDataListener)1 ValueConversionException (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.conversion.ValueConversionException)1 ValueConverter (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.conversion.ValueConverter)1 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)1