[jboss-cvs] JBoss Messaging SVN: r6482 - in trunk: examples/jms and 13 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 17 13:34:02 EDT 2009


Author: timfox
Date: 2009-04-17 13:34:02 -0400 (Fri, 17 Apr 2009)
New Revision: 6482

Added:
   trunk/examples/jms/topic-hierarchies/
   trunk/examples/jms/topic-hierarchies/build.xml
   trunk/examples/jms/topic-hierarchies/readme.html
   trunk/examples/jms/topic-hierarchies/server0/
   trunk/examples/jms/topic-hierarchies/server0/client-jndi.properties
   trunk/examples/jms/topic-hierarchies/server0/jbm-configuration.xml
   trunk/examples/jms/topic-hierarchies/server0/jbm-jms.xml
   trunk/examples/jms/topic-hierarchies/server0/jbm-queues.xml
   trunk/examples/jms/topic-hierarchies/server0/jbm-security.xml
   trunk/examples/jms/topic-hierarchies/server0/jbm-standalone-beans.xml
   trunk/examples/jms/topic-hierarchies/src/
   trunk/examples/jms/topic-hierarchies/src/org/
   trunk/examples/jms/topic-hierarchies/src/org/jboss/
   trunk/examples/jms/topic-hierarchies/src/org/jboss/jms/
   trunk/examples/jms/topic-hierarchies/src/org/jboss/jms/example/
   trunk/examples/jms/topic-hierarchies/src/org/jboss/jms/example/TopicHierarchyExample.java
Removed:
   trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
   trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
Modified:
   trunk/.classpath
   trunk/examples/jms/producer-rate-limit/src/org/jboss/jms/example/ProducerRateLimitExample.java
   trunk/src/main/org/jboss/messaging/core/postoffice/AddressManager.java
   trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/SimpleAddressManager.java
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
   trunk/tests/src/org/jboss/messaging/tests/performance/persistence/StorageManagerTimingTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
Log:
added topic hierarchies example

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/.classpath	2009-04-17 17:34:02 UTC (rev 6482)
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry excluding="**/.svn/**/*" kind="src" path="src/main"/>
-	<classpathentry kind="src" path="examples/jms/static-selector/src"/>
 	<classpathentry kind="src" path="build/src"/>
 	<classpathentry kind="src" path="tests/jms-tests/config"/>
 	<classpathentry kind="src" path="tests/config"/>
@@ -15,6 +14,8 @@
 	<classpathentry kind="src" path="src/schemas"/>
 	<classpathentry kind="src" path="tests/joram-tests/src"/>
 	<classpathentry kind="src" path="tests/joram-tests/config"/>
+	<classpathentry kind="src" path="examples/jms/static-selector/src"/>
+	<classpathentry kind="src" path="examples/jms/topic-hierarchies/src"/>
 	<classpathentry kind="src" path="examples/jms/security/src"/>
 	<classpathentry kind="src" path="examples/jms/producer-rate-limit/src"/>
 	<classpathentry kind="src" path="examples/jms/interceptor/src"/>

Modified: trunk/examples/jms/producer-rate-limit/src/org/jboss/jms/example/ProducerRateLimitExample.java
===================================================================
--- trunk/examples/jms/producer-rate-limit/src/org/jboss/jms/example/ProducerRateLimitExample.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/examples/jms/producer-rate-limit/src/org/jboss/jms/example/ProducerRateLimitExample.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -34,7 +34,7 @@
  * This example demonstrates how a message producer can be limited to produce messages at a maximum rate
  * specified in messages per sec.
  *
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
  */
 public class ProducerRateLimitExample extends JMSExample
 {

Added: trunk/examples/jms/topic-hierarchies/build.xml
===================================================================
--- trunk/examples/jms/topic-hierarchies/build.xml	                        (rev 0)
+++ trunk/examples/jms/topic-hierarchies/build.xml	2009-04-17 17:34:02 UTC (rev 6482)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+      <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+      ]>
+
+<!-- =========================================================================================== -->
+<!--                                                                                             -->
+<!-- JBoss, Home of Professional Open Source                                                     -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated                        -->
+<!-- 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.                                    -->
+<!--                                                                                             -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging JMS Queue Example">
+
+   <import file="../common/build.xml"/>
+
+   <target name="run">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.TopicHierarchyExample"/>
+      </antcall>
+   </target>
+
+   <target name="runRemote">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.TopicHierarchyExample"/>
+         <param name="jbm.example.runServer" value="false"/>
+      </antcall>
+   </target>
+
+</project>
\ No newline at end of file

Added: trunk/examples/jms/topic-hierarchies/readme.html
===================================================================
--- trunk/examples/jms/topic-hierarchies/readme.html	                        (rev 0)
+++ trunk/examples/jms/topic-hierarchies/readme.html	2009-04-17 17:34:02 UTC (rev 6482)
@@ -0,0 +1,179 @@
+<html>
+  <head>
+    <title>JBoss Messaging Topic Hierarchy Example</title>
+    <link rel="stylesheet" type="text/css" href="../common/common.css">
+  </head>
+  <body>
+     <h1>JBoss Messaging Topic Hierarchy Example</h1>
+     <br>
+     <p>JBoss Messaging supports topic hierarchies. With a topic hierarchy you can register a subscriber with a wild-card
+     and that subscriber will receive any messages sent to an address that matches the wildcard.</p>
+     <p>JBoss Messaging wild-cards can use the character '#' which means "match any number of words", and
+     the character '*' which means "match a single word". Words are delimited by the character "."</p>
+     <p>For example if I subscribe using the wild-card "news.europe.#", then that matches messages sent to the addresses
+     "news.europe", "news.europe.sport" and "news.europe.entertainment", but it does not match messages sent to the
+     address "news.usa.wrestling"</p>
+     <p>For more information on the wild-card syntax please consult the user manual.</p>
+     <h2>Example step-by-step</h2>
+     <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
+     <p>In this example we will define a hierarchy of topics in the file <code>jbm-jms.xml</code></p>
+     <pre>
+        <code>
+   &lt;topic name="news"&gt;
+      &lt;entry name="/topic/news"/&gt;
+   &lt;/topic&gt;
+   
+   &lt;topic name="news.usa"&gt;
+      &lt;entry name="/topic/news.usa"/&gt;
+   &lt;/topic&gt;
+   
+   &lt;topic name="news.usa.wrestling"&gt;
+      &lt;entry name="/topic/news.wrestling"/&gt;
+   &lt;/topic&gt;
+   
+   &lt;topic name="news.europe"&gt;
+      &lt;entry name="/topic/news.europe"/&gt;
+   &lt;/topic&gt;
+   
+   &lt;topic name="news.europe.sport"&gt;
+      &lt;entry name="/topic/news.europe.sport"/&gt;
+   &lt;/topic&gt;
+   
+   &lt;topic name="news.europe.entertainment"&gt;
+      &lt;entry name="/topic/news.europe.entertainment"/&gt;
+   &lt;/topic&gt;
+        </code>
+     </pre>
+     <p>Then we will create a subscriber using the wildcard "news.europe.#".</p>
+     <p>We will then send three messages: one to the address news.usa.wrestling, one to the address news.europe.sport,
+     and one to the address news.europe.entertainment.</p>
+     <p>We will verify that the message sent to news.usa.wrestling does not get received since it does not match, 
+     but the messages sent to the other two addresses do get received since they match.</p>
+     <br>
+     <ol>
+        <li>Create an initial context to perform the JNDI lookup.</code></li>
+        <pre>
+           <code>initialContext = getContext(0);</code>
+        </pre>
+
+        <li>Perform a lookup on the Connection Factory</li>
+        <pre>
+           <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+        </pre>
+
+        <li>Create a JMS Connection</li>
+        <pre>
+           <code>connection = cf.createConnection();</code>
+        </pre>
+
+        <li>Create a JMS Session</li>
+        <pre>
+           <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+        </pre>
+
+        <li>Instantiate a topic representing the wildcard we're going to subscribe to.</li>
+        <pre>
+           <code>Topic topicSubscribe = new JBossTopic("news.europe.#");</code>
+        </pre>
+
+        <li>Create a consumer (topic subscriber) that will consume using that wildcard.
+         The consumer will receive any messages sent to any topic that starts with news.europe</li>
+        <pre>
+          <code>MessageConsumer messageConsumer = session.createConsumer(topicSubscribe);</code>
+       </pre>
+
+        <li>Create an anonymous producer. The sending address is specified at send time.</li>
+        <pre>
+           <code>MessageProducer producer = session.createProducer(null);</code>
+        </pre>
+
+        <li>Instantiate some more topic objects corresponding to the individual topics
+         we're going to send messages to. You could look these up from JNDI if you wanted to.</li>
+        <pre>
+           <code>
+         Topic topicNewsUsaWrestling = new JBossTopic("news.usa.wrestling");
+         
+         Topic topicNewsEuropeSport = new JBossTopic("news.europe.sport");
+         
+         Topic topicNewsEuropeEntertainment = new JBossTopic("news.europe.entertainment");</code>
+        </pre>
+
+        <li>Send a message destined for the usa wrestling topic.</li>
+          <pre>
+           <code>
+         TextMessage messageWrestlingNews = session.createTextMessage("Hulk Hogan starts ballet classes");
+         
+         producer.send(topicNewsUsaWrestling, messageWrestlingNews);
+           </code>
+        </pre>
+
+        <li>Send a message destined for the europe sport topic.</li>
+        <pre>
+           <code>
+         TextMessage messageEuropeSport = session.createTextMessage("Lewis Hamilton joins European synchronized swimming team");
+         
+         producer.send(topicNewsEuropeSport, messageEuropeSport);           
+           </code>
+        </pre>
+
+        <li>Send a message destined for the europe entertainment topic</li>
+        <pre>
+           <code>
+         TextMessage messageEuropeEntertainment = session.createTextMessage("John Lennon resurrected from dead");
+         
+         producer.send(topicNewsEuropeEntertainment, messageEuropeEntertainment);
+           </code>
+        </pre>
+        
+        <li>Start the connection</li>
+        <pre>
+           <code>
+        connection.start();
+           </code>
+        </pre>
+        
+        <li>We don't receive the usa wrestling message since we subscribed to news.europe.# and
+         that doesn't match news.usa.wrestling. However we do receive the Europe sport message, and the
+         europe entertainment message, since these match the wildcard.</li>
+        <pre>
+           <code>
+        TextMessage messageReceived1 = (TextMessage)messageConsumer.receive(5000);
+         
+        System.out.println("Received message: " + messageReceived1.getText());
+         
+        TextMessage messageReceived2 = (TextMessage)messageConsumer.receive(5000);
+         
+        System.out.println("Received message: " + messageReceived2.getText());
+         
+        Message message = messageConsumer.receive(1000);
+         
+        if (message != null)
+        {
+           return false;
+        }
+         
+        System.out.println("Didn't received any more message: " + message);
+           </code>
+        </pre>
+        
+        <li>Be sure to close our resources!</li>
+
+        <pre>
+           <code>finally
+           {
+              if (initialContext != null)
+              {
+                initialContext.close();
+              }
+              if (connection != null)
+              {
+                 connection.close();
+              }
+           }</code>
+        </pre>
+
+
+
+     </ol>
+  </body>
+</html>
\ No newline at end of file

Added: trunk/examples/jms/topic-hierarchies/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/topic-hierarchies/server0/client-jndi.properties	                        (rev 0)
+++ trunk/examples/jms/topic-hierarchies/server0/client-jndi.properties	2009-04-17 17:34:02 UTC (rev 6482)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/topic-hierarchies/server0/jbm-configuration.xml
===================================================================
--- trunk/examples/jms/topic-hierarchies/server0/jbm-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/topic-hierarchies/server0/jbm-configuration.xml	2009-04-17 17:34:02 UTC (rev 6482)
@@ -0,0 +1,29 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd">
+   <configuration>
+
+      <!-- Connectors -->
+
+      <connectors>
+         <connector name="netty-connector">
+            <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+            <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+         </connector>
+      </connectors>
+      
+      <!-- Acceptors -->
+      <acceptors>
+         <acceptor name="netty-acceptor">
+            <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+            <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+         </acceptor>
+      </acceptors>
+
+      <!-- Other config -->
+
+      <journal-min-files>2</journal-min-files>
+
+   </configuration>
+
+</deployment>

Added: trunk/examples/jms/topic-hierarchies/server0/jbm-jms.xml
===================================================================
--- trunk/examples/jms/topic-hierarchies/server0/jbm-jms.xml	                        (rev 0)
+++ trunk/examples/jms/topic-hierarchies/server0/jbm-jms.xml	2009-04-17 17:34:02 UTC (rev 6482)
@@ -0,0 +1,41 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-jms.xsd ">
+   <!--the connection factory used by the example-->
+   <connection-factory name="ConnectionFactory">
+      <connector-ref connector-name="netty-connector"/>
+      <entries>
+         <entry name="ConnectionFactory"/>
+         <entry name="XAConnectionFactory"/>
+         <entry name="java:/ConnectionFactory"/>
+         <entry name="java:/XAConnectionFactory"/>
+      </entries>
+   </connection-factory>
+
+   <!--the topics used by the example-->
+   
+   <topic name="news">
+      <entry name="/topic/news"/>
+   </topic>
+   
+   <topic name="news.usa">
+      <entry name="/topic/news.usa"/>
+   </topic>
+   
+   <topic name="news.usa.wrestling">
+      <entry name="/topic/news.wrestling"/>
+   </topic>
+   
+   <topic name="news.europe">
+      <entry name="/topic/news.europe"/>
+   </topic>
+   
+   <topic name="news.europe.sport">
+      <entry name="/topic/news.europe.sport"/>
+   </topic>
+   
+   <topic name="news.europe.entertainment">
+      <entry name="/topic/news.europe.entertainment"/>
+   </topic>
+
+</deployment>

Added: trunk/examples/jms/topic-hierarchies/server0/jbm-queues.xml
===================================================================
--- trunk/examples/jms/topic-hierarchies/server0/jbm-queues.xml	                        (rev 0)
+++ trunk/examples/jms/topic-hierarchies/server0/jbm-queues.xml	2009-04-17 17:34:02 UTC (rev 6482)
@@ -0,0 +1,15 @@
+<settings xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-queues.xsd ">
+
+   <!--security for example queue-->
+   <security match="jms.#">
+      <permission type="createDurableQueue" roles="guest"/>
+      <permission type="deleteDurableQueue" roles="guest"/>
+      <permission type="createTempQueue" roles="guest"/>
+      <permission type="deleteTempQueue" roles="guest"/>
+      <permission type="consume" roles="guest"/>
+      <permission type="send" roles="guest"/>
+   </security>
+
+</settings>

Added: trunk/examples/jms/topic-hierarchies/server0/jbm-security.xml
===================================================================
--- trunk/examples/jms/topic-hierarchies/server0/jbm-security.xml	                        (rev 0)
+++ trunk/examples/jms/topic-hierarchies/server0/jbm-security.xml	2009-04-17 17:34:02 UTC (rev 6482)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-security.xsd ">
+   <!-- the default user.  this is used where username is null-->
+   <defaultuser name="guest" password="guest">
+      <role name="guest"/>
+   </defaultuser>
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/topic-hierarchies/server0/jbm-standalone-beans.xml
===================================================================
--- trunk/examples/jms/topic-hierarchies/server0/jbm-standalone-beans.xml	                        (rev 0)
+++ trunk/examples/jms/topic-hierarchies/server0/jbm-standalone-beans.xml	2009-04-17 17:34:02 UTC (rev 6482)
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+   <!-- JNDI server. Disable this if you don't want JNDI -->
+   <bean name="JNDIServer" class="org.jnp.server.Main">
+      <property name="namingInfo">
+         <inject bean="Naming"/>
+      </property>
+      <property name="port">1099</property>
+      <property name="bindAddress">localhost</property>
+      <property name="rmiPort">1098</property>
+      <property name="rmiBindAddress">localhost</property>
+   </bean>
+   
+   <!-- MBean server -->
+   <bean name="MBeanServer" class="javax.management.MBeanServer">
+      <constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   </bean> 
+
+   <!-- The core configuration -->
+   <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+   <!-- The security manager -->
+   <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+
+   <!-- The core server -->
+   <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl"> 
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+         <parameter>
+            <inject bean="MBeanServer"/>
+         </parameter>
+         <parameter>
+            <inject bean="JBMSecurityManager"/>
+         </parameter>        
+      </constructor>         
+   </bean>
+   
+   <!-- The JMS server -->
+   <bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl">
+      <constructor>         
+         <parameter>
+            <inject bean="MessagingServer"/>
+         </parameter>
+      </constructor>
+   </bean>
+
+</deployment>

Added: trunk/examples/jms/topic-hierarchies/src/org/jboss/jms/example/TopicHierarchyExample.java
===================================================================
--- trunk/examples/jms/topic-hierarchies/src/org/jboss/jms/example/TopicHierarchyExample.java	                        (rev 0)
+++ trunk/examples/jms/topic-hierarchies/src/org/jboss/jms/example/TopicHierarchyExample.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -0,0 +1,142 @@
+/*
+   * 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.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+import org.jboss.messaging.jms.JBossTopic;
+
+/**
+ * This example demonstrates how a JMS TopicSubscriber can be created to subscribe to a wild-card Topic.
+ * 
+ * For more information please see the readme.html
+ *
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ */
+public class TopicHierarchyExample extends JMSExample
+{
+   public static void main(String[] args)
+   {
+      new TopicHierarchyExample().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 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. Create a JMS Session
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         
+         //Step 6. Instantiate a topic representing the wildcard we're going to subscribe to 
+         Topic topicSubscribe = new JBossTopic("news.europe.#");
+         
+         //Step 7. Create a consumer (topic subscriber) that will consume using that wildcard
+         // The consumer will receive any messages sent to any topic that starts with news.europe
+         MessageConsumer messageConsumer = session.createConsumer(topicSubscribe);
+ 
+         //Step 8. Create an anonymous producer
+         MessageProducer producer = session.createProducer(null);
+         
+         //Step 9. Instantiate some more topic objects corresponding to the individual topics
+         //we're going to send messages to
+         Topic topicNewsUsaWrestling = new JBossTopic("news.usa.wrestling");
+         
+         Topic topicNewsEuropeSport = new JBossTopic("news.europe.sport");
+         
+         Topic topicNewsEuropeEntertainment = new JBossTopic("news.europe.entertainment");
+        
+         //Step 10. Send a message destined for the usa wrestling topic
+         TextMessage messageWrestlingNews = session.createTextMessage("Hulk Hogan starts ballet classes");
+         
+         producer.send(topicNewsUsaWrestling, messageWrestlingNews);
+         
+         //Step 11. Send a message destined for the europe sport topic
+         TextMessage messageEuropeSport = session.createTextMessage("Lewis Hamilton joins European synchronized swimming team");
+         
+         producer.send(topicNewsEuropeSport, messageEuropeSport);
+         
+         //Step 12. Send a message destined for the europe entertainment topic
+         TextMessage messageEuropeEntertainment = session.createTextMessage("John Lennon resurrected from dead");
+         
+         producer.send(topicNewsEuropeEntertainment, messageEuropeEntertainment);
+         
+         //Step 9. Start the connection
+         
+         connection.start();
+         
+         //Step 10. We don't receive the usa wrestling message since we subscribed to news.europe.# and
+         //that doesn't match news.usa.wrestling. However we do receive the Europe sport message, and the
+         //europe entertainment message, since these match the wildcard.
+                           
+         TextMessage messageReceived1 = (TextMessage)messageConsumer.receive(5000);
+         
+         System.out.println("Received message: " + messageReceived1.getText());
+         
+         TextMessage messageReceived2 = (TextMessage)messageConsumer.receive(5000);
+         
+         System.out.println("Received message: " + messageReceived2.getText());
+         
+         Message message = messageConsumer.receive(1000);
+         
+         if (message != null)
+         {
+            return false;
+         }
+         
+         System.out.println("Didn't received any more message: " + message);
+
+         return true;
+      }
+      finally
+      {
+         //Step 12. Be sure to close our resources!
+         if (initialContext != null)
+         {
+            initialContext.close();
+         }
+         if(connection != null)
+         {
+            connection.close();
+         }
+      }
+   }
+
+}

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/AddressManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/AddressManager.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/AddressManager.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -38,7 +38,9 @@
 
    Binding removeBinding(SimpleString uniqueName);
 
-   Bindings getBindings(SimpleString address);
+   Bindings getBindingsForRoutingAddress(SimpleString address);
+   
+   Bindings getMatchingBindings(SimpleString address);
 
    void clear();
 

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -58,6 +58,8 @@
    Bindings getBindingsForAddress(SimpleString address) throws Exception;
 
    Binding getBinding(SimpleString uniqueName);
+   
+   Bindings getMatchingBindings(SimpleString address);
 
    void route(ServerMessage message) throws Exception;
    

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -531,7 +531,7 @@
       {
          managementService.unregisterQueue(uniqueName, binding.getAddress());
 
-         if (addressManager.getBindings(binding.getAddress()) == null)
+         if (addressManager.getBindingsForRoutingAddress(binding.getAddress()) == null)
          {
             managementService.unregisterAddress(binding.getAddress());
          }
@@ -540,7 +540,7 @@
       {
          managementService.unregisterDivert(uniqueName);
 
-         if (addressManager.getBindings(binding.getAddress()) == null)
+         if (addressManager.getBindingsForRoutingAddress(binding.getAddress()) == null)
          {
             managementService.unregisterAddress(binding.getAddress());
          }
@@ -565,7 +565,7 @@
 
    public Bindings getBindingsForAddress(final SimpleString address)
    {
-      Bindings bindings = addressManager.getBindings(address);
+      Bindings bindings = addressManager.getBindingsForRoutingAddress(address);
 
       if (bindings == null)
       {
@@ -579,6 +579,11 @@
    {
       return addressManager.getBinding(name);
    }
+   
+   public Bindings getMatchingBindings(final SimpleString address)
+   {
+      return addressManager.getMatchingBindings(address);
+   }
 
    public void route(final ServerMessage message, Transaction tx) throws Exception
    {
@@ -646,7 +651,7 @@
          }
       }
 
-      Bindings bindings = addressManager.getBindings(address);
+      Bindings bindings = addressManager.getBindingsForRoutingAddress(address);
 
       if (bindings != null)
       {
@@ -666,7 +671,7 @@
 
    public boolean redistribute(final ServerMessage message, final SimpleString routingName, final Transaction tx) throws Exception
    {
-      Bindings bindings = addressManager.getBindings(message.getDestination());
+      Bindings bindings = addressManager.getBindingsForRoutingAddress(message.getDestination());
 
       if (bindings != null)
       {

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/SimpleAddressManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/SimpleAddressManager.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/SimpleAddressManager.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -26,6 +26,7 @@
 import java.util.concurrent.ConcurrentMap;
 
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.postoffice.Address;
 import org.jboss.messaging.core.postoffice.AddressManager;
 import org.jboss.messaging.core.postoffice.Binding;
 import org.jboss.messaging.core.postoffice.Bindings;
@@ -72,7 +73,7 @@
       return binding;
    }
 
-   public Bindings getBindings(final SimpleString address)
+   public Bindings getBindingsForRoutingAddress(final SimpleString address)
    {
       return mappings.get(address);
    }
@@ -86,7 +87,27 @@
    {
       return nameMap;
    }
-
+   
+   public Bindings getMatchingBindings(final SimpleString address)
+   {
+      Address add = new AddressImpl(address);
+      
+      Bindings bindings = new BindingsImpl();
+      
+      for (Binding binding: nameMap.values())
+      {
+         Address addCheck = new AddressImpl(binding.getAddress());
+         
+         if (addCheck.matches(add))
+         {
+            bindings.addBinding(binding);
+         }
+      }
+      
+      return bindings;
+   }
+   
+   
    public void clear()
    {
       nameMap.clear();

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -23,8 +23,10 @@
 
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.postoffice.Address;
@@ -59,9 +61,10 @@
 
    private final Map<SimpleString, Address> wildCardAddresses = new HashMap<SimpleString, Address>();
 
-   public Bindings getBindings(final SimpleString address)
+   public Bindings getBindingsForRoutingAddress(final SimpleString address)
    {
-      Bindings bindings = super.getBindings(address);
+      Bindings bindings = super.getBindingsForRoutingAddress(address);
+      
       //this should only happen if we're routing to an address that has no mappings when we're running checkAllowable
       if (bindings == null && !wildCardAddresses.isEmpty())
       {
@@ -70,7 +73,7 @@
          {
             for (Address destAdd : add.getLinkedAddresses())
             {
-               Bindings b = super.getBindings(destAdd.getAddress());
+               Bindings b = super.getBindingsForRoutingAddress(destAdd.getAddress());
                if (b != null)
                {
                   Collection<Binding> theBindings = b.getBindings();
@@ -81,11 +84,11 @@
                }
             }
          }
-         bindings = super.getBindings(address);
+         bindings = super.getBindingsForRoutingAddress(address);
       }
       return bindings;
    }
-
+      
    /**
     * If the address to add the binding to contains a wildcard then a copy of the binding (with the same underlying queue)
     * will be added to the actual mappings. Otherwise the binding is added as normal.
@@ -110,7 +113,7 @@
          {
             for (Address destAdd : add.getLinkedAddresses())
             {
-               Bindings bindings = super.getBindings(destAdd.getAddress());
+               Bindings bindings = super.getBindingsForRoutingAddress(destAdd.getAddress());
                for (Binding b : bindings.getBindings())
                {
                   super.addMappingInternal(binding.getAddress(), b);
@@ -139,7 +142,7 @@
          {
             for (Address destination : add.getLinkedAddresses())
             {
-               Bindings bindings = super.getBindings(destination.getAddress());
+               Bindings bindings = super.getBindingsForRoutingAddress(destination.getAddress());
                if (bindings != null)
                {
                   for (Binding b : bindings.getBindings())
@@ -241,14 +244,14 @@
    private synchronized void removeAndUpdateAddressMap(final Address address)
    {
       //we only remove if there are no bindings left
-      Bindings bindings = super.getBindings(address.getAddress());
+      Bindings bindings = super.getBindingsForRoutingAddress(address.getAddress());
       if (bindings == null || bindings.getBindings().size() == 0)
       {
          List<Address> addresses = address.getLinkedAddresses();
          for (Address address1 : addresses)
          {
             address1.removeLinkedAddress(address);
-            Bindings linkedBindings = super.getBindings(address1.getAddress());
+            Bindings linkedBindings = super.getBindingsForRoutingAddress(address1.getAddress());
             if (linkedBindings == null || linkedBindings.getBindings().size() == 0)
             {
                removeAddress(address1);

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -1120,7 +1120,7 @@
             {
                storageManager.addQueueBinding(queueBinding);
             }
-         }
+         }         
       }
    }
 

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -1474,7 +1474,12 @@
 
          List<SimpleString> names = new ArrayList<SimpleString>();
 
-         Bindings bindings = postOffice.getBindingsForAddress(address);
+         Bindings bindings = postOffice.getMatchingBindings(address);
+         
+         for (Binding binding: bindings.getBindings())
+         {
+            log.info("Got binding " + binding.getAddress() + " : " + binding.getUniqueName());
+         }
 
          for (Binding binding : bindings.getBindings())
          {

Deleted: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -1,142 +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.messaging.tests.performance.persistence;
-
-import org.jboss.messaging.core.filter.Filter;
-import org.jboss.messaging.core.postoffice.Binding;
-import org.jboss.messaging.core.postoffice.BindingType;
-import org.jboss.messaging.core.server.Bindable;
-import org.jboss.messaging.core.server.ServerMessage;
-import org.jboss.messaging.utils.SimpleString;
-
-/**
- * 
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-public class FakeBinding implements Binding
-{
-   
-   public SimpleString getClusterName()
-   {
-     
-      return null;
-   }
-
-   public BindingType getType()
-   {
-     
-      return null;
-   }
-
-   public int getDistance()
-   {
-     
-      return 0;
-   }
-
-   public SimpleString getOriginatingNodeID()
-   {
-     
-      return null;
-   }
-
-   public Filter getFilter()
-   {
-     
-      return null;
-   }
-
-   public int getID()
-   {
-     
-      return 0;
-   }
-
-   public void setID(int id)
-   {
-     
-      
-   }
-
-   public void willRoute(ServerMessage message)
-   {
-     
-      
-   }
-
-   public boolean filterMatches(ServerMessage message) throws Exception
-   {
-     
-      return false;
-   }
-
-   public boolean isHighAcceptPriority(ServerMessage message)
-   {
-     
-      return false;
-   }
-
-   public SimpleString getRoutingName()
-   {
-     
-      return null;
-   }
-
-   public SimpleString getUniqueName()
-   {
-     
-      return null;
-   }
-
-   public boolean isExclusive()
-   {
-     
-      return false;
-   }
-
-   private SimpleString address;
-
-   private Bindable bindable;
-
-   public FakeBinding(final SimpleString address, final Bindable bindable)
-   {
-      this.address = address;
-      this.bindable = bindable;
-   }
-   
-   public SimpleString getAddress()
-   {
-      return address;
-   }
-
-   public Bindable getBindable()
-   {
-      return bindable;
-   }
-
-   public boolean isQueueBinding()
-   {
-      return true;
-   }
-}

Deleted: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -1,161 +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.messaging.tests.performance.persistence;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.messaging.core.paging.PagingManager;
-import org.jboss.messaging.core.postoffice.Binding;
-import org.jboss.messaging.core.postoffice.Bindings;
-import org.jboss.messaging.core.postoffice.DuplicateIDCache;
-import org.jboss.messaging.core.postoffice.PostOffice;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.ServerMessage;
-import org.jboss.messaging.core.transaction.Transaction;
-import org.jboss.messaging.utils.ConcurrentHashSet;
-import org.jboss.messaging.utils.SimpleString;
-
-/**
- *
- * A FakePostOffice
- *
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- *
- */
-public class FakePostOffice implements PostOffice
-{
-   public boolean redistribute(ServerMessage message, SimpleString routingName, Transaction tx) throws Exception
-   {
-     
-      return false;
-   }
-
-   public void sendQueueInfoToQueue(SimpleString queueName, SimpleString address) throws Exception
-   {
-     
-      
-   }
-
-   private ConcurrentHashMap<SimpleString, Binding> bindings = new ConcurrentHashMap<SimpleString, Binding>();
-
-   private org.jboss.messaging.utils.ConcurrentHashSet<SimpleString> addresses = new ConcurrentHashSet<SimpleString>();
-
-   private volatile boolean started;
-
-   public void addBinding(Binding binding) throws Exception
-   {
-      bindings.put(binding.getAddress(), binding);
-   }
-
-   public void route(ServerMessage message, Transaction tx) throws Exception
-   {
-   }
-
-   public void route(ServerMessage message) throws Exception
-   {
-   }
-
-   public boolean addDestination(SimpleString address, boolean temporary) throws Exception
-   {
-      return addresses.addIfAbsent(address);
-   }
-
-   public boolean containsDestination(SimpleString address)
-   {
-      return addresses.contains(address);
-   }
-
-   public Binding getBinding(SimpleString queueName)
-   {
-      return bindings.get(queueName);
-   }
-
-   public Bindings getBindingsForAddress(SimpleString address) throws Exception
-   {
-      return null;
-   }
-
-   public List<Queue> getQueues()
-   {
-      return null;
-   }
-
-   public Map<SimpleString, List<Binding>> getMappings()
-   {
-      return null;
-   }
-
-   public Set<SimpleString> listAllDestinations()
-   {
-      return null;
-   }
-
-   public Binding removeBinding(SimpleString queueName) throws Exception
-   {
-      return null;
-   }
-
-   public boolean removeDestination(SimpleString address, boolean temporary) throws Exception
-   {
-      return false;
-   }
-
-   public void start() throws Exception
-   {
-      started = true;
-   }
-
-   public void stop() throws Exception
-   {
-      started = false;
-   }
-
-   public boolean isStarted()
-   {
-      return started;
-   }
-
-   public List<Queue> activate()
-   {
-      return null;
-   }
-
-   public PagingManager getPagingManager()
-   {
-      return null;
-   }
-
-   public DuplicateIDCache getDuplicateIDCache(SimpleString address)
-   {
-      return null;
-   }
-
-   public void sendQueueInfoToQueue(SimpleString queueName) throws Exception
-   {
-   }
-
-   
-}

Modified: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/StorageManagerTimingTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/StorageManagerTimingTest.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/StorageManagerTimingTest.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -28,7 +28,6 @@
 
 import org.jboss.messaging.core.asyncio.impl.AsynchronousFileImpl;
 import org.jboss.messaging.core.buffers.ChannelBuffers;
-import org.jboss.messaging.core.buffers.HeapChannelBuffer;
 import org.jboss.messaging.core.config.impl.FileConfiguration;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.persistence.impl.journal.JournalStorageManager;

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java	2009-04-17 16:44:58 UTC (rev 6481)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/paging/impl/PagingStoreImplTest.java	2009-04-17 17:34:02 UTC (rev 6482)
@@ -1169,6 +1169,12 @@
    class FakePostOffice implements PostOffice
    {
 
+      public Bindings getMatchingBindings(SimpleString address)
+      {
+         // TODO Auto-generated method stub
+         return null;
+      }
+
       /* (non-Javadoc)
        * @see org.jboss.messaging.core.postoffice.PostOffice#activate()
        */




More information about the jboss-cvs-commits mailing list