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;
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSystem;
14 import org.opendaylight.controller.remote.rpc.messages.UpdateSchemaContext;
15 import org.opendaylight.controller.sal.core.api.Broker;
16 import org.opendaylight.controller.sal.core.api.Provider;
17 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
18 import org.opendaylight.controller.sal.core.api.model.SchemaService;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import java.util.Collection;
27 * This is the base class which initialize all the actors, listeners and
28 * default RPc implementation so remote invocation of rpcs.
30 public class RemoteRpcProvider implements AutoCloseable, Provider, SchemaContextListener {
32 private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class);
34 private final ActorSystem actorSystem;
35 private final RpcProvisionRegistry rpcProvisionRegistry;
36 private Broker.ProviderSession brokerSession;
37 private SchemaContext schemaContext;
38 private ActorRef rpcManager;
41 public RemoteRpcProvider(ActorSystem actorSystem, RpcProvisionRegistry rpcProvisionRegistry) {
42 this.actorSystem = actorSystem;
43 this.rpcProvisionRegistry = rpcProvisionRegistry;
47 public void close() throws Exception {
48 this.actorSystem.shutdown();
52 public void onSessionInitiated(Broker.ProviderSession session) {
53 this.brokerSession = session;
58 public Collection<ProviderFunctionality> getProviderFunctionality() {
62 private void start() {
63 LOG.info("Starting all rpc listeners and actors.");
64 // Create actor to handle and sync routing table in cluster
65 SchemaService schemaService = brokerSession.getService(SchemaService.class);
66 schemaContext = schemaService.getGlobalContext();
68 rpcManager = actorSystem.actorOf(RpcManager.props(schemaContext, brokerSession, rpcProvisionRegistry), ActorConstants.RPC_MANAGER);
70 LOG.debug("Rpc actors are created.");
75 public void onGlobalContextUpdated(SchemaContext schemaContext) {
76 this.schemaContext = schemaContext;
77 rpcManager.tell(new UpdateSchemaContext(schemaContext), null);