You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2015/04/15 00:56:37 UTC
qpid-jms git commit: https://issues.apache.org/jira/browse/QPIDJMS-40
Repository: qpid-jms
Updated Branches:
refs/heads/master e7d083e36 -> 0e2271141
https://issues.apache.org/jira/browse/QPIDJMS-40
some initial work to wire together the cause of the close into the
exceptions reported from session, consumer and producer instances.
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/0e227114
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/0e227114
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/0e227114
Branch: refs/heads/master
Commit: 0e22711418c4ce80284aad42d350decdeafab2bd
Parents: e7d083e
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue Apr 14 18:56:26 2015 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue Apr 14 18:56:26 2015 -0400
----------------------------------------------------------------------
.../java/org/apache/qpid/jms/JmsConnection.java | 11 +++++--
.../org/apache/qpid/jms/JmsMessageConsumer.java | 21 +++++++++++--
.../org/apache/qpid/jms/JmsMessageProducer.java | 19 +++++++++--
.../java/org/apache/qpid/jms/JmsSession.java | 33 +++++++++++++++-----
.../integration/ConsumerIntegrationTest.java | 14 +++------
.../integration/ProducerIntegrationTest.java | 6 +++-
.../jms/integration/SessionIntegrationTest.java | 6 +++-
7 files changed, 84 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0e227114/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
index 556e3d7..241101f 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
@@ -222,11 +222,18 @@ public class JmsConnection implements Connection, TopicConnection, QueueConnecti
* Called to free all Connection resources.
*/
protected void shutdown() throws JMSException {
+ shutdown(null);
+ }
+
+ /**
+ * Called to free all Connection resources.
+ */
+ protected void shutdown(Exception cause) throws JMSException {
// NOTE - Once ConnectionConsumer is added we must shutdown those as well.
for (JmsSession session : sessions.values()) {
- session.shutdown();
+ session.shutdown(cause);
}
if (isConnected() && !failed.get() && !closing.get()) {
@@ -1086,7 +1093,7 @@ public class JmsConnection implements Connection, TopicConnection, QueueConnecti
}
try {
- shutdown();
+ shutdown(ex);
} catch (JMSException e) {
LOG.warn("Exception during connection cleanup, " + e, e);
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0e227114/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
index ac70db0..328062b 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
@@ -58,6 +58,7 @@ public class JmsMessageConsumer implements MessageConsumer, JmsMessageAvailableC
protected final Lock lock = new ReentrantLock();
protected final AtomicBoolean suspendedConnection = new AtomicBoolean();
protected final AtomicBoolean delivered = new AtomicBoolean();
+ protected Exception failureCause;
/**
* Create a non-durable MessageConsumer
@@ -185,8 +186,13 @@ public class JmsMessageConsumer implements MessageConsumer, JmsMessageAvailableC
* @throws JMSException
*/
protected void shutdown() throws JMSException {
+ shutdown(null);
+ }
+
+ protected void shutdown(Exception cause) throws JMSException {
if (closed.compareAndSet(false, true)) {
- this.session.remove(this);
+ failureCause = cause;
+ session.remove(this);
stop(true);
}
}
@@ -247,8 +253,17 @@ public class JmsMessageConsumer implements MessageConsumer, JmsMessageAvailableC
}
protected void checkClosed() throws IllegalStateException {
- if (this.closed.get()) {
- throw new IllegalStateException("The MessageConsumer is closed");
+ if (closed.get()) {
+ IllegalStateException jmsEx = null;
+
+ if (failureCause == null) {
+ jmsEx = new IllegalStateException("The MessageConsumer is closed");
+ } else {
+ jmsEx = new IllegalStateException("The MessageConsumer was closed due to an unrecoverable error.");
+ jmsEx.initCause(failureCause);
+ }
+
+ throw jmsEx;
}
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0e227114/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
index c76358d..f8c180e 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
@@ -48,6 +48,7 @@ public class JmsMessageProducer implements MessageProducer {
protected boolean disableMessageId;
protected boolean disableTimestamp;
protected final AtomicLong messageSequence = new AtomicLong();
+ protected Exception failureCause;
protected JmsMessageProducer(JmsProducerId producerId, JmsSession session, JmsDestination destination) throws JMSException {
this.session = session;
@@ -91,8 +92,13 @@ public class JmsMessageProducer implements MessageProducer {
* @throws JMSException
*/
protected void shutdown() throws JMSException {
+ shutdown(null);
+ }
+
+ protected void shutdown(Exception cause) throws JMSException {
if (closed.compareAndSet(false, true)) {
- this.session.remove(this);
+ failureCause = cause;
+ session.remove(this);
}
}
@@ -303,7 +309,16 @@ public class JmsMessageProducer implements MessageProducer {
protected void checkClosed() throws IllegalStateException {
if (closed.get()) {
- throw new IllegalStateException("The MessageProducer is closed");
+ IllegalStateException jmsEx = null;
+
+ if (failureCause == null) {
+ jmsEx = new IllegalStateException("The MessageProducer is closed");
+ } else {
+ jmsEx = new IllegalStateException("The MessageProducer was closed due to an unrecoverable error.");
+ jmsEx.initCause(failureCause);
+ }
+
+ throw jmsEx;
}
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0e227114/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
index a2020b6..3f6ef07 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
@@ -102,6 +102,7 @@ public class JmsSession implements Session, QueueSession, TopicSession, JmsMessa
private final AtomicLong producerIdGenerator = new AtomicLong();
private JmsTransactionContext transactionContext;
private boolean sessionRecovered;
+ private Exception failureCause;
protected JmsSession(JmsConnection connection, JmsSessionId sessionId, int acknowledgementMode) throws JMSException {
this.connection = connection;
@@ -245,23 +246,26 @@ public class JmsSession implements Session, QueueSession, TopicSession, JmsMessa
* @throws JMSException if an error occurs while shutting down the session resources.
*/
protected void shutdown() throws JMSException {
+ shutdown(null);
+ }
+
+ protected void shutdown(Exception cause) throws JMSException {
if (closed.compareAndSet(false, true)) {
stop();
+ failureCause = cause;
for (JmsMessageConsumer consumer : new ArrayList<JmsMessageConsumer>(this.consumers.values())) {
- consumer.shutdown();
+ consumer.shutdown(cause);
}
for (JmsMessageProducer producer : new ArrayList<JmsMessageProducer>(this.producers.values())) {
- producer.shutdown();
+ producer.shutdown(cause);
}
}
}
void remotelyClosed(Exception cause) {
- // TODO - Store cause and use as exception when session methods called ?
- // failureCause = cause; ?
try {
- shutdown();
+ shutdown(cause);
} catch (Throwable error) {
LOG.trace("Ignoring exception thrown during cleanup of remotely closed session", error);
}
@@ -277,7 +281,7 @@ public class JmsSession implements Session, QueueSession, TopicSession, JmsMessa
try {
JmsMessageConsumer consumer = consumers.get(((JmsConsumerInfo) resource).getConsumerId());
if (consumer != null) {
- consumer.shutdown();
+ consumer.shutdown(cause);
}
} catch (Throwable error) {
LOG.trace("Ignoring exception thrown during cleanup of remotely closed consumer", error);
@@ -286,7 +290,7 @@ public class JmsSession implements Session, QueueSession, TopicSession, JmsMessa
try {
JmsMessageProducer producer = producers.get(((JmsProducerInfo) resource).getProducerId());
if (producer != null) {
- producer.shutdown();
+ producer.shutdown(cause);
}
} catch (Throwable error) {
LOG.trace("Ignoring exception thrown during cleanup of remotely closed producer", error);
@@ -804,7 +808,16 @@ public class JmsSession implements Session, QueueSession, TopicSession, JmsMessa
protected void checkClosed() throws IllegalStateException {
if (closed.get()) {
- throw new IllegalStateException("The Session is closed");
+ IllegalStateException jmsEx = null;
+
+ if (failureCause == null) {
+ jmsEx = new IllegalStateException("The Session is closed");
+ } else {
+ jmsEx = new IllegalStateException("The Session was closed due to an unrecoverable error.");
+ jmsEx.initCause(failureCause);
+ }
+
+ throw jmsEx;
}
}
@@ -916,6 +929,10 @@ public class JmsSession implements Session, QueueSession, TopicSession, JmsMessa
return new JmsProducerId(sessionInfo.getSessionId(), producerIdGenerator.incrementAndGet());
}
+ protected void setFailureCause(Exception failureCause) {
+ this.failureCause = failureCause;
+ }
+
private String getNextMessageId(JmsMessageProducer producer) {
return producer.getProducerId().toString() + "-" + producer.getNextMessageSequence();
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0e227114/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConsumerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConsumerIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConsumerIntegrationTest.java
index 7ab8844..97697d8 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConsumerIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConsumerIntegrationTest.java
@@ -19,7 +19,6 @@
package org.apache.qpid.jms.integration;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import javax.jms.Connection;
import javax.jms.IllegalStateException;
@@ -78,19 +77,16 @@ public class ConsumerIntegrationTest extends QpidJmsTestCase {
try {
consumer.getMessageListener();
} catch (IllegalStateException jmsise) {
- return true;
+ if (jmsise.getCause() != null) {
+ return true;
+ } else {
+ return false;
+ }
}
return false;
}
}, 2000, 10));
- try {
- consumer.getMessageListener();
- fail("Expected ISE to be thrown due to being closed");
- } catch (IllegalStateException jmsise) {
- // expected
- }
-
// Try closing it explicitly, should effectively no-op in client.
// The test peer will throw during close if it sends anything.
consumer.close();
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0e227114/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
index 88c7028..cfba435 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
@@ -542,7 +542,11 @@ public class ProducerIntegrationTest extends QpidJmsTestCase {
try {
producer.getDestination();
} catch (IllegalStateException jmsise) {
- return true;
+ if (jmsise.getCause() != null) {
+ return true;
+ } else {
+ return false;
+ }
}
return false;
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0e227114/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SessionIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SessionIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SessionIntegrationTest.java
index 6d9249d..7891e92 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SessionIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SessionIntegrationTest.java
@@ -1292,7 +1292,11 @@ public class SessionIntegrationTest extends QpidJmsTestCase {
try {
consumer.getMessageListener();
} catch (IllegalStateException jmsise) {
- return true;
+ if (jmsise.getCause() != null) {
+ return true;
+ } else {
+ return false;
+ }
}
return false;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org