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%2FRoutedRpcListener.java;h=c354320b8bea6bc450daeb976bdbe82d1e6f1ed9;hp=a6eeac02708a20e8a746581d80c5054a776ed671;hb=e631dc96f0461b2270377dc072b9f969a875667a;hpb=11e9ade9af527aba7faeb633d3c9c7552fd09d2d diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RoutedRpcListener.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RoutedRpcListener.java index a6eeac0270..c354320b8b 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RoutedRpcListener.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/RoutedRpcListener.java @@ -11,88 +11,82 @@ package org.opendaylight.controller.remote.rpc; import akka.actor.ActorRef; import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import org.opendaylight.controller.md.sal.common.api.routing.RouteChange; import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; -import org.opendaylight.controller.remote.rpc.messages.AddRoutedRpc; -import org.opendaylight.controller.remote.rpc.messages.RemoveRoutedRpc; -import org.opendaylight.controller.remote.rpc.utils.ActorUtil; +import org.opendaylight.controller.remote.rpc.registry.RpcRegistry; import org.opendaylight.controller.sal.connector.api.RpcRouter; import org.opendaylight.controller.sal.core.api.RpcRoutingContext; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - public class RoutedRpcListener implements RouteChangeListener{ - private static final Logger LOG = LoggerFactory.getLogger(RoutedRpcListener.class); - private final ActorRef rpcRegistry; - private final String actorPath; - - public RoutedRpcListener(ActorRef rpcRegistry, String actorPath) { - Preconditions.checkNotNull(rpcRegistry, "rpc registry actor should not be null"); - Preconditions.checkNotNull(actorPath, "actor path of rpc broker on current node should not be null"); + private static final Logger LOG = LoggerFactory.getLogger(RoutedRpcListener.class); + private final ActorRef rpcRegistry; - this.rpcRegistry = rpcRegistry; - this.actorPath = actorPath; - } + public RoutedRpcListener(final ActorRef rpcRegistry) { + Preconditions.checkNotNull(rpcRegistry, "rpc registry actor should not be null"); + this.rpcRegistry = rpcRegistry; + } - @Override - public void onRouteChange(RouteChange routeChange) { - Map> announcements = routeChange.getAnnouncements(); - announce(getRouteIdentifiers(announcements)); + @Override + public void onRouteChange(final RouteChange routeChange) { + final Map> announcements = routeChange.getAnnouncements(); + if(announcements != null && announcements.size() > 0){ + announce(getRouteIdentifiers(announcements)); + } - Map> removals = routeChange.getRemovals(); - remove(getRouteIdentifiers(removals)); - } + final Map> removals = routeChange.getRemovals(); + if(removals != null && removals.size() > 0 ) { + remove(getRouteIdentifiers(removals)); + } + } - /** - * - * @param announcements - */ - private void announce(Set> announcements) { - LOG.debug("Announcing [{}]", announcements); - AddRoutedRpc addRpcMsg = new AddRoutedRpc(announcements, actorPath); - try { - ActorUtil.executeLocalOperation(rpcRegistry, addRpcMsg, ActorUtil.LOCAL_ASK_DURATION, ActorUtil.LOCAL_AWAIT_DURATION); - } catch (Exception e) { - // Just logging it because Akka API throws this exception - LOG.error(e.toString()); + /** + * + * @param announcements + */ + private void announce(final Set> announcements) { + if(LOG.isDebugEnabled()) { + LOG.debug("Announcing [{}]", announcements); + } + final RpcRegistry.Messages.AddOrUpdateRoutes addRpcMsg = + new RpcRegistry.Messages.AddOrUpdateRoutes(new ArrayList<>(announcements)); + rpcRegistry.tell(addRpcMsg, ActorRef.noSender()); } - } - /** - * - * @param removals - */ - private void remove(Set> removals){ - LOG.debug("Removing [{}]", removals); - RemoveRoutedRpc removeRpcMsg = new RemoveRoutedRpc(removals, actorPath); - 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()); + /** + * + * @param removals + */ + private void remove(final Set> removals){ + if(LOG.isDebugEnabled()) { + LOG.debug("Removing [{}]", removals); + } + final RpcRegistry.Messages.RemoveRoutes removeRpcMsg = + new RpcRegistry.Messages.RemoveRoutes(new ArrayList<>(removals)); + rpcRegistry.tell(removeRpcMsg, ActorRef.noSender()); } - } - /** - * - * @param changes - * @return - */ - private Set> getRouteIdentifiers(Map> changes) { - RouteIdentifierImpl routeId = null; - Set> routeIdSet = new HashSet<>(); + /** + * + * @param changes + * @return + */ + private Set> getRouteIdentifiers( + final Map> changes) { - for (RpcRoutingContext context : changes.keySet()){ - for (YangInstanceIdentifier instanceId : changes.get(context)){ - routeId = new RouteIdentifierImpl(null, context.getRpc(), instanceId); - routeIdSet.add(routeId); - } + final Set> routeIdSet = new HashSet<>(); + for (final RpcRoutingContext context : changes.keySet()){ + for (final YangInstanceIdentifier instanceId : changes.get(context)){ + final RouteIdentifierImpl routeId = new RouteIdentifierImpl(null, context.getRpc(), instanceId); + routeIdSet.add(routeId); + } + } + return routeIdSet; } - return routeIdSet; - } }