package org.opendaylight.controller.remote.rpc;
-
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
-import org.opendaylight.controller.remote.rpc.messages.UpdateSchemaContext;
+import akka.actor.PoisonPill;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import java.util.Collection;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.controller.sal.core.api.Broker;
import org.opendaylight.controller.sal.core.api.Provider;
-import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
import org.opendaylight.controller.sal.core.api.model.SchemaService;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.Collection;
-
/**
* This is the base class which initialize all the actors, listeners and
* default RPc implementation so remote invocation of rpcs.
*/
-public class RemoteRpcProvider implements AutoCloseable, Provider, SchemaContextListener {
-
- private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class);
-
- private final ActorSystem actorSystem;
- private final RpcProvisionRegistry rpcProvisionRegistry;
- private Broker.ProviderSession brokerSession;
- private SchemaContext schemaContext;
- private ActorRef rpcManager;
-
-
- public RemoteRpcProvider(ActorSystem actorSystem, RpcProvisionRegistry rpcProvisionRegistry) {
- this.actorSystem = actorSystem;
- this.rpcProvisionRegistry = rpcProvisionRegistry;
- }
-
- @Override
- public void close() throws Exception {
- this.actorSystem.shutdown();
- }
-
- @Override
- public void onSessionInitiated(Broker.ProviderSession session) {
- this.brokerSession = session;
- start();
- }
-
- @Override
- public Collection<ProviderFunctionality> getProviderFunctionality() {
- return null;
- }
-
- private void start() {
- LOG.info("Starting all rpc listeners and actors.");
- // Create actor to handle and sync routing table in cluster
- SchemaService schemaService = brokerSession.getService(SchemaService.class);
- schemaContext = schemaService.getGlobalContext();
-
- rpcManager = actorSystem.actorOf(RpcManager.props(schemaContext, brokerSession, rpcProvisionRegistry), ActorConstants.RPC_MANAGER);
-
- LOG.debug("Rpc actors are created.");
- }
-
-
- @Override
- public void onGlobalContextUpdated(SchemaContext schemaContext) {
- this.schemaContext = schemaContext;
- rpcManager.tell(new UpdateSchemaContext(schemaContext), null);
-
- }
+public class RemoteRpcProvider implements AutoCloseable, Provider {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class);
+
+ private final DOMRpcProviderService rpcProvisionRegistry;
+ private final RemoteRpcProviderConfig config;
+ private final ActorSystem actorSystem;
+
+ private DOMRpcService rpcService;
+ private SchemaService schemaService;
+ private ActorRef rpcManager;
+
+ public RemoteRpcProvider(final ActorSystem actorSystem, final DOMRpcProviderService rpcProvisionRegistry,
+ final RemoteRpcProviderConfig config) {
+ this.actorSystem = actorSystem;
+ this.rpcProvisionRegistry = rpcProvisionRegistry;
+ this.config = Preconditions.checkNotNull(config);
+ }
+
+ public void setRpcService(final DOMRpcService rpcService) {
+ this.rpcService = rpcService;
+ }
+
+ public void setSchemaService(final SchemaService schemaService) {
+ this.schemaService = schemaService;
+ }
+
+ @Override
+ public void close() {
+ if (rpcManager != null) {
+ LOG.info("Stopping RPC Manager at {}", rpcManager);
+ rpcManager.tell(PoisonPill.getInstance(), ActorRef.noSender());
+ rpcManager = null;
+ }
+ }
+
+ @Override
+ public void onSessionInitiated(final Broker.ProviderSession session) {
+ rpcService = session.getService(DOMRpcService.class);
+ start();
+ }
+
+ @Override
+ public Collection<ProviderFunctionality> getProviderFunctionality() {
+ return ImmutableSet.of();
+ }
+
+ public void start() {
+ LOG.info("Starting Remote RPC service...");
+ rpcManager = actorSystem.actorOf(RpcManager.props(rpcProvisionRegistry, rpcService, config),
+ config.getRpcManagerName());
+ LOG.debug("RPC Manager started at {}", rpcManager);
+ }
}