ExponentialBackoff: rename retryTime() method from getRetryInstant()

This commit is contained in:
Andreas Schildbach 2023-03-18 10:31:54 +01:00
parent 516acd51c6
commit 06f2367069
3 changed files with 10 additions and 10 deletions

View File

@ -563,7 +563,7 @@ public class PeerGroup implements TransactionBroadcaster {
return;
}
boolean havePeerWeCanTry = !inactives.isEmpty() && backoffMap.get(inactives.peek()).getRetryInstant().isBefore(now);
boolean havePeerWeCanTry = !inactives.isEmpty() && backoffMap.get(inactives.peek()).retryTime().isBefore(now);
doDiscovery = !havePeerWeCanTry;
} finally {
firstRun = false;
@ -590,7 +590,7 @@ public class PeerGroup implements TransactionBroadcaster {
// Inactives is sorted by backoffMap time.
if (inactives.isEmpty()) {
if (countConnectedAndPendingPeers() < getMaxConnections()) {
Duration interval = TimeUtils.longest(Duration.between(now, groupBackoff.getRetryInstant()), MIN_PEER_DISCOVERY_INTERVAL);
Duration interval = TimeUtils.longest(Duration.between(now, groupBackoff.retryTime()), MIN_PEER_DISCOVERY_INTERVAL);
log.info("Peer discovery didn't provide us any more peers, will try again in "
+ interval.toMillis() + " ms.");
executor.schedule(this, interval.toMillis(), TimeUnit.MILLISECONDS);
@ -609,8 +609,8 @@ public class PeerGroup implements TransactionBroadcaster {
// Most likely we were given a fixed set of addresses in some test scenario.
return;
}
Instant retryTime = backoffMap.get(addrToTry).getRetryInstant();
retryTime = TimeUtils.later(retryTime, groupBackoff.getRetryInstant());
Instant retryTime = backoffMap.get(addrToTry).retryTime();
retryTime = TimeUtils.later(retryTime, groupBackoff.retryTime());
if (retryTime.isAfter(now)) {
Duration delay = Duration.between(now, retryTime);
log.info("Waiting {} ms before next connect attempt to {}", delay.toMillis(), addrToTry);

View File

@ -89,13 +89,13 @@ public class ExponentialBackoff implements Comparable<ExponentialBackoff> {
}
/** Get the next time to retry */
public Instant getRetryInstant() {
public Instant retryTime() {
return retryTime;
}
/**
* Get the next time to retry, in milliseconds since the epoch
* @deprecated use {@link #getRetryInstant()}
* @deprecated use {@link #retryTime()}
**/
@Deprecated
public long getRetryTime() {

View File

@ -37,24 +37,24 @@ public class ExponentialBackoffTest {
@Test
public void testSuccess() {
assertEquals(TimeUtils.currentTime(), backoff.getRetryInstant());
assertEquals(TimeUtils.currentTime(), backoff.retryTime());
backoff.trackFailure();
backoff.trackFailure();
backoff.trackSuccess();
assertEquals(TimeUtils.currentTime(), backoff.getRetryInstant());
assertEquals(TimeUtils.currentTime(), backoff.retryTime());
}
@Test
public void testFailure() {
assertEquals(TimeUtils.currentTime(), backoff.getRetryInstant());
assertEquals(TimeUtils.currentTime(), backoff.retryTime());
backoff.trackFailure();
backoff.trackFailure();
backoff.trackFailure();
assertEquals(TimeUtils.currentTime().plusMillis(121), backoff.getRetryInstant());
assertEquals(TimeUtils.currentTime().plusMillis(121), backoff.retryTime());
}
@Test