From c9d600a864b1385b5d3809e9337109a0a1bd203e Mon Sep 17 00:00:00 2001 From: Wolf-Dieter Fink Date: Fri, 9 Aug 2019 12:48:04 +0200 Subject: [PATCH] EJBCLIENT-344 remove unnecessary implementations of ..NodeSelector --- .../jboss/ejb/client/ClusterNodeSelector.java | 44 ------------------- .../ejb/client/DeploymentNodeSelector.java | 23 ---------- 2 files changed, 67 deletions(-) diff --git a/src/main/java/org/jboss/ejb/client/ClusterNodeSelector.java b/src/main/java/org/jboss/ejb/client/ClusterNodeSelector.java index 26627b83b..2a20eba8c 100644 --- a/src/main/java/org/jboss/ejb/client/ClusterNodeSelector.java +++ b/src/main/java/org/jboss/ejb/client/ClusterNodeSelector.java @@ -109,24 +109,6 @@ static ClusterNodeSelector useRandomConnectedNode(ClusterNodeSelector fallback) }; } - /** - * Always try to round-robin among connected nodes. If no nodes are connected, the fallback is used. Note - * that the round-robin node count may be shared among multiple node sets, thus certain specific usage patterns - * may defeat the round-robin behavior. - * - * @param fallback the fallback selector (must not be {@code null}) - * @return the node selector (not {@code null}) - */ - static ClusterNodeSelector useRoundRobinConnectedNode(ClusterNodeSelector fallback) { - Assert.checkNotNullParam("fallback", fallback); - return new ClusterNodeSelector() { - private final AtomicInteger count = new AtomicInteger(); - public String selectNode(final String clusterName, final String[] connectedNodes, final String[] totalAvailableNodes) { - return connectedNodes.length > 0 ? connectedNodes[Math.floorMod(count.getAndIncrement(), connectedNodes.length)] : fallback.selectNode(clusterName, connectedNodes, totalAvailableNodes); - } - }; - } - /** * Determine the action to take based on a threshold of minimum connections. If the minimum is met, or if * there are no more available nodes to choose from, the {@code met} selector is used, otherwise the {@code unmet} @@ -163,30 +145,4 @@ static ClusterNodeSelector useRandomUnconnectedNode(ClusterNodeSelector fallback return available.get(ThreadLocalRandom.current().nextInt(available.size())); }; } - - /** - * Always try to use an unconnected node in a round-robin fashion. If all nodes are connected, the fallback is used. - * - * @param fallback the selector to use if all available nodes are connected (must not be {@code null}) - * @return the node selector (not {@code null}) - */ - static ClusterNodeSelector useRoundRobinUnconnectedNode(ClusterNodeSelector fallback) { - Assert.checkNotNullParam("fallback", fallback); - return new ClusterNodeSelector() { - private final AtomicInteger count = new AtomicInteger(); - public String selectNode(final String clusterName, final String[] connectedNodes, final String[] totalAvailableNodes) { - if (connectedNodes.length == totalAvailableNodes.length) { - // totalAvailableNodes contains all connectedNodes; if their sizes are equal then all nodes must be connected - return fallback.selectNode(clusterName, connectedNodes, totalAvailableNodes); - } - final HashSet connected = new HashSet<>(connectedNodes.length); - Collections.addAll(connected, connectedNodes); - final ArrayList available = new ArrayList<>(totalAvailableNodes.length); - Collections.addAll(available, totalAvailableNodes); - available.removeAll(connected); - assert ! available.isEmpty(); - return available.get(Math.floorMod(count.getAndIncrement(), connectedNodes.length)); - } - }; - } } diff --git a/src/main/java/org/jboss/ejb/client/DeploymentNodeSelector.java b/src/main/java/org/jboss/ejb/client/DeploymentNodeSelector.java index b67800487..aadefd561 100644 --- a/src/main/java/org/jboss/ejb/client/DeploymentNodeSelector.java +++ b/src/main/java/org/jboss/ejb/client/DeploymentNodeSelector.java @@ -53,29 +53,6 @@ public interface DeploymentNodeSelector { */ String selectNode(final String[] eligibleNodes, final String appName, final String moduleName, final String distinctName); - /** - * Create a deployment node selector that prefers one or more favorite nodes, falling back to another selector if - * none of the favorites are found. - * - * @param favorites the favorite nodes, in decreasing order of preference (must not be {@code null}) - * @param fallback the fallback selector (must not be {@code null}) - * @return the selector (not {@code null}) - */ - static DeploymentNodeSelector favorite(Collection favorites, DeploymentNodeSelector fallback) { - Assert.checkNotNullParam("favorites", favorites); - Assert.checkNotNullParam("fallback", fallback); - return (eligibleNodes, appName, moduleName, distinctName) -> { - final HashSet set = new HashSet(eligibleNodes.length); - Collections.addAll(set, eligibleNodes); - for (String favorite : favorites) { - if (set.contains(favorite)) { - return favorite; - } - } - return fallback.selectNode(eligibleNodes, appName, moduleName, distinctName); - }; - } - /** * A deployment node selector which prefers the first node always. This will generally avoid load balancing in most * cases.