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 com.google.common.collect.ImmutableSet;
16 import java.util.Collection;
17 import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
18 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
19 import org.opendaylight.controller.sal.core.api.Broker;
20 import org.opendaylight.controller.sal.core.api.Provider;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * This is the base class which initialize all the actors, listeners and
26 * default RPc implementation so remote invocation of rpcs.
28 public class RemoteRpcProvider implements AutoCloseable, Provider {
30 private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class);
32 private final DOMRpcProviderService rpcProvisionRegistry;
33 private final RemoteRpcProviderConfig config;
34 private final ActorSystem actorSystem;
36 private DOMRpcService rpcService;
37 private ActorRef rpcManager;
39 public RemoteRpcProvider(final ActorSystem actorSystem, final DOMRpcProviderService rpcProvisionRegistry,
40 final RemoteRpcProviderConfig config) {
41 this.actorSystem = actorSystem;
42 this.rpcProvisionRegistry = rpcProvisionRegistry;
43 this.config = Preconditions.checkNotNull(config);
46 public void setRpcService(final DOMRpcService rpcService) {
47 this.rpcService = rpcService;
52 if (rpcManager != null) {
53 LOG.info("Stopping RPC Manager at {}", rpcManager);
54 rpcManager.tell(PoisonPill.getInstance(), ActorRef.noSender());
60 public void onSessionInitiated(final Broker.ProviderSession session) {
61 rpcService = session.getService(DOMRpcService.class);
66 public Collection<ProviderFunctionality> getProviderFunctionality() {
67 return ImmutableSet.of();
71 LOG.info("Starting Remote RPC service...");
72 rpcManager = actorSystem.actorOf(RpcManager.props(rpcProvisionRegistry, rpcService, config),
73 config.getRpcManagerName());
74 LOG.debug("RPC Manager started at {}", rpcManager);