From 06f236706986f689c6eafe77c5f02faed38a30ca Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sat, 18 Mar 2023 10:31:54 +0100 Subject: [PATCH] ExponentialBackoff: rename `retryTime()` method from `getRetryInstant()` --- core/src/main/java/org/bitcoinj/core/PeerGroup.java | 8 ++++---- .../main/java/org/bitcoinj/utils/ExponentialBackoff.java | 4 ++-- .../java/org/bitcoinj/utils/ExponentialBackoffTest.java | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/PeerGroup.java b/core/src/main/java/org/bitcoinj/core/PeerGroup.java index c47b3fdad..e727084a5 100644 --- a/core/src/main/java/org/bitcoinj/core/PeerGroup.java +++ b/core/src/main/java/org/bitcoinj/core/PeerGroup.java @@ -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); diff --git a/core/src/main/java/org/bitcoinj/utils/ExponentialBackoff.java b/core/src/main/java/org/bitcoinj/utils/ExponentialBackoff.java index 6d1c07f48..ca60cd6b1 100644 --- a/core/src/main/java/org/bitcoinj/utils/ExponentialBackoff.java +++ b/core/src/main/java/org/bitcoinj/utils/ExponentialBackoff.java @@ -89,13 +89,13 @@ public class ExponentialBackoff implements Comparable { } /** 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() { diff --git a/core/src/test/java/org/bitcoinj/utils/ExponentialBackoffTest.java b/core/src/test/java/org/bitcoinj/utils/ExponentialBackoffTest.java index 2a56fe596..5f80466a9 100644 --- a/core/src/test/java/org/bitcoinj/utils/ExponentialBackoffTest.java +++ b/core/src/test/java/org/bitcoinj/utils/ExponentialBackoffTest.java @@ -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