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
9 package org.opendaylight.controller.remote.rpc;
11 import akka.actor.ActorRef;
12 import akka.pattern.Patterns;
13 import akka.util.Timeout;
14 import com.google.common.base.Preconditions;
15 import com.google.common.util.concurrent.CheckedFuture;
16 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
17 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
18 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation;
19 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
20 import org.opendaylight.controller.remote.rpc.messages.ExecuteRpc;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 * A {@link DOMRpcImplementation} which routes invocation requests to a remote invoker actor.
26 * @author Robert Varga
28 final class RemoteRpcImplementation implements DOMRpcImplementation {
29 // 0 for local, 1 for binding, 2 for remote
30 private static final long COST = 2;
32 private final ActorRef remoteInvoker;
33 private final Timeout askDuration;
35 RemoteRpcImplementation(final ActorRef remoteInvoker, final RemoteRpcProviderConfig config) {
36 this.remoteInvoker = Preconditions.checkNotNull(remoteInvoker);
37 this.askDuration = config.getAskDuration();
41 public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final DOMRpcIdentifier rpc,
42 final NormalizedNode<?, ?> input) {
43 final RemoteDOMRpcFuture ret = RemoteDOMRpcFuture.create(rpc.getType().getLastComponent());
44 ret.completeWith(Patterns.ask(remoteInvoker, ExecuteRpc.from(rpc, input), askDuration));
49 public long invocationCost() {