X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2FRpcInvoker.java;fp=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2FRpcInvoker.java;h=0000000000000000000000000000000000000000;hp=4d3a66c00e4ba2eb25d68a27520c4ad83338550c;hb=927bce5688e4b9d33d3e5e9b769d8a0dba5ccdd4;hpb=a2b838f96589b502578fa4e15cef2769f886a378 diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcInvoker.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcInvoker.java deleted file mode 100644 index 4d3a66c00e..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcInvoker.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.remote.rpc; - -import akka.actor.ActorRef; -import akka.actor.Props; -import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor; -import org.opendaylight.controller.remote.rpc.messages.ExecuteRpc; -import org.opendaylight.controller.remote.rpc.messages.RpcResponse; -import org.opendaylight.mdsal.dom.api.DOMRpcResult; -import org.opendaylight.mdsal.dom.api.DOMRpcService; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -/** - * Actor receiving invocation requests from remote nodes, routing them to - * {@link DOMRpcService#invokeRpc(SchemaPath, NormalizedNode)}. - */ -final class RpcInvoker extends AbstractUntypedActor { - private final DOMRpcService rpcService; - - private RpcInvoker(final DOMRpcService rpcService) { - this.rpcService = Preconditions.checkNotNull(rpcService); - } - - public static Props props(final DOMRpcService rpcService) { - Preconditions.checkNotNull(rpcService, "DOMRpcService can not be null"); - return Props.create(RpcInvoker.class, rpcService); - } - - @Override - protected void handleReceive(final Object message) { - if (message instanceof ExecuteRpc) { - executeRpc((ExecuteRpc) message); - } else { - unknownMessage(message); - } - } - - @SuppressWarnings("checkstyle:IllegalCatch") - private void executeRpc(final ExecuteRpc msg) { - LOG.debug("Executing rpc {}", msg.getRpc()); - final SchemaPath schemaPath = SchemaPath.create(true, msg.getRpc()); - final ActorRef sender = getSender(); - final ActorRef self = self(); - - final ListenableFuture future; - try { - future = rpcService.invokeRpc(schemaPath, msg.getInputNormalizedNode()); - } catch (final RuntimeException e) { - LOG.debug("Failed to invoke RPC {}", msg.getRpc(), e); - sender.tell(new akka.actor.Status.Failure(e), sender); - return; - } - - Futures.addCallback(future, new FutureCallback() { - @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.debug("Failed to execute RPC {}", msg.getRpc(), failure); - LOG.error("Failed to execute RPC {} due to {}. More details are available on DEBUG level.", - msg.getRpc(), Throwables.getRootCause(failure).getMessage()); - sender.tell(new akka.actor.Status.Failure(failure), self); - } - }, MoreExecutors.directExecutor()); - } -}