[jboss-cvs] JBoss Messaging SVN: r7105 - in trunk: examples/common and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 28 14:26:31 EDT 2009


Author: ataylor
Date: 2009-05-28 14:26:30 -0400 (Thu, 28 May 2009)
New Revision: 7105

Added:
   trunk/examples/common/src/org/jboss/common/example/DummyXid.java
Modified:
   trunk/build-messaging.xml
   trunk/examples/common/build.xml
   trunk/examples/core/embedded-remote/build.xml
   trunk/examples/core/microcontainer/build.xml
   trunk/examples/jms/xa-heuristic/src/org/jboss/jms/example/XAHeuristicExample.java
   trunk/examples/jms/xa-receive/src/org/jboss/jms/example/XAReceiveExample.java
   trunk/examples/jms/xa-send/src/org/jboss/jms/example/XASendExample.java
Log:
example fixes


Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml	2009-05-28 15:48:51 UTC (rev 7104)
+++ trunk/build-messaging.xml	2009-05-28 18:26:30 UTC (rev 7105)
@@ -624,6 +624,9 @@
             <include name="org/jboss/naming/**/*.class"/>
             <include name="org/jnp/server/NamingServer_Stub.class"/>
          </zipfileset>
+         <zipfileset src="${jboss.jboss.common.logging.spi.lib}/jboss-common-logging-spi.jar">
+            <include name="org/jboss/logging/**/*.class"/>
+         </zipfileset>
       </jar>
    </target>
    
@@ -675,7 +678,10 @@
 	   
       <jar jarfile="${build.jars.dir}/${jms.client.jar.name}">         
          <fileset dir="${build.jms.classes.dir}" includes="org/jboss/messaging/jms/*.class"/>
-	 <fileset dir="${build.jms.classes.dir}" includes="org/jboss/messaging/jms/client/*.class"/>
+	      <fileset dir="${build.jms.classes.dir}" includes="org/jboss/messaging/jms/client/*.class"/>
+         <fileset dir="${build.jms.classes.dir}" includes="org/jboss/messaging/jms/referenceable/*.class"/>
+         <fileset dir="${build.jms.classes.dir}" includes="org/jboss/messaging/jms/server/management/*.class"/>
+         <fileset dir="${build.jms.classes.dir}" includes="org/jboss/messaging/jms/server/management/impl/JMSManagementHelper.class"/>
       </jar>
 	   
    </target>
@@ -717,6 +723,7 @@
          <fileset dir="${build.core.classes.dir}">
             <include name="version.properties"/>
             <include name="org/jboss/messaging/core/client/**/*.class"/>
+            <include name="org/jboss/messaging/core/filter/**/*.class"/>
             <include name="org/jboss/messaging/core/buffers/**/*.class"/>
             <include name="org/jboss/messaging/core/exception/**/*.class"/>
             <include name="org/jboss/messaging/core/logging/**/*.class"/>

Modified: trunk/examples/common/build.xml
===================================================================
--- trunk/examples/common/build.xml	2009-05-28 15:48:51 UTC (rev 7104)
+++ trunk/examples/common/build.xml	2009-05-28 18:26:30 UTC (rev 7105)
@@ -68,16 +68,27 @@
       <path refid="extra.classpath"/>
    </path>
 
+   <path id="client.compilation.classpath">
+      <fileset dir="${jbm.jars.dir}">
+         <include name="**/*client*.jar"/>
+         <include  name="**/jbm-jms-api.jar"/>
+      </fileset>
+      <path refid="extra.classpath"/>
+   </path>
+
    <path id="client.classpath">
-      <path refid="compilation.classpath"/>
+      <path refid="client.compilation.classpath"/>
       <pathelement location="${config.dir}"/>
       <pathelement location="${example.config.dir}"/>
       <pathelement location="${classes.dir}"/>
       <fileset dir="${client.jars.dir}">
          <include name="**/*client*.jar"/>
       </fileset>
+      <fileset dir="${jbm.jars.dir}">
+         <include  name="**/jbm-transports.jar"/>
+      </fileset>
       <fileset dir="${jars.dir}">
-         <include name="netty/lib/netty-3.1.0.BETA3.jar"/>
+         <include name="**/netty-3.1.0.BETA3.jar"/>
       </fileset>
    </path>
 
@@ -123,6 +134,8 @@
    <target name="runExample" depends="compile">
 
       <property name="serverclasspath" refid="server.classpath"/>
+      <property name="clientClasspath" refid="client.classpath"/>
+      <echo>client classpath = ${clientClasspath}</echo>
       <property file="${imported.basedir}/config/server.properties"/>
       <java classname="${example.classname}" fork="true" resultproperty="example-result">
          <jvmarg value="-Djbm.example.server.classpath=${serverclasspath}"/>

Added: trunk/examples/common/src/org/jboss/common/example/DummyXid.java
===================================================================
--- trunk/examples/common/src/org/jboss/common/example/DummyXid.java	                        (rev 0)
+++ trunk/examples/common/src/org/jboss/common/example/DummyXid.java	2009-05-28 18:26:30 UTC (rev 7105)
@@ -0,0 +1,208 @@
+/*
+ * 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.common.example;
+
+import org.jboss.messaging.utils.Base64;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+public class DummyXid implements Xid
+{
+   private static final long serialVersionUID = 407053232840068514L;
+
+   private byte[] branchQualifier;
+
+   private int formatId;
+
+   private byte[] globalTransactionId;
+
+   private int hash;
+
+   private boolean hashCalculated;
+
+   // Static --------------------------------------------------------
+
+   public static String toBase64String(final Xid xid)
+   {
+      return Base64.encodeBytes(toByteArray(xid));
+   }
+
+   private static byte[] toByteArray(final Xid xid)
+   {
+      byte[] branchQualifier = xid.getBranchQualifier();
+      byte[] globalTransactionId = xid.getGlobalTransactionId();
+      int formatId = xid.getFormatId();
+
+      byte[] hashBytes = new byte[branchQualifier.length + globalTransactionId.length + 4];
+      System.arraycopy(branchQualifier, 0, hashBytes, 0, branchQualifier.length);
+      System.arraycopy(globalTransactionId, 0, hashBytes, branchQualifier.length, globalTransactionId.length);
+      byte[] intBytes = new byte[4];
+      for (int i = 0; i < 4; i++)
+      {
+         intBytes[i] = (byte)((formatId >> (i * 8)) % 0xFF);
+      }
+      System.arraycopy(intBytes, 0, hashBytes, branchQualifier.length + globalTransactionId.length, 4);
+      return hashBytes;
+   }
+
+   // Constructors --------------------------------------------------
+
+   /**
+    * Standard constructor
+    * @param branchQualifier
+    * @param formatId
+    * @param globalTransactionId
+    */
+   public DummyXid(final byte[] branchQualifier, final int formatId, final byte[] globalTransactionId)
+   {
+      this.branchQualifier = branchQualifier;
+      this.formatId = formatId;
+      this.globalTransactionId = globalTransactionId;
+   }
+
+   /**
+    * Copy constructor
+    * @param other
+    */
+   public DummyXid(final Xid other)
+   {
+      this.branchQualifier = copyBytes(other.getBranchQualifier());
+      this.formatId = other.getFormatId();
+      this.globalTransactionId = copyBytes(other.getGlobalTransactionId());
+   }
+
+   // Xid implementation ------------------------------------------------------------------
+
+   public byte[] getBranchQualifier()
+   {
+      return branchQualifier;
+   }
+
+   public int getFormatId()
+   {
+      return formatId;
+   }
+
+   public byte[] getGlobalTransactionId()
+   {
+      return globalTransactionId;
+   }
+
+   // Public -------------------------------------------------------------------------------
+
+   public int hashCode()
+   {
+      if (!hashCalculated)
+      {
+         calcHash();
+      }
+      return hash;
+   }
+
+   public boolean equals(Object other)
+   {
+      if (this == other)
+      {
+         return true;
+      }
+      if (!(other instanceof Xid))
+      {
+         return false;
+      }
+      Xid xother = (Xid)other;
+      if (xother.getFormatId() != formatId)
+      {
+         return false;
+      }
+      if (xother.getBranchQualifier().length != this.branchQualifier.length)
+      {
+         return false;
+      }
+      if (xother.getGlobalTransactionId().length != this.globalTransactionId.length)
+      {
+         return false;
+      }
+      for (int i = 0; i < this.branchQualifier.length; i++)
+      {
+         byte[] otherBQ = xother.getBranchQualifier();
+         if (this.branchQualifier[i] != otherBQ[i])
+         {
+            return false;
+         }
+      }
+      for (int i = 0; i < this.globalTransactionId.length; i++)
+      {
+         byte[] otherGtx = xother.getGlobalTransactionId();
+         if (this.globalTransactionId[i] != otherGtx[i])
+         {
+            return false;
+         }
+      }
+      return true;
+   }
+
+   public String toString()
+   {
+     	return "XidImpl (" + System.identityHashCode(this) + " bq:" + stringRep(branchQualifier) +
+     	" formatID:" + formatId + " gtxid:" + stringRep(globalTransactionId);
+   }
+
+   // Private -------------------------------------------------------------------------------
+
+   private String stringRep(final byte[] bytes)
+   {
+      StringBuffer buff = new StringBuffer();
+      for (int i = 0; i < bytes.length; i++)
+      {
+         byte b = bytes[i];
+
+         buff.append(b);
+
+         if (i != bytes.length - 1)
+         {
+            buff.append('.');
+         }
+      }
+
+      return buff.toString();
+   }
+
+   private void calcHash()
+   {
+      byte[] hashBytes = toByteArray(this);
+      String s = new String(hashBytes);
+      hash = s.hashCode();
+      hashCalculated = true;
+   }
+
+   private byte[] copyBytes(byte[] other)
+   {
+      byte[] bytes = new byte[other.length];
+
+      System.arraycopy(other, 0, bytes, 0, other.length);
+
+      return bytes;
+   }
+}

Modified: trunk/examples/core/embedded-remote/build.xml
===================================================================
--- trunk/examples/core/embedded-remote/build.xml	2009-05-28 15:48:51 UTC (rev 7104)
+++ trunk/examples/core/embedded-remote/build.xml	2009-05-28 18:26:30 UTC (rev 7105)
@@ -31,19 +31,6 @@
 <project default="run" name="JBoss Messaging Embedded Example">
 
    <import file="../../common/build.xml"/>
-
-   <!-- We use a minimal classpath on this example -->
-   <path id="local.classpath">
-      <fileset dir="${jbm.jars.dir}">
-        <include name="jbm-core-client.jar"/>
-        <include name="jbm-transports.jar"/>
-      </fileset>
-   	  <fileset dir="${jars.dir}">
-        <include name="netty/lib/*jar"/>
-        <exclude name="**/*-sources.jar"/>
-   	  </fileset>
-      <pathelement location="${classes.dir}"/>	   	
-   </path>
 	
    <path id="remote.classpath">
     <fileset dir="${jbm.jars.dir}">
@@ -51,7 +38,7 @@
       <include name="jbm-transports.jar"/>
     </fileset>
  	  <fileset dir="${jars.dir}">
-      <include name="netty/lib/*jar"/>
+      <include name="**/netty*jar"/>
       <exclude name="**/*-sources.jar"/>
  	  </fileset>
     <pathelement location="${classes.dir}"/>	   	
@@ -60,14 +47,15 @@
    <target name="run" depends="compile">
    	
    	   <pathconvert refid="remote.classpath" property="remote-classpath"/>
-   	
-   	   <echo message="path = ${remote-classpath}"/>
+      <pathconvert refid="client.classpath" property="client-classpath"/>
+   	   <echo message="client path = ${client-classpath}"/>
+   	   <echo message="remote path = ${remote-classpath}"/>
 
 	   <java classname="org.jboss.core.example.EmbeddedRemoteExample" fork="true" resultproperty="example-result">
 	      <jvmarg value="-Xms50M"/>      
 	      <jvmarg value="-Xmx50M"/>
 	   	  <sysproperty key="remote-classpath" value="${remote-classpath}"/>
-	      <classpath refid="local.classpath"/>
+	      <classpath refid="client.classpath"/>
 	   </java>
        <fail message="EmbeddedRemoteExample failed">
           <condition>

Modified: trunk/examples/core/microcontainer/build.xml
===================================================================
--- trunk/examples/core/microcontainer/build.xml	2009-05-28 15:48:51 UTC (rev 7104)
+++ trunk/examples/core/microcontainer/build.xml	2009-05-28 18:26:30 UTC (rev 7105)
@@ -35,49 +35,42 @@
    <!-- We use a minimal classpath on this example -->
    <path id="local.classpath">
       <fileset dir="${jbm.jars.dir}">
-        <include name="jbm-core.jar"/>
-        <include name="jbm-transports.jar"/>
-        <include name="jbm-bootstrap.jar"/>
-        <include name="jbm-jbossas-security.jar"/>	
+         <include name="jbm-core.jar"/>
+         <include name="jbm-transports.jar"/>
+         <include name="jbm-bootstrap.jar"/>
+         <include name="jbm-jbossas-security.jar"/>
       </fileset>
-   	  <fileset dir="${jars.dir}">
-        <include name="netty/lib/*jar"/>
-        <include name="jboss/microcontainer/lib/jboss-dependency.jar"/>
-        <include name="jboss/microcontainer/lib/jboss-kernel.jar"/>
+      <fileset dir="${jbm.jars.dir}">
+         <include name="jboss-mc.jar"/>
+      </fileset>
+      <fileset dir="${jars.dir}">
+         <include name="**/netty*jar"/>
 
-   	  	<include name="jboss/jboss-common-logging-spi/lib/*.jar"/>
-   	  	<include name="jboss/jboss-reflect/lib/jboss-reflect.jar"/>
-   	  	<include name="jboss/common-core/lib/jboss-common-core.jar"/>
-   	  	<include name="jboss/jboss-mdr/lib/jboss-mdr.jar"/>
-   	  	<include name="jboss/jbossxb/lib/jboss-xml-binding.jar"/>
-   	  	<include name="sun-jaxb/lib/jaxb-api.jar"/>
-   	  	<include name="jboss/aop/lib/jboss-aop.jar"/>
-   	  	<include name="trove/lib/trove.jar"/>
-   	  	<include name="javassist/lib/javassist.jar"/>
-   	  	<exclude name="**/*-sources.jar"/>
-   	  	
-   	  	
-   	 
-        <!-- <include name="**/*.jar"/>
+
+         <exclude name="**/*-sources.jar"/>
+
+
+         <!-- <include name="**/*.jar"/>
          -->
-   	  </fileset>
-    <pathelement location="${classes.dir}"/>	   	
-    <pathelement location="./server0"/>	   	
+      </fileset>
+      <pathelement location="${classes.dir}"/>
+      <pathelement location="./server0"/>
    </path>
 
-	<target name="run" depends="compile">
-	   <java classname="org.jboss.core.example.EmbeddedMicroContainerExample" fork="true" resultproperty="example-result">
-	      <jvmarg value="-Xms50M"/>      
-	      <jvmarg value="-Xmx50M"/>
-	      <classpath refid="local.classpath"/>
-	   </java>
-       <fail message="EmbeddedMicroContainerExample failed">
-          <condition>
-             <not>
-                <equals arg1="${example-result}" arg2="0"/>
-             </not>
-          </condition>
-       </fail>
+   <target name="run" depends="compile">
+      <java classname="org.jboss.core.example.EmbeddedMicroContainerExample" fork="true"
+            resultproperty="example-result">
+         <jvmarg value="-Xms50M"/>
+         <jvmarg value="-Xmx50M"/>
+         <classpath refid="local.classpath"/>
+      </java>
+      <fail message="EmbeddedMicroContainerExample failed">
+         <condition>
+            <not>
+               <equals arg1="${example-result}" arg2="0"/>
+            </not>
+         </condition>
+      </fail>
 
    </target>
 </project>

Modified: trunk/examples/jms/xa-heuristic/src/org/jboss/jms/example/XAHeuristicExample.java
===================================================================
--- trunk/examples/jms/xa-heuristic/src/org/jboss/jms/example/XAHeuristicExample.java	2009-05-28 15:48:51 UTC (rev 7104)
+++ trunk/examples/jms/xa-heuristic/src/org/jboss/jms/example/XAHeuristicExample.java	2009-05-28 18:26:30 UTC (rev 7105)
@@ -21,9 +21,9 @@
    */
 package org.jboss.jms.example;
 
+import org.jboss.common.example.DummyXid;
 import org.jboss.common.example.JBMExample;
 import org.jboss.messaging.core.management.ObjectNames;
-import org.jboss.messaging.core.transaction.impl.XidImpl;
 import org.jboss.messaging.utils.UUIDGenerator;
 
 import javax.jms.JMSException;
@@ -107,7 +107,7 @@
          TextMessage worldMessage = session.createTextMessage("world");
          
          //Step 12. create a transaction
-         Xid xid1 = new XidImpl("xa-example1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
+         Xid xid1 = new DummyXid("xa-example1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
          
          //Step 13. Get the JMS XAResource
          XAResource xaRes = xaSession.getXAResource();
@@ -130,7 +130,7 @@
          checkNoMessageReceived();
          
          //Step 19. Create another transaction.
-         Xid xid2 = new XidImpl("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
+         Xid xid2 = new DummyXid("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
          
          //Step 20. Begin the transaction work
          xaRes.start(xid2, XAResource.TMNOFLAGS);
@@ -166,10 +166,10 @@
          }
 
          //Step 28. Roll back the first transaction
-         mbsc.invoke(serverObject, "rollbackPreparedTransaction", new String[] {XidImpl.toBase64String(xid1)}, new String[]{"java.lang.String"});
+         mbsc.invoke(serverObject, "rollbackPreparedTransaction", new String[] {DummyXid.toBase64String(xid1)}, new String[]{"java.lang.String"});
          
          //Step 29. Commit the second one
-         mbsc.invoke(serverObject, "commitPreparedTransaction", new String[] {XidImpl.toBase64String(xid2)}, new String[]{"java.lang.String"});
+         mbsc.invoke(serverObject, "commitPreparedTransaction", new String[] {DummyXid.toBase64String(xid2)}, new String[]{"java.lang.String"});
          
          Thread.sleep(2000);
          

Modified: trunk/examples/jms/xa-receive/src/org/jboss/jms/example/XAReceiveExample.java
===================================================================
--- trunk/examples/jms/xa-receive/src/org/jboss/jms/example/XAReceiveExample.java	2009-05-28 15:48:51 UTC (rev 7104)
+++ trunk/examples/jms/xa-receive/src/org/jboss/jms/example/XAReceiveExample.java	2009-05-28 18:26:30 UTC (rev 7105)
@@ -21,6 +21,10 @@
    */
 package org.jboss.jms.example;
 
+import org.jboss.common.example.DummyXid;
+import org.jboss.common.example.JBMExample;
+import org.jboss.messaging.utils.UUIDGenerator;
+
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
@@ -33,10 +37,6 @@
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-import org.jboss.common.example.JBMExample;
-import org.jboss.messaging.core.transaction.impl.XidImpl;
-import org.jboss.messaging.utils.UUIDGenerator;
-
 /**
  * A simple JMS example showing the usage of XA support in JMS.
  *
@@ -92,7 +92,7 @@
          TextMessage worldMessage = session.createTextMessage("world");
          
          //Step 12. create a transaction
-         Xid xid1 = new XidImpl("xa-example1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
+         Xid xid1 = new DummyXid("xa-example1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
          
          //Step 13. Get the JMS XAResource
          XAResource xaRes = xaSession.getXAResource();
@@ -120,7 +120,7 @@
          xaRes.rollback(xid1);
          
          //Step 20. Create another transaction
-         Xid xid2 = new XidImpl("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
+         Xid xid2 = new DummyXid("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
          
          //Step 21. Start the transaction
          xaRes.start(xid2, XAResource.TMNOFLAGS);

Modified: trunk/examples/jms/xa-send/src/org/jboss/jms/example/XASendExample.java
===================================================================
--- trunk/examples/jms/xa-send/src/org/jboss/jms/example/XASendExample.java	2009-05-28 15:48:51 UTC (rev 7104)
+++ trunk/examples/jms/xa-send/src/org/jboss/jms/example/XASendExample.java	2009-05-28 18:26:30 UTC (rev 7105)
@@ -21,7 +21,9 @@
    */
 package org.jboss.jms.example;
 
-import java.util.ArrayList;
+import org.jboss.common.example.DummyXid;
+import org.jboss.common.example.JBMExample;
+import org.jboss.messaging.utils.UUIDGenerator;
 
 import javax.jms.JMSException;
 import javax.jms.Message;
@@ -37,11 +39,8 @@
 import javax.naming.InitialContext;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
+import java.util.ArrayList;
 
-import org.jboss.common.example.JBMExample;
-import org.jboss.messaging.core.transaction.impl.XidImpl;
-import org.jboss.messaging.utils.UUIDGenerator;
-
 /**
  * A simple JMS example showing the usage of XA support in JMS.
  *
@@ -99,7 +98,7 @@
          TextMessage worldMessage = session.createTextMessage("world");
          
          //Step 12. create a transaction
-         Xid xid1 = new XidImpl("xa-example1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
+         Xid xid1 = new DummyXid("xa-example1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
          
          //Step 13. Get the JMS XAResource
          XAResource xaRes = xaSession.getXAResource();
@@ -129,7 +128,7 @@
          checkNoMessageReceived();
          
          //Step 21. Create another transaction
-         Xid xid2 = new XidImpl("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
+         Xid xid2 = new DummyXid("xa-example2".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
          
          //Step 22. Start the transaction
          xaRes.start(xid2, XAResource.TMNOFLAGS);




More information about the jboss-cvs-commits mailing list