Skip to content

Commit

Permalink
Fixed getSiteNames(): returning duplicates by using a list instead of…
Browse files Browse the repository at this point in the history
… a set
  • Loading branch information
belaban committed Aug 4, 2023
1 parent e9345e9 commit 581a203
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/org/jgroups/protocols/relay/RELAY.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public Route getRoute(String site_name) {
* @return A {@link List} of sites name that are currently up or {@code null} if this node is not a Site Master (i.e.
* {@link #isSiteMaster()} returns false).
*/
public List<String> getCurrentSites() {
public Collection<String> getCurrentSites() {
Relayer rel=relayer;
return rel == null ? null : rel.getSiteNames();
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/jgroups/protocols/relay/RELAY2.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ protected void startRelayer(Relayer2 rel, String bridge_name) {

protected String _printTopology(Relayer rel) {
Map<Address,String> local_sitemasters=new HashMap<>();
List<String> all_sites=rel.getSiteNames();
Collection<String> all_sites=rel.getSiteNames();
List<Supplier<Boolean>> topo_reqs=new ArrayList<>();
for(String site_name: all_sites) {
Route r=rel.getRoute(site_name);
Expand Down
9 changes: 3 additions & 6 deletions src/org/jgroups/protocols/relay/Relayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import org.jgroups.logging.Log;
import org.jgroups.util.Util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -110,9 +107,9 @@ protected synchronized Route getForwardingRouteMatching(String site, Address sen
return null;
}

protected List<String> getSiteNames() {
protected Collection<String> getSiteNames() {
return Stream.concat(Stream.of(relay.site()), routes.keySet().stream())
.collect(Collectors.toList());
.collect(Collectors.toSet());
}

protected static boolean isExcluded(Route route, String... excluded_sites) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ protected boolean checkQueue() {
System.out.printf("-- sorted requests from %s to: %s\n", requests, l);
requests.clear();
requests.addAll(l);
process(requests);
process();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,16 @@ protected static Route getRoute(JChannel ch, String site_name) {
return relay.getRoute(site_name);
}

protected List<String> getCurrentSites(JChannel channel) {
protected static Collection<String> getCurrentSites(JChannel channel) {
RELAY relay=channel.getProtocolStack().findProtocol(RELAY.class);
return relay.getCurrentSites();
}

protected void assertSiteView(JChannel channel, Collection<String> sitesName) {
List<String> sites = getCurrentSites(channel);
protected static void assertSiteView(JChannel channel, Collection<String> siteNames) {
Collection<String> sites=getCurrentSites(channel);
assert sites != null;
assert sites.size() == sitesName.size();
for (String site : sitesName)
assert sites.size() == siteNames.size();
for(String site: siteNames)
assert sites.contains(site);
}

Expand Down

0 comments on commit 581a203

Please sign in to comment.