Skip to content

Commit 63faaec

Browse files
Make ConnectionFactory#networkRecoveryInterval a long
There is no real need for it to be a long but other libraries and JVM languages may use longs for various reasons and using a long with an int field is * Unsafe * Not entirely obvious to some developers
1 parent aa2cc31 commit 63faaec

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ public class ConnectionFactory implements Cloneable {
9999
private boolean automaticRecovery = false;
100100
private boolean topologyRecovery = true;
101101

102-
private int networkRecoveryInterval = 5000;
102+
// long is used to make sure the users can use both ints
103+
// and longs safely. It is unlikely that anybody'd need
104+
// to use recovery intervals > Integer.MAX_VALUE in practice.
105+
private long networkRecoveryInterval = 5000;
103106

104107
/** @return number of consumer threads in default {@link ExecutorService} */
105108
@Deprecated
@@ -638,7 +641,7 @@ public Connection newConnection(ExecutorService executor) throws IOException {
638641
* Returns automatic connection recovery interval in milliseconds.
639642
* @return how long will automatic recovery wait before attempting to reconnect, in ms; default is 5000
640643
*/
641-
public int getNetworkRecoveryInterval() {
644+
public long getNetworkRecoveryInterval() {
642645
return networkRecoveryInterval;
643646
}
644647

@@ -649,4 +652,12 @@ public int getNetworkRecoveryInterval() {
649652
public void setNetworkRecoveryInterval(int networkRecoveryInterval) {
650653
this.networkRecoveryInterval = networkRecoveryInterval;
651654
}
655+
656+
/**
657+
* Sets connection recovery interval. Default is 5000.
658+
* @param networkRecoveryInterval how long will automatic recovery wait before attempting to reconnect, in ms
659+
*/
660+
public void setNetworkRecoveryInterval(long networkRecoveryInterval) {
661+
this.networkRecoveryInterval = networkRecoveryInterval;
662+
}
652663
}

src/com/rabbitmq/client/impl/ConnectionParams.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ConnectionParams {
1717
private final int requestedChannelMax;
1818
private final int requestedHeartbeat;
1919
private final SaslConfig saslConfig;
20-
private final int networkRecoveryInterval;
20+
private final long networkRecoveryInterval;
2121
private final boolean topologyRecovery;
2222

2323
private ExceptionHandler exceptionHandler;
@@ -41,7 +41,7 @@ public class ConnectionParams {
4141
public ConnectionParams(String username, String password, ExecutorService executor,
4242
String virtualHost, Map<String, Object> clientProperties,
4343
int requestedFrameMax, int requestedChannelMax, int requestedHeartbeat,
44-
SaslConfig saslConfig, int networkRecoveryInterval,
44+
SaslConfig saslConfig, long networkRecoveryInterval,
4545
boolean topologyRecovery, ExceptionHandler exceptionHandler, ThreadFactory threadFactory) {
4646
this.username = username;
4747
this.password = password;
@@ -98,7 +98,7 @@ public ExceptionHandler getExceptionHandler() {
9898
return exceptionHandler;
9999
}
100100

101-
public int getNetworkRecoveryInterval() {
101+
public long getNetworkRecoveryInterval() {
102102
return networkRecoveryInterval;
103103
}
104104

test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.concurrent.atomic.AtomicInteger;
1919

2020
public class ConnectionRecovery extends BrokerTestCase {
21-
public static final int RECOVERY_INTERVAL = 2000;
21+
public static final long RECOVERY_INTERVAL = 2000;
2222

2323
public void testConnectionRecovery() throws IOException, InterruptedException {
2424
assertTrue(connection.isOpen());

0 commit comments

Comments
 (0)