Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteActionImplementation.java
1 /*
2  * Copyright (c) 2019 Nordix Foundation.  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 akka.actor.ActorRef;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.controller.remote.rpc.messages.ExecuteAction;
13 import org.opendaylight.mdsal.dom.api.DOMActionImplementation;
14 import org.opendaylight.mdsal.dom.api.DOMActionResult;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * A {@link DOMActionImplementation} which routes invocation requests to a remote invoker actor.
23  */
24 final class RemoteActionImplementation extends AbstractRemoteImplementation<ExecuteAction>
25         implements DOMActionImplementation {
26     private static final Logger LOG = LoggerFactory.getLogger(RemoteActionImplementation.class);
27
28     RemoteActionImplementation(final ActorRef remoteInvoker, final RemoteOpsProviderConfig config) {
29         super(remoteInvoker, config);
30     }
31
32     /**
33      * Routes action request to a remote invoker, which will execute the action and return with result.
34      */
35     @Override
36     public ListenableFuture<DOMActionResult> invokeAction(final SchemaPath type, final DOMDataTreeIdentifier path,
37                                                           final ContainerNode input) {
38         LOG.debug("invoking action {} with path {}", type, path);
39         return new RemoteDOMActionFuture(type, ask(ExecuteAction.from(type, path, input)));
40     }
41
42     @Override
43     public long invocationCost() {
44         return COST;
45     }
46 }

©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.