Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteOpsProvider.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.remote.rpc;
9
10 import static java.util.Objects.requireNonNull;
11
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSystem;
14 import akka.actor.PoisonPill;
15 import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
16 import org.opendaylight.mdsal.dom.api.DOMActionService;
17 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
18 import org.opendaylight.mdsal.dom.api.DOMRpcService;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * This is the base class which initialize all the actors, listeners and
24  * default RPc implementation so remote invocation of rpcs.
25  */
26 public class RemoteOpsProvider implements AutoCloseable {
27
28     private static final Logger LOG = LoggerFactory.getLogger(RemoteOpsProvider.class);
29
30     private final DOMRpcProviderService rpcProvisionRegistry;
31     private final RemoteOpsProviderConfig config;
32     private final ActorSystem actorSystem;
33     private final DOMRpcService rpcService;
34     private final DOMActionProviderService actionProvisionRegistry;
35     private final DOMActionService actionService;
36
37     private ActorRef opsManager;
38
39     public RemoteOpsProvider(final ActorSystem actorSystem, final DOMRpcProviderService rpcProvisionRegistry,
40                              final DOMRpcService rpcService, final RemoteOpsProviderConfig config,
41                              final DOMActionProviderService actionProviderService,
42                              final DOMActionService actionService) {
43         this.actorSystem = requireNonNull(actorSystem);
44         this.rpcProvisionRegistry = requireNonNull(rpcProvisionRegistry);
45         this.rpcService = requireNonNull(rpcService);
46         this.config = requireNonNull(config);
47         this.actionProvisionRegistry = requireNonNull(actionProviderService);
48         this.actionService = requireNonNull(actionService);
49     }
50
51     @Override
52     public void close() {
53         if (opsManager != null) {
54             LOG.info("Stopping Ops Manager at {}", opsManager);
55             opsManager.tell(PoisonPill.getInstance(), ActorRef.noSender());
56             opsManager = null;
57         }
58     }
59
60     public void start() {
61         LOG.info("Starting Remote Ops service...");
62         opsManager = actorSystem.actorOf(OpsManager.props(rpcProvisionRegistry, rpcService, config,
63                 actionProvisionRegistry, actionService), config.getRpcManagerName());
64         LOG.debug("Ops Manager started at {}", opsManager);
65     }
66 }

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