X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2FRemoteRpcProvider.java;h=e4f6a21f8e75fafca75fb29bd6f8ba249c85f19f;hp=80aebd1918a33e5fa588ec13348e11a4515f32e3;hb=ea13216ab31269d4d0b822efb346a00ad82276ef;hpb=b3b985fc482c43274ea1f8fa70c05ed16d96af4d diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProvider.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProvider.java index 80aebd1918..e4f6a21f8e 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProvider.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RemoteRpcProvider.java @@ -8,20 +8,16 @@ 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,70 +25,52 @@ 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 { - - private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class); - - private final DOMRpcProviderService rpcProvisionRegistry; - - private ListenerRegistration schemaListenerRegistration; - private final ActorSystem actorSystem; - private SchemaService schemaService; - private DOMRpcService rpcService; - private SchemaContext schemaContext; - private ActorRef rpcManager; - private final RemoteRpcProviderConfig config; - +public class RemoteRpcProvider implements AutoCloseable, Provider { - public RemoteRpcProvider(final ActorSystem actorSystem, - final DOMRpcProviderService rpcProvisionRegistry, - final RemoteRpcProviderConfig config) { - this.actorSystem = actorSystem; - this.rpcProvisionRegistry = rpcProvisionRegistry; - this.config = Preconditions.checkNotNull(config); - } + private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class); - public void setRpcService(DOMRpcService rpcService) { - this.rpcService = rpcService; - } + private final DOMRpcProviderService rpcProvisionRegistry; + private final RemoteRpcProviderConfig config; + private final ActorSystem actorSystem; - public void setSchemaService(SchemaService schemaService) { - this.schemaService = schemaService; - } + private DOMRpcService rpcService; + private ActorRef rpcManager; - @Override - public void close() throws Exception { - if (schemaListenerRegistration != null) { - schemaListenerRegistration.close(); - schemaListenerRegistration = null; + public RemoteRpcProvider(final ActorSystem actorSystem, final DOMRpcProviderService rpcProvisionRegistry, + final RemoteRpcProviderConfig config) { + this.actorSystem = actorSystem; + this.rpcProvisionRegistry = rpcProvisionRegistry; + this.config = Preconditions.checkNotNull(config); } - } - @Override - public void onSessionInitiated(final Broker.ProviderSession session) { - schemaService = session.getService(SchemaService.class); - rpcService = session.getService(DOMRpcService.class); - start(); - } + public void setRpcService(final DOMRpcService rpcService) { + this.rpcService = rpcService; + } - @Override - public Collection getProviderFunctionality() { - return null; - } + @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..."); + @Override + public void onSessionInitiated(final Broker.ProviderSession session) { + rpcService = session.getService(DOMRpcService.class); + start(); + } - schemaContext = schemaService.getGlobalContext(); - rpcManager = actorSystem.actorOf(RpcManager.props(schemaContext, - rpcProvisionRegistry, rpcService, config), config.getRpcManagerName()); - schemaListenerRegistration = schemaService.registerSchemaContextListener(this); - LOG.debug("rpc manager started"); - } + @Override + public Collection getProviderFunctionality() { + return ImmutableSet.of(); + } - @Override - public void onGlobalContextUpdated(final SchemaContext schemaContext) { - this.schemaContext = schemaContext; - rpcManager.tell(new UpdateSchemaContext(schemaContext), 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); + } }