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 java.util.Collection;
15 import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
16 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
17 import org.opendaylight.controller.remote.rpc.messages.UpdateSchemaContext;
18 import org.opendaylight.controller.sal.core.api.Broker;
19 import org.opendaylight.controller.sal.core.api.Provider;
20 import org.opendaylight.controller.sal.core.api.model.SchemaService;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * This is the base class which initialize all the actors, listeners and
29 * default RPc implementation so remote invocation of rpcs.
31 public class RemoteRpcProvider implements AutoCloseable, Provider, SchemaContextListener {
33 private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class);
35 private final DOMRpcProviderService rpcProvisionRegistry;
37 private ListenerRegistration<SchemaContextListener> schemaListenerRegistration;
38 private ActorSystem actorSystem;
39 private Broker.ProviderSession brokerSession;
40 private SchemaContext schemaContext;
41 private ActorRef rpcManager;
42 private final RemoteRpcProviderConfig config;
45 public RemoteRpcProvider(final ActorSystem actorSystem, final DOMRpcProviderService rpcProvisionRegistry) {
46 this.actorSystem = actorSystem;
47 this.rpcProvisionRegistry = rpcProvisionRegistry;
48 config = new RemoteRpcProviderConfig(actorSystem.settings().config());
52 public void close() throws Exception {
53 if (actorSystem != null) {
54 actorSystem.shutdown();
57 if (schemaListenerRegistration != null) {
58 schemaListenerRegistration.close();
59 schemaListenerRegistration = null;
64 public void onSessionInitiated(final Broker.ProviderSession session) {
65 brokerSession = session;
70 public Collection<ProviderFunctionality> getProviderFunctionality() {
74 private void start() {
75 LOG.info("Starting remote rpc service...");
77 final SchemaService schemaService = brokerSession.getService(SchemaService.class);
78 final DOMRpcService rpcService = brokerSession.getService(DOMRpcService.class);
79 schemaContext = schemaService.getGlobalContext();
80 rpcManager = actorSystem.actorOf(RpcManager.props(schemaContext,
81 rpcProvisionRegistry, rpcService), config.getRpcManagerName());
82 schemaListenerRegistration = schemaService.registerSchemaContextListener(this);
83 LOG.debug("rpc manager started");
87 public void onGlobalContextUpdated(final SchemaContext schemaContext) {
88 this.schemaContext = schemaContext;
89 rpcManager.tell(new UpdateSchemaContext(schemaContext), null);