Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EJBCLIENT-344 remove unnecessary implementations of ..NodeSelector #411

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions src/main/java/org/jboss/ejb/client/ClusterNodeSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <em>may</em> 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, <em>or</em> if
* there are no more available nodes to choose from, the {@code met} selector is used, otherwise the {@code unmet}
Expand Down Expand Up @@ -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<String> connected = new HashSet<>(connectedNodes.length);
Collections.addAll(connected, connectedNodes);
final ArrayList<String> available = new ArrayList<>(totalAvailableNodes.length);
Collections.addAll(available, totalAvailableNodes);
available.removeAll(connected);
assert ! available.isEmpty();
return available.get(Math.floorMod(count.getAndIncrement(), connectedNodes.length));
}
};
}
}
23 changes: 0 additions & 23 deletions src/main/java/org/jboss/ejb/client/DeploymentNodeSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> favorites, DeploymentNodeSelector fallback) {
Assert.checkNotNullParam("favorites", favorites);
Assert.checkNotNullParam("fallback", fallback);
return (eligibleNodes, appName, moduleName, distinctName) -> {
final HashSet<String> set = new HashSet<String>(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.
Expand Down