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%2FRpcListener.java;h=28ff1523cbb676c5bf47d6180d96c9e7f1304230;hp=f6149906692ad0e5133938068508e80364d0769e;hb=1e884647502a8d91f8a57bde8193c60b9bbcce0d;hpb=07ba9a998f0b3c3045ed8e31afda5c96de141b3b diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcListener.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcListener.java index f614990669..28ff1523cb 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcListener.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RpcListener.java @@ -10,50 +10,55 @@ package org.opendaylight.controller.remote.rpc; import akka.actor.ActorRef; -import org.opendaylight.controller.remote.rpc.messages.AddRpc; -import org.opendaylight.controller.remote.rpc.messages.RemoveRpc; -import org.opendaylight.controller.remote.rpc.utils.ActorUtil; -import org.opendaylight.controller.sal.core.api.RpcRegistrationListener; -import org.opendaylight.yangtools.yang.common.QName; +import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier; +import org.opendaylight.controller.remote.rpc.registry.RpcRegistry; +import org.opendaylight.controller.sal.connector.api.RpcRouter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class RpcListener implements RpcRegistrationListener{ +public class RpcListener implements DOMRpcAvailabilityListener{ private static final Logger LOG = LoggerFactory.getLogger(RpcListener.class); private final ActorRef rpcRegistry; - private final String actorPath; - public RpcListener(ActorRef rpcRegistry, String actorPath) { + public RpcListener(final ActorRef rpcRegistry) { this.rpcRegistry = rpcRegistry; - this.actorPath = actorPath; } - @Override - public void onRpcImplementationAdded(QName rpc) { - LOG.debug("Adding registration for [{}]", rpc); - RouteIdentifierImpl routeId = new RouteIdentifierImpl(null, rpc, null); - AddRpc addRpcMsg = new AddRpc(routeId, actorPath); - try { - ActorUtil.executeLocalOperation(rpcRegistry, addRpcMsg, ActorUtil.LOCAL_ASK_DURATION, ActorUtil.LOCAL_AWAIT_DURATION); - LOG.debug("Route added [{}-{}]", routeId, this.actorPath); - } catch (Exception e) { - // Just logging it because Akka API throws this exception - LOG.error(e.toString()); - } + @Override + public void onRpcAvailable(@Nonnull final Collection rpcs) { + Preconditions.checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null."); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding registration for [{}]", rpcs); + } + final List> routeIds = new ArrayList<>(); - } + for (final DOMRpcIdentifier rpc : rpcs) { + final RpcRouter.RouteIdentifier routeId = new RouteIdentifierImpl(null, rpc.getType().getLastComponent(), null); + routeIds.add(routeId); + } + final RpcRegistry.Messages.AddOrUpdateRoutes addRpcMsg = new RpcRegistry.Messages.AddOrUpdateRoutes(routeIds); + rpcRegistry.tell(addRpcMsg, ActorRef.noSender()); + } - @Override - public void onRpcImplementationRemoved(QName rpc) { - LOG.debug("Removing registration for [{}]", rpc); - RouteIdentifierImpl routeId = new RouteIdentifierImpl(null, rpc, null); - RemoveRpc removeRpcMsg = new RemoveRpc(routeId); - try { - ActorUtil.executeLocalOperation(rpcRegistry, removeRpcMsg, ActorUtil.LOCAL_ASK_DURATION, ActorUtil.LOCAL_AWAIT_DURATION); - } catch (Exception e) { - // Just logging it because Akka API throws this exception - LOG.error(e.toString()); + @Override + public void onRpcUnavailable(@Nonnull final Collection rpcs) { + Preconditions.checkArgument(rpcs != null, "Input Collection of DOMRpcIdentifier can not be null."); + if(LOG.isDebugEnabled()) { + LOG.debug("Removing registration for [{}]", rpcs); + } + final List> routeIds = new ArrayList<>(); + for (final DOMRpcIdentifier rpc : rpcs) { + final RpcRouter.RouteIdentifier routeId = new RouteIdentifierImpl(null, rpc.getType().getLastComponent(), null); + routeIds.add(routeId); + } + final RpcRegistry.Messages.RemoveRoutes removeRpcMsg = new RpcRegistry.Messages.RemoveRoutes(routeIds); + rpcRegistry.tell(removeRpcMsg, ActorRef.noSender()); } - } }