[jboss-cvs] JBoss Messaging SVN: r6458 - in trunk: examples/jms/large-message/src/org/jboss/jms/example and 18 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 16 16:25:24 EDT 2009


Author: clebert.suconic at jboss.com
Date: 2009-04-16 16:25:23 -0400 (Thu, 16 Apr 2009)
New Revision: 6458

Added:
   trunk/src/main/org/jboss/messaging/core/client/LargeMessageBuffer.java
   trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBufferImpl.java
Removed:
   trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java
   trunk/tests/src/org/jboss/messaging/tests/soak/chunk/
Modified:
   trunk/examples/jms/large-message/readme.html
   trunk/examples/jms/large-message/src/org/jboss/jms/example/LargeMessageExample.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
   trunk/src/main/org/jboss/messaging/core/message/Message.java
   trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalLargeServerMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java
   trunk/src/main/org/jboss/messaging/core/server/LargeServerMessage.java
   trunk/src/main/org/jboss/messaging/core/server/ServerMessage.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java
   trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/BridgeTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/SimpleTransformer.java
   trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/JMSBridgeReconnectionTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/JMSBridgeTest.java
   trunk/tests/src/org/jboss/messaging/tests/stress/chunk/MessageChunkStressTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
Log:
LargeMessage streaming with long support, and JMS Example

Modified: trunk/examples/jms/large-message/readme.html
===================================================================
--- trunk/examples/jms/large-message/readme.html	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/examples/jms/large-message/readme.html	2009-04-16 20:25:23 UTC (rev 6458)
@@ -44,11 +44,18 @@
           <code>MessageProducer messageProducer = session.createProducer(topic);</code>
        </pre>
 
-        <li>Create a BytesMessage with 1MB arbitrary bytes</li>
+        <li>Create a BytesMessage</li>
         <pre><code>
          BytesMessage message = session.createBytesMessage();
-         message.writeBytes(new byte[1024 * 1024]);
         </code></pre>
+        
+        <li>Set the File Stream</li>
+        <pre><code>
+         FileInputStream fileInputStream = new FileInputStream(fileInput);
+         BufferedInputStream bufferedInput = new BufferedInputStream(fileInputStream);
+         ((JBossMessage)message).setInputStream(bufferedInput);
+         </code></pre>
+        
 
         <li>We send message to the queue. After the send completion the message file will be located at ./build/data/largeMessages</li>
         <pre>
@@ -65,12 +72,26 @@
            <code>connection.start();</code>
         </pre>
 
-        <li>The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'</li>
+        <li>Receive the message'</li>
         <pre><code>
-        BytesMessage messageReceived = (BytesMessage) messageConsumer.receive(5000);
+        BytesMessage messageReceived = (BytesMessage) messageConsumer.receive(120000);
         System.out.println("Received message: " + messageReceived.getBodyLength() + " bytes");
         </code></pre>
+        
 
+         <li>Setting a stream to receive the message. You may choose to use the regular BytesMessage or STreamMessage interface but this method is much faster for large messages.</li>
+        <pre><code>
+         FileOutputStream fileOutputStream = new FileOutputStream(fileOutput);
+         BufferedOutputStream bufferedOutput = new BufferedOutputStream(fileOutputStream);
+         ((JBossMessage)messageReceived).setOutputStream(bufferedOutput);
+        </code></pre>
+         
+         <li>setOutputStream is a non-blocking operation. You may choose to wait the streaming completion.</li> 
+        <pre><code>
+         ((JBossMessage)messageReceived).waitCompletionOnStream(300000);
+        </code></pre>
+        
+
         <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
 
         <pre>

Modified: trunk/examples/jms/large-message/src/org/jboss/jms/example/LargeMessageExample.java
===================================================================
--- trunk/examples/jms/large-message/src/org/jboss/jms/example/LargeMessageExample.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/examples/jms/large-message/src/org/jboss/jms/example/LargeMessageExample.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -21,6 +21,14 @@
    */
 package org.jboss.jms.example;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
 import javax.jms.BytesMessage;
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
@@ -30,6 +38,8 @@
 import javax.jms.Session;
 import javax.naming.InitialContext;
 
+import org.jboss.messaging.jms.client.JBossMessage;
+
 /**
  * A simple JMS Queue example that creates a producer and consumer on a queue and sends then receives a message.
  *
@@ -42,71 +52,127 @@
       new LargeMessageExample().run(args);
    }
 
+   private final long FILE_SIZE = 4l * 1024l * 1024l * 1024l; // 4G (if you want to change this size, make it a multiple
+                                                              // of 1024 * 1024)
+
    public boolean runExample() throws Exception
    {
       Connection connection = null;
       InitialContext initialContext = null;
+      File fileInput = File.createTempFile("example", ".jbm");
+      File fileOutput = File.createTempFile("example", ".jbm");
       try
       {
-         //Step 1. Create an initial context to perform the JNDI lookup.
+         // Step 1. Create an initial context to perform the JNDI lookup.
          initialContext = getContext(0);
 
-         //Step 2. Perfom a lookup on the queue
-         Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
+         // Step 2. Perfom a lookup on the queue
+         Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
 
-         //Step 3. Perform a lookup on the Connection Factory. This ConnectionFactory has a special set on this example. Messages with more than 10K are considered large
-         ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+         // Step 3. Perform a lookup on the Connection Factory. This ConnectionFactory has a special set on this
+         // example. Messages with more than 10K are considered large
+         ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
 
-         //Step 4.Create a JMS Connection
+         // Step 4.Create a JMS Connection
          connection = cf.createConnection();
 
-         //Step 5. Create a JMS Session
+         // Step 5. Create a JMS Session
          Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
-         //Step 6. Create a JMS Message Producer
+         // Step 6. Create a JMS Message Producer
          MessageProducer producer = session.createProducer(queue);
 
-         //Step 7. Create a BytesMessage with 1MB arbitrary bytes
+         // creating an arbitray file
+         createFile(fileInput, FILE_SIZE);
+
+         // Step 7. Create a BytesMessage
          BytesMessage message = session.createBytesMessage();
-         byte[] bytes = new byte[100 * 1024 * 1024];
-         message.writeBytes(bytes);
-         
-         System.out.println("Sending message of " + bytes.length + " bytes");
-         
-         //Step 8. Send the Message
+
+
+         // Step 8. Set the InputStream
+         FileInputStream fileInputStream = new FileInputStream(fileInput);
+         BufferedInputStream bufferedInput = new BufferedInputStream(fileInputStream);
+         ((JBossMessage)message).setInputStream(bufferedInput);
+
+         // Step 9. Send the Message
          producer.send(message);
-         
+
          System.out.println("Large Message sent");
-         
+
          // if you sleep the example and look at ./build/data/largeMessages you will see the largeMessage stored on disk
 
-         //Step 9. Create a JMS Message Consumer
+         // Step 10. Create a JMS Message Consumer
          MessageConsumer messageConsumer = session.createConsumer(queue);
 
-         //Step 10. Start the Connection
+         // Step 11. Start the Connection
          connection.start();
 
-         //Step 11. Receive the message
-         BytesMessage messageReceived = (BytesMessage) messageConsumer.receive(60000);
+         // Step 12. Receive the message
+         BytesMessage messageReceived = (BytesMessage)messageConsumer.receive(120000);
 
-         System.out.println("Received message: " + messageReceived.getBodyLength() + " bytes");
+         System.out.println("Received message with: " + messageReceived.getBodyLength() + " bytes");
 
+         FileOutputStream fileOutputStream = new FileOutputStream(fileOutput);
+         BufferedOutputStream bufferedOutput = new BufferedOutputStream(fileOutputStream);
+
+         // Step 13. Setting a stream to receive the message. You may choose to use the regular BytesMessage or STreamMessage interface but this method is much faster for large messages.
+         ((JBossMessage)messageReceived).setOutputStream(bufferedOutput);
+         
+         // Step 14. We don' t want to close the connection while the message is being processed. 
+         ((JBossMessage)messageReceived).waitCompletionOnStream(300000);
+
+
          initialContext.close();
-         
+
          return true;
       }
       finally
       {
-         //Step 12. Be sure to close our JMS resources!
+         // Deleting the tmporary files created
+         try
+         {
+            fileInput.delete();
+         }
+         catch (Throwable ignored)
+         {
+         }
+
+         try
+         {
+            fileOutput.delete();
+         }
+         catch (Throwable ignored)
+         {
+         }
+
+         // Step 12. Be sure to close our JMS resources!
          if (initialContext != null)
          {
             initialContext.close();
          }
-         if(connection != null)
+         if (connection != null)
          {
             connection.close();
          }
       }
    }
 
+   /**
+    * @param tmpFile
+    * @param fileSize
+    * @throws FileNotFoundException
+    * @throws IOException
+    */
+   private void createFile(File tmpFile, long fileSize) throws FileNotFoundException, IOException
+   {
+      FileOutputStream fileOut = new FileOutputStream(tmpFile);
+      BufferedOutputStream buffOut = new BufferedOutputStream(fileOut);
+      byte[] outBuffer = new byte[1024 * 1024];
+      for (long i = 0; i < fileSize; i += outBuffer.length) // 4G message
+      {
+         buffOut.write(outBuffer);
+      }
+      buffOut.close();
+   }
+
 }

Added: trunk/src/main/org/jboss/messaging/core/client/LargeMessageBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/LargeMessageBuffer.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/client/LargeMessageBuffer.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -0,0 +1,51 @@
+/*
+ * 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.messaging.core.client;
+
+import java.io.OutputStream;
+
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+
+/**
+ * A LargeMessageBufferImpl
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public interface LargeMessageBuffer extends MessagingBuffer
+{
+   long getSize();
+
+   void discardUnusedPackets();
+
+   void close();
+
+   void setOutputStream(final OutputStream output) throws MessagingException;
+
+   void saveBuffer(final OutputStream output) throws MessagingException;
+
+   boolean waitCompletion(long timeWait) throws MessagingException;
+
+}

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -74,7 +74,7 @@
 
    private ClientMessageInternal currentChunkMessage;
    
-   private LargeMessageBuffer currentLargeMessageBuffer;
+   private LargeMessageBufferImpl currentLargeMessageBuffer;
    
    // When receiving LargeMessages, the user may choose to not read the body, on this case we need to discard te body before moving to the next message.
    private ClientMessageInternal largeMessageReceived;
@@ -413,7 +413,7 @@
       
       currentChunkMessage.setLargeMessage(true);
 
-      currentLargeMessageBuffer = new LargeMessageBuffer(this, packet.getLargeMessageSize(), 60);
+      currentLargeMessageBuffer = new LargeMessageBufferImpl(this, packet.getLargeMessageSize(), 60);
 
       currentChunkMessage.setBody(currentLargeMessageBuffer);
 

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -25,6 +25,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.jboss.messaging.core.client.LargeMessageBuffer;
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
@@ -111,6 +112,18 @@
          consumer.acknowledge(this);
       }
    }
+   
+   public long getLargeBodySize()
+   {
+      if (largeMessage)
+      {
+         return ((LargeMessageBuffer)getBody()).getSize();
+      }
+      else
+      {
+         return this.getBodySize();
+      }
+   }
 
    public int getFlowControlSize()
    {
@@ -141,17 +154,8 @@
    {
       this.largeMessage = largeMessage;
    }
-   
 
    /* (non-Javadoc)
-    * @see org.jboss.messaging.core.client.impl.ClientMessageInternal#isFileMessage()
-    */
-   public boolean isFileMessage()
-   {
-      return false;
-   }
-
-   /* (non-Javadoc)
     * @see org.jboss.messaging.core.client.impl.ClientMessageInternal#discardLargeBody()
     */
    public void discardLargeBody()
@@ -169,7 +173,7 @@
    {
       if (largeMessage)
       {
-         ((LargeMessageBuffer)this.getBody()).saveBuffer(out);
+         ((LargeMessageBufferImpl)this.getBody()).saveBuffer(out);
       }
       else
       {
@@ -192,7 +196,7 @@
    {
       if (largeMessage)
       {
-         ((LargeMessageBuffer)this.getBody()).setOutputStream(out);
+         ((LargeMessageBufferImpl)this.getBody()).setOutputStream(out);
       }
       else
       {
@@ -208,7 +212,7 @@
    {
       if (largeMessage)
       {
-         return ((LargeMessageBuffer)this.getBody()).waitCompletion(timeMilliseconds);
+         return ((LargeMessageBufferImpl)this.getBody()).waitCompletion(timeMilliseconds);
       }
       else
       {

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -42,12 +42,8 @@
    void setFlowControlSize(int flowControlSize);
 
    void onReceipt(ClientConsumerInternal consumer);
-
-   boolean isLargeMessage();
    
    void setLargeMessage(boolean largeMessage);
-   
-   boolean isFileMessage();
 
    /**
     * Discard unused packets (used on large-message)

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -28,7 +28,6 @@
 import java.io.InputStream;
 
 import org.jboss.messaging.core.buffers.ChannelBuffers;
-import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.message.Message;
@@ -225,9 +224,9 @@
 
       SessionSendMessage message = new SessionSendMessage(msg, sendBlocking);
       
-      if (msg.getBodyInputStream() != null ||  msg.getEncodeSize() >= minLargeMessageSize || msg.getBody() instanceof LargeMessageBuffer)
+      if (msg.getBodyInputStream() != null ||  msg.getEncodeSize() >= minLargeMessageSize || msg.isLargeMessage())
       {
-         sendMessageInChunks(sendBlocking, (ClientMessageInternal)msg);
+         sendMessageInChunks(sendBlocking, msg);
       }
       else if (sendBlocking)
       {
@@ -243,7 +242,7 @@
     * @param msg
     * @throws MessagingException
     */
-   private void sendMessageInChunks(final boolean sendBlocking, final ClientMessageInternal msg) throws MessagingException
+   private void sendMessageInChunks(final boolean sendBlocking, final Message msg) throws MessagingException
    {
       int headerSize = msg.getPropertiesEncodeSize();
 
@@ -253,7 +252,9 @@
                                       "Header size (" + headerSize + ") is too big, use the messageBody for large data, or increase minLargeMessageSize");
       }
       
-      if (msg.getBodyInputStream() == null)
+      
+      // msg.getBody() could be Null on LargeServerMessage
+      if (msg.getBodyInputStream() == null && msg.getBody() != null)
       {
          msg.getBody().readerIndex(0);
       }
@@ -315,13 +316,13 @@
       }
       else
       {
-         final int bodySize = msg.getBodySize();
+         final long bodySize = msg.getLargeBodySize();
    
          for (int pos = 0; pos < bodySize;)
          {
             final boolean lastChunk;
                      
-            final int chunkLength = Math.min(bodySize - pos, minLargeMessageSize); 
+            final int chunkLength = Math.min((int)(bodySize - pos), minLargeMessageSize); 
             
             final MessagingBuffer bodyBuffer = ChannelBuffers.buffer(chunkLength); 
    

Deleted: trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -1,1064 +0,0 @@
-/*
- * 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.messaging.core.client.impl;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.GatheringByteChannel;
-import java.nio.channels.ScatteringByteChannel;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-import org.jboss.messaging.core.buffers.ChannelBuffer;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
-import org.jboss.messaging.utils.DataConstants;
-import org.jboss.messaging.utils.SimpleString;
-import org.jboss.messaging.utils.UTF8Util;
-
-/**
- * This class aggregates several SessionReceiveContinuationMessages as it was being handled by a single buffer.
- * This buffer can be consumed as messages are arriving, and it will hold the packets until they are read using the ChannelBuffer interface, or the setOutputStream or saveStream are called.
- *
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- *
- *
- */
-public class LargeMessageBuffer implements ChannelBuffer
-{
-   // Constants -----------------------------------------------------
-
-   private final String READ_ONLY_ERROR_MESSAGE = "This is a read-only buffer, setOperations are not supported";
-
-   // Attributes ----------------------------------------------------
-
-   private final ClientConsumerInternal consumerInternal;
-
-   private final LinkedBlockingQueue<SessionReceiveContinuationMessage> packets = new LinkedBlockingQueue<SessionReceiveContinuationMessage>();
-
-   private SessionReceiveContinuationMessage currentPacket = null;
-
-   private final int totalSize;
-
-   private boolean streamEnded = false;
-
-   private final int readTimeout;
-
-   private int readerIndex = 0;
-
-   private int packetPosition = -1;
-
-   private int lastIndex = 0;
-
-   private int packetLastPosition = -1;
-
-   private OutputStream outStream;
-
-   private Exception handledException;
-
-   // Static --------------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   public LargeMessageBuffer(final ClientConsumerInternal consumerInternal, final int totalSize, final int readTimeout)
-   {
-      this.consumerInternal = consumerInternal;
-      this.readTimeout = readTimeout;
-      this.totalSize = totalSize;
-   }
-
-   // Public --------------------------------------------------------
-
-   public synchronized Exception getHandledException()
-   {
-      return handledException;
-   }
-
-   /**
-    * 
-    */
-   public void discardUnusedPackets()
-   {
-      if (outStream == null)
-      {
-         try
-         {
-            checkForPacket(this.totalSize - 1);
-         }
-         catch (Exception ignored)
-         {
-         }
-      }
-   }
-
-   /**
-    * Add a buff to the List, or save it to the OutputStream if set
-    * @param packet
-    */
-   public synchronized void addPacket(final SessionReceiveContinuationMessage packet)
-   {
-      if (outStream != null)
-      {
-         try
-         {
-            if (!packet.isContinues())
-            {
-               streamEnded = true;
-            }
-
-            outStream.write(packet.getBody());
-
-            consumerInternal.flowControl(packet.getPacketSize(), true);
-
-            if (streamEnded)
-            {
-               outStream.close();
-            }
-
-            notifyAll();
-         }
-         catch (Exception e)
-         {
-            handledException = e;
-
-         }
-      }
-      else
-      {
-         packets.offer(packet);
-      }
-   }
-
-   public synchronized void close()
-   {
-      this.packets.offer(new SessionReceiveContinuationMessage());
-      this.streamEnded = true;
-      notifyAll();
-   }
-
-   public synchronized void setOutputStream(final OutputStream output) throws MessagingException
-   {
-      while (true)
-      {
-         SessionReceiveContinuationMessage packet = this.packets.poll();
-         if (packet == null)
-         {
-            break;
-         }
-         try
-         {
-            output.write(packet.getBody());
-         }
-         catch (IOException e)
-         {
-            throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY,
-                                         "Error writing body of message",
-                                         e);
-         }
-      }
-
-      this.outStream = output;
-   }
-
-   public synchronized void saveBuffer(final OutputStream output) throws MessagingException
-   {
-      setOutputStream(output);
-      waitCompletion(0);
-   }
-
-   /**
-    * 
-    * @param timeWait Milliseconds to Wait. 0 means forever
-    * @throws Exception
-    */
-   public synchronized boolean waitCompletion(long timeWait) throws MessagingException
-   {
-
-      if (outStream == null)
-      {
-         // There is no stream.. it will never achieve the end of streaming
-         return false;
-      }
-
-      long timeOut = System.currentTimeMillis() + timeWait;
-      while (!streamEnded && handledException == null)
-      {
-         try
-         {
-            this.wait(readTimeout == 0 ? 1 : (readTimeout * 1000));
-         }
-         catch (InterruptedException e)
-         {
-            throw new MessagingException(MessagingException.INTERNAL_ERROR, e.getMessage(), e);
-         }
-
-         if (timeWait > 0 && System.currentTimeMillis() > timeOut)
-         {
-            throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY,
-                                         "Timeout waiting for LargeMessage Body");
-         }
-      }
-
-      if (this.handledException != null)
-      {
-         throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY,
-                                      "Error on saving LargeMessageBuffer",
-                                      this.handledException);
-      }
-
-      return this.streamEnded;
-
-   }
-
-   // Channel Buffer Implementation ---------------------------------
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#array()
-    */
-   public byte[] array()
-   {
-      throw new IllegalAccessError("array not supported on LargeMessageBuffer");
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#capacity()
-    */
-   public int capacity()
-   {
-      return -1;
-   }
-
-   public byte readByte()
-   {
-      return getByte(readerIndex++);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getByte(int)
-    */
-   public byte getByte(final int index)
-   {
-      checkForPacket(index);
-      return currentPacket.getBody()[index - packetPosition];
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, org.jboss.messaging.core.buffers.ChannelBuffer, int, int)
-    */
-   public void getBytes(final int index, final ChannelBuffer dst, final int dstIndex, final int length)
-   {
-      byte[] destBytes = new byte[length];
-      getBytes(index, destBytes);
-      dst.setBytes(dstIndex, destBytes);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, byte[], int, int)
-    */
-   public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length)
-   {
-      byte bytesToGet[] = new byte[length];
-
-      getBytes(index, bytesToGet);
-
-      System.arraycopy(bytesToGet, 0, dst, dstIndex, length);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, java.nio.ByteBuffer)
-    */
-   public void getBytes(final int index, final ByteBuffer dst)
-   {
-      byte bytesToGet[] = new byte[dst.remaining()];
-      getBytes(index, bytesToGet);
-      dst.put(bytesToGet);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, java.io.OutputStream, int)
-    */
-   public void getBytes(final int index, final OutputStream out, final int length) throws IOException
-   {
-      byte bytesToGet[] = new byte[length];
-      getBytes(index, bytesToGet);
-      out.write(bytesToGet);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, java.nio.channels.GatheringByteChannel, int)
-    */
-   public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException
-   {
-      byte bytesToGet[] = new byte[length];
-      getBytes(index, bytesToGet);
-      return out.write(ByteBuffer.wrap(bytesToGet));
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getInt(int)
-    */
-   public int getInt(final int index)
-   {
-      return (getByte(index) & 0xff) << 24 | (getByte(index + 1) & 0xff) << 16 |
-             (getByte(index + 2) & 0xff) << 8 |
-             (getByte(index + 3) & 0xff) << 0;
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getLong(int)
-    */
-   public long getLong(final int index)
-   {
-      return ((long)getByte(index) & 0xff) << 56 | ((long)getByte(index + 1) & 0xff) << 48 |
-             ((long)getByte(index + 2) & 0xff) << 40 |
-             ((long)getByte(index + 3) & 0xff) << 32 |
-             ((long)getByte(index + 4) & 0xff) << 24 |
-             ((long)getByte(index + 5) & 0xff) << 16 |
-             ((long)getByte(index + 6) & 0xff) << 8 |
-             ((long)getByte(index + 7) & 0xff) << 0;
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getShort(int)
-    */
-   public short getShort(final int index)
-   {
-      return (short)(getByte(index) << 8 | getByte(index + 1) & 0xFF);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getUnsignedMedium(int)
-    */
-   public int getUnsignedMedium(final int index)
-   {
-      return (getByte(index) & 0xff) << 16 | (getByte(index + 1) & 0xff) << 8 | (getByte(index + 2) & 0xff) << 0;
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setByte(int, byte)
-    */
-   public void setByte(final int index, final byte value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, org.jboss.messaging.core.buffers.ChannelBuffer, int, int)
-    */
-   public void setBytes(final int index, final ChannelBuffer src, final int srcIndex, final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, byte[], int, int)
-    */
-   public void setBytes(final int index, final byte[] src, final int srcIndex, final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, java.nio.ByteBuffer)
-    */
-   public void setBytes(final int index, final ByteBuffer src)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, java.io.InputStream, int)
-    */
-   public int setBytes(final int index, final InputStream in, final int length) throws IOException
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, java.nio.channels.ScatteringByteChannel, int)
-    */
-   public int setBytes(final int index, final ScatteringByteChannel in, final int length) throws IOException
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setInt(int, int)
-    */
-   public void setInt(final int index, final int value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setLong(int, long)
-    */
-   public void setLong(final int index, final long value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setMedium(int, int)
-    */
-   public void setMedium(final int index, final int value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setShort(int, short)
-    */
-   public void setShort(final int index, final short value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#toByteBuffer(int, int)
-    */
-   public ByteBuffer toByteBuffer(final int index, final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#toString(int, int, java.lang.String)
-    */
-   public String toString(final int index, final int length, final String charsetName)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public int readerIndex()
-   {
-      return readerIndex;
-   }
-
-   public void readerIndex(final int readerIndex)
-   {
-      checkForPacket(readerIndex);
-      this.readerIndex = readerIndex;
-   }
-
-   public int writerIndex()
-   {
-      return totalSize;
-   }
-
-   public void writerIndex(final int writerIndex)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void setIndex(final int readerIndex, final int writerIndex)
-   {
-      checkForPacket(readerIndex);
-      this.readerIndex = readerIndex;
-   }
-
-   public void clear()
-   {
-   }
-
-   public boolean readable()
-   {
-      return true;
-   }
-
-   public boolean writable()
-   {
-      return false;
-   }
-
-   public int readableBytes()
-   {
-      return this.totalSize - this.readerIndex;
-   }
-
-   public int writableBytes()
-   {
-      return 0;
-   }
-
-   public void markReaderIndex()
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void resetReaderIndex()
-   {
-      checkForPacket(0);
-   }
-
-   public void markWriterIndex()
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void resetWriterIndex()
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void discardReadBytes()
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public short getUnsignedByte(final int index)
-   {
-      return (short)(getByte(index) & 0xFF);
-   }
-
-   public int getUnsignedShort(final int index)
-   {
-      return getShort(index) & 0xFFFF;
-   }
-
-   public int getMedium(final int index)
-   {
-      int value = getUnsignedMedium(index);
-      if ((value & 0x800000) != 0)
-      {
-         value |= 0xff000000;
-      }
-      return value;
-   }
-
-   public long getUnsignedInt(final int index)
-   {
-      return getInt(index) & 0xFFFFFFFFL;
-   }
-
-   public void getBytes(int index, final byte[] dst)
-   {
-      // TODO: optimize this by using System.arraycopy
-      for (int i = 0; i < dst.length; i++)
-      {
-         dst[i] = getByte(index++);
-      }
-   }
-
-   public void getBytes(final int index, final ChannelBuffer dst)
-   {
-      getBytes(index, dst, dst.writableBytes());
-   }
-
-   public void getBytes(final int index, final ChannelBuffer dst, final int length)
-   {
-      if (length > dst.writableBytes())
-      {
-         throw new IndexOutOfBoundsException();
-      }
-      getBytes(index, dst, dst.writerIndex(), length);
-      dst.writerIndex(dst.writerIndex() + length);
-   }
-
-   public void setBytes(final int index, final byte[] src)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void setBytes(final int index, final ChannelBuffer src)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void setBytes(final int index, final ChannelBuffer src, final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void setZero(final int index, final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public short readUnsignedByte()
-   {
-      return (short)(readByte() & 0xFF);
-   }
-
-   public short readShort()
-   {
-      short v = getShort(readerIndex);
-      readerIndex += 2;
-      return v;
-   }
-
-   public int readUnsignedShort()
-   {
-      return readShort() & 0xFFFF;
-   }
-
-   public int readMedium()
-   {
-      int value = readUnsignedMedium();
-      if ((value & 0x800000) != 0)
-      {
-         value |= 0xff000000;
-      }
-      return value;
-   }
-
-   public int readUnsignedMedium()
-   {
-      int v = getUnsignedMedium(readerIndex);
-      readerIndex += 3;
-      return v;
-   }
-
-   public int readInt()
-   {
-      int v = getInt(readerIndex);
-      readerIndex += 4;
-      return v;
-   }
-
-   public long readUnsignedInt()
-   {
-      return readInt() & 0xFFFFFFFFL;
-   }
-
-   public long readLong()
-   {
-      long v = getLong(readerIndex);
-      readerIndex += 8;
-      return v;
-   }
-
-   public void readBytes(final byte[] dst, final int dstIndex, final int length)
-   {
-      getBytes(readerIndex, dst, dstIndex, length);
-      readerIndex += length;
-   }
-
-   public void readBytes(final byte[] dst)
-   {
-      readBytes(dst, 0, dst.length);
-   }
-
-   public void readBytes(final ChannelBuffer dst)
-   {
-      readBytes(dst, dst.writableBytes());
-   }
-
-   public void readBytes(final ChannelBuffer dst, final int length)
-   {
-      if (length > dst.writableBytes())
-      {
-         throw new IndexOutOfBoundsException();
-      }
-      readBytes(dst, dst.writerIndex(), length);
-      dst.writerIndex(dst.writerIndex() + length);
-   }
-
-   public void readBytes(final ChannelBuffer dst, final int dstIndex, final int length)
-   {
-      getBytes(readerIndex, dst, dstIndex, length);
-      readerIndex += length;
-   }
-
-   public void readBytes(final ByteBuffer dst)
-   {
-      int length = dst.remaining();
-      getBytes(readerIndex, dst);
-      readerIndex += length;
-   }
-
-   public int readBytes(final GatheringByteChannel out, final int length) throws IOException
-   {
-      int readBytes = getBytes(readerIndex, out, length);
-      readerIndex += readBytes;
-      return readBytes;
-   }
-
-   public void readBytes(final OutputStream out, final int length) throws IOException
-   {
-      getBytes(readerIndex, out, length);
-      readerIndex += length;
-   }
-
-   public void skipBytes(final int length)
-   {
-
-      int newReaderIndex = readerIndex + length;
-      checkForPacket(newReaderIndex);
-      readerIndex = newReaderIndex;
-   }
-
-   public void writeByte(final byte value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeShort(final short value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeMedium(final int value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeInt(final int value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeLong(final long value)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeBytes(final byte[] src, final int srcIndex, final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeBytes(final byte[] src)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeBytes(final ChannelBuffer src)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeBytes(final ChannelBuffer src, final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeBytes(MessagingBuffer src, int srcIndex, int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeBytes(final ChannelBuffer src, final int srcIndex, final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeBytes(final ByteBuffer src)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeBytes(final InputStream in, final int length) throws IOException
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public int writeBytes(final ScatteringByteChannel in, final int length) throws IOException
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public void writeZero(final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public ByteBuffer toByteBuffer()
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public ByteBuffer[] toByteBuffers()
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public ByteBuffer[] toByteBuffers(final int index, final int length)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public String toString(final String charsetName)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   public Object getUnderlyingBuffer()
-   {
-      return this;
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readBoolean()
-    */
-   public boolean readBoolean()
-   {
-      return readByte() != 0;
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readChar()
-    */
-   public char readChar()
-   {
-      return (char)readShort();
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readDouble()
-    */
-   public double readDouble()
-   {
-      return Double.longBitsToDouble(readLong());
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readFloat()
-    */
-   public float readFloat()
-   {
-      return Float.intBitsToFloat(readInt());
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readNullableSimpleString()
-    */
-   public SimpleString readNullableSimpleString()
-   {
-      int b = readByte();
-      if (b == DataConstants.NULL)
-      {
-         return null;
-      }
-      else
-      {
-         return readSimpleString();
-      }
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readNullableString()
-    */
-   public String readNullableString()
-   {
-      int b = readByte();
-      if (b == DataConstants.NULL)
-      {
-         return null;
-      }
-      else
-      {
-         return readString();
-      }
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readSimpleString()
-    */
-   public SimpleString readSimpleString()
-   {
-      int len = readInt();
-      byte[] data = new byte[len];
-      readBytes(data);
-      return new SimpleString(data);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readString()
-    */
-   public String readString()
-   {
-      int len = readInt();
-      char[] chars = new char[len];
-      for (int i = 0; i < len; i++)
-      {
-         chars[i] = readChar();
-      }
-      return new String(chars);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readUTF()
-    */
-   public String readUTF() throws Exception
-   {
-      return UTF8Util.readUTF(this);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeBoolean(boolean)
-    */
-   public void writeBoolean(final boolean val)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeChar(char)
-    */
-   public void writeChar(final char val)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeDouble(double)
-    */
-   public void writeDouble(final double val)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeFloat(float)
-    */
-   public void writeFloat(final float val)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeNullableSimpleString(org.jboss.messaging.util.SimpleString)
-    */
-   public void writeNullableSimpleString(final SimpleString val)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeNullableString(java.lang.String)
-    */
-   public void writeNullableString(final String val)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeSimpleString(org.jboss.messaging.util.SimpleString)
-    */
-   public void writeSimpleString(final SimpleString val)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeString(java.lang.String)
-    */
-   public void writeString(final String val)
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeUTF(java.lang.String)
-    */
-   public void writeUTF(final String utf) throws Exception
-   {
-      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
-   }
-
-   /* (non-Javadoc)
-    * @see org.jboss.messaging.core.buffers.ChannelBuffer#compareTo(org.jboss.messaging.core.buffers.ChannelBuffer)
-    */
-   public int compareTo(final ChannelBuffer buffer)
-   {
-      return -1;
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   private void popPacket()
-   {
-      try
-      {
-
-         if (streamEnded)
-         {
-            // no more packets, we are over the last one already
-            throw new IndexOutOfBoundsException();
-         }
-
-         int sizeToAdd = currentPacket != null ? currentPacket.getBody().length : 1;
-         currentPacket = packets.poll(readTimeout, TimeUnit.SECONDS);
-         if (currentPacket == null)
-         {
-            throw new IndexOutOfBoundsException();
-         }
-
-         if (currentPacket.getBody() == null) // Empty packet as a signal to interruption
-         {
-            currentPacket = null;
-            streamEnded = true;
-            throw new IndexOutOfBoundsException();
-         }
-
-         consumerInternal.flowControl(currentPacket.getPacketSize(), true);
-
-         packetPosition += sizeToAdd;
-
-         packetLastPosition = packetPosition + currentPacket.getBody().length;
-      }
-      catch (IndexOutOfBoundsException e)
-      {
-         throw e;
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-
-   private void checkForPacket(final int index)
-   {
-      if (this.outStream != null)
-      {
-         throw new IllegalAccessError("Can't read the messageBody after setting outputStream");
-      }
-      if (index >= totalSize)
-      {
-         throw new IndexOutOfBoundsException();
-      }
-      if (index < lastIndex)
-      {
-         throw new IllegalAccessError("LargeMessage have read-only and one-way buffers");
-      }
-      lastIndex = index;
-
-      while (index >= packetLastPosition && !streamEnded)
-      {
-         popPacket();
-      }
-   }
-
-   // Inner classes -------------------------------------------------
-
-}

Copied: trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBufferImpl.java (from rev 6449, trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBufferImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/LargeMessageBufferImpl.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -0,0 +1,1177 @@
+/*
+ * 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.messaging.core.client.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.GatheringByteChannel;
+import java.nio.channels.ScatteringByteChannel;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.messaging.core.buffers.ChannelBuffer;
+import org.jboss.messaging.core.client.LargeMessageBuffer;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.utils.DataConstants;
+import org.jboss.messaging.utils.SimpleString;
+import org.jboss.messaging.utils.UTF8Util;
+
+/**
+ * This class aggregates several SessionReceiveContinuationMessages as it was being handled by a single buffer.
+ * This buffer can be consumed as messages are arriving, and it will hold the packets until they are read using the ChannelBuffer interface, or the setOutputStream or saveStream are called.
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class LargeMessageBufferImpl implements ChannelBuffer, LargeMessageBuffer
+{
+   // Constants -----------------------------------------------------
+
+   private final String READ_ONLY_ERROR_MESSAGE = "This is a read-only buffer, setOperations are not supported";
+
+   // Attributes ----------------------------------------------------
+
+   private final ClientConsumerInternal consumerInternal;
+
+   private final LinkedBlockingQueue<SessionReceiveContinuationMessage> packets = new LinkedBlockingQueue<SessionReceiveContinuationMessage>();
+
+   private SessionReceiveContinuationMessage currentPacket = null;
+
+   private final long totalSize;
+
+   private boolean streamEnded = false;
+
+   private final int readTimeout;
+
+   private long readerIndex = 0;
+
+   private long packetPosition = -1;
+
+   private long lastIndex = 0;
+
+   private long packetLastPosition = -1;
+
+   private OutputStream outStream;
+
+   private Exception handledException;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public LargeMessageBufferImpl(final ClientConsumerInternal consumerInternal, final long totalSize, final int readTimeout)
+   {
+      this.consumerInternal = consumerInternal;
+      this.readTimeout = readTimeout;
+      this.totalSize = totalSize;
+   }
+
+   // Public --------------------------------------------------------
+
+   public synchronized Exception getHandledException()
+   {
+      return handledException;
+   }
+
+   /**
+    * 
+    */
+   public void discardUnusedPackets()
+   {
+      if (outStream == null)
+      {
+         try
+         {
+            checkForPacket(this.totalSize - 1);
+         }
+         catch (Exception ignored)
+         {
+         }
+      }
+   }
+   
+   long size;
+   
+   /**
+    * Add a buff to the List, or save it to the OutputStream if set
+    * @param packet
+    */
+   public synchronized void addPacket(final SessionReceiveContinuationMessage packet)
+   {
+      if (outStream != null)
+      {
+         try
+         {
+            if (!packet.isContinues())
+            {
+               streamEnded = true;
+            }
+
+            outStream.write(packet.getBody());
+
+            consumerInternal.flowControl(packet.getPacketSize(), true);
+
+            notifyAll();
+
+            if (streamEnded)
+            {
+               outStream.close();
+            }
+         }
+         catch (Exception e)
+         {
+            handledException = e;
+
+         }
+      }
+      else
+      {
+         packets.offer(packet);
+      }
+   }
+
+   public synchronized void close()
+   {
+      this.packets.offer(new SessionReceiveContinuationMessage());
+      this.streamEnded = true;
+      notifyAll();
+   }
+
+   public synchronized void setOutputStream(final OutputStream output) throws MessagingException
+   {
+      if (currentPacket != null)
+      {
+         sendPacketToOutput(output, currentPacket);
+         currentPacket = null;
+      }
+      while (true)
+      {
+         SessionReceiveContinuationMessage packet = this.packets.poll();
+         if (packet == null)
+         {
+            break;
+         }
+         consumerInternal.flowControl(packet.getPacketSize(), true);
+         sendPacketToOutput(output, packet);
+      }
+
+      this.outStream = output;
+   }
+
+   /**
+    * @param output
+    * @param packet
+    * @throws MessagingException
+    */
+   private void sendPacketToOutput(final OutputStream output, SessionReceiveContinuationMessage packet) throws MessagingException
+   {
+      try
+      {
+         if (!packet.isContinues())
+         {
+            streamEnded = true;
+         }
+         output.write(packet.getBody());
+      }
+      catch (IOException e)
+      {
+         throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY,
+                                      "Error writing body of message",
+                                      e);
+      }
+   }
+
+   public synchronized void saveBuffer(final OutputStream output) throws MessagingException
+   {
+      setOutputStream(output);
+      waitCompletion(0);
+   }
+
+   /**
+    * 
+    * @param timeWait Milliseconds to Wait. 0 means forever
+    * @throws Exception
+    */
+   public synchronized boolean waitCompletion(long timeWait) throws MessagingException
+   {
+
+      if (outStream == null)
+      {
+         // There is no stream.. it will never achieve the end of streaming
+         return false;
+      }
+
+      long timeOut = System.currentTimeMillis() + timeWait;
+      while (!streamEnded && handledException == null)
+      {
+         try
+         {
+            this.wait(readTimeout == 0 ? 1 : (readTimeout * 1000));
+         }
+         catch (InterruptedException e)
+         {
+            throw new MessagingException(MessagingException.INTERNAL_ERROR, e.getMessage(), e);
+         }
+
+         if (timeWait > 0 && System.currentTimeMillis() > timeOut)
+         {
+            throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY,
+                                         "Timeout waiting for LargeMessage Body");
+         }
+      }
+
+      if (this.handledException != null)
+      {
+         throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY,
+                                      "Error on saving LargeMessageBufferImpl",
+                                      this.handledException);
+      }
+
+      return this.streamEnded;
+
+   }
+
+   // Channel Buffer Implementation ---------------------------------
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#array()
+    */
+   public byte[] array()
+   {
+      throw new IllegalAccessError("array not supported on LargeMessageBufferImpl");
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#capacity()
+    */
+   public int capacity()
+   {
+      return -1;
+   }
+
+   public byte readByte()
+   {
+      return getByte(readerIndex++);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getByte(int)
+    */
+   public byte getByte(final int index)
+   {
+      checkForPacket(index);
+      return currentPacket.getBody()[(int)(index - packetPosition)];
+   }
+   
+   private byte getByte(final long index)
+   {
+      checkForPacket(index);
+      return currentPacket.getBody()[(int)(index - packetPosition)];
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, org.jboss.messaging.core.buffers.ChannelBuffer, int, int)
+    */
+   public void getBytes(final int index, final ChannelBuffer dst, final int dstIndex, final int length)
+   {
+      byte[] destBytes = new byte[length];
+      getBytes(index, destBytes);
+      dst.setBytes(dstIndex, destBytes);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, org.jboss.messaging.core.buffers.ChannelBuffer, int, int)
+    */
+   public void getBytes(final long index, final ChannelBuffer dst, final int dstIndex, final int length)
+   {
+      byte[] destBytes = new byte[length];
+      getBytes(index, destBytes);
+      dst.setBytes(dstIndex, destBytes);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, byte[], int, int)
+    */
+   public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length)
+   {
+      byte bytesToGet[] = new byte[length];
+
+      getBytes(index, bytesToGet);
+
+      System.arraycopy(bytesToGet, 0, dst, dstIndex, length);
+   }
+
+   public void getBytes(final long index, final byte[] dst, final int dstIndex, final int length)
+   {
+      byte bytesToGet[] = new byte[length];
+
+      getBytes(index, bytesToGet);
+
+      System.arraycopy(bytesToGet, 0, dst, dstIndex, length);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, java.nio.ByteBuffer)
+    */
+   public void getBytes(final int index, final ByteBuffer dst)
+   {
+      byte bytesToGet[] = new byte[dst.remaining()];
+      getBytes(index, bytesToGet);
+      dst.put(bytesToGet);
+   }
+
+   public void getBytes(final long index, final ByteBuffer dst)
+   {
+      byte bytesToGet[] = new byte[dst.remaining()];
+      getBytes(index, bytesToGet);
+      dst.put(bytesToGet);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, java.io.OutputStream, int)
+    */
+   public void getBytes(final int index, final OutputStream out, final int length) throws IOException
+   {
+      byte bytesToGet[] = new byte[length];
+      getBytes(index, bytesToGet);
+      out.write(bytesToGet);
+   }
+
+   public void getBytes(final long index, final OutputStream out, final int length) throws IOException
+   {
+      byte bytesToGet[] = new byte[length];
+      getBytes(index, bytesToGet);
+      out.write(bytesToGet);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getBytes(int, java.nio.channels.GatheringByteChannel, int)
+    */
+   public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException
+   {
+      byte bytesToGet[] = new byte[length];
+      getBytes(index, bytesToGet);
+      return out.write(ByteBuffer.wrap(bytesToGet));
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getInt(int)
+    */
+   public int getInt(final int index)
+   {
+      return (getByte(index) & 0xff) << 24 | (getByte(index + 1) & 0xff) << 16 |
+             (getByte(index + 2) & 0xff) << 8 |
+             (getByte(index + 3) & 0xff) << 0;
+   }
+
+   public int getInt(final long index)
+   {
+      return (getByte(index) & 0xff) << 24 | (getByte(index + 1) & 0xff) << 16 |
+             (getByte(index + 2) & 0xff) << 8 |
+             (getByte(index + 3) & 0xff) << 0;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getLong(int)
+    */
+   public long getLong(final int index)
+   {
+      return ((long)getByte(index) & 0xff) << 56 | ((long)getByte(index + 1) & 0xff) << 48 |
+             ((long)getByte(index + 2) & 0xff) << 40 |
+             ((long)getByte(index + 3) & 0xff) << 32 |
+             ((long)getByte(index + 4) & 0xff) << 24 |
+             ((long)getByte(index + 5) & 0xff) << 16 |
+             ((long)getByte(index + 6) & 0xff) << 8 |
+             ((long)getByte(index + 7) & 0xff) << 0;
+   }
+
+   public long getLong(final long index)
+   {
+      return ((long)getByte(index) & 0xff) << 56 | ((long)getByte(index + 1) & 0xff) << 48 |
+             ((long)getByte(index + 2) & 0xff) << 40 |
+             ((long)getByte(index + 3) & 0xff) << 32 |
+             ((long)getByte(index + 4) & 0xff) << 24 |
+             ((long)getByte(index + 5) & 0xff) << 16 |
+             ((long)getByte(index + 6) & 0xff) << 8 |
+             ((long)getByte(index + 7) & 0xff) << 0;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getShort(int)
+    */
+   public short getShort(final int index)
+   {
+      return (short)(getByte(index) << 8 | getByte(index + 1) & 0xFF);
+   }
+
+   public short getShort(final long index)
+   {
+      return (short)(getByte(index) << 8 | getByte(index + 1) & 0xFF);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#getUnsignedMedium(int)
+    */
+   public int getUnsignedMedium(final int index)
+   {
+      return (getByte(index) & 0xff) << 16 | (getByte(index + 1) & 0xff) << 8 | (getByte(index + 2) & 0xff) << 0;
+   }
+
+   public int getUnsignedMedium(final long index)
+   {
+      return (getByte(index) & 0xff) << 16 | (getByte(index + 1) & 0xff) << 8 | (getByte(index + 2) & 0xff) << 0;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setByte(int, byte)
+    */
+   public void setByte(final int index, final byte value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, org.jboss.messaging.core.buffers.ChannelBuffer, int, int)
+    */
+   public void setBytes(final int index, final ChannelBuffer src, final int srcIndex, final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, byte[], int, int)
+    */
+   public void setBytes(final int index, final byte[] src, final int srcIndex, final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, java.nio.ByteBuffer)
+    */
+   public void setBytes(final int index, final ByteBuffer src)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, java.io.InputStream, int)
+    */
+   public int setBytes(final int index, final InputStream in, final int length) throws IOException
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setBytes(int, java.nio.channels.ScatteringByteChannel, int)
+    */
+   public int setBytes(final int index, final ScatteringByteChannel in, final int length) throws IOException
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setInt(int, int)
+    */
+   public void setInt(final int index, final int value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setLong(int, long)
+    */
+   public void setLong(final int index, final long value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setMedium(int, int)
+    */
+   public void setMedium(final int index, final int value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#setShort(int, short)
+    */
+   public void setShort(final int index, final short value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#toByteBuffer(int, int)
+    */
+   public ByteBuffer toByteBuffer(final int index, final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#toString(int, int, java.lang.String)
+    */
+   public String toString(final int index, final int length, final String charsetName)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public int readerIndex()
+   {
+      return (int)readerIndex;
+   }
+
+   public void readerIndex(final int readerIndex)
+   {
+      checkForPacket(readerIndex);
+      this.readerIndex = readerIndex;
+   }
+
+   public int writerIndex()
+   {
+      return (int)totalSize;
+   }
+
+   public long getSize()
+   {
+      return totalSize;
+   }
+
+   public void writerIndex(final int writerIndex)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void setIndex(final int readerIndex, final int writerIndex)
+   {
+      checkForPacket(readerIndex);
+      this.readerIndex = readerIndex;
+   }
+
+   public void clear()
+   {
+   }
+
+   public boolean readable()
+   {
+      return true;
+   }
+
+   public boolean writable()
+   {
+      return false;
+   }
+
+   public int readableBytes()
+   {
+      long readableBytes = this.totalSize - this.readerIndex;
+      
+      if (readableBytes > Integer.MAX_VALUE)
+      {
+         return Integer.MAX_VALUE;
+      }
+      else
+      {
+         return (int)(this.totalSize - this.readerIndex);
+      }
+   }
+
+   public int writableBytes()
+   {
+      return 0;
+   }
+
+   public void markReaderIndex()
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void resetReaderIndex()
+   {
+      checkForPacket(0);
+   }
+
+   public void markWriterIndex()
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void resetWriterIndex()
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void discardReadBytes()
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public short getUnsignedByte(final int index)
+   {
+      return (short)(getByte(index) & 0xFF);
+   }
+
+   public int getUnsignedShort(final int index)
+   {
+      return getShort(index) & 0xFFFF;
+   }
+
+   public int getMedium(final int index)
+   {
+      int value = getUnsignedMedium(index);
+      if ((value & 0x800000) != 0)
+      {
+         value |= 0xff000000;
+      }
+      return value;
+   }
+
+   public long getUnsignedInt(final int index)
+   {
+      return getInt(index) & 0xFFFFFFFFL;
+   }
+
+   public void getBytes(int index, final byte[] dst)
+   {
+      // TODO: optimize this by using System.arraycopy
+      for (int i = 0; i < dst.length; i++)
+      {
+         dst[i] = getByte(index++);
+      }
+   }
+
+   public void getBytes(long index, final byte[] dst)
+   {
+      // TODO: optimize this by using System.arraycopy
+      for (int i = 0; i < dst.length; i++)
+      {
+         dst[i] = getByte(index++);
+      }
+   }
+
+   public void getBytes(final int index, final ChannelBuffer dst)
+   {
+      getBytes(index, dst, dst.writableBytes());
+   }
+
+   public void getBytes(final int index, final ChannelBuffer dst, final int length)
+   {
+      if (length > dst.writableBytes())
+      {
+         throw new IndexOutOfBoundsException();
+      }
+      getBytes(index, dst, dst.writerIndex(), length);
+      dst.writerIndex(dst.writerIndex() + length);
+   }
+
+   public void setBytes(final int index, final byte[] src)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void setBytes(final int index, final ChannelBuffer src)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void setBytes(final int index, final ChannelBuffer src, final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void setZero(final int index, final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public short readUnsignedByte()
+   {
+      return (short)(readByte() & 0xFF);
+   }
+
+   public short readShort()
+   {
+      short v = getShort(readerIndex);
+      readerIndex += 2;
+      return v;
+   }
+
+   public int readUnsignedShort()
+   {
+      return readShort() & 0xFFFF;
+   }
+
+   public int readMedium()
+   {
+      int value = readUnsignedMedium();
+      if ((value & 0x800000) != 0)
+      {
+         value |= 0xff000000;
+      }
+      return value;
+   }
+
+   public int readUnsignedMedium()
+   {
+      int v = getUnsignedMedium(readerIndex);
+      readerIndex += 3;
+      return v;
+   }
+
+   public int readInt()
+   {
+      int v = getInt(readerIndex);
+      readerIndex += 4;
+      return v;
+   }
+
+   public long readUnsignedInt()
+   {
+      return readInt() & 0xFFFFFFFFL;
+   }
+
+   public long readLong()
+   {
+      long v = getLong(readerIndex);
+      readerIndex += 8;
+      return v;
+   }
+
+   public void readBytes(final byte[] dst, final int dstIndex, final int length)
+   {
+      getBytes(readerIndex, dst, dstIndex, length);
+      readerIndex += length;
+   }
+
+   public void readBytes(final byte[] dst)
+   {
+      readBytes(dst, 0, dst.length);
+   }
+
+   public void readBytes(final ChannelBuffer dst)
+   {
+      readBytes(dst, dst.writableBytes());
+   }
+
+   public void readBytes(final ChannelBuffer dst, final int length)
+   {
+      if (length > dst.writableBytes())
+      {
+         throw new IndexOutOfBoundsException();
+      }
+      readBytes(dst, dst.writerIndex(), length);
+      dst.writerIndex(dst.writerIndex() + length);
+   }
+
+   public void readBytes(final ChannelBuffer dst, final int dstIndex, final int length)
+   {
+      getBytes(readerIndex, dst, dstIndex, length);
+      readerIndex += length;
+   }
+
+   public void readBytes(final ByteBuffer dst)
+   {
+      int length = dst.remaining();
+      getBytes(readerIndex, dst);
+      readerIndex += length;
+   }
+
+   public int readBytes(final GatheringByteChannel out, final int length) throws IOException
+   {
+      int readBytes = getBytes((int)readerIndex, out, length);
+      readerIndex += readBytes;
+      return readBytes;
+   }
+
+   public void readBytes(final OutputStream out, final int length) throws IOException
+   {
+      getBytes(readerIndex, out, length);
+      readerIndex += length;
+   }
+
+   public void skipBytes(final int length)
+   {
+
+      long newReaderIndex = readerIndex + length;
+      checkForPacket(newReaderIndex);
+      readerIndex = newReaderIndex;
+   }
+
+   public void writeByte(final byte value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeShort(final short value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeMedium(final int value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeInt(final int value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeLong(final long value)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeBytes(final byte[] src, final int srcIndex, final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeBytes(final byte[] src)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeBytes(final ChannelBuffer src)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeBytes(final ChannelBuffer src, final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeBytes(MessagingBuffer src, int srcIndex, int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeBytes(final ChannelBuffer src, final int srcIndex, final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeBytes(final ByteBuffer src)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeBytes(final InputStream in, final int length) throws IOException
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public int writeBytes(final ScatteringByteChannel in, final int length) throws IOException
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public void writeZero(final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public ByteBuffer toByteBuffer()
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public ByteBuffer[] toByteBuffers()
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public ByteBuffer[] toByteBuffers(final int index, final int length)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public String toString(final String charsetName)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   public Object getUnderlyingBuffer()
+   {
+      return this;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readBoolean()
+    */
+   public boolean readBoolean()
+   {
+      return readByte() != 0;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readChar()
+    */
+   public char readChar()
+   {
+      return (char)readShort();
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readDouble()
+    */
+   public double readDouble()
+   {
+      return Double.longBitsToDouble(readLong());
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readFloat()
+    */
+   public float readFloat()
+   {
+      return Float.intBitsToFloat(readInt());
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readNullableSimpleString()
+    */
+   public SimpleString readNullableSimpleString()
+   {
+      int b = readByte();
+      if (b == DataConstants.NULL)
+      {
+         return null;
+      }
+      else
+      {
+         return readSimpleString();
+      }
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readNullableString()
+    */
+   public String readNullableString()
+   {
+      int b = readByte();
+      if (b == DataConstants.NULL)
+      {
+         return null;
+      }
+      else
+      {
+         return readString();
+      }
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readSimpleString()
+    */
+   public SimpleString readSimpleString()
+   {
+      int len = readInt();
+      byte[] data = new byte[len];
+      readBytes(data);
+      return new SimpleString(data);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readString()
+    */
+   public String readString()
+   {
+      int len = readInt();
+      char[] chars = new char[len];
+      for (int i = 0; i < len; i++)
+      {
+         chars[i] = readChar();
+      }
+      return new String(chars);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#readUTF()
+    */
+   public String readUTF() throws Exception
+   {
+      return UTF8Util.readUTF(this);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeBoolean(boolean)
+    */
+   public void writeBoolean(final boolean val)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeChar(char)
+    */
+   public void writeChar(final char val)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeDouble(double)
+    */
+   public void writeDouble(final double val)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeFloat(float)
+    */
+   public void writeFloat(final float val)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeNullableSimpleString(org.jboss.messaging.util.SimpleString)
+    */
+   public void writeNullableSimpleString(final SimpleString val)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeNullableString(java.lang.String)
+    */
+   public void writeNullableString(final String val)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeSimpleString(org.jboss.messaging.util.SimpleString)
+    */
+   public void writeSimpleString(final SimpleString val)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeString(java.lang.String)
+    */
+   public void writeString(final String val)
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.remoting.spi.MessagingBuffer#writeUTF(java.lang.String)
+    */
+   public void writeUTF(final String utf) throws Exception
+   {
+      throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.buffers.ChannelBuffer#compareTo(org.jboss.messaging.core.buffers.ChannelBuffer)
+    */
+   public int compareTo(final ChannelBuffer buffer)
+   {
+      return -1;
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private void popPacket()
+   {
+      try
+      {
+
+         if (streamEnded)
+         {
+            // no more packets, we are over the last one already
+            throw new IndexOutOfBoundsException();
+         }
+
+         int sizeToAdd = currentPacket != null ? currentPacket.getBody().length : 1;
+         currentPacket = packets.poll(readTimeout, TimeUnit.SECONDS);
+         if (currentPacket == null)
+         {
+            throw new IndexOutOfBoundsException();
+         }
+
+         if (currentPacket.getBody() == null) // Empty packet as a signal to interruption
+         {
+            currentPacket = null;
+            streamEnded = true;
+            throw new IndexOutOfBoundsException();
+         }
+
+         consumerInternal.flowControl(currentPacket.getPacketSize(), true);
+
+         packetPosition += sizeToAdd;
+
+         packetLastPosition = packetPosition + currentPacket.getBody().length;
+      }
+      catch (IndexOutOfBoundsException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   private void checkForPacket(final long index)
+   {
+      if (this.outStream != null)
+      {
+         throw new IllegalAccessError("Can't read the messageBody after setting outputStream");
+      }
+      if (index >= totalSize)
+      {
+         throw new IndexOutOfBoundsException();
+      }
+      if (index < lastIndex)
+      {
+         throw new IllegalAccessError("LargeMessage have read-only and one-way buffers");
+      }
+      lastIndex = index;
+
+      while (index >= packetLastPosition && !streamEnded)
+      {
+         popPacket();
+      }
+   }
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: trunk/src/main/org/jboss/messaging/core/message/Message.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/Message.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/message/Message.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -83,6 +83,10 @@
    void decodeProperties(MessagingBuffer buffer);
       
    int getBodySize();
+
+   boolean isLargeMessage();
+   
+   long getLargeBodySize();
          
    // Used on Message chunk
    void encodeBody(MessagingBuffer buffer, long start, int size);

Modified: trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalLargeServerMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalLargeServerMessage.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalLargeServerMessage.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -156,6 +156,19 @@
       // FIXME: The file could be bigger than MAX_INT
       return (int)bodySize;
    }
+   
+   public synchronized long getLargeBodySize()
+   {
+      try
+      {
+         validateFile();
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e.getMessage(), e);
+      }
+      return bodySize;
+   }
 
    @Override
    public synchronized int getEncodeSize()

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -41,8 +41,8 @@
    // Constants -----------------------------------------------------
 
    public static final int SESSION_RECEIVE_MESSAGE_LARGE_MESSAGE_SIZE = BASIC_PACKET_SIZE + DataConstants.SIZE_LONG +
+                                                                       DataConstants.SIZE_LONG +
                                                                        DataConstants.SIZE_INT +
-                                                                       DataConstants.SIZE_INT +
                                                                        DataConstants.SIZE_BOOLEAN +
                                                                        DataConstants.SIZE_INT;
 
@@ -63,13 +63,13 @@
    private int deliveryCount;
    
    /** Since we receive the message before the entire message was received, */
-   private int largeMessageSize;
+   private long largeMessageSize;
 
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
 
-   public SessionReceiveMessage(final long consumerID, final byte[] largeMessageHeader, final int largeMessageSize, final int deliveryCount)
+   public SessionReceiveMessage(final long consumerID, final byte[] largeMessageHeader, final long largeMessageSize, final int deliveryCount)
    {
       super(SESS_RECEIVE_MSG);
 
@@ -142,7 +142,7 @@
    /**
     * @return the largeMessageSize
     */
-   public int getLargeMessageSize()
+   public long getLargeMessageSize()
    {
       return largeMessageSize;
    }
@@ -168,7 +168,7 @@
       buffer.writeBoolean(largeMessage);
       if (largeMessage)
       {
-         buffer.writeInt(largeMessageSize);
+         buffer.writeLong(largeMessageSize);
          buffer.writeInt(largeMessageHeader.length);
          buffer.writeBytes(largeMessageHeader);
       }
@@ -190,7 +190,7 @@
 
       if (largeMessage)
       {
-         largeMessageSize = buffer.readInt();
+         largeMessageSize = buffer.readLong();
          int size = buffer.readInt();
          largeMessageHeader = new byte[size];
          buffer.readBytes(largeMessageHeader);

Modified: trunk/src/main/org/jboss/messaging/core/server/LargeServerMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/LargeServerMessage.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/server/LargeServerMessage.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -38,6 +38,8 @@
    /** Close the files if opened */
    void releaseResources();
    
+   long getLargeBodySize();
+   
    void complete() throws Exception;
    
    void deleteFile() throws Exception;

Modified: trunk/src/main/org/jboss/messaging/core/server/ServerMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/ServerMessage.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/server/ServerMessage.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -53,8 +53,6 @@
 
    int getMemoryEstimate();
 
-   boolean isLargeMessage();
-
    void setStored();
 
    boolean isStored();

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -744,7 +744,7 @@
          // we must hold one reference, or the file will be deleted before it could be delivered
          pendingLargeMessage.incrementRefCount();
 
-         sizePendingLargeMessage = pendingLargeMessage.getBodySize();
+         sizePendingLargeMessage = pendingLargeMessage.getLargeBodySize();
 
          this.ref = ref;
       }
@@ -780,7 +780,7 @@
 
                initialMessage = new SessionReceiveMessage(id,
                                                           headerBuffer.array(),
-                                                          pendingLargeMessage.getBodySize(),
+                                                          pendingLargeMessage.getLargeBodySize(),
                                                           ref.getDeliveryCount());
             }
 

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -148,6 +148,11 @@
    {
       return false;
    }
+   
+   public long getLargeBodySize()
+   {
+      return (long)getBodySize();
+   }
 
    public int getMemoryEstimate()
    {

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -31,6 +31,7 @@
 
 import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.LargeMessageBufferImpl;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 
@@ -422,8 +423,8 @@
    public long getBodyLength() throws JMSException
    {
       checkRead();
-
-      return getBody().writerIndex();
+      
+      return message.getLargeBodySize();
    }
 
    public void doBeforeSend() throws Exception

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -12,6 +12,8 @@
 
 package org.jboss.messaging.jms.client;
 
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -757,6 +759,7 @@
       {
          return String.valueOf(message.getDeliveryCount());
       }
+      
       Object val = message.getProperty(new SimpleString(name));
       if (val instanceof SimpleString)
       {
@@ -928,7 +931,30 @@
    {
       return JBossMessage.TYPE;
    }
+   
+   
+   public void setInputStream(final InputStream input) throws MessagingException
+   {
+      message.setBodyInputStream(input);
+   }
+   
+   
+   public void setOutputStream(final OutputStream output) throws MessagingException
+   {
+      message.setOutputStream(output);
+   }
 
+   public void saveToOutputStream(final OutputStream output) throws MessagingException
+   {
+      message.saveToOutputStream(output);
+   }
+
+   public boolean waitCompletionOnStream(long timeWait) throws MessagingException
+   {
+      return message.waitOutputStreamCompletion(timeWait);
+   }
+   
+
    public String toString()
    {
       StringBuffer sb = new StringBuffer("JBossMessage[");

Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -21,12 +21,11 @@
   */
 package org.jboss.test.messaging.jms.message;
 
-import java.io.BufferedOutputStream;
-import java.io.InputStream;
+import java.io.IOException;
 import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.jms.BytesMessage;
 import javax.jms.Connection;
@@ -36,6 +35,7 @@
 import javax.jms.Session;
 
 import org.jboss.messaging.jms.client.JBossMessage;
+import org.jboss.messaging.tests.util.UnitTestCase;
 import org.jboss.test.messaging.jms.JMSTestCase;
 
 /**
@@ -71,13 +71,13 @@
          prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
 
          BytesMessage m = session.createBytesMessage();
-         
-         ((JBossMessage)m).getCoreMessage().setBodyInputStream(createFakeLargeStream((byte)'j', 1024 * 1024));
 
+         ((JBossMessage)m).setInputStream(UnitTestCase.createFakeLargeStream(1024 * 1024));
+
          prod.send(m);
 
          conn.close();
-         
+
          conn = cf.createConnection();
 
          session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -87,9 +87,9 @@
          conn.start();
 
          BytesMessage rm = (BytesMessage)cons.receive(10000);
-         
+
          byte data[] = new byte[1024];
-         
+
          System.out.println("Message = " + rm);
 
          for (int i = 0; i < 1024 * 1024; i += 1024)
@@ -97,12 +97,12 @@
             System.out.println("Read message chunk " + i);
             int numberOfBytes = rm.readBytes(data);
             assertEquals(1024, numberOfBytes);
-            for (int j = 0 ; j < 1024; j++)
+            for (int j = 0; j < 1024; j++)
             {
-               assertEquals((byte)'j', data[j]);
+               assertEquals(UnitTestCase.getSamplebyte(i + j), data[j]);
             }
          }
-         
+
          assertNotNull(rm);
 
       }
@@ -115,8 +115,7 @@
       }
 
    }
-   
-   
+
    public void testSimpleLargeMessage2() throws Exception
    {
       Connection conn = null;
@@ -131,13 +130,13 @@
          prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
 
          BytesMessage m = session.createBytesMessage();
-         
-         ((JBossMessage)m).getCoreMessage().setBodyInputStream(createFakeLargeStream((byte)'j', 10));
 
+         ((JBossMessage)m).setInputStream(UnitTestCase.createFakeLargeStream(10));
+
          prod.send(m);
 
          conn.close();
-         
+
          conn = cf.createConnection();
 
          session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -147,18 +146,18 @@
          conn.start();
 
          BytesMessage rm = (BytesMessage)cons.receive(10000);
-         
+
          byte data[] = new byte[1024];
-         
+
          System.out.println("Message = " + rm);
 
          int numberOfBytes = rm.readBytes(data);
          assertEquals(10, numberOfBytes);
-         for (int j = 0 ; j < numberOfBytes; j++)
+         for (int j = 0; j < numberOfBytes; j++)
          {
-            assertEquals((byte)'j', data[j]);
+            assertEquals(UnitTestCase.getSamplebyte(j), data[j]);
          }
-         
+
          assertNotNull(rm);
 
       }
@@ -171,81 +170,104 @@
       }
 
    }
-   
-   
-   public void testReceiveAfterACK() throws Exception
-   {
-      // Make sure ACK will not delete the file while deliver is done
-   }
 
-   // Package protected ---------------------------------------------
 
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-   
-   
-   private InputStream createFakeLargeStream(final byte byteToWrite, final long size) throws Exception
+   public void testWaitOnOutputStream() throws Exception
    {
+      int msgSize = 1024 * 1024;
       
-      final PipedInputStream pipedInput = new PipedInputStream();
-      final PipedOutputStream pipedOut = new PipedOutputStream(pipedInput);
-      final OutputStream out = new BufferedOutputStream(pipedOut);
-      
-      
-      new Thread()
+      Connection conn = null;
+
+      try
       {
-         public void run()
+         conn = cf.createConnection();
+
+         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageProducer prod = session.createProducer(queue1);
+         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+         BytesMessage m = session.createBytesMessage();
+
+         ((JBossMessage)m).setInputStream(UnitTestCase.createFakeLargeStream(msgSize));
+
+         prod.send(m);
+
+         conn.close();
+
+         conn = cf.createConnection();
+
+         session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageConsumer cons = session.createConsumer(queue1);
+
+         conn.start();
+
+         BytesMessage rm = (BytesMessage)cons.receive(10000);
+         assertNotNull(rm);
+
+         final AtomicLong numberOfBytes = new AtomicLong(0);
+         
+         final AtomicInteger numberOfErrors = new AtomicInteger(0);
+
+         OutputStream out = new OutputStream()
          {
-            try
+
+            int position = 0;
+            @Override
+            public void write(int b) throws IOException
             {
-               for (long i = 0; i < size; i++)
+               numberOfBytes.incrementAndGet();
+               if (UnitTestCase.getSamplebyte(position++) != b)
                {
-                  out.write(byteToWrite);
+                  System.out.println("Wrong byte at position " + position);
+                  numberOfErrors.incrementAndGet();
                }
             }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-            }
-            finally
-            {
-               try
-               {
-                  out.close();
-               }
-               catch (Throwable ignored)
-               {
-               }
-            }
+            
+         };
+
+         
+         ((JBossMessage)rm).setOutputStream(out);
+         
+         assertTrue(((JBossMessage)rm).waitCompletionOnStream(10000));
+         
+         assertEquals(msgSize, numberOfBytes.get());
+         
+         assertEquals(0, numberOfErrors.get());
+         
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
          }
-         
-      }.start();
-      
-      
-      return pipedInput;
-      
+      }
+
    }
-   
 
-   
+   // Package protected ---------------------------------------------
 
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
    // Inner classes -------------------------------------------------
-   
-   
+
    class ThreadReader extends Thread
    {
       CountDownLatch latch;
-      
+
       ThreadReader(CountDownLatch latch)
       {
          this.latch = latch;
       }
-      
+
       public void run()
       {
       }
    }
-   
 
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -25,11 +25,11 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
@@ -83,17 +83,21 @@
    // Protected -----------------------------------------------------
 
    protected void testChunks(final boolean isXA,
+                             final boolean rollbackFirstSend,
+                             final boolean useStreamOnConsume,
                              final boolean realFiles,
                              final boolean preAck,
                              final boolean sendingBlocking,
                              final boolean testBrowser,
                              final boolean useMessageConsumer,
                              final int numberOfMessages,
-                             final int numberOfBytes,
+                             final long numberOfBytes,
                              final int waitOnConsumer,
                              final long delayDelivery) throws Exception
    {
       testChunks(isXA,
+                 rollbackFirstSend,
+                 useStreamOnConsume,
                  realFiles,
                  preAck,
                  sendingBlocking,
@@ -108,13 +112,15 @@
    }
 
    protected void testChunks(final boolean isXA,
+                             final boolean rollbackFirstSend,
+                             final boolean useStreamOnConsume,
                              final boolean realFiles,
                              final boolean preAck,
                              final boolean sendingBlocking,
                              final boolean testBrowser,
                              final boolean useMessageConsumer,
                              final int numberOfMessages,
-                             final int numberOfBytes,
+                             final long numberOfBytes,
                              final int waitOnConsumer,
                              final long delayDelivery,
                              final int producerWindow,
@@ -158,22 +164,25 @@
 
          ClientProducer producer = session.createProducer(ADDRESS);
 
-         sendMessages(numberOfMessages, numberOfBytes, delayDelivery, session, producer);
+         if (rollbackFirstSend)
+         {
+            sendMessages(numberOfMessages, numberOfBytes, delayDelivery, session, producer);
 
-         if (isXA)
-         {
-            session.end(xid, XAResource.TMSUCCESS);
-            session.rollback(xid);
-            xid = newXID();
-            session.start(xid, XAResource.TMNOFLAGS);
+            if (isXA)
+            {
+               session.end(xid, XAResource.TMSUCCESS);
+               session.rollback(xid);
+               xid = newXID();
+               session.start(xid, XAResource.TMNOFLAGS);
+            }
+            else
+            {
+               session.rollback();
+            }
+
+            validateNoFilesOnLargeDir();
          }
-         else
-         {
-            session.rollback();
-         }
 
-         validateNoFilesOnLargeDir();
-
          sendMessages(numberOfMessages, numberOfBytes, delayDelivery, session, producer);
 
          if (isXA)
@@ -223,7 +232,7 @@
             if (useMessageConsumer)
             {
                final CountDownLatch latchDone = new CountDownLatch(numberOfMessages);
-               final AtomicInteger errrors = new AtomicInteger(0);
+               final AtomicInteger errors = new AtomicInteger(0);
 
                MessageHandler handler = new MessageHandler()
                {
@@ -234,8 +243,6 @@
 
                      try
                      {
-                        latchDone.countDown();
-
                         System.out.println("Message on consumer: " + msgCounter);
 
                         if (delayDelivery > 0)
@@ -261,34 +268,79 @@
                                         ((Integer)message.getProperty(new SimpleString("counter-message"))).intValue());
                         }
 
-                        MessagingBuffer buffer = message.getBody();
-                        buffer.resetReaderIndex();
-                        assertEquals(numberOfBytes, buffer.writerIndex());
-                        for (int b = 0; b < numberOfBytes; b++)
+                        if (useStreamOnConsume)
                         {
-                           assertEquals((byte)'a', buffer.readByte());
+                           final AtomicLong bytesRead = new AtomicLong(0);
+                           message.saveToOutputStream(new OutputStream()
+                           {
+
+                              public void write(byte b[]) throws IOException
+                              {
+                                 if (b[0] == getSamplebyte(bytesRead.get()))
+                                 {
+                                    bytesRead.addAndGet(b.length);
+                                    System.out.println("Read position " + bytesRead.get() + " on consumer");
+                                 }
+                                 else
+                                 {
+                                    System.out.println("Received invalid packet at position " + bytesRead.get());
+                                 }
+                              }
+
+                              @Override
+                              public void write(int b) throws IOException
+                              {
+                                 bytesRead.incrementAndGet();
+                                 if (b == (byte)'a')
+                                 {
+                                    bytesRead.incrementAndGet();
+                                 }
+                                 else
+                                 {
+                                    System.out.println("byte not as expected!");
+                                 }
+                              }
+                           });
+
+                           assertEquals(numberOfBytes, bytesRead.get());
                         }
+                        else
+                        {
+
+                           MessagingBuffer buffer = message.getBody();
+                           buffer.resetReaderIndex();
+                           assertEquals(numberOfBytes, buffer.writerIndex());
+                           for (long b = 0; b < numberOfBytes; b++)
+                           {
+                              if (b % (1024l * 1024l) == 0)
+                              {
+                                 System.out.println("Read " + b + " bytes");
+                              }
+                              
+                              assertEquals(getSamplebyte(b), buffer.readByte());
+                           }
+                        }
                      }
                      catch (Throwable e)
                      {
                         e.printStackTrace();
-                        errrors.incrementAndGet();
+                        System.out.println("Got an error");
+                        errors.incrementAndGet();
                      }
                      finally
                      {
+                        latchDone.countDown();
                         msgCounter++;
                      }
                   }
                };
 
                session.start();
-               
-               Thread.sleep(1000);
 
                consumer.setMessageHandler(handler);
 
-               assertTrue(latchDone.await(20, TimeUnit.SECONDS));
-               assertEquals(0, errrors.get());
+               assertTrue(latchDone.await(waitOnConsumer, TimeUnit.SECONDS));
+               assertEquals(0, errors.get());
 
             }
             else
@@ -331,11 +383,58 @@
 
                   MessagingBuffer buffer = message.getBody();
                   buffer.resetReaderIndex();
-                  assertEquals(numberOfBytes, buffer.writerIndex());
-                  for (int b = 0; b < numberOfBytes; b++)
+
+                  if (useStreamOnConsume)
                   {
-                     assertEquals((byte)'a', buffer.readByte());
+                     final AtomicLong bytesRead = new AtomicLong(0);
+                     message.saveToOutputStream(new OutputStream()
+                     {
+
+                        public void write(byte b[]) throws IOException
+                        {
+                           if (b[0] == getSamplebyte(bytesRead.get()))
+                           {
+                              bytesRead.addAndGet(b.length);
+                           }
+                           else
+                           {
+                              System.out.println("Received invalid packet at position " + bytesRead.get());
+                           }
+
+                        }
+
+                        @Override
+                        public void write(int b) throws IOException
+                        {
+                           if (bytesRead.get() % (1024l * 1024l) == 0)
+                           {
+                              System.out.println("Read " + bytesRead.get() + " bytes");
+                           }
+                           if (b == (byte)'a')
+                           {
+                              bytesRead.incrementAndGet();
+                           }
+                           else
+                           {
+                              System.out.println("byte not as expected!");
+                           }
+                        }
+                     });
+
+                     assertEquals(numberOfBytes, bytesRead.get());
                   }
+                  else
+                  {
+                     for (long b = 0; b < numberOfBytes; b++)
+                     {
+                        if (b % (1024l * 1024l) == 0l)
+                        {
+                           System.out.println("Read " + b + " bytes");
+                        }
+                        assertEquals(getSamplebyte(b), buffer.readByte());
+                     }
+                  }
+
                }
 
             }
@@ -406,28 +505,30 @@
     * @throws MessagingException
     */
    private void sendMessages(final int numberOfMessages,
-                             final int numberOfBytes,
+                             final long numberOfBytes,
                              final long delayDelivery,
                              final ClientSession session,
                              final ClientProducer producer) throws Exception
    {
+      System.out.println("NumberOfBytes = " + numberOfBytes);
       for (int i = 0; i < numberOfMessages; i++)
       {
          ClientMessage message = session.createClientMessage(true);
-         
-         // If the test is using more than 1M, we will only use the Streaming, as it require too much memory from the test
+
+         // If the test is using more than 1M, we will only use the Streaming, as it require too much memory from the
+         // test
          if (numberOfBytes > 1024 * 1024 || i % 2 == 0)
          {
             System.out.println("Sending message (stream)" + i);
-            message.setBodyInputStream(createFakeLargeStream(numberOfBytes, (byte)'a'));
+            message.setBodyInputStream(createFakeLargeStream(numberOfBytes));
          }
          else
          {
             System.out.println("Sending message (array)" + i);
-            byte[] bytes = new byte[numberOfBytes];
+            byte[] bytes = new byte[(int)numberOfBytes];
             for (int j = 0; j < bytes.length; j++)
             {
-               bytes[j] = 'a';
+               bytes[j] = getSamplebyte(j);
             }
             message.getBody().writeBytes(bytes);
          }
@@ -466,13 +567,13 @@
    }
 
    protected ClientMessage createLargeClientMessage(final ClientSession session,
-                                                    final int numberOfBytes,
+                                                    final long numberOfBytes,
                                                     final boolean persistent) throws Exception
    {
 
       ClientMessage clientMessage = session.createClientMessage(persistent);
 
-      clientMessage.setBodyInputStream(createFakeLargeStream(numberOfBytes, (byte)'a'));
+      clientMessage.setBodyInputStream(createFakeLargeStream(numberOfBytes));
 
       return clientMessage;
    }
@@ -527,41 +628,6 @@
       assertEquals(0, largeMessagesFileDir.listFiles().length);
    }
 
-   protected InputStream createFakeLargeStream(final int size, final byte byteUsed) throws Exception
-   {
-      return new InputStream()
-      {
-         private int count;
-
-         private boolean closed = false;
-
-         @Override
-         public void close() throws IOException
-         {
-            super.close();
-            closed = true;
-         }
-
-         @Override
-         public int read() throws IOException
-         {
-            if (closed)
-            {
-               throw new IOException("Stream was closed");
-            }
-            if (count++ < size)
-            {
-               return byteUsed;
-            }
-            else
-            {
-               return -1;
-            }
-         }
-      };
-
-   }
-
    protected OutputStream createFakeOutputStream() throws Exception
    {
 

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -61,7 +61,7 @@
 
    // Constants -----------------------------------------------------
 
-   final static int RECEIVE_WAIT_TIME = 10000;
+   final static int RECEIVE_WAIT_TIME = 60000;
 
    private final int LARGE_MESSAGE_SIZE = 20 * 1024;
 
@@ -86,7 +86,7 @@
       internalTestResendMessage(150 * 1024);
    }
    
-   public void internalTestResendMessage(int messageSize) throws Exception
+   public void internalTestResendMessage(long messageSize) throws Exception
    {
       ClientSession session = null;
 
@@ -151,7 +151,7 @@
          
          for (int i = 0 ; i < messageSize; i++)
          {
-            assertEquals((byte)'a', msg2.getBody().readByte());
+            assertEquals(getSamplebyte(i), msg2.getBody().readByte());
          }
          
          session.close();
@@ -176,137 +176,150 @@
          {
          }
       }
-      // Reusing a largemessage should throw an exception
    }
+   public void testMessageChunkFilePersistenceOneHugeMessage() throws Exception
+   {
+      testChunks(false, false, true, true, false, false, false, false, 1, 100 * 1024l * 1024l, RECEIVE_WAIT_TIME, 0, 10 * 1024 * 1024, 1024 * 1024);
+   }
 
-   public void testMessageChunkFilePersistenceOneMessage() throws Exception
+   public void testMessageChunkFilePersistenceOneMessageStreaming() throws Exception
    {
-      testChunks(false, true, false, false, true, false, 10, 1024 * 1024, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, false, true, true, false, false, false, false, 1, 100 * 1024l * 1024l, RECEIVE_WAIT_TIME, 0);
    }
 
-   public void testMessageChunkFilePersistenceOneMessageConsumer() throws Exception
+   public void testMessageChunkFilePersistenceSmallMessageStreaming() throws Exception
    {
-      testChunks(false, true, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, false, true, true, false, false, false, false, 100, 1024, RECEIVE_WAIT_TIME, 0);
    }
 
+   public void testMessageChunkFilePersistenceOneHugeMessageConsumer() throws Exception
+   {
+      testChunks(false, false, true, true, false, false, false, true, 1, 100 * 1024 * 1024, 120000, 0, 10 * 1024 * 1024, 1024 * 1024);
+   }
+
    public void testMessageChunkFilePersistence() throws Exception
    {
-      testChunks(false, true, false, false, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, true, false, false, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceConsumer() throws Exception
    {
-      testChunks(false, true, false, false, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, true, false, false, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceXA() throws Exception
    {
-      testChunks(true, true, false, false, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, false, false, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
+   public void testMessageChunkFilePersistenceXAStream() throws Exception
+   {
+      testChunks(true, false, true, true, false, false, false, false, 1, 1024 * 1024, RECEIVE_WAIT_TIME, 0);
+   }
+
    public void testMessageChunkFilePersistenceXAConsumer() throws Exception
    {
-      testChunks(true, true, false, false, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, false, false, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceBlocked() throws Exception
    {
-      testChunks(false, true, false, true, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, true, false, true, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceBlockedConsumer() throws Exception
    {
-      testChunks(false, true, false, true, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, true, false, true, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceBlockedXA() throws Exception
    {
-      testChunks(true, true, false, true, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, false, true, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceBlockedXAConsumer() throws Exception
    {
-      testChunks(true, true, false, true, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, false, true, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceBlockedPreACK() throws Exception
    {
-      testChunks(false, true, true, true, true, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, true, true, true, true, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceBlockedPreACKConsumer() throws Exception
    {
-      testChunks(false, true, true, true, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, true, true, true, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceBlockedPreACKXA() throws Exception
    {
-      testChunks(true, true, true, true, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, true, true, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceBlockedPreACKXAConsumer() throws Exception
    {
-      testChunks(true, true, true, true, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, true, true, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkFilePersistenceDelayed() throws Exception
    {
-      testChunks(false, true, false, false, false, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
+      testChunks(false, true, false, true, false, false, false, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
    }
 
    public void testMessageChunkFilePersistenceDelayedConsumer() throws Exception
    {
-      testChunks(false, true, false, false, false, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
+      testChunks(false, true, false, true, false, false, false, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
    }
 
    public void testMessageChunkFilePersistenceDelayedXA() throws Exception
    {
-      testChunks(true, true, false, false, false, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
+      testChunks(true, true, false, true, false, false, false, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
    }
 
    public void testMessageChunkFilePersistenceDelayedXAConsumer() throws Exception
    {
-      testChunks(true, true, false, false, false, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
+      testChunks(true, true, false, true, false, false, false, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 2000);
    }
 
    public void testMessageChunkNullPersistence() throws Exception
    {
-      testChunks(false, false, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, false, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkNullPersistenceConsumer() throws Exception
    {
-      testChunks(false, false, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, false, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkNullPersistenceXA() throws Exception
    {
-      testChunks(true, false, false, false, true, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, false, false, false, true, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkNullPersistenceXAConsumer() throws Exception
    {
-      testChunks(true, false, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, false, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testMessageChunkNullPersistenceDelayed() throws Exception
    {
-      testChunks(false, false, false, false, false, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
+      testChunks(false, true, false, false, false, false, false, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
    }
 
    public void testMessageChunkNullPersistenceDelayedConsumer() throws Exception
    {
-      testChunks(false, false, false, false, false, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
+      testChunks(false, true, false, false, false, false, false, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
    }
 
    public void testMessageChunkNullPersistenceDelayedXA() throws Exception
    {
-      testChunks(true, false, false, false, false, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
+      testChunks(true, true, false, false, false, false, false, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
    }
 
    public void testMessageChunkNullPersistenceDelayedXAConsumer() throws Exception
    {
-      testChunks(true, false, false, false, false, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
+      testChunks(true, true, false, false, false, false, false, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 100);
    }
 
    public void testPageOnLargeMessage() throws Exception
@@ -322,82 +335,82 @@
 
    public void testSendSmallMessageXA() throws Exception
    {
-      testChunks(true, true, false, false, true, false, 100, 4, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, false, false, true, false, 100, 4, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testSendSmallMessageXAConsumer() throws Exception
    {
-      testChunks(true, true, false, false, true, true, 100, 4, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, false, false, true, true, 100, 4, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testSendSmallMessageNullPersistenceXA() throws Exception
    {
-      testChunks(true, false, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, false, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testSendSmallMessageNullPersistenceXAConsumer() throws Exception
    {
-      testChunks(true, false, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, false, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testSendRegularMessageNullPersistenceDelayed() throws Exception
    {
-      testChunks(false, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(false, true, false, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
    public void testSendRegularMessageNullPersistenceDelayedConsumer() throws Exception
    {
-      testChunks(false, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(false, true, false, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
    public void testSendRegularMessageNullPersistenceDelayedXA() throws Exception
    {
-      testChunks(true, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(true, true, false, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
    public void testSendRegularMessageNullPersistenceDelayedXAConsumer() throws Exception
    {
-      testChunks(true, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(true, true, false, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
    public void testSendRegularMessagePersistence() throws Exception
    {
-      testChunks(false, true, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, true, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testSendRegularMessagePersistenceConsumer() throws Exception
    {
-      testChunks(false, true, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, true, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testSendRegularMessagePersistenceXA() throws Exception
    {
-      testChunks(true, true, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testSendRegularMessagePersistenceXAConsumer() throws Exception
    {
-      testChunks(true, true, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, true, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
    public void testSendRegularMessagePersistenceDelayed() throws Exception
    {
-      testChunks(false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(false, true, false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
    public void testSendRegularMessagePersistenceDelayedConsumer() throws Exception
    {
-      testChunks(false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(false, true, false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
    public void testSendRegularMessagePersistenceDelayedXA() throws Exception
    {
-      testChunks(false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(false, true, false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
    public void testSendRegularMessagePersistenceDelayedXAConsumer() throws Exception
    {
-      testChunks(false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(false, true, false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
    public void testTwoBindingsTwoStartedConsumers() throws Exception
@@ -803,7 +816,7 @@
          for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
          {
             Message clientFile = session.createClientMessage(true);
-            clientFile.setBodyInputStream(createFakeLargeStream(SIZE, (byte)i));
+            clientFile.setBodyInputStream(createFakeLargeStream(SIZE));
             producer.send(clientFile);
 
          }
@@ -836,7 +849,7 @@
                {
                   for (int byteRead = 0; byteRead < SIZE; byteRead++)
                   {
-                     assertEquals((byte)i, msg.getBody().readByte());
+                     assertEquals(getSamplebyte(byteRead), msg.getBody().readByte());
                   }
                }
 
@@ -899,7 +912,7 @@
          session.createQueue(ADDRESS, ADDRESS, null, true);
 
          Message clientFile = session.createClientMessage(true);
-         clientFile.setBodyInputStream(createFakeLargeStream(SIZE, (byte)'a'));
+         clientFile.setBodyInputStream(createFakeLargeStream(SIZE));
 
          ClientProducer producer = session.createProducer(ADDRESS);
 
@@ -982,7 +995,7 @@
          for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
          {
             Message msg = session.createClientMessage(true);
-            msg.setBodyInputStream(createFakeLargeStream(SIZE, (byte)'a'));
+            msg.setBodyInputStream(createFakeLargeStream(SIZE));
             msg.putIntProperty(new SimpleString("key"), i);
             producer.send(msg);
 

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/BridgeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/BridgeTest.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/BridgeTest.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -59,240 +59,375 @@
 
    public void testSimpleBridge() throws Exception
    {
-      Map<String, Object> server0Params = new HashMap<String, Object>();
-      MessagingServer server0 = createClusteredServerWithParams(0, false, server0Params);
+      internaltestSimpleBridge(false, false);
+   }
 
-      Map<String, Object> server1Params = new HashMap<String, Object>();
-      server1Params.put(SERVER_ID_PROP_NAME, 1);
-      MessagingServer server1 = createClusteredServerWithParams(1, false, server1Params);
+   public void testSimpleBridgeFiles() throws Exception
+   {
+      internaltestSimpleBridge(false, true);
+   }
 
-      final String testAddress = "testAddress";
-      final String queueName0 = "queue0";
-      final String forwardAddress = "forwardAddress";
-      final String queueName1 = "queue1";
+   public void testSimpleBridgeLargeMessageNullPersistence() throws Exception
+   {
+      internaltestSimpleBridge(true, false);
+   }
 
-      Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();
-      TransportConfiguration server0tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
-                                                                    server0Params);
-      TransportConfiguration server1tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
-                                                                    server1Params);
-      connectors.put(server1tc.getName(), server1tc);
+   public void testSimpleBridgeLargeMessageFiles() throws Exception
+   {
+      internaltestSimpleBridge(true, true);
+   }
 
-      server0.getConfiguration().setConnectorConfigurations(connectors);
+   public void internaltestSimpleBridge(boolean largeMessage, boolean useFiles) throws Exception
+   {
+      MessagingServer server0 = null;
+      MessagingServer server1 = null;
 
-      Pair<String, String> connectorPair = new Pair<String, String>(server1tc.getName(), null);
+      try
+      {
 
-      BridgeConfiguration bridgeConfiguration = new BridgeConfiguration("bridge1",
-                                                                        queueName0,
-                                                                        forwardAddress,
-                                                                        null,                                                                   
-                                                                        null,
-                                                                        1000,
-                                                                        1d,
-                                                                        -1,
-                                                                        true,
-                                                                        false,                                                                        
-                                                                        connectorPair);
+         Map<String, Object> server0Params = new HashMap<String, Object>();
+         server0 = createClusteredServerWithParams(0, useFiles, server0Params);
 
-      List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
-      bridgeConfigs.add(bridgeConfiguration);
-      server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
+         Map<String, Object> server1Params = new HashMap<String, Object>();
+         server1Params.put(SERVER_ID_PROP_NAME, 1);
+         server1 = createClusteredServerWithParams(1, useFiles, server1Params);
 
-      QueueConfiguration queueConfig0 = new QueueConfiguration(testAddress, queueName0, null, true);
-      List<QueueConfiguration> queueConfigs0 = new ArrayList<QueueConfiguration>();
-      queueConfigs0.add(queueConfig0);
-      server0.getConfiguration().setQueueConfigurations(queueConfigs0);
+         final String testAddress = "testAddress";
+         final String queueName0 = "queue0";
+         final String forwardAddress = "forwardAddress";
+         final String queueName1 = "queue1";
 
-      QueueConfiguration queueConfig1 = new QueueConfiguration(forwardAddress, queueName1, null, true);
-      List<QueueConfiguration> queueConfigs1 = new ArrayList<QueueConfiguration>();
-      queueConfigs1.add(queueConfig1);
-      server1.getConfiguration().setQueueConfigurations(queueConfigs1);
+         Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();
+         TransportConfiguration server0tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+                                                                       server0Params);
 
-      server1.start();
-      server0.start();
+         TransportConfiguration server1tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+                                                                       server1Params);
+         connectors.put(server1tc.getName(), server1tc);
 
-      ClientSessionFactory sf0 = new ClientSessionFactoryImpl(server0tc);
+         server0.getConfiguration().setConnectorConfigurations(connectors);
 
-      ClientSessionFactory sf1 = new ClientSessionFactoryImpl(server1tc);
+         Pair<String, String> connectorPair = new Pair<String, String>(server1tc.getName(), null);
 
-      ClientSession session0 = sf0.createSession(false, true, true);
+         BridgeConfiguration bridgeConfiguration = new BridgeConfiguration("bridge1",
+                                                                           queueName0,
+                                                                           forwardAddress,
+                                                                           null,
+                                                                           null,
+                                                                           1000,
+                                                                           1d,
+                                                                           -1,
+                                                                           true,
+                                                                           false,
+                                                                           connectorPair);
 
-      ClientSession session1 = sf1.createSession(false, true, true);
+         List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
+         bridgeConfigs.add(bridgeConfiguration);
+         server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
 
-      ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
+         QueueConfiguration queueConfig0 = new QueueConfiguration(testAddress, queueName0, null, true);
+         List<QueueConfiguration> queueConfigs0 = new ArrayList<QueueConfiguration>();
+         queueConfigs0.add(queueConfig0);
+         server0.getConfiguration().setQueueConfigurations(queueConfigs0);
 
-      ClientConsumer consumer1 = session1.createConsumer(queueName1);
+         QueueConfiguration queueConfig1 = new QueueConfiguration(forwardAddress, queueName1, null, true);
+         List<QueueConfiguration> queueConfigs1 = new ArrayList<QueueConfiguration>();
+         queueConfigs1.add(queueConfig1);
+         server1.getConfiguration().setQueueConfigurations(queueConfigs1);
 
-      session1.start();
+         server1.start();
+         server0.start();
 
-      final int numMessages = 10;
+         ClientSessionFactory sf0 = new ClientSessionFactoryImpl(server0tc);
 
-      final SimpleString propKey = new SimpleString("testkey");
+         ClientSessionFactory sf1 = new ClientSessionFactoryImpl(server1tc);
 
-      for (int i = 0; i < numMessages; i++)
-      {
-         ClientMessage message = session0.createClientMessage(false);
+         ClientSession session0 = sf0.createSession(false, true, true);
 
-         message.putIntProperty(propKey, i);
+         ClientSession session1 = sf1.createSession(false, true, true);
 
-         producer0.send(message);
-      }
+         ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
 
-      for (int i = 0; i < numMessages; i++)
-      {
-         ClientMessage message = consumer1.receive(200);
+         ClientConsumer consumer1 = session1.createConsumer(queueName1);
 
-         assertNotNull(message);
+         session1.start();
 
-         assertEquals((Integer)i, (Integer)message.getProperty(propKey));
+         final int numMessages = 10;
 
-         message.acknowledge();
-      }
+         final SimpleString propKey = new SimpleString("testkey");
 
-      assertNull(consumer1.receive(200));
+         for (int i = 0; i < numMessages; i++)
+         {
+            ClientMessage message = session0.createClientMessage(false);
 
-      session0.close();
+            if (largeMessage)
+            {
+               message.setBodyInputStream(createFakeLargeStream(1024 * 1024));
+            }
 
-      session1.close();
+            message.putIntProperty(propKey, i);
 
-      sf0.close();
+            producer0.send(message);
+         }
 
-      sf1.close();
+         for (int i = 0; i < numMessages; i++)
+         {
+            ClientMessage message = consumer1.receive(200);
 
-      server0.stop();
+            assertNotNull(message);
 
-      server1.stop();
+            assertEquals((Integer)i, (Integer)message.getProperty(propKey));
+
+            if (largeMessage)
+            {
+               readMessages(message);
+            }
+
+            message.acknowledge();
+         }
+
+         assertNull(consumer1.receive(200));
+
+         session0.close();
+
+         session1.close();
+
+         sf0.close();
+
+         sf1.close();
+
+      }
+      finally
+      {
+         try
+         {
+            server0.stop();
+         }
+         catch (Throwable ignored)
+         {
+         }
+
+         try
+         {
+            server1.stop();
+         }
+         catch (Throwable ignored)
+         {
+         }
+      }
+
    }
 
-   
+   /**
+    * @param message
+    */
+   private void readMessages(ClientMessage message)
+   {
+      byte byteRead[] = new byte[1024];
+
+      for (int j = 0; j < 1024; j++)
+      {
+         message.getBody().readBytes(byteRead);
+      }
+   }
+
    public void testWithFilter() throws Exception
    {
-      Map<String, Object> server0Params = new HashMap<String, Object>();
-      MessagingServer server0 = createClusteredServerWithParams(0, false, server0Params);
+      internalTestWithFilter(false, false);
+   }
 
-      Map<String, Object> server1Params = new HashMap<String, Object>();
-      server1Params.put(SERVER_ID_PROP_NAME, 1);
-      MessagingServer server1 = createClusteredServerWithParams(1, false, server1Params);
+   public void testWithFilterFiles() throws Exception
+   {
+      internalTestWithFilter(false, true);
+   }
 
-      final String testAddress = "testAddress";
-      final String queueName0 = "queue0";
-      final String forwardAddress = "forwardAddress";
-      final String queueName1 = "queue1";
+   public void testWithFilterLargeMessages() throws Exception
+   {
+      internalTestWithFilter(true, false);
+   }
 
-      Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();
-      TransportConfiguration server0tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
-                                                                    server0Params);
-      TransportConfiguration server1tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
-                                                                    server1Params);
-      connectors.put(server1tc.getName(), server1tc);
+   public void testWithFilterLargeMessagesFiles() throws Exception
+   {
+      internalTestWithFilter(true, true);
+   }
 
-      server0.getConfiguration().setConnectorConfigurations(connectors);
+   public void internalTestWithFilter(final boolean largeMessage, final boolean useFiles) throws Exception
+   {
+      MessagingServer server0 = null;
+      MessagingServer server1 = null;
 
-      Pair<String, String> connectorPair = new Pair<String, String>(server1tc.getName(), null);
+      try
+      {
 
-      final String filterString = "animal='goat'";
+         Map<String, Object> server0Params = new HashMap<String, Object>();
+         server0 = createClusteredServerWithParams(0, useFiles, server0Params);
 
-      BridgeConfiguration bridgeConfiguration = new BridgeConfiguration("bridge1",
-                                                                        queueName0,
-                                                                        forwardAddress,
-                                                                        filterString,                                                                    
-                                                                        null,
-                                                                        1000,
-                                                                        1d,
-                                                                        -1,
-                                                                        true,
-                                                                        false,                                                                        
-                                                                        connectorPair);
+         Map<String, Object> server1Params = new HashMap<String, Object>();
+         server1Params.put(SERVER_ID_PROP_NAME, 1);
+         server1 = createClusteredServerWithParams(1, useFiles, server1Params);
 
-      List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
-      bridgeConfigs.add(bridgeConfiguration);
-      server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
+         final String testAddress = "testAddress";
+         final String queueName0 = "queue0";
+         final String forwardAddress = "forwardAddress";
+         final String queueName1 = "queue1";
 
-      QueueConfiguration queueConfig0 = new QueueConfiguration(testAddress, queueName0, null, true);
-      List<QueueConfiguration> queueConfigs0 = new ArrayList<QueueConfiguration>();
-      queueConfigs0.add(queueConfig0);
-      server0.getConfiguration().setQueueConfigurations(queueConfigs0);
+         Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();
+         TransportConfiguration server0tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+                                                                       server0Params);
+         TransportConfiguration server1tc = new TransportConfiguration("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory",
+                                                                       server1Params);
+         connectors.put(server1tc.getName(), server1tc);
 
-      QueueConfiguration queueConfig1 = new QueueConfiguration(forwardAddress, queueName1, null, true);
-      List<QueueConfiguration> queueConfigs1 = new ArrayList<QueueConfiguration>();
-      queueConfigs1.add(queueConfig1);
-      server1.getConfiguration().setQueueConfigurations(queueConfigs1);
+         server0.getConfiguration().setConnectorConfigurations(connectors);
 
-      server1.start();
-      server0.start();
+         Pair<String, String> connectorPair = new Pair<String, String>(server1tc.getName(), null);
 
-      ClientSessionFactory sf0 = new ClientSessionFactoryImpl(server0tc);
+         final String filterString = "animal='goat'";
 
-      ClientSessionFactory sf1 = new ClientSessionFactoryImpl(server1tc);
+         BridgeConfiguration bridgeConfiguration = new BridgeConfiguration("bridge1",
+                                                                           queueName0,
+                                                                           forwardAddress,
+                                                                           filterString,
+                                                                           null,
+                                                                           1000,
+                                                                           1d,
+                                                                           -1,
+                                                                           true,
+                                                                           false,
+                                                                           connectorPair);
 
-      ClientSession session0 = sf0.createSession(false, true, true);
+         List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
+         bridgeConfigs.add(bridgeConfiguration);
+         server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
 
-      ClientSession session1 = sf1.createSession(false, true, true);
+         QueueConfiguration queueConfig0 = new QueueConfiguration(testAddress, queueName0, null, true);
+         List<QueueConfiguration> queueConfigs0 = new ArrayList<QueueConfiguration>();
+         queueConfigs0.add(queueConfig0);
+         server0.getConfiguration().setQueueConfigurations(queueConfigs0);
 
-      ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
+         QueueConfiguration queueConfig1 = new QueueConfiguration(forwardAddress, queueName1, null, true);
+         List<QueueConfiguration> queueConfigs1 = new ArrayList<QueueConfiguration>();
+         queueConfigs1.add(queueConfig1);
+         server1.getConfiguration().setQueueConfigurations(queueConfigs1);
 
-      ClientConsumer consumer1 = session1.createConsumer(queueName1);
+         server1.start();
+         server0.start();
 
-      session1.start();
+         ClientSessionFactory sf0 = new ClientSessionFactoryImpl(server0tc);
 
-      final int numMessages = 10;
+         ClientSessionFactory sf1 = new ClientSessionFactoryImpl(server1tc);
 
-      final SimpleString propKey = new SimpleString("testkey");
+         ClientSession session0 = sf0.createSession(false, true, true);
 
-      final SimpleString selectorKey = new SimpleString("animal");
+         ClientSession session1 = sf1.createSession(false, true, true);
 
-      for (int i = 0; i < numMessages; i++)
-      {
-         ClientMessage message = session0.createClientMessage(false);
+         ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
 
-         message.putIntProperty(propKey, i);
+         ClientConsumer consumer1 = session1.createConsumer(queueName1);
 
-         message.putStringProperty(selectorKey, new SimpleString("monkey"));
+         session1.start();
 
-         producer0.send(message);
-      }
+         final int numMessages = 10;
 
-      assertNull(consumer1.receive(200));
+         final SimpleString propKey = new SimpleString("testkey");
 
-      for (int i = 0; i < numMessages; i++)
-      {
-         ClientMessage message = session0.createClientMessage(false);
+         final SimpleString selectorKey = new SimpleString("animal");
 
-         message.putIntProperty(propKey, i);
+         for (int i = 0; i < numMessages; i++)
+         {
+            ClientMessage message = session0.createClientMessage(false);
 
-         message.putStringProperty(selectorKey, new SimpleString("goat"));
+            message.putIntProperty(propKey, i);
 
-         producer0.send(message);
-      }
+            message.putStringProperty(selectorKey, new SimpleString("monkey"));
+            
+            if (largeMessage)
+            {
+               message.setBodyInputStream(createFakeLargeStream(1024 * 1024));
+            }
 
-      for (int i = 0; i < numMessages; i++)
-      {
-         ClientMessage message = consumer1.receive(200);
+            producer0.send(message);
+         }
 
-         assertNotNull(message);
+         assertNull(consumer1.receive(200));
 
-         assertEquals((Integer)i, (Integer)message.getProperty(propKey));
+         for (int i = 0; i < numMessages; i++)
+         {
+            ClientMessage message = session0.createClientMessage(false);
 
-         message.acknowledge();
-      }
+            message.putIntProperty(propKey, i);
 
-      assertNull(consumer1.receive(200));
+            message.putStringProperty(selectorKey, new SimpleString("goat"));
 
-      session0.close();
+            if (largeMessage)
+            {
+               message.setBodyInputStream(createFakeLargeStream(1024 * 1024));
+            }
 
-      session1.close();
+            producer0.send(message);
+         }
 
-      sf0.close();
+         for (int i = 0; i < numMessages; i++)
+         {
+            ClientMessage message = consumer1.receive(200);
 
-      sf1.close();
+            assertNotNull(message);
 
-      server0.stop();
+            assertEquals((Integer)i, (Integer)message.getProperty(propKey));
 
-      server1.stop();
+            message.acknowledge();
+            
+            if (largeMessage)
+            {
+               readMessages(message);
+            }
+         }
+
+         assertNull(consumer1.receive(200));
+
+         session0.close();
+
+         session1.close();
+
+         sf0.close();
+
+         sf1.close();
+      }
+
+      finally
+      {
+         try
+         {
+            server0.stop();
+         }
+         catch (Throwable ignored)
+         {
+         }
+
+         try
+         {
+            server1.stop();
+         }
+         catch (Throwable ignored)
+         {
+         }
+
+      }
+
    }
-
+   
    public void testWithTransformer() throws Exception
    {
+      internaltestWithTransformer(false);
+   }
+
+   public void testWithTransformerFiles() throws Exception
+   {
+      internaltestWithTransformer(true);
+   }
+
+   public void internaltestWithTransformer(boolean useFiles) throws Exception
+   {
       Map<String, Object> server0Params = new HashMap<String, Object>();
       MessagingServer server0 = createClusteredServerWithParams(0, false, server0Params);
 
@@ -319,13 +454,13 @@
       BridgeConfiguration bridgeConfiguration = new BridgeConfiguration("bridge1",
                                                                         queueName0,
                                                                         forwardAddress,
-                                                                        null,                                                                      
+                                                                        null,
                                                                         SimpleTransformer.class.getName(),
                                                                         1000,
                                                                         1d,
                                                                         -1,
                                                                         true,
-                                                                        false,                                                                        
+                                                                        false,
                                                                         connectorPair);
 
       List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
@@ -370,7 +505,7 @@
          message.putStringProperty(propKey, new SimpleString("bing"));
 
          message.getBody().writeString("doo be doo be doo be doo");
-
+         
          producer0.send(message);
       }
 
@@ -389,6 +524,8 @@
          assertEquals("dee be dee be dee be dee", sval);
 
          message.acknowledge();
+         
+         
       }
 
       assertNull(consumer1.receive(200));
@@ -405,5 +542,18 @@
 
       server1.stop();
    }
+   
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      clearData();
+   }
+   
+   protected void tearDown() throws Exception
+   {
+      clearData();
+      super.setUp();
+   }
 
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/SimpleTransformer.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/SimpleTransformer.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/SimpleTransformer.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -57,6 +57,8 @@
       //Change the body
       MessagingBuffer buffer = message.getBody();
       
+      buffer.readerIndex(0);
+      
       String str = buffer.readString();
       
       if (!str.equals("doo be doo be doo be doo"))

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTestBase.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -41,10 +41,12 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.jms.BytesMessage;
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.DeliveryMode;
 import javax.jms.Destination;
+import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
@@ -69,6 +71,7 @@
 import org.jboss.messaging.jms.bridge.DestinationFactory;
 import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
 import org.jboss.messaging.jms.client.JBossConnectionFactory;
+import org.jboss.messaging.jms.client.JBossMessage;
 import org.jboss.messaging.jms.server.JMSServerManager;
 import org.jboss.messaging.jms.server.impl.JMSServerManagerImpl;
 import org.jboss.messaging.jms.server.management.JMSQueueControlMBean;
@@ -307,7 +310,7 @@
       localTargetQueue = (Queue)localTargetQueueFactory.createDestination();
    }
 
-   protected void sendMessages(ConnectionFactory cf, Destination dest, int start, int numMessages, boolean persistent) throws Exception
+   protected void sendMessages(ConnectionFactory cf, Destination dest, int start, int numMessages, boolean persistent, boolean largeMessage) throws Exception
    {
       Connection conn = null;
 
@@ -323,9 +326,19 @@
 
          for (int i = start; i < start + numMessages; i++)
          {
-            TextMessage tm = sess.createTextMessage("message" + i);
+            if (largeMessage)
+            {
+               BytesMessage msg = sess.createBytesMessage();
+               ((JBossMessage)msg).setInputStream(createFakeLargeStream(1024l * 1024l));
+               msg.setStringProperty("msg", "message" + i);
+               prod.send(msg);
+            }
+            else
+            {
+               TextMessage tm = sess.createTextMessage("message" + i);
+               prod.send(tm);
+            }
 
-            prod.send(tm);
          }
       }
       finally
@@ -341,7 +354,8 @@
                                         Destination dest,
                                         QualityOfServiceMode qosMode,
                                         int numMessages,
-                                        boolean longWaitForFirst) throws Exception
+                                        boolean longWaitForFirst,
+                                        boolean largeMessage) throws Exception
    {
       Connection conn = null;
 
@@ -357,7 +371,7 @@
 
          // Consume the messages
 
-         Set msgs = new HashSet();
+         Set<String> msgs = new HashSet<String>();
 
          int count = 0;
 
@@ -365,7 +379,7 @@
          // waiting for recovery to kick in
          while (true)
          {
-            TextMessage tm = (TextMessage)cons.receive(count == 0 ? (longWaitForFirst ? 60000 : 10000) : 5000);
+            Message tm = cons.receive(count == 0 ? (longWaitForFirst ? 60000 : 10000) : 5000);
 
             if (tm == null)
             {
@@ -373,8 +387,22 @@
             }
 
             // log.info("Got message " + tm.getText());
+            
+            if (largeMessage)
+            {
+               BytesMessage bmsg = (BytesMessage)tm;
+               msgs.add(tm.getStringProperty("msg"));
+               byte buffRead[] = new byte[1024];
+               for (int i = 0; i < 1024; i++)
+               {
+                  assertEquals(1024, bmsg.readBytes(buffRead));
+               }
+            }
+            else
+            {
+               msgs.add(((TextMessage)tm).getText());
+            }
 
-            msgs.add(tm.getText());
 
             count++;
 
@@ -413,7 +441,7 @@
       }
    }
 
-   protected void checkAllMessageReceivedInOrder(ConnectionFactory cf, Destination dest, int start, int numMessages) throws Exception
+   protected void checkAllMessageReceivedInOrder(ConnectionFactory cf, Destination dest, int start, int numMessages, boolean largeMessage) throws Exception
    {
       Connection conn = null;
       try
@@ -430,13 +458,25 @@
 
          for (int i = 0; i < numMessages; i++)
          {
-            TextMessage tm = (TextMessage)cons.receive(30000);
+            Message tm = cons.receive(30000);
 
             assertNotNull(tm);
-
-            // log.info("Got message " + tm.getText());
-
-            assertEquals("message" + (i + start), tm.getText());
+            
+            
+            if (largeMessage)
+            {
+               BytesMessage bmsg = (BytesMessage)tm;
+               assertEquals("message" + (i + start), tm.getStringProperty("msg"));
+               byte buffRead[] = new byte[1024];
+               for (int j = 0; j < 1024; j++)
+               {
+                  assertEquals(1024, bmsg.readBytes(buffRead));
+               }
+            }
+            else
+            {
+               assertEquals("message" + (i + start),((TextMessage)tm).getText());
+            }
          }
       }
       finally
@@ -495,5 +535,4 @@
    }
 
    // Inner classes -------------------------------------------------------------------
-
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/JMSBridgeReconnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/JMSBridgeReconnectionTest.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/JMSBridgeReconnectionTest.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -21,7 +21,6 @@
  */
 package org.jboss.messaging.tests.integration.jms.bridge;
 
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
 import org.jboss.messaging.jms.bridge.impl.JMSBridgeImpl;
@@ -45,36 +44,42 @@
    
    public void testCrashAndReconnectDestBasic_OnceAndOnlyOnce_P() throws Exception
    {
-      testCrashAndReconnectDestBasic(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true);
+      testCrashAndReconnectDestBasic(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, false);
    }
+
+//  The bridge won't work with largeMessages & failures
+//   public void testCrashAndReconnectDestBasic_OnceAndOnlyOnce_P_LargeMessage() throws Exception
+//   {
+//      testCrashAndReconnectDestBasic(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, true, true);
+//   }
    
    public void testCrashAndReconnectDestBasic_OnceAndOnlyOnce_NP() throws Exception
    {
-      testCrashAndReconnectDestBasic(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false);
+      testCrashAndReconnectDestBasic(QualityOfServiceMode.ONCE_AND_ONLY_ONCE, false, false);
    }
 
    // dups ok
 
    public void testCrashAndReconnectDestBasic_DuplicatesOk_P() throws Exception
    {
-      testCrashAndReconnectDestBasic(QualityOfServiceMode.DUPLICATES_OK, true);
+      testCrashAndReconnectDestBasic(QualityOfServiceMode.DUPLICATES_OK, true, false);
    }
 
    public void testCrashAndReconnectDestBasic_DuplicatesOk_NP() throws Exception
    {
-      testCrashAndReconnectDestBasic(QualityOfServiceMode.DUPLICATES_OK, false);
+      testCrashAndReconnectDestBasic(QualityOfServiceMode.DUPLICATES_OK, false, false);
    }
 
    // At most once
 
    public void testCrashAndReconnectDestBasic_AtMostOnce_P() throws Exception
    {
-      testCrashAndReconnectDestBasic(QualityOfServiceMode.AT_MOST_ONCE, true);
+      testCrashAndReconnectDestBasic(QualityOfServiceMode.AT_MOST_ONCE, true, false);
    }
 
    public void testCrashAndReconnectDestBasic_AtMostOnce_NP() throws Exception
    {
-      testCrashAndReconnectDestBasic(QualityOfServiceMode.AT_MOST_ONCE, false);
+      testCrashAndReconnectDestBasic(QualityOfServiceMode.AT_MOST_ONCE, false, false);
    }
 
    // Crash tests specific to XA transactions
@@ -144,7 +149,7 @@
     * Send some more messages
     * Verify all messages are received
     */
-   private void testCrashAndReconnectDestBasic(QualityOfServiceMode qosMode, boolean persistent) throws Exception
+   private void testCrashAndReconnectDestBasic(QualityOfServiceMode qosMode, boolean persistent, boolean largeMessage) throws Exception
    {
       JMSBridgeImpl bridge = null;
          
@@ -162,7 +167,7 @@
          
          //Send some messages
          
-         sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2 , persistent);
+         sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2 , persistent, largeMessage);
          
          //Verify none are received
          
@@ -198,11 +203,11 @@
          
          log.info("Sending more messages");
          
-         sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent);
+         sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent, largeMessage);
          
          log.info("Sent messages");
          
-         checkMessagesReceived(cf1, targetQueue, qosMode, NUM_MESSAGES, false);                  
+         checkMessagesReceived(cf1, targetQueue, qosMode, NUM_MESSAGES, false, largeMessage);                  
       }
       finally
       {      
@@ -247,7 +252,7 @@
          final int NUM_MESSAGES = 10;            
          //Send some messages
          
-         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent);
+         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent, false);
                   
          //verify none are received
          
@@ -276,9 +281,9 @@
          
          setUpAdministeredObjects();
          
-         sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent);
+         sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent, false);
                            
-         checkMessagesReceived(cf1, targetQueue, QualityOfServiceMode.ONCE_AND_ONLY_ONCE, NUM_MESSAGES, false);         
+         checkMessagesReceived(cf1, targetQueue, QualityOfServiceMode.ONCE_AND_ONLY_ONCE, NUM_MESSAGES, false, false);         
       }
       finally
       {      

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/JMSBridgeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/JMSBridgeTest.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/bridge/JMSBridgeTest.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -21,10 +21,9 @@
  */
 package org.jboss.messaging.tests.integration.jms.bridge;
 
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
-import org.jboss.messaging.jms.bridge.impl.JMSBridgeImpl;
-import org.jboss.messaging.jms.client.JBossMessage;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.jms.Connection;
 import javax.jms.DeliveryMode;
@@ -35,10 +34,12 @@
 import javax.jms.TextMessage;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
 
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
+import org.jboss.messaging.jms.bridge.impl.JMSBridgeImpl;
+import org.jboss.messaging.jms.client.JBossMessage;
+
 /**
  * A JMSBridgeTest
  *
@@ -559,7 +560,19 @@
       }                  
    }
    
-   public void testStartBridgeWithJTATransactionAlreadyRunning() throws Exception
+   
+   
+   public void testStartBridgeWithJTATransactionAlreadyRunningLargeMessage() throws Exception
+   {
+      internalTestStartBridgeWithJTATransactionAlreadyRunning(true);
+   }
+   
+   public void testStartBridgeWithJTATransactionAlreadyRunningRegularMessage() throws Exception
+   {
+      internalTestStartBridgeWithJTATransactionAlreadyRunning(false);
+   }
+   
+   public void internalTestStartBridgeWithJTATransactionAlreadyRunning(boolean largeMessage) throws Exception
    {  
       JMSBridgeImpl bridge = null;
       
@@ -588,9 +601,9 @@
          bridge.setTransactionManager(mgr);
          bridge.start();
          
-         this.sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false);
+         this.sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false, largeMessage);
             
-         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);                          
+         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, largeMessage);                          
       }
       finally
       {      
@@ -623,8 +636,17 @@
          }     
       }                  
    }   
+   public void testNonDurableSubscriberLargeMessage() throws Exception
+   {
+      internalTestNonDurableSubscriber(true, 1);
+   }
    
-   public void testNonDurableSubscriber() throws Exception
+   public void testNonDurableSubscriberRegularMessage() throws Exception
+   {
+      internalTestNonDurableSubscriber(false, 1);
+   }
+   
+   public void internalTestNonDurableSubscriber(boolean largeMessage, int batchSize) throws Exception
    { 
       JMSBridgeImpl bridge = null;
             
@@ -635,15 +657,15 @@
          bridge = new JMSBridgeImpl(cff0, cff1, sourceTopicFactory, targetQueueFactory,
                   null, null, null, null,
                   null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
-                  1, -1,
+                  batchSize, -1,
                   null, null, false);
          bridge.setTransactionManager(newTransactionManager());
 
          bridge.start();
             
-         sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false);
+         sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false, largeMessage);
          
-         checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);                    
+         checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, largeMessage);                    
       }
       finally
       {                        
@@ -653,9 +675,19 @@
          }
       }                  
    }
+
+   public void testDurableSubscriberLargeMessage() throws Exception
+   {
+      internalTestDurableSubscriber(true, 1);
+   }
    
-   public void testDurableSubscriber() throws Exception
+   public void testDurableSubscriberRegularMessage() throws Exception
    {
+      internalTestDurableSubscriber(false, 1);
+   }
+
+   public void internalTestDurableSubscriber(boolean largeMessage, int batchSize) throws Exception
+   {
       JMSBridgeImpl bridge = null;
             
       try
@@ -665,15 +697,15 @@
          bridge = new JMSBridgeImpl(cff0, cff1, sourceTopicFactory, targetQueueFactory,
                   null, null, null, null,
                   null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE,
-                  1, -1,
+                  batchSize, -1,
                   "subTest", "clientid123", false);
          bridge.setTransactionManager(newTransactionManager());
 
          bridge.start();
             
-         sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, true);
+         sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, true, largeMessage);
          
-         checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);              
+         checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, largeMessage);              
       }
       finally
       {                      
@@ -1162,7 +1194,7 @@
          
          t.start();
          
-         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, false);
                                               
          t.join();
          
@@ -1236,7 +1268,7 @@
          
          t.start();
          
-         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, false);
                                               
          t.join();
          
@@ -1311,7 +1343,7 @@
          
          t.start();
          
-         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
+         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES, false);
                          
          t.join();
          
@@ -1368,7 +1400,7 @@
             
          //Send half the messges
 
-         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent);
+         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent, false);
                          
          //Verify none are received
          
@@ -1376,27 +1408,27 @@
          
          //Send the other half
          
-         this.sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent);
+         this.sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES / 2, persistent, false);
          
          //This should now be receivable
          
-         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, false);
          
          //Send another batch with one more than batch size
          
-         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES + 1, persistent);
+         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES + 1, persistent, false);
                   
          //Make sure only batch size are received
          
-         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
+         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, false);
          
          //Final batch
          
-         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES - 1, persistent);
+         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES - 1, persistent, false);
          
-         this.checkAllMessageReceivedInOrder(cf1, targetQueue, NUM_MESSAGES, 1);
+         this.checkAllMessageReceivedInOrder(cf1, targetQueue, NUM_MESSAGES, 1, false );
          
-         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES - 1);
+         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES - 1, false);
       }
       finally
       {      
@@ -1425,18 +1457,18 @@
 
          bridge.start();
             
-         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent);
+         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES / 2, persistent, false);
          
          this.checkEmpty(targetQueue, 1);                
          
          //Send the other half
          
-         this.sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES /2, persistent);
+         this.sendMessages(cf0, sourceQueue, NUM_MESSAGES / 2, NUM_MESSAGES /2, persistent, false);
          
          
          //This should now be receivable
          
-         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
+         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES, false);
          
          this.checkEmpty(localTargetQueue, 0);
          
@@ -1444,19 +1476,19 @@
          
          //Send another batch with one more than batch size
          
-         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES + 1, persistent);
+         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES + 1, persistent, false);
          
          //Make sure only batch size are received
          
-         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
+         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES, false);
          
          //Final batch
          
-         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES - 1, persistent);
+         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES - 1, persistent, false);
          
-         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, NUM_MESSAGES, 1);
+         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, NUM_MESSAGES, 1, false);
          
-         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES - 1);
+         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES - 1, false);
       }
       finally
       {               
@@ -1490,7 +1522,7 @@
          
          //Send some message
 
-         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES, persistent);                 
+         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES, persistent, false);                 
          
          //Verify none are received
          
@@ -1498,7 +1530,7 @@
          
          //Messages should now be receivable
          
-         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);         
+         this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES, false);         
       }
       finally
       {      
@@ -1534,7 +1566,7 @@
 
          //Send some message
 
-         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES, persistent);                 
+         this.sendMessages(cf0, sourceQueue, 0, NUM_MESSAGES, persistent, false);                 
          
          //Verify none are received
          
@@ -1542,7 +1574,7 @@
          
          //Messages should now be receivable
          
-         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);
+         this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES, false);
       }
       finally
       {              
@@ -1587,4 +1619,6 @@
       }
       
    } 
+   
+   
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/stress/chunk/MessageChunkStressTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/stress/chunk/MessageChunkStressTest.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/stress/chunk/MessageChunkStressTest.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -46,9 +46,9 @@
 
    // Public --------------------------------------------------------
       
-   public void testMessageChunkFilePersistence1M() throws Exception
+   public void testMessageChunkFilePersistenceOneHugeMessage() throws Exception
    {
-      testChunks(false, true, false, false, true, false, 100, 1024 * 1024, 50000, 0);
+      testChunks(false, false, true, true, false, false, false, false, 1, 4l * 1024 * 1024l * 1024l + 1024l, 120000, 0, 10 * 1024 * 1024, 1024 * 1024);
    }
 
    // Package protected ---------------------------------------------

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -39,7 +39,7 @@
 import org.jboss.messaging.core.client.MessageHandler;
 import org.jboss.messaging.core.client.impl.ClientConsumerInternal;
 import org.jboss.messaging.core.client.impl.ClientMessageInternal;
-import org.jboss.messaging.core.client.impl.LargeMessageBuffer;
+import org.jboss.messaging.core.client.impl.LargeMessageBufferImpl;
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveMessage;
@@ -69,7 +69,7 @@
    // Test Simple getBytes
    public void testGetBytes() throws Exception
    {
-      LargeMessageBuffer buffer = create15BytesSample();
+      LargeMessageBufferImpl buffer = create15BytesSample();
 
       for (int i = 1; i <= 15; i++)
       {
@@ -96,7 +96,7 @@
    // Test for void getBytes(final int index, final byte[] dst)
    public void testGetBytesIByteArray() throws Exception
    {
-      LargeMessageBuffer buffer = create15BytesSample();
+      LargeMessageBufferImpl buffer = create15BytesSample();
 
       byte[] bytes = new byte[15];
       buffer.getBytes(0, bytes);
@@ -119,7 +119,7 @@
    // testing void getBytes(int index, ChannelBuffer dst, int dstIndex, int length)
    public void testGetBytesILChannelBufferII() throws Exception
    {
-      LargeMessageBuffer buffer = create15BytesSample();
+      LargeMessageBufferImpl buffer = create15BytesSample();
 
       ChannelBuffer dstBuffer = ChannelBuffers.buffer(20);
 
@@ -136,7 +136,7 @@
    // testing void getBytes(int index, ChannelBuffer dst, int dstIndex, int length)
    public void testReadIntegers() throws Exception
    {
-      LargeMessageBuffer buffer = createBufferWithIntegers(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+      LargeMessageBufferImpl buffer = createBufferWithIntegers(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
 
       for (int i = 1; i <= 15; i++)
       {
@@ -156,7 +156,7 @@
    // testing void getBytes(int index, ChannelBuffer dst, int dstIndex, int length)
    public void testReadLongs() throws Exception
    {
-      LargeMessageBuffer buffer = createBufferWithLongs(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+      LargeMessageBufferImpl buffer = createBufferWithLongs(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
 
       for (int i = 1; i <= 15; i++)
       {
@@ -187,7 +187,7 @@
       dynamic.writeDouble(d1);
       dynamic.writeFloat(f1);
 
-      LargeMessageBuffer readBuffer = splitBuffer(3, dynamic.array());
+      LargeMessageBufferImpl readBuffer = splitBuffer(3, dynamic.array());
 
       assertEquals(str1, readBuffer.readUTF());
       assertEquals(str2, readBuffer.readString());
@@ -198,7 +198,7 @@
    public void testReadPartialData() throws Exception
    {
 
-      final LargeMessageBuffer buffer = new LargeMessageBuffer(new FakeConsumerInternal(), 10, 10);
+      final LargeMessageBufferImpl buffer = new LargeMessageBufferImpl(new FakeConsumerInternal(), 10, 10);
 
       buffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[] { 0, 1, 2, 3, 4 }, true, true));
 
@@ -249,7 +249,7 @@
 
    public void testInterruptData() throws Exception
    {
-      LargeMessageBuffer readBuffer = splitBuffer(3, new byte[] { 0, 1, 2, 3, 4 });
+      LargeMessageBufferImpl readBuffer = splitBuffer(3, new byte[] { 0, 1, 2, 3, 4 });
 
       byte bytes[] = new byte[30];
       readBuffer.readBytes(bytes, 0, 5);
@@ -262,7 +262,7 @@
 
    public void testStreamData() throws Exception
    {
-      final LargeMessageBuffer outBuffer = new LargeMessageBuffer(new FakeConsumerInternal(), 1024 * 11 + 123, 1);
+      final LargeMessageBufferImpl outBuffer = new LargeMessageBufferImpl(new FakeConsumerInternal(), 1024 * 11 + 123, 1);
 
       final PipedOutputStream output = new PipedOutputStream();
       final PipedInputStream input = new PipedInputStream(output);
@@ -373,11 +373,25 @@
       assertEquals(0, errors.get());
 
    }
+   
+   public void testStreamDataWaitCompletionOnCompleteBuffer() throws Exception
+   {
+      final LargeMessageBufferImpl outBuffer = create15BytesSample();
+      
+      outBuffer.saveBuffer(new OutputStream()
+      {
+         @Override
+         public void write(int b) throws IOException
+         {
+            // nohting to be done
+         }
+      });
+   }
 
    public void testErrorOnSetStreaming() throws Exception
    {
       long start = System.currentTimeMillis();
-      final LargeMessageBuffer outBuffer = new LargeMessageBuffer(new FakeConsumerInternal(), 5, 30);
+      final LargeMessageBufferImpl outBuffer = new LargeMessageBufferImpl(new FakeConsumerInternal(), 5, 30);
 
       outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[] { 0, 1, 2, 3, 4 }, true, false));
 
@@ -415,12 +429,12 @@
    /**
     * @return
     */
-   private LargeMessageBuffer create15BytesSample() throws Exception
+   private LargeMessageBufferImpl create15BytesSample() throws Exception
    {
       return splitBuffer(5, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
    }
 
-   private LargeMessageBuffer createBufferWithIntegers(int splitFactor, int... values) throws Exception
+   private LargeMessageBufferImpl createBufferWithIntegers(int splitFactor, int... values) throws Exception
    {
       ByteArrayOutputStream byteOut = new ByteArrayOutputStream(values.length * 4);
       DataOutputStream dataOut = new DataOutputStream(byteOut);
@@ -433,7 +447,7 @@
       return splitBuffer(splitFactor, byteOut.toByteArray());
    }
 
-   private LargeMessageBuffer createBufferWithLongs(int splitFactor, long... values) throws Exception
+   private LargeMessageBufferImpl createBufferWithLongs(int splitFactor, long... values) throws Exception
    {
       ByteArrayOutputStream byteOut = new ByteArrayOutputStream(values.length * 8);
       DataOutputStream dataOut = new DataOutputStream(byteOut);
@@ -446,9 +460,9 @@
       return splitBuffer(splitFactor, byteOut.toByteArray());
    }
 
-   private LargeMessageBuffer splitBuffer(int splitFactor, byte[] bytes) throws Exception
+   private LargeMessageBufferImpl splitBuffer(int splitFactor, byte[] bytes) throws Exception
    {
-      LargeMessageBuffer outBuffer = new LargeMessageBuffer(new FakeConsumerInternal(), bytes.length, 5);
+      LargeMessageBufferImpl outBuffer = new LargeMessageBufferImpl(new FakeConsumerInternal(), bytes.length, 5);
 
       ByteArrayInputStream input = new ByteArrayInputStream(bytes);
 

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -740,6 +740,14 @@
       {
       }
 
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.message.Message#getLargeBodySize()
+       */
+      public long getLargeBodySize()
+      {
+         return 0;
+      }
+
    }
 
    class FakeFilter implements Filter

Modified: trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java	2009-04-16 16:14:36 UTC (rev 6457)
+++ trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java	2009-04-16 20:25:23 UTC (rev 6458)
@@ -47,6 +47,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
@@ -363,6 +364,51 @@
       }
    }
    
+   
+   public static byte getSamplebyte(final long position)
+   {
+      return (byte)('a' + (position) % ('z' - 'a' + 1));
+   }
+
+   // Creates a Fake LargeStream without using a real file
+   public static InputStream createFakeLargeStream(final long size) throws Exception
+   {
+      return new InputStream()
+      {
+         private long count;
+
+         private boolean closed = false;
+
+         @Override
+         public void close() throws IOException
+         {
+            super.close();
+            System.out.println("Sent " + count + " bytes over fakeOutputStream, while size = " + size);
+            closed = true;
+         }
+
+         @Override
+         public int read() throws IOException
+         {
+            if (closed)
+            {
+               throw new IOException("Stream was closed");
+            }
+            if (count++ < size)
+            {
+               return getSamplebyte(count - 1);
+            }
+            else
+            {
+               return -1;
+            }
+         }
+      };
+
+   }
+
+   
+   
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------




More information about the jboss-cvs-commits mailing list