Remove reliance on org.opendaylight.controller.sal.core.api.Broker
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteRpcProvider.java
index 8b4ce31d2ea0ee7e82352e72fd5249b37e6873a6..51e56d0d984dcf93e7e47843f11c18d57bdfab8c 100644 (file)
@@ -8,77 +8,51 @@
 
 package org.opendaylight.controller.remote.rpc;
 
-
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
-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.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 akka.actor.PoisonPill;
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 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 RpcProvisionRegistry rpcProvisionRegistry;
-
-  private ActorSystem actorSystem;
-  private Broker.ProviderSession brokerSession;
-  private SchemaContext schemaContext;
-  private ActorRef rpcManager;
-  private RemoteRpcProviderConfig config;
-
-
-  public RemoteRpcProvider(ActorSystem actorSystem, RpcProvisionRegistry rpcProvisionRegistry) {
-    this.actorSystem = actorSystem;
-    this.rpcProvisionRegistry = rpcProvisionRegistry;
-    this.config = new RemoteRpcProviderConfig(actorSystem.settings().config());
-  }
-
-  @Override
-  public void close() throws Exception {
-    if (this.actorSystem != null)
-      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 remote rpc service...");
-
-    SchemaService schemaService = brokerSession.getService(SchemaService.class);
-    schemaContext = schemaService.getGlobalContext();
-
-    rpcManager = actorSystem.actorOf(RpcManager.props(schemaContext, brokerSession, rpcProvisionRegistry),
-                                     config.getRpcManagerName());
-
-    LOG.debug("rpc manager started");
-  }
-
-  @Override
-  public void onGlobalContextUpdated(SchemaContext schemaContext) {
-    this.schemaContext = schemaContext;
-    rpcManager.tell(new UpdateSchemaContext(schemaContext), null);
-
-  }
+public class RemoteRpcProvider implements AutoCloseable {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class);
+
+    private final DOMRpcProviderService rpcProvisionRegistry;
+    private final RemoteRpcProviderConfig config;
+    private final ActorSystem actorSystem;
+    private final DOMRpcService rpcService;
+
+    private ActorRef rpcManager;
+
+    public RemoteRpcProvider(final ActorSystem actorSystem, final DOMRpcProviderService rpcProvisionRegistry,
+            final DOMRpcService rpcService, final RemoteRpcProviderConfig config) {
+        this.actorSystem = Preconditions.checkNotNull(actorSystem);
+        this.rpcProvisionRegistry = Preconditions.checkNotNull(rpcProvisionRegistry);
+        this.rpcService = Preconditions.checkNotNull(rpcService);
+        this.config = Preconditions.checkNotNull(config);
+    }
+
+    @Override
+    public void close() {
+        if (rpcManager != null) {
+            LOG.info("Stopping RPC Manager at {}", rpcManager);
+            rpcManager.tell(PoisonPill.getInstance(), ActorRef.noSender());
+            rpcManager = null;
+        }
+    }
+
+    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);
+    }
 }