diff options
| author | Andrew Stitcher <astitcher@apache.org> | 2011-12-18 05:09:07 +0000 |
|---|---|---|
| committer | Andrew Stitcher <astitcher@apache.org> | 2011-12-18 05:09:07 +0000 |
| commit | fb08688252d1043b202e1b88a9cd5b37da67794c (patch) | |
| tree | 918cb48793f3c686e52f8ccf714b306a65f53852 /java/client/src | |
| parent | d9ff8e43999e4c59d4092064a6e2c80773534864 (diff) | |
| download | qpid-python-fb08688252d1043b202e1b88a9cd5b37da67794c.tar.gz | |
QPID-3044: Implement JCA Adapter for Java JMS client
- Large contributions from Weston Price & Kevin Conner
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1220336 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/src')
3 files changed, 43 insertions, 5 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java index f0c003e02a..700073488e 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionFactory.java @@ -46,6 +46,12 @@ public class AMQConnectionFactory implements ConnectionFactory, QueueConnectionF { private final ConnectionURL _connectionDetails; + // The default constructor is necessary to allow AMQConnectionFactory to be deserialised from JNDI + public AMQConnectionFactory() + { + _connectionDetails = null; + } + public AMQConnectionFactory(final String url) throws URLSyntaxException { if (url == null) diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java b/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java index d96544adf8..3f9eadeef3 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQQueueBrowser.java @@ -30,6 +30,7 @@ import javax.jms.Queue; import javax.jms.QueueBrowser; import java.util.ArrayList; import java.util.Enumeration; +import java.util.NoSuchElementException; import java.util.concurrent.atomic.AtomicBoolean; public class AMQQueueBrowser implements QueueBrowser @@ -112,9 +113,12 @@ public class AMQQueueBrowser implements QueueBrowser public QueueBrowserEnumeration(BasicMessageConsumer consumer) throws JMSException { - _nextMessage = consumer == null ? null : consumer.receiveBrowse(); + if (consumer != null) + { + _consumer = consumer; + prefetchMessage(); + } _logger.info("QB:created with first element:" + _nextMessage); - _consumer = consumer; } public boolean hasMoreElements() @@ -126,18 +130,46 @@ public class AMQQueueBrowser implements QueueBrowser public Object nextElement() { Message msg = _nextMessage; + if (msg == null) + { + throw new NoSuchElementException("No messages") ; + } try { _logger.info("QB:nextElement about to receive"); - _nextMessage = _consumer.receiveBrowse(); + prefetchMessage(); _logger.info("QB:nextElement received:" + _nextMessage); } catch (JMSException e) { _logger.warn("Exception caught while queue browsing", e); _nextMessage = null; + try + { + closeConsumer() ; + } + catch (final JMSException jmse) {} // ignore } return msg; } - } + + private void prefetchMessage() throws JMSException + { + _nextMessage = _consumer.receiveBrowse(); + if (_nextMessage == null) + { + closeConsumer() ; + } + } + + private void closeConsumer() throws JMSException + { + if (_consumer != null) + { + BasicMessageConsumer consumer = _consumer ; + _consumer = null ; + consumer.close() ; + } + } + } } diff --git a/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java b/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java index 81b9940ed5..0f3be4ba18 100644 --- a/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java +++ b/java/client/src/main/java/org/apache/qpid/client/TopicPublisherAdapter.java @@ -123,7 +123,7 @@ public class TopicPublisherAdapter implements TopicPublisher public void send(Destination dest, Message msg) throws JMSException { checkPreConditions(); - checkTopic(_topic); + checkTopic(dest); _delegate.send(dest, msg); } |
