Remove unneeded SchemaService reference
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteRpcImplementation.java
1 /*
2  * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.remote.rpc;
10
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;
22
23 /**
24  * A {@link DOMRpcImplementation} which routes invocation requests to a remote invoker actor.
25  *
26  * @author Robert Varga
27  */
28 final class RemoteRpcImplementation implements DOMRpcImplementation {
29     // 0 for local, 1 for binding, 2 for remote
30     private static final long COST = 2;
31
32     private final ActorRef remoteInvoker;
33     private final Timeout askDuration;
34
35     RemoteRpcImplementation(final ActorRef remoteInvoker, final RemoteRpcProviderConfig config) {
36         this.remoteInvoker = Preconditions.checkNotNull(remoteInvoker);
37         this.askDuration = config.getAskDuration();
38     }
39
40     @Override
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));
45         return ret;
46     }
47
48     @Override
49     public long invocationCost() {
50         return COST;
51     }
52 }