Skip to content

Commit

Permalink
EJBCLIENT-356 use eagerNodes mechanism for faster discovery result on…
Browse files Browse the repository at this point in the history
…ly when org.jboss.ejb.client.discovery.additional-node-timeout sysprop is set (#481)
  • Loading branch information
chengfang authored Nov 9, 2020
1 parent 1d9dddf commit 8ef14f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ public SessionID handleSessionCreation(final EJBSessionCreationInvocationContext
return sessionID;
}

/**
* Gets the value (in milliseconds) of discovery additional timeout,
* configured with system property {@code org.jboss.ejb.client.discovery.additional-node-timeout}.
*
* @return the value (in milliseconds) of discovery additional timeout
*/
public static long getDiscoveryAdditionalTimeout() {
return DISCOVERY_ADDITIONAL_TIMEOUT;
}

/**
* Intended to be called by interceptors which assign a new destination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javax.net.ssl.SSLContext;

import org.jboss.ejb._private.Logs;
import org.jboss.ejb.client.DiscoveryEJBClientInterceptor;
import org.jboss.ejb.client.EJBClientConnection;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.ejb.client.EJBModuleIdentifier;
Expand Down Expand Up @@ -374,7 +375,7 @@ final class DiscoveryAttempt implements DiscoveryRequest, DiscoveryResult {
/**
* nodes that have already been provided to the discovery provider eagerly
*/
private final Set<String> eagerNodes = Collections.synchronizedSet(new HashSet<>());
private final Set<String> eagerNodes;

DiscoveryAttempt(final ServiceType serviceType, final FilterSpec filterSpec, final DiscoveryResult discoveryResult, final RemoteEJBReceiver ejbReceiver, final AuthenticationContext authenticationContext) {
this.serviceType = serviceType;
Expand Down Expand Up @@ -421,6 +422,8 @@ public void handleDone(final EJBClientChannel clientChannel, final URI destinati
countDown();
}
};

eagerNodes = DiscoveryEJBClientInterceptor.getDiscoveryAdditionalTimeout() == 0 ? null : Collections.synchronizedSet(new HashSet<>());
}

void connectAndDiscover(URI uri, String clusterEffective) {
Expand Down Expand Up @@ -470,12 +473,12 @@ void countDown() {
final EJBModuleIdentifier module = filterSpec.accept(MI_EXTRACTOR);
if (phase2) {
if (node != null) {
if (!eagerNodes.contains(node)) {
if (eagerNodes == null || !eagerNodes.contains(node)) {
final NodeInformation information = nodes.get(node);
if (information != null) information.discover(serviceType, filterSpec, result);
}
} else for (NodeInformation information : nodes.values()) {
if (!eagerNodes.contains(information.getNodeName())) {
if (eagerNodes == null || !eagerNodes.contains(information.getNodeName())) {
information.discover(serviceType, filterSpec, result);
}
}
Expand All @@ -484,7 +487,7 @@ void countDown() {
boolean ok = false;
// optimize for simple module identifier and node name queries
if (node != null) {
if (!eagerNodes.contains(node)) {
if (eagerNodes == null || !eagerNodes.contains(node)) {
final NodeInformation information = nodes.get(node);
if (information != null) {
if (information.discover(serviceType, filterSpec, result)) {
Expand All @@ -493,13 +496,13 @@ void countDown() {
}
}
} else for (NodeInformation information : nodes.values()) {
if (!eagerNodes.contains(information.getNodeName())) {
if (eagerNodes == null || !eagerNodes.contains(information.getNodeName())) {
if (information.discover(serviceType, filterSpec, result)) {
ok = true;
}
}
}
if (ok || !eagerNodes.isEmpty()) {
if (ok || (eagerNodes != null && !eagerNodes.isEmpty())) {
result.complete();
} else {
// everything failed. We have to reconnect everything.
Expand Down Expand Up @@ -558,7 +561,7 @@ void countDown() {
countDown();
}
}
} else {
} else if (eagerNodes != null) {
final DiscoveryResult result = this.discoveryResult;
final String node = filterSpec.accept(NODE_EXTRACTOR);
if (node != null) {
Expand Down

0 comments on commit 8ef14f3

Please sign in to comment.