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=80aebd1918a33e5fa588ec13348e11a4515f32e3;hp=ac50b8fe5b0fcdcbfb9f78ef495308586a4a313c;hb=b3b985fc482c43274ea1f8fa70c05ed16d96af4d;hpb=98eda7d02fdb6ae0c72edb88b125d166d6933ed0 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 ac50b8fe5b..80aebd1918 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 @@ -11,20 +11,20 @@ package org.opendaylight.controller.remote.rpc; import akka.actor.ActorRef; import akka.actor.ActorSystem; +import com.google.common.base.Preconditions; +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.remote.rpc.registry.ClusterWrapper; -import org.opendaylight.controller.remote.rpc.registry.ClusterWrapperImpl; 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.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; -import java.util.Collection; - /** * This is the base class which initialize all the actors, listeners and * default RPc implementation so remote invocation of rpcs. @@ -33,26 +33,45 @@ public class RemoteRpcProvider implements AutoCloseable, Provider, SchemaContext private static final Logger LOG = LoggerFactory.getLogger(RemoteRpcProvider.class); + private final DOMRpcProviderService rpcProvisionRegistry; + + private ListenerRegistration schemaListenerRegistration; private final ActorSystem actorSystem; - private final RpcProvisionRegistry rpcProvisionRegistry; - private Broker.ProviderSession brokerSession; + private SchemaService schemaService; + private DOMRpcService rpcService; private SchemaContext schemaContext; private ActorRef rpcManager; + private final RemoteRpcProviderConfig config; - public RemoteRpcProvider(ActorSystem actorSystem, RpcProvisionRegistry rpcProvisionRegistry) { + 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(DOMRpcService rpcService) { + this.rpcService = rpcService; + } + + public void setSchemaService(SchemaService schemaService) { + this.schemaService = schemaService; } @Override public void close() throws Exception { - this.actorSystem.shutdown(); + if (schemaListenerRegistration != null) { + schemaListenerRegistration.close(); + schemaListenerRegistration = null; + } } @Override - public void onSessionInitiated(Broker.ProviderSession session) { - this.brokerSession = session; + public void onSessionInitiated(final Broker.ProviderSession session) { + schemaService = session.getService(SchemaService.class); + rpcService = session.getService(DOMRpcService.class); start(); } @@ -61,23 +80,19 @@ public class RemoteRpcProvider implements AutoCloseable, Provider, SchemaContext return null; } - private void start() { - LOG.info("Starting all rpc listeners and actors."); - // Create actor to handle and sync routing table in cluster - ClusterWrapper clusterWrapper = new ClusterWrapperImpl(actorSystem); - SchemaService schemaService = brokerSession.getService(SchemaService.class); - schemaContext = schemaService.getGlobalContext(); - - rpcManager = actorSystem.actorOf(RpcManager.props(clusterWrapper, schemaContext, brokerSession, rpcProvisionRegistry), ActorConstants.RPC_MANAGER); + public void start() { + LOG.info("Starting remote rpc service..."); - LOG.debug("Rpc actors are created."); + 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 void onGlobalContextUpdated(SchemaContext schemaContext) { + public void onGlobalContextUpdated(final SchemaContext schemaContext) { this.schemaContext = schemaContext; rpcManager.tell(new UpdateSchemaContext(schemaContext), null); - } }