@@ -75,6 +75,9 @@ public class ConnectionFactory implements Cloneable {
7575 /** The default connection timeout;
7676 * zero means wait indefinitely */
7777 public static final int DEFAULT_CONNECTION_TIMEOUT = 0 ;
78+ /** The default shutdown timeout;
79+ * zero means wait indefinitely */
80+ public static final int DEFAULT_SHUTDOWN_TIMEOUT = 10000 ;
7881
7982 /** The default SSL protocol */
8083 private static final String DEFAULT_SSL_PROTOCOL = "SSLv3" ;
@@ -88,6 +91,7 @@ public class ConnectionFactory implements Cloneable {
8891 private int requestedFrameMax = DEFAULT_FRAME_MAX ;
8992 private int requestedHeartbeat = DEFAULT_HEARTBEAT ;
9093 private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT ;
94+ private int shutdownTimeout = DEFAULT_SHUTDOWN_TIMEOUT ;
9195 private Map <String , Object > _clientProperties = AMQConnection .defaultClientProperties ();
9296 private SocketFactory factory = SocketFactory .getDefault ();
9397 private SaslConfig saslConfig = DefaultSaslConfig .PLAIN ;
@@ -333,6 +337,26 @@ public int getConnectionTimeout() {
333337 return this .connectionTimeout ;
334338 }
335339
340+ /**
341+ * Set the shutdown timeout. This is the amount of time that Consumer implementations have to
342+ * continue working through deliveries (and other Consumer callbacks) <b>after</b> the connection
343+ * has closed but before the ConsumerWorkService is torn down. If consumers exceed this timeout
344+ * then any remaining queued deliveries (and other Consumer callbacks, <b>including</b>
345+ * the Consumer's handleShutdownSignal() invocation) will be lost.
346+ * @param shutdownTimeout shutdown timeout in milliseconds; zero for infinite; default 10000
347+ */
348+ public void setShutdownTimeout (int shutdownTimeout ) {
349+ this .shutdownTimeout = shutdownTimeout ;
350+ }
351+
352+ /**
353+ * Retrieve the shutdown timeout.
354+ * @return the shutdown timeout, in milliseconds; zero for infinite
355+ */
356+ public int getShutdownTimeout () {
357+ return shutdownTimeout ;
358+ }
359+
336360 /**
337361 * Set the requested heartbeat.
338362 * @param requestedHeartbeat the initially requested heartbeat interval, in seconds; zero for none
@@ -602,7 +626,7 @@ public Connection newConnection(ExecutorService executor, Address[] addrs)
602626
603627 public ConnectionParams params (ExecutorService executor ) {
604628 return new ConnectionParams (username , password , executor , virtualHost , getClientProperties (),
605- requestedFrameMax , requestedChannelMax , requestedHeartbeat , saslConfig ,
629+ requestedFrameMax , requestedChannelMax , requestedHeartbeat , shutdownTimeout , saslConfig ,
606630 networkRecoveryInterval , topologyRecovery , exceptionHandler , threadFactory );
607631 }
608632
0 commit comments