@@ -70,9 +70,14 @@ public class ConnectionFactory implements Cloneable {
70
70
public static final int DEFAULT_AMQP_PORT = AMQP .PROTOCOL .PORT ;
71
71
/** The default ssl port */
72
72
public static final int DEFAULT_AMQP_OVER_SSL_PORT = 5671 ;
73
- /** The default connection timeout;
73
+ /** The default TCP connection timeout;
74
74
* zero means wait indefinitely */
75
75
public static final int DEFAULT_CONNECTION_TIMEOUT = 0 ;
76
+ /**
77
+ * The default AMQP 0-9-1 connection handshake timeout. See DEFAULT_CONNECTION_TIMEOUT
78
+ * for TCP (socket) connection timeout.
79
+ */
80
+ public static final int DEFAULT_HANDSHAKE_TIMEOUT = 10000 ;
76
81
/** The default shutdown timeout;
77
82
* zero means wait indefinitely */
78
83
public static final int DEFAULT_SHUTDOWN_TIMEOUT = 10000 ;
@@ -89,6 +94,7 @@ public class ConnectionFactory implements Cloneable {
89
94
private int requestedFrameMax = DEFAULT_FRAME_MAX ;
90
95
private int requestedHeartbeat = DEFAULT_HEARTBEAT ;
91
96
private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT ;
97
+ private int handshakeTimeout = DEFAULT_HANDSHAKE_TIMEOUT ;
92
98
private int shutdownTimeout = DEFAULT_SHUTDOWN_TIMEOUT ;
93
99
private Map <String , Object > _clientProperties = AMQConnection .defaultClientProperties ();
94
100
private SocketFactory factory = SocketFactory .getDefault ();
@@ -308,21 +314,41 @@ public int getRequestedHeartbeat() {
308
314
}
309
315
310
316
/**
311
- * Set the connection timeout.
312
- * @param connectionTimeout connection establishment timeout in milliseconds; zero for infinite
317
+ * Set the TCP connection timeout.
318
+ * @param connectionTimeout connection TCP establishment timeout in milliseconds; zero for infinite
313
319
*/
314
320
public void setConnectionTimeout (int connectionTimeout ) {
315
321
this .connectionTimeout = connectionTimeout ;
316
322
}
317
323
318
324
/**
319
- * Retrieve the connection timeout.
320
- * @return the connection timeout, in milliseconds; zero for infinite
325
+ * Retrieve the TCP connection timeout.
326
+ * @return the TCP connection timeout, in milliseconds; zero for infinite
321
327
*/
322
328
public int getConnectionTimeout () {
323
329
return this .connectionTimeout ;
324
330
}
325
331
332
+ /**
333
+ * Retrieve the AMQP 0-9-1 protocol handshake timeout.
334
+ * @return the AMQP0-9-1 protocol handshake timeout, in milliseconds
335
+ */
336
+ public int getHandshakeTimeout () {
337
+ return handshakeTimeout ;
338
+ }
339
+
340
+ /**
341
+ * Set the AMQP0-9-1 protocol handshake timeout.
342
+ * @param handshakeTimeout the AMQP0-9-1 protocol handshake timeout, in milliseconds
343
+ */
344
+ public void setHandshakeTimeout (int handshakeTimeout ) {
345
+ if (handshakeTimeout < connectionTimeout ) {
346
+ this .handshakeTimeout = handshakeTimeout ;
347
+ } else {
348
+ throw new IllegalArgumentException ("handshake timeout cannot be lower than TCP connection timeout" );
349
+ }
350
+ }
351
+
326
352
/**
327
353
* Set the shutdown timeout. This is the amount of time that Consumer implementations have to
328
354
* continue working through deliveries (and other Consumer callbacks) <b>after</b> the connection
@@ -629,9 +655,12 @@ public Connection newConnection(ExecutorService executor, Address[] addrs)
629
655
}
630
656
631
657
public ConnectionParams params (ExecutorService executor ) {
632
- return new ConnectionParams (username , password , executor , virtualHost , getClientProperties (),
633
- requestedFrameMax , requestedChannelMax , requestedHeartbeat , shutdownTimeout , saslConfig ,
634
- networkRecoveryInterval , topologyRecovery , exceptionHandler , threadFactory );
658
+ // TODO: switch to use setters for all fields
659
+ ConnectionParams result = new ConnectionParams (username , password , executor , virtualHost , getClientProperties (),
660
+ requestedFrameMax , requestedChannelMax , requestedHeartbeat , shutdownTimeout , saslConfig ,
661
+ networkRecoveryInterval , topologyRecovery , exceptionHandler , threadFactory );
662
+ result .setHandshakeTimeout (handshakeTimeout );
663
+ return result ;
635
664
}
636
665
637
666
/**
0 commit comments