Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / AbstractRemoteImplementation.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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 package org.opendaylight.controller.remote.rpc;
9
10 import static java.util.Objects.requireNonNull;
11
12 import akka.actor.ActorRef;
13 import akka.pattern.Patterns;
14 import akka.util.Timeout;
15 import org.opendaylight.controller.remote.rpc.messages.AbstractExecute;
16 import scala.concurrent.Future;
17
18 /**
19  * An abstract base class for remote RPC/action implementations.
20  */
21 abstract class AbstractRemoteImplementation<T extends AbstractExecute<?>> {
22     // 0 for local, 1 for binding, 2 for remote
23     static final long COST = 2;
24
25     private final ActorRef remoteInvoker;
26     private final Timeout askDuration;
27
28     AbstractRemoteImplementation(final ActorRef remoteInvoker, final RemoteOpsProviderConfig config) {
29         this.remoteInvoker = requireNonNull(remoteInvoker);
30         this.askDuration = config.getAskDuration();
31     }
32
33     final Future<Object> ask(final T message) {
34         return Patterns.ask(remoteInvoker, requireNonNull(message), askDuration);
35     }
36 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.