[jboss-cvs] JBoss Messaging SVN: r6359 - in trunk/examples/jms/topic-selector: src/org/jboss/jms/example and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 8 08:16:01 EDT 2009


Author: gaohoward
Date: 2009-04-08 08:16:01 -0400 (Wed, 08 Apr 2009)
New Revision: 6359

Added:
   trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample1.java
Removed:
   trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample.java
Modified:
   trunk/examples/jms/topic-selector/build.xml
   trunk/examples/jms/topic-selector/readme.html
Log:
change it to topic example 1


Modified: trunk/examples/jms/topic-selector/build.xml
===================================================================
--- trunk/examples/jms/topic-selector/build.xml	2009-04-08 11:50:03 UTC (rev 6358)
+++ trunk/examples/jms/topic-selector/build.xml	2009-04-08 12:16:01 UTC (rev 6359)
@@ -28,19 +28,19 @@
 <!-- =========================================================================================== -->
 
 
-<project default="run" name="JBoss Messaging JMS Topic Selector Example">
+<project default="run" name="JBoss Messaging JMS Topic Selector Example 1">
 
    <import file="../common/build.xml"/>
 
    <target name="run">
       <antcall target="runExample">
-         <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample"/>
+         <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample1"/>
       </antcall>
    </target>
 
    <target name="runRemote">
       <antcall target="runExample">
-         <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample"/>
+         <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample1"/>
          <param name="jbm.example.runServer" value="false"/>
       </antcall>
    </target>

Modified: trunk/examples/jms/topic-selector/readme.html
===================================================================
--- trunk/examples/jms/topic-selector/readme.html	2009-04-08 11:50:03 UTC (rev 6358)
+++ trunk/examples/jms/topic-selector/readme.html	2009-04-08 12:16:01 UTC (rev 6359)
@@ -1,10 +1,10 @@
 <html>
   <head>
-    <title>JBoss Messaging JMS Topic With Selectors Example</title>
+    <title>JBoss Messaging JMS Topic Selector Example 1</title>
     <link rel="stylesheet" type="text/css" href="../common/common.css">
   </head>
   <body>
-     <h1>JMS Topic Example</h1>
+     <h1>JMS Topic Selector Example 1</h1>
      <br>
      <p>This example shows you how to send message to a JMS Topic, and subscribe them using selectors with JBoss Messaging, also creating 3 non durable subscribers. 2 subscriptions using selectors, and a third one that should receive the complete set of messages.</p>
      <p>Topics and selectors are a standard part of JMS, please consult the JMS 1.1 specification for full details.</p>

Deleted: trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample.java
===================================================================
--- trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample.java	2009-04-08 11:50:03 UTC (rev 6358)
+++ trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample.java	2009-04-08 12:16:01 UTC (rev 6359)
@@ -1,173 +0,0 @@
-/*
-   * JBoss, Home of Professional Open Source
-   * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
-   * by the @authors tag. See the copyright.txt in the distribution for a
-   * full listing of individual contributors.
-   *
-   * This is free software; you can redistribute it and/or modify it
-   * under the terms of the GNU Lesser General Public License as
-   * published by the Free Software Foundation; either version 2.1 of
-   * the License, or (at your option) any later version.
-   *
-   * This software is distributed in the hope that it will be useful,
-   * but WITHOUT ANY WARRANTY; without even the implied warranty of
-   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   * Lesser General Public License for more details.
-   *
-   * You should have received a copy of the GNU Lesser General Public
-   * License along with this software; if not, write to the Free
-   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-   */
-package org.jboss.jms.example;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-
-/**
- * A simple JMS Topic example that creates a producer and consumer on a queue and sends and receives a message.
- *
- * @author <a href="csuconic at redhat.com">Clebert Suconic</a>
- */
-public class TopicSelectorExample extends JMSExample
-{
-   public static void main(String[] args)
-   {
-      new TopicSelectorExample().run(args);
-   }
-
-   public boolean runExample() throws Exception
-   {
-      Connection connection = null;
-      
-      InitialContext initialContext = null;
-      try
-      {
-
-         // Step 1. Create an initial context to perform the JNDI lookup.
-         initialContext = getContext(0);
-
-         // Step 2. Look-up the JMS topic
-         Topic topic = (Topic)initialContext.lookup("/topic/exampleTopic");
-
-         // Step 3. Look-up the JMS connection factory
-         ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
-         // Step 4. Create a JMS connection
-         connection = cf.createConnection();
-
-         // Step 5. Create a JMS session
-         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         // Step 6. Create a JMS message producer
-         MessageProducer producer = session.createProducer(topic);
-
-         // Step 7. Create one subscription with a specific Filter for someID=1
-         MessageConsumer messageConsumer1 = session.createConsumer(topic, "someID=1", false);
-
-         // Step 8. Create another subscription with a specific Filter for someID=2
-         MessageConsumer messageConsumer2 = session.createConsumer(topic, "someID=2", false);
-
-         // Step 9. Create another subscription with no filters, which will receive every message sent to the topic
-         MessageConsumer messageConsumer3 = session.createConsumer(topic);
-
-         // Step 10. Send 20 messages, 10 with someID=1, 10 with someID=2
-
-         for (int i = 1; i < 10; i++)
-         {
-            for (int someID = 1; someID <= 2; someID++)
-            {
-               // Step 10.1 Create a text message
-               TextMessage message1 = session.createTextMessage("This is a text message " + i +
-                                                                " sent for someID=" +
-                                                                someID);
-
-               // Step 10.1 Set a property
-               message1.setIntProperty("someID", someID);
-
-               // Step 10.2 Send the message
-               producer.send(message1);
-
-               System.out.println("Sent message: " + message1.getText());
-            }
-         }
-
-         // Step 11. Start the JMS Connection. This step will activate the subscribers to receive messages.
-         connection.start();
-
-         // Step 12. Consume the messages from MessageConsumer1, filtering out someID=2
-
-         System.out.println("*************************************************************");
-         System.out.println("MessageConsumer1 will only receive messages where someID=1:");
-         for (;;)
-         {
-            TextMessage messageReceivedA = (TextMessage)messageConsumer1.receive(1000);
-            if (messageReceivedA == null)
-            {
-               break;
-            }
-
-            System.out.println("messageConsumer1 received " + messageReceivedA.getText() +
-                               " someID = " +
-                               messageReceivedA.getIntProperty("someID"));
-         }
-
-         // Step 13. Consume the messages from MessageConsumer2, filtering out someID=2
-         System.out.println("*************************************************************");
-         System.out.println("MessageConsumer2 will only receive messages where someID=2:");
-         for (;;)
-         {
-            TextMessage messageReceivedB = (TextMessage)messageConsumer2.receive(1000);
-            if (messageReceivedB == null)
-            {
-               break;
-            }
-
-            System.out.println("messageConsumer2 received " + messageReceivedB.getText() +
-                               " someID = " +
-                               messageReceivedB.getIntProperty("someID"));
-         }
-
-         // Step 14. Consume the messages from MessageConsumer3, receiving the complete set of messages
-         System.out.println("*************************************************************");
-         System.out.println("MessageConsumer3 will receive every message:");
-         for (;;)
-         {
-            TextMessage messageReceivedC = (TextMessage)messageConsumer3.receive(1000);
-            if (messageReceivedC == null)
-            {
-               break;
-            }
-            System.out.println("messageConsumer3 received " + messageReceivedC.getText() +
-                               " someID = " +
-                               messageReceivedC.getIntProperty("someID"));
-         }
-
-         // Step 15. Close the subscribers
-         messageConsumer1.close();
-         messageConsumer2.close();
-         messageConsumer3.close();
-         
-         return true;
-
-      }
-      finally
-      {
-         // Step 15. Be sure to close our JMS resources!
-         if (initialContext != null)
-         {
-            initialContext.close();
-         }
-         if (connection != null)
-         {
-            connection.close();
-         }
-      }
-   }
-}

Copied: trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample1.java (from rev 6358, trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample.java)
===================================================================
--- trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample1.java	                        (rev 0)
+++ trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample1.java	2009-04-08 12:16:01 UTC (rev 6359)
@@ -0,0 +1,173 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+   * by the @authors tag. See the copyright.txt in the distribution for a
+   * full listing of individual contributors.
+   *
+   * This is free software; you can redistribute it and/or modify it
+   * under the terms of the GNU Lesser General Public License as
+   * published by the Free Software Foundation; either version 2.1 of
+   * the License, or (at your option) any later version.
+   *
+   * This software is distributed in the hope that it will be useful,
+   * but WITHOUT ANY WARRANTY; without even the implied warranty of
+   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   * Lesser General Public License for more details.
+   *
+   * You should have received a copy of the GNU Lesser General Public
+   * License along with this software; if not, write to the Free
+   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+   */
+package org.jboss.jms.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+/**
+ * A simple JMS Topic example that creates a producer and consumer on a queue and sends and receives a message.
+ *
+ * @author <a href="csuconic at redhat.com">Clebert Suconic</a>
+ */
+public class TopicSelectorExample1 extends JMSExample
+{
+   public static void main(String[] args)
+   {
+      new TopicSelectorExample1().run(args);
+   }
+
+   public boolean runExample() throws Exception
+   {
+      Connection connection = null;
+      
+      InitialContext initialContext = null;
+      try
+      {
+
+         // Step 1. Create an initial context to perform the JNDI lookup.
+         initialContext = getContext(0);
+
+         // Step 2. Look-up the JMS topic
+         Topic topic = (Topic)initialContext.lookup("/topic/exampleTopic");
+
+         // Step 3. Look-up the JMS connection factory
+         ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+
+         // Step 4. Create a JMS connection
+         connection = cf.createConnection();
+
+         // Step 5. Create a JMS session
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Step 6. Create a JMS message producer
+         MessageProducer producer = session.createProducer(topic);
+
+         // Step 7. Create one subscription with a specific Filter for someID=1
+         MessageConsumer messageConsumer1 = session.createConsumer(topic, "someID=1", false);
+
+         // Step 8. Create another subscription with a specific Filter for someID=2
+         MessageConsumer messageConsumer2 = session.createConsumer(topic, "someID=2", false);
+
+         // Step 9. Create another subscription with no filters, which will receive every message sent to the topic
+         MessageConsumer messageConsumer3 = session.createConsumer(topic);
+
+         // Step 10. Send 20 messages, 10 with someID=1, 10 with someID=2
+
+         for (int i = 1; i < 10; i++)
+         {
+            for (int someID = 1; someID <= 2; someID++)
+            {
+               // Step 10.1 Create a text message
+               TextMessage message1 = session.createTextMessage("This is a text message " + i +
+                                                                " sent for someID=" +
+                                                                someID);
+
+               // Step 10.1 Set a property
+               message1.setIntProperty("someID", someID);
+
+               // Step 10.2 Send the message
+               producer.send(message1);
+
+               System.out.println("Sent message: " + message1.getText());
+            }
+         }
+
+         // Step 11. Start the JMS Connection. This step will activate the subscribers to receive messages.
+         connection.start();
+
+         // Step 12. Consume the messages from MessageConsumer1, filtering out someID=2
+
+         System.out.println("*************************************************************");
+         System.out.println("MessageConsumer1 will only receive messages where someID=1:");
+         for (;;)
+         {
+            TextMessage messageReceivedA = (TextMessage)messageConsumer1.receive(1000);
+            if (messageReceivedA == null)
+            {
+               break;
+            }
+
+            System.out.println("messageConsumer1 received " + messageReceivedA.getText() +
+                               " someID = " +
+                               messageReceivedA.getIntProperty("someID"));
+         }
+
+         // Step 13. Consume the messages from MessageConsumer2, filtering out someID=2
+         System.out.println("*************************************************************");
+         System.out.println("MessageConsumer2 will only receive messages where someID=2:");
+         for (;;)
+         {
+            TextMessage messageReceivedB = (TextMessage)messageConsumer2.receive(1000);
+            if (messageReceivedB == null)
+            {
+               break;
+            }
+
+            System.out.println("messageConsumer2 received " + messageReceivedB.getText() +
+                               " someID = " +
+                               messageReceivedB.getIntProperty("someID"));
+         }
+
+         // Step 14. Consume the messages from MessageConsumer3, receiving the complete set of messages
+         System.out.println("*************************************************************");
+         System.out.println("MessageConsumer3 will receive every message:");
+         for (;;)
+         {
+            TextMessage messageReceivedC = (TextMessage)messageConsumer3.receive(1000);
+            if (messageReceivedC == null)
+            {
+               break;
+            }
+            System.out.println("messageConsumer3 received " + messageReceivedC.getText() +
+                               " someID = " +
+                               messageReceivedC.getIntProperty("someID"));
+         }
+
+         // Step 15. Close the subscribers
+         messageConsumer1.close();
+         messageConsumer2.close();
+         messageConsumer3.close();
+         
+         return true;
+
+      }
+      finally
+      {
+         // Step 15. Be sure to close our JMS resources!
+         if (initialContext != null)
+         {
+            initialContext.close();
+         }
+         if (connection != null)
+         {
+            connection.close();
+         }
+      }
+   }
+}


Property changes on: trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample1.java
___________________________________________________________________
Name: svn:mergeinfo
   + 




More information about the jboss-cvs-commits mailing list