@@ -70,6 +70,9 @@ public class ConnectionFactory implements Cloneable {
7070 /** The default port to use for AMQP connections when using SSL */
7171 public static final int DEFAULT_AMQP_OVER_SSL_PORT = 5671 ;
7272
73+ /** The default connection timeout (wait indefinitely until connection established or error occurs) */
74+ public static final int DEFAULT_CONNECTION_TIMEOUT = 0 ;
75+
7376 /**
7477 * The default SSL protocol (currently "SSLv3").
7578 */
@@ -83,6 +86,7 @@ public class ConnectionFactory implements Cloneable {
8386 private int requestedChannelMax = DEFAULT_CHANNEL_MAX ;
8487 private int requestedFrameMax = DEFAULT_FRAME_MAX ;
8588 private int requestedHeartbeat = DEFAULT_HEARTBEAT ;
89+ private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT ;
8690 private Map <String , Object > _clientProperties = AMQConnection .defaultClientProperties ();
8791 private SocketFactory factory = SocketFactory .getDefault ();
8892 private SaslConfig saslConfig = new DefaultSaslConfig (this );
@@ -216,6 +220,22 @@ public int getRequestedHeartbeat() {
216220 return this .requestedHeartbeat ;
217221 }
218222
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+
219239 /**
220240 * Set the requested heartbeat.
221241 * @param requestedHeartbeat the initially requested heartbeat interval, in seconds; zero for none
@@ -339,7 +359,7 @@ protected FrameHandler createFrameHandler(Address addr)
339359 int portNumber = portOrDefault (addr .getPort ());
340360 Socket socket = factory .createSocket ();
341361 configureSocket (socket );
342- socket .connect (new InetSocketAddress (hostName , portNumber ));
362+ socket .connect (new InetSocketAddress (hostName , portNumber ), connectionTimeout );
343363 return createFrameHandler (socket );
344364 }
345365
0 commit comments