2 * Copyright (c) 2014 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.actor.ActorSystem;
13 import akka.actor.PoisonPill;
14 import com.google.common.base.Preconditions;
15 import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
16 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * This is the base class which initialize all the actors, listeners and
22 * default RPc implementation so remote invocation of rpcs.
24 public class RemoteRpcProvider implements AutoCloseable {
26 private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class);
28 private final DOMRpcProviderService rpcProvisionRegistry;
29 private final RemoteRpcProviderConfig config;
30 private final ActorSystem actorSystem;
31 private final DOMRpcService rpcService;
33 private ActorRef rpcManager;
35 public RemoteRpcProvider(final ActorSystem actorSystem, final DOMRpcProviderService rpcProvisionRegistry,
36 final DOMRpcService rpcService, final RemoteRpcProviderConfig config) {
37 this.actorSystem = Preconditions.checkNotNull(actorSystem);
38 this.rpcProvisionRegistry = Preconditions.checkNotNull(rpcProvisionRegistry);
39 this.rpcService = Preconditions.checkNotNull(rpcService);
40 this.config = Preconditions.checkNotNull(config);
45 if (rpcManager != null) {
46 LOG.info("Stopping RPC Manager at {}", rpcManager);
47 rpcManager.tell(PoisonPill.getInstance(), ActorRef.noSender());
53 LOG.info("Starting Remote RPC service...");
54 rpcManager = actorSystem.actorOf(RpcManager.props(rpcProvisionRegistry, rpcService, config),
55 config.getRpcManagerName());
56 LOG.debug("RPC Manager started at {}", rpcManager);