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%2Futils%2FLatestEntryRoutingLogic.java;h=f7b36a776e74af78b80b86837be5951b318b20a0;hp=f01baf009ba9026c23ab43eed10089e3961e0fdf;hb=7aaa993c7f3ed5cb11ffede692ef23f4ed2c9e47;hpb=9228eee6e438894b091f7bee8a4ba7b53286ef8f diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/utils/LatestEntryRoutingLogic.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/utils/LatestEntryRoutingLogic.java index f01baf009b..f7b36a776e 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/utils/LatestEntryRoutingLogic.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/utils/LatestEntryRoutingLogic.java @@ -11,52 +11,56 @@ package org.opendaylight.controller.remote.rpc.utils; import akka.actor.ActorRef; import akka.japi.Pair; import com.google.common.base.Preconditions; - +import java.io.Serializable; import java.util.Collection; import java.util.Comparator; import java.util.SortedSet; import java.util.TreeSet; /** - * This class will return First Entry + * This class will return First Entry. */ -public class LatestEntryRoutingLogic implements RoutingLogic{ +public class LatestEntryRoutingLogic implements RoutingLogic { + + private final SortedSet> actorRefSet; - private SortedSet> actorRefSet; + public LatestEntryRoutingLogic(Collection> entries) { + Preconditions.checkNotNull(entries, "Entries should not be null"); + Preconditions.checkArgument(!entries.isEmpty(), "Entries collection should not be empty"); + + actorRefSet = new TreeSet<>(new LatestEntryComparator()); + actorRefSet.addAll(entries); + } - public LatestEntryRoutingLogic(Collection> entries) { - Preconditions.checkNotNull(entries, "Entries should not be null"); - Preconditions.checkArgument(!entries.isEmpty(), "Entries collection should not be empty"); + @Override + public ActorRef select() { + return actorRefSet.last().first(); + } - actorRefSet = new TreeSet<>(new LatestEntryComparator()); - actorRefSet.addAll(entries); - } + private static class LatestEntryComparator implements Comparator>, Serializable { + private static final long serialVersionUID = 1L; - @Override - public ActorRef select() { - return actorRefSet.last().first(); - } + @Override + public int compare(Pair o1, Pair o2) { + if (o1 == null && o2 == null) { + return 0; + } + if (o1 != null && o2 != null && o1.second() == null && o2.second() == null) { + return 0; + } - private class LatestEntryComparator implements Comparator> { + if ((o1 == null || o1.second() == null) && o2 != null) { + return -1; + } - @Override - public int compare(Pair o1, Pair o2) { - if(o1 == null && o2 == null) { - return 0; - } - if(o1 == null && o2 != null) { - return -1; - } - if(o1 != null && o2 == null) { - return 1; - } - - return o1.second().compareTo(o2.second()); + if (o2 == null || o2.second() == null) { + return 1; + } + return o1.second().compareTo(o2.second()); + } } - - } }