[jboss-cvs] JBoss Messaging SVN: r6360 - in trunk/examples/jms/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:19:43 EDT 2009


Author: gaohoward
Date: 2009-04-08 08:19:43 -0400 (Wed, 08 Apr 2009)
New Revision: 6360

Added:
   trunk/examples/jms/selector/src/org/jboss/jms/example/TopicSelectorExample2.java
Removed:
   trunk/examples/jms/selector/src/org/jboss/jms/example/SelectorExample.java
Modified:
   trunk/examples/jms/selector/build.xml
   trunk/examples/jms/selector/readme.html
Log:
rename to topic selector example 2


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

Modified: trunk/examples/jms/selector/readme.html
===================================================================
--- trunk/examples/jms/selector/readme.html	2009-04-08 12:16:01 UTC (rev 6359)
+++ trunk/examples/jms/selector/readme.html	2009-04-08 12:19:43 UTC (rev 6360)
@@ -1,10 +1,10 @@
 <html>
   <head>
-    <title>JBoss Messaging JMS Selector Example</title>
+    <title>JBoss Messaging JMS Topic Selector Example 2</title>
     <link rel="stylesheet" type="text/css" href="../common/common.css">
   </head>
   <body>
-     <h1>JMS Selector Example</h1>
+     <h1>JMS Selector Example 2</h1>
      <br>
      <p>This example shows you how to selectively consume messages using message selectors.</p>
      

Deleted: trunk/examples/jms/selector/src/org/jboss/jms/example/SelectorExample.java
===================================================================
--- trunk/examples/jms/selector/src/org/jboss/jms/example/SelectorExample.java	2009-04-08 12:16:01 UTC (rev 6359)
+++ trunk/examples/jms/selector/src/org/jboss/jms/example/SelectorExample.java	2009-04-08 12:19:43 UTC (rev 6360)
@@ -1,159 +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.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-
-/**
- * A simple JMS example that consumes messages using selectors.
- *
- * @author <a href="hgao at redhat.com">Howard Gao</a>
- */
-public class SelectorExample extends JMSExample
-{
-   private volatile boolean result = true;
-   
-   public static void main(String[] args)
-   {
-      new SelectorExample().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. perform a lookup on the topic
-         Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");
-
-         //Step 3. perform a lookup on the Connection Factory
-         ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
-
-         //Step 4. Create a JMS Connection
-         connection = cf.createConnection();
-         
-         //Step 5. Start the Connection
-         connection.start();
-
-         //Step 6. Create a JMS Session
-         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         //Step 7. Create a Message Producer
-         MessageProducer producer = session.createProducer(topic);
-         
-         //Step 8. Prepare two selectors
-         String redSelector = "color='red'";
-         String greenSelector = "color='green'";
-
-         //Step 9. Create a JMS Message Consumer that receives 'red' messages
-         MessageConsumer redConsumer = session.createConsumer(topic, redSelector);
-         redConsumer.setMessageListener(new SimpleMessageListener("red"));
-
-         //Step 10. Create a second JMS message consumer that receives 'green' messages
-         MessageConsumer greenConsumer = session.createConsumer(topic, greenSelector);
-         greenConsumer.setMessageListener(new SimpleMessageListener("green"));
-         
-         //Step 11. Create another JMS message consumer that receives all messages.
-         MessageConsumer allConsumer = session.createConsumer(topic);
-         allConsumer.setMessageListener(new SimpleMessageListener("all"));
-         
-         //Step 12. Create three messages, each has a color property
-         TextMessage redMessage = session.createTextMessage("Red");
-         redMessage.setStringProperty("color", "red");
-         TextMessage greenMessage = session.createTextMessage("Green");
-         greenMessage.setStringProperty("color", "green");
-         TextMessage blueMessage = session.createTextMessage("Blue");
-         blueMessage.setStringProperty("color", "blue");
-
-         //Step 13. Send the Messages
-         producer.send(redMessage);
-         System.out.println("Message sent: " + redMessage.getText());
-         producer.send(greenMessage);
-         System.out.println("Message sent: " + greenMessage.getText());
-         producer.send(blueMessage);
-         System.out.println("Message sent: " + blueMessage.getText());
-         
-         Thread.sleep(5000);
-         
-         return result;
-      }
-      finally
-      {
-         //Step 14. Be sure to close our JMS resources!
-         if (connection != null)
-         {
-            connection.close();
-         }
-         
-         // Also the initialContext
-         if (initialContext != null)
-         {
-            initialContext.close();
-         }
-      }
-   }
-   
-   public class SimpleMessageListener implements MessageListener
-   {
-
-      private String name;
-      
-      public SimpleMessageListener(String listener)
-      {
-         name = listener;
-      }
-
-      public void onMessage(Message msg)
-      {
-         TextMessage textMessage = (TextMessage)msg;
-         try
-         {
-            String colorProp = msg.getStringProperty("color");
-            System.out.println("Receiver " + name + " receives message [" + textMessage.getText() + "] with color property: " + colorProp);
-            if ((!colorProp.equals(name)) && (!name.equals("all")))
-            {
-               result = false;
-            }
-         }
-         catch (JMSException e)
-         {
-            e.printStackTrace();
-            result = false;
-         }
-      }
-      
-   }
-}

Copied: trunk/examples/jms/selector/src/org/jboss/jms/example/TopicSelectorExample2.java (from rev 6359, trunk/examples/jms/selector/src/org/jboss/jms/example/SelectorExample.java)
===================================================================
--- trunk/examples/jms/selector/src/org/jboss/jms/example/TopicSelectorExample2.java	                        (rev 0)
+++ trunk/examples/jms/selector/src/org/jboss/jms/example/TopicSelectorExample2.java	2009-04-08 12:19:43 UTC (rev 6360)
@@ -0,0 +1,159 @@
+/*
+   * 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.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+/**
+ * A simple JMS example that consumes messages using selectors.
+ *
+ * @author <a href="hgao at redhat.com">Howard Gao</a>
+ */
+public class TopicSelectorExample2 extends JMSExample
+{
+   private volatile boolean result = true;
+   
+   public static void main(String[] args)
+   {
+      new TopicSelectorExample2().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. perform a lookup on the topic
+         Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");
+
+         //Step 3. perform a lookup on the Connection Factory
+         ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+
+         //Step 4. Create a JMS Connection
+         connection = cf.createConnection();
+         
+         //Step 5. Start the Connection
+         connection.start();
+
+         //Step 6. Create a JMS Session
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         //Step 7. Create a Message Producer
+         MessageProducer producer = session.createProducer(topic);
+         
+         //Step 8. Prepare two selectors
+         String redSelector = "color='red'";
+         String greenSelector = "color='green'";
+
+         //Step 9. Create a JMS Message Consumer that receives 'red' messages
+         MessageConsumer redConsumer = session.createConsumer(topic, redSelector);
+         redConsumer.setMessageListener(new SimpleMessageListener("red"));
+
+         //Step 10. Create a second JMS message consumer that receives 'green' messages
+         MessageConsumer greenConsumer = session.createConsumer(topic, greenSelector);
+         greenConsumer.setMessageListener(new SimpleMessageListener("green"));
+         
+         //Step 11. Create another JMS message consumer that receives all messages.
+         MessageConsumer allConsumer = session.createConsumer(topic);
+         allConsumer.setMessageListener(new SimpleMessageListener("all"));
+         
+         //Step 12. Create three messages, each has a color property
+         TextMessage redMessage = session.createTextMessage("Red");
+         redMessage.setStringProperty("color", "red");
+         TextMessage greenMessage = session.createTextMessage("Green");
+         greenMessage.setStringProperty("color", "green");
+         TextMessage blueMessage = session.createTextMessage("Blue");
+         blueMessage.setStringProperty("color", "blue");
+
+         //Step 13. Send the Messages
+         producer.send(redMessage);
+         System.out.println("Message sent: " + redMessage.getText());
+         producer.send(greenMessage);
+         System.out.println("Message sent: " + greenMessage.getText());
+         producer.send(blueMessage);
+         System.out.println("Message sent: " + blueMessage.getText());
+         
+         Thread.sleep(5000);
+         
+         return result;
+      }
+      finally
+      {
+         //Step 14. Be sure to close our JMS resources!
+         if (connection != null)
+         {
+            connection.close();
+         }
+         
+         // Also the initialContext
+         if (initialContext != null)
+         {
+            initialContext.close();
+         }
+      }
+   }
+   
+   public class SimpleMessageListener implements MessageListener
+   {
+
+      private String name;
+      
+      public SimpleMessageListener(String listener)
+      {
+         name = listener;
+      }
+
+      public void onMessage(Message msg)
+      {
+         TextMessage textMessage = (TextMessage)msg;
+         try
+         {
+            String colorProp = msg.getStringProperty("color");
+            System.out.println("Receiver " + name + " receives message [" + textMessage.getText() + "] with color property: " + colorProp);
+            if ((!colorProp.equals(name)) && (!name.equals("all")))
+            {
+               result = false;
+            }
+         }
+         catch (JMSException e)
+         {
+            e.printStackTrace();
+            result = false;
+         }
+      }
+      
+   }
+}


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




More information about the jboss-cvs-commits mailing list