Skip to content

Commit

Permalink
Changes after review.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-cebo committed Dec 18, 2023
1 parent 3bb2e89 commit ea92293
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/pubnub/api/PNConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/com/pubnub/api/managers/ReconnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -79,7 +70,7 @@ private void registerRetryTimer() {
return;
}

if (failedCalls >= maxConnectionRetries) {
if (maxConnectionIsNotSetToInfinite() && failedCalls >= maxConnectionRetries) {
callback.onMaxReconnectionExhaustion();
return;
}
Expand All @@ -94,6 +85,10 @@ public void run() {
}, getNextIntervalInMilliSeconds());
}

private boolean maxConnectionIsNotSetToInfinite() {
return maxConnectionRetries != -1;
}

int getNextIntervalInMilliSeconds() {
int timerInterval = 0;
failedCalls++;
Expand Down Expand Up @@ -122,7 +117,6 @@ private double getRandomDelayInMilliSeconds() {
return random.nextInt(BOUND);
}


private void stopHeartbeatTimer() {
if (timer != null) {
timer.cancel();
Expand Down

0 comments on commit ea92293

Please sign in to comment.