[jboss-cvs] JBoss Messaging SVN: r6821 - in branches/Branch_1_4: docs/examples and 24 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat May 16 09:23:50 EDT 2009


Author: gaohoward
Date: 2009-05-16 09:23:49 -0400 (Sat, 16 May 2009)
New Revision: 6821

Added:
   branches/Branch_1_4/docs/examples/ordering-group/
   branches/Branch_1_4/docs/examples/ordering-group/README.html
   branches/Branch_1_4/docs/examples/ordering-group/build.xml
   branches/Branch_1_4/docs/examples/ordering-group/etc/
   branches/Branch_1_4/docs/examples/ordering-group/etc/jndi.properties
   branches/Branch_1_4/docs/examples/ordering-group/etc/log4j.xml
   branches/Branch_1_4/docs/examples/ordering-group/src/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/ConsumerThread.java
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/OrderingGroup.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/OrderingGroupMonitor.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupAckTest.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupConnectionConsumerTest.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupGeneralTest.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/message/JMSOrderingGroupPropertyTest.java
Removed:
   branches/Branch_1_4/docs/examples/ordering-group/README.html
   branches/Branch_1_4/docs/examples/ordering-group/build.xml
   branches/Branch_1_4/docs/examples/ordering-group/etc/
   branches/Branch_1_4/docs/examples/ordering-group/etc/jndi.properties
   branches/Branch_1_4/docs/examples/ordering-group/etc/log4j.xml
   branches/Branch_1_4/docs/examples/ordering-group/src/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/ConsumerThread.java
   branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java
Modified:
   branches/Branch_1_4/.classpath
   branches/Branch_1_4/integration/EAP4/.classpath
   branches/Branch_1_4/integration/EAP4/etc/aop-messaging-client.xml
   branches/Branch_1_4/integration/EAP4/etc/xmdesc/ConnectionFactory-xmbean.xml
   branches/Branch_1_4/src/main/org/jboss/jms/client/JBossMessageProducer.java
   branches/Branch_1_4/src/main/org/jboss/jms/client/container/ProducerAspect.java
   branches/Branch_1_4/src/main/org/jboss/jms/client/container/StateCreationAspect.java
   branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
   branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java
   branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java
   branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java
   branches/Branch_1_4/src/main/org/jboss/jms/client/state/ConnectionState.java
   branches/Branch_1_4/src/main/org/jboss/jms/client/state/ProducerState.java
   branches/Branch_1_4/src/main/org/jboss/jms/client/state/SessionState.java
   branches/Branch_1_4/src/main/org/jboss/jms/delegate/ProducerDelegate.java
   branches/Branch_1_4/src/main/org/jboss/jms/message/JBossMessage.java
   branches/Branch_1_4/src/main/org/jboss/jms/server/ConnectionFactoryManager.java
   branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java
   branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/ChannelSupport.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/PagingChannelSupport.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeManagementTest.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/ConnectionConsumerTest.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java
Log:
JBMESSAGING-1416


Modified: branches/Branch_1_4/.classpath
===================================================================
--- branches/Branch_1_4/.classpath	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/.classpath	2009-05-16 13:23:49 UTC (rev 6821)
@@ -15,6 +15,7 @@
 	<classpathentry kind="src" path="docs/examples/ejb3mdb/src"/>
 	<classpathentry kind="src" path="docs/examples/http/src"/>
 	<classpathentry kind="src" path="docs/examples/mdb/src"/>
+	<classpathentry kind="src" path="docs/examples/ordering-group/src"/>
 	<classpathentry kind="src" path="docs/examples/queue/src"/>
 	<classpathentry kind="src" path="docs/examples/secure-socket/src"/>
 	<classpathentry kind="src" path="docs/examples/stateless/src"/>

Copied: branches/Branch_1_4/docs/examples/ordering-group (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group)


Property changes on: branches/Branch_1_4/docs/examples/ordering-group
___________________________________________________________________
Name: svn:mergeinfo
   + 

Deleted: branches/Branch_1_4/docs/examples/ordering-group/README.html
===================================================================
--- branches/Branch_1416_merge/docs/examples/ordering-group/README.html	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/docs/examples/ordering-group/README.html	2009-05-16 13:23:49 UTC (rev 6821)
@@ -1,138 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<html>
-<head>
-  <meta content="text/html; charset=ISO-8859-1"
- http-equiv="content-type">
-  <title>JBoss Messaging Example - Ordering Group</title>
-</head>
-<body>
-<br>
-<h1>JBoss Messaging Ordering Group Example</h1>
-
-$Revision: 2750 $
-
-<h2>Overview</h2>
-
-<br>
-
-This example creates a JMS Connection to a JBoss Messaging instance and uses it to create a
-session and two message producers, one normal producer called 'producer1', the other producer
-called 'producer' is used to produce ordering group messages. Then both producers send 5 messages
-(producer1 sending 2 and producer 3) to "queue/testQueue". The example then starts two consumer 
-threads to receive these messages. Once the messages are all received, it check the results.<br>
-<br>
-This example illustrates that ordering group messages will be delivered exactly in the same
-order as they are sent, even if the messages has different priorities and are consumed by
-multiple consumers at the same time.
-<br>
-This example relies on having access to a running JBoss Messaging
-instance.
-The JBoss Messaging instance must be installed and started according to
-the
-"Installation" paragraph from the release documentation. However, the
-example will automatically deploy its own queue, unless a queue with
-the same name is already deployed. <br>
-<br>
-This example also relies on having access to <span
- style="font-family: monospace;">jboss-messaging-client.jar</span>
-archive that comes with the release bundle. If you run this example
-from an unzipped installation bundle, the example run script is
-correctly configured to find the client jar. Otherwise, you must modify
-example's <span style="font-family: monospace;">build.xml</span>
-accordingly.<br>
-<br>
-<span style="font-style: italic;"></span>
-<h2>Running the example</h2>
-1. Set up the JBOSS_HOME environment variable to point to the JBoss
-instance you deployed JBoss Messaging into. For example, if you
-deployed JBoss Messaging in <span style="font-family: monospace;">C:\jboss-4.2.0.GA\server\messaging\deploy,</span>
-then your JBOSS_HOME value should be <span
- style="font-family: monospace;">C:\</span><span
- style="font-family: monospace;">jboss-4.2.0.GA</span><br>
-<span style="font-family: monospace;"></span><span
- style="font-family: monospace;"></span><br>
-2. Go to the example's home directory<br>
-<br>
-<div style="margin-left: 40px;"><span style="font-family: monospace;">cd
-...\examples\queue</span><br>
-</div>
-<br>
-3. Run the example:<br>
-<br>
-<div style="margin-left: 40px;"><span style="font-family: monospace;">ant</span>
-<br>
-<br>
-<br>
-</div>
-The output of a successful run should be similar to:<br>
-<div style="margin-left: 40px;"><br>
-</div>
-<table
- style="width: 90%; text-align: left; font-family: monospace; background-color: rgb(204, 204, 204); margin-left: 40px;"
- border="1" cellpadding="2" cellspacing="2">
-  <tbody>
-    <tr>
-      <td style="vertical-align: top;">
-<pre>
-Buildfile: build.xml
-
-identify:
-     [echo] ###########################################################################
-     [echo] #                       Running the ORDERING-GROUP example                         #
-     [echo] ###########################################################################
-     [echo] The queue:      testQueue
-     [echo] The client jar: ../../../output/lib/jboss-messaging-client.jar
-
-sanity-check:
-
-init:
-    [mkdir] Created dir: C:\java\messaging\docs\examples\queue\output\classes
-    [mkdir] Created dir: C:\java\messaging\docs\examples\common\output\classes
-
-compile:
-    [javac] Compiling 5 source files to C:\java\messaging\docs\examples\common\output\classes
-    [javac] Compiling 1 source file to C:\java\messaging\docs\examples\queue\output\classes
-
-run:
-     [java] Queue /queue/testQueue exists
-     [java] The message was successfully sent to the testQueue queue
-     [java] Received message: Hello!
-     [java] The example connected to JBoss Messaging version 1.3.0.GA (1.3)
-     [java] 
-     [java] #####################
-     [java] ###    SUCCESS!   ###
-     [java] #####################
-
-BUILD SUCCESSFUL
-Total time: 4 seconds
-</pre>
-      </td>
-    </tr>
-  </tbody>
-</table>
-<div style="margin-left: 40px;"><br>
-</div>
-<br>
-<br>
-<h2>Troublesooting</h2>
-<h3>1. I get <span style="font-family: monospace;">"javax.jms.JMSSecurityException:
-User null is NOT authenticated" <br>
-</span></h3>
-You probably didn't install JBoss Messaging correctly. A fresh JBoss
-Messaging installation requires changes in the security configuration
-of a <span style="font-family: monospace;">default </span>JBoss
-instance, specifically a properly configured "<small><span
- style="font-family: courier new,courier,monospace;">messaging</span></small>"
-security domain.&nbsp; Follow the instructions from the "Installation"
-paragraph of the release documentation. <br>
-<br>
-<br>
-<hr style="width: 100%; height: 2px;"><br>
-<br>
-<br>
-<br>
-<br>
-<br>
-<br>
-</body>
-</html>

Copied: branches/Branch_1_4/docs/examples/ordering-group/README.html (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/README.html)
===================================================================
--- branches/Branch_1_4/docs/examples/ordering-group/README.html	                        (rev 0)
+++ branches/Branch_1_4/docs/examples/ordering-group/README.html	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,138 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <meta content="text/html; charset=ISO-8859-1"
+ http-equiv="content-type">
+  <title>JBoss Messaging Example - Ordering Group</title>
+</head>
+<body>
+<br>
+<h1>JBoss Messaging Ordering Group Example</h1>
+
+$Revision: 2750 $
+
+<h2>Overview</h2>
+
+<br>
+
+This example creates a JMS Connection to a JBoss Messaging instance and uses it to create a
+session and two message producers, one normal producer called 'producer1', the other producer
+called 'producer' is used to produce ordering group messages. Then both producers send 5 messages
+(producer1 sending 2 and producer 3) to "queue/testQueue". The example then starts two consumer 
+threads to receive these messages. Once the messages are all received, it check the results.<br>
+<br>
+This example illustrates that ordering group messages will be delivered exactly in the same
+order as they are sent, even if the messages has different priorities and are consumed by
+multiple consumers at the same time.
+<br>
+This example relies on having access to a running JBoss Messaging
+instance.
+The JBoss Messaging instance must be installed and started according to
+the
+"Installation" paragraph from the release documentation. However, the
+example will automatically deploy its own queue, unless a queue with
+the same name is already deployed. <br>
+<br>
+This example also relies on having access to <span
+ style="font-family: monospace;">jboss-messaging-client.jar</span>
+archive that comes with the release bundle. If you run this example
+from an unzipped installation bundle, the example run script is
+correctly configured to find the client jar. Otherwise, you must modify
+example's <span style="font-family: monospace;">build.xml</span>
+accordingly.<br>
+<br>
+<span style="font-style: italic;"></span>
+<h2>Running the example</h2>
+1. Set up the JBOSS_HOME environment variable to point to the JBoss
+instance you deployed JBoss Messaging into. For example, if you
+deployed JBoss Messaging in <span style="font-family: monospace;">C:\jboss-4.2.0.GA\server\messaging\deploy,</span>
+then your JBOSS_HOME value should be <span
+ style="font-family: monospace;">C:\</span><span
+ style="font-family: monospace;">jboss-4.2.0.GA</span><br>
+<span style="font-family: monospace;"></span><span
+ style="font-family: monospace;"></span><br>
+2. Go to the example's home directory<br>
+<br>
+<div style="margin-left: 40px;"><span style="font-family: monospace;">cd
+...\examples\queue</span><br>
+</div>
+<br>
+3. Run the example:<br>
+<br>
+<div style="margin-left: 40px;"><span style="font-family: monospace;">ant</span>
+<br>
+<br>
+<br>
+</div>
+The output of a successful run should be similar to:<br>
+<div style="margin-left: 40px;"><br>
+</div>
+<table
+ style="width: 90%; text-align: left; font-family: monospace; background-color: rgb(204, 204, 204); margin-left: 40px;"
+ border="1" cellpadding="2" cellspacing="2">
+  <tbody>
+    <tr>
+      <td style="vertical-align: top;">
+<pre>
+Buildfile: build.xml
+
+identify:
+     [echo] ###########################################################################
+     [echo] #                       Running the ORDERING-GROUP example                         #
+     [echo] ###########################################################################
+     [echo] The queue:      testQueue
+     [echo] The client jar: ../../../output/lib/jboss-messaging-client.jar
+
+sanity-check:
+
+init:
+    [mkdir] Created dir: C:\java\messaging\docs\examples\queue\output\classes
+    [mkdir] Created dir: C:\java\messaging\docs\examples\common\output\classes
+
+compile:
+    [javac] Compiling 5 source files to C:\java\messaging\docs\examples\common\output\classes
+    [javac] Compiling 1 source file to C:\java\messaging\docs\examples\queue\output\classes
+
+run:
+     [java] Queue /queue/testQueue exists
+     [java] The message was successfully sent to the testQueue queue
+     [java] Received message: Hello!
+     [java] The example connected to JBoss Messaging version 1.3.0.GA (1.3)
+     [java] 
+     [java] #####################
+     [java] ###    SUCCESS!   ###
+     [java] #####################
+
+BUILD SUCCESSFUL
+Total time: 4 seconds
+</pre>
+      </td>
+    </tr>
+  </tbody>
+</table>
+<div style="margin-left: 40px;"><br>
+</div>
+<br>
+<br>
+<h2>Troublesooting</h2>
+<h3>1. I get <span style="font-family: monospace;">"javax.jms.JMSSecurityException:
+User null is NOT authenticated" <br>
+</span></h3>
+You probably didn't install JBoss Messaging correctly. A fresh JBoss
+Messaging installation requires changes in the security configuration
+of a <span style="font-family: monospace;">default </span>JBoss
+instance, specifically a properly configured "<small><span
+ style="font-family: courier new,courier,monospace;">messaging</span></small>"
+security domain.&nbsp; Follow the instructions from the "Installation"
+paragraph of the release documentation. <br>
+<br>
+<br>
+<hr style="width: 100%; height: 2px;"><br>
+<br>
+<br>
+<br>
+<br>
+<br>
+<br>
+</body>
+</html>

Deleted: branches/Branch_1_4/docs/examples/ordering-group/build.xml
===================================================================
--- branches/Branch_1416_merge/docs/examples/ordering-group/build.xml	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/docs/examples/ordering-group/build.xml	2009-05-16 13:23:49 UTC (rev 6821)
@@ -1,96 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-
-   To run the example, set JBOSS_HOME and run ant (with no parameters)
-
-   $Id: build.xml 3140 2007-09-26 08:44:19Z ataylor $
-
- -->
-
-<project name="OrderingGroupExample" default="run">
-
-   <property environment="ENV"/>
-
-   <!-- These properties may be overriden by calling ants when this example is used in a smoke test -->
-   <property file="../examples.properties"/>
-   <property name="messaging.client.jar.path" value="../../"/>
-   <property name="messaging.client.jar.name" value="jboss-messaging-client.jar"/>
-   <property name="jboss.home" value="${ENV.JBOSS_HOME}"/>
-   <property name="jboss.configuration" value="messaging"/>
-   <property name="example.queue.name" value="testQueue"/>
-
-   <path id="common.compilation.classpath">
-      <fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
-      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
-   </path>
-
-   <path id="example.compilation.classpath">
-      <path refid="common.compilation.classpath"/>
-      <pathelement path="../common/output/classes"/>
-   </path>
-
-   <path id="execution.classpath">
-      <pathelement path="./etc"/>
-      <pathelement path="../common/output/classes"/>
-      <pathelement path="./output/classes"/>
-      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
-      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/jboss-remoting.jar"/>
-      <fileset file="${jboss.home}/client/jbossall-client.jar"/>
-      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/log4j.jar"/>
-      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/javassist.jar"/>
-      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/jboss-aop-jdk50.jar"/>
-      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/trove.jar"/>
-   </path>
-
-   <target name="identify">
-      <echo message="###########################################################################"/>
-      <echo message="#                  Running the OrderingGroup example                      #"/>
-      <echo message="###########################################################################"/>
-      <echo message="The queue:      ${example.queue.name}"/>
-      <echo message="The client jar: ${messaging.client.jar.path}/${messaging.client.jar.name}"/>
-   </target>
-
-   <target name="sanity-check" depends="identify">
-      <available property="client.jar.present" file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
-      <fail message="Could not find client jar ${messaging.client.jar.path}/${messaging.client.jar.name}"
-            unless="client.jar.present"/>
-   </target>
-
-   <target name="init" depends="sanity-check">
-      <mkdir dir="./output/classes"/>
-      <mkdir dir="../common/output/classes"/>
-   </target>
-
-   <target name="compile" depends="init">
-      <javac destdir="../common/output/classes" debug="on" debuglevel="lines,vars,source">
-         <src path="../common/src"/>
-         <classpath refid="common.compilation.classpath"/>
-      </javac>
-      <javac destdir="./output/classes" debug="on" debuglevel="lines,vars,source">
-         <src path="./src"/>
-         <classpath refid="example.compilation.classpath"/>
-      </javac>
-   </target>
-
-   <target name="run" depends="compile">
-      <!-- QueueExample expects to find the name of the queue to connect to as value of the
-           'example.queue.name' property, which *may* be defined by calling ants when this example
-            is used in a smoke test -->
-      <java classname="org.jboss.example.jms.ordering.OrderingGroupExample"
-            classpathref="execution.classpath" fork="yes" failonerror="true">
-         <sysproperty key="example.queue.name" value="${example.queue.name}"/>
-         <sysproperty key="com.sun.management.jmxremote" value=""/>
-         <!--
-         <jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=example"/>
-         -->
-      </java>
-   </target>
-
-   <target name="clean">
-      <delete dir="./output" quiet="true"/>
-      <delete dir="../common/output" quiet="true"/>
-   </target>
-
-</project>
-

Copied: branches/Branch_1_4/docs/examples/ordering-group/build.xml (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/build.xml)
===================================================================
--- branches/Branch_1_4/docs/examples/ordering-group/build.xml	                        (rev 0)
+++ branches/Branch_1_4/docs/examples/ordering-group/build.xml	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+   To run the example, set JBOSS_HOME and run ant (with no parameters)
+
+   $Id: build.xml 3140 2007-09-26 08:44:19Z ataylor $
+
+ -->
+
+<project name="OrderingGroupExample" default="run">
+
+   <property environment="ENV"/>
+
+   <!-- These properties may be overriden by calling ants when this example is used in a smoke test -->
+   <property file="../examples.properties"/>
+   <property name="messaging.client.jar.path" value="../../"/>
+   <property name="messaging.client.jar.name" value="jboss-messaging-client.jar"/>
+   <property name="jboss.home" value="${ENV.JBOSS_HOME}"/>
+   <property name="jboss.configuration" value="messaging"/>
+   <property name="example.queue.name" value="testQueue"/>
+
+   <path id="common.compilation.classpath">
+      <fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+   </path>
+
+   <path id="example.compilation.classpath">
+      <path refid="common.compilation.classpath"/>
+      <pathelement path="../common/output/classes"/>
+   </path>
+
+   <path id="execution.classpath">
+      <pathelement path="./etc"/>
+      <pathelement path="../common/output/classes"/>
+      <pathelement path="./output/classes"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/jboss-remoting.jar"/>
+      <fileset file="${jboss.home}/client/jbossall-client.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/log4j.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/javassist.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/jboss-aop-jdk50.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/trove.jar"/>
+   </path>
+
+   <target name="identify">
+      <echo message="###########################################################################"/>
+      <echo message="#                  Running the OrderingGroup example                      #"/>
+      <echo message="###########################################################################"/>
+      <echo message="The queue:      ${example.queue.name}"/>
+      <echo message="The client jar: ${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+   </target>
+
+   <target name="sanity-check" depends="identify">
+      <available property="client.jar.present" file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+      <fail message="Could not find client jar ${messaging.client.jar.path}/${messaging.client.jar.name}"
+            unless="client.jar.present"/>
+   </target>
+
+   <target name="init" depends="sanity-check">
+      <mkdir dir="./output/classes"/>
+      <mkdir dir="../common/output/classes"/>
+   </target>
+
+   <target name="compile" depends="init">
+      <javac destdir="../common/output/classes" debug="on" debuglevel="lines,vars,source">
+         <src path="../common/src"/>
+         <classpath refid="common.compilation.classpath"/>
+      </javac>
+      <javac destdir="./output/classes" debug="on" debuglevel="lines,vars,source">
+         <src path="./src"/>
+         <classpath refid="example.compilation.classpath"/>
+      </javac>
+   </target>
+
+   <target name="run" depends="compile">
+      <!-- QueueExample expects to find the name of the queue to connect to as value of the
+           'example.queue.name' property, which *may* be defined by calling ants when this example
+            is used in a smoke test -->
+      <java classname="org.jboss.example.jms.ordering.OrderingGroupExample"
+            classpathref="execution.classpath" fork="yes" failonerror="true">
+         <sysproperty key="example.queue.name" value="${example.queue.name}"/>
+         <sysproperty key="com.sun.management.jmxremote" value=""/>
+         <!--
+         <jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=example"/>
+         -->
+      </java>
+   </target>
+
+   <target name="clean">
+      <delete dir="./output" quiet="true"/>
+      <delete dir="../common/output" quiet="true"/>
+   </target>
+
+</project>
+

Copied: branches/Branch_1_4/docs/examples/ordering-group/etc (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/etc)

Deleted: branches/Branch_1_4/docs/examples/ordering-group/etc/jndi.properties
===================================================================
--- branches/Branch_1416_merge/docs/examples/ordering-group/etc/jndi.properties	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/docs/examples/ordering-group/etc/jndi.properties	2009-05-16 13:23:49 UTC (rev 6821)
@@ -1,4 +0,0 @@
-### JBossNS properties
-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

Copied: branches/Branch_1_4/docs/examples/ordering-group/etc/jndi.properties (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/etc/jndi.properties)
===================================================================
--- branches/Branch_1_4/docs/examples/ordering-group/etc/jndi.properties	                        (rev 0)
+++ branches/Branch_1_4/docs/examples/ordering-group/etc/jndi.properties	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,4 @@
+### JBossNS properties
+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

Deleted: branches/Branch_1_4/docs/examples/ordering-group/etc/log4j.xml
===================================================================
--- branches/Branch_1416_merge/docs/examples/ordering-group/etc/log4j.xml	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/docs/examples/ordering-group/etc/log4j.xml	2009-05-16 13:23:49 UTC (rev 6821)
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
-
-<!-- $Id: log4j.xml 2318 2007-02-15 02:11:43Z ovidiu.feodorov at jboss.com $ -->
-
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
-
-   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
-      <param name="Target" value="System.out"/>
-      <param name="Threshold" value="INFO"/>
-      <layout class="org.apache.log4j.PatternLayout">
-         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p @%t [%c{1}] %m%n"/>
-      </layout>
-   </appender>
-
-  <root>
-      <appender-ref ref="CONSOLE"/>
-   </root>
-
-</log4j:configuration>

Copied: branches/Branch_1_4/docs/examples/ordering-group/etc/log4j.xml (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/etc/log4j.xml)
===================================================================
--- branches/Branch_1_4/docs/examples/ordering-group/etc/log4j.xml	                        (rev 0)
+++ branches/Branch_1_4/docs/examples/ordering-group/etc/log4j.xml	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- $Id: log4j.xml 2318 2007-02-15 02:11:43Z ovidiu.feodorov at jboss.com $ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+      <param name="Target" value="System.out"/>
+      <param name="Threshold" value="INFO"/>
+      <layout class="org.apache.log4j.PatternLayout">
+         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p @%t [%c{1}] %m%n"/>
+      </layout>
+   </appender>
+
+  <root>
+      <appender-ref ref="CONSOLE"/>
+   </root>
+
+</log4j:configuration>

Copied: branches/Branch_1_4/docs/examples/ordering-group/src (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/src)

Copied: branches/Branch_1_4/docs/examples/ordering-group/src/org (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/src/org)

Copied: branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/src/org/jboss)

Copied: branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/src/org/jboss/example)

Copied: branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/src/org/jboss/example/jms)

Copied: branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/src/org/jboss/example/jms/ordering)

Deleted: branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/ConsumerThread.java
===================================================================
--- branches/Branch_1416_merge/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/ConsumerThread.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/ConsumerThread.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -1,110 +0,0 @@
-/*
- * 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.
- */
-package org.jboss.example.jms.ordering;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import javax.jms.MessageConsumer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Destination;
-
-/**
- *
- * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
- *
- */
-public class ConsumerThread extends Thread
-{
-   private OrderingGroupExample example;
-   private Session session;
-   private MessageConsumer consumer;
-   private Connection connection;
-
-   public ConsumerThread(String name, OrderingGroupExample theExample, ConnectionFactory fact, Destination queue) throws JMSException
-   {
-      super(name);
-      example = theExample;
-      
-      connection = fact.createConnection();
-      session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-      consumer = session.createConsumer(queue);
-      connection.start();
-   }
-
-   public void delay(long nt)
-   {
-      try
-      {
-         Thread.sleep(nt);
-      }
-      catch (InterruptedException e)
-      {
-      }
-   }
-
-   //receiving the messages
-   public void run()
-   {
-      int n = example.getNumMessages();
-      try
-      {
-         while (true)
-         {
-            if (example.allReceived())
-            {
-               break;
-            }
-            TextMessage msg = (TextMessage)consumer.receive(2000);
-            if (msg != null)
-            {
-               if (msg.getText().equals(OrderingGroupExample.ORDERING_MSG1))
-               {
-                  //whoever receives first message, delay for 2 sec.
-                  delay(2000);
-               }
-               example.reportReceive(msg);
-               msg.acknowledge();
-            }
-         }
-      }
-      catch (JMSException e)
-      {
-         e.printStackTrace();
-      }
-      finally
-      {
-         if (session != null)
-         {
-            try
-            {
-               connection.close();
-            }
-            catch (JMSException e)
-            {
-            }
-         }
-      }
-   }
-   
-}

Copied: branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/ConsumerThread.java (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/ConsumerThread.java)
===================================================================
--- branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/ConsumerThread.java	                        (rev 0)
+++ branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/ConsumerThread.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+package org.jboss.example.jms.ordering;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Destination;
+
+/**
+ *
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ *
+ */
+public class ConsumerThread extends Thread
+{
+   private OrderingGroupExample example;
+   private Session session;
+   private MessageConsumer consumer;
+   private Connection connection;
+
+   public ConsumerThread(String name, OrderingGroupExample theExample, ConnectionFactory fact, Destination queue) throws JMSException
+   {
+      super(name);
+      example = theExample;
+      
+      connection = fact.createConnection();
+      session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+      consumer = session.createConsumer(queue);
+      connection.start();
+   }
+
+   public void delay(long nt)
+   {
+      try
+      {
+         Thread.sleep(nt);
+      }
+      catch (InterruptedException e)
+      {
+      }
+   }
+
+   //receiving the messages
+   public void run()
+   {
+      int n = example.getNumMessages();
+      try
+      {
+         while (true)
+         {
+            if (example.allReceived())
+            {
+               break;
+            }
+            TextMessage msg = (TextMessage)consumer.receive(2000);
+            if (msg != null)
+            {
+               if (msg.getText().equals(OrderingGroupExample.ORDERING_MSG1))
+               {
+                  //whoever receives first message, delay for 2 sec.
+                  delay(2000);
+               }
+               example.reportReceive(msg);
+               msg.acknowledge();
+            }
+         }
+      }
+      catch (JMSException e)
+      {
+         e.printStackTrace();
+      }
+      finally
+      {
+         if (session != null)
+         {
+            try
+            {
+               connection.close();
+            }
+            catch (JMSException e)
+            {
+            }
+         }
+      }
+   }
+   
+}

Deleted: branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java
===================================================================
--- branches/Branch_1416_merge/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -1,210 +0,0 @@
-/*
- * 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.
- */
-package org.jboss.example.jms.ordering;
-
-import java.util.ArrayList;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Message;
-import javax.naming.InitialContext;
-
-import org.jboss.example.jms.common.ExampleSupport;
-import org.jboss.jms.client.JBossMessageProducer;
-
-/**
- * This example creates a JMS Connection to a JBoss Messaging instance and uses it to create a
- * session and two message producers, one normal producer called 'producer1', the other producer
- * called 'producer' is used to produce ordering group messages. Then both producers send 5 messages
- * (producer1 sending 2 and producer 3) to "queue/testQueue". The example then starts two consumer 
- * threads to receive these messages. Once the messages are all received, it check the results.
- * 
- * This example illustrates that ordering group messages will be delivered exactly in the same
- * order as they are sent, even if the messages has different priorities and are consumed by
- * multiple consumers at the same time.
- *
- * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
- *
- */
-public class OrderingGroupExample extends ExampleSupport
-{
-   public static final String NORMAL_MSG = "Hello-normal";
-   public static final String NORMAL_MSG1 = "Hello-normal-1";
-   public static final String ORDERING_MSG1 = "Hello!";
-   public static final String ORDERING_MSG2 = "Hello-1!";
-   public static final String ORDERING_MSG3 = "Hello-2!";
-
-   private ArrayList<String> deliveryRecords = new ArrayList<String>();
-
-   private void checkResults() throws Exception
-   {
-      int len = deliveryRecords.size();
-      System.out.println("len: " + len);
-      assertEquals(5, len);
-
-      int n1 = deliveryRecords.indexOf(ORDERING_MSG1);
-      int n2 = deliveryRecords.indexOf(ORDERING_MSG2);
-      int n3 = deliveryRecords.indexOf(ORDERING_MSG3);
-
-      int flag = 1;
-      if ( (n1 < n2) && (n2 < n3) )
-      {
-         flag = 0;
-      }
-      assertEquals(0, flag);
-   }
-
-   public boolean allReceived()
-   {
-      synchronized(deliveryRecords)
-      {
-         return deliveryRecords.size() == 5;
-      }
-   }
-
-   public void example() throws Exception
-   {
-      String destinationName = getDestinationJNDIName();
-      
-      InitialContext ic = null;
-      ConnectionFactory cf = null;
-      Connection connection =  null;
-
-      try
-      {         
-         ic = new InitialContext();
-         
-         cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
-         Queue queue = (Queue)ic.lookup(destinationName);
-         log("Queue " + destinationName + " exists");
-         
-         connection = cf.createConnection();
-         Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
-        
-         JBossMessageProducer producer1 = (JBossMessageProducer)session.createProducer(queue);
-         TextMessage normalMsg = session.createTextMessage(NORMAL_MSG);
-         TextMessage normalMsg1 = session.createTextMessage(NORMAL_MSG1);
-
-         log("Sending mormal message with lower priority 1");
-         producer1.send(normalMsg1, Message.DEFAULT_DELIVERY_MODE, 1, Message.DEFAULT_TIME_TO_LIVE);
-
-         JBossMessageProducer producer = (JBossMessageProducer)session.createProducer(queue);
-         producer.enableOrderingGroup("MyOrderingGroup");
-         
-         TextMessage message = session.createTextMessage(ORDERING_MSG1);
-         message.setJMSPriority(0);
-         log("Sending message with priority 0");
-         producer.send(message, Message.DEFAULT_DELIVERY_MODE, 5, Message.DEFAULT_TIME_TO_LIVE);
-         
-         TextMessage message2 = session.createTextMessage(ORDERING_MSG2);
-         log("Sending message2 with priority 8");
-         producer.send(message2, Message.DEFAULT_DELIVERY_MODE, 6, Message.DEFAULT_TIME_TO_LIVE);
-
-         log("Sending normal message with priority 7");
-         producer1.send(normalMsg, Message.DEFAULT_DELIVERY_MODE, 7, Message.DEFAULT_TIME_TO_LIVE);
-         
-         TextMessage message3 = session.createTextMessage(ORDERING_MSG3);
-         log("Sending message3 with priority 5");
-         producer.send(message3, Message.DEFAULT_DELIVERY_MODE, 8, Message.DEFAULT_TIME_TO_LIVE);
-         
-         log("The message was successfully sent to the " + queue.getQueueName() + " queue");
-         
-         connection.start();
-         session.commit();
-
-         ConsumerThread client1 = new ConsumerThread("Client-1", this, cf, queue);
-         ConsumerThread client2 = new ConsumerThread("Client-2", this, cf, queue);
-
-         client1.start();
-         client2.start();
-
-         client1.join();
-         client2.join();
-
-         checkResults();
-
-         displayProviderInfo(connection.getMetaData());
-                 
-      }
-      finally
-      {         
-         if(ic != null)
-         {
-            try
-            {
-               ic.close();
-            }
-            catch(Exception e)
-            {
-               throw e;
-            }
-         }
-         
-         // ALWAYS close your connection in a finally block to avoid leaks.
-         // Closing connection also takes care of closing its related objects e.g. sessions.
-         closeConnection(connection);
-      }
-   }
-   
-   private void closeConnection(Connection con)
-   {      
-      try
-      {
-         if (con != null)
-         {
-            con.close();
-         }         
-      }
-      catch(JMSException jmse)
-      {
-         log("Could not close connection " + con +" exception was " + jmse);
-      }
-   }
-      
-   protected boolean isQueueExample()
-   {
-      return true;
-   }
-   
-   public static void main(String[] args)
-   {
-      new OrderingGroupExample().run();
-   }
-
-   public void reportReceive(TextMessage msg) throws JMSException
-   {
-      synchronized(deliveryRecords)
-      {
-         deliveryRecords.add(msg.getText());
-      }
-   }
-
-   public int getNumMessages()
-   {
-      return 5;
-   }
-      
-}

Copied: branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java (from rev 6820, branches/Branch_1416_merge/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java)
===================================================================
--- branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java	                        (rev 0)
+++ branches/Branch_1_4/docs/examples/ordering-group/src/org/jboss/example/jms/ordering/OrderingGroupExample.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,210 @@
+/*
+ * 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.
+ */
+package org.jboss.example.jms.ordering;
+
+import java.util.ArrayList;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Message;
+import javax.naming.InitialContext;
+
+import org.jboss.example.jms.common.ExampleSupport;
+import org.jboss.jms.client.JBossMessageProducer;
+
+/**
+ * This example creates a JMS Connection to a JBoss Messaging instance and uses it to create a
+ * session and two message producers, one normal producer called 'producer1', the other producer
+ * called 'producer' is used to produce ordering group messages. Then both producers send 5 messages
+ * (producer1 sending 2 and producer 3) to "queue/testQueue". The example then starts two consumer 
+ * threads to receive these messages. Once the messages are all received, it check the results.
+ * 
+ * This example illustrates that ordering group messages will be delivered exactly in the same
+ * order as they are sent, even if the messages has different priorities and are consumed by
+ * multiple consumers at the same time.
+ *
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ *
+ */
+public class OrderingGroupExample extends ExampleSupport
+{
+   public static final String NORMAL_MSG = "Hello-normal";
+   public static final String NORMAL_MSG1 = "Hello-normal-1";
+   public static final String ORDERING_MSG1 = "Hello!";
+   public static final String ORDERING_MSG2 = "Hello-1!";
+   public static final String ORDERING_MSG3 = "Hello-2!";
+
+   private ArrayList<String> deliveryRecords = new ArrayList<String>();
+
+   private void checkResults() throws Exception
+   {
+      int len = deliveryRecords.size();
+      System.out.println("len: " + len);
+      assertEquals(5, len);
+
+      int n1 = deliveryRecords.indexOf(ORDERING_MSG1);
+      int n2 = deliveryRecords.indexOf(ORDERING_MSG2);
+      int n3 = deliveryRecords.indexOf(ORDERING_MSG3);
+
+      int flag = 1;
+      if ( (n1 < n2) && (n2 < n3) )
+      {
+         flag = 0;
+      }
+      assertEquals(0, flag);
+   }
+
+   public boolean allReceived()
+   {
+      synchronized(deliveryRecords)
+      {
+         return deliveryRecords.size() == 5;
+      }
+   }
+
+   public void example() throws Exception
+   {
+      String destinationName = getDestinationJNDIName();
+      
+      InitialContext ic = null;
+      ConnectionFactory cf = null;
+      Connection connection =  null;
+
+      try
+      {         
+         ic = new InitialContext();
+         
+         cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+         Queue queue = (Queue)ic.lookup(destinationName);
+         log("Queue " + destinationName + " exists");
+         
+         connection = cf.createConnection();
+         Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+        
+         JBossMessageProducer producer1 = (JBossMessageProducer)session.createProducer(queue);
+         TextMessage normalMsg = session.createTextMessage(NORMAL_MSG);
+         TextMessage normalMsg1 = session.createTextMessage(NORMAL_MSG1);
+
+         log("Sending mormal message with lower priority 1");
+         producer1.send(normalMsg1, Message.DEFAULT_DELIVERY_MODE, 1, Message.DEFAULT_TIME_TO_LIVE);
+
+         JBossMessageProducer producer = (JBossMessageProducer)session.createProducer(queue);
+         producer.enableOrderingGroup("MyOrderingGroup");
+         
+         TextMessage message = session.createTextMessage(ORDERING_MSG1);
+         message.setJMSPriority(0);
+         log("Sending message with priority 0");
+         producer.send(message, Message.DEFAULT_DELIVERY_MODE, 5, Message.DEFAULT_TIME_TO_LIVE);
+         
+         TextMessage message2 = session.createTextMessage(ORDERING_MSG2);
+         log("Sending message2 with priority 8");
+         producer.send(message2, Message.DEFAULT_DELIVERY_MODE, 6, Message.DEFAULT_TIME_TO_LIVE);
+
+         log("Sending normal message with priority 7");
+         producer1.send(normalMsg, Message.DEFAULT_DELIVERY_MODE, 7, Message.DEFAULT_TIME_TO_LIVE);
+         
+         TextMessage message3 = session.createTextMessage(ORDERING_MSG3);
+         log("Sending message3 with priority 5");
+         producer.send(message3, Message.DEFAULT_DELIVERY_MODE, 8, Message.DEFAULT_TIME_TO_LIVE);
+         
+         log("The message was successfully sent to the " + queue.getQueueName() + " queue");
+         
+         connection.start();
+         session.commit();
+
+         ConsumerThread client1 = new ConsumerThread("Client-1", this, cf, queue);
+         ConsumerThread client2 = new ConsumerThread("Client-2", this, cf, queue);
+
+         client1.start();
+         client2.start();
+
+         client1.join();
+         client2.join();
+
+         checkResults();
+
+         displayProviderInfo(connection.getMetaData());
+                 
+      }
+      finally
+      {         
+         if(ic != null)
+         {
+            try
+            {
+               ic.close();
+            }
+            catch(Exception e)
+            {
+               throw e;
+            }
+         }
+         
+         // ALWAYS close your connection in a finally block to avoid leaks.
+         // Closing connection also takes care of closing its related objects e.g. sessions.
+         closeConnection(connection);
+      }
+   }
+   
+   private void closeConnection(Connection con)
+   {      
+      try
+      {
+         if (con != null)
+         {
+            con.close();
+         }         
+      }
+      catch(JMSException jmse)
+      {
+         log("Could not close connection " + con +" exception was " + jmse);
+      }
+   }
+      
+   protected boolean isQueueExample()
+   {
+      return true;
+   }
+   
+   public static void main(String[] args)
+   {
+      new OrderingGroupExample().run();
+   }
+
+   public void reportReceive(TextMessage msg) throws JMSException
+   {
+      synchronized(deliveryRecords)
+      {
+         deliveryRecords.add(msg.getText());
+      }
+   }
+
+   public int getNumMessages()
+   {
+      return 5;
+   }
+      
+}

Modified: branches/Branch_1_4/integration/EAP4/.classpath
===================================================================
--- branches/Branch_1_4/integration/EAP4/.classpath	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/integration/EAP4/.classpath	2009-05-16 13:23:49 UTC (rev 6821)
@@ -15,6 +15,7 @@
 	<classpathentry kind="src" path="docs/examples/ejb3mdb/src"/>
 	<classpathentry kind="src" path="docs/examples/http/src"/>
 	<classpathentry kind="src" path="docs/examples/mdb/src"/>
+	<classpathentry kind="src" path="docs/examples/ordering-group/src"/>
 	<classpathentry kind="src" path="docs/examples/queue/src"/>
 	<classpathentry kind="src" path="docs/examples/secure-socket/src"/>
 	<classpathentry kind="src" path="docs/examples/stateless/src"/>

Modified: branches/Branch_1_4/integration/EAP4/etc/aop-messaging-client.xml
===================================================================
--- branches/Branch_1_4/integration/EAP4/etc/aop-messaging-client.xml	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/integration/EAP4/etc/aop-messaging-client.xml	2009-05-16 13:23:49 UTC (rev 6821)
@@ -260,6 +260,12 @@
    <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientProducerDelegate->close())">
       <advice name="handleClose" aspect="org.jboss.jms.client.container.ProducerAspect"/>
    </bind>    
+   <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientProducerDelegate->enableOrderingGroup(..))">
+      <advice name="handleEnableOrderingGroup" aspect="org.jboss.jms.client.container.ProducerAspect"/>
+   </bind>    
+   <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientProducerDelegate->disableOrderingGroup())">
+      <advice name="handleDisableOrderingGroup" aspect="org.jboss.jms.client.container.ProducerAspect"/>
+   </bind>    
    <!-- Producers never go to the server - so no need for a failover interceptor -->   
 
    <!--

Modified: branches/Branch_1_4/integration/EAP4/etc/xmdesc/ConnectionFactory-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/EAP4/etc/xmdesc/ConnectionFactory-xmbean.xml	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/integration/EAP4/etc/xmdesc/ConnectionFactory-xmbean.xml	2009-05-16 13:23:49 UTC (rev 6821)
@@ -129,6 +129,24 @@
       <name>DisableRemotingChecks</name>
       <type>boolean</type>
    </attribute>
+   
+   <attribute access="read-write" getMethod="isDisableRemotingChecks" setMethod="setDisableRemotingChecks">
+      <description>Disable remoting connector parameter sanity checks. There is rarely a good reason to set this to true</description>
+      <name>DisableRemotingChecks</name>
+      <type>boolean</type>
+   </attribute>
+   
+   <attribute access="read-write" getMethod="isEnableOrderingGroup" setMethod="setEnableOrderingGroup">
+      <description>Enable/Disable message ordering group on connection factory. Default is false.</description>
+      <name>EnableOrderingGroup</name>
+      <type>boolean</type>
+   </attribute>
+   
+   <attribute access="read-write" getMethod="getDefaultOrderingGroupName" setMethod="setDefaultOrderingGroupName">
+      <description>The default name for message ordering group, only make sense when ordering group is enabled on the connection factory.</description>
+      <name>DefaultOrderingGroupName</name>
+      <type>java.lang.String</type>
+   </attribute>
 
    <!-- Managed operations -->
 
@@ -152,4 +170,4 @@
       <name>destroy</name>
    </operation>
 
-</mbean>
\ No newline at end of file
+</mbean>

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/JBossMessageProducer.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/JBossMessageProducer.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/JBossMessageProducer.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -40,6 +40,7 @@
 /**
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -212,6 +213,41 @@
       return (Queue)getDestination();
    }
    
+   // JBM Ordering Group Extension Implementation ---------------------------------
+
+
+   /**
+    * Lets the Producer send Ordering Group Messages.
+    * 
+    * This methods makes the producer to be able to send messages in an ordering
+    * group named by orgpName. If the ogrpName is null, the group name
+    * will be automatically generated. By default a newly created producer
+    * has this feature disabled.
+    * 
+    * Calling this method will override the group name set by previous call, if any.
+    * Users should make sure the uniqueness of the name if they supply one themselves
+    * across the JMS server domain. Auto-generated names always are guaranteed to be
+    * unique.
+    * 
+    * @param ogrpName the name of the group or null for an auto-generated name.
+    * 
+    */
+   public void enableOrderingGroup(String ogrpName) throws JMSException
+   {
+      delegate.enableOrderingGroup(ogrpName);
+   }
+   
+   /**
+    * Disables the ordering group capability of the producer.
+    * After this method is called, the producer no longer sends out
+    * ordering group messages.
+    */
+   public void disableOrderingGroup() throws JMSException
+   {
+      delegate.disableOrderingGroup();
+   }
+
+   
    // Public --------------------------------------------------------
 
    public ProducerDelegate getDelegate()

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/container/ProducerAspect.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/container/ProducerAspect.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/container/ProducerAspect.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -39,7 +39,6 @@
 import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.jms.client.state.ProducerState;
 import org.jboss.jms.client.state.SessionState;
-import org.jboss.jms.delegate.ConnectionDelegate;
 import org.jboss.jms.delegate.SessionDelegate;
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.destination.JBossTemporaryQueue;
@@ -62,6 +61,7 @@
  * Remember! PER_INSTANCE aspects are very expensive so we avoid them.
  *
  * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com>Howard Gao</a>
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -263,7 +263,14 @@
       {
          m.setJMSMessageID(messageToSend.getJMSMessageID());
       }
-            
+      
+      // Processing the ordering group message here.
+      if (producerState.isOrderingGroupEnabled())
+      {
+         String grpName = producerState.getOrderingGroupName();
+         messageToSend.setJBMOrderingGroupName(grpName);
+      }
+
       // we now invoke the send(Message) method on the session, which will eventually be fielded
       // by connection endpoint
       ((SessionDelegate)sessionState.getDelegate()).send(messageToSend, false);
@@ -385,6 +392,26 @@
       return null;
    }
    
+   public Object handleEnableOrderingGroup(Invocation invocation) throws Throwable
+   {
+      Object[] args = ((MethodInvocation)invocation).getArguments();
+      String orderingGroupName = (String)args[0];
+      
+      ProducerState state = getProducerState(invocation);
+
+      state.setOrderingGroupName(orderingGroupName);
+      state.setOrderingGroupEnabled(true);
+      
+      return null;
+   }
+   
+   public Object handleDisableOrderingGroup(Invocation invocation) throws Throwable
+   {
+      ProducerState pState = getProducerState(invocation);
+      pState.disableOrderingGroup();
+      return null;
+   }
+   
    // Class YYY overrides --------------------------------------------------------------------------
 
    // Protected ------------------------------------------------------------------------------------

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/container/StateCreationAspect.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/container/StateCreationAspect.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/container/StateCreationAspect.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -107,7 +107,8 @@
 
          ConnectionState connectionState =
             new ConnectionState(serverID, connectionDelegate,
-                                remotingConnection, versionToUse);
+                                remotingConnection, versionToUse, 
+                                connectionDelegate.isEnableOrderingGroup(), connectionDelegate.getDefaultOrderingGroupName());
 
          listener.setConnectionState(connectionState);
           
@@ -131,7 +132,8 @@
 
       SessionState sessionState =
          new SessionState(connectionState, sessionDelegate, transacted,
-                          ackMode, xa, sessionDelegate.getDupsOKBatchSize());
+                          ackMode, xa, sessionDelegate.getDupsOKBatchSize(), 
+                          connectionState.isEnableOrderingGroup(), connectionState.getDefaultOrderingGroupName());
 
       delegate.setState(sessionState);
       return delegate;
@@ -179,6 +181,11 @@
 
       ProducerState producerState = new ProducerState(sessionState, producerDelegate, dest);
 
+      if (sessionState.isEnableOrderingGroup())
+      {
+         producerState.setOrderingGroupEnabled(true);
+         producerState.setOrderingGroupName(sessionState.getDefaultOrderingGroupName());
+      }
       delegate.setState(producerState);
 
       // send an arbitrary invocation into the producer delegate, this will trigger AOP stack

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -55,6 +55,7 @@
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  *
  * @version <tt>$Revision$</tt>
  *
@@ -204,6 +205,10 @@
    private boolean supportsFailover;
    
    private boolean supportsLoadBalancing;
+   
+   private boolean enableOrderingGroup;
+   
+   private String defaultOrderingGroupName;
 
    // Constructors ---------------------------------------------------------------------------------
 
@@ -211,13 +216,15 @@
                                                    ClientConnectionFactoryDelegate[] delegates,
                                                    Map failoverMap,
                                                    LoadBalancingPolicy loadBalancingPolicy,
-                                                   boolean supportsFailover)
+                                                   boolean supportsFailover, boolean enableOrderingGroup, String defaultOrderingGroupName)
    {
       this.uniqueName = uniqueName;
       this.delegates = delegates;
       this.failoverMap = failoverMap;
       this.loadBalancingPolicy = loadBalancingPolicy;
       this.supportsFailover = supportsFailover;
+      this.setEnableOrderingGroup(enableOrderingGroup);
+      this.setDefaultOrderingGroupName(defaultOrderingGroupName);
    }
 
    // ConnectionFactoryDelegate implementation -----------------------------------------------------
@@ -383,6 +390,40 @@
    
    // Inner classes --------------------------------------------------------------------------------
 
+   /**
+    * @param enableOrderingGroup the enableOrderingGroup to set
+    */
+   public void setEnableOrderingGroup(boolean enableOrderingGroup)
+   {
+      this.enableOrderingGroup = enableOrderingGroup;
+   }
+
+   /**
+    * @return the enableOrderingGroup
+    */
+   public boolean isEnableOrderingGroup()
+   {
+      return enableOrderingGroup;
+   }
+
+
+   /**
+    * @param defaultOrderingGroupName the defaultOrderingGroupName to set
+    */
+   public void setDefaultOrderingGroupName(String defaultOrderingGroupName)
+   {
+      this.defaultOrderingGroupName = defaultOrderingGroupName;
+   }
+
+   /**
+    * @return the defaultOrderingGroupName
+    */
+   public String getDefaultOrderingGroupName()
+   {
+      return defaultOrderingGroupName;
+   }
+
+
    static FinalizerShutdownHook finalizerHook;
 
    static

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -81,6 +81,10 @@
    private transient JMSRemotingConnection remotingConnection;
 
    private transient Version versionToUse;
+   
+   private boolean enableOrderingGroup;
+   
+   private String defaultOrderingGroupName;
 
    // Static ---------------------------------------------------------------------------------------
 
@@ -339,6 +343,26 @@
       out.writeInt(serverID);
    }
 
+   public void setEnableOrderingGroup(boolean enableOrderingGroup)
+   {
+      this.enableOrderingGroup = enableOrderingGroup;
+   }
+
+   public boolean isEnableOrderingGroup()
+   {
+      return enableOrderingGroup;
+   }
+   
+   public void setDefaultOrderingGroup(String defaultOrderingGroupName2)
+   {
+      this.defaultOrderingGroupName = defaultOrderingGroupName2;
+   }
+   
+   public String getDefaultOrderingGroupName()
+   {
+      return defaultOrderingGroupName;
+   }
+
    // Package Private ------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -79,6 +79,10 @@
    
    private boolean sendAcksAsync;
    
+   private boolean enableOrderingGroup;
+   
+   private String defaultOrderingGroupName;
+   
    // Static ---------------------------------------------------------------------------------------
    
    /*
@@ -109,7 +113,7 @@
 
    public ClientConnectionFactoryDelegate(String uniqueName, String objectID, int serverID, String serverLocatorURI,
                                           Version serverVersion, boolean clientPing, boolean strictTck,
-                                          boolean sendAcksAsync)
+                                          boolean sendAcksAsync, boolean enableOrderingGroup, String defaultOrderingGroupName)
    {
       super(objectID);
 
@@ -120,6 +124,8 @@
       this.clientPing = clientPing;
       this.strictTck = strictTck;
       this.sendAcksAsync = sendAcksAsync;
+      this.setEnableOrderingGroup(enableOrderingGroup);
+      this.setDefaultOrderingGroupName(defaultOrderingGroupName);
    }
    
    public ClientConnectionFactoryDelegate()
@@ -198,6 +204,10 @@
          connectionDelegate.setRemotingConnection(remotingConnection);
          
          connectionDelegate.setVersionToUse(version);
+         
+         connectionDelegate.setEnableOrderingGroup(this.enableOrderingGroup);
+         
+         connectionDelegate.setDefaultOrderingGroup(this.defaultOrderingGroupName);
       }
       else
       {
@@ -357,6 +367,38 @@
       out.writeBoolean(sendAcksAsync);
    }
 
+   /**
+    * @param enableOrderingGroup the enableOrderingGroup to set
+    */
+   public void setEnableOrderingGroup(boolean enableOrderingGroup)
+   {
+      this.enableOrderingGroup = enableOrderingGroup;
+   }
+
+   /**
+    * @return the enableOrderingGroup
+    */
+   public boolean isEnableOrderingGroup()
+   {
+      return enableOrderingGroup;
+   }
+
+   /**
+    * @param defaultOrderingGroupName the defaultOrderingGroupName to set
+    */
+   public void setDefaultOrderingGroupName(String defaultOrderingGroupName)
+   {
+      this.defaultOrderingGroupName = defaultOrderingGroupName;
+   }
+
+   /**
+    * @return the defaultOrderingGroupName
+    */
+   public String getDefaultOrderingGroupName()
+   {
+      return defaultOrderingGroupName;
+   }
+
    // Inner Classes --------------------------------------------------------------------------------
 
 }

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -33,6 +33,7 @@
  *
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  *
  * @version <tt>$Revision$</tt>
  *
@@ -218,19 +219,30 @@
       throw new IllegalStateException("This invocation should not be handled here!");
    }
 
-   // Public ---------------------------------------------------------------------------------------
+   // JBM Ordering Group Extension ---------------------------------
 
+   public void enableOrderingGroup(String ogrpName) throws JMSException
+   {
+      throw new IllegalStateException("This invocation should not be handled here!");
+   }
+   
+   public void disableOrderingGroup() throws JMSException
+   {
+      throw new IllegalStateException("This invocation should not be handled here!");
+   }
+
    public String toString()
    {
       return "ProducerDelegate[" + System.identityHashCode(this) + ", ID=" + id + "]";
    }
+   // Public ---------------------------------------------------------------------------------------
 
    // Protected ------------------------------------------------------------------------------------
    
    // Package Private ------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------
-
+   
    // Inner Classes --------------------------------------------------------------------------------
 
 }

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/state/ConnectionState.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/state/ConnectionState.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/state/ConnectionState.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -87,12 +87,16 @@
    private ConnectionFactoryDelegate clusteredConnectionFactoryDelegate;
 
    private FailoverCommandCenter fcc;
+   
+   private boolean enableOrderingGroup;
+   
+   private String defaultOrderingGroupName;
 
    // Constructors ---------------------------------------------------------------------------------
 
    public ConnectionState(int serverID, ConnectionDelegate delegate,
                           JMSRemotingConnection remotingConnection,
-                          Version versionToUse)
+                          Version versionToUse, boolean enableOrderingGroup, String defaultOrderingGroupName)
       throws Exception
    {
       super(null, (DelegateSupport)delegate);
@@ -110,6 +114,10 @@
       this.resourceManager = ResourceManagerFactory.instance.checkOutResourceManager(serverID);
 
       this.serverID = serverID;
+      
+      this.setEnableOrderingGroup(enableOrderingGroup);
+      
+      this.setDefaultOrderingGroupName(defaultOrderingGroupName);
    }
 
    // HierarchicalState implementation -------------------------------------------------------------
@@ -285,6 +293,38 @@
       return "ConnectionState[" + ((ClientConnectionDelegate)delegate).getID() + "]";
    }
 
+   /**
+    * @param enableOrderingGroup the enableOrderingGroup to set
+    */
+   public void setEnableOrderingGroup(boolean enableOrderingGroup)
+   {
+      this.enableOrderingGroup = enableOrderingGroup;
+   }
+
+   /**
+    * @return the enableOrderingGroup
+    */
+   public boolean isEnableOrderingGroup()
+   {
+      return enableOrderingGroup;
+   }
+
+   /**
+    * @param defaultOrderingGroupName the defaultOrderingGroupName to set
+    */
+   public void setDefaultOrderingGroupName(String defaultOrderingGroupName)
+   {
+      this.defaultOrderingGroupName = defaultOrderingGroupName;
+   }
+
+   /**
+    * @return the defaultOrderingGroupName
+    */
+   public String getDefaultOrderingGroupName()
+   {
+      return defaultOrderingGroupName;
+   }
+
    // Package protected ----------------------------------------------------------------------------
 
    // Protected ------------------------------------------------------------------------------------

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/state/ProducerState.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/state/ProducerState.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/state/ProducerState.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -22,6 +22,7 @@
 package org.jboss.jms.client.state;
 
 import java.util.Collections;
+import java.util.UUID;
 
 import javax.jms.DeliveryMode;
 import javax.jms.Destination;
@@ -36,6 +37,7 @@
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodoorv</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  *
  * @version <tt>$Revision$</tt>
  *
@@ -61,6 +63,8 @@
    private SessionState parent;
    private ProducerDelegate delegate;
 
+   private boolean isOrderingGroupEnabled = false;
+   private String orderingGroupName = null;
    // Constructors ---------------------------------------------------------------------------------
 
    public ProducerState(SessionState parent, ProducerDelegate delegate, Destination dest)
@@ -166,6 +170,40 @@
       this.deliveryMode = deliveryMode;
    }
 
+   public void setOrderingGroupEnabled(boolean isOrderingGroupEnabled)
+   {
+      this.isOrderingGroupEnabled = isOrderingGroupEnabled;
+   }
+
+   public boolean isOrderingGroupEnabled()
+   {
+      return isOrderingGroupEnabled;
+   }
+
+   public void setOrderingGroupName(String ordGroupName)
+   {
+      if (ordGroupName == null)
+      {
+         ordGroupName = "JBM-ORD-GRP:" + UUID.randomUUID().toString();
+      }
+      this.orderingGroupName = ordGroupName;
+   }
+
+   public String getOrderingGroupName()
+   {
+      return orderingGroupName;
+   }
+
+   //let the session reset the ordering group
+   public void disableOrderingGroup()
+   {
+      if (isOrderingGroupEnabled)
+      {
+         setOrderingGroupEnabled(false);
+         parent.removeOrderingGroup(orderingGroupName);
+      }
+   }
+
    // Package protected ----------------------------------------------------------------------------
 
    // Protected ------------------------------------------------------------------------------------

Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/state/SessionState.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/state/SessionState.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/state/SessionState.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -29,7 +29,6 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 
 import javax.jms.MessageListener;
@@ -54,14 +53,13 @@
 import org.jboss.messaging.util.OrderedExecutorFactory;
 import org.jboss.messaging.util.Version;
 
-import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
-
 /**
  * State corresponding to a session. This state is acessible inside aspects/interceptors.
  * 
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -108,6 +106,13 @@
    //The distinguished message listener - for ASF
    private MessageListener sessionListener;
    
+   /* Holding sequential counters for ordering groups.
+    * Each ordering group has a sequence counter used to generate sequence numbers for
+    * its messages. The sequence number of a message indicates the order in which the message
+    * is to be delivered.
+    */
+   private HashMap<String, OrderingGroupSeq> orderingGrpSeqMap = new HashMap<String, OrderingGroupSeq>();
+   
    //This is somewhat strange - but some of the MQ and TCK tests expect an XA session to behaviour as AUTO_ACKNOWLEDGE when not enlisted in
    //a transaction
    //This is the opposite behaviour as what is required when the XA session handles MDB delivery or when using the message bridge.
@@ -117,11 +122,15 @@
    
    private long npSendSequence;
    
+   private boolean enableOrderingGroup;
+   
+   private String defaultOrderingGroupName;
+   
    // Constructors ---------------------------------------------------------------------------------
 
    public SessionState(ConnectionState parent, ClientSessionDelegate delegate,
                        boolean transacted, int ackMode, boolean xa,
-                       int dupsOKBatchSize)
+                       int dupsOKBatchSize, boolean enableOrderingGroup, String defaultOrderingGroupName)
    {
       super(parent, (DelegateSupport)delegate);
 
@@ -156,6 +165,10 @@
       callbackHandlers = new HashMap();
       
       executor = executorFactory.getExecutor("jbm-client-session-threads");
+      
+      this.setEnableOrderingGroup(enableOrderingGroup);
+      
+      this.setDefaultOrderingGroupName(defaultOrderingGroupName);
    }
 
    // HierarchicalState implementation -------------------------------------------------------------
@@ -490,6 +503,12 @@
    {
       return "SessionState[" + sessionID + "]";
    }
+   
+   //remove the ordering group from map.
+   public void removeOrderingGroup(String orderingGroupName)
+   {
+      orderingGrpSeqMap.remove(orderingGroupName);
+   }
 
    // Package protected ----------------------------------------------------------------------------
 
@@ -499,5 +518,54 @@
 
    // Inner classes --------------------------------------------------------------------------------
    
+   /**
+    * @param enableOrderingGroup the enableOrderingGroup to set
+    */
+   public void setEnableOrderingGroup(boolean enableOrderingGroup)
+   {
+      this.enableOrderingGroup = enableOrderingGroup;
+   }
+
+   /**
+    * @return the enableOrderingGroup
+    */
+   public boolean isEnableOrderingGroup()
+   {
+      return enableOrderingGroup;
+   }
+
+   /**
+    * @param defaultOrderingGroupName the defaultOrderingGroupName to set
+    */
+   public void setDefaultOrderingGroupName(String defaultOrderingGroupName)
+   {
+      this.defaultOrderingGroupName = defaultOrderingGroupName;
+   }
+
+   /**
+    * @return the defaultOrderingGroupName
+    */
+   public String getDefaultOrderingGroupName()
+   {
+      return defaultOrderingGroupName;
+   }
+
+   //A sequence generator class. sequence starts from 1
+   public static class OrderingGroupSeq
+   {
+      private long counter;
+      
+      public OrderingGroupSeq()
+      {
+         counter = 0;
+      }
+
+      public long getNext()
+      {
+         counter++;
+         return counter;
+      }
+   }
+
 }
 

Modified: branches/Branch_1_4/src/main/org/jboss/jms/delegate/ProducerDelegate.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/delegate/ProducerDelegate.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/delegate/ProducerDelegate.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -32,6 +32,7 @@
  * 
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  * @version <tt>$Revision$</tt>
  */
 public interface ProducerDelegate extends Closeable
@@ -75,4 +76,8 @@
              int deliveryMode,
              int priority,
              long timeToLive, boolean keepOriginalID) throws JMSException;
+   
+   void enableOrderingGroup(String ogrpName) throws JMSException;
+   
+   void disableOrderingGroup() throws JMSException;
 }

Modified: branches/Branch_1_4/src/main/org/jboss/jms/message/JBossMessage.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/message/JBossMessage.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/message/JBossMessage.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -68,6 +68,7 @@
  * @author Hiram Chirino (Cojonudo14 at hotmail.com)
  * @author David Maplesden (David.Maplesden at orion.co.nz)
  * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  *
  * $Id$
  */
@@ -112,6 +113,9 @@
    //Used when bridging a message
    public static final String JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST = "JBM_BRIDGE_MSG_ID_LIST";
    
+   //Used in ordering group
+   public static final String JBOSS_MESSAGING_ORDERING_GROUP_ID = "JBM_ORDERING_GROUP_ID";
+   
    private static final Logger log = Logger.getLogger(JBossMessage.class);   
       
    // Static --------------------------------------------------------
@@ -222,7 +226,7 @@
       {
          deliveryCount = m.getIntProperty("JMSXDeliveryCount");
       }
-      catch (JMSException e)
+      catch (Exception e)
       {
          log.error("Failed to get delivery count", e);
       }
@@ -457,7 +461,13 @@
       //when routing the message
       this.destination = destination; 
    }
-   
+
+   //used in message ordering group. Marking the message as an ordering group member.
+   public void setJBMOrderingGroupName(String grpName) throws JMSException
+   {
+      setStringProperty(JBOSS_MESSAGING_ORDERING_GROUP_ID, grpName);
+   }
+
    //We need to override getHeaders - so the JMSDestination header gets persisted to the db
    //This is called by the persistence manager
    public Map getHeaders()
@@ -1089,6 +1099,7 @@
                                             "' is reserved due to selector syntax.");
       }          
    }
+
    
    // Protected -----------------------------------------------------
    

Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/ConnectionFactoryManager.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/ConnectionFactoryManager.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/ConnectionFactoryManager.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -28,6 +28,7 @@
 /**
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  * @version <tt>$Revision$</tt>
  *          <p/>
  *          $Id$
@@ -50,7 +51,9 @@
                                  boolean supportsLoadBalancing,
                                  LoadBalancingFactory loadBalancingPolicy,
                                  boolean strictTck,
-                                 boolean sendAcksAsync) throws Exception;
+                                 boolean sendAcksAsync,
+                                 boolean enableOrderingGroup,
+                                 String defaultOrderingGroupName) throws Exception;
 
    void unregisterConnectionFactory(String uniqueName, boolean supportsFailover, boolean supportsLoadBalancing) throws Exception;
 }

Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -32,6 +32,7 @@
  *
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -83,6 +84,10 @@
    private boolean sendAcksAsync;
    
    private boolean disableRemotingChecks;
+   
+   private boolean enableOrderingGroup;
+   
+   private String defaultOrderingGroupName;
 
    // Constructors ---------------------------------------------------------------------------------
 
@@ -206,7 +211,7 @@
                                       locatorURI, enablePing, prefetchSize, slowConsumers,
                                       defaultTempQueueFullSize, defaultTempQueuePageSize,                                      
                                       defaultTempQueueDownCacheSize, dupsOKBatchSize, supportsFailover, supportsLoadBalancing,
-                                      loadBalancingFactory, strictTck, sendAcksAsync);               
+                                      loadBalancingFactory, strictTck, sendAcksAsync, enableOrderingGroup, defaultOrderingGroupName);               
          
          String info = "Connector " + locator.getProtocol() + "://" +
             locator.getHost() + ":" + locator.getPort();
@@ -464,7 +469,26 @@
       
    	this.disableRemotingChecks = disable;
    }
+   
+   public void setEnableOrderingGroup(boolean enable)
+   {
+      enableOrderingGroup = enable;
+   }
 
+   public boolean isEnableOrderingGroup()
+   {
+      return enableOrderingGroup;
+   }
+   
+   public void setDefaultOrderingGroupName(String name)
+   {
+      defaultOrderingGroupName = name;
+   }
+   
+   public String getDefaultOrderingGroupName()
+   {
+      return defaultOrderingGroupName;
+   }
    // JMX managed operations -----------------------------------------------------------------------
 
    // Public ---------------------------------------------------------------------------------------

Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -64,6 +64,8 @@
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ * 
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -127,7 +129,9 @@
                                                       boolean supportsLoadBalancing,
                                                       LoadBalancingFactory loadBalancingFactory,
                                                       boolean strictTck,
-                                                      boolean sendAcksAsync)
+                                                      boolean sendAcksAsync,
+                                                      boolean enableOrderingGroup,
+                                                      String defaultOrderingGroupName)
       throws Exception
    {
       log.debug(this + " registering connection factory '" + uniqueName + "', bindings: " + jndiBindings);
@@ -182,7 +186,7 @@
       ClientConnectionFactoryDelegate localDelegate =
          new ClientConnectionFactoryDelegate(uniqueName, id, serverPeer.getServerPeerID(),
                                              locatorURI, version, clientPing, useStrict,
-                                             sendAcksAsync);
+                                             sendAcksAsync, enableOrderingGroup, defaultOrderingGroupName);
 
       log.debug(this + " created local delegate " + localDelegate);
 
@@ -212,7 +216,7 @@
          	log.error(msg);
          	throw new IllegalArgumentException(msg);
          }
-         delegate = createClusteredDelegate(uniqueName, localDelegates.values(), loadBalancingFactory, endpoint, supportsFailover);
+         delegate = createClusteredDelegate(uniqueName, localDelegates.values(), loadBalancingFactory, endpoint, supportsFailover, enableOrderingGroup, defaultOrderingGroupName);
 
          log.debug(this + " created clustered delegate " + delegate);
       }
@@ -462,7 +466,8 @@
     */
    private ClientClusteredConnectionFactoryDelegate  createClusteredDelegate(String uniqueName, Collection localDelegates, LoadBalancingFactory loadBalancingFactory,
                                                                              ServerConnectionFactoryEndpoint endpoint,
-                                                                             boolean supportsFailover)
+                                                                             boolean supportsFailover, boolean enableOrderingGroup, 
+                                                                             String defaultOrderingGroupName)
       throws Exception
    {
       log.trace(this + " creating a clustered ConnectionFactoryDelegate based on " + localDelegates);
@@ -480,7 +485,7 @@
 
       endpoint.updateTopology(delegates, failoverMap);
 
-      return new ClientClusteredConnectionFactoryDelegate(uniqueName, delegates, failoverMap, lbp, supportsFailover);
+      return new ClientClusteredConnectionFactoryDelegate(uniqueName, delegates, failoverMap, lbp, supportsFailover, enableOrderingGroup, defaultOrderingGroupName);
    }
 
    private void rebindConnectionFactory(Context ic, JNDIBindings jndiBindings,

Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/ChannelSupport.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/ChannelSupport.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/ChannelSupport.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -28,6 +28,10 @@
 import java.util.ListIterator;
 import java.util.Set;
 
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+
+import org.jboss.jms.message.JBossMessage;
 import org.jboss.jms.server.MessagingTimeoutFactory;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.contract.Channel;
@@ -56,6 +60,7 @@
  *
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  * @version <tt>$Revision$</tt> $Id: ChannelSupport.java,v 1.65
  *          2006/06/27 19:44:39 timfox Exp $
  */
@@ -101,6 +106,8 @@
    protected int maxSize;
 
    protected SynchronizedInt messagesAdded;
+   
+   protected OrderingGroupMonitor monitor = new OrderingGroupMonitor();
 
    // Constructors ---------------------------------------------------------------------------------
 
@@ -155,6 +162,8 @@
 
       // Each channel has its own copy of the reference
       ref = ref.copy();
+      
+      monitor.registerMessage(ref);
 
       try
       {
@@ -214,6 +223,9 @@
 
       // Each channel has its own copy of the reference
       ref = ref.copy();
+      
+      //guarding against any ordering group messages.
+      monitor.registerMessage(ref);
 
       try
       {
@@ -594,6 +606,7 @@
 
       synchronized (lock)
       {
+         monitor.unmarkSending(ref);
          messageRefs.addFirst(ref, ref.getMessage().getPriority());
       }
 
@@ -621,7 +634,6 @@
          if (!getReceiversReady())
          {
          	if (trace) { log.trace(this + " receivers not ready so not delivering"); }
-
             return;
          }
 
@@ -631,66 +643,107 @@
 
             if (ref != null)
             {
-               // Attempt to push the ref to a receiver
-
-               if (trace) { log.trace(this + " pushing " + ref); }
-
-               Delivery del = distributor.handle(this, ref, null);
-
-               setReceiversReady(del != null);
-
-               if (del == null)
+               int status = monitor.isAvailable(ref);
+               if (status != OrderingGroupMonitor.OK)
                {
-                  // No receiver, broken receiver or full receiver so we stop delivering
-                  if (trace) { log.trace(this + " got no delivery for " + ref + " so no receiver got the message. Stopping delivery."); }
-
-                  break;
-               }
-               else if (!del.isSelectorAccepted())
-               {
-                  // No receiver accepted the message because no selectors matched, so we create
-                  // an iterator (if we haven't already created it) to iterate through the refs
-                  // in the channel. No delivery was really performed
-
+                  if (trace)
+                  {
+                     log.trace("Hold sending off ordering group message " + ref);
+                  }
+                  //iterating time
                   if (iter == null)
                   {
                      iter = messageRefs.iterator();
-
                      //We just tried the first one, so we don't want to try it again
                      iter.next();
                   }
                }
                else
                {
-                  if (trace) { log.trace(this + ": " + del + " returned for message " + ref); }
+                  // Attempt to push the ref to a receiver
 
-                  // Receiver accepted the reference
+                  if (trace)
+                  {
+                     log.trace(this + " pushing " + ref);
+                  }
 
-                  synchronized (lock)
+                  Delivery del = distributor.handle(this, ref, null);
+
+                  setReceiversReady(del != null);
+
+                  if (del == null)
                   {
+
+                     // No receiver, broken receiver or full receiver so we stop delivering
+                     if (trace)
+                     {
+                        log.trace(this + " got no delivery for " +
+                                  ref +
+                                  " so no receiver got the message. Stopping delivery.");
+                     }
+
+                     break;
+                  }
+                  else if (!del.isSelectorAccepted())
+                  {
+                     // No receiver accepted the message because no selectors matched, so we create
+                     // an iterator (if we haven't already created it) to iterate through the refs
+                     // in the channel. No delivery was really performed
+
+                     if (OrderingGroupMonitor.isOrderingGroupMessage(ref))
+                     {
+                        log.warn("Warning! Using message selectors with ordering group can cause unpredicatable results!");
+                     }
+                     
                      if (iter == null)
                      {
-                        if (trace) { log.trace(this + " removing first ref in memory"); }
+                        iter = messageRefs.iterator();
 
-                        removeFirstInMemory();
+                        // We just tried the first one, so we don't want to try it again
+                        iter.next();
                      }
-                     else
+                  }
+                  else
+                  {
+                     if (trace)
                      {
-                        if (trace) { log.trace(this + " removed current message from iterator"); }
+                        log.trace(this + ": " + del + " returned for message " + ref);
+                     }
 
-                        iter.remove();
+                     monitor.markSending(ref);
+                     
+                     // Receiver accepted the reference
+                     synchronized (lock)
+                     {
+                        if (iter == null)
+                        {
+                           if (trace)
+                           {
+                              log.trace(this + " removing first ref in memory");
+                           }
+
+                           removeFirstInMemory();
+                        }
+                        else
+                        {
+                           if (trace)
+                           {
+                              log.trace(this + " removed current message from iterator");
+                           }
+
+                           iter.remove();
+                        }
                      }
+
+                     deliveringCount.increment();
                   }
-
-                  deliveringCount.increment();
                }
             }
             else
             {
                // No more refs in channel or only ones that don't match any selectors
                if (trace) { log.trace(this + " no more refs to deliver "); }
-
-               break;
+                  break;
             }
          }
       }
@@ -797,6 +850,22 @@
             pm.addTransaction(tx);
          }
       }
+      
+      MessageReference ref = d.getReference();
+      if (OrderingGroupMonitor.isOrderingGroupMessage(ref))
+      {
+         if (trace)
+         {
+            log.trace("Ordering group message " + ref + " has been completed, trying to send next.");
+         }
+         synchronized (lock)
+         {
+            if (monitor.messageCompleted(ref))
+            {
+               deliverInternal();
+            }
+         }
+      }
    }
 
    protected InMemoryCallback getCallback(Transaction tx)
@@ -839,9 +908,32 @@
 
    // Private --------------------------------------------------------------------------------------
 
+   //debug use, remove when done.
+   public static String getRefText(MessageReference ref)
+   {
+      String result = "<null>";
+      if (ref == null) return result;
+      Object rmsg = ref.getMessage();
+      if (rmsg instanceof JBossMessage)
+      {
+         JBossMessage msg = (JBossMessage)ref.getMessage();
+         if (msg instanceof TextMessage)
+         {
+            try
+            {
+               result = "(" + ((TextMessage)msg).getText() + ")";
+            }
+            catch (JMSException e)
+            {
+            }
+         }
+      }
+      return result;
+   }
+   
    private MessageReference nextReference(ListIterator iter) throws Throwable
    {
-      MessageReference ref;
+      MessageReference ref = null;
 
       if (iter == null)
       {
@@ -857,6 +949,7 @@
          if (iter.hasNext())
          {
             ref = (MessageReference)iter.next();
+            //if (monitor.challengeSend(ref) == OrderingGroupMonitor.OK) break;
          }
          else
          {
@@ -982,7 +1075,12 @@
 
       public void afterRollback(boolean onePhase) throws Exception
       {
-      	//NOOP
+         //tx rolled back, we need to inform the monitor
+         for(Iterator i = refsToAdd.iterator(); i.hasNext(); )
+         {
+            MessageReference ref = (MessageReference)i.next();
+            monitor.unmarkSending(ref);
+         }
       }
 
       public String toString()

Copied: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/OrderingGroup.java (from rev 6820, branches/Branch_1416_merge/src/main/org/jboss/messaging/core/impl/OrderingGroup.java)
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/OrderingGroup.java	                        (rev 0)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/OrderingGroup.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,279 @@
+/*
+ * 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.core.impl;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jms.JMSException;
+
+import org.jboss.logging.Logger;
+import org.jboss.messaging.core.contract.MessageReference;
+
+/**
+*
+* This class holds the states of messages in an ordering group.
+*
+* @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+*
+*/
+public class OrderingGroup
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   private List<ReferenceHolder> sortedList = new LinkedList<ReferenceHolder>();
+
+   private HashMap<Long, ReferenceHolder> refMap = new HashMap<Long, ReferenceHolder>();
+
+   private String groupName;
+
+   // Static --------------------------------------------------------
+   private static final Logger log = Logger.getLogger(OrderingGroup.class);
+
+   // Constructors --------------------------------------------------
+   public OrderingGroup(String name)
+   {
+      groupName = name;
+   }
+
+   private OrderingGroup()
+   {
+   }
+
+   // Public --------------------------------------------------------
+   /**
+    * Adding a message to a list. As messages are coming in order, we can just put
+    * the message to the end of the list.
+    * 
+    * @param ref The message reference to be added
+    * 
+    * @throws JMSException 
+    */
+   public boolean register(MessageReference ref)
+   {
+      Long mid = ref.getMessage().getMessageID();
+      ReferenceHolder holder = refMap.get(mid);
+      if (holder != null)
+      {
+         return true;
+      }
+      try
+      {
+         holder = new ReferenceHolder(ref);
+      }
+      catch (JMSException e)
+      {
+         log.error("error creating ReferenceHolder. ", e);
+      }
+      if (holder == null)
+      {
+         return false;
+      }
+      sortedList.add(holder);
+      refMap.put(mid, holder);
+      return true;
+   }
+
+   /**
+    * See if the ref be there and be the first
+    * Simply comparing the addresses simply doesn't work!
+    */
+   public int isAvailable(MessageReference ref)
+   {
+      if (sortedList.size() == 0) {
+         return OrderingGroupMonitor.OK;
+      }
+      
+      ReferenceHolder holder = sortedList.get(0);
+      return holder.isAvailable(ref);
+   }
+
+   /**
+    * remove the message reference from the group
+    * Note: the ref will be removed if and only if the ref
+    * resides the first in the list, otherwise just ignore it.
+    */
+   public void unregister(MessageReference ref)
+   {
+      if (sortedList.size() == 0) {
+         return;
+      }
+      ReferenceHolder holder = sortedList.get(0);
+      if (holder == null)
+      {
+         return;
+      }
+      if (holder.matchMessage(ref))
+      {
+         long count = holder.releaseRef();
+         if (count == 0)
+         {
+            sortedList.remove(0);
+            refMap.remove(ref.getMessage().getMessageID());
+         }
+      }
+   }
+
+   /**
+    * check if there are more message available in the list.
+    */
+   public boolean hasPendingMessage()
+   {
+      boolean result = false;
+      if (sortedList.size() == 0)
+      {
+         return result;
+      }
+      result = sortedList.size() > 0;
+      return result;
+   }
+
+   /**
+    * Set the flag that the Message is being delivered.
+    * @param ref
+    */
+   public void markSending(MessageReference ref)
+   {
+      if (sortedList.size() == 0)
+      {
+         return;
+      }
+      ReferenceHolder holder = sortedList.get(0);
+      if (holder.matchMessage(ref))
+      {
+         holder.markSending();
+      }
+   }
+
+   public String getGroupName()
+   {
+      return groupName;
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}
+
+class ReferenceHolder
+{
+
+   private Long seq;
+
+   private MessageReference ref;
+
+   private long refCount;
+
+   private long pendingSentCount;
+
+   public ReferenceHolder(MessageReference r) throws JMSException
+   {
+      ref = r;
+      refCount = 1;
+      pendingSentCount = 0;
+   }
+
+   public void markSending()
+   {
+      pendingSentCount++;
+   }
+
+   public long unmarkSending()
+   {
+      if (pendingSentCount > 0)
+      {
+         pendingSentCount--;
+      }
+      return pendingSentCount;
+   }
+
+   public boolean isPending()
+   {
+      return pendingSentCount > 0;
+   }
+
+   public int isAvailable(MessageReference exRef)
+   {
+      if (matchMessage(exRef))
+      {
+         if (pendingSentCount < refCount)
+         {
+            return OrderingGroupMonitor.OK;
+         }
+         return OrderingGroupMonitor.NOT_OK_BEING_SENT;
+      }
+      return OrderingGroupMonitor.NOT_OK_NOT_FIRST;
+   }
+
+   /**
+    * So far only allowed to register once. 
+    */
+   public void addRef()
+   {
+      refCount++;
+   }
+
+   public long releaseRef()
+   {
+      if (refCount > 0)
+      {
+         refCount--;
+      }
+      return refCount;
+   }
+
+   /**
+    * decrease the ref count
+    * here we don't care about pendingSentCount here.
+    */
+   public long releaseSendnRef()
+   {
+      refCount--;
+      pendingSentCount--;
+      return refCount;
+   }
+
+   /**
+    * If the holder holds the same message as in the ref.
+    */
+   public boolean matchMessage(MessageReference newRef)
+   {
+      Long mid1 = newRef.getMessage().getMessageID();
+      Long mid2 = ref.getMessage().getMessageID();
+      return mid1.equals(mid2);
+   }
+
+   public MessageReference getMessageRef()
+   {
+      return ref;
+   }
+
+}

Copied: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/OrderingGroupMonitor.java (from rev 6820, branches/Branch_1416_merge/src/main/org/jboss/messaging/core/impl/OrderingGroupMonitor.java)
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/OrderingGroupMonitor.java	                        (rev 0)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/OrderingGroupMonitor.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,235 @@
+/*
+ * 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.core.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.jms.JMSException;
+
+import org.jboss.jms.message.JBossMessage;
+import org.jboss.logging.Logger;
+import org.jboss.messaging.core.contract.Message;
+import org.jboss.messaging.core.contract.MessageReference;
+
+/**
+*
+* This class guards against any delivering of ordering group messages.
+*
+* @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+*
+*/
+public class OrderingGroupMonitor
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   private HashMap<String, OrderingGroup> orderingGroups = new HashMap<String, OrderingGroup>();
+
+   // Static --------------------------------------------------------
+   private static final Logger log = Logger.getLogger(OrderingGroupMonitor.class);
+
+   public static final int OK = 0;
+   public static final int NOT_OK_NOT_FIRST = 1;
+
+   public static final int NOT_OK_BEING_SENT = 2;
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   /**
+    * Check the message is it is a member of an ordering group, if so,
+    * put it in; if not, do nothing.
+    * if the message is dropped due to maxSize being reached, it won't 
+    * get registered.
+    */
+   public void registerMessage(MessageReference ref)
+   {
+      String grpName = extractGroupName(ref);
+      if (grpName == null)
+      {
+         return;
+      }
+      synchronized (orderingGroups)
+      {
+         OrderingGroup group = orderingGroups.get(grpName);
+         if (group == null)
+         {
+            group = new OrderingGroup(grpName);
+            orderingGroups.put(grpName, group);
+         }
+         group.register(ref);
+      }
+   }
+
+   /**
+    * If ref is not in our registry, just return true.
+    * If in our registry, check if the ref is the first of the group.
+    * return true if it at the first place. return false otherwise.
+    */
+   public int isAvailable(MessageReference ref)
+   {
+      int result = OK;
+      String grpName = extractGroupName(ref);
+      if (grpName != null)
+      {
+         synchronized (orderingGroups)
+         {
+            OrderingGroup group = orderingGroups.get(grpName);
+            if (group != null)
+            {
+               result = group.isAvailable(ref);
+            }
+         }
+      }
+      else
+      {
+         log.debug("message doesn't have group prop, fine by me");
+      }
+      return result;
+   }
+
+   /**
+    * This method indicates a messgae is completed.
+    * it is called when a message is acked, commited or rollback
+    * once the message is completed, the next one in a ordering 
+    * group becomes deliverable.
+    * return if there is more messages available after this one.
+    */
+   public boolean messageCompleted(MessageReference ref)
+   {
+      String grpName = extractGroupName(ref);
+      if (grpName == null)
+      {
+         //not a ordering group message
+         return false;
+      }
+      synchronized (orderingGroups)
+      {
+         OrderingGroup group = orderingGroups.get(grpName);
+         if (group != null)
+         {
+            group.unregister(ref);
+         }
+         return this.hasMessageInQueue();
+      }
+   }
+
+   /**
+    * Check if there is any pending messages in any group.
+    */
+   private boolean hasMessageInQueue()
+   {
+      boolean result = false;
+      synchronized (orderingGroups)
+      {
+         Iterator<OrderingGroup> iter = orderingGroups.values().iterator();
+         while (iter.hasNext())
+         {
+            OrderingGroup group = iter.next();
+            if (group.hasPendingMessage())
+            {
+               result = true;
+               break;
+            }
+         }
+         
+      }
+      return result;
+   }
+
+   /**
+    * reducing the refcount, if zero, remove it.
+    */
+   public void unmarkSending(MessageReference ref)
+   {
+      String grpName = extractGroupName(ref);
+      if (grpName == null)
+      {
+         return;
+      }
+      synchronized (orderingGroups)
+      {
+         OrderingGroup group = orderingGroups.get(grpName);
+         if (group != null)
+         {
+            group.unregister(ref);
+         }
+      }
+   }
+
+   public void markSending(MessageReference ref)
+   {
+      String grpName = extractGroupName(ref);
+      if (grpName != null)
+      {
+         synchronized (orderingGroups)
+         {
+            OrderingGroup group = orderingGroups.get(grpName);
+            if (group != null)
+            {
+               group.markSending(ref);
+            }
+         }
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+   private static String extractGroupName(MessageReference ref)
+   {
+      String name = null;
+      try
+      {
+         Message obj = ref.getMessage();
+         if (obj instanceof JBossMessage)
+         {
+            JBossMessage msg = (JBossMessage)ref.getMessage();
+            if (msg != null)
+            {
+               name = msg.getStringProperty(JBossMessage.JBOSS_MESSAGING_ORDERING_GROUP_ID);
+            }
+         }
+      }
+      catch (JMSException e)
+      {
+      }
+      return name;
+   }
+
+   /**
+    * check if the message has a group name
+    */
+   public static boolean isOrderingGroupMessage(MessageReference ref)
+   {
+      return extractGroupName(ref) != null;
+   }
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/PagingChannelSupport.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/PagingChannelSupport.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/PagingChannelSupport.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -43,6 +43,8 @@
  * of memory.
  *
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ * 
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -502,7 +504,10 @@
       {
          ReferenceInfo info = (ReferenceInfo)iter.next();
          
-         addFromRefInfo(info, refMap);
+         MessageReference added = addFromRefInfo(info, refMap);
+         //note, we registered the ref 'after' it has been added to the list
+         //it is safe as long as the caller of this method is synchronized on lock.
+         monitor.registerMessage(added);
       }
    }
         

Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeManagementTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeManagementTest.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeManagementTest.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -111,3 +111,4 @@
    // Inner classes -------------------------------------------------
 
 }
+

Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/ConnectionConsumerTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/ConnectionConsumerTest.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/ConnectionConsumerTest.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -41,6 +41,8 @@
  * ConnectionConsumer tests
  *
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ * 
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -550,41 +552,41 @@
    }
    
    
-   class MockServerSessionPool implements ServerSessionPool
+}
+
+class MockServerSession implements ServerSession
+{
+   Session session;
+   
+   MockServerSession(Session sess)
    {
-      private ServerSession serverSession;
-      
-      MockServerSessionPool(Session sess)
-      {
-         serverSession = new MockServerSession(sess);
-      }
-
-      public ServerSession getServerSession() throws JMSException
-      {
-         return serverSession;
-      }      
+      this.session = sess;
    }
    
-   class MockServerSession implements ServerSession
+
+   public Session getSession() throws JMSException
    {
-      Session session;
-      
-      MockServerSession(Session sess)
-      {
-         this.session = sess;
-      }
-      
+      return session;
+   }
 
-      public Session getSession() throws JMSException
-      {
-         return session;
-      }
-
-      public void start() throws JMSException
-      {
-         session.run();
-      }
-      
+   public void start() throws JMSException
+   {
+      session.run();
    }
    
 }
+
+class MockServerSessionPool implements ServerSessionPool
+{
+   private ServerSession serverSession;
+   
+   MockServerSessionPool(Session sess)
+   {
+      serverSession = new MockServerSession(sess);
+   }
+
+   public ServerSession getServerSession() throws JMSException
+   {
+      return serverSession;
+   }      
+}

Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -38,13 +38,16 @@
 import javax.management.ObjectName;
 
 import org.jboss.jms.client.JBossConnectionFactory;
+import org.jboss.jms.client.JBossMessageProducer;
 import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
+import org.jboss.jms.message.JBossMessage;
 import org.jboss.test.messaging.tools.ServerManagement;
 import org.jboss.test.messaging.tools.container.ServiceContainer;
 
 /**
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -618,6 +621,241 @@
 
    }
 
+   /**
+    * This is test the configuration of ordering group on connection factories
+    * First it deployed a connection factory with ordering group disabled, then use the factory to 
+    * send messages. then check the message at the receiving end to make sure the 
+    * configuration really take effect.
+    * 
+    * Also it tests the connection factory with the ordering group related parameters absent.
+    * in which case the effect should be same as the above.
+    */
+   public void testAdministrativelyConfiguredNoOrderingGroup() throws Exception
+   {
+      Connection c = null;
+      Connection c2 = null;
+
+      try
+      {
+         String mbeanConfig = "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" + "       name=\"jboss.messaging.connectionfactory:service=TestNoOrderingGroupConnectionFactory\"\n"
+                              + "       xmbean-dd=\"xmdesc/ConnectionFactory-xmbean.xml\">\n"
+                              + "       <depends optional-attribute-name=\"ServerPeer\">jboss.messaging:service=ServerPeer</depends>\n"
+                              + "       <depends optional-attribute-name=\"Connector\">jboss.messaging:service=Connector,transport=bisocket</depends>\n"
+                              + "       <attribute name=\"JNDIBindings\">\n"
+                              + "          <bindings>\n"
+                              + "            <binding>/TestNoOrderingGroupConnectionFactory</binding>\n"
+                              + "          </bindings>\n"
+                              + "       </attribute>\n"
+                              + "       <attribute name=\"EnableOrderingGroup\">false</attribute>\n"
+                              + "       <attribute name=\"DefaultOrderingGroupName\">MyOrderingGroup</attribute>\n"
+                              + " </mbean>";
+
+         ObjectName on = ServerManagement.deploy(mbeanConfig);
+         ServerManagement.invoke(on, "create", new Object[0], new String[0]);
+         ServerManagement.invoke(on, "start", new Object[0], new String[0]);
+
+         ConnectionFactory cf = (ConnectionFactory)ic.lookup("/TestNoOrderingGroupConnectionFactory");
+         c = cf.createConnection();
+
+         Session session = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod = session.createProducer(queue1);
+
+         final int NUM_MSG = 1000;
+
+         for (int i = 1; i < NUM_MSG; i++)
+         {
+            TextMessage tm = session.createTextMessage("message " + i);
+            prod.send(tm);
+         }
+
+         c.start();
+
+         MessageConsumer consmr = session.createConsumer(queue1);
+
+         for (int i = 1; i < NUM_MSG; i++)
+         {
+            TextMessage rm = (TextMessage)consmr.receive(500);
+            assertNotNull(rm);
+            // each message should not have the header.
+            String orderingGroupName = rm.getStringProperty(JBossMessage.JBOSS_MESSAGING_ORDERING_GROUP_ID);
+            assertNull(orderingGroupName);
+         }
+
+         session.close();
+
+         String mbeanConfig2 = "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" + "       name=\"jboss.messaging.connectionfactory:service=TestNoOrderingGroupConnectionFactory2\"\n"
+                               + "       xmbean-dd=\"xmdesc/ConnectionFactory-xmbean.xml\">\n"
+                               + "       <depends optional-attribute-name=\"ServerPeer\">jboss.messaging:service=ServerPeer</depends>\n"
+                               + "       <depends optional-attribute-name=\"Connector\">jboss.messaging:service=Connector,transport=bisocket</depends>\n"
+                               + "       <attribute name=\"JNDIBindings\">\n"
+                               + "          <bindings>\n"
+                               + "            <binding>/TestNoOrderingGroupConnectionFactory2</binding>\n"
+                               + "          </bindings>\n"
+                               + "       </attribute>\n"
+                               + " </mbean>";
+
+         ObjectName on2 = ServerManagement.deploy(mbeanConfig2);
+         ServerManagement.invoke(on2, "create", new Object[0], new String[0]);
+         ServerManagement.invoke(on2, "start", new Object[0], new String[0]);
+
+         ConnectionFactory cf2 = (ConnectionFactory)ic.lookup("/TestNoOrderingGroupConnectionFactory2");
+         c2 = cf2.createConnection();
+
+         Session session2 = c2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod2 = session2.createProducer(queue1);
+
+         for (int i = 1; i < NUM_MSG; i++)
+         {
+            TextMessage tm = session2.createTextMessage("message " + i);
+            prod2.send(tm);
+         }
+
+         c2.start();
+
+         MessageConsumer consmr2 = session2.createConsumer(queue1);
+
+         for (int i = 1; i < NUM_MSG; i++)
+         {
+            TextMessage rm = (TextMessage)consmr2.receive(500);
+            assertNotNull(rm);
+            // each message should not have the header.
+            String orderingGroupName = rm.getStringProperty(JBossMessage.JBOSS_MESSAGING_ORDERING_GROUP_ID);
+            assertNull(orderingGroupName);
+         }
+
+         ServerManagement.invoke(on, "stop", new Object[0], new String[0]);
+         ServerManagement.invoke(on, "destroy", new Object[0], new String[0]);
+         ServerManagement.undeploy(on);
+
+         ServerManagement.invoke(on2, "stop", new Object[0], new String[0]);
+         ServerManagement.invoke(on2, "destroy", new Object[0], new String[0]);
+         ServerManagement.undeploy(on2);
+      }
+      finally
+      {
+         try
+         {
+            if (c != null)
+            {
+               log.info("Closing connection");
+               c.close();
+               log.info("Closed connection");
+            }
+            if (c2 != null)
+            {
+               log.info("Closing connection");
+               c2.close();
+               log.info("Closed connection");
+            }
+         }
+         catch (Exception e)
+         {
+            log.warn(e.toString(), e);
+         }
+      }
+   }
+
+   
+   /**
+    * This is test the configuration of ordering group on connection factories
+    * First it deployed a ordering-group configured factory, then use the factory to 
+    * send messages. then check the message at the receiving end to make sure the 
+    * configuration really take effect.
+    */
+   public void testAdministrativelyConfiguredOrderingGroup() throws Exception
+   {
+      Connection c = null;
+      
+      try
+      {
+         String mbeanConfig = "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" + "       name=\"jboss.messaging.connectionfactory:service=TestOrderingGroupConnectionFactory\"\n"
+         + "       xmbean-dd=\"xmdesc/ConnectionFactory-xmbean.xml\">\n"
+         + "       <depends optional-attribute-name=\"ServerPeer\">jboss.messaging:service=ServerPeer</depends>\n"
+         + "       <depends optional-attribute-name=\"Connector\">jboss.messaging:service=Connector,transport=bisocket</depends>\n"
+         + "       <attribute name=\"JNDIBindings\">\n"
+         + "          <bindings>\n"
+         + "            <binding>/TestOrderingGroupConnectionFactory</binding>\n"
+         + "          </bindings>\n"
+         + "       </attribute>\n"
+         + "       <attribute name=\"EnableOrderingGroup\">true</attribute>\n"
+         + "       <attribute name=\"DefaultOrderingGroupName\">MyOrderingGroup2</attribute>\n"
+         + " </mbean>";
+
+         ObjectName on = ServerManagement.deploy(mbeanConfig);
+         ServerManagement.invoke(on, "create", new Object[0], new String[0]);
+         ServerManagement.invoke(on, "start", new Object[0], new String[0]);
+
+         ConnectionFactory cf = (ConnectionFactory)ic.lookup("/TestOrderingGroupConnectionFactory");
+         c = cf.createConnection();
+
+         Session session = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageProducer prod = session.createProducer(queue1);
+
+         final int NUM_MSG = 1000;
+
+         for (int i = 1; i < NUM_MSG; i++)
+         {
+            TextMessage tm = session.createTextMessage("message " + i);
+            prod.send(tm);
+         }
+
+         c.start();
+
+         MessageConsumer consmr = session.createConsumer(queue1);
+
+         for (int i = 1; i < NUM_MSG; i++)
+         {
+            TextMessage rm = (TextMessage)consmr.receive(500);
+            assertNotNull(rm);
+            // each message should have the header.
+            String orderingGroupName = rm.getStringProperty(JBossMessage.JBOSS_MESSAGING_ORDERING_GROUP_ID);
+            assertNotNull(orderingGroupName);
+            assertEquals("MyOrderingGroup2", orderingGroupName);
+         }
+         
+         //this tests that factory defaults can be overridden.
+         JBossMessageProducer jProd = (JBossMessageProducer)prod;
+         jProd.enableOrderingGroup("MyAnotherOrderingGroup");
+
+         for (int i = 1; i < NUM_MSG; i++)
+         {
+            TextMessage tm = session.createTextMessage("message " + i);
+            jProd.send(tm);
+         }
+
+         for (int i = 1; i < NUM_MSG; i++)
+         {
+            TextMessage rm = (TextMessage)consmr.receive(500);
+            assertNotNull(rm);
+            // each message should have the header.
+            String orderingGroupName = rm.getStringProperty(JBossMessage.JBOSS_MESSAGING_ORDERING_GROUP_ID);
+            assertNotNull(orderingGroupName);
+            assertEquals("MyAnotherOrderingGroup", orderingGroupName);
+         }
+
+         session.close();
+         ServerManagement.invoke(on, "stop", new Object[0], new String[0]);
+         ServerManagement.invoke(on, "destroy", new Object[0], new String[0]);
+         ServerManagement.undeploy(on);
+      }
+      finally
+      {
+         try
+         {
+            if (c != null)
+            {
+               log.info("Closing connection");
+               c.close();
+               log.info("Closed connection");
+            }
+         }
+         catch (Exception e)
+         {
+            log.warn(e.toString(), e);
+         }
+      }
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------

Copied: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupAckTest.java (from rev 6820, branches/Branch_1416_merge/tests/src/org/jboss/test/messaging/jms/OrderingGroupAckTest.java)
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupAckTest.java	                        (rev 0)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupAckTest.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,510 @@
+/*
+ * 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.test.messaging.jms;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.QueueConnection;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.XAConnection;
+import javax.jms.XASession;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.jboss.jms.client.JBossMessageProducer;
+import org.jboss.jms.tx.MessagingXid;
+import org.jboss.jms.tx.ResourceManagerFactory;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.container.ServiceContainer;
+
+/**
+ * A OrderingGroupAckTest
+ *
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ * 
+ * Created Oct 28, 2008 2:30:18 PM
+ *
+ *
+ */
+public class OrderingGroupAckTest extends JMSTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+   public OrderingGroupAckTest(String name)
+   {
+      super(name);
+   }
+
+   // TestCase overrides -------------------------------------------
+
+   protected void setUp() throws Exception
+   {
+      // if this is not set testMockCoordinatorRecoveryWithJBossTSXids will create an invalid ObjectStore
+      ServiceContainer.setupObjectStoreDir();
+      super.setUp();
+   }
+
+   public void tearDown() throws Exception
+   {
+      super.tearDown();
+
+      ResourceManagerFactory.instance.clear();
+   }
+
+   // Public --------------------------------------------------------
+
+   /*
+    * This test shows how ordering group delivery handles transactions.
+    * A rollback will cause the first message to be re-delivered.
+    * A commit will cause the second message to be available for delivery.
+    */
+   public void testRollbackCommit() throws Exception
+   {
+      QueueConnection conn = null;
+
+      try
+      {
+         conn = cf.createQueueConnection();
+         QueueSession sess = conn.createQueueSession(true, 0);
+         JBossMessageProducer producer = (JBossMessageProducer)sess.createProducer(queue1);
+         producer.enableOrderingGroup(null);
+
+         QueueReceiver cons = sess.createReceiver(queue1);
+
+         conn.start();
+
+         Message m1 = sess.createTextMessage("testing1");
+         Message m2 = sess.createTextMessage("testing2");
+         producer.send(m1);
+         producer.send(m2);
+
+         sess.commit();
+
+         TextMessage mr = (TextMessage)cons.receive(3000);
+         assertNotNull(mr);
+         assertEquals("testing1", mr.getText());
+
+         sess.rollback();
+
+         mr = (TextMessage)cons.receive(3000);
+         assertNotNull(mr);
+         assertEquals("testing1", mr.getText());
+
+         // second message cannot be received
+         // if the first message is not committed.
+         mr = (TextMessage)cons.receive(3000);
+         assertNull(mr);
+
+         sess.commit();
+
+         mr = (TextMessage)cons.receive(3000);
+         assertNotNull(mr);
+         assertEquals("testing2", mr.getText());
+
+         sess.commit();
+
+         checkEmpty(queue1);
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   /*
+    * This test shows how ordering group handles client acknowledge.
+    * the second message will never be sent out unless the first message is acked.
+    */
+   public void testClientAcknowledge() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+         conn = cf.createConnection();
+
+         Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+         JBossMessageProducer producer = (JBossMessageProducer)producerSess.createProducer(queue1);
+         producer.enableOrderingGroup(null);
+
+         Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+         MessageConsumer consumer = consumerSess.createConsumer(queue1);
+         conn.start();
+
+         final int NUM_MSG = 100;
+
+         // Send some messages
+         for (int i = 0; i < 100; ++i)
+         {
+            TextMessage tm = producerSess.createTextMessage("ordering" + i);
+            producer.send(tm);
+         }
+
+         assertRemainingMessages(NUM_MSG);
+
+         log.trace("Sent messages");
+
+         int count = 0;
+         while (true)
+         {
+            Message m = consumer.receive(400);
+            if (m == null)
+               break;
+            count++;
+         }
+
+         assertRemainingMessages(NUM_MSG);
+
+         log.trace("Received " + count + " messages");
+
+         // if ordering group, count should be 1.
+         assertEquals(1, count);
+
+         consumerSess.recover();
+
+         assertRemainingMessages(NUM_MSG);
+
+         log.trace("Session recover called");
+
+         TextMessage m = null;
+
+         int i = 0;
+         for (; i < 100; ++i)
+         {
+            m = (TextMessage)consumer.receive();
+            log.trace("Received message " + i);
+            m.acknowledge();
+            assertTrue(m.getText().equals("ordering" + i));
+         }
+
+         assertRemainingMessages(0);
+
+         // make sure I don't receive anything else
+
+         checkEmpty(queue1);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   /*
+    * send 4 messages, start a XA transaction to receive, messages will be received only if
+    * the last message is committed. 
+    */
+   public void testSimpleXATransactionalReceive() throws Exception
+   {
+      log.trace("starting testSimpleXATransactionalReceive");
+
+      Connection conn1 = null;
+
+      XAConnection xconn1 = null;
+
+      try
+      {
+         // First send a message to the queue
+         conn1 = cf.createConnection();
+
+         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         JBossMessageProducer prod = (JBossMessageProducer)sess1.createProducer(queue1);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+         prod.enableOrderingGroup("testSimpleXATransactionalReceive");
+
+         TextMessage tm1 = sess1.createTextMessage("tm1");
+         TextMessage tm2 = sess1.createTextMessage("tm2");
+         TextMessage tm3 = sess1.createTextMessage("tm3");
+         TextMessage tm4 = sess1.createTextMessage("tm4");
+
+         prod.send(tm1);
+         prod.send(tm2);
+         prod.send(tm3);
+         prod.send(tm4);
+
+         xconn1 = cf.createXAConnection();
+
+         XASession xsess1 = xconn1.createXASession();
+
+         XAResource res1 = xsess1.getXAResource();
+
+         // Pretend to be a transaction manager by interacting through the XAResources
+         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+
+         res1.start(xid1, XAResource.TMNOFLAGS);
+
+         MessageConsumer cons = xsess1.createConsumer(queue1);
+
+         xconn1.start();
+
+         // Consume the message
+
+         TextMessage rm1 = (TextMessage)cons.receive(1000);
+
+         assertNotNull(rm1);
+
+         assertEquals(tm1.getText(), rm1.getText());
+
+         res1.end(xid1, XAResource.TMSUCCESS);
+
+         // next message should not be received.
+         rm1 = (TextMessage)cons.receive(2000);
+         assertNull(rm1);
+
+         // prepare the tx
+         res1.prepare(xid1);
+
+         res1.commit(xid1, false);
+
+         rm1 = (TextMessage)cons.receive(2000);
+         assertNotNull(rm1);
+         assertEquals(rm1.getText(), tm2.getText());
+
+         rm1 = (TextMessage)cons.receive(2000);
+         assertNotNull(rm1);
+         assertEquals(rm1.getText(), tm3.getText());
+
+         rm1 = (TextMessage)cons.receive(2000);
+         assertNotNull(rm1);
+         assertEquals(rm1.getText(), tm4.getText());
+
+         checkEmpty(queue1);
+
+         conn1.close();
+
+         xconn1.close();
+
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            try
+            {
+               conn1.close();
+            }
+            catch (Exception e)
+            {
+               // Ignore
+            }
+         }
+
+         if (xconn1 != null)
+         {
+            try
+            {
+               xconn1.close();
+            }
+            catch (Exception e)
+            {
+               // Ignore
+            }
+         }
+      }
+   }
+
+   /*
+    * send 4 messages, start a XA transaction to receive. 
+    * In XA recovery, the messages will be re-sent without
+    * breaking the original order
+    */
+   public void testSimpleXATransactionalRecoveryCommitReceive() throws Exception
+   {
+      log.trace("starting testSimpleXATransactionalRecoveryCommitReceive");
+
+      Connection conn1 = null;
+
+      XAConnection xconn1 = null;
+
+      XAConnection xconn2 = null;
+
+      try
+      {
+         // First send a message to the queue
+         conn1 = cf.createConnection();
+
+         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         JBossMessageProducer prod = (JBossMessageProducer)sess1.createProducer(queue1);
+         // non-persistent will cause message lost in server failure
+         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+         prod.enableOrderingGroup("testSimpleXATransactionalRecoveryCommitReceive");
+
+         TextMessage tm1 = sess1.createTextMessage("tm1");
+         TextMessage tm2 = sess1.createTextMessage("tm2");
+         TextMessage tm3 = sess1.createTextMessage("tm3");
+         TextMessage tm4 = sess1.createTextMessage("tm4");
+
+         prod.send(tm1);
+         prod.send(tm2);
+         prod.send(tm3);
+         prod.send(tm4);
+
+         xconn1 = cf.createXAConnection();
+
+         XASession xsess1 = xconn1.createXASession();
+
+         XAResource res1 = xsess1.getXAResource();
+
+         // Pretend to be a transaction manager by interacting through the XAResources
+         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
+
+         res1.start(xid1, XAResource.TMNOFLAGS);
+
+         MessageConsumer cons = xsess1.createConsumer(queue1);
+
+         xconn1.start();
+
+         // Consume the message
+
+         TextMessage rm1 = (TextMessage)cons.receive(1000);
+
+         assertNotNull(rm1);
+
+         assertEquals(tm1.getText(), rm1.getText());
+
+         res1.end(xid1, XAResource.TMSUCCESS);
+
+         // prepare the tx
+
+         res1.prepare(xid1);
+
+         conn1.close();
+
+         xconn1.close();
+
+         conn1 = null;
+
+         xconn1 = null;
+
+         // Now "crash" the server
+
+         ServerManagement.stopServerPeer();
+
+         ServerManagement.startServerPeer();
+
+         deployAndLookupAdministeredObjects();
+
+         // Now recover
+
+         xconn2 = cf.createXAConnection();
+
+         XASession xsess2 = xconn2.createXASession();
+
+         XAResource res3 = xsess2.getXAResource();
+
+         Xid[] xids = res3.recover(XAResource.TMSTARTRSCAN);
+         assertEquals(1, xids.length);
+
+         Xid[] xids2 = res3.recover(XAResource.TMENDRSCAN);
+         assertEquals(0, xids2.length);
+
+         assertEquals(xid1, xids[0]);
+
+         // Commit the tx
+
+         res3.commit(xids[0], false);
+
+         // The message should be acknowldged
+
+         xconn2.close();
+
+         conn1 = cf.createConnection();
+
+         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageConsumer cons1 = sess1.createConsumer(queue1);
+
+         conn1.start();
+
+         // tm2, tm3, tm4 should be received.
+         TextMessage tmr = (TextMessage)cons1.receive(1000);
+         assertNotNull(tmr);
+         assertEquals(tmr.getText(), tm2.getText());
+
+         tmr = (TextMessage)cons1.receive(1000);
+         assertNotNull(tmr);
+         assertEquals(tmr.getText(), tm3.getText());
+
+         tmr = (TextMessage)cons1.receive(1000);
+         assertNotNull(tmr);
+         assertEquals(tmr.getText(), tm4.getText());
+
+         checkEmpty(queue1);
+
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            try
+            {
+               conn1.close();
+            }
+            catch (Exception e)
+            {
+               // Ignore
+            }
+         }
+
+         if (xconn1 != null)
+         {
+            try
+            {
+               xconn1.close();
+            }
+            catch (Exception e)
+            {
+               // Ignore
+            }
+         }
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Copied: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupConnectionConsumerTest.java (from rev 6820, branches/Branch_1416_merge/tests/src/org/jboss/test/messaging/jms/OrderingGroupConnectionConsumerTest.java)
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupConnectionConsumerTest.java	                        (rev 0)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupConnectionConsumerTest.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,466 @@
+/*
+ * 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.test.messaging.jms;
+
+import java.util.ArrayList;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import EDU.oswego.cs.dl.util.concurrent.Latch;
+
+import org.jboss.jms.client.JBossConnectionConsumer;
+import org.jboss.jms.client.JBossMessageProducer;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+/**
+ * A OrderingGroupConnectionConsumerTest
+ *
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ * 
+ * Created Oct 29, 2008 2:45:38 PM
+ *
+ *
+ */
+public class OrderingGroupConnectionConsumerTest extends JMSTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+   public OrderingGroupConnectionConsumerTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+   public void setUp() throws Exception
+   {
+      super.setUp();
+   }
+
+   public void tearDown() throws Exception
+   {
+      super.tearDown();
+      mList.clear();
+   }
+
+   /*
+    * Make sure the ordering group messages are received in order
+    * thru a ConnectionConsumer.
+    */
+   public void testSimpleReceive() throws Exception
+   {
+      if (ServerManagement.isRemote())
+         return;
+
+      Connection consumerConn = null;
+
+      Connection producerConn = null;
+
+      try
+      {
+         consumerConn = cf.createConnection();
+
+         consumerConn.start();
+
+         Session sessCons1 = consumerConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         OrderingGroupMessageListener listener = new OrderingGroupMessageListener(this);
+
+         sessCons1.setMessageListener(listener);
+
+         ServerSessionPool pool = new OrderingServerSessionPool(sessCons1);
+
+         JBossConnectionConsumer cc = (JBossConnectionConsumer)consumerConn.createConnectionConsumer(queue1,
+                                                                                                     null,
+                                                                                                     pool,
+                                                                                                     5);
+
+         producerConn = cf.createConnection();
+
+         Session sessProd = producerConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         JBossMessageProducer prod = (JBossMessageProducer)sessProd.createProducer(queue1);
+         prod.enableOrderingGroup(null);
+
+         forceGC();
+
+         for (int i = 0; i < NUM_MESSAGES; i++)
+         {
+            TextMessage m = sessProd.createTextMessage("testing" + i);
+            prod.send(m, Message.DEFAULT_DELIVERY_MODE, i % 10, Message.DEFAULT_TIME_TO_LIVE);
+         }
+
+         // waiting enough time to allow delivery complete.
+         msgLatch.attempt(10000);
+
+         // check the order
+         assertEquals(NUM_MESSAGES, mList.size());
+
+         for (int i = 0; i < NUM_MESSAGES; ++i)
+         {
+            TextMessage txm = mList.get(i);
+            assertEquals(txm.getText(), "testing" + i);
+         }
+
+         // allow consumer thread gracefully shutdown
+         doze(3000);
+
+         cc.close();
+
+         consumerConn.close();
+         consumerConn = null;
+         producerConn.close();
+         producerConn = null;
+      }
+      finally
+      {
+         if (consumerConn != null)
+            consumerConn.close();
+         if (producerConn != null)
+            producerConn.close();
+
+      }
+   }
+
+   /**
+    * @param i
+    */
+   private void doze(long nt)
+   {
+      try
+      {
+         Thread.sleep(nt);
+      }
+      catch (InterruptedException e)
+      {
+      }
+   }
+
+   /*
+    * Make sure the ordering group messages are received in order
+    * thru a ConnectionConsumer in transaction mode.
+    */
+
+   public void testTransactedReceive() throws Exception
+   {
+      if (ServerManagement.isRemote())
+         return;
+
+      Connection consumerConn = null;
+
+      Connection producerConn = null;
+
+      try
+      {
+         consumerConn = cf.createConnection();
+
+         consumerConn.start();
+
+         Session sessCons1 = consumerConn.createSession(true, Session.SESSION_TRANSACTED);
+
+         TxOrderingGroupMessageListener listener1 = new TxOrderingGroupMessageListener(this, sessCons1);
+
+         sessCons1.setMessageListener(listener1);
+
+         ServerSessionPool pool = new MockServerSessionPool(sessCons1);
+
+         JBossConnectionConsumer cc = (JBossConnectionConsumer)consumerConn.createConnectionConsumer(queue1,
+                                                                                                     null,
+                                                                                                     pool,
+                                                                                                     5);
+
+         producerConn = cf.createConnection();
+
+         Session sessProd = producerConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         JBossMessageProducer prod = (JBossMessageProducer)sessProd.createProducer(queue1);
+         prod.enableOrderingGroup(null);
+
+         forceGC();
+
+         for (int i = 0; i < NUM_MESSAGES; i++)
+         {
+            TextMessage m = sessProd.createTextMessage("testing" + i);
+            prod.send(m, Message.DEFAULT_DELIVERY_MODE, i % 10, Message.DEFAULT_TIME_TO_LIVE);
+         }
+
+         // waiting enough time to allow delivery complete.
+         msgLatch.attempt(10000);
+
+         // check the order
+         assertEquals(NUM_MESSAGES, mList.size());
+
+         for (int i = 0; i < NUM_MESSAGES; ++i)
+         {
+            TextMessage txm = mList.get(i);
+            assertEquals(txm.getText(), "testing" + i);
+         }
+
+         doze(3000);
+
+         cc.close();
+
+         consumerConn.close();
+         consumerConn = null;
+         producerConn.close();
+         producerConn = null;
+      }
+      finally
+      {
+         if (consumerConn != null)
+            consumerConn.close();
+         if (producerConn != null)
+            producerConn.close();
+
+      }
+   }
+
+   /*
+    * Make sure the ordering group messages are received in order
+    * thru a ConnectionConsumer in transaction mode, by two listeners.
+    */
+   public void testTransactedConcurrentReceive() throws Exception
+   {
+      if (ServerManagement.isRemote())
+         return;
+
+      Connection consumerConn = null;
+
+      Connection producerConn = null;
+
+      try
+      {
+         consumerConn = cf.createConnection();
+
+         consumerConn.start();
+
+         Session sessCons1 = consumerConn.createSession(true, Session.SESSION_TRANSACTED);
+         Session sessCons2 = consumerConn.createSession(true, Session.SESSION_TRANSACTED);
+
+         TxOrderingGroupMessageListener listener1 = new TxOrderingGroupMessageListener(this, sessCons1);
+         TxOrderingGroupMessageListener listener2 = new TxOrderingGroupMessageListener(this, sessCons2);
+
+         sessCons1.setMessageListener(listener1);
+         sessCons2.setMessageListener(listener2);
+
+         OrderingServerSessionPool pool = new OrderingServerSessionPool(sessCons1, sessCons2);
+
+         JBossConnectionConsumer cc = (JBossConnectionConsumer)consumerConn.createConnectionConsumer(queue1,
+                                                                                                     null,
+                                                                                                     pool,
+                                                                                                     5);
+
+         producerConn = cf.createConnection();
+
+         Session sessProd = producerConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         JBossMessageProducer prod = (JBossMessageProducer)sessProd.createProducer(queue1);
+         prod.enableOrderingGroup(null);
+
+         forceGC();
+
+         for (int i = 0; i < NUM_MESSAGES; i++)
+         {
+            TextMessage m = sessProd.createTextMessage("testing" + i);
+            prod.send(m, Message.DEFAULT_DELIVERY_MODE, i % 10, Message.DEFAULT_TIME_TO_LIVE);
+         }
+
+         // waiting enough time to allow delivery complete.
+         msgLatch.attempt(10000);
+
+         // check the order
+         assertEquals(NUM_MESSAGES, mList.size());
+
+         for (int i = 0; i < NUM_MESSAGES; ++i)
+         {
+            TextMessage txm = mList.get(i);
+            assertEquals(txm.getText(), "testing" + i);
+         }
+
+         doze(3000);
+
+         cc.close();
+
+         Session nSess = consumerConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer nCon = nSess.createConsumer(queue1);
+
+         Message mx = nCon.receive(500);
+         assertNull(mx);
+
+         consumerConn.close();
+         consumerConn = null;
+         producerConn.close();
+         producerConn = null;
+      }
+      finally
+      {
+         if (consumerConn != null)
+            consumerConn.close();
+         if (producerConn != null)
+            producerConn.close();
+
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+   Latch msgLatch = new Latch();
+
+   ArrayList<TextMessage> mList = new ArrayList<TextMessage>();
+
+   final int NUM_MESSAGES = 100;
+
+   // Inner classes -------------------------------------------------
+   class OrderingGroupMessageListener implements MessageListener
+   {
+
+      OrderingGroupConnectionConsumerTest owner;
+
+      OrderingGroupMessageListener(OrderingGroupConnectionConsumerTest theTest)
+      {
+         owner = theTest;
+      }
+
+      public synchronized void onMessage(Message message)
+      {
+         try
+         {
+            owner.addReceived((TextMessage)message);
+         }
+         catch (Exception e)
+         {
+            log.error(e);
+         }
+      }
+   }
+
+   class TxOrderingGroupMessageListener implements MessageListener
+   {
+
+      OrderingGroupConnectionConsumerTest owner;
+
+      long counter = 0;
+
+      Session sessRef;
+
+      TxOrderingGroupMessageListener(OrderingGroupConnectionConsumerTest theTest, Session sess)
+      {
+         owner = theTest;
+         sessRef = sess;
+      }
+
+      public synchronized void onMessage(Message message)
+      {
+         try
+         {
+            // roll back once for every 5 messages
+            if (counter % 5 == 0)
+            {
+               sessRef.rollback();
+            }
+            else
+            {
+               owner.addReceived((TextMessage)message);
+               sessRef.commit();
+            }
+            counter++;
+         }
+         catch (Exception e)
+         {
+            log.error(e);
+         }
+      }
+   }
+
+   class OrderingServerSessionPool implements ServerSessionPool
+   {
+      private ServerSession serverSession1;
+
+      private ServerSession serverSession2;
+
+      private long counter;
+
+      OrderingServerSessionPool(Session sess1, Session sess2)
+      {
+         serverSession1 = new MockServerSession(sess1);
+         serverSession2 = new MockServerSession(sess2);
+         counter = 0L;
+      }
+
+      /**
+       * @param sessCons1
+       */
+      public OrderingServerSessionPool(Session sessCons1)
+      {
+         serverSession1 = new MockServerSession(sessCons1);
+         serverSession2 = null;
+      }
+
+      public synchronized ServerSession getServerSession() throws JMSException
+      {
+         if (serverSession2 == null)
+         {
+            return serverSession1;
+         }
+
+         ServerSession result = serverSession2;
+         if (counter % 2 == 0)
+         {
+            result = serverSession1;
+         }
+         counter++;
+         return result;
+      }
+   }
+
+   /**
+    * here we do not synchronize because this is called from onMessage().
+    * It is guaranteed that next message won't arrive until the previous 
+    * message processing is finished (meaning onMessage() returns in auto-ack mode)
+    */
+   public void addReceived(TextMessage message)
+   {
+      mList.add(message);
+      if (mList.size() == NUM_MESSAGES)
+      {
+         msgLatch.release();
+      }
+   }
+
+}

Copied: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupGeneralTest.java (from rev 6820, branches/Branch_1416_merge/tests/src/org/jboss/test/messaging/jms/OrderingGroupGeneralTest.java)
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupGeneralTest.java	                        (rev 0)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupGeneralTest.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,863 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, 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.test.messaging.jms;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.jms.client.JBossMessageProducer;
+import org.jboss.jms.message.JBossMessage;
+
+/**
+ * This is additional tests for ordering group feature in 1.4. Other tests of ordering group
+ * are scattered in tests elsewhere that suitable for their test categories.
+ * 
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ *
+ */
+
+public class OrderingGroupGeneralTest extends JMSTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+   public OrderingGroupGeneralTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+   
+   /**
+    * nP --> 1C (multiple producers vs single client)
+    * create four producers from two connections and all send some message belonging
+    * to one same ordering group. check the receiving end that they are received orderly.
+    */
+   public void testMultipleProducersSingleClient() throws Exception
+   {
+      Connection conn1 = null;
+      Connection conn2 = null;
+      Connection conn3 = null;
+      
+      try
+      {
+         conn1 = cf.createConnection();         
+         conn2 = cf.createConnection();         
+         conn3 = cf.createConnection();         
+         
+         conn1.start();
+         conn2.start();
+         conn3.start();
+         
+         //two producers on conn1 and two more on conn2
+         JBossMessageProducer[] prods = new JBossMessageProducer[4];
+         Session sess1 = conn1.createSession(false, 0);
+         prods[0] = (JBossMessageProducer)sess1.createProducer(queue1);
+         prods[1] = (JBossMessageProducer)sess1.createProducer(queue1);
+         //now we do on different sessions 
+         Session sess2 = conn2.createSession(false, 0);
+         prods[2] = (JBossMessageProducer)sess2.createProducer(queue1);
+         Session sess3 = conn2.createSession(false, 0);
+         prods[3] = (JBossMessageProducer)sess3.createProducer(queue1);
+         
+         //enable ordering group
+         final String ORDER_GROUP_NAME = "SameOneGroup";
+         
+         prods[0].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[1].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[2].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[3].enableOrderingGroup(ORDER_GROUP_NAME);
+         
+         //creating and messages.
+         final int NUM_MSG = 200;
+         TextMessage[] testMsgs = new TextMessage[NUM_MSG];
+         Random rand = new Random();
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            testMsgs[i] = sess1.createTextMessage("ordering" + i);
+            //sending, in real world the order of sending may not be the order of arriving
+            //as the sending can be performed on different threads, processes or machines.
+            //but in test we need to know beforehand the order so that we can verify.
+            int indx = rand.nextInt(4);
+            int priority = rand.nextInt(10);
+            prods[indx].send(testMsgs[i], DeliveryMode.PERSISTENT, priority, 0);
+         }
+         
+         //receiving and verifying
+         Session session = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = session.createConsumer(queue1);
+         
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            TextMessage rm = (TextMessage)cons.receive(500);
+            assertNotNull(rm);
+            assertEquals("ordering" + i, rm.getText());
+         }
+
+         checkEmpty(queue1);
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            conn1.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+         if (conn3 != null)
+         {
+            conn3.close();
+         }
+      }
+   }
+
+   /**
+    * 1P --> nC (multiple producers vs multiple clients)
+    * create one producer send some messages belonging
+    * to one same ordering group. Receive them by two clients of different modes.
+    * check the receiving end that they are received orderly.
+    */
+   public void testOneProducersMultipleClient() throws Exception
+   {
+      Connection conn1 = null;
+
+      Connection conn2 = null;
+      Connection conn3 = null;
+      
+      try
+      {
+         conn1 = cf.createConnection();         
+
+         conn2 = cf.createConnection();         
+         conn3 = cf.createConnection();         
+         
+         conn1.start();
+
+         
+         //two producers on conn1 and two more on conn2
+         JBossMessageProducer[] prods = new JBossMessageProducer[1];
+         Session sess1 = conn1.createSession(false, 0);
+         prods[0] = (JBossMessageProducer)sess1.createProducer(queue1);
+         
+         //enable ordering group
+         final String ORDER_GROUP_NAME = "SameOneGroup";
+         
+         prods[0].enableOrderingGroup(ORDER_GROUP_NAME);
+         
+         //creating and messages.
+         final int NUM_MSG = 200;
+         TextMessage[] testMsgs = new TextMessage[NUM_MSG];
+         Random rand = new Random();
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            testMsgs[i] = sess1.createTextMessage("ordering" + i);
+            int priority = rand.nextInt(10);
+            prods[0].send(testMsgs[i], DeliveryMode.PERSISTENT, priority, 0);
+         }
+         
+         //receiving and verifying
+         Session session = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons1 = session.createConsumer(queue1);
+         cons1.setMessageListener(new MsgOrderListener(true));
+         
+         Session session2 = conn3.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+         MessageConsumer cons2 = session2.createConsumer(queue1);
+         cons2.setMessageListener(new MsgOrderListener(false));
+         
+         conn2.start();
+         conn3.start();
+
+         //delay for 10 sec, let delivery over
+         delay(10000);
+         
+         checkEmpty(queue1);
+         
+         //check the order now.
+         assertEquals(NUM_MSG, rcvBuffer.size());
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            assertEquals("ordering" + i, rcvBuffer.get(i).getText());
+         }
+         
+         rcvBuffer.clear();
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            conn1.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+         if (conn3 != null)
+         {
+            conn3.close();
+         }
+      }
+   }
+
+   /**
+    * nP --> nC (multiple producers vs multiple clients)
+    * create four producers from two connections and all send some message belonging
+    * to one same ordering group. Receive them by two clients of different modes.
+    * check the receiving end that they are received orderly.
+    */
+   public void testMultipleProducersMultipleClients() throws Exception
+   {
+      Connection conn1 = null;
+      Connection conn2 = null;
+      Connection conn3 = null;
+      Connection conn4 = null;
+      
+      try
+      {
+         conn1 = cf.createConnection();         
+         conn2 = cf.createConnection();         
+         conn3 = cf.createConnection();         
+         conn4 = cf.createConnection();         
+         
+         conn1.start();
+         conn2.start();
+         
+         //two producers on conn1 and two more on conn2
+         JBossMessageProducer[] prods = new JBossMessageProducer[4];
+         Session sess1 = conn1.createSession(false, 0);
+         prods[0] = (JBossMessageProducer)sess1.createProducer(queue1);
+         prods[1] = (JBossMessageProducer)sess1.createProducer(queue1);
+         //now we do on different sessions 
+         Session sess2 = conn2.createSession(false, 0);
+         prods[2] = (JBossMessageProducer)sess2.createProducer(queue1);
+         Session sess3 = conn2.createSession(false, 0);
+         prods[3] = (JBossMessageProducer)sess3.createProducer(queue1);
+         
+         //enable ordering group
+         final String ORDER_GROUP_NAME = "SameOneGroup";
+         
+         prods[0].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[1].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[2].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[3].enableOrderingGroup(ORDER_GROUP_NAME);
+         
+         //creating and messages.
+         final int NUM_MSG = 200;
+         TextMessage[] testMsgs = new TextMessage[NUM_MSG];
+         Random rand = new Random();
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            testMsgs[i] = sess1.createTextMessage("ordering" + i);
+            //sending, in real world the order of sending may not be the order of arriving
+            //as the sending can be performed on different threads, processes or machines.
+            //but in test we need to know beforehand the order so that we can verify.
+            int indx = rand.nextInt(4);
+            int priority = rand.nextInt(10);
+            prods[indx].send(testMsgs[i], DeliveryMode.PERSISTENT, priority, 0);
+         }
+         
+         //receiving and verifying
+         Session session = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons1 = session.createConsumer(queue1);
+         cons1.setMessageListener(new MsgOrderListener(true));
+         
+         Session session2 = conn4.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+         MessageConsumer cons2 = session2.createConsumer(queue1);
+         cons2.setMessageListener(new MsgOrderListener(false));
+         
+         conn3.start();
+         conn4.start();
+
+         //delay for 10 sec, let delivery over
+         delay(10000);
+         
+         checkEmpty(queue1);
+         
+         //check the order now.
+         assertEquals(NUM_MSG, rcvBuffer.size());
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            assertEquals("ordering" + i, rcvBuffer.get(i).getText());
+         }
+         
+         rcvBuffer.clear();
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            conn1.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+         if (conn3 != null)
+         {
+            conn3.close();
+         }
+         if (conn4 != null)
+         {
+            conn4.close();
+         }
+      }
+   }
+   
+   /**
+    * four producers, two ordering groups, one client
+    */
+   public void testMultipleProducersInMultiGroups() throws Exception
+   {
+      Connection conn1 = null;
+      Connection conn2 = null;
+      Connection conn3 = null;
+      
+      try
+      {
+         conn1 = cf.createConnection();         
+         conn2 = cf.createConnection();         
+         conn3 = cf.createConnection();         
+         
+         conn1.start();
+         conn2.start();
+         
+         //two producers on conn1 and two more on conn2
+         JBossMessageProducer[] prods = new JBossMessageProducer[4];
+         Session sess1 = conn1.createSession(false, 0);
+         prods[0] = (JBossMessageProducer)sess1.createProducer(queue1);
+         prods[1] = (JBossMessageProducer)sess1.createProducer(queue1);
+         //now we do on different sessions 
+         Session sess2 = conn2.createSession(false, 0);
+         prods[2] = (JBossMessageProducer)sess2.createProducer(queue1);
+         Session sess3 = conn2.createSession(false, 0);
+         prods[3] = (JBossMessageProducer)sess3.createProducer(queue1);
+         
+         //enable ordering group
+         final String ORDER_GROUP_NAME1 = "SameOneGroup1";
+         final String ORDER_GROUP_NAME2 = "SameOneGroup2";
+         
+         prods[0].enableOrderingGroup(ORDER_GROUP_NAME1);
+         prods[1].enableOrderingGroup(ORDER_GROUP_NAME2);
+         prods[2].enableOrderingGroup(ORDER_GROUP_NAME1);
+         prods[3].enableOrderingGroup(ORDER_GROUP_NAME2);
+         
+         //creating and messages.
+         final int NUM_MSG = 100;
+         TextMessage[] testMsgs1 = new TextMessage[NUM_MSG];
+         TextMessage[] testMsgs2 = new TextMessage[NUM_MSG];
+
+         Random rand = new Random();
+         int i1 = 0;
+         int i2 = 0;
+         boolean dowork1 = true;
+         boolean dowork2 = true;
+         
+         while( dowork1 || dowork2 )
+         {
+            //sending, make sending random, to see if two groups interfere each other
+
+            boolean first = rand.nextBoolean();
+            int indx = rand.nextInt(2);
+            int priority = rand.nextInt(10);
+
+            if (first && dowork1)
+            {
+               testMsgs1[i1] = sess1.createTextMessage("ordering" + i1);
+               //sending group 1
+               if (indx == 0)
+               {
+                  prods[0].send(testMsgs1[i1], DeliveryMode.PERSISTENT, priority, 0);
+               }
+               else
+               {
+                  prods[2].send(testMsgs1[i1], DeliveryMode.PERSISTENT, priority, 0);
+               }
+               i1++;
+               if (i1 >= NUM_MSG)
+               {
+                  dowork1 = false;
+               }
+            }
+            else if (dowork2)
+            {
+               testMsgs2[i2] = sess1.createTextMessage("ordering" + i2);
+               //sending group2
+               if (indx == 0)
+               {
+                  prods[1].send(testMsgs2[i2], DeliveryMode.PERSISTENT, priority, 0);
+               }
+               else
+               {
+                  prods[3].send(testMsgs2[i2], DeliveryMode.PERSISTENT, priority, 0);
+               }
+               i2++;
+               if (i2 >= NUM_MSG)
+               {
+                  dowork2 = false;
+               }
+            }
+         }
+
+         //receiving and verifying
+         Session session = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer cons = session.createConsumer(queue1);
+
+         conn3.start();
+         
+         ArrayList<TextMessage> rGroup1 = new ArrayList<TextMessage>();
+         ArrayList<TextMessage> rGroup2 = new ArrayList<TextMessage>();
+
+         for (int i = 0; i < NUM_MSG*2; i++)
+         {
+            TextMessage rm = (TextMessage)cons.receive(2000);
+            assertNotNull(rm);
+            
+            if (isGroup(rm, ORDER_GROUP_NAME1))
+            {
+               rGroup1.add(rm);
+            }
+            else if (isGroup(rm, ORDER_GROUP_NAME2))
+            {
+               rGroup2.add(rm);
+            }
+            else
+            {
+               fail("message " + rm.getText() + " doesn't belong any ordering group.");
+            }
+         }
+         
+         //check ordering
+         assertEquals(NUM_MSG, rGroup1.size());
+         assertEquals(NUM_MSG, rGroup2.size());
+
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            TextMessage rm1 = rGroup1.get(i);
+            TextMessage rm2 = rGroup2.get(i);
+            
+            assertEquals("ordering" + i, rm1.getText());
+            assertEquals("ordering" + i, rm2.getText());
+         }
+         
+         checkEmpty(queue1);
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            conn1.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+         if (conn3 != null)
+         {
+            conn3.close();
+         }
+      }      
+   }
+
+   /**
+    * nP --> nC (multiple producers vs multiple clients in transaction mode)
+    * create four producers from two connections and all send some message belonging
+    * to one same ordering group. Receive them by two clients of different modes.
+    * check the receiving end that they are received orderly.
+    */
+   public void testMultipleProducersMultipleTxClients() throws Exception
+   {
+      Connection conn1 = null;
+      Connection conn2 = null;
+      Connection conn3 = null;
+      Connection conn4 = null;
+      
+      try
+      {
+         conn1 = cf.createConnection();         
+         conn2 = cf.createConnection();         
+         conn3 = cf.createConnection();         
+         conn4 = cf.createConnection();         
+         
+         conn1.start();
+         conn2.start();
+         
+         //two producers on conn1 and two more on conn2
+         JBossMessageProducer[] prods = new JBossMessageProducer[4];
+         Session sess1 = conn1.createSession(false, 0);
+         prods[0] = (JBossMessageProducer)sess1.createProducer(queue1);
+         prods[1] = (JBossMessageProducer)sess1.createProducer(queue1);
+         //now we do on different sessions 
+         Session sess2 = conn2.createSession(false, 0);
+         prods[2] = (JBossMessageProducer)sess2.createProducer(queue1);
+         Session sess3 = conn2.createSession(false, 0);
+         prods[3] = (JBossMessageProducer)sess3.createProducer(queue1);
+         
+         //enable ordering group
+         final String ORDER_GROUP_NAME = "SameOneGroup";
+         
+         prods[0].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[1].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[2].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[3].enableOrderingGroup(ORDER_GROUP_NAME);
+         
+         //creating and messages.
+         final int NUM_MSG = 200;
+         TextMessage[] testMsgs = new TextMessage[NUM_MSG];
+         Random rand = new Random();
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            testMsgs[i] = sess1.createTextMessage("ordering" + i);
+            //sending, in real world the order of sending may not be the order of arriving
+            //as the sending can be performed on different threads, processes or machines.
+            //but in test we need to know beforehand the order so that we can verify.
+            int indx = rand.nextInt(4);
+            int priority = rand.nextInt(10);
+            prods[indx].send(testMsgs[i], DeliveryMode.PERSISTENT, priority, 0);
+         }
+         
+         //receiving and verifying
+         MsgReceiverThread thread1 = new MsgReceiverThread(conn3, queue1, true, 1);
+         MsgReceiverThread thread2 = new MsgReceiverThread(conn4, queue1, true, 20); //slow one
+         
+         conn3.start();
+         conn4.start();
+         
+         thread1.start();
+         thread2.start();
+
+         thread1.join();
+         thread2.join();
+         
+         checkEmpty(queue1);
+         
+         //check the order now.
+         assertEquals(NUM_MSG, rcvBuffer1.size());
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            assertEquals("ordering" + i, rcvBuffer1.get(i).getText());
+         }
+         
+         rcvBuffer1.clear();
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            conn1.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+         if (conn3 != null)
+         {
+            conn3.close();
+         }
+         if (conn4 != null)
+         {
+            conn4.close();
+         }
+      }
+   }
+
+   /**
+    * nP --> nC (multiple producers vs multiple clients in client-ack mode)
+    * create four producers from two connections and all send some message belonging
+    * to one same ordering group. Receive them by two clients of different modes.
+    * check the receiving end that they are received orderly.
+    */
+   public void testMultipleProducersMultipleClientAckClients() throws Exception
+   {
+      Connection conn1 = null;
+      Connection conn2 = null;
+      Connection conn3 = null;
+      Connection conn4 = null;
+      
+      try
+      {
+         conn1 = cf.createConnection();         
+         conn2 = cf.createConnection();         
+         conn3 = cf.createConnection();         
+         conn4 = cf.createConnection();         
+         
+         conn1.start();
+         conn2.start();
+         
+         //two producers on conn1 and two more on conn2
+         JBossMessageProducer[] prods = new JBossMessageProducer[4];
+         Session sess1 = conn1.createSession(false, 0);
+         prods[0] = (JBossMessageProducer)sess1.createProducer(queue1);
+         prods[1] = (JBossMessageProducer)sess1.createProducer(queue1);
+         //now we do on different sessions 
+         Session sess2 = conn2.createSession(false, 0);
+         prods[2] = (JBossMessageProducer)sess2.createProducer(queue1);
+         Session sess3 = conn2.createSession(false, 0);
+         prods[3] = (JBossMessageProducer)sess3.createProducer(queue1);
+         
+         //enable ordering group
+         final String ORDER_GROUP_NAME = "SameOneGroup";
+         
+         prods[0].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[1].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[2].enableOrderingGroup(ORDER_GROUP_NAME);
+         prods[3].enableOrderingGroup(ORDER_GROUP_NAME);
+         
+         //creating and messages.
+         final int NUM_MSG = 200;
+         TextMessage[] testMsgs = new TextMessage[NUM_MSG];
+         Random rand = new Random();
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            testMsgs[i] = sess1.createTextMessage("ordering" + i);
+            //sending, in real world the order of sending may not be the order of arriving
+            //as the sending can be performed on different threads, processes or machines.
+            //but in test we need to know beforehand the order so that we can verify.
+            int indx = rand.nextInt(4);
+            int priority = rand.nextInt(10);
+            prods[indx].send(testMsgs[i], DeliveryMode.PERSISTENT, priority, 0);
+         }
+         
+         //receiving and verifying
+         MsgReceiverThread thread1 = new MsgReceiverThread(conn3, queue1, false, 1);
+         MsgReceiverThread thread2 = new MsgReceiverThread(conn4, queue1, false, 10); //slow one
+         
+         conn3.start();
+         conn4.start();
+         
+         thread1.start();
+         thread2.start();
+
+         thread1.join();
+         thread2.join();
+         
+         checkEmpty(queue1);
+         
+         //check the order now.
+         assertEquals(NUM_MSG, rcvBuffer1.size());
+         for (int i = 0; i < NUM_MSG; i++)
+         {
+            assertEquals("ordering" + i, rcvBuffer1.get(i).getText());
+         }
+         
+         rcvBuffer1.clear();
+      }
+      finally
+      {
+         if (conn1 != null)
+         {
+            conn1.close();
+         }
+         if (conn2 != null)
+         {
+            conn2.close();
+         }
+         if (conn3 != null)
+         {
+            conn3.close();
+         }
+         if (conn4 != null)
+         {
+            conn4.close();
+         }
+      }
+   }
+
+   /**
+    * @param rm
+    * @param order_group_name1
+    * @return
+    * @throws JMSException 
+    */
+   private boolean isGroup(TextMessage rm, String name) throws JMSException
+   {
+      String grpName = rm.getStringProperty(JBossMessage.JBOSS_MESSAGING_ORDERING_GROUP_ID);
+      assertNotNull(grpName);
+      
+      return grpName.equals(name);
+   }
+
+   public void testMultipleProducersInOneGroupTx()
+   {
+      
+   }
+   
+   public void testMultipleProducersInMultiGroupsTx()
+   {
+      
+   }
+   
+   public void delay(long t)
+   {
+      try
+      {
+         Thread.sleep(t);
+      }
+      catch (InterruptedException e)
+      {
+         e.printStackTrace();
+      }
+   }
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+   private static ArrayList<TextMessage> rcvBuffer = new ArrayList<TextMessage>();
+   private static ArrayList<TextMessage> rcvBuffer1 = new ArrayList<TextMessage>();
+   
+   public class MsgOrderListener implements MessageListener
+   {
+      
+      private boolean autoAck;
+
+      public MsgOrderListener(boolean isAutoAck)
+      {
+         autoAck = isAutoAck;
+      }
+
+      public void onMessage(Message msg)
+      {
+         synchronized(rcvBuffer)
+         {
+            rcvBuffer.add((TextMessage)msg);
+         }
+         
+         if (!autoAck)
+         {
+            delay(50);
+            try
+            {
+               msg.acknowledge();
+            }
+            catch (JMSException e)
+            {
+               fail("Acknowledge failed. ");
+            }
+         }
+      }
+   }
+   
+   public class MsgReceiverThread extends Thread
+   {
+
+      Connection conn;
+      Queue dest;
+      boolean isTx;
+      int delay;
+      
+      public MsgReceiverThread(Connection conn, Queue dest, boolean isTx, int delay)
+      {
+         this.conn = conn;
+         this.dest = dest;
+         this.isTx = isTx;
+         this.delay = delay;
+      }
+      
+      //receiving message, it rollbacks somtimes.
+      //stop when timeout
+      public void run()
+      {
+         Session session;
+         try
+         {
+            Random rand = new Random();
+            
+            session = conn.createSession(isTx, isTx ? Session.SESSION_TRANSACTED : Session.CLIENT_ACKNOWLEDGE);
+            MessageConsumer cons = session.createConsumer(dest);
+            
+            //if we can't receive a msg in 10 sec, we think no message available
+            //either all messages has been received, or something wrong.
+            TextMessage rm = (TextMessage)cons.receive(10000);
+            while (rm != null)
+            {
+               delay(delay);//indicate how fast a receiver can be
+               if (isTx)
+               {
+                  int rbIdx = rand.nextInt(4);
+                  //%25 change of rollback
+                  if ( rbIdx == 1 )
+                  {
+                     //roll back
+                     session.rollback();
+                  }
+                  else
+                  {
+                     synchronized(rcvBuffer1)
+                     {
+                        rcvBuffer1.add(rm);
+                     }
+                     session.commit();
+                  }
+               }
+               else
+               {
+                  int recoverIdx = rand.nextInt(4);
+                  //%25 chance of recover
+                  if (recoverIdx == 0)
+                  {
+                     //redeliver
+                     session.recover();
+                  }
+                  else
+                  {
+                     //ok
+                     synchronized(rcvBuffer1)
+                     {
+                        rcvBuffer1.add(rm);
+                     }
+                     rm.acknowledge();
+                  }
+               }
+               
+               rm = (TextMessage)cons.receive(10000);
+            }
+            //receive finish, thread ends.
+         }
+         catch (JMSException e)
+         {
+            e.printStackTrace();
+            fail("Exception in MsgReceiverThread");
+         }
+      }
+   }
+
+}

Copied: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java (from rev 6820, branches/Branch_1416_merge/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java)
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java	                        (rev 0)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/OrderingGroupMiscTest.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,493 @@
+/*
+ * 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.test.messaging.jms;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.management.ObjectName;
+
+import org.jboss.jms.client.JBossMessageProducer;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+/**
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ */
+public class OrderingGroupMiscTest extends JMSTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+   private HashMap<String, ArrayList<TextMessage>> recvBuffer = new HashMap<String, ArrayList<TextMessage>>();
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+   public OrderingGroupMiscTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+
+   /*
+    * Sending 5 messages and letting the 3rd and 5th messages go to dlq and 
+    * the others (1st, 2nd and 4th) should go to the receiver
+    */
+   public void testOrderingWithDLQ() throws Exception
+   {
+      if (ServerManagement.isRemote())
+      {
+         return;
+      }
+
+      final int NUM_MESSAGES = 5;
+
+      final int MAX_DELIVERIES = 8;
+
+      ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
+
+      String testQueueObjectName = "jboss.messaging.destination:service=Queue,name=Queue1";
+
+      Connection conn = null;
+
+      try
+      {
+         String defaultDLQObjectName = "jboss.messaging.destination:service=Queue,name=Queue2";
+
+         ServerManagement.setAttribute(serverPeerObjectName,
+                                       "DefaultMaxDeliveryAttempts",
+                                       String.valueOf(MAX_DELIVERIES));
+
+         ServerManagement.setAttribute(serverPeerObjectName, "DefaultDLQ", defaultDLQObjectName);
+
+         ServerManagement.setAttribute(new ObjectName(testQueueObjectName), "DLQ", "");
+
+         conn = cf.createConnection();
+
+         {
+            Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            JBossMessageProducer prod = (JBossMessageProducer)sess.createProducer(queue1);
+
+            for (int i = 0; i < NUM_MESSAGES; i++)
+            {
+               TextMessage tm = sess.createTextMessage("Message:" + i);
+
+               prod.send(tm);
+            }
+
+            Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+            MessageConsumer cons = sess2.createConsumer(queue1);
+
+            conn.start();
+
+            // first
+            TextMessage rm1 = (TextMessage)cons.receive(1000);
+            assertNotNull(rm1);
+            assertEquals("Message:0", rm1.getText());
+            rm1.acknowledge();
+
+            // second
+            TextMessage rm2 = (TextMessage)cons.receive(1000);
+            assertNotNull(rm2);
+            assertEquals("Message:1", rm2.getText());
+            rm2.acknowledge();
+
+            // third, leaving a hole
+            for (int i = 0; i < MAX_DELIVERIES; i++)
+            {
+               TextMessage rm3 = (TextMessage)cons.receive(1000);
+               assertNotNull(rm3);
+               assertEquals("Message:2", rm3.getText());
+               sess2.recover();
+            }
+
+            // fourth
+            TextMessage rm4 = (TextMessage)cons.receive(1000);
+            assertNotNull(rm4);
+            assertEquals("Message:3", rm4.getText());
+            rm4.acknowledge();
+
+            // fifth, leaving another hole
+            for (int i = 0; i < MAX_DELIVERIES; i++)
+            {
+               TextMessage rm5 = (TextMessage)cons.receive(1000);
+               assertNotNull(rm5);
+               assertEquals("Message:4", rm5.getText());
+               sess2.recover();
+            }
+
+            TextMessage rmx = (TextMessage)cons.receive(1000);
+            assertNull(rmx);
+
+            // At this point all the messages have been delivered exactly MAX_DELIVERIES times
+
+            checkEmpty(queue1);
+
+            // Now should be in default dlq
+            MessageConsumer cons3 = sess.createConsumer(queue2);
+
+            TextMessage dm3 = (TextMessage)cons3.receive(1000);
+            assertNotNull(dm3);
+            assertEquals("Message:2", dm3.getText());
+
+            TextMessage dm5 = (TextMessage)cons3.receive(1000);
+            assertNotNull(dm5);
+            assertEquals("Message:4", dm5.getText());
+
+            conn.close();
+         }
+      }
+      finally
+      {
+         ServerManagement.setAttribute(serverPeerObjectName,
+                                       "DefaultDLQ",
+                                       "jboss.messaging.destination:service=Queue,name=DLQ");
+
+         ServerManagement.setAttribute(new ObjectName(testQueueObjectName), "DLQ", "");
+
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   /*
+    * Sending 5 messages and letting the 3rd and 5th messages expire and 
+    * the others (1st, 2nd and 4th) should go to the receiver
+    */
+   public void testOrderingWithExpiryQueue() throws Exception
+   {
+      final int NUM_MESSAGES = 5;
+
+      Connection conn = null;
+
+      ObjectName serverPeerObjectName = ServerManagement.getServerPeerObjectName();
+
+      try
+      {
+         ServerManagement.deployQueue("DefaultExpiry");
+
+         ServerManagement.deployQueue("TestOrderingQueue");
+
+         String defaultExpiryObjectName = "jboss.messaging.destination:service=Queue,name=DefaultExpiry";
+
+         String testQueueObjectName = "jboss.messaging.destination:service=Queue,name=TestOrderingQueue";
+
+         ServerManagement.setAttribute(serverPeerObjectName, "DefaultExpiryQueue", defaultExpiryObjectName);
+
+         ServerManagement.setAttribute(new ObjectName(testQueueObjectName), "ExpiryQueue", "");
+
+         Queue testQueue = (Queue)ic.lookup("/queue/TestOrderingQueue");
+
+         Queue defaultExpiry = (Queue)ic.lookup("/queue/DefaultExpiry");
+
+         conn = cf.createConnection();
+
+         {
+            Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            JBossMessageProducer prod = (JBossMessageProducer)sess.createProducer(testQueue);
+
+            conn.start();
+
+            for (int i = 0; i < NUM_MESSAGES; i++)
+            {
+               TextMessage tm = sess.createTextMessage("Message:" + i);
+
+               if (i == 2 || i == 4)
+               {
+                  // Send messages with time to live of 2000 enough time to get to client consumer - so
+                  // they won't be expired on the server side
+                  prod.send(tm, DeliveryMode.PERSISTENT, 4, 2000);
+               }
+               else
+               {
+                  prod.send(tm);
+               }
+            }
+
+            Session sess2 = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+            MessageConsumer cons = sess2.createConsumer(testQueue);
+
+            // The messages should now be sitting in the consumer buffer
+            // Now give them enough time to expire
+            Thread.sleep(2500);
+
+            // this moment, only first message is delivered but waiting for ack.
+            // 3rd and 5th message still in queue, but when they are delivered
+            // they will be expired and won't be received by this consumer.
+            TextMessage rm1 = (TextMessage)cons.receive(1000);
+            assertNotNull(rm1);
+            assertEquals("Message:0", rm1.getText());
+            rm1.acknowledge();
+
+            TextMessage rm2 = (TextMessage)cons.receive(1000);
+            assertNotNull(rm2);
+            assertEquals("Message:1", rm2.getText());
+            rm2.acknowledge();
+
+            TextMessage rm3 = (TextMessage)cons.receive(1000);
+            assertNotNull(rm3);
+            assertEquals("Message:3", rm3.getText());
+            rm3.acknowledge();
+
+            TextMessage rm4 = (TextMessage)cons.receive(1000);
+            assertNull(rm4);
+
+            // Message should all be in the default expiry queue - let's check
+
+            MessageConsumer cons3 = sess.createConsumer(defaultExpiry);
+
+            TextMessage dm1 = (TextMessage)cons3.receive(1000);
+            assertNotNull(dm1);
+            assertEquals("Message:2", dm1.getText());
+
+            TextMessage dm2 = (TextMessage)cons3.receive(1000);
+            assertNotNull(dm2);
+            assertEquals("Message:4", dm2.getText());
+
+            conn.close();
+         }
+
+      }
+      finally
+      {
+         ServerManagement.setAttribute(serverPeerObjectName,
+                                       "DefaultExpiryQueue",
+                                       "jboss.messaging.destination:service=Queue,name=ExpiryQueue");
+
+         ServerManagement.undeployQueue("DefaultExpiry");
+
+         ServerManagement.undeployQueue("TestOrderingQueue");
+
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   /*
+    * First send 2 normal messages, then send 10 ordering messages with some priority and 
+    * then disable ordering, then send 2 more normal messages with high
+    * priority. Make sure the normal messages are received first
+    * and the ordered messages are received later but ordered.
+    */
+   public void testOrderingGroupOnOff() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+         conn = cf.createConnection();
+
+         Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+         JBossMessageProducer producer = (JBossMessageProducer)producerSess.createProducer(queue1);
+
+         conn.start();
+
+         TextMessage tmNormal1 = producerSess.createTextMessage("NoOrdering-1");
+         producer.send(tmNormal1, DeliveryMode.PERSISTENT, 6, Message.DEFAULT_TIME_TO_LIVE);
+         TextMessage tmNormal2 = producerSess.createTextMessage("NoOrdering-2");
+         producer.send(tmNormal2, DeliveryMode.PERSISTENT, 7, Message.DEFAULT_TIME_TO_LIVE);
+
+         producer.enableOrderingGroup(null);
+         // sending out ordering messages with priorities ranging from 0 to 5;
+         for (int i = 0; i < 10; i++)
+         {
+            TextMessage tm = producerSess.createTextMessage("Ordering" + i);
+            producer.send(tm, DeliveryMode.PERSISTENT, i % 6, Message.DEFAULT_TIME_TO_LIVE);
+         }
+
+         producer.disableOrderingGroup();
+
+         TextMessage tmNormal3 = producerSess.createTextMessage("NoOrdering-3");
+         producer.send(tmNormal3, DeliveryMode.PERSISTENT, 8, Message.DEFAULT_TIME_TO_LIVE);
+         TextMessage tmNormal4 = producerSess.createTextMessage("NoOrdering-4");
+         producer.send(tmNormal4, DeliveryMode.PERSISTENT, 9, Message.DEFAULT_TIME_TO_LIVE);
+
+         Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+         MessageConsumer consumer = consumerSess.createConsumer(queue1);
+
+         TextMessage rmNormal = (TextMessage)consumer.receive(1000);
+         assertNotNull(rmNormal);
+         assertEquals("NoOrdering-4", rmNormal.getText());
+
+         rmNormal = (TextMessage)consumer.receive(1000);
+         assertNotNull(rmNormal);
+         assertEquals("NoOrdering-3", rmNormal.getText());
+
+         rmNormal = (TextMessage)consumer.receive(1000);
+         assertNotNull(rmNormal);
+         assertEquals("NoOrdering-2", rmNormal.getText());
+
+         rmNormal = (TextMessage)consumer.receive(1000);
+         assertNotNull(rmNormal);
+         assertEquals("NoOrdering-1", rmNormal.getText());
+
+         for (int i = 0; i < 10; i++)
+         {
+            TextMessage rm = (TextMessage)consumer.receive(1000);
+            assertNotNull(rm);
+            assertEquals("Ordering" + i, rm.getText());
+            rm.acknowledge();
+         }
+
+         assertNull(consumer.receive(1000));
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   /*
+    * create 10 ordering groups, each sending 100 messages
+    * make sure the order of each group is guaranteed.
+    */
+   public void testMultipleOrderingGroups() throws Exception
+   {
+
+      final int NUM_PRODUCERS = 10;
+      final int NUM_MSG = 100;
+      JBossMessageProducer[] prods = new JBossMessageProducer[NUM_PRODUCERS];
+      Connection conn = null;
+
+      try
+      {
+         conn = cf.createConnection();
+
+         Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         for (int i = 0; i < NUM_PRODUCERS; i++)
+         {
+            prods[i] = (JBossMessageProducer)producerSess.createProducer(queue1);
+            prods[i].enableOrderingGroup(null);
+         }
+
+         Session consumerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer consumer = consumerSess.createConsumer(queue1);
+         conn.start();
+
+         // Send some messages
+         for (int i = 0; i < NUM_PRODUCERS; i++)
+         {
+            String key = prepareReceivingBuffer(i);
+            for (int j = 0; j < NUM_MSG; j++)
+            {
+               TextMessage tm = producerSess.createTextMessage(key + ":" + j);
+               prods[i].send(tm, DeliveryMode.PERSISTENT, j % 10, Message.DEFAULT_TIME_TO_LIVE);
+            }
+         }
+
+         assertEquals(NUM_PRODUCERS, recvBuffer.size());
+
+         log.trace("Sent messages");
+
+         while (true)
+         {
+            TextMessage rm = (TextMessage)consumer.receive(1000);
+            if (rm == null)
+               break;
+            putToBuffer(rm);
+         }
+
+         for (int i = 0; i < NUM_PRODUCERS; ++i)
+         {
+            String key = "ordering-" + i;
+            ArrayList<TextMessage> group = recvBuffer.get(key);
+            assertEquals(NUM_MSG, group.size());
+            for (int j = 0; j < NUM_MSG; ++j)
+            {
+               TextMessage rm = group.get(j);
+               assertEquals(key + ":" + j, rm.getText());
+            }
+         }
+
+         // make sure I don't receive anything else
+
+         checkEmpty(queue1);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   /**
+    * @param rm
+    * @throws JMSException 
+    */
+   private void putToBuffer(TextMessage rm) throws JMSException
+   {
+      String text = rm.getText();
+      String[] tokens = text.split(":");
+      String key = tokens[0];
+      ArrayList<TextMessage> group = recvBuffer.get(key);
+      group.add(rm);
+   }
+
+   /**
+    * initialize a buffer for receiving ordering group messages.
+    * @param i
+    */
+   private String prepareReceivingBuffer(int i)
+   {
+      String key = "ordering-" + i;
+      ArrayList<TextMessage> grpBuffer = recvBuffer.get(key);
+      if (grpBuffer == null)
+      {
+         grpBuffer = new ArrayList<TextMessage>();
+         recvBuffer.put(key, grpBuffer);
+      }
+      return key;
+   }
+
+   // Inner classes -------------------------------------------------
+}

Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java	2009-05-16 08:01:55 UTC (rev 6820)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -22,6 +22,7 @@
 package org.jboss.test.messaging.jms.bridge;
 
 import org.jboss.jms.server.bridge.Bridge;
+import org.jboss.jms.server.bridge.BridgeService;
 import org.jboss.logging.Logger;
 import org.jboss.test.messaging.tools.ServerManagement;
 

Copied: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/message/JMSOrderingGroupPropertyTest.java (from rev 6820, branches/Branch_1416_merge/tests/src/org/jboss/test/messaging/jms/message/JMSOrderingGroupPropertyTest.java)
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/message/JMSOrderingGroupPropertyTest.java	                        (rev 0)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/message/JMSOrderingGroupPropertyTest.java	2009-05-16 13:23:49 UTC (rev 6821)
@@ -0,0 +1,286 @@
+/*
+ * 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.test.messaging.jms.message;
+
+import java.util.Random;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.jms.client.JBossMessageProducer;
+import org.jboss.test.messaging.jms.JMSTestCase;
+
+/**
+ * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
+ */
+public class JMSOrderingGroupPropertyTest extends JMSTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+   public JMSOrderingGroupPropertyTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+   /*
+    * Note - this test is testing the order of messages under the control of 
+    * ordering group message producers. All messages sent through a order group
+    * message producer obeys strict ordering rule -- they are delivered in the order
+    * they are sent, regardless of priorities.
+    */
+   public void testMessageOrderWithPriority() throws Exception
+   {
+      Connection conn = cf.createConnection();
+
+      conn.start();
+
+      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      JBossMessageProducer prod = (JBossMessageProducer)sessSend.createProducer(queue1);
+
+      prod.enableOrderingGroup(null);
+
+      TextMessage m0 = sessSend.createTextMessage("a");
+      TextMessage m1 = sessSend.createTextMessage("b");
+      TextMessage m2 = sessSend.createTextMessage("c");
+      TextMessage m3 = sessSend.createTextMessage("d");
+      TextMessage m4 = sessSend.createTextMessage("e");
+      TextMessage m5 = sessSend.createTextMessage("f");
+      TextMessage m6 = sessSend.createTextMessage("g");
+      TextMessage m7 = sessSend.createTextMessage("h");
+      TextMessage m8 = sessSend.createTextMessage("i");
+      TextMessage m9 = sessSend.createTextMessage("j");
+
+      Random rdm = new Random();
+      int pri = rdm.nextInt(10);
+      prod.send(m0, DeliveryMode.NON_PERSISTENT, pri, 0);
+      pri = rdm.nextInt(10);
+      prod.send(m1, DeliveryMode.NON_PERSISTENT, pri, 0);
+      pri = rdm.nextInt(10);
+      prod.send(m2, DeliveryMode.NON_PERSISTENT, pri, 0);
+      pri = rdm.nextInt(10);
+      prod.send(m3, DeliveryMode.NON_PERSISTENT, pri, 0);
+      pri = rdm.nextInt(10);
+      prod.send(m4, DeliveryMode.NON_PERSISTENT, pri, 0);
+      pri = rdm.nextInt(10);
+      prod.send(m5, DeliveryMode.NON_PERSISTENT, pri, 0);
+      pri = rdm.nextInt(10);
+      prod.send(m6, DeliveryMode.NON_PERSISTENT, pri, 0);
+      pri = rdm.nextInt(10);
+      prod.send(m7, DeliveryMode.NON_PERSISTENT, pri, 0);
+      pri = rdm.nextInt(10);
+      prod.send(m8, DeliveryMode.NON_PERSISTENT, pri, 0);
+      pri = rdm.nextInt(10);
+      prod.send(m9, DeliveryMode.NON_PERSISTENT, pri, 0);
+
+      // NP messages are sent async so we need to allow them time to all hit the server
+      Thread.sleep(2000);
+
+      Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      MessageConsumer cons = sessReceive.createConsumer(queue1);
+
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("a", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("b", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("c", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("d", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("e", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("f", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("g", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("h", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("i", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("j", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(500);
+         assertNull(t);
+      }
+
+      cons.close();
+
+      conn.close();
+   }
+
+   /*
+    * If messages are sent to a queue with certain priorities, and a consumer is already open
+    * then it is likely that they will be immediately sent to the consumer.
+    * even in this case, ordering group should be strictly obeyed.
+    */
+   public void testMessageOrderWithConsumerBuffering() throws Exception
+   {
+      Connection conn = cf.createConnection();
+
+      conn.start();
+
+      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      JBossMessageProducer prod = (JBossMessageProducer)sessSend.createProducer(queue1);
+      prod.enableOrderingGroup(null);
+
+      TextMessage m0 = sessSend.createTextMessage("a");
+      TextMessage m1 = sessSend.createTextMessage("b");
+      TextMessage m2 = sessSend.createTextMessage("c");
+      TextMessage m3 = sessSend.createTextMessage("d");
+      TextMessage m4 = sessSend.createTextMessage("e");
+      TextMessage m5 = sessSend.createTextMessage("f");
+      TextMessage m6 = sessSend.createTextMessage("g");
+      TextMessage m7 = sessSend.createTextMessage("h");
+      TextMessage m8 = sessSend.createTextMessage("i");
+      TextMessage m9 = sessSend.createTextMessage("j");
+
+      Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      MessageConsumer cons = sessReceive.createConsumer(queue1);
+
+      prod.send(m0, DeliveryMode.NON_PERSISTENT, 0, 0);
+      prod.send(m1, DeliveryMode.NON_PERSISTENT, 1, 0);
+      prod.send(m2, DeliveryMode.NON_PERSISTENT, 2, 0);
+      prod.send(m3, DeliveryMode.NON_PERSISTENT, 3, 0);
+      prod.send(m4, DeliveryMode.NON_PERSISTENT, 4, 0);
+      prod.send(m5, DeliveryMode.NON_PERSISTENT, 5, 0);
+      prod.send(m6, DeliveryMode.NON_PERSISTENT, 6, 0);
+      prod.send(m7, DeliveryMode.NON_PERSISTENT, 7, 0);
+      prod.send(m8, DeliveryMode.NON_PERSISTENT, 8, 0);
+      prod.send(m9, DeliveryMode.NON_PERSISTENT, 9, 0);
+
+      // Let them all get there
+
+      Thread.sleep(2000);
+
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("a", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("b", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("c", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("d", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("e", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("f", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("g", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("h", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("i", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(1000);
+         assertNotNull(t);
+         assertEquals("j", t.getText());
+      }
+      {
+         TextMessage t = (TextMessage)cons.receive(500);
+         assertNull(t);
+      }
+
+      cons.close();
+
+      conn.close();
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}




More information about the jboss-cvs-commits mailing list