diff options
4 files changed, 55 insertions, 10 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index ed2127a78a..80502cccf1 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -930,7 +930,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi } - public boolean hasConsumer(TemporaryQueue destination) + public boolean hasConsumer(Destination destination) { AtomicInteger counter = _destinationConsumerCount.get(destination); @@ -1246,7 +1246,7 @@ public class AMQSession extends Closeable implements Session, QueueSession, Topi public TemporaryTopic createTemporaryTopic() throws JMSException { checkNotClosed(); - return new AMQTemporaryTopic(); + return new AMQTemporaryTopic(this); } public void unsubscribe(String name) throws JMSException diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java b/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java index abb76edb67..05e3165886 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java @@ -50,11 +50,9 @@ final class AMQTemporaryQueue extends AMQQueue implements TemporaryQueue throw new JMSException("Temporary Queue has consumers so cannot be deleted"); } - if(_session.isQueueBound(getQueueName())) - { - _session.deleteQueue(getQueueName()); - } - + // Currently TemporaryQueue is set to be auto-delete which means that the queue will be deleted + // by the server when there are no more subscriptions to that queue. This is probably not + // quite right for JMSCompliance. } } diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java b/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java index 0ba5cb3c3a..122b13cf3b 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java @@ -29,12 +29,14 @@ import javax.jms.TemporaryTopic; class AMQTemporaryTopic extends AMQTopic implements TemporaryTopic { + private final AMQSession _session; /** * Create new temporary topic. */ - public AMQTemporaryTopic() + public AMQTemporaryTopic(AMQSession session) { super("TempQueue" + Long.toString(System.currentTimeMillis())); + _session = session; } /** @@ -42,8 +44,14 @@ class AMQTemporaryTopic extends AMQTopic implements TemporaryTopic */ public void delete() throws JMSException { - throw new UnsupportedOperationException("Delete not supported, " + - "will auto-delete when connection closed"); + if(_session.hasConsumer(this)) + { + throw new JMSException("Temporary Topic has consumers so cannot be deleted"); + } + + // Currently TemporaryQueue is set to be auto-delete which means that the queue will be deleted + // by the server when there are no more subscriptions to that queue. This is probably not + // quite right for JMSCompliance. } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java index 3b6e3517c2..80de66735c 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java @@ -200,6 +200,45 @@ public class TopicSessionTest extends TestCase con.close(); } + public void testTempoaryTopic() throws Exception + { + AMQConnection conn = new AMQConnection("vm://:1?retries='0'", "guest", "guest", "test", "/test"); + TopicSession session = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); + TemporaryTopic topic = session.createTemporaryTopic(); + assertNotNull(topic); + TopicPublisher producer = session.createPublisher(topic); + MessageConsumer consumer = session.createConsumer(topic); + conn.start(); + producer.send(session.createTextMessage("hello")); + TextMessage tm = (TextMessage) consumer.receive(2000); + assertNotNull(tm); + assertEquals("hello",tm.getText()); + + try + { + topic.delete(); + fail("Expected JMSException : should not be able to delete while there are active consumers"); + } + catch(JMSException je) + { + ; //pass + } + + consumer.close(); + + try + { + topic.delete(); + } + catch(JMSException je) + { + fail("Unexpected Exception: " + je.getMessage()); + } + + conn.close(); + } + + public static junit.framework.Test suite() { return new junit.framework.TestSuite(TopicSessionTest.class); |