qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgr...@apache.org
Subject svn commit: r487804 - in /incubator/qpid/trunk/qpid/java/client/src: main/java/org/apache/qpid/client/ test/java/org/apache/qpid/test/unit/topic/
Date Sat, 16 Dec 2006 14:22:02 GMT
Author: rgreig
Date: Sat Dec 16 06:22:01 2006
New Revision: 487804

URL: http://svn.apache.org/viewvc?view=rev&rev=487804
Log:
QPID-204 : Implement TemporaryTopic.delete

Modified:
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java
    incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java?view=diff&rev=487804&r1=487803&r2=487804
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQSession.java
Sat Dec 16 06:22:01 2006
@@ -930,7 +930,7 @@
     }
 
 
-    public boolean hasConsumer(TemporaryQueue destination)
+    public boolean hasConsumer(Destination destination)
     {
         AtomicInteger counter = _destinationConsumerCount.get(destination);
 
@@ -1246,7 +1246,7 @@
     public TemporaryTopic createTemporaryTopic() throws JMSException
     {
         checkNotClosed();
-        return new AMQTemporaryTopic();
+        return new AMQTemporaryTopic(this);
     }
 
     public void unsubscribe(String name) throws JMSException

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java?view=diff&rev=487804&r1=487803&r2=487804
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
Sat Dec 16 06:22:01 2006
@@ -50,11 +50,9 @@
             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.
     }
 
 }

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java?view=diff&rev=487804&r1=487803&r2=487804
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryTopic.java
Sat Dec 16 06:22:01 2006
@@ -29,12 +29,14 @@
 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 @@
      */
     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.
     }
 
 }

Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java?view=diff&rev=487804&r1=487803&r2=487804
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/topic/TopicSessionTest.java
Sat Dec 16 06:22:01 2006
@@ -200,6 +200,45 @@
         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);



Mime
View raw message