Search in sources :

Example 1 with MethodInvocationHandler

use of org.eclipse.milo.opcua.sdk.server.api.methods.MethodInvocationHandler 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)

Aggregations

MethodInvocationHandler (org.eclipse.milo.opcua.sdk.server.api.methods.MethodInvocationHandler)1 StatusCode (org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode)1 CallMethodRequest (org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest)1 CallMethodResult (org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult)1