BUG-3128: rework sal-remoterpc-connector
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteRpcProvider.java
index 52f803d5429d44d0b60bd1c7bc7c6ac161fa9e33..a0e1f87874df9009728f0a6e732e1d27319ad3e9 100644 (file)
@@ -8,20 +8,17 @@
 
 package org.opendaylight.controller.remote.rpc;
 
-
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
+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.remote.rpc.messages.UpdateSchemaContext;
 import org.opendaylight.controller.sal.core.api.Broker;
 import org.opendaylight.controller.sal.core.api.Provider;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -29,19 +26,17 @@ import org.slf4j.LoggerFactory;
  * 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 {
+public class RemoteRpcProvider implements AutoCloseable, Provider {
 
     private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class);
 
     private final DOMRpcProviderService rpcProvisionRegistry;
-
-    private ListenerRegistration<SchemaContextListener> schemaListenerRegistration;
+    private final RemoteRpcProviderConfig config;
     private final ActorSystem actorSystem;
-    private SchemaService schemaService;
+
     private DOMRpcService rpcService;
-    private SchemaContext schemaContext;
+    private SchemaService schemaService;
     private ActorRef rpcManager;
-    private final RemoteRpcProviderConfig config;
 
     public RemoteRpcProvider(final ActorSystem actorSystem, final DOMRpcProviderService rpcProvisionRegistry,
             final RemoteRpcProviderConfig config) {
@@ -50,47 +45,38 @@ public class RemoteRpcProvider implements AutoCloseable, Provider, SchemaContext
         this.config = Preconditions.checkNotNull(config);
     }
 
-    public void setRpcService(DOMRpcService rpcService) {
+    public void setRpcService(final DOMRpcService rpcService) {
         this.rpcService = rpcService;
     }
 
-    public void setSchemaService(SchemaService schemaService) {
+    public void setSchemaService(final SchemaService schemaService) {
         this.schemaService = schemaService;
     }
 
     @Override
-    public void close() throws Exception {
-        if (schemaListenerRegistration != null) {
-            schemaListenerRegistration.close();
-            schemaListenerRegistration = null;
+    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) {
-        schemaService = session.getService(SchemaService.class);
         rpcService = session.getService(DOMRpcService.class);
         start();
     }
 
     @Override
     public Collection<ProviderFunctionality> getProviderFunctionality() {
-        return null;
+        return ImmutableSet.of();
     }
 
     public void start() {
-        LOG.info("Starting remote rpc service...");
-
-        schemaContext = schemaService.getGlobalContext();
-        rpcManager = actorSystem.actorOf(RpcManager.props(schemaContext, rpcProvisionRegistry, rpcService, config),
+        LOG.info("Starting Remote RPC service...");
+        rpcManager = actorSystem.actorOf(RpcManager.props(rpcProvisionRegistry, rpcService, config),
                 config.getRpcManagerName());
-        schemaListenerRegistration = schemaService.registerSchemaContextListener(this);
-        LOG.debug("rpc manager started");
-    }
-
-    @Override
-    public void onGlobalContextUpdated(final SchemaContext newSchemaContext) {
-        this.schemaContext = newSchemaContext;
-        rpcManager.tell(new UpdateSchemaContext(newSchemaContext), null);
+        LOG.debug("RPC Manager started at {}", rpcManager);
     }
 }