@@ -70,6 +70,9 @@ public class ConnectionFactory implements Cloneable {
70
70
/** The default port to use for AMQP connections when using SSL */
71
71
public static final int DEFAULT_AMQP_OVER_SSL_PORT = 5671 ;
72
72
73
+ /** The default connection timeout (wait indefinitely until connection established or error occurs) */
74
+ public static final int DEFAULT_CONNECTION_TIMEOUT = 0 ;
75
+
73
76
/**
74
77
* The default SSL protocol (currently "SSLv3").
75
78
*/
@@ -83,6 +86,7 @@ public class ConnectionFactory implements Cloneable {
83
86
private int requestedChannelMax = DEFAULT_CHANNEL_MAX ;
84
87
private int requestedFrameMax = DEFAULT_FRAME_MAX ;
85
88
private int requestedHeartbeat = DEFAULT_HEARTBEAT ;
89
+ private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT ;
86
90
private Map <String , Object > _clientProperties = AMQConnection .defaultClientProperties ();
87
91
private SocketFactory factory = SocketFactory .getDefault ();
88
92
private SaslConfig saslConfig = new DefaultSaslConfig (this );
@@ -216,6 +220,22 @@ public int getRequestedHeartbeat() {
216
220
return this .requestedHeartbeat ;
217
221
}
218
222
223
+ /**
224
+ * Set the connection timeout.
225
+ * @param connectionTimeout connection establishment timeout in milliseconds; zero for infinite
226
+ */
227
+ public void setConnectionTimeout (int connectionTimeout ) {
228
+ this .connectionTimeout = connectionTimeout ;
229
+ }
230
+
231
+ /**
232
+ * Retrieve the connection timeout.
233
+ * @return the connection timeout, in milliseconds; zero for infinite
234
+ */
235
+ public int getConnectionTimeout () {
236
+ return this .connectionTimeout ;
237
+ }
238
+
219
239
/**
220
240
* Set the requested heartbeat.
221
241
* @param requestedHeartbeat the initially requested heartbeat interval, in seconds; zero for none
@@ -339,7 +359,7 @@ protected FrameHandler createFrameHandler(Address addr)
339
359
int portNumber = portOrDefault (addr .getPort ());
340
360
Socket socket = factory .createSocket ();
341
361
configureSocket (socket );
342
- socket .connect (new InetSocketAddress (hostName , portNumber ));
362
+ socket .connect (new InetSocketAddress (hostName , portNumber ), connectionTimeout );
343
363
return createFrameHandler (socket );
344
364
}
345
365
0 commit comments