Repository: activemq Updated Branches: refs/heads/master a3a5a1aff -> f43c09080
https://issues.apache.org/jira/browse/AMQ-6362 Add option connectResponseTimeout to allow a stuck connection in ensureConnectionInfoSent from stalling out a client. Timeout is disabled by default. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/f43c0908 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/f43c0908 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/f43c0908 Branch: refs/heads/master Commit: f43c090809bbb59d86ffac8f8105f08a71142aaa Parents: a3a5a1a Author: Timothy Bish <[email protected]> Authored: Mon Jul 18 11:30:38 2016 -0400 Committer: Timothy Bish <[email protected]> Committed: Mon Jul 18 11:30:38 2016 -0400 ---------------------------------------------------------------------- .../org/apache/activemq/ActiveMQConnection.java | 11 +++++++++- .../activemq/ActiveMQConnectionFactory.java | 13 ++++++++++- .../activemq/ActiveMQConnectionFactoryTest.java | 23 ++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/f43c0908/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java index 11cb74e..2faa5e2 100755 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java @@ -210,6 +210,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon private List<String> trustedPackages = new ArrayList<String>(); private boolean trustAllPackages = false; + private int connectResponseTimeout; /** * Construct an <code>ActiveMQConnection</code> @@ -1496,7 +1497,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon if (info.getClientId() == null || info.getClientId().trim().length() == 0) { info.setClientId(clientIdGenerator.generateId()); } - syncSendPacket(info.copy()); + syncSendPacket(info.copy(), getConnectResponseTimeout()); this.isConnectionInfoSentToBroker = true; // Add a temp destination advisory consumer so that @@ -2605,4 +2606,12 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon public void setTrustAllPackages(boolean trustAllPackages) { this.trustAllPackages = trustAllPackages; } + + public int getConnectResponseTimeout() { + return connectResponseTimeout; + } + + public void setConnectResponseTimeout(int connectResponseTimeout) { + this.connectResponseTimeout = connectResponseTimeout; + } } http://git-wip-us.apache.org/repos/asf/activemq/blob/f43c0908/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java index 4d958e6..2a868ee 100755 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java @@ -160,6 +160,7 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne private int producerWindowSize = DEFAULT_PRODUCER_WINDOW_SIZE; private long warnAboutUnstartedConnectionTimeout = 500L; private int sendTimeout = 0; + private int connectResponseTimeout = 0; private boolean sendAcksAsync=true; private TransportListener transportListener; private ExceptionListener exceptionListener; @@ -421,6 +422,7 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne connection.setConsumerExpiryCheckEnabled(isConsumerExpiryCheckEnabled()); connection.setTrustedPackages(getTrustedPackages()); connection.setTrustAllPackages(isTrustAllPackages()); + connection.setConnectResponseTimeout(getConnectResponseTimeout()); if (transportListener != null) { connection.addTransportListener(transportListener); } @@ -438,7 +440,7 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne // // ///////////////////////////////////////////// - public String getBrokerURL() { + public String getBrokerURL() { return brokerURL == null ? null : brokerURL.toString(); } @@ -831,6 +833,7 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne props.setProperty("alwaysSyncSend", Boolean.toString(isAlwaysSyncSend())); props.setProperty("producerWindowSize", Integer.toString(getProducerWindowSize())); props.setProperty("sendTimeout", Integer.toString(getSendTimeout())); + props.setProperty("connectResponseTimeout", Integer.toString(getConnectResponseTimeout())); props.setProperty("sendAcksAsync",Boolean.toString(isSendAcksAsync())); props.setProperty("auditDepth", Integer.toString(getAuditDepth())); props.setProperty("auditMaximumProducerNumber", Integer.toString(getAuditMaximumProducerNumber())); @@ -1275,4 +1278,12 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne public void setTrustAllPackages(boolean trustAllPackages) { this.trustAllPackages = trustAllPackages; } + + public int getConnectResponseTimeout() { + return connectResponseTimeout; + } + + public void setConnectResponseTimeout(int connectResponseTimeout) { + this.connectResponseTimeout = connectResponseTimeout; + } } http://git-wip-us.apache.org/repos/asf/activemq/blob/f43c0908/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java index b2725bf..e2fbd87 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java @@ -98,6 +98,29 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport { assertEquals(5000, cf.getAuditDepth()); } + public void testConnectAttemptTimeotOptionIsApplied() throws URISyntaxException, JMSException { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost"); + + assertEquals(0, cf.getConnectResponseTimeout()); + + // the broker url have been adjusted. + assertEquals("vm://localhost", cf.getBrokerURL()); + + ActiveMQConnection connection = (ActiveMQConnection)cf.createConnection(); + assertEquals(0, connection.getConnectResponseTimeout()); + connection.close(); + + cf = new ActiveMQConnectionFactory("vm://localhost?jms.connectResponseTimeout=1000"); + assertEquals(1000, cf.getConnectResponseTimeout()); + + // the broker url have been adjusted. + assertEquals("vm://localhost", cf.getBrokerURL()); + + connection = (ActiveMQConnection)cf.createConnection(); + assertEquals(1000, connection.getConnectResponseTimeout()); + connection.close(); + } + public void testUseURIToConfigureRedeliveryPolicy() throws URISyntaxException, JMSException { ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory( "vm://localhost?broker.persistent=false&broker.useJmx=false&jms.redeliveryPolicy.maximumRedeliveries=2");
