+ @SuppressWarnings("checkstyle:IllegalCatch")
+ private void executeRpc(final ExecuteRpc msg) {
+ LOG.debug("Executing rpc {}", msg.getRpc());
+ final NormalizedNode<?, ?> input = RemoteRpcInput.from(msg.getInputNormalizedNode());
+ final SchemaPath schemaPath = SchemaPath.create(true, msg.getRpc());
+ final ActorRef sender = getSender();
+ final ActorRef self = self();
+
+ try {
+ final CheckedFuture<DOMRpcResult, DOMRpcException> future = rpcService.invokeRpc(schemaPath, input);
+
+ Futures.addCallback(future, new FutureCallback<DOMRpcResult>() {
+ @Override
+ public void onSuccess(final DOMRpcResult result) {
+ if (result == null) {
+ // This shouldn't happen but the FutureCallback annotates the result param with Nullable so
+ // handle null here to avoid FindBugs warning.
+ LOG.debug("Got null DOMRpcResult - sending null response for execute rpc : {}", msg.getRpc());
+ sender.tell(new RpcResponse(null), self);
+ return;
+ }
+
+ if (!result.getErrors().isEmpty()) {
+ final String message = String.format("Execution of RPC %s failed", msg.getRpc());
+ sender.tell(new akka.actor.Status.Failure(new RpcErrorsException(message,
+ result.getErrors())), self);
+ } else {
+ LOG.debug("Sending response for execute rpc : {}", msg.getRpc());
+
+ sender.tell(new RpcResponse(result.getResult()), self);
+ }
+ }
+
+ @Override
+ public void onFailure(final Throwable failure) {
+ LOG.error(
+ "executeRpc for {} failed with root cause: {}. For exception details, enable Debug logging.",
+ msg.getRpc(), Throwables.getRootCause(failure));
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Detailed exception for execute RPC failure :{}", failure);
+ }
+ sender.tell(new akka.actor.Status.Failure(failure), self);
+ }
+ });
+ } catch (final RuntimeException e) {
+ sender.tell(new akka.actor.Status.Failure(e), sender);
+ }
+ }