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);
}
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);
});
}
Aggregations