Skip to content

Commit

Permalink
- make recheck interval configurable
Browse files Browse the repository at this point in the history
- use nanoTime
  • Loading branch information
Igor Vagulin committed Jan 21, 2019
1 parent e80d456 commit adb40f3
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.AccessController;
import java.security.GeneralSecurityException;
import java.security.PrivilegedAction;
import java.util.ArrayList;
Expand All @@ -40,6 +41,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -85,7 +87,16 @@ final class RemotingEJBDiscoveryProvider implements DiscoveryProvider, Discovere
private final ConcurrentHashMap<String, Set<String>> clusterNodes = new ConcurrentHashMap<>();

private final ConcurrentHashMap<String, URI> effectiveAuthURIs = new ConcurrentHashMap<>();


private static final long DESTINATION_RECHECK_INTERVAL =
AccessController.doPrivileged((PrivilegedAction<Long>) () -> {
String val = System.getProperty("org.jboss.ejb.client.destination-recheck-interval");
try {
return TimeUnit.MILLISECONDS.toNanos(Long.valueOf(val));
} catch (NumberFormatException e) {
return TimeUnit.MILLISECONDS.toNanos(5000L);
}
});

public RemotingEJBDiscoveryProvider() {
Endpoint.getCurrent(); //this will blow up if remoting is not present, preventing this from being registered
Expand Down Expand Up @@ -119,8 +130,8 @@ private boolean haveNotExpiredFailedDestination(URI uri) {
return false;
else {
long failureTimestamp = failedDestinations.get(uri);
long delta = System.currentTimeMillis() - failureTimestamp;
return delta < 5000;
long delta = System.nanoTime() - failureTimestamp;
return delta < DESTINATION_RECHECK_INTERVAL;
}
}

Expand Down Expand Up @@ -357,7 +368,7 @@ public void handleCancelled(final URI destination) {

public void handleFailed(final IOException exception, final URI destination) {
DiscoveryAttempt.this.discoveryResult.reportProblem(exception);
failedDestinations.put(destination, System.currentTimeMillis());
failedDestinations.put(destination, System.nanoTime());
countDown();
}

Expand All @@ -374,7 +385,7 @@ public void handleCancelled(final URI destination) {

public void handleFailed(final IOException exception, final URI destination) {
DiscoveryAttempt.this.discoveryResult.reportProblem(exception);
failedDestinations.put(destination, System.currentTimeMillis());
failedDestinations.put(destination, System.nanoTime());
countDown();
}

Expand Down

0 comments on commit adb40f3

Please sign in to comment.