Separate out RaftEntryMeta
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / OpsInvoker.java
index 5ccea6a423a3519c649dd4c56818e601c29247b7..2d2bd7933830178e05dc996b29420504bb5114af 100644 (file)
@@ -24,15 +24,15 @@ import org.opendaylight.controller.remote.rpc.messages.ActionResponse;
 import org.opendaylight.controller.remote.rpc.messages.ExecuteAction;
 import org.opendaylight.controller.remote.rpc.messages.ExecuteRpc;
 import org.opendaylight.controller.remote.rpc.messages.RpcResponse;
-import org.opendaylight.mdsal.dom.api.DOMActionResult;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 
 /**
  * Actor receiving invocation requests from remote nodes, routing them to
@@ -67,11 +67,11 @@ final class OpsInvoker extends AbstractUntypedActor {
 
     @Override
     protected void handleReceive(final Object message) {
-        if (message instanceof ExecuteRpc) {
+        if (message instanceof ExecuteRpc executeRpc) {
             LOG.debug("Handling ExecuteOps Message");
-            execute((ExecuteRpc) message);
-        } else if (message instanceof ExecuteAction) {
-            execute((ExecuteAction) message);
+            execute(executeRpc);
+        } else if (message instanceof ExecuteAction executeAction) {
+            execute(executeAction);
         } else {
             unknownMessage(message);
         }
@@ -91,17 +91,17 @@ final class OpsInvoker extends AbstractUntypedActor {
             return;
         }
 
-        Futures.addCallback(future, new AbstractCallback<DOMRpcResult>(getSender(), msg.getType()) {
+        Futures.addCallback(future, new AbstractCallback<QName, DOMRpcResult>(getSender(), msg.getType()) {
             @Override
-            Object nullResponse(final SchemaPath type) {
+            Object nullResponse(final QName type) {
                 LOG.warn("Execution of {} resulted in null result", type);
                 return new RpcResponse(null);
             }
 
             @Override
-            Object response(final SchemaPath type, final DOMRpcResult result) {
-                final Collection<? extends RpcError> errors = result.getErrors();
-                return errors.isEmpty() ? new RpcResponse(result.getResult())
+            Object response(final QName type, final DOMRpcResult result) {
+                final Collection<? extends RpcError> errors = result.errors();
+                return errors.isEmpty() ? new RpcResponse(result.value())
                         // This is legacy (wrong) behavior, which ignores the fact that errors may be just warnings,
                         // discarding any output
                         : new Failure(new RpcErrorsException(String.format("Execution of rpc %s failed", type),
@@ -116,7 +116,7 @@ final class OpsInvoker extends AbstractUntypedActor {
 
         final ActorRef sender = getSender();
 
-        final ListenableFuture<? extends DOMActionResult> future;
+        final ListenableFuture<? extends DOMRpcResult> future;
         try {
             future = actionService.invokeAction(msg.getType(), msg.getPath(), msg.getInput());
         } catch (final RuntimeException e) {
@@ -125,16 +125,16 @@ final class OpsInvoker extends AbstractUntypedActor {
             return;
         }
 
-        Futures.addCallback(future, new AbstractCallback<DOMActionResult>(getSender(), msg.getType()) {
+        Futures.addCallback(future, new AbstractCallback<Absolute, DOMRpcResult>(getSender(), msg.getType()) {
             @Override
-            Object nullResponse(final SchemaPath type) {
+            Object nullResponse(final Absolute type) {
                 throw new IllegalStateException("Null invocation result of action " + type);
             }
 
             @Override
-            Object response(final SchemaPath type, final DOMActionResult result) {
-                final Collection<? extends RpcError> errors = result.getErrors();
-                return errors.isEmpty() ? new ActionResponse(result.getOutput(), result.getErrors())
+            Object response(final Absolute type, final DOMRpcResult result) {
+                final var errors = result.errors();
+                return errors.isEmpty() ? new ActionResponse(result.value(), errors)
                     // This is legacy (wrong) behavior, which ignores the fact that errors may be just warnings,
                     // discarding any output
                     : new Failure(new RpcErrorsException(String.format("Execution of action %s failed", type),
@@ -143,17 +143,17 @@ final class OpsInvoker extends AbstractUntypedActor {
         }, MoreExecutors.directExecutor());
     }
 
-    private abstract class AbstractCallback<T> implements FutureCallback<T> {
+    private abstract class AbstractCallback<T, R> implements FutureCallback<R> {
         private final ActorRef replyTo;
-        private final SchemaPath type;
+        private final T type;
 
-        AbstractCallback(final ActorRef replyTo, final SchemaPath type) {
+        AbstractCallback(final ActorRef replyTo, final T type) {
             this.replyTo = requireNonNull(replyTo);
             this.type = requireNonNull(type);
         }
 
         @Override
-        public final void onSuccess(final T result) {
+        public final void onSuccess(final R result) {
             final Object response;
             if (result == null) {
                 // This shouldn't happen but the FutureCallback annotates the result param with Nullable so handle null
@@ -175,8 +175,8 @@ final class OpsInvoker extends AbstractUntypedActor {
             replyTo.tell(new Failure(failure), self());
         }
 
-        abstract @NonNull Object nullResponse(@NonNull SchemaPath type);
+        abstract @NonNull Object nullResponse(@NonNull T type);
 
-        abstract @NonNull Object response(@NonNull SchemaPath type, @NonNull T result);
+        abstract @NonNull Object response(@NonNull T type, @NonNull R result);
     }
 }