+ LOG.trace("{}: Rpc operation invoked with schema type: {} and node: {}.", id, type, input);
+
+ final NormalizedNodeMessage normalizedNodeMessage =
+ new NormalizedNodeMessage(YangInstanceIdentifier.EMPTY, input);
+ final Future<Object> scalaFuture =
+ Patterns.ask(masterActorRef,
+ new InvokeRpcMessage(new SchemaPathMessage(type), normalizedNodeMessage),
+ NetconfTopologyUtils.TIMEOUT);
+
+ final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
+
+ final CheckedFuture<DOMRpcResult, DOMRpcException> checkedFuture = Futures.makeChecked(settableFuture,
+ new Function<Exception, DOMRpcException>() {
+
+ @Nullable
+ @Override
+ public DOMRpcException apply(@Nullable final Exception exception) {
+ return new ClusteringRpcException(id + ": Exception during remote rpc invocation.",
+ exception);
+ }
+ });
+
+ scalaFuture.onComplete(new OnComplete<Object>() {
+ @Override
+ public void onComplete(final Throwable failure, final Object success) throws Throwable {
+ if (failure != null) {
+ settableFuture.setException(failure);
+ return;
+ }
+ if (success instanceof Throwable) {
+ settableFuture.setException((Throwable) success);
+ return;
+ }
+ if (success instanceof EmptyResultResponse || success == null) {
+ settableFuture.set(null);
+ return;
+ }
+ final Collection<RpcError> errors = ((InvokeRpcMessageReply) success).getRpcErrors();
+ final NormalizedNodeMessage normalizedNodeMessageResult =
+ ((InvokeRpcMessageReply) success).getNormalizedNodeMessage();
+ final DOMRpcResult result;
+ if (normalizedNodeMessageResult == null ){
+ result = new DefaultDOMRpcResult(errors);
+ } else {
+ if (errors == null) {
+ result = new DefaultDOMRpcResult(normalizedNodeMessageResult.getNode());
+ } else {
+ result = new DefaultDOMRpcResult(normalizedNodeMessageResult.getNode(), errors);
+ }
+ }
+ settableFuture.set(result);
+ }
+ }, actorSystem.dispatcher());
+
+ return checkedFuture;
+