2 * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.remote.rpc;
10 import static java.util.Objects.requireNonNull;
12 import akka.actor.ActorRef;
13 import akka.pattern.Patterns;
14 import akka.util.Timeout;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import org.opendaylight.controller.remote.rpc.messages.ExecuteRpc;
17 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
18 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
19 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
23 * A {@link DOMRpcImplementation} which routes invocation requests to a remote invoker actor.
25 * @author Robert Varga
27 final class RemoteRpcImplementation implements DOMRpcImplementation {
28 // 0 for local, 1 for binding, 2 for remote
29 private static final long COST = 2;
31 private final ActorRef remoteInvoker;
32 private final Timeout askDuration;
34 RemoteRpcImplementation(final ActorRef remoteInvoker, final RemoteRpcProviderConfig config) {
35 this.remoteInvoker = requireNonNull(remoteInvoker);
36 this.askDuration = config.getAskDuration();
40 public ListenableFuture<DOMRpcResult> invokeRpc(final DOMRpcIdentifier rpc,
41 final NormalizedNode<?, ?> input) {
42 final RemoteDOMRpcFuture ret = RemoteDOMRpcFuture.create(rpc.getType().getLastComponent());
43 ret.completeWith(Patterns.ask(remoteInvoker, ExecuteRpc.from(rpc, input), askDuration));
48 public long invocationCost() {