From 4e5f052bd708057ac0e21ba7e2751429909b51ae Mon Sep 17 00:00:00 2001 From: "marcin.cebo" Date: Fri, 15 Dec 2023 12:16:26 +0100 Subject: [PATCH 1/5] Modified PNReconnectionPolicy Default and max value for maximumReconnectionRetries is 10 Added random value 0,001-2,999s to delay between retry both for Linear and Exponential policy. --- .../java/com/pubnub/api/PNConfiguration.java | 7 ++- .../managers/DelayedReconnectionManager.java | 18 +++++++- .../api/managers/ReconnectionManager.java | 46 ++++++++++++++----- .../api/managers/ReconnectionManagerTest.java | 14 +++--- 4 files changed, 64 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/pubnub/api/PNConfiguration.java b/src/main/java/com/pubnub/api/PNConfiguration.java index e646c07d6..09cc16cd7 100644 --- a/src/main/java/com/pubnub/api/PNConfiguration.java +++ b/src/main/java/com/pubnub/api/PNConfiguration.java @@ -38,6 +38,7 @@ public class PNConfiguration { private static final int SUBSCRIBE_TIMEOUT = 310; private static final int CONNECT_TIMEOUT = 5; private static final int FILE_MESSAGE_PUBLISH_RETRY_LIMIT = 5; + private static final int MAXIMUM_RECONNECTION_RETRIES = 10; @Getter private SSLSocketFactory sslSocketFactory; @@ -201,7 +202,9 @@ public void setUserId(@NotNull UserId userId) { private PNReconnectionPolicy reconnectionPolicy; /** - * Set how many times the reconneciton manager will try to connect before giving app + * Set how many times the reconnection manager will try to connect before giving up. + * Max allowed value is 10. + * Default is 10. */ @Setter private int maximumReconnectionRetries; @@ -284,7 +287,7 @@ public PNConfiguration(@NotNull UserId userId) throws PubNubException { startSubscriberThread = true; - maximumReconnectionRetries = -1; + maximumReconnectionRetries = MAXIMUM_RECONNECTION_RETRIES; dedupOnSubscribe = false; suppressLeaveEvents = false; diff --git a/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java b/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java index 7a84b8599..63f6274ed 100644 --- a/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java +++ b/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java @@ -5,17 +5,21 @@ import com.pubnub.api.enums.PNReconnectionPolicy; import lombok.extern.slf4j.Slf4j; +import java.text.DecimalFormat; +import java.util.Random; import java.util.Timer; import java.util.TimerTask; @Slf4j public class DelayedReconnectionManager { private static final int DELAY_SECONDS = 3; + private static final int MAX_RANDOM = 3; private static final int MILLISECONDS = 1000; private final PNReconnectionPolicy pnReconnectionPolicy; private ReconnectionCallback callback; private PubNub pubnub; + private Random random = new Random(); /** * Timer for heartbeat operations. @@ -34,12 +38,13 @@ public void scheduleDelayedReconnection() { } timer = new Timer("Delayed Reconnection Manager timer", true); + int effectiveDelayInMilliSeconds = (int) ((DELAY_SECONDS + getRandomDelay()) * MILLISECONDS); timer.schedule(new TimerTask() { @Override public void run() { callTime(); } - }, DELAY_SECONDS * MILLISECONDS); + }, effectiveDelayInMilliSeconds); } public void setReconnectionListener(ReconnectionCallback reconnectionCallback) { @@ -61,8 +66,19 @@ private boolean isReconnectionPolicyUndefined() { return false; } + private double getRandomDelay() { + double randomDelay = MAX_RANDOM * random.nextDouble(); + randomDelay = roundTo3DecimalPlaces(randomDelay); + return randomDelay; + } + private void callTime() { stop(); callback.onReconnection(); } + + private double roundTo3DecimalPlaces(double value) { + DecimalFormat decimalFormat = new DecimalFormat("#.###"); + return Double.parseDouble(decimalFormat.format(value)); + } } diff --git a/src/main/java/com/pubnub/api/managers/ReconnectionManager.java b/src/main/java/com/pubnub/api/managers/ReconnectionManager.java index 7a1cc4858..6f866b4cf 100644 --- a/src/main/java/com/pubnub/api/managers/ReconnectionManager.java +++ b/src/main/java/com/pubnub/api/managers/ReconnectionManager.java @@ -9,7 +9,9 @@ import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; +import java.text.DecimalFormat; import java.util.Calendar; +import java.util.Random; import java.util.Timer; import java.util.TimerTask; @@ -18,10 +20,12 @@ public class ReconnectionManager { private static final int LINEAR_INTERVAL = 3; - private static final int MIN_EXPONENTIAL_BACKOFF = 1; + private static final int MAX_RANDOM = 3; + private static final int MIN_EXPONENTIAL_BACKOFF = 2; private static final int MAX_EXPONENTIAL_BACKOFF = 32; private static final int MILLISECONDS = 1000; + public static final int MAXIMUM_RECONNECTION_RETRIES_DEFAULT = 10; private ReconnectionCallback callback; private PubNub pubnub; @@ -31,6 +35,7 @@ public class ReconnectionManager { private PNReconnectionPolicy pnReconnectionPolicy; private int maxConnectionRetries; + private Random random = new Random(); /** * Timer for heartbeat operations. @@ -40,7 +45,16 @@ public class ReconnectionManager { public ReconnectionManager(PubNub pubnub) { this.pubnub = pubnub; this.pnReconnectionPolicy = pubnub.getConfiguration().getReconnectionPolicy(); - this.maxConnectionRetries = pubnub.getConfiguration().getMaximumReconnectionRetries(); + this.maxConnectionRetries = getMaximumReconnectionRetries(); + } + + private int getMaximumReconnectionRetries() { + int maximumReconnectionRetries = pubnub.getConfiguration().getMaximumReconnectionRetries(); + if (maximumReconnectionRetries < 0 || maximumReconnectionRetries > MAXIMUM_RECONNECTION_RETRIES_DEFAULT) { + maximumReconnectionRetries = MAXIMUM_RECONNECTION_RETRIES_DEFAULT; + } + log.debug("maximumReconnectionRetries is: " + maximumReconnectionRetries); + return maximumReconnectionRetries; } public void setReconnectionListener(ReconnectionCallback reconnectionCallback) { @@ -55,10 +69,10 @@ public void startPolling() { exponentialMultiplier = 1; failedCalls = 0; - registerHeartbeatTimer(); + registerRetryTimer(); } - private void registerHeartbeatTimer() { + private void registerRetryTimer() { // make sure only one timer is running at a time. stopHeartbeatTimer(); @@ -66,7 +80,7 @@ private void registerHeartbeatTimer() { return; } - if (maxConnectionRetries != -1 && failedCalls >= maxConnectionRetries) { // _what's -1? + if (failedCalls >= maxConnectionRetries) { callback.onMaxReconnectionExhaustion(); return; } @@ -78,10 +92,10 @@ private void registerHeartbeatTimer() { public void run() { callTime(); } - }, getNextInterval() * MILLISECONDS); + }, getNextIntervalInMilliSeconds()); } - int getNextInterval() { + int getNextIntervalInMilliSeconds() { int timerInterval = LINEAR_INTERVAL; failedCalls++; @@ -95,16 +109,26 @@ int getNextInterval() { } else if (timerInterval < 1) { timerInterval = MIN_EXPONENTIAL_BACKOFF; } - log.debug("timerInterval = " + timerInterval + " at: " + Calendar.getInstance().getTime().toString()); + timerInterval = (int) ((timerInterval + getRandomDelay()) * MILLISECONDS); + log.debug("timerInterval = " + timerInterval + "ms at: " + Calendar.getInstance().getTime().toString()); } if (pnReconnectionPolicy == PNReconnectionPolicy.LINEAR) { - timerInterval = LINEAR_INTERVAL; + timerInterval = (int) ((LINEAR_INTERVAL + getRandomDelay()) * MILLISECONDS); } - return timerInterval; } + private double getRandomDelay() { + double randomDelay = MAX_RANDOM * random.nextDouble(); + return roundTo3DecimalPlaces(randomDelay); + } + + private double roundTo3DecimalPlaces(double value) { + DecimalFormat decimalFormat = new DecimalFormat("#.###"); + return Double.parseDouble(decimalFormat.format(value)); + } + private void stopHeartbeatTimer() { if (timer != null) { timer.cancel(); @@ -121,7 +145,7 @@ public void onResponse(PNTimeResult result, @NotNull PNStatus status) { callback.onReconnection(); } else { log.debug("callTime() at: " + Calendar.getInstance().getTime().toString()); - registerHeartbeatTimer(); + registerRetryTimer(); } } }); diff --git a/src/test/java/com/pubnub/api/managers/ReconnectionManagerTest.java b/src/test/java/com/pubnub/api/managers/ReconnectionManagerTest.java index 647e14bbf..2738eed96 100644 --- a/src/test/java/com/pubnub/api/managers/ReconnectionManagerTest.java +++ b/src/test/java/com/pubnub/api/managers/ReconnectionManagerTest.java @@ -9,7 +9,6 @@ import java.util.UUID; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class ReconnectionManagerTest { @@ -20,10 +19,11 @@ public void reconnectionIntervalsEqualsForLinear() throws PubNubException { pnConfiguration.setReconnectionPolicy(PNReconnectionPolicy.LINEAR); final ReconnectionManager reconnectionManagerUnderTest = new ReconnectionManager(pubNub); - int firstInterval = reconnectionManagerUnderTest.getNextInterval(); - int secondInterval = reconnectionManagerUnderTest.getNextInterval(); + int firstInterval = reconnectionManagerUnderTest.getNextIntervalInMilliSeconds(); + int secondInterval = reconnectionManagerUnderTest.getNextIntervalInMilliSeconds(); - assertEquals(secondInterval, firstInterval); + assertTrue(firstInterval >= 3000 && firstInterval <= 6000); + assertTrue(secondInterval >= 3000 && secondInterval <= 6000); } @Test @@ -33,9 +33,9 @@ public void reconnectionIntervalsIncreaseForExponential() throws PubNubException PubNub pubNub = new PubNub(pnConfiguration); final ReconnectionManager reconnectionManagerUnderTest = new ReconnectionManager(pubNub); - int firstInterval = reconnectionManagerUnderTest.getNextInterval(); - int secondInterval = reconnectionManagerUnderTest.getNextInterval(); - int thirdInterval = reconnectionManagerUnderTest.getNextInterval(); + int firstInterval = reconnectionManagerUnderTest.getNextIntervalInMilliSeconds(); + int secondInterval = reconnectionManagerUnderTest.getNextIntervalInMilliSeconds(); + int thirdInterval = reconnectionManagerUnderTest.getNextIntervalInMilliSeconds(); assertTrue(firstInterval < secondInterval); assertTrue(secondInterval < thirdInterval); From 3bb2e89fcffed8ac7c18bad3cc2287490c959fb5 Mon Sep 17 00:00:00 2001 From: "marcin.cebo" Date: Mon, 18 Dec 2023 13:15:29 +0100 Subject: [PATCH 2/5] Changes after review. --- .../java/com/pubnub/api/PNConfiguration.java | 4 +-- .../managers/DelayedReconnectionManager.java | 21 ++++--------- .../api/managers/ReconnectionManager.java | 30 ++++++++----------- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/pubnub/api/PNConfiguration.java b/src/main/java/com/pubnub/api/PNConfiguration.java index 09cc16cd7..daf201b13 100644 --- a/src/main/java/com/pubnub/api/PNConfiguration.java +++ b/src/main/java/com/pubnub/api/PNConfiguration.java @@ -38,7 +38,7 @@ public class PNConfiguration { private static final int SUBSCRIBE_TIMEOUT = 310; private static final int CONNECT_TIMEOUT = 5; private static final int FILE_MESSAGE_PUBLISH_RETRY_LIMIT = 5; - private static final int MAXIMUM_RECONNECTION_RETRIES = 10; + private static final int MAXIMUM_RECONNECTION_RETRIES_DEFAULT = 6; @Getter private SSLSocketFactory sslSocketFactory; @@ -287,7 +287,7 @@ public PNConfiguration(@NotNull UserId userId) throws PubNubException { startSubscriberThread = true; - maximumReconnectionRetries = MAXIMUM_RECONNECTION_RETRIES; + maximumReconnectionRetries = MAXIMUM_RECONNECTION_RETRIES_DEFAULT; dedupOnSubscribe = false; suppressLeaveEvents = false; diff --git a/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java b/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java index 63f6274ed..2bcbb75d7 100644 --- a/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java +++ b/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java @@ -5,21 +5,19 @@ import com.pubnub.api.enums.PNReconnectionPolicy; import lombok.extern.slf4j.Slf4j; -import java.text.DecimalFormat; import java.util.Random; import java.util.Timer; import java.util.TimerTask; @Slf4j public class DelayedReconnectionManager { - private static final int DELAY_SECONDS = 3; - private static final int MAX_RANDOM = 3; - private static final int MILLISECONDS = 1000; + private static final int BASE_DELAY_MILLISECONDS = 2000; + private static final int BOUND = 1000; private final PNReconnectionPolicy pnReconnectionPolicy; private ReconnectionCallback callback; private PubNub pubnub; - private Random random = new Random(); + private final Random random = new Random(); /** * Timer for heartbeat operations. @@ -38,7 +36,7 @@ public void scheduleDelayedReconnection() { } timer = new Timer("Delayed Reconnection Manager timer", true); - int effectiveDelayInMilliSeconds = (int) ((DELAY_SECONDS + getRandomDelay()) * MILLISECONDS); + int effectiveDelayInMilliSeconds = (int) (BASE_DELAY_MILLISECONDS + getRandomDelayInMilliSeconds()); timer.schedule(new TimerTask() { @Override public void run() { @@ -66,19 +64,12 @@ private boolean isReconnectionPolicyUndefined() { return false; } - private double getRandomDelay() { - double randomDelay = MAX_RANDOM * random.nextDouble(); - randomDelay = roundTo3DecimalPlaces(randomDelay); - return randomDelay; + private double getRandomDelayInMilliSeconds() { + return random.nextInt(BOUND); } private void callTime() { stop(); callback.onReconnection(); } - - private double roundTo3DecimalPlaces(double value) { - DecimalFormat decimalFormat = new DecimalFormat("#.###"); - return Double.parseDouble(decimalFormat.format(value)); - } } diff --git a/src/main/java/com/pubnub/api/managers/ReconnectionManager.java b/src/main/java/com/pubnub/api/managers/ReconnectionManager.java index 6f866b4cf..7cee83cd8 100644 --- a/src/main/java/com/pubnub/api/managers/ReconnectionManager.java +++ b/src/main/java/com/pubnub/api/managers/ReconnectionManager.java @@ -9,7 +9,6 @@ import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; -import java.text.DecimalFormat; import java.util.Calendar; import java.util.Random; import java.util.Timer; @@ -19,13 +18,13 @@ @Slf4j public class ReconnectionManager { - private static final int LINEAR_INTERVAL = 3; - private static final int MAX_RANDOM = 3; + private static final int BASE_LINEAR_INTERVAL_IN_MILLISECONDS = 3000; private static final int MIN_EXPONENTIAL_BACKOFF = 2; private static final int MAX_EXPONENTIAL_BACKOFF = 32; - private static final int MILLISECONDS = 1000; - public static final int MAXIMUM_RECONNECTION_RETRIES_DEFAULT = 10; + private static final int BOUND = 1000; + private static final int MILLISECONDS = BOUND; + private static final int MAXIMUM_RECONNECTION_RETRIES_DEFAULT = 10; private ReconnectionCallback callback; private PubNub pubnub; @@ -35,7 +34,7 @@ public class ReconnectionManager { private PNReconnectionPolicy pnReconnectionPolicy; private int maxConnectionRetries; - private Random random = new Random(); + private final Random random = new Random(); /** * Timer for heartbeat operations. @@ -96,7 +95,7 @@ public void run() { } int getNextIntervalInMilliSeconds() { - int timerInterval = LINEAR_INTERVAL; + int timerInterval = 0; failedCalls++; if (pnReconnectionPolicy == PNReconnectionPolicy.EXPONENTIAL) { @@ -105,29 +104,24 @@ int getNextIntervalInMilliSeconds() { if (timerInterval > MAX_EXPONENTIAL_BACKOFF) { timerInterval = MIN_EXPONENTIAL_BACKOFF; exponentialMultiplier = 1; - log.debug("timerInterval > MAXEXPONENTIALBACKOFF at: " + Calendar.getInstance().getTime().toString()); + log.debug("timerInterval > MAXEXPONENTIALBACKOFF at: " + Calendar.getInstance().getTime()); } else if (timerInterval < 1) { timerInterval = MIN_EXPONENTIAL_BACKOFF; } - timerInterval = (int) ((timerInterval + getRandomDelay()) * MILLISECONDS); - log.debug("timerInterval = " + timerInterval + "ms at: " + Calendar.getInstance().getTime().toString()); + timerInterval = (int) ((timerInterval * MILLISECONDS) + getRandomDelayInMilliSeconds()); + log.debug("timerInterval = " + timerInterval + "ms at: " + Calendar.getInstance().getTime()); } if (pnReconnectionPolicy == PNReconnectionPolicy.LINEAR) { - timerInterval = (int) ((LINEAR_INTERVAL + getRandomDelay()) * MILLISECONDS); + timerInterval = (int) (BASE_LINEAR_INTERVAL_IN_MILLISECONDS + getRandomDelayInMilliSeconds()); } return timerInterval; } - private double getRandomDelay() { - double randomDelay = MAX_RANDOM * random.nextDouble(); - return roundTo3DecimalPlaces(randomDelay); + private double getRandomDelayInMilliSeconds() { + return random.nextInt(BOUND); } - private double roundTo3DecimalPlaces(double value) { - DecimalFormat decimalFormat = new DecimalFormat("#.###"); - return Double.parseDouble(decimalFormat.format(value)); - } private void stopHeartbeatTimer() { if (timer != null) { From ea9229368d568969ee2a69fe68ab99bb981b3971 Mon Sep 17 00:00:00 2001 From: "marcin.cebo" Date: Mon, 18 Dec 2023 13:46:58 +0100 Subject: [PATCH 3/5] Changes after review. --- .../java/com/pubnub/api/PNConfiguration.java | 2 +- .../api/managers/ReconnectionManager.java | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/pubnub/api/PNConfiguration.java b/src/main/java/com/pubnub/api/PNConfiguration.java index daf201b13..a2f0d4ef0 100644 --- a/src/main/java/com/pubnub/api/PNConfiguration.java +++ b/src/main/java/com/pubnub/api/PNConfiguration.java @@ -38,7 +38,7 @@ public class PNConfiguration { private static final int SUBSCRIBE_TIMEOUT = 310; private static final int CONNECT_TIMEOUT = 5; private static final int FILE_MESSAGE_PUBLISH_RETRY_LIMIT = 5; - private static final int MAXIMUM_RECONNECTION_RETRIES_DEFAULT = 6; + private static final int MAXIMUM_RECONNECTION_RETRIES_DEFAULT = -1; // infinite @Getter private SSLSocketFactory sslSocketFactory; diff --git a/src/main/java/com/pubnub/api/managers/ReconnectionManager.java b/src/main/java/com/pubnub/api/managers/ReconnectionManager.java index 7cee83cd8..9f9ce3da5 100644 --- a/src/main/java/com/pubnub/api/managers/ReconnectionManager.java +++ b/src/main/java/com/pubnub/api/managers/ReconnectionManager.java @@ -44,16 +44,7 @@ public class ReconnectionManager { public ReconnectionManager(PubNub pubnub) { this.pubnub = pubnub; this.pnReconnectionPolicy = pubnub.getConfiguration().getReconnectionPolicy(); - this.maxConnectionRetries = getMaximumReconnectionRetries(); - } - - private int getMaximumReconnectionRetries() { - int maximumReconnectionRetries = pubnub.getConfiguration().getMaximumReconnectionRetries(); - if (maximumReconnectionRetries < 0 || maximumReconnectionRetries > MAXIMUM_RECONNECTION_RETRIES_DEFAULT) { - maximumReconnectionRetries = MAXIMUM_RECONNECTION_RETRIES_DEFAULT; - } - log.debug("maximumReconnectionRetries is: " + maximumReconnectionRetries); - return maximumReconnectionRetries; + this.maxConnectionRetries = pubnub.getConfiguration().getMaximumReconnectionRetries(); } public void setReconnectionListener(ReconnectionCallback reconnectionCallback) { @@ -79,7 +70,7 @@ private void registerRetryTimer() { return; } - if (failedCalls >= maxConnectionRetries) { + if (maxConnectionIsNotSetToInfinite() && failedCalls >= maxConnectionRetries) { callback.onMaxReconnectionExhaustion(); return; } @@ -94,6 +85,10 @@ public void run() { }, getNextIntervalInMilliSeconds()); } + private boolean maxConnectionIsNotSetToInfinite() { + return maxConnectionRetries != -1; + } + int getNextIntervalInMilliSeconds() { int timerInterval = 0; failedCalls++; @@ -122,7 +117,6 @@ private double getRandomDelayInMilliSeconds() { return random.nextInt(BOUND); } - private void stopHeartbeatTimer() { if (timer != null) { timer.cancel(); From 93ffebaa8ed9c0351cc167d936f2ca0b1bfb27b7 Mon Sep 17 00:00:00 2001 From: "marcin.cebo" Date: Mon, 18 Dec 2023 15:08:30 +0100 Subject: [PATCH 4/5] Changes after review. --- src/main/java/com/pubnub/api/PNConfiguration.java | 3 +-- .../pubnub/api/managers/DelayedReconnectionManager.java | 2 +- .../java/com/pubnub/api/managers/ReconnectionManager.java | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/pubnub/api/PNConfiguration.java b/src/main/java/com/pubnub/api/PNConfiguration.java index a2f0d4ef0..3f509ad5a 100644 --- a/src/main/java/com/pubnub/api/PNConfiguration.java +++ b/src/main/java/com/pubnub/api/PNConfiguration.java @@ -203,8 +203,7 @@ public void setUserId(@NotNull UserId userId) { /** * Set how many times the reconnection manager will try to connect before giving up. - * Max allowed value is 10. - * Default is 10. + * Default is -1 which means to retry infinitely. */ @Setter private int maximumReconnectionRetries; diff --git a/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java b/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java index 2bcbb75d7..afac4d367 100644 --- a/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java +++ b/src/main/java/com/pubnub/api/managers/DelayedReconnectionManager.java @@ -64,7 +64,7 @@ private boolean isReconnectionPolicyUndefined() { return false; } - private double getRandomDelayInMilliSeconds() { + private int getRandomDelayInMilliSeconds() { return random.nextInt(BOUND); } diff --git a/src/main/java/com/pubnub/api/managers/ReconnectionManager.java b/src/main/java/com/pubnub/api/managers/ReconnectionManager.java index 9f9ce3da5..6631d3dcf 100644 --- a/src/main/java/com/pubnub/api/managers/ReconnectionManager.java +++ b/src/main/java/com/pubnub/api/managers/ReconnectionManager.java @@ -70,7 +70,7 @@ private void registerRetryTimer() { return; } - if (maxConnectionIsNotSetToInfinite() && failedCalls >= maxConnectionRetries) { + if (!maxConnectionIsSetToInfinite() && failedCalls >= maxConnectionRetries) { callback.onMaxReconnectionExhaustion(); return; } @@ -85,8 +85,8 @@ public void run() { }, getNextIntervalInMilliSeconds()); } - private boolean maxConnectionIsNotSetToInfinite() { - return maxConnectionRetries != -1; + private boolean maxConnectionIsSetToInfinite() { + return maxConnectionRetries == -1; } int getNextIntervalInMilliSeconds() { @@ -113,7 +113,7 @@ int getNextIntervalInMilliSeconds() { return timerInterval; } - private double getRandomDelayInMilliSeconds() { + private int getRandomDelayInMilliSeconds() { return random.nextInt(BOUND); } From 09a817a21d0cd45bbf8872d812c5f6de87bdcd80 Mon Sep 17 00:00:00 2001 From: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:34:07 +0000 Subject: [PATCH 5/5] PubNub SDK v6.4.5 release. --- .pubnub.yml | 15 +++++++++++---- CHANGELOG.md | 7 +++++++ README.md | 4 ++-- build.gradle | 2 +- gradle.properties | 2 +- src/main/java/com/pubnub/api/PubNub.java | 2 +- src/test/java/com/pubnub/api/PubNubTest.java | 2 +- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index d87511a8a..354e13766 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,9 +1,9 @@ name: java -version: 6.4.4 +version: 6.4.5 schema: 1 scm: github.com/pubnub/java files: - - build/libs/pubnub-gson-6.4.4-all.jar + - build/libs/pubnub-gson-6.4.5-all.jar sdks: - type: library @@ -23,8 +23,8 @@ sdks: - distribution-type: library distribution-repository: maven - package-name: pubnub-gson-6.4.4 - location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-gson/6.4.4/pubnub-gson-6.4.4.jar + package-name: pubnub-gson-6.4.5 + location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-gson/6.4.5/pubnub-gson-6.4.5.jar supported-platforms: supported-operating-systems: Android: @@ -115,6 +115,13 @@ sdks: is-required: Required changelog: + - date: 2023-12-18 + version: v6.4.5 + changes: + - type: bug + text: "Added reading message type from fetch messages response." + - type: bug + text: "Added random value 0.001-0.999s to delay between retries both for Linear and Exponential reconnection policies." - date: 2023-11-30 version: v6.4.4 changes: diff --git a/CHANGELOG.md b/CHANGELOG.md index cba23543a..3ad1b6de8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## v6.4.5 +December 18 2023 + +#### Fixed +- Added reading message type from fetch messages response. +- Added random value 0.001-0.999s to delay between retries both for Linear and Exponential reconnection policies. + ## v6.4.4 November 30 2023 diff --git a/README.md b/README.md index a571cd500..6963ac7cc 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,13 @@ You will need the publish and subscribe keys to authenticate your app. Get your com.pubnub pubnub-gson - 6.4.4 + 6.4.5 ``` * for Gradle, add the following dependency in your `gradle.build`: ```groovy - implementation 'com.pubnub:pubnub-gson:6.4.4' + implementation 'com.pubnub:pubnub-gson:6.4.5' ``` 2. Configure your keys: diff --git a/build.gradle b/build.gradle index 42388c3ee..387f1b4f8 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ plugins { } group = 'com.pubnub' -version = '6.4.4' +version = '6.4.5' description = """""" diff --git a/gradle.properties b/gradle.properties index abe45b364..33684a749 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ SONATYPE_HOST=DEFAULT SONATYPE_AUTOMATIC_RELEASE=true GROUP=com.pubnub POM_ARTIFACT_ID=pubnub-gson -VERSION_NAME=6.4.4 +VERSION_NAME=6.4.5 POM_PACKAGING=jar POM_NAME=PubNub Java SDK diff --git a/src/main/java/com/pubnub/api/PubNub.java b/src/main/java/com/pubnub/api/PubNub.java index 1928b77e0..9c82a08c8 100644 --- a/src/main/java/com/pubnub/api/PubNub.java +++ b/src/main/java/com/pubnub/api/PubNub.java @@ -105,7 +105,7 @@ public class PubNub { private static final int TIMESTAMP_DIVIDER = 1000; private static final int MAX_SEQUENCE = 65535; - private static final String SDK_VERSION = "6.4.4"; + private static final String SDK_VERSION = "6.4.5"; private final ListenerManager listenerManager; private final StateManager stateManager; diff --git a/src/test/java/com/pubnub/api/PubNubTest.java b/src/test/java/com/pubnub/api/PubNubTest.java index 8a9350716..c139f68e8 100644 --- a/src/test/java/com/pubnub/api/PubNubTest.java +++ b/src/test/java/com/pubnub/api/PubNubTest.java @@ -100,7 +100,7 @@ public void getVersionAndTimeStamp() { pubnub = new PubNub(pnConfiguration); String version = pubnub.getVersion(); int timeStamp = pubnub.getTimestamp(); - Assert.assertEquals("6.4.4", version); + Assert.assertEquals("6.4.5", version); Assert.assertTrue(timeStamp > 0); }