Skip to content

Commit 3b43a75

Browse files
Add heartbeat error limit (#275)
* Add heartbeat error limit In case of any problems we should not quit immediately heartbeat calls. The interval is chosen so it's possible to call heartbeat 3 times during one presence interval, therefore we should keep trying at least few more times * PubNub SDK v6.3.5 release. --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com>
1 parent fe58165 commit 3b43a75

8 files changed

Lines changed: 34 additions & 15 deletions

File tree

.pubnub.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: java
2-
version: 6.3.4
2+
version: 6.3.5
33
schema: 1
44
scm: github.com/pubnub/java
55
files:
6-
- build/libs/pubnub-gson-6.3.4-all.jar
6+
- build/libs/pubnub-gson-6.3.5-all.jar
77
sdks:
88
-
99
type: library
@@ -23,8 +23,8 @@ sdks:
2323
-
2424
distribution-type: library
2525
distribution-repository: GitHub
26-
package-name: pubnub-gson-6.3.4
27-
location: https://github.com/pubnub/java/releases/download/v6.3.4/pubnub-gson-6.3.4-all.jar
26+
package-name: pubnub-gson-6.3.5
27+
location: https://github.com/pubnub/java/releases/download/v6.3.5/pubnub-gson-6.3.5-all.jar
2828
supported-platforms:
2929
supported-operating-systems:
3030
Android:
@@ -135,8 +135,8 @@ sdks:
135135
-
136136
distribution-type: library
137137
distribution-repository: maven
138-
package-name: pubnub-gson-6.3.4
139-
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-gson/6.3.4/pubnub-gson-6.3.4.jar
138+
package-name: pubnub-gson-6.3.5
139+
location: https://repo.maven.apache.org/maven2/com/pubnub/pubnub-gson/6.3.5/pubnub-gson-6.3.5.jar
140140
supported-platforms:
141141
supported-operating-systems:
142142
Android:
@@ -234,6 +234,11 @@ sdks:
234234
is-required: Required
235235

236236
changelog:
237+
- date: 2023-05-18
238+
version: v6.3.5
239+
changes:
240+
- type: bug
241+
text: "In case of error retry heartbeat call limited number of times."
237242
- date: 2023-03-06
238243
version: v6.3.4
239244
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v6.3.5
2+
May 18 2023
3+
4+
#### Fixed
5+
- In case of error retry heartbeat call limited number of times.
6+
17
## v6.3.4
28
March 06 2023
39

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ You will need the publish and subscribe keys to authenticate your app. Get your
2222
<dependency>
2323
<groupId>com.pubnub</groupId>
2424
<artifactId>pubnub-gson</artifactId>
25-
<version>6.3.4</version>
25+
<version>6.3.5</version>
2626
</dependency>
2727
```
2828

2929
* for Gradle, add the following dependency in your `gradle.build`:
3030
```groovy
31-
implementation 'com.pubnub:pubnub-gson:6.3.4'
31+
implementation 'com.pubnub:pubnub-gson:6.3.5'
3232
```
3333

3434
2. Configure your keys:

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
}
1111
group = 'com.pubnub'
1212

13-
version = '6.3.4'
13+
version = '6.3.5'
1414

1515
description = """"""
1616

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SONATYPE_HOST=DEFAULT
33
SONATYPE_AUTOMATIC_RELEASE=true
44
GROUP=com.pubnub
55
POM_ARTIFACT_ID=pubnub-gson
6-
VERSION_NAME=6.3.4
6+
VERSION_NAME=6.3.5
77
POM_PACKAGING=jar
88

99
POM_NAME=PubNub Java SDK

src/main/java/com/pubnub/api/PubNub.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public class PubNub {
105105
private static final int TIMESTAMP_DIVIDER = 1000;
106106
private static final int MAX_SEQUENCE = 65535;
107107

108-
private static final String SDK_VERSION = "6.3.4";
108+
private static final String SDK_VERSION = "6.3.5";
109109
private final ListenerManager listenerManager;
110110
private final StateManager stateManager;
111111

src/main/java/com/pubnub/api/managers/SubscriptionManager.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Timer;
2424
import java.util.TimerTask;
2525
import java.util.concurrent.LinkedBlockingQueue;
26+
import java.util.concurrent.atomic.AtomicInteger;
2627

2728
import static com.pubnub.api.managers.StateManager.ChannelFilter.WITHOUT_TEMPORARY_UNAVAILABLE;
2829
import static com.pubnub.api.managers.StateManager.MILLIS_IN_SECOND;
@@ -33,8 +34,12 @@ public class SubscriptionManager {
3334

3435
private static final int HEARTBEAT_INTERVAL_MULTIPLIER = 1000;
3536

37+
private static final int MAX_HEARTBEAT_RETRIES = 5;
38+
3639
private volatile boolean connected;
3740

41+
private final AtomicInteger heartbeatRetries = new AtomicInteger(0);
42+
3843
PubNub pubnub;
3944
private final TelemetryManager telemetryManager;
4045
private final TokenManager tokenManager;
@@ -232,6 +237,7 @@ private void stopHeartbeatTimer() {
232237
heartbeatCall.silentCancel();
233238
heartbeatCall = null;
234239
}
240+
heartbeatRetries.set(0);
235241
}
236242

237243
private synchronized void cancelDelayedLoopIterationForTemporaryUnavailableChannels() {
@@ -452,15 +458,17 @@ public void onResponse(Boolean result, @NotNull PNStatus status) {
452458
pubnub.getConfiguration().getHeartbeatNotificationOptions();
453459

454460
if (status.isError()) {
461+
if (heartbeatRetries.getAndIncrement() >= MAX_HEARTBEAT_RETRIES) {
462+
stopHeartbeatTimer();
463+
}
464+
455465
if (heartbeatVerbosity == PNHeartbeatNotificationOptions.ALL
456466
|| heartbeatVerbosity == PNHeartbeatNotificationOptions.FAILURES) {
457467
listenerManager.announce(status);
458468
}
459469

460-
// stop the heartbeating logic since an error happened.
461-
stopHeartbeatTimer();
462-
463470
} else {
471+
heartbeatRetries.set(0);
464472
if (heartbeatVerbosity == PNHeartbeatNotificationOptions.ALL) {
465473
listenerManager.announce(status);
466474
}

src/test/java/com/pubnub/api/PubNubTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void getVersionAndTimeStamp() {
100100
pubnub = new PubNub(pnConfiguration);
101101
String version = pubnub.getVersion();
102102
int timeStamp = pubnub.getTimestamp();
103-
Assert.assertEquals("6.3.4", version);
103+
Assert.assertEquals("6.3.5", version);
104104
Assert.assertTrue(timeStamp > 0);
105105
}
106106

0 commit comments

Comments
 (0)