[jboss-cvs] JBoss Messaging SVN: r6382 - in branches/Branch_Temp_Clebert_LargeMessage: src/main/org/jboss/messaging/core/client/impl and 19 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 9 11:36:58 EDT 2009


Author: clebert.suconic at jboss.com
Date: 2009-04-09 11:36:58 -0400 (Thu, 09 Apr 2009)
New Revision: 6382

Added:
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/client/
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/client/impl/
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java
Removed:
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientFileMessage.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageImpl.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageInternal.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientFileMessageTest.java
Modified:
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientMessage.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientSession.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/exception/MessagingException.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/message/Message.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendContinuationMessage.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendLargeMessage.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java
   branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/joram-tests/src/org/jboss/test/jms/AbstractAdmin.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/String64KLimitTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkCleanupTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCreateConsumerTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/soak/chunk/MessageChunkSoakTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeConsumer.java
   branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java
Log:
Uploading a backup to a branch

Deleted: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientFileMessage.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientFileMessage.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientFileMessage.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -1,41 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.core.client;
-
-import java.io.File;
-
-/**
- * A ClientFileMessage
- *
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- * 
- * Created Oct 14, 2008 3:21:15 PM
- *
- *
- */
-public interface ClientFileMessage extends ClientMessage
-{
-   File getFile();
-
-   void setFile(File file);
-}

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientMessage.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientMessage.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientMessage.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -22,6 +22,8 @@
 
 package org.jboss.messaging.core.client;
 
+import java.io.OutputStream;
+
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.message.Message;
 
@@ -30,6 +32,7 @@
  * A ClientMessage
  * 
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  *
  */
 public interface ClientMessage extends Message
@@ -37,6 +40,21 @@
    int getDeliveryCount();
    
    void setDeliveryCount(int deliveryCount);
+   
+   /** Sets the outputStream of large messages. It doesn't block on waiting the large-message to complete 
+    * @throws MessagingException */
+   void setOutputStream(OutputStream out) throws MessagingException;
+   
+   /** Save the content of the message to the outputStream. It blocks until the entire data was received */
+   void saveToOutputStream(OutputStream out) throws MessagingException;
 
+   /**
+    * Wait the outputStream completion of the message.
+    * @param timeMilliseconds - 0 means wait forever
+    * @return true if it reached the end
+    * @throws MessagingException
+    */
+   boolean waitOutputStreamCompletion(long timeMilliseconds) throws MessagingException;
+
    void acknowledge() throws MessagingException;   
 }

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientSession.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientSession.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/ClientSession.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -22,8 +22,6 @@
 
 package org.jboss.messaging.core.client;
 
-import java.io.File;
-
 import javax.transaction.xa.XAResource;
 
 import org.jboss.messaging.core.exception.MessagingException;
@@ -90,35 +88,6 @@
 
    ClientConsumer createConsumer(String queueName, String filterString, int windowSize, int maxRate, boolean browseOnly) throws MessagingException;
 
-   ClientConsumer createFileConsumer(File directory, SimpleString queueName) throws MessagingException;
-
-   ClientConsumer createFileConsumer(File directory, SimpleString queueName, SimpleString filterString) throws MessagingException;
-
-   ClientConsumer createFileConsumer(File directory,
-                                     SimpleString queueName,
-                                     SimpleString filterString,
-                                     boolean browseOnly) throws MessagingException;
-
-   ClientConsumer createFileConsumer(File directory,
-                                     SimpleString queueName,
-                                     SimpleString filterString,
-                                     int windowSize,
-                                     int maxRate,
-                                     boolean browseOnly) throws MessagingException;
-
-   ClientConsumer createFileConsumer(File directory, String queueName) throws MessagingException;
-
-   ClientConsumer createFileConsumer(File directory, String queueName, String filterString) throws MessagingException;
-
-   ClientConsumer createFileConsumer(File directory, String queueName, String filterString, boolean browseOnly) throws MessagingException;
-
-   ClientConsumer createFileConsumer(File directory,
-                                     String queueName,
-                                     String filterString,
-                                     int windowSize,
-                                     int maxRate,
-                                     boolean browseOnly) throws MessagingException;
-
    /**
     * Create a producer with no default address.
     * Address must be specified every time a message is sent
@@ -183,8 +152,6 @@
 
    ClientMessage createClientMessage(final boolean durable);
 
-   ClientFileMessage createFileMessage(final boolean durable);
-
    void start() throws MessagingException;
 
    void stop() throws MessagingException;

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -13,13 +13,11 @@
 package org.jboss.messaging.core.client.impl;
 
 import java.io.File;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.Executor;
 
 import org.jboss.messaging.core.buffers.ChannelBuffers;
-import org.jboss.messaging.core.client.ClientFileMessage;
 import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.client.MessageHandler;
 import org.jboss.messaging.core.exception.MessagingException;
@@ -31,7 +29,6 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionConsumerFlowCreditMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveMessage;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.utils.Future;
 import org.jboss.messaging.utils.TokenBucketLimiter;
 
@@ -79,6 +76,11 @@
 
    private ClientMessageInternal currentChunkMessage;
    
+   private LargeMessageBuffer 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;
+
    private final TokenBucketLimiter rateLimiter;
 
    private volatile Thread receiverThread;
@@ -118,7 +120,7 @@
       this.channel = channel;
 
       this.session = session;
-      
+
       this.rateLimiter = rateLimiter;
 
       sessionExecutor = executor;
@@ -137,12 +139,18 @@
    {
       checkClosed();
       
+      if (largeMessageReceived != null)
+      {
+         // Check if there are pending packets to be received
+         largeMessageReceived.discardLargeBody();
+         largeMessageReceived = null;
+      }
+
       if (rateLimiter != null)
       {
          rateLimiter.limit();
       }
 
-
       if (handler != null)
       {
          throw new MessagingException(MessagingException.ILLEGAL_STATE,
@@ -171,11 +179,10 @@
          while (true)
          {
             ClientMessageInternal m = null;
-            
+
             synchronized (this)
             {
-               while ((stopped || (m = buffer.removeFirst()) == null) &&
-                      !closed && toWait > 0)
+               while ((stopped || (m = buffer.removeFirst()) == null) && !closed && toWait > 0)
 
                {
                   if (start == -1)
@@ -190,7 +197,7 @@
                   catch (InterruptedException e)
                   {
                   }
-                  
+
                   if (m != null || closed)
                   {
                      break;
@@ -212,6 +219,8 @@
 
                if (expired)
                {
+                  m.discardLargeBody();
+                  
                   session.expire(id, m.getMessageID());
 
                   if (toWait > 0)
@@ -224,6 +233,11 @@
                   }
                }
 
+               if (m.isLargeMessage())
+               {
+                  this.largeMessageReceived = m;
+               }
+               
                return m;
             }
             else
@@ -268,7 +282,7 @@
       }
 
       boolean noPreviousHandler = handler == null;
-      
+
       if (handler != theHandler && clientWindowSize == 0)
       {
          sendCredits(1);
@@ -323,14 +337,14 @@
    public void stop() throws MessagingException
    {
       waitForOnMessageToComplete();
-      
+
       synchronized (this)
       {
          if (stopped)
          {
             return;
          }
-         
+
          stopped = true;
       }
    }
@@ -365,18 +379,14 @@
 
       ClientMessageInternal messageToHandle = message;
 
-      if (isFileConsumer())
-      {
-         messageToHandle = cloneAsFileMessage(message);
-      }
-
       messageToHandle.onReceipt(this);
 
+      // Add it to the buffer
+      buffer.addLast(messageToHandle, messageToHandle.getPriority());
+
       if (handler != null)
       {
          // Execute using executor
-
-         buffer.addLast(messageToHandle, messageToHandle.getPriority());
          if (!stopped)
          {
             queueExecutor();
@@ -384,9 +394,6 @@
       }
       else
       {
-         // Add it to the buffer
-         buffer.addLast(messageToHandle, messageToHandle.getPriority());
-
          notify();
       }
    }
@@ -398,11 +405,25 @@
          // This is ok - we just ignore the message
          return;
       }
-
+      
+      System.out.println("Received largeMessage, packetSize = " + packet.getPacketSize());
+      
       // Flow control for the first packet, we will have others
       flowControl(packet.getPacketSize(), true);
 
-      currentChunkMessage = createFileMessage(packet.getLargeMessageHeader());
+      currentChunkMessage = new ClientMessageImpl();
+      
+      currentChunkMessage.decodeProperties(ChannelBuffers.wrappedBuffer(packet.getLargeMessageHeader()));
+      
+      currentChunkMessage.setLargeMessage(true);
+
+      currentLargeMessageBuffer = new LargeMessageBuffer(this, packet.getLargeMessageSize(), 60);
+
+      currentChunkMessage.setBody(currentLargeMessageBuffer);
+
+      currentChunkMessage.setFlowControlSize(0);
+
+      handleMessage(currentChunkMessage);
    }
 
    public synchronized void handleLargeMessageContinuation(final SessionReceiveContinuationMessage chunk) throws Exception
@@ -411,45 +432,8 @@
       {
          return;
       }
-
-      if (chunk.isContinues())
-      {
-         flowControl(chunk.getPacketSize(), true);
-      }
-
-      if (isFileConsumer())
-      {
-         ClientFileMessageInternal fileMessage = (ClientFileMessageInternal)currentChunkMessage;
-         addBytesBody(fileMessage, chunk.getBody());
-      }
-      else
-      {
-         if (currentChunkMessage.getBody() == null)
-         {
-            currentChunkMessage.setBody(ChannelBuffers.dynamicBuffer(chunk.getBody()));
-         }
-         else
-         {
-            currentChunkMessage.getBody().writeBytes(chunk.getBody());
-         }
-      }
-
-      if (!chunk.isContinues())
-      {
-         // Close the file that was being generated
-         if (isFileConsumer())
-         {
-            ((ClientFileMessageInternal)currentChunkMessage).closeChannel();
-         }
-
-         currentChunkMessage.setFlowControlSize(chunk.getPacketSize());
-
-         ClientMessageInternal msgToSend = currentChunkMessage;
-
-         currentChunkMessage = null;
-
-         handleMessage(msgToSend);
-      }
+      
+      currentLargeMessageBuffer.addPacket(chunk);
    }
 
    public void clear()
@@ -499,39 +483,18 @@
       }
    }
 
-   // Public7
-   // ---------------------------------------------------------------------------------------
-
-   // Package protected
-   // ---------------------------------------------------------------------------------------
-
-   // Protected
-   // ---------------------------------------------------------------------------------------
-
-   // Private
-   // ---------------------------------------------------------------------------------------
-
-   private void requeueExecutors()
+   public void flowControl(final int messageBytes, final boolean isLargeMessage) throws MessagingException
    {
-      for (int i = 0; i < buffer.size(); i++)
-      {
-         queueExecutor();
-      }
-   }
-
-   private void queueExecutor()
-   {
-      sessionExecutor.execute(runner);
-   }
-
-   private void flowControl(final int messageBytes, final boolean isLargeMessage) throws MessagingException
-   {
       if (clientWindowSize >= 0)
       {
          creditsToSend += messageBytes;
+         
+         System.out.println("Received " + messageBytes + "  credits, credits to Send = " + creditsToSend + "  clientwindowSize = " + clientWindowSize);
 
          if (creditsToSend >= clientWindowSize)
          {
+            
+            System.out.println("Sending credits back");
 
             if (isLargeMessage)
             {
@@ -540,21 +503,23 @@
                final int credits = creditsToSend;
 
                creditsToSend = 0;
-               sessionExecutor.execute(new Runnable()
-               {
-                  public void run()
-                  {
-                     sendCredits(credits);
-                  }
 
+               sendCredits(credits);
 
-               });
+               // sessionExecutor.execute(new Runnable()
+               // {
+               // public void run()
+               // {
+               // sendCredits(credits);
+               // }
+               // });
             }
             else
             {
                if (clientWindowSize == 0)
                {
-                  // sending the credits - 1 initially send to fire the slow consumer, or the slow consumer would be always buffering one after received the first message
+                  // sending the credits - 1 initially send to fire the slow consumer, or the slow consumer would be
+                  // always buffering one after received the first message
                   sendCredits(creditsToSend - 1);
                }
                else
@@ -567,6 +532,31 @@
       }
    }
 
+   // Public
+   // ---------------------------------------------------------------------------------------
+
+   // Package protected
+   // ---------------------------------------------------------------------------------------
+
+   // Protected
+   // ---------------------------------------------------------------------------------------
+
+   // Private
+   // ---------------------------------------------------------------------------------------
+
+   private void requeueExecutors()
+   {
+      for (int i = 0; i < buffer.size(); i++)
+      {
+         queueExecutor();
+      }
+   }
+
+   private void queueExecutor()
+   {
+      sessionExecutor.execute(runner);
+   }
+
    /**
     * @param credits
     */
@@ -625,7 +615,7 @@
       MessageHandler theHandler = handler;
 
       if (theHandler != null)
-      {         
+      {
          if (rateLimiter != null)
          {
             rateLimiter.limit();
@@ -646,13 +636,19 @@
             {
                onMessageThread = Thread.currentThread();
 
+               System.out.println("Calling handler " + handler);
                theHandler.onMessage(message);
+               
+               if (message.isLargeMessage())
+               {
+                  message.discardLargeBody();
+               }
             }
             else
             {
                session.expire(id, message.getMessageID());
             }
-            
+
             // If slow consumer, we need to send 1 credit to make sure we get another message
             if (clientWindowSize == 0)
             {
@@ -669,7 +665,10 @@
    private void flowControlBeforeConsumption(final ClientMessageInternal message) throws MessagingException
    {
       // Chunk messages will execute the flow control while receiving the chunks
-      flowControl(message.getFlowControlSize(), false);
+      if (message.getFlowControlSize() != 0)
+      {
+         flowControl(message.getFlowControlSize(), false);
+      }
    }
 
    private void doCleanUp(final boolean sendCloseMessage) throws MessagingException
@@ -721,16 +720,6 @@
 
    private void clearBuffer()
    {
-      if (isFileConsumer())
-      {
-         for (ClientMessage message : buffer)
-         {
-            if (message instanceof ClientFileMessage)
-            {
-               ((ClientFileMessage)message).getFile().delete();
-            }
-         }
-      }
       buffer.clear();
    }
 
@@ -743,89 +732,6 @@
       session.acknowledge(id, message.getMessageID());
    }
 
-   private ClientMessageInternal cloneAsFileMessage(final ClientMessageInternal message) throws Exception
-   {
-      if (message instanceof ClientFileMessageImpl)
-      {
-         // nothing to be done
-         return message;
-      }
-      else
-      {
-         int propertiesSize = message.getPropertiesEncodeSize();
-
-         MessagingBuffer bufferProperties = session.createBuffer(propertiesSize);
-
-         // FIXME: Find a better way to clone this ClientMessageImpl as ClientFileMessageImpl without using the
-         // MessagingBuffer.
-         // There is no direct access into the Properties, and I couldn't add a direct cast to this method without loose
-         // abstraction
-         message.encodeProperties(bufferProperties);
-
-         bufferProperties.resetReaderIndex();
-
-         ClientFileMessageImpl cloneMessage = new ClientFileMessageImpl();
-
-         cloneMessage.decodeProperties(bufferProperties);
-
-         cloneMessage.setDeliveryCount(message.getDeliveryCount());
-
-         cloneMessage.setLargeMessage(message.isLargeMessage());
-
-         cloneMessage.setFile(new File(directory, cloneMessage.getMessageID() + "-" +
-                                                  session.getName() +
-                                                  "-" +
-                                                  getID() +
-                                                  ".jbm"));
-
-         cloneMessage.setFlowControlSize(message.getFlowControlSize());
-
-         addBytesBody(cloneMessage, message.getBody().array());
-
-         cloneMessage.closeChannel();
-
-         return cloneMessage;
-      }
-   }
-
-   private ClientMessageInternal createFileMessage(final byte[] header) throws Exception
-   {
-
-      MessagingBuffer headerBuffer = ChannelBuffers.wrappedBuffer(header);
-
-      if (isFileConsumer())
-      {
-         if (!directory.exists())
-         {
-            boolean ok = directory.mkdirs();
-
-            if (!ok)
-            {
-               throw new IOException("Failed to create directory " + directory.getCanonicalPath());
-            }
-         }
-
-         ClientFileMessageImpl message = new ClientFileMessageImpl();
-         message.decodeProperties(headerBuffer);
-         message.setFile(new File(directory, message.getMessageID() + "-" + session.getName() + "-" + getID() + ".jbm"));
-         message.setLargeMessage(true);
-         return message;
-      }
-      else
-      {
-         ClientMessageImpl message = new ClientMessageImpl();
-         message.decodeProperties(headerBuffer);
-         message.setLargeMessage(true);
-         return message;
-      }
-   }
-
-   private void addBytesBody(final ClientFileMessageInternal fileMessage, final byte[] body) throws Exception
-   {
-      FileChannel channel = fileMessage.getChannel();
-      channel.write(ByteBuffer.wrap(body));
-   }
-
    // Inner classes
    // --------------------------------------------------------------------------------
 

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -44,6 +44,8 @@
    void handleLargeMessage(SessionReceiveMessage largeMessageHeader) throws Exception;
    
    void handleLargeMessageContinuation(SessionReceiveContinuationMessage continuation) throws Exception;
+   
+   void flowControl(final int messageBytes, final boolean isLargeMessage) throws MessagingException;
 
    void clear();
 

Deleted: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageImpl.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageImpl.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageImpl.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -1,246 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.core.client.impl;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
-
-/**
- * A ClientFileMessageImpl
- *
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- * 
- * Created Oct 13, 2008 4:33:56 PM
- *
- *
- */
-public class ClientFileMessageImpl extends ClientMessageImpl implements ClientFileMessageInternal
-{
-   private File file;
-
-   private FileChannel currentChannel;
-
-   public ClientFileMessageImpl()
-   {
-   }
-
-   public ClientFileMessageImpl(final boolean durable)
-   {
-      super(durable, null);
-   }
-
-   /**
-    * @param type
-    * @param durable
-    * @param expiration
-    * @param timestamp
-    * @param priority
-    * @param body
-    */
-   public ClientFileMessageImpl(final byte type,
-                                final boolean durable,
-                                final long expiration,
-                                final long timestamp,
-                                final byte priority,
-                                final MessagingBuffer body)
-   {
-      super(type, durable, expiration, timestamp, priority, body);
-   }
-
-   /**
-    * @param type
-    * @param durable
-    * @param body
-    */
-   public ClientFileMessageImpl(final byte type, final boolean durable, final MessagingBuffer body)
-   {
-      super(type, durable, body);
-   }
-
-   /**
-    * @param deliveryCount
-    */
-   public ClientFileMessageImpl(final int deliveryCount)
-   {
-      super(deliveryCount);
-   }
-
-   /**
-    * @return the file
-    */
-   public File getFile()
-   {
-      return file;
-   }
-
-   /**
-    * @param file the file to set
-    */
-   public void setFile(final File file)
-   {
-      this.file = file;
-   }
-
-   @Override
-   public MessagingBuffer getBody()
-   {
-      throw new UnsupportedOperationException("getBody is not supported on FileMessages.");
-   }
-
-   /**
-    * If a ClientFileMessage is Smaller then the MinLargeMessage configured on the SessionFactory (or JMSConnectionFactory), it will still be sent as any other message,
-    * and for that the file body (which should be small) will be read from the file an populated on the output buffer
-    *  
-    *  */
-   public void encodeBody(MessagingBuffer buffer)
-   {
-      FileChannel channel = null;
-      try
-      {
-         // We open a new channel on getBody.
-         // for a better performance, users should be using the channels when using file
-         channel = newChannel();
-
-         ByteBuffer fileBuffer = ByteBuffer.allocate((int)channel.size());
-
-         channel.position(0);
-         channel.read(fileBuffer);
-
-         buffer.writeBytes(fileBuffer.array(), 0, fileBuffer.limit());
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-      finally
-      {
-         try
-         {
-            channel.close();
-         }
-         catch (Throwable ignored)
-         {
-
-         }
-      }
-   }
-
-   /** 
-    * Read the file content from start to size.
-    */
-   @Override
-   public synchronized void encodeBody(final MessagingBuffer buffer, final long start, final int size)
-   {
-      try
-      {
-         FileChannel channel = getChannel();
-
-         ByteBuffer bufferRead = ByteBuffer.allocate(size);
-
-         channel.position(start);
-         channel.read(bufferRead);
-
-         buffer.writeBytes(bufferRead.array());
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e.getMessage(), e);
-      }
-   }
-
-   @Override
-   public void setBody(final MessagingBuffer body)
-   {
-      throw new RuntimeException("Not supported");
-   }
-
-   public synchronized FileChannel getChannel() throws MessagingException
-   {
-      if (currentChannel == null)
-      {
-         currentChannel = newChannel();
-      }
-
-      return currentChannel;
-   }
-
-   public synchronized void closeChannel() throws MessagingException
-   {
-      if (currentChannel != null)
-      {
-         try
-         {
-            currentChannel.close();
-         }
-         catch (IOException e)
-         {
-            throw new MessagingException(MessagingException.INTERNAL_ERROR, e.getMessage(), e);
-         }
-         currentChannel = null;
-      }
-
-   }
-
-   @Override
-   public synchronized int getBodySize()
-   {
-      return (int)file.length();
-   }
-   
-   public boolean isFileMessage()
-   {
-      return true;
-   }
-
-
-   /**
-    * @return
-    * @throws FileNotFoundException
-    * @throws IOException
-    */
-   private FileChannel newChannel() throws MessagingException
-   {
-      try
-      {
-         RandomAccessFile randomFile = new RandomAccessFile(getFile(), "rw");
-         
-         randomFile.seek(0);
-
-         FileChannel channel = randomFile.getChannel();
-         
-         return channel;
-      }
-      catch (IOException e)
-      {
-         throw new MessagingException(MessagingException.INTERNAL_ERROR, e.getMessage(), e);
-      }
-   }
-
-}

Deleted: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageInternal.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageInternal.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientFileMessageInternal.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-
-package org.jboss.messaging.core.client.impl;
-
-import java.nio.channels.FileChannel;
-
-import org.jboss.messaging.core.client.ClientFileMessage;
-import org.jboss.messaging.core.exception.MessagingException;
-
-/**
- * A ClientFileMessageInternal
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * 
- * Created 10 Dec 2008 19:02:06
- *
- *
- */
-public interface ClientFileMessageInternal extends ClientFileMessage
-{
-   void setLargeMessage(boolean largeMessage);
-
-   FileChannel getChannel() throws MessagingException;
-   
-   void closeChannel() throws MessagingException;   
-}

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientMessageImpl.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -22,6 +22,9 @@
 
 package org.jboss.messaging.core.client.impl;
 
+import java.io.IOException;
+import java.io.OutputStream;
+
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
@@ -138,6 +141,7 @@
    {
       this.largeMessage = largeMessage;
    }
+   
 
    /* (non-Javadoc)
     * @see org.jboss.messaging.core.client.impl.ClientMessageInternal#isFileMessage()
@@ -147,4 +151,70 @@
       return false;
    }
 
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.client.impl.ClientMessageInternal#discardLargeBody()
+    */
+   public void discardLargeBody()
+   {
+      if (largeMessage)
+      {
+         ((LargeMessageBuffer)getBody()).discardUnusedPackets();
+      }
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.client.ClientMessage#saveToOutputStream(java.io.OutputStream)
+    */
+   public void saveToOutputStream(OutputStream out) throws MessagingException
+   {
+      if (largeMessage)
+      {
+         ((LargeMessageBuffer)this.getBody()).saveBuffer(out);
+      }
+      else
+      {
+         try
+         {
+            out.write(this.getBody().array());
+         }
+         catch (IOException e)
+         {
+            throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY, "Error saving the message body", e);
+         }
+      }
+      
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.client.ClientMessage#setOutputStream(java.io.OutputStream)
+    */
+   public void setOutputStream(OutputStream out) throws MessagingException
+   {
+      if (largeMessage)
+      {
+         ((LargeMessageBuffer)this.getBody()).setOutputStream(out);
+      }
+      else
+      {
+         saveToOutputStream(out);
+      }
+      
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.messaging.core.client.ClientMessage#waitOutputStreamCompletion()
+    */
+   public boolean waitOutputStreamCompletion(long timeMilliseconds) throws MessagingException
+   {
+      if (largeMessage)
+      {
+         return ((LargeMessageBuffer)this.getBody()).waitCompletion(timeMilliseconds);
+      }
+      else
+      {
+         return true;
+      }
+   }
+
+
 }

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientMessageInternal.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -45,5 +45,12 @@
 
    boolean isLargeMessage();
    
-   boolean isFileMessage();    
+   void setLargeMessage(boolean largeMessage);
+   
+   boolean isFileMessage();
+
+   /**
+    * Discard unused packets (used on large-message)
+    */
+   void discardLargeBody();    
 }

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -24,7 +24,11 @@
 
 import static org.jboss.messaging.utils.SimpleString.toSimpleString;
 
+import java.io.IOException;
+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;
@@ -221,7 +225,7 @@
 
       SessionSendMessage message = new SessionSendMessage(msg, sendBlocking);
 
-      if (msg.getEncodeSize() >= minLargeMessageSize)
+      if (msg.getBodyInputStream() != null ||  msg.getEncodeSize() >= minLargeMessageSize)
       {
          sendMessageInChunks(sendBlocking, (ClientMessageInternal)msg);
       }
@@ -252,51 +256,88 @@
       MessagingBuffer headerBuffer = ChannelBuffers.buffer(headerSize); 
       msg.encodeProperties(headerBuffer);
 
-      final int bodySize = msg.getBodySize();
+      SessionSendLargeMessage initialChunk = new SessionSendLargeMessage(headerBuffer.array());
 
-      SessionSendLargeMessage initialChunk = new SessionSendLargeMessage(headerBuffer.array(), false);
-
       channel.send(initialChunk);
       
-      for (int pos = 0; pos < bodySize;)
+      
+      if (msg.getBodyInputStream() != null)
       {
-         final boolean lastChunk;
-                  
-         final int chunkLength = Math.min(bodySize - pos, minLargeMessageSize); 
          
-         final MessagingBuffer bodyBuffer = ChannelBuffers.buffer(chunkLength); 
+         boolean lastChunk = false;
+         InputStream input = msg.getBodyInputStream();
+         while (!lastChunk)
+         {
+            byte[] bytesRead = new byte[minLargeMessageSize];
+            int numberOfBytesRead;
+            
+            try
+            {
+               numberOfBytesRead = input.read(bytesRead);
+            }
+            catch (IOException e)
+            {
+               throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY, "Error reading the LargeMessageBody", e);
+            }
+            
+            if (numberOfBytesRead < 0)
+            {
+               numberOfBytesRead = 0;
+               lastChunk = true;
+            }
+            
+            final SessionSendContinuationMessage chunk = new SessionSendContinuationMessage(bytesRead, numberOfBytesRead, !lastChunk, lastChunk && sendBlocking);
 
-         msg.encodeBody(bodyBuffer, pos, chunkLength);
-
-         pos += chunkLength;
+            if (sendBlocking && lastChunk)
+            {
+               // When sending it blocking, only the last chunk will be blocking.
+               channel.sendBlocking(chunk);
+            }
+            else
+            {
+               channel.send(chunk);
+            }         
+         }
          
-         lastChunk = pos >= bodySize;
-
-         final SessionSendContinuationMessage chunk = new SessionSendContinuationMessage(bodyBuffer.array(), !lastChunk, lastChunk && sendBlocking);
-
-         if (sendBlocking && lastChunk)
+         try
          {
-            // When sending it blocking, only the last chunk will be blocking.
-            channel.sendBlocking(chunk);
+            input.close();
          }
-         else
+         catch (IOException e)
          {
-            channel.send(chunk);
-         }         
+            throw new MessagingException(MessagingException.LARGE_MESSAGE_ERROR_BODY, "Error closing stream from LargeMessageBody", e);
+         }
       }
-
-      // Note: This could be either a regular message, with a huge body,
-      //       or a ClientFileMessage.
-      if (msg.isFileMessage())
+      else
       {
-         try
+         final int bodySize = msg.getBodySize();
+   
+         for (int pos = 0; pos < bodySize;)
          {
-            ((ClientFileMessageInternal)msg).closeChannel();
+            final boolean lastChunk;
+                     
+            final int chunkLength = Math.min(bodySize - pos, minLargeMessageSize); 
+            
+            final MessagingBuffer bodyBuffer = ChannelBuffers.buffer(chunkLength); 
+   
+            msg.encodeBody(bodyBuffer, pos, chunkLength);
+   
+            pos += chunkLength;
+            
+            lastChunk = pos >= bodySize;
+   
+            final SessionSendContinuationMessage chunk = new SessionSendContinuationMessage(bodyBuffer.array(), chunkLength, !lastChunk, lastChunk && sendBlocking);
+   
+            if (sendBlocking && lastChunk)
+            {
+               // When sending it blocking, only the last chunk will be blocking.
+               channel.sendBlocking(chunk);
+            }
+            else
+            {
+               channel.send(chunk);
+            }         
          }
-         catch (Exception e)
-         {
-            log.warn(e.getMessage(), e);
-         }
       }
    }
 

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -38,7 +38,6 @@
 
 import org.jboss.messaging.core.buffers.ChannelBuffers;
 import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
 import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.client.SendAcknowledgementHandler;
@@ -87,7 +86,6 @@
 import org.jboss.messaging.utils.OrderedExecutorFactory;
 import org.jboss.messaging.utils.SimpleIDGenerator;
 import org.jboss.messaging.utils.SimpleString;
-import org.jboss.messaging.utils.TokenBucketLimiter;
 import org.jboss.messaging.utils.TokenBucketLimiterImpl;
 
 /*
@@ -370,77 +368,6 @@
       return createConsumer(toSimpleString(queueName), toSimpleString(filterString), windowSize, maxRate, browseOnly);
    }
 
-   public ClientConsumer createFileConsumer(final File directory, final SimpleString queueName) throws MessagingException
-   {
-      return createFileConsumer(directory, queueName, null, false);
-   }
-
-   public ClientConsumer createFileConsumer(final File directory, final String queueName) throws MessagingException
-   {
-      return createFileConsumer(directory, toSimpleString(queueName));
-   }
-
-   public ClientConsumer createFileConsumer(final File directory,
-                                            final SimpleString queueName,
-                                            final SimpleString filterString) throws MessagingException
-   {
-      return createFileConsumer(directory, queueName, filterString, consumerWindowSize, consumerMaxRate, false);
-   }
-
-   public ClientConsumer createFileConsumer(final File directory, final String queueName, final String filterString) throws MessagingException
-   {
-      return createFileConsumer(directory, toSimpleString(queueName), toSimpleString(filterString));
-   }
-
-   public ClientConsumer createFileConsumer(final File directory,
-                                            final SimpleString queueName,
-                                            final SimpleString filterString,
-                                            final boolean browseOnly) throws MessagingException
-   {
-      return createFileConsumer(directory, queueName, filterString, consumerWindowSize, consumerMaxRate, browseOnly);
-   }
-
-   public ClientConsumer createFileConsumer(final File directory,
-                                            final String queueName,
-                                            final String filterString,
-                                            final boolean browseOnly) throws MessagingException
-   {
-      return createFileConsumer(directory, toSimpleString(queueName), toSimpleString(filterString), browseOnly);
-   }
-
-   /*
-    * Note, we DO NOT currently support direct consumers (i.e. consumers we're delivery occurs on the remoting thread.
-    * Direct consumers have issues with blocking and failover.
-    * E.g. if direct then inside MessageHandler call a blocking method like rollback or acknowledge (blocking)
-    * This can block until failove completes, which disallows the thread to be used to deliver any responses to the client
-    * during that period, so failover won't occur.
-    * If we want direct consumers we need to rethink how they work
-   */
-   public ClientConsumer createFileConsumer(final File directory,
-                                            final SimpleString queueName,
-                                            final SimpleString filterString,
-                                            final int windowSize,
-                                            final int maxRate,
-                                            final boolean browseOnly) throws MessagingException
-   {
-      return internalCreateConsumer(queueName, filterString, windowSize, maxRate, browseOnly, directory);
-   }
-
-   public ClientConsumer createFileConsumer(final File directory,
-                                            final String queueName,
-                                            final String filterString,
-                                            final int windowSize,
-                                            final int maxRate,
-                                            final boolean browseOnly) throws MessagingException
-   {
-      return createFileConsumer(directory,
-                                toSimpleString(queueName),
-                                toSimpleString(filterString),
-                                windowSize,
-                                maxRate,
-                                browseOnly);
-   }
-
    public ClientProducer createProducer() throws MessagingException
    {
       return createProducer((SimpleString)null);
@@ -567,11 +494,6 @@
       return ChannelBuffers.dynamicBuffer(size);
    }
 
-   public ClientFileMessage createFileMessage(final boolean durable)
-   {
-      return new ClientFileMessageImpl(durable);
-   }
-
    public boolean isClosed()
    {
       return closed;
@@ -1296,7 +1218,7 @@
                                     final boolean temp) throws MessagingException
    {
       checkClosed();
-      
+
       if (durable && temp)
       {
          throw new MessagingException(MessagingException.INTERNAL_ERROR, "Queue can not be both durable and temporay");

Added: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java	                        (rev 0)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/client/impl/LargeMessageBuffer.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -0,0 +1,1028 @@
+/*
+ * 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.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 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)
+      {
+         checkForPacket(this.totalSize - 1);
+      }
+   }
+
+   
+   /**
+    * 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 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 * 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(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();
+         }
+         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 (index >= totalSize)
+      {
+         throw new IndexOutOfBoundsException();
+      }
+      if (index < packetPosition)
+      {
+         throw new IllegalAccessError("LargeMessage have read-only and one-way buffers");
+      }
+      while (index >= packetLastPosition)
+      {
+         popPacket();
+      }
+   }
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/exception/MessagingException.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/exception/MessagingException.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/exception/MessagingException.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -66,6 +66,8 @@
    public static final int INCOMPATIBLE_CLIENT_SERVER_VERSIONS = 108;
 
    public static final int SESSION_EXISTS = 109;
+   
+   public static final int LARGE_MESSAGE_ERROR_BODY = 110;
 
    
    // Native Error codes ----------------------------------------------

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/message/Message.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/message/Message.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/message/Message.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -22,6 +22,7 @@
 
 package org.jboss.messaging.core.message;
 
+import java.io.InputStream;
 import java.util.Set;
 
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
@@ -86,6 +87,13 @@
    // Used on Message chunk
    void encodeBody(MessagingBuffer buffer, long start, int size);
    
+   /** Used to set the MessageBody out of a File or any other Streaming you choose */
+   void setBodyInputStream(InputStream stream);
+   
+   /** Used to set the MessageBody out of a File or any other Streaming you choose */
+   InputStream getBodyInputStream();
+   
+   
    void encodeBody(MessagingBuffer buffer);
    
    void decodeBody(MessagingBuffer buffer);

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -27,6 +27,7 @@
 import static org.jboss.messaging.utils.DataConstants.SIZE_INT;
 import static org.jboss.messaging.utils.DataConstants.SIZE_LONG;
 
+import java.io.InputStream;
 import java.util.Set;
 
 import org.jboss.messaging.core.buffers.ChannelBuffers;
@@ -96,6 +97,10 @@
    private byte priority;
 
    private MessagingBuffer body;
+
+   /** Used on LargeMessages */
+   private InputStream bodyInputStream;
+
      
    // Constructors --------------------------------------------------
 
@@ -323,6 +328,24 @@
       return System.currentTimeMillis() - expiration >= 0;
    }
    
+   /**
+    * @return the bodyInputStream
+    */
+   public InputStream getBodyInputStream()
+   {
+      return bodyInputStream;
+   }
+
+   /**
+    * @param bodyInputStream the bodyInputStream to set
+    */
+   public void setBodyInputStream(InputStream bodyInputStream)
+   {
+      this.bodyInputStream = bodyInputStream;
+   }
+
+
+   
    // Properties
    // ---------------------------------------------------------------------------------------
 

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionReceiveMessage.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -42,6 +42,7 @@
 
    public static final int SESSION_RECEIVE_MESSAGE_LARGE_MESSAGE_SIZE = BASIC_PACKET_SIZE + DataConstants.SIZE_LONG +
                                                                        DataConstants.SIZE_INT +
+                                                                       DataConstants.SIZE_INT +
                                                                        DataConstants.SIZE_BOOLEAN +
                                                                        DataConstants.SIZE_INT;
 
@@ -60,12 +61,15 @@
    private ServerMessage serverMessage;
 
    private int deliveryCount;
+   
+   /** Since we receive the message before the entire message was received, */
+   private int largeMessageSize;
 
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
 
-   public SessionReceiveMessage(final long consumerID, final byte[] largeMessageHeader, final int deliveryCount)
+   public SessionReceiveMessage(final long consumerID, final byte[] largeMessageHeader, final int largeMessageSize, final int deliveryCount)
    {
       super(SESS_RECEIVE_MSG);
 
@@ -76,6 +80,8 @@
       this.deliveryCount = deliveryCount;
 
       this.largeMessage = true;
+      
+      this.largeMessageSize = largeMessageSize;
    }
 
    public SessionReceiveMessage(final long consumerID, final ServerMessage message, final int deliveryCount)
@@ -133,6 +139,14 @@
       return deliveryCount;
    }
 
+   /**
+    * @return the largeMessageSize
+    */
+   public int getLargeMessageSize()
+   {
+      return largeMessageSize;
+   }
+
    public int getRequiredBufferSize()
    {
       if (largeMessage)
@@ -154,6 +168,7 @@
       buffer.writeBoolean(largeMessage);
       if (largeMessage)
       {
+         buffer.writeInt(largeMessageSize);
          buffer.writeInt(largeMessageHeader.length);
          buffer.writeBytes(largeMessageHeader);
       }
@@ -175,6 +190,7 @@
 
       if (largeMessage)
       {
+         largeMessageSize = buffer.readInt();
          int size = buffer.readInt();
          largeMessageHeader = new byte[size];
          buffer.readBytes(largeMessageHeader);

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendContinuationMessage.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendContinuationMessage.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendContinuationMessage.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -44,6 +44,9 @@
 
    private boolean requiresResponse;
 
+   // Not sent through the wire. Just to define how many bytes to send of body
+   private transient int bodyLength;
+
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
@@ -63,11 +66,13 @@
     * @param requiresResponse
     */
    public SessionSendContinuationMessage(final byte[] body,
+                                         final int bodyLength,
                                          final boolean continues,
                                          final boolean requiresResponse)
    {
       super(SESS_SEND_CONTINUATION, body, continues);
       this.requiresResponse = requiresResponse;
+      this.bodyLength = bodyLength;
    }
 
 
@@ -90,7 +95,9 @@
    @Override
    public void encodeBody(final MessagingBuffer buffer)
    {
-      super.encodeBody(buffer);
+      buffer.writeInt(bodyLength);
+      buffer.writeBytes(body, 0, bodyLength);
+      buffer.writeBoolean(continues);
       buffer.writeBoolean(requiresResponse);
    }
 

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendLargeMessage.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendLargeMessage.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionSendLargeMessage.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -44,19 +44,15 @@
    /** We need to set the MessageID when replicating this on the server */
    private long largeMessageId = -1;
 
-   private boolean requiresResponse;
-
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
 
-   public SessionSendLargeMessage(final byte[] largeMessageHeader, final boolean requiresResponse)
+   public SessionSendLargeMessage(final byte[] largeMessageHeader)
    {
       super(SESS_SEND_LARGE);
 
       this.largeMessageHeader = largeMessageHeader;
-
-      this.requiresResponse = requiresResponse;
    }
 
    public SessionSendLargeMessage()
@@ -71,11 +67,6 @@
       return largeMessageHeader;
    }
 
-   public boolean isRequiresResponse()
-   {
-      return requiresResponse;
-   }
-
    /**
     * @return the largeMessageId
     */
@@ -98,7 +89,6 @@
       buffer.writeInt(largeMessageHeader.length);
       buffer.writeBytes(largeMessageHeader);
       buffer.writeLong(largeMessageId);
-      buffer.writeBoolean(requiresResponse);
    }
 
    @Override
@@ -111,16 +101,13 @@
       buffer.readBytes(largeMessageHeader);
 
       largeMessageId = buffer.readLong();
-
-      requiresResponse = buffer.readBoolean();
    }
 
    public int getRequiredBufferSize()
    {
       int size = BASIC_PACKET_SIZE + DataConstants.SIZE_INT +
                  largeMessageHeader.length +
-                 DataConstants.SIZE_LONG +
-                 DataConstants.SIZE_BOOLEAN;
+                 DataConstants.SIZE_LONG;
 
       return size;
    }

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -137,13 +137,13 @@
    private final ManagementService managementService;
 
    private final Binding binding;
-   
-   
+
    private MessagingServer server;
 
    // Constructors ---------------------------------------------------------------------------------
 
-   public ServerConsumerImpl(final MessagingServer server, final long id,
+   public ServerConsumerImpl(final MessagingServer server,
+                             final long id,
                              final long replicatedSessionID,
                              final ServerSession session,
                              final QueueBinding binding,
@@ -160,7 +160,7 @@
                              final ManagementService managementService) throws Exception
    {
       this.server = server;
-      
+
       this.id = id;
 
       this.replicatedSessionID = replicatedSessionID;
@@ -217,9 +217,14 @@
    }
 
    public void close() throws Exception
-   {    
+   {
       setStarted(false);
 
+      if (largeMessageDeliverer != null)
+      {
+         largeMessageDeliverer.close();
+      }
+
       messageQueue.removeConsumer(this);
 
       session.removeConsumer(this);
@@ -414,23 +419,27 @@
    }
 
    public void deliverReplicated(final long messageID) throws Exception
-   {      
+   {
       MessageReference ref = messageQueue.removeFirstReference(messageID);
 
       if (ref == null)
       {
          // The order is correct, but it hasn't been depaged yet, so we need to force a depage
          PagingStore store = pagingManager.getPageStore(binding.getAddress());
-         
+
          // force a depage
          if (!store.readPage()) // This returns false if there are no pages
          {
-            throw new IllegalStateException("Cannot find ref " + messageID + " server " + System.identityHashCode(server) + " queue " + this.messageQueue.getName());
+            throw new IllegalStateException("Cannot find ref " + messageID +
+                                            " server " +
+                                            System.identityHashCode(server) +
+                                            " queue " +
+                                            this.messageQueue.getName());
          }
          else
          {
             ref = messageQueue.removeFirstReference(messageID);
-            
+
             if (ref == null)
             {
                throw new IllegalStateException("Cannot find ref after depaging");
@@ -451,7 +460,7 @@
                                          handled);
       }
    }
-   
+
    public void failedOver()
    {
       if (messageQueue.consumerFailedOver())
@@ -732,6 +741,9 @@
       {
          pendingLargeMessage = message;
 
+         // we must hold one reference, or the file will be deleted before it could be delivered
+         pendingLargeMessage.incrementRefCount();
+
          sizePendingLargeMessage = pendingLargeMessage.getBodySize();
 
          this.ref = ref;
@@ -766,7 +778,10 @@
 
                pendingLargeMessage.encodeProperties(headerBuffer);
 
-               initialMessage = new SessionReceiveMessage(id, headerBuffer.array(), ref.getDeliveryCount());
+               initialMessage = new SessionReceiveMessage(id,
+                                                          headerBuffer.array(),
+                                                          pendingLargeMessage.getBodySize(),
+                                                          ref.getDeliveryCount());
             }
 
             int precalculateAvailableCredits;
@@ -838,32 +853,8 @@
                trace("Finished deliverLargeMessage isBackup = " + messageQueue.isBackup());
             }
 
-            pendingLargeMessage.releaseResources();
+            close();
 
-            if (preAcknowledge && !browseOnly)
-            {
-               // We added a reference for pre-ack, to avoid deleting the file before it was delivered
-               if (pendingLargeMessage.decrementRefCount() == 0)
-               {
-                  // On pre-acks for Large messages, the decrement was deferred to large-message, hence we need to
-                  // subtract the size inside largeMessage
-                  try
-                  {
-                     PagingStore store = pagingManager.getPageStore(binding.getAddress());
-                     store.addSize(-pendingLargeMessage.getMemoryEstimate());
-                  }
-                  catch (Exception e)
-                  {
-                     // This shouldn't happen on getPageStore
-                     log.error("Error getting pageStore", e);
-                  }
-               }
-            }
-
-            largeMessageDeliverer = null;
-
-            pendingLargeMessagesCounter.decrementAndGet();
-
             return true;
          }
          finally
@@ -873,6 +864,47 @@
       }
 
       /**
+       * 
+       */
+      public void close()
+      {
+         pendingLargeMessage.releaseResources();
+
+         int counter = pendingLargeMessage.decrementRefCount();
+         
+         if (preAcknowledge && !browseOnly)
+         {
+            // PreAck will have an extra reference
+            counter = pendingLargeMessage.decrementRefCount();
+         }
+
+         if (!browseOnly)
+         {
+            // We added a reference to avoid deleting the file before it was delivered
+            // if (pendingLargeMessage.decrementRefCount() == 0)
+            if (counter == 0)
+            {
+               // The decrement was deferred to large-message, hence we need to
+               // subtract the size inside largeMessage
+               try
+               {
+                  PagingStore store = pagingManager.getPageStore(binding.getAddress());
+                  store.addSize(-pendingLargeMessage.getMemoryEstimate());
+               }
+               catch (Exception e)
+               {
+                  // This shouldn't happen as the pageStore should have been initialized already.
+                  log.error("Error getting pageStore", e);
+               }
+            }
+         }
+
+         largeMessageDeliverer = null;
+
+         pendingLargeMessagesCounter.decrementAndGet();
+      }
+
+      /**
        * Credits flow control are calculated in advance.
        * @return
        */

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerMessageImpl.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -121,7 +121,9 @@
    
    public int incrementRefCount()
    {
-      return refCount.incrementAndGet();
+      int value = refCount.incrementAndGet();
+      //new Exception ("Incrementing refCount = " + value).printStackTrace();
+      return value;
    }
    
    public int incrementDurableRefCount()
@@ -136,7 +138,9 @@
 
    public int decrementRefCount()
    {
-      return refCount.decrementAndGet();
+      int value = refCount.decrementAndGet();
+      //new Exception ("Decrementing refCount = " + value).printStackTrace();
+      return value;
    }
    
    public int getRefCount()

Modified: branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -2201,17 +2201,8 @@
       {
          log.error("Failed to create large message", e);
          Packet response = null;
-         if (packet.isRequiresResponse())
-         {
-            if (e instanceof MessagingException)
-            {
-               response = new MessagingExceptionMessage((MessagingException)e);
-            }
-            else
-            {
-               response = new MessagingExceptionMessage(new MessagingException(MessagingException.INTERNAL_ERROR));
-            }
-         }
+
+         
          channel.confirm(packet);
          if (response != null)
          {
@@ -2236,15 +2227,8 @@
 
    private void doSendLargeMessage(final SessionSendLargeMessage packet)
    {
-      Packet response = null;
-
       try
       {
-         if (packet.isRequiresResponse())
-         {
-            response = new NullResponseMessage();
-         }
-         
          long id = storageManager.generateUniqueID();
                  
          currentLargeMessage.setMessageID(id);
@@ -2252,26 +2236,9 @@
       catch (Exception e)
       {
          log.error("Failed to send message", e);
-
-         if (packet.isRequiresResponse())
-         {
-            if (e instanceof MessagingException)
-            {
-               response = new MessagingExceptionMessage((MessagingException)e);
-            }
-            else
-            {
-               response = new MessagingExceptionMessage(new MessagingException(MessagingException.INTERNAL_ERROR));
-            }
-         }
       }
 
       channel.confirm(packet);
-
-      if (response != null)
-      {
-         channel.send(response);
-      }
    }
 
    private void doSend(final SessionSendMessage packet)

Added: branches/Branch_Temp_Clebert_LargeMessage/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java	                        (rev 0)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -0,0 +1,196 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test.messaging.jms.message;
+
+import java.io.BufferedOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.concurrent.CountDownLatch;
+
+import javax.jms.BytesMessage;
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.jboss.messaging.jms.client.JBossMessage;
+import org.jboss.test.messaging.jms.JMSTestCase;
+
+/**
+ *
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 6220 $</tt>
+ *
+ * $Id: MessageHeaderTest.java 6220 2009-03-30 19:38:11Z timfox $
+ */
+public class LargeMessageTest extends JMSTestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public void testSimpleLargeMessage() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+         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).getCoreMessage().setBodyInputStream(createFakeLargeStream((byte)'j', 1024 * 1024));
+
+         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);
+         
+         byte data[] = new byte[1024];
+         
+         System.out.println("Message = " + rm);
+
+         for (int i = 0; i < 1024 * 1024; i += 1024)
+         {
+            System.out.println("Read message chunk " + i);
+            int numberOfBytes = rm.readBytes(data);
+            assertEquals(1024, numberOfBytes);
+            for (int j = 0 ; j < 1024; j++)
+            {
+               assertEquals((byte)'j', data[j]);
+            }
+         }
+         
+         assertNotNull(rm);
+
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+
+   }
+   
+   
+   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
+   {
+      
+      final PipedInputStream pipedInput = new PipedInputStream();
+      final PipedOutputStream pipedOut = new PipedOutputStream(pipedInput);
+      final OutputStream out = new BufferedOutputStream(pipedOut);
+      
+      
+      new Thread()
+      {
+         public void run()
+         {
+            try
+            {
+               for (long i = 0; i < size; i++)
+               {
+                  out.write(byteToWrite);
+               }
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+            }
+            finally
+            {
+               try
+               {
+                  out.close();
+               }
+               catch (Throwable ignored)
+               {
+               }
+            }
+         }
+         
+      }.start();
+      
+      
+      return pipedInput;
+      
+   }
+   
+
+   
+
+   // Inner classes -------------------------------------------------
+   
+   
+   class ThreadReader extends Thread
+   {
+      CountDownLatch latch;
+      
+      ThreadReader(CountDownLatch latch)
+      {
+         this.latch = latch;
+      }
+      
+      public void run()
+      {
+      }
+   }
+   
+
+}

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -43,7 +43,6 @@
 
 import org.jboss.messaging.core.buffers.ChannelBuffers;
 import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
 import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.client.ClientSession;
@@ -1071,11 +1070,6 @@
          return message;
       }
 
-      public ClientFileMessage createFileMessage(boolean durable)
-      {
-         return null;
-      }
-
       public void start() throws MessagingException
       {
       }

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/joram-tests/src/org/jboss/test/jms/AbstractAdmin.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/joram-tests/src/org/jboss/test/jms/AbstractAdmin.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/joram-tests/src/org/jboss/test/jms/AbstractAdmin.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -46,7 +46,7 @@
 
    public void stop() throws Exception
    {
-      // TODO Auto-generated method stub
+     
       
    }
    

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/String64KLimitTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/String64KLimitTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/String64KLimitTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -121,25 +121,25 @@
 
       assertNotNull(rm1);
 
+      assertEquals(s1, rm1.getBody().readString());
+
       ClientMessage rm2 = consumer.receive(1000);
 
       assertNotNull(rm2);
 
+      assertEquals(s2, rm2.getBody().readString());
+
       ClientMessage rm3 = consumer.receive(1000);
 
+      assertEquals(s3, rm3.getBody().readString());
+
       assertNotNull(rm3);
 
       ClientMessage rm4 = consumer.receive(1000);
 
+      assertEquals(s4, rm4.getBody().readString());
+
       assertNotNull(rm4);
-
-      assertEquals(s1, rm1.getBody().readString());
-
-      assertEquals(s2, rm2.getBody().readString());
-
-      assertEquals(s3, rm3.getBody().readString());
-
-      assertEquals(s4, rm4.getBody().readString());
    }
 
    public void test64KLimitWithWriteUTF() throws Exception

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkCleanupTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkCleanupTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkCleanupTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -23,11 +23,10 @@
 package org.jboss.messaging.tests.integration.chunkmessage;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.util.HashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
 import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.client.ClientSession;
@@ -44,7 +43,6 @@
 import org.jboss.messaging.core.settings.impl.AddressSettings;
 import org.jboss.messaging.tests.integration.chunkmessage.mock.MockConnector;
 import org.jboss.messaging.tests.integration.chunkmessage.mock.MockConnectorFactory;
-import org.jboss.messaging.utils.SimpleString;
 
 /**
  * A ChunkCleanupTest
@@ -67,12 +65,18 @@
    // Constructors --------------------------------------------------
 
    // Public --------------------------------------------------------
+   
+   
    public void testCleanup() throws Exception
    {
       clearData();
+      
+      FileOutputStream fileOut = new FileOutputStream(new File(getLargeMessagesDir(), "1234.tmp"));
+      
+      fileOut.write(new byte[1024]); // anything
+      
+      fileOut.close();
 
-      createLargeFile(getLargeMessagesDir(), "1234.tmp", 13333);
-
       Configuration config = createDefaultConfig();
 
       server = createServer(true, config, new HashMap<String, AddressSettings>());
@@ -84,7 +88,7 @@
 
          File directoryLarge = new File(getLargeMessagesDir());
 
-         assertEquals(0, directoryLarge.list().length);
+         assertEquals("The startup should have been deleted 1234.tmp", 0, directoryLarge.list().length);
       }
       finally
       {
@@ -105,7 +109,7 @@
 
       server.start();
 
-      final int numberOfIntegersBigMessage = 150000;
+      final int numberOfBytes = 2 * 1024 * 1024;
 
       ClientSession session = null;
 
@@ -154,7 +158,7 @@
 
          ClientProducer producer = session.createProducer(ADDRESS);
 
-         ClientFileMessage clientLarge = createLargeClientMessage(session, numberOfIntegersBigMessage);
+         ClientMessage clientLarge = createLargeClientMessage(session, numberOfBytes);
 
          try
          {
@@ -182,94 +186,6 @@
       }
 
    }
-
-   // Validate the functions to create and verify files
-   public void testFiles() throws Exception
-   {
-      clearData();
-
-      File file = createLargeFile(getTemporaryDir(), "test.tst", 13333);
-
-      checkFileRead(file, 13333);
-   }
-
-   public void testClearOnClientBuffer() throws Exception
-   {
-      clearData();
-
-      server = createServer(true);
-      server.start();
-
-      final int numberOfIntegers = 10;
-      final int numberOfMessages = 100;
-
-      try
-      {
-         ClientSessionFactory sf = createInVMFactory();
-
-         sf.setBlockOnNonPersistentSend(true);
-         sf.setBlockOnPersistentSend(true);
-         sf.setBlockOnAcknowledge(true);
-
-         ClientSession session = sf.createSession(null, null, false, true, false, false, 0);
-
-         session.createQueue(ADDRESS, ADDRESS, null, true);
-
-         server.getPostOffice().getPagingManager().getGlobalSize();
-
-         ClientProducer producer = session.createProducer(ADDRESS);
-
-         File tmpData = createLargeFile(getTemporaryDir(), "someFile.dat", numberOfIntegers);
-
-         for (int i = 0; i < numberOfMessages; i++)
-         {
-            ClientMessage message = session.createFileMessage(true);
-            ((ClientFileMessage)message).setFile(tmpData);
-            message.putIntProperty(new SimpleString("counter-message"), i);
-            System.currentTimeMillis();
-            producer.send(message);
-         }
-
-         ClientConsumer consumer = session.createFileConsumer(new File(getClientLargeMessagesDir()), ADDRESS);;
-
-         File clientfiles = new File(getClientLargeMessagesDir());
-
-         session.start();
-
-         ClientMessage msg = consumer.receive(1000);
-         msg.acknowledge();
-
-         for (int i = 0; i < 100; i++)
-         {
-            if (clientfiles.listFiles().length > 0)
-            {
-               break;
-            }
-            Thread.sleep(100);
-         }
-
-         assertTrue(clientfiles.listFiles().length > 0);
-
-         session.close();
-
-         assertEquals(1, clientfiles.list().length); // 1 message was received, that should be kept
-
-         validateNoFilesOnLargeDir();
-
-      }
-      finally
-      {
-         try
-         {
-            server.stop();
-         }
-         catch (Throwable ignored)
-         {
-         }
-      }
-
-   }
-
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/chunkmessage/ChunkTestBase.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -25,20 +25,22 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
+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 javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
 import org.jboss.messaging.core.buffers.ChannelBuffers;
 import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
 import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.MessageHandler;
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.message.impl.MessageImpl;
@@ -82,45 +84,41 @@
 
    protected void testChunks(final boolean isXA,
                              final boolean realFiles,
-                             final boolean useFile,
                              final boolean preAck,
                              final boolean sendingBlocking,
                              final boolean testBrowser,
+                             final boolean useMessageConsumer,
                              final int numberOfMessages,
-                             final int numberOfIntegers,
+                             final int numberOfBytes,
                              final int waitOnConsumer,
                              final long delayDelivery) throws Exception
    {
       testChunks(isXA,
                  realFiles,
-                 useFile,
                  preAck,
                  sendingBlocking,
                  testBrowser,
+                 useMessageConsumer,
                  numberOfMessages,
-                 numberOfIntegers,
+                 numberOfBytes,
                  waitOnConsumer,
                  delayDelivery,
                  -1,
-                 100 * 1024,
-                 10 * 1024,
-                 false);
+                 10 * 1024);
    }
 
    protected void testChunks(final boolean isXA,
                              final boolean realFiles,
-                             final boolean useFile,
                              final boolean preAck,
                              final boolean sendingBlocking,
                              final boolean testBrowser,
+                             final boolean useMessageConsumer,
                              final int numberOfMessages,
-                             final int numberOfIntegers,
+                             final int numberOfBytes,
                              final int waitOnConsumer,
                              final long delayDelivery,
                              final int producerWindow,
-                             final int minSizeProducer,
-                             final int minSizeConsumer,
-                             final boolean testTime) throws Exception
+                             final int minSize) throws Exception
    {
       clearData();
 
@@ -143,7 +141,7 @@
             sf.setSendWindowSize(producerWindow);
          }
 
-         sf.setMinLargeMessageSize(minSizeProducer);
+         sf.setMinLargeMessageSize(minSize);
 
          ClientSession session;
 
@@ -160,7 +158,7 @@
 
          ClientProducer producer = session.createProducer(ADDRESS);
 
-         sendMessages(useFile, numberOfMessages, numberOfIntegers, delayDelivery, testTime, session, producer);
+         sendMessages(numberOfMessages, numberOfBytes, delayDelivery, session, producer);
 
          if (isXA)
          {
@@ -176,7 +174,7 @@
 
          validateNoFilesOnLargeDir();
 
-         sendMessages(useFile, numberOfMessages, numberOfIntegers, delayDelivery, testTime, session, producer);
+         sendMessages(numberOfMessages, numberOfBytes, delayDelivery, session, producer);
 
          if (isXA)
          {
@@ -202,8 +200,6 @@
             sf = createInVMFactory();
          }
 
-         sf.setMinLargeMessageSize(minSizeConsumer);
-
          session = sf.createSession(null, null, isXA, false, false, preAck, 0);
 
          if (isXA)
@@ -214,99 +210,139 @@
 
          ClientConsumer consumer = null;
 
-         // If delayed deliveries... it doesn't make sense with Browsing
-         for (int iteration = (testBrowser ? 0 : 1); iteration < 2; iteration++)
+         for (int iteration = testBrowser ? 0 : 1; iteration < 2; iteration++)
          {
 
+            System.out.println("Iteration: " + iteration);
+
+            session.stop();
+
             // first time with a browser
-            if (realFiles)
+            consumer = session.createConsumer(ADDRESS, null, iteration == 0);
+
+            if (useMessageConsumer)
             {
-               consumer = session.createFileConsumer(new File(getClientLargeMessagesDir()),
-                                                     ADDRESS,
-                                                     null,
-                                                     iteration == 0);
-            }
-            else
-            {
-               consumer = session.createConsumer(ADDRESS, null, iteration == 0);
-            }
+               final CountDownLatch latchDone = new CountDownLatch(numberOfMessages);
+               final AtomicInteger errrors = new AtomicInteger(0);
 
-            session.start();
+               MessageHandler handler = new MessageHandler()
+               {
+                  int msgCounter;
 
-            for (int i = 0; i < numberOfMessages; i++)
-            {
-               long start = System.currentTimeMillis();
+                  public void onMessage(final ClientMessage message)
+                  {
 
-               ClientMessage message = consumer.receive(waitOnConsumer + delayDelivery);
+                     try
+                     {
+                        latchDone.countDown();
 
-               assertNotNull(message);
+                        System.out.println("Message: " + msgCounter);
 
-               if (realFiles)
-               {
-                  assertTrue(message instanceof ClientFileMessage);
-               }
+                        if (delayDelivery > 0)
+                        {
+                           long originalTime = (Long)message.getProperty(new SimpleString("original-time"));
+                           assertTrue(System.currentTimeMillis() - originalTime + "<" + delayDelivery,
+                                      System.currentTimeMillis() - originalTime >= delayDelivery);
+                        }
 
-               if (testTime)
-               {
-                  System.out.println("Message received in " + (System.currentTimeMillis() - start));
-               }
-               start = System.currentTimeMillis();
+                        if (!preAck)
+                        {
+                           message.acknowledge();
+                        }
 
-               if (delayDelivery > 0)
-               {
-                  long originalTime = (Long)message.getProperty(new SimpleString("original-time"));
-                  assertTrue((System.currentTimeMillis() - originalTime) + "<" + delayDelivery,
-                             System.currentTimeMillis() - originalTime >= delayDelivery);
-               }
+                        assertNotNull(message);
 
-               if (!preAck)
-               {
-                  message.acknowledge();
-               }
+                        if (delayDelivery <= 0)
+                        {
+                           // right now there is no guarantee of ordered delivered on multiple scheduledMessages with
+                           // the same
+                           // scheduled delivery time
+                           assertEquals(msgCounter,
+                                        ((Integer)message.getProperty(new SimpleString("counter-message"))).intValue());
+                        }
 
-               if (isXA)
-               {
-                  session.end(xid, XAResource.TMSUCCESS);
-                  session.commit(xid, true);
-                  xid = newXID();
-                  session.start(xid, XAResource.TMNOFLAGS);
-               }
-               else
-               {
-                  session.commit();
-               }
+                        MessagingBuffer buffer = message.getBody();
+                        buffer.resetReaderIndex();
+                        assertEquals(numberOfBytes, buffer.writerIndex());
+                        for (int b = 0; b < numberOfBytes; b++)
+                        {
+                           assertEquals((byte)'a', buffer.readByte());
+                        }
+                     }
+                     catch (Throwable e)
+                     {
+                        e.printStackTrace();
+                        errrors.incrementAndGet();
+                     }
+                     finally
+                     {
+                        msgCounter++;
+                     }
+                  }
+               };
 
-               assertNotNull(message);
+               session.start();
+               
+               Thread.sleep(1000);
 
-               if (delayDelivery <= 0)
-               {
-                  // right now there is no guarantee of ordered delivered on multiple scheduledMessages with the same
-                  // scheduled delivery time
-                  assertEquals(i, ((Integer)message.getProperty(new SimpleString("counter-message"))).intValue());
-               }
+               consumer.setMessageHandler(handler);
 
-               if (!testTime)
+               assertTrue(latchDone.await(20, TimeUnit.SECONDS));
+               assertEquals(0, errrors.get());
+
+            }
+            else
+            {
+
+               session.start();
+
+               for (int i = 0; i < numberOfMessages; i++)
                {
-                  if (message instanceof ClientFileMessage)
+                  System.currentTimeMillis();
+
+                  ClientMessage message = consumer.receive(waitOnConsumer + delayDelivery);
+
+                  assertNotNull(message);
+
+                  System.out.println("Message: " + i);
+
+                  System.currentTimeMillis();
+
+                  if (delayDelivery > 0)
                   {
-                     checkFileRead(((ClientFileMessage)message).getFile(), numberOfIntegers);
+                     long originalTime = (Long)message.getProperty(new SimpleString("original-time"));
+                     assertTrue(System.currentTimeMillis() - originalTime + "<" + delayDelivery,
+                                System.currentTimeMillis() - originalTime >= delayDelivery);
                   }
-                  else
+
+                  if (!preAck)
                   {
-                     MessagingBuffer buffer = message.getBody();
-                     buffer.resetReaderIndex();
-                     assertEquals(numberOfIntegers * DataConstants.SIZE_INT, buffer.writerIndex());
-                     for (int b = 0; b < numberOfIntegers; b++)
-                     {
-                        assertEquals(b, buffer.readInt());
-                     }
+                     message.acknowledge();
                   }
+
+                  assertNotNull(message);
+
+                  if (delayDelivery <= 0)
+                  {
+                     // right now there is no guarantee of ordered delivered on multiple scheduledMessages with the same
+                     // scheduled delivery time
+                     assertEquals(i, ((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++)
+                  {
+                     assertEquals((byte)'a', buffer.readByte());
+                  }
                }
+
             }
+            consumer.close();
 
             if (iteration == 0)
             {
-               consumer.close();
                if (isXA)
                {
                   session.end(xid, XAResource.TMSUCCESS);
@@ -319,6 +355,20 @@
                   session.rollback();
                }
             }
+            else
+            {
+               if (isXA)
+               {
+                  session.end(xid, XAResource.TMSUCCESS);
+                  session.commit(xid, true);
+                  xid = newXID();
+                  session.start(xid, XAResource.TMNOFLAGS);
+               }
+               else
+               {
+                  session.commit();
+               }
+            }
          }
 
          session.close();
@@ -355,68 +405,29 @@
     * @throws IOException
     * @throws MessagingException
     */
-   private void sendMessages(final boolean useFile,
-                             final int numberOfMessages,
-                             final int numberOfIntegers,
+   private void sendMessages(final int numberOfMessages,
+                             final int numberOfBytes,
                              final long delayDelivery,
-                             final boolean testTime,
-                             ClientSession session,
-                             ClientProducer producer) throws FileNotFoundException, IOException, MessagingException
+                             final ClientSession session,
+                             final ClientProducer producer) throws Exception
    {
-      if (useFile)
+      for (int i = 0; i < numberOfMessages; i++)
       {
-         File tmpData = createLargeFile(getTemporaryDir(), "someFile.dat", numberOfIntegers);
-
-         for (int i = 0; i < numberOfMessages; i++)
+         System.out.println("Sending message " + i);
+         ClientMessage message = session.createClientMessage(true);
+         message.setBodyInputStream(createFakeLargeStream(numberOfBytes, (byte)'a'));
+         message.putIntProperty(new SimpleString("counter-message"), i);
+         if (delayDelivery > 0)
          {
-            ClientMessage message = session.createFileMessage(true);
-            ((ClientFileMessage)message).setFile(tmpData);
-            message.putIntProperty(new SimpleString("counter-message"), i);
-            long timeStart = System.currentTimeMillis();
-            if (delayDelivery > 0)
-            {
-               long time = System.currentTimeMillis();
-               message.putLongProperty(new SimpleString("original-time"), time);
-               message.putLongProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME, time + delayDelivery);
+            long time = System.currentTimeMillis();
+            message.putLongProperty(new SimpleString("original-time"), time);
+            message.putLongProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME, time + delayDelivery);
 
-               producer.send(message);
-            }
-            else
-            {
-               producer.send(message);
-            }
-            if (testTime)
-            {
-               System.out.println("Message sent in " + (System.currentTimeMillis() - timeStart));
-            }
+            producer.send(message);
          }
-
-      }
-      else
-      {
-         for (int i = 0; i < numberOfMessages; i++)
+         else
          {
-            ClientMessage message = session.createClientMessage(true);
-            message.putIntProperty(new SimpleString("counter-message"), i);
-            message.setBody(createLargeBuffer(numberOfIntegers));
-            long timeStart = System.currentTimeMillis();
-            if (delayDelivery > 0)
-            {
-               long time = System.currentTimeMillis();
-               message.putLongProperty(new SimpleString("original-time"), time);
-               message.putLongProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME, time + delayDelivery);
-
-               producer.send(message);
-            }
-            else
-            {
-               producer.send(message);
-            }
-
-            if (testTime)
-            {
-               System.out.println("Message sent in " + (System.currentTimeMillis() - timeStart));
-            }
+            producer.send(message);
          }
       }
    }
@@ -434,66 +445,24 @@
 
    }
 
-   protected ClientFileMessage createLargeClientMessage(final ClientSession session, final int numberOfIntegers) throws Exception
+   protected ClientMessage createLargeClientMessage(final ClientSession session, final int numberOfBytes) throws Exception
    {
-      return createLargeClientMessage(session, numberOfIntegers, true);
+      return createLargeClientMessage(session, numberOfBytes, true);
    }
 
-   protected ClientFileMessage createLargeClientMessage(final ClientSession session,
-                                                        final int numberOfIntegers,
-                                                        boolean persistent) throws Exception
+   protected ClientMessage createLargeClientMessage(final ClientSession session,
+                                                    final int numberOfBytes,
+                                                    final boolean persistent) throws Exception
    {
 
-      ClientFileMessage clientMessage = session.createFileMessage(persistent);
+      ClientMessage clientMessage = session.createClientMessage(persistent);
 
-      File tmpFile = createLargeFile(getTemporaryDir(), "tmpUpload.data", numberOfIntegers);
+      clientMessage.setBodyInputStream(createFakeLargeStream(numberOfBytes, (byte)'a'));
 
-      clientMessage.setFile(tmpFile);
-
       return clientMessage;
    }
 
    /**
-    * @param name
-    * @param numberOfIntegers
-    * @return
-    * @throws FileNotFoundException
-    * @throws IOException
-    */
-   protected File createLargeFile(final String directory, final String name, final int numberOfIntegers) throws FileNotFoundException,
-                                                                                                        IOException
-   {
-      File tmpFile = new File(directory + "/" + name);
-
-      RandomAccessFile random = new RandomAccessFile(tmpFile, "rw");
-      FileChannel channel = random.getChannel();
-
-      ByteBuffer buffer = ByteBuffer.allocate(4 * 1000);
-
-      for (int i = 0; i < numberOfIntegers; i++)
-      {
-         if (buffer.position() > 0 && i % 1000 == 0)
-         {
-            buffer.flip();
-            channel.write(buffer);
-            buffer.clear();
-         }
-         buffer.putInt(i);
-      }
-
-      if (buffer.position() > 0)
-      {
-         buffer.flip();
-         channel.write(buffer);
-      }
-
-      channel.close();
-      random.close();
-
-      return tmpFile;
-   }
-
-   /**
     * @param session
     * @param queueToRead
     * @param numberOfIntegers
@@ -501,36 +470,18 @@
     * @throws FileNotFoundException
     * @throws IOException
     */
-   protected void readMessage(final ClientSession session, final SimpleString queueToRead, final int numberOfIntegers) throws MessagingException,
-                                                                                                                      FileNotFoundException,
-                                                                                                                      IOException
+   protected void readMessage(final ClientSession session, final SimpleString queueToRead, final int numberOfBytes) throws MessagingException,
+                                                                                                                   FileNotFoundException,
+                                                                                                                   IOException
    {
       session.start();
 
-      ClientConsumer consumer = session.createFileConsumer(new File(getClientLargeMessagesDir()), queueToRead);
+      ClientConsumer consumer = session.createConsumer(queueToRead);
 
       ClientMessage clientMessage = consumer.receive(5000);
 
       assertNotNull(clientMessage);
 
-      if (!(clientMessage instanceof ClientFileMessage))
-      {
-         System.out.println("Size = " + clientMessage.getBodySize());
-      }
-
-      if (clientMessage instanceof ClientFileMessage)
-      {
-         assertTrue(clientMessage instanceof ClientFileMessage);
-
-         ClientFileMessage fileClientMessage = (ClientFileMessage)clientMessage;
-
-         assertNotNull(fileClientMessage);
-         File receivedFile = fileClientMessage.getFile();
-
-         checkFileRead(receivedFile, numberOfIntegers);
-
-      }
-
       clientMessage.acknowledge();
 
       session.commit();
@@ -539,61 +490,97 @@
    }
 
    /**
-    * @param receivedFile
-    * @throws FileNotFoundException
-    * @throws IOException
+    * Deleting a file on LargeDire is an asynchronous process. Wee need to keep looking for a while if the file hasn't been deleted yet
     */
-   protected void checkFileRead(final File receivedFile, final int numberOfIntegers) throws FileNotFoundException,
-                                                                                    IOException
+   protected void validateNoFilesOnLargeDir() throws Exception
    {
-      RandomAccessFile random2 = new RandomAccessFile(receivedFile, "r");
-      FileChannel channel2 = random2.getChannel();
+      File largeMessagesFileDir = new File(getLargeMessagesDir());
 
-      ByteBuffer buffer2 = ByteBuffer.allocate(1000 * 4);
+      // Deleting the file is async... we keep looking for a period of the time until the file is really gone
+      for (int i = 0; i < 100; i++)
+      {
+         if (largeMessagesFileDir.listFiles().length > 0)
+         {
+            Thread.sleep(10);
+         }
+         else
+         {
+            break;
+         }
+      }
 
-      channel2.position(0l);
+      assertEquals(0, largeMessagesFileDir.listFiles().length);
+   }
 
-      for (int i = 0; i < numberOfIntegers;)
+   protected InputStream createFakeLargeStream(final int size, final byte byteUsed) throws Exception
+   {
+      return new InputStream()
       {
-         channel2.read(buffer2);
+         private int count;
 
-         buffer2.flip();
-         for (int j = 0; j < buffer2.limit() / 4; j++, i++)
+         private boolean closed = false;
+
+         @Override
+         public void close() throws IOException
          {
-            assertEquals(i, buffer2.getInt());
+            super.close();
+            closed = true;
          }
 
-         buffer2.clear();
-      }
+         @Override
+         public int read() throws IOException
+         {
+            if (closed)
+            {
+               throw new IOException("Stream was closed");
+            }
+            if (count++ < size)
+            {
+               return byteUsed;
+            }
+            else
+            {
+               return -1;
+            }
+         }
+      };
 
-      channel2.close();
    }
 
-   /**
-    * Deleting a file on LargeDire is an asynchronous process. Wee need to keep looking for a while if the file hasn't been deleted yet
-    */
-   protected void validateNoFilesOnLargeDir() throws Exception
+   protected OutputStream createFakeOutputStream() throws Exception
    {
-      File largeMessagesFileDir = new File(getLargeMessagesDir());
 
-      // Deleting the file is async... we keep looking for a period of the time until the file is really gone
-      for (int i = 0; i < 100; i++)
+      return new OutputStream()
       {
-         if (largeMessagesFileDir.listFiles().length > 0)
+         private boolean closed = false;
+
+         private int count;
+
+         @Override
+         public void close() throws IOException
          {
-            Thread.sleep(10);
+            super.close();
+            closed = true;
          }
-         else
+
+         @Override
+         public void write(final int b) throws IOException
          {
-            break;
+            if (count++ % 1024 * 1024 == 0)
+            {
+               System.out.println("OutputStream received " + count + " bytes");
+            }
+            if (closed)
+            {
+               throw new IOException("Stream was closed");
+            }
          }
-      }
 
-      assertEquals(0, largeMessagesFileDir.listFiles().length);
+      };
+
    }
 
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------
-
 }

Deleted: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientFileMessageTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientFileMessageTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientFileMessageTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -1,133 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.tests.integration.client;
-
-import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
-import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.impl.ClientFileMessageImpl;
-import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.tests.util.ServiceTestBase;
-import org.jboss.messaging.utils.SimpleString;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-
-/**
- * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
- */
-public class ClientFileMessageTest extends ServiceTestBase
-{
-   public final SimpleString addressA = new SimpleString("addressA");
-
-   public final SimpleString queueA = new SimpleString("queueA");
-
-   public void testConsumeFileMessage() throws Exception
-   {
-      String testDir = System.getProperty("java.io.tmpdir", "/tmp") + "/jbm-unit-test";
-
-      MessagingServer server = createServer(false);
-      try
-      {
-         server.start();
-         ClientSessionFactory cf = createInVMFactory();
-         cf.setMinLargeMessageSize(1000);
-         ClientSession sendSession = cf.createSession(false, true, true);
-         ClientSession recSession = cf.createSession(false, true, true);
-         sendSession.createQueue(addressA, queueA, false);
-         ClientProducer cp = sendSession.createProducer(addressA);
-         File directory = new File(testDir);
-         directory.mkdirs();
-         ClientConsumer cc = recSession.createFileConsumer(directory, queueA);
-         recSession.start();
-         ClientMessage message = recSession.createClientMessage(false);
-         byte[] bytes = new byte[3000];
-         message.getBody().writeBytes(bytes);
-         cp.send(message);
-         ClientFileMessageImpl m = (ClientFileMessageImpl) cc.receive(5000);
-         assertNotNull(m);
-         FileChannel channel = m.getChannel();
-         ByteBuffer dst = ByteBuffer.allocate(3000);
-         channel.read(dst);
-         assertEqualsByteArrays(bytes, dst.array());
-         sendSession.close();
-         recSession.close();
-      }
-      finally
-      {
-         if (server.isStarted())
-         {
-            server.stop();
-         }
-      }
-   }
-
-   public void testProduceFileMessage() throws Exception
-   {
-      String testDir = System.getProperty("java.io.tmpdir", "/tmp") + "/jbm-unit-test";
-
-      MessagingServer server = createServer(false);
-      try
-      {
-         server.start();
-         ClientSessionFactory cf = createInVMFactory();
-         cf.setMinLargeMessageSize(1000);
-         ClientSession sendSession = cf.createSession(false, true, true);
-         ClientSession recSession = cf.createSession(false, true, true);
-         sendSession.createQueue(addressA, queueA, false);
-         ClientProducer cp = sendSession.createProducer(addressA);
-         File directory = new File(testDir);
-         directory.delete();
-         directory.mkdirs();
-         ClientConsumer cc = recSession.createConsumer(queueA);
-         recSession.start();
-         ClientFileMessage message = sendSession.createFileMessage(false);
-         byte[] bytes = new byte[3000];
-         File src = new File(directory, "test.jbm");
-         src.createNewFile();
-         FileOutputStream fos = new FileOutputStream(src);
-         fos.write(bytes);
-         fos.close();
-         message.setFile(src);
-         cp.send(message);
-         ClientMessage m = cc.receive(5000);
-         assertNotNull(m);
-         byte[] recBytes = new byte[3000];
-         m.getBody().readBytes(recBytes);
-         assertEqualsByteArrays(bytes, recBytes);
-         sendSession.close();
-         recSession.close();
-      }
-      finally
-      {
-         if (server.isStarted())
-         {
-            server.stop();
-         }
-      }
-   }
-}

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCloseTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -26,8 +26,6 @@
 import static org.jboss.messaging.tests.util.RandomUtil.randomSimpleString;
 import static org.jboss.messaging.tests.util.RandomUtil.randomXid;
 
-import java.io.File;
-
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 
@@ -98,14 +96,6 @@
       {
          public void run() throws MessagingException
          {
-            session.createFileConsumer(new File("."), randomSimpleString());
-         }
-      });
-
-      expectMessagingException(MessagingException.OBJECT_CLOSED, new MessagingAction()
-      {
-         public void run() throws MessagingException
-         {
             session.createQueue(randomSimpleString(), randomSimpleString(), randomBoolean());
          }
       });

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCreateConsumerTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCreateConsumerTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionCreateConsumerTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -47,7 +47,7 @@
          cf.setProducerMaxRate(99);
          cf.setBlockOnNonPersistentSend(true);
          cf.setBlockOnNonPersistentSend(true);
-         ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+         ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
          clientSession.createQueue(queueName, queueName, false);
          ClientConsumer consumer = clientSession.createConsumer(queueName);
          assertNotNull(consumer);
@@ -69,7 +69,7 @@
          cf.setProducerMaxRate(99);
          cf.setBlockOnNonPersistentSend(true);
          cf.setBlockOnNonPersistentSend(true);
-         ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+         ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
          try
          {
             clientSession.createConsumer(queueName);
@@ -97,7 +97,7 @@
          cf.setProducerMaxRate(99);
          cf.setBlockOnNonPersistentSend(true);
          cf.setBlockOnNonPersistentSend(true);
-         ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+         ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
          clientSession.createQueue(queueName, queueName, false);
          ClientConsumer consumer = clientSession.createConsumer(queueName, "foo=bar");
          assertNotNull(consumer);
@@ -119,7 +119,7 @@
          cf.setProducerMaxRate(99);
          cf.setBlockOnNonPersistentSend(true);
          cf.setBlockOnNonPersistentSend(true);
-         ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+         ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
          clientSession.createQueue(queueName, queueName, false);
          try
          {
@@ -148,7 +148,7 @@
          cf.setProducerMaxRate(99);
          cf.setBlockOnNonPersistentSend(true);
          cf.setBlockOnNonPersistentSend(true);
-         ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+         ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
          clientSession.createQueue(queueName, queueName, false);
          ClientConsumer consumer = clientSession.createConsumer(queueName, null, true);
          assertNotNull(consumer);
@@ -170,7 +170,7 @@
          cf.setProducerMaxRate(99);
          cf.setBlockOnNonPersistentSend(true);
          cf.setBlockOnNonPersistentSend(true);
-         ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
+         ClientSessionInternal clientSession = (ClientSessionInternal)cf.createSession(false, true, true);
          clientSession.createQueue(queueName, queueName, false);
          ClientConsumer consumer = clientSession.createConsumer(queueName, null, 100, 100, false);
          assertNotNull(consumer);
@@ -182,148 +182,4 @@
       }
    }
 
-   public void testCreateFileConsumerTest() throws Exception
-   {
-      MessagingServer service = createServer(false);
-      try
-      {
-         service.start();
-         ClientSessionFactory cf = createInVMFactory();
-         cf.setProducerMaxRate(99);
-         cf.setBlockOnNonPersistentSend(true);
-         cf.setBlockOnNonPersistentSend(true);
-         ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
-         clientSession.createQueue(queueName, queueName, false);
-         ClientConsumer consumer = clientSession.createFileConsumer(new File(""), queueName);
-         assertNotNull(consumer);
-         clientSession.close();
-      }
-      finally
-      {
-         service.stop();
-      }
-   }
-
-   public void testCreateFileConsumerNoQ() throws Exception
-      {
-         MessagingServer service = createServer(false);
-         try
-         {
-            service.start();
-            ClientSessionFactory cf = createInVMFactory();
-            cf.setProducerMaxRate(99);
-            cf.setBlockOnNonPersistentSend(true);
-            cf.setBlockOnNonPersistentSend(true);
-            ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
-            try
-            {
-               clientSession.createFileConsumer(new File(""), queueName);
-               fail("should throw exception");
-            }
-            catch (MessagingException e)
-            {
-               assertEquals(e.getCode(), MessagingException.QUEUE_DOES_NOT_EXIST);
-            }
-            clientSession.close();
-         }
-         finally
-         {
-            service.stop();
-         }
-      }
-
-      public void testCreateFileConsumerWithFilter() throws Exception
-      {
-         MessagingServer service = createServer(false);
-         try
-         {
-            service.start();
-            ClientSessionFactory cf = createInVMFactory();
-            cf.setProducerMaxRate(99);
-            cf.setBlockOnNonPersistentSend(true);
-            cf.setBlockOnNonPersistentSend(true);
-            ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
-            clientSession.createQueue(queueName, queueName, false);
-            ClientConsumer consumer = clientSession.createFileConsumer(new File(""), queueName, "foo=bar");
-            assertNotNull(consumer);
-            clientSession.close();
-         }
-         finally
-         {
-            service.stop();
-         }
-      }
-
-      public void testCreateFileConsumerWithInvalidFilter() throws Exception
-      {
-         MessagingServer service = createServer(false);
-         try
-         {
-            service.start();
-            ClientSessionFactory cf = createInVMFactory();
-            cf.setProducerMaxRate(99);
-            cf.setBlockOnNonPersistentSend(true);
-            cf.setBlockOnNonPersistentSend(true);
-            ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
-            clientSession.createQueue(queueName, queueName, false);
-            try
-            {
-               clientSession.createFileConsumer(new File(""), queueName, "foobar");
-               fail("should throw exception");
-            }
-            catch (MessagingException e)
-            {
-               assertEquals(e.getCode(), MessagingException.INVALID_FILTER_EXPRESSION);
-            }
-            clientSession.close();
-         }
-         finally
-         {
-            service.stop();
-         }
-      }
-
-      public void testCreateFileConsumerWithBrowseOnly() throws Exception
-      {
-         MessagingServer service = createServer(false);
-         try
-         {
-            service.start();
-            ClientSessionFactory cf = createInVMFactory();
-            cf.setProducerMaxRate(99);
-            cf.setBlockOnNonPersistentSend(true);
-            cf.setBlockOnNonPersistentSend(true);
-            ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
-            clientSession.createQueue(queueName, queueName, false);
-            ClientConsumer consumer = clientSession.createFileConsumer(new File(""), queueName, null, true);
-            assertNotNull(consumer);
-            clientSession.close();
-         }
-         finally
-         {
-            service.stop();
-         }
-      }
-
-      public void testCreateFileConsumerWithOverrides() throws Exception
-      {
-         MessagingServer service = createServer(false);
-         try
-         {
-            service.start();
-            ClientSessionFactory cf = createInVMFactory();
-            cf.setProducerMaxRate(99);
-            cf.setBlockOnNonPersistentSend(true);
-            cf.setBlockOnNonPersistentSend(true);
-            ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
-            clientSession.createQueue(queueName, queueName, false);
-            ClientConsumer consumer = clientSession.createFileConsumer(new File(""), queueName, null, 100, 100, false);
-            assertNotNull(consumer);
-            clientSession.close();
-         }
-         finally
-         {
-            service.stop();
-         }
-      }
 }

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/ClientSessionTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -26,7 +26,6 @@
 import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.impl.ClientFileMessageInternal;
 import org.jboss.messaging.core.client.impl.ClientSessionImpl;
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.remoting.FailureListener;
@@ -348,48 +347,6 @@
       }
    }
 
-   public void testCreateClientFileMessageNonDurable() throws Exception
-   {
-      MessagingServer server = createServer(false);
-      try
-      {
-         server.start();
-         ClientSessionFactory cf = createInVMFactory();
-         ClientSession clientSession = cf.createSession(false, true, true);
-         ClientFileMessageInternal clientMessage = (ClientFileMessageInternal) clientSession.createFileMessage(false);
-         assertEquals(false, clientMessage.isDurable());
-         clientSession.close();
-      }
-      finally
-      {
-         if (server.isStarted())
-         {
-            server.stop();
-         }
-      }
-   }
-
-   public void testCreateClientFileMessageDurable() throws Exception
-   {
-      MessagingServer server = createServer(false);
-      try
-      {
-         server.start();
-         ClientSessionFactory cf = createInVMFactory();
-         ClientSession clientSession = cf.createSession(false, true, true);
-         ClientFileMessageInternal clientMessage = (ClientFileMessageInternal) clientSession.createFileMessage(true);
-         assertEquals(true, clientMessage.isDurable());
-         clientSession.close();
-      }
-      finally
-      {
-         if (server.isStarted())
-         {
-            server.stop();
-         }
-      }
-   }
-
    public void testGetVersion() throws Exception
    {
       MessagingServer server = createServer(false);

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/integration/client/MessageChunkTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -22,7 +22,6 @@
 
 package org.jboss.messaging.tests.integration.client;
 
-import java.io.File;
 import java.util.HashMap;
 
 import javax.transaction.xa.XAResource;
@@ -32,15 +31,17 @@
 
 import org.jboss.messaging.core.buffers.ChannelBuffers;
 import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.client.ClientFileMessage;
 import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientConsumerInternal;
 import org.jboss.messaging.core.config.Configuration;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.settings.impl.AddressSettings;
 import org.jboss.messaging.tests.integration.chunkmessage.ChunkTestBase;
 import org.jboss.messaging.utils.DataConstants;
@@ -62,6 +63,8 @@
 
    final static int RECEIVE_WAIT_TIME = 10000;
 
+   private final int LARGE_MESSAGE_SIZE = 20 * 1024;
+
    // Attributes ----------------------------------------------------
 
    static final SimpleString ADDRESS = new SimpleString("SimpleAddress");
@@ -73,67 +76,145 @@
 
    // Public --------------------------------------------------------
 
+   public void testReuseMessage() throws Exception
+   {
+      // Reusing a largemessage should throw an exception
+   }
 
+   public void testMessageChunkFilePersistenceOneMessage() throws Exception
+   {
+      testChunks(false, true, false, false, true, false, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+   }
+
+   public void testMessageChunkFilePersistenceOneMessageConsumer() throws Exception
+   {
+      for (int i = 0; i < 100; i++)
+      {
+         System.out.println("#test " + i);
+         testChunks(false, true, false, false, true, true, 1, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+      }
+   }
+
    public void testMessageChunkFilePersistence() throws Exception
    {
-      testChunks(false, true, false, false, false, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+      testChunks(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);
+   }
+
    public void testMessageChunkFilePersistenceXA() throws Exception
    {
-      testChunks(true, true, false, false, false, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, false, true, false, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
    }
 
+   public void testMessageChunkFilePersistenceXAConsumer() throws Exception
+   {
+      testChunks(true, true, false, false, true, true, 100, LARGE_MESSAGE_SIZE, RECEIVE_WAIT_TIME, 0);
+   }
+
    public void testMessageChunkFilePersistenceBlocked() throws Exception
    {
-      testChunks(false, true, false, false, true, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+      testChunks(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);
+   }
+
    public void testMessageChunkFilePersistenceBlockedXA() throws Exception
    {
-      testChunks(true, true, false, false, true, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, 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);
+   }
+
    public void testMessageChunkFilePersistenceBlockedPreACK() throws Exception
    {
-      testChunks(false, true, false, true, true, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+      testChunks(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);
+   }
+
    public void testMessageChunkFilePersistenceBlockedPreACKXA() throws Exception
    {
-      testChunks(true, true, false, true, true, true, 100, 262144, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, 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);
+   }
+
    public void testMessageChunkFilePersistenceDelayed() throws Exception
    {
-      testChunks(false, true, false, false, false, false, 1, 50000, RECEIVE_WAIT_TIME, 2000);
+      testChunks(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);
+   }
+
    public void testMessageChunkFilePersistenceDelayedXA() throws Exception
    {
-      testChunks(true, true, false, false, false, false, 1, 50000, RECEIVE_WAIT_TIME, 2000);
+      testChunks(true, 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);
+   }
+
    public void testMessageChunkNullPersistence() throws Exception
    {
-      testChunks(false, false, false, false, false, true, 1, 50000, RECEIVE_WAIT_TIME, 0);
+      testChunks(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);
+   }
+
    public void testMessageChunkNullPersistenceXA() throws Exception
    {
-      testChunks(true, false, false, false, false, true, 1, 50000, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, 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);
+   }
+
    public void testMessageChunkNullPersistenceDelayed() throws Exception
    {
-      testChunks(false, false, false, false, false, false, 100, 50000, RECEIVE_WAIT_TIME, 100);
+      testChunks(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);
+   }
+
    public void testMessageChunkNullPersistenceDelayedXA() throws Exception
    {
-      testChunks(true, false, false, false, false, false, 100, 50000, RECEIVE_WAIT_TIME, 100);
+      testChunks(true, 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);
+   }
+
    public void testPageOnLargeMessage() throws Exception
    {
       testPageOnLargeMessage(true, false);
@@ -145,84 +226,84 @@
 
    }
 
-   public void testSendfileMessage() throws Exception
+   public void testSendSmallMessageXA() throws Exception
    {
-      testChunks(false, true, true, false, false, true, 100, 50000, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, false, true, false, 100, 4, RECEIVE_WAIT_TIME, 0);
    }
 
-   public void testSendfileMessageXA() throws Exception
+   public void testSendSmallMessageXAConsumer() throws Exception
    {
-      testChunks(true, true, true, false, false, true, 100, 50000, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, true, false, false, true, true, 100, 4, RECEIVE_WAIT_TIME, 0);
    }
 
-   public void testSendfileMessageOnNullPersistence() throws Exception
+   public void testSendSmallMessageNullPersistenceXA() throws Exception
    {
-      testChunks(false, false, true, false, false, true, 100, 50000, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, false, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
-   public void testSendfileMessageOnNullPersistenceXA() throws Exception
+   public void testSendSmallMessageNullPersistenceXAConsumer() throws Exception
    {
-      testChunks(true, false, true, false, false, true, 100, 50000, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, false, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
-   public void testSendfileMessageOnNullPersistenceSmallMessage() throws Exception
+   public void testSendRegularMessageNullPersistenceDelayed() throws Exception
    {
-      testChunks(false, false, true, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
-   public void testSendfileMessageOnNullPersistenceSmallMessageXA() throws Exception
+   public void testSendRegularMessageNullPersistenceDelayedConsumer() throws Exception
    {
-      testChunks(true, false, true, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
-   public void testSendfileMessageSmallMessage() throws Exception
+   public void testSendRegularMessageNullPersistenceDelayedXA() throws Exception
    {
-      testChunks(false, true, true, false, false, true, 100, 4, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
-   public void testSendfileMessageSmallMessageXA() throws Exception
+   public void testSendRegularMessageNullPersistenceDelayedXAConsumer() throws Exception
    {
-      testChunks(true, true, true, false, false, true, 100, 4, RECEIVE_WAIT_TIME, 0);
+      testChunks(true, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
-   public void testSendRegularMessageNullPersistence() throws Exception
+   public void testSendRegularMessagePersistence() throws Exception
    {
-      testChunks(false, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
-   public void testSendRegularMessageNullPersistenceXA() throws Exception
+   public void testSendRegularMessagePersistenceConsumer() throws Exception
    {
-      testChunks(true, false, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
-   public void testSendRegularMessageNullPersistenceDelayed() throws Exception
+   public void testSendRegularMessagePersistenceXA() throws Exception
    {
-      testChunks(false, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(true, true, false, false, true, false, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
-   public void testSendRegularMessageNullPersistenceDelayedXA() throws Exception
+   public void testSendRegularMessagePersistenceXAConsumer() throws Exception
    {
-      testChunks(true, false, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(true, true, false, false, true, true, 100, 100, RECEIVE_WAIT_TIME, 0);
    }
 
-   public void testSendRegularMessagePersistence() throws Exception
+   public void testSendRegularMessagePersistenceDelayed() throws Exception
    {
-      testChunks(false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
-   public void testSendRegularMessagePersistenceXA() throws Exception
+   public void testSendRegularMessagePersistenceDelayedConsumer() throws Exception
    {
-      testChunks(true, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 0);
+      testChunks(false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
-   public void testSendRegularMessagePersistenceDelayed() throws Exception
+   public void testSendRegularMessagePersistenceDelayedXA() throws Exception
    {
       testChunks(false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
-   public void testSendRegularMessagePersistenceDelayedXA() throws Exception
+   public void testSendRegularMessagePersistenceDelayedXAConsumer() throws Exception
    {
-      testChunks(false, true, false, false, false, false, 100, 100, RECEIVE_WAIT_TIME, 1000);
+      testChunks(false, true, false, false, false, true, 100, 100, RECEIVE_WAIT_TIME, 1000);
    }
 
    public void testTwoBindingsTwoStartedConsumers() throws Exception
@@ -230,8 +311,6 @@
       // there are two bindings.. one is ACKed, the other is not, the server is restarted
       // The other binding is acked... The file must be deleted
 
-      clearData();
-
       try
       {
 
@@ -261,7 +340,7 @@
 
          producer.close();
 
-         ClientConsumer consumer = session.createFileConsumer(new File(getClientLargeMessagesDir()), queue[1]);
+         ClientConsumer consumer = session.createConsumer(queue[1]);
          ClientMessage msg = consumer.receive(RECEIVE_WAIT_TIME);
          assertNull(consumer.receive(1000));
          assertNotNull(msg);
@@ -273,7 +352,7 @@
 
          session.stop();
 
-         ClientConsumer consumer1 = session.createFileConsumer(new File(getClientLargeMessagesDir()), queue[0]);
+         ClientConsumer consumer1 = session.createConsumer(queue[0]);
 
          session.start();
 
@@ -316,8 +395,6 @@
       // there are two bindings.. one is ACKed, the other is not, the server is restarted
       // The other binding is acked... The file must be deleted
 
-      clearData();
-
       try
       {
 
@@ -394,8 +471,6 @@
 
    private void internalTestSendRollback(final boolean isXA) throws Exception
    {
-      clearData();
-
       server = createServer(true);
 
       server.start();
@@ -452,13 +527,11 @@
       simpleRollbackInternalTest(true);
    }
 
-   public void simpleRollbackInternalTest(boolean isXA) throws Exception
+   public void simpleRollbackInternalTest(final boolean isXA) throws Exception
    {
       // there are two bindings.. one is ACKed, the other is not, the server is restarted
       // The other binding is acked... The file must be deleted
 
-      clearData();
-
       try
       {
 
@@ -480,7 +553,7 @@
 
          session.createQueue(ADDRESS, ADDRESS, null, true);
 
-         int numberOfIntegers = 50000;
+         int numberOfBytes = 200000;
 
          session.start();
 
@@ -492,7 +565,7 @@
 
          for (int n = 0; n < 10; n++)
          {
-            Message clientFile = createLargeClientMessage(session, numberOfIntegers, n % 2 == 0);
+            Message clientFile = createLargeClientMessage(session, numberOfBytes, n % 2 == 0);
 
             producer.send(clientFile);
 
@@ -510,6 +583,8 @@
                session.rollback();
             }
 
+            clientFile = createLargeClientMessage(session, numberOfBytes, n % 2 == 0);
+
             producer.send(clientFile);
 
             assertNull(consumer.receiveImmediate());
@@ -533,7 +608,7 @@
 
                assertNotNull(clientMessage);
 
-               assertEquals(numberOfIntegers * 4, clientMessage.getBody().writerIndex());
+               assertEquals(numberOfBytes, clientMessage.getBody().writerIndex());
 
                clientMessage.acknowledge();
 
@@ -586,6 +661,270 @@
 
    }
 
+   public void testBufferMultipleLargeMessages() throws Exception
+   {
+      ClientSession session = null;
+      MessagingServer server = null;
+
+      final int SIZE = 10 * 1024;
+      final int NUMBER_OF_MESSAGES = 30;
+      try
+      {
+
+         server = createServer(true);
+
+         server.start();
+
+         ClientSessionFactory sf = createInVMFactory();
+
+         sf.setMinLargeMessageSize(1024);
+         sf.setConsumerWindowSize(1024 * 1024);
+
+         session = sf.createSession(null, null, false, false, false, false, 0);
+
+         session.createQueue(ADDRESS, ADDRESS, null, true);
+
+         ClientProducer producer = session.createProducer(ADDRESS);
+
+         for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
+         {
+            Message clientFile = session.createClientMessage(true);
+            clientFile.setBodyInputStream(createFakeLargeStream(SIZE, (byte)i));
+            producer.send(clientFile);
+
+         }
+         session.commit();
+         producer.close();
+
+         session.start();
+
+         ClientConsumerInternal consumer = (ClientConsumerInternal)session.createConsumer(ADDRESS);
+
+         // Wait the consumer to be complete with 10 messages before getting others
+         long timeout = System.currentTimeMillis() + 10000;
+         while (consumer.getBufferSize() < NUMBER_OF_MESSAGES && timeout > System.currentTimeMillis())
+         {
+            Thread.sleep(10);
+         }
+         assertEquals(NUMBER_OF_MESSAGES, consumer.getBufferSize());
+
+         // Reads the messages, rollback.. read them again
+         for (int trans = 0; trans < 2; trans++)
+         {
+
+            for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
+            {
+               ClientMessage msg = consumer.receive(10000);
+               assertNotNull(msg);
+
+               // it will ignore the buffer (not read it) on the first try
+               if (trans == 0)
+               {
+                  for (int byteRead = 0; byteRead < SIZE; byteRead++)
+                  {
+                     assertEquals((byte)i, msg.getBody().readByte());
+                  }
+               }
+
+               msg.acknowledge();
+            }
+            if (trans == 0)
+            {
+               session.rollback();
+            }
+            else
+            {
+               session.commit();
+            }
+         }
+
+         assertEquals(0l, server.getPostOffice().getPagingManager().getGlobalSize());
+         assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getDeliveringCount());
+         assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getMessageCount());
+
+      }
+      finally
+      {
+         try
+         {
+            session.close();
+         }
+         catch (Throwable ignored)
+         {
+         }
+
+         try
+         {
+            server.stop();
+         }
+         catch (Throwable ignored)
+         {
+         }
+      }
+   }
+
+   public void testSendStreamingSingleMessage() throws Exception
+   {
+      ClientSession session = null;
+      MessagingServer server = null;
+
+      final int SIZE = 10 * 1024 * 1024;
+      try
+      {
+
+         server = createServer(true);
+
+         server.start();
+
+         ClientSessionFactory sf = createInVMFactory();
+
+         sf.setMinLargeMessageSize(100 * 1024);
+
+         session = sf.createSession(null, null, false, true, true, false, 0);
+
+         session.createQueue(ADDRESS, ADDRESS, null, true);
+
+         Message clientFile = session.createClientMessage(true);
+         clientFile.setBodyInputStream(createFakeLargeStream(SIZE, (byte)'a'));
+
+         ClientProducer producer = session.createProducer(ADDRESS);
+
+         session.start();
+
+         System.out.println("Sending");
+         producer.send(clientFile);
+
+         producer.close();
+
+         System.out.println("Waiting");
+
+         ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+         ClientMessage msg2 = consumer.receive(10000);
+
+         msg2.acknowledge();
+
+         msg2.setOutputStream(createFakeOutputStream());
+         assertTrue(msg2.waitOutputStreamCompletion(60000));
+
+         // for (int i = 0; i < SIZE; i++)
+         // {
+         // byte value = msg2.getBody().readByte();
+         // assertEquals("Error position " + i, (byte)'a', value);
+         // }
+
+         session.commit();
+
+         assertEquals(0l, server.getPostOffice().getPagingManager().getGlobalSize());
+         assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getDeliveringCount());
+         assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getMessageCount());
+
+      }
+      finally
+      {
+         try
+         {
+            session.close();
+         }
+         catch (Throwable ignored)
+         {
+         }
+
+         try
+         {
+            server.stop();
+         }
+         catch (Throwable ignored)
+         {
+         }
+      }
+   }
+
+   /** Receive messages but never reads them, leaving the buffer pending */
+   public void testIgnoreStreaming() throws Exception
+   {
+      ClientSession session = null;
+      MessagingServer server = null;
+
+      final int SIZE = 10 * 1024;
+      final int NUMBER_OF_MESSAGES = 1;
+      try
+      {
+
+         server = createServer(true);
+
+         server.start();
+
+         ClientSessionFactory sf = createInVMFactory();
+
+         sf.setMinLargeMessageSize(1024);
+
+         session = sf.createSession(null, null, false, true, true, false, 0);
+
+         session.createQueue(ADDRESS, ADDRESS, null, true);
+
+         ClientProducer producer = session.createProducer(ADDRESS);
+
+         for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
+         {
+            Message msg = session.createClientMessage(true);
+            msg.setBodyInputStream(createFakeLargeStream(SIZE, (byte)'a'));
+            msg.putIntProperty(new SimpleString("key"), i);
+            producer.send(msg);
+
+            System.out.println("Sent msg " + i);
+         }
+
+         session.start();
+
+         System.out.println("Sending");
+
+         producer.close();
+
+         System.out.println("Waiting");
+
+         ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+         for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
+         {
+            ClientMessage msg = consumer.receive(50000);
+            assertNotNull(msg);
+
+            assertEquals(i, msg.getProperty(new SimpleString("key")));
+
+            msg.acknowledge();
+         }
+
+         consumer.close();
+
+         session.commit();
+
+         assertEquals(0l, server.getPostOffice().getPagingManager().getGlobalSize());
+         assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getDeliveringCount());
+         assertEquals(0, ((Queue)server.getPostOffice().getBinding(ADDRESS).getBindable()).getMessageCount());
+
+         System.out.println("Thread done");
+      }
+      finally
+      {
+         try
+         {
+            session.close();
+         }
+         catch (Throwable ignored)
+         {
+         }
+
+         try
+         {
+            server.stop();
+         }
+         catch (Throwable ignored)
+         {
+         }
+      }
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
@@ -594,22 +933,21 @@
    protected void setUp() throws Exception
    {
       super.setUp();
-      log.info("\n*********************************************************************************\n Starting " + this.getName() +
+      clearData();
+      log.info("\n*********************************************************************************\n Starting " + getName() +
                "\n*********************************************************************************");
    }
 
    @Override
    protected void tearDown() throws Exception
    {
-      log.info("\n*********************************************************************************\nDone with  " + this.getName() +
+      log.info("\n*********************************************************************************\nDone with  " + getName() +
                "\n*********************************************************************************");
       super.tearDown();
    }
 
    protected void testPageOnLargeMessage(final boolean realFiles, final boolean sendBlocking) throws Exception
    {
-      clearData();
-
       Configuration config = createDefaultConfig();
 
       config.setPagingMaxGlobalSizeBytes(20 * 1024);
@@ -666,7 +1004,7 @@
             producer.send(message);
          }
 
-         ClientFileMessage clientFile = createLargeClientMessage(session, numberOfIntegersBigMessage);
+         ClientMessage clientFile = createLargeClientMessage(session, numberOfIntegersBigMessage);
 
          producer.send(clientFile);
 

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -39,79 +39,79 @@
    
    public SimpleString getClusterName()
    {
-      // TODO Auto-generated method stub
+     
       return null;
    }
 
    public BindingType getType()
    {
-      // TODO Auto-generated method stub
+     
       return null;
    }
 
    public int getDistance()
    {
-      // TODO Auto-generated method stub
+     
       return 0;
    }
 
    public SimpleString getOriginatingNodeID()
    {
-      // TODO Auto-generated method stub
+     
       return null;
    }
 
    public Filter getFilter()
    {
-      // TODO Auto-generated method stub
+     
       return null;
    }
 
    public int getID()
    {
-      // TODO Auto-generated method stub
+     
       return 0;
    }
 
    public void setID(int id)
    {
-      // TODO Auto-generated method stub
+     
       
    }
 
    public void willRoute(ServerMessage message)
    {
-      // TODO Auto-generated method stub
+     
       
    }
 
    public boolean filterMatches(ServerMessage message) throws Exception
    {
-      // TODO Auto-generated method stub
+     
       return false;
    }
 
    public boolean isHighAcceptPriority(ServerMessage message)
    {
-      // TODO Auto-generated method stub
+     
       return false;
    }
 
    public SimpleString getRoutingName()
    {
-      // TODO Auto-generated method stub
+     
       return null;
    }
 
    public SimpleString getUniqueName()
    {
-      // TODO Auto-generated method stub
+     
       return null;
    }
 
    public boolean isExclusive()
    {
-      // TODO Auto-generated method stub
+     
       return false;
    }
 

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -49,13 +49,13 @@
 {
    public boolean redistribute(ServerMessage message, SimpleString routingName, Transaction tx) throws Exception
    {
-      // TODO Auto-generated method stub
+     
       return false;
    }
 
    public void sendQueueInfoToQueue(SimpleString queueName, SimpleString address) throws Exception
    {
-      // TODO Auto-generated method stub
+     
       
    }
 

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/soak/chunk/MessageChunkSoakTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/soak/chunk/MessageChunkSoakTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/soak/chunk/MessageChunkSoakTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -49,20 +49,18 @@
 
    public void testMessageChunkFilePersistence1G() throws Exception
    {
-      testChunks(false, 
+      testChunks(false,
                  true,
-                 true,
                  false,
-                 true,
                  false,
-                 2,
-                 268435456,
+                 false,
+                 false,
+                 1,
+                 1024 * 1024 * 1024,
                  300000,
                  0,
                  -1,
-                 ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE,
-                 ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE,
-                 true);
+                 ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    }
 
    // Package protected ---------------------------------------------

Added: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java	                        (rev 0)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/client/impl/LargeMessageBufferTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -0,0 +1,595 @@
+/*
+ * 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.tests.unit.core.client.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jboss.messaging.core.buffers.ChannelBuffer;
+import org.jboss.messaging.core.buffers.ChannelBuffers;
+import org.jboss.messaging.core.client.ClientMessage;
+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.exception.MessagingException;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveMessage;
+import org.jboss.messaging.tests.util.RandomUtil;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ * A LargeMessageBufferUnitTest
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class LargeMessageBufferTest extends UnitTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Test Simple getBytes
+   public void testGetBytes() throws Exception
+   {
+      LargeMessageBuffer buffer = create15BytesSample();
+
+      for (int i = 1; i <= 15; i++)
+      {
+         try
+         {
+            assertEquals(i, buffer.readByte());
+         }
+         catch (Exception e)
+         {
+            throw new Exception("Exception at position " + i, e);
+         }
+      }
+
+      try
+      {
+         buffer.readByte();
+         fail("supposed to throw an exception");
+      }
+      catch (IndexOutOfBoundsException e)
+      {
+      }
+   }
+
+   // Test for void getBytes(final int index, final byte[] dst)
+   public void testGetBytesIByteArray() throws Exception
+   {
+      LargeMessageBuffer buffer = create15BytesSample();
+
+      byte[] bytes = new byte[15];
+      buffer.getBytes(0, bytes);
+
+      validateAgainstSample(bytes);
+
+      try
+      {
+         buffer = create15BytesSample();
+
+         bytes = new byte[16];
+         buffer.getBytes(0, bytes);
+         fail("supposed to throw an exception");
+      }
+      catch (java.lang.IndexOutOfBoundsException e)
+      {
+      }
+   }
+
+   // testing void getBytes(int index, ChannelBuffer dst, int dstIndex, int length)
+   public void testGetBytesILChannelBufferII() throws Exception
+   {
+      LargeMessageBuffer buffer = create15BytesSample();
+
+      ChannelBuffer dstBuffer = ChannelBuffers.buffer(20);
+
+      dstBuffer.setIndex(0, 5);
+
+      buffer.getBytes(0, dstBuffer);
+
+      byte[] compareBytes = new byte[15];
+      dstBuffer.getBytes(5, compareBytes);
+
+      validateAgainstSample(compareBytes);
+   }
+
+   // 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);
+
+      for (int i = 1; i <= 15; i++)
+      {
+         assertEquals(i, buffer.readInt());
+      }
+
+      try
+      {
+         buffer.readByte();
+         fail("supposed to throw an exception");
+      }
+      catch (IndexOutOfBoundsException e)
+      {
+      }
+   }
+
+   // 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);
+
+      for (int i = 1; i <= 15; i++)
+      {
+         assertEquals(i, buffer.readLong());
+      }
+
+      try
+      {
+         buffer.readByte();
+         fail("supposed to throw an exception");
+      }
+      catch (IndexOutOfBoundsException e)
+      {
+      }
+   }
+
+   public void testReadData() throws Exception
+   {
+      ChannelBuffer dynamic = ChannelBuffers.dynamicBuffer(1);
+
+      String str1 = RandomUtil.randomString();
+      String str2 = RandomUtil.randomString();
+      Double d1 = RandomUtil.randomDouble();
+      float f1 = RandomUtil.randomFloat();
+
+      dynamic.writeUTF(str1);
+      dynamic.writeString(str2);
+      dynamic.writeDouble(d1);
+      dynamic.writeFloat(f1);
+
+      LargeMessageBuffer readBuffer = splitBuffer(3, dynamic.array());
+
+      assertEquals(str1, readBuffer.readUTF());
+      assertEquals(str2, readBuffer.readString());
+      assertEquals(d1, readBuffer.readDouble());
+      assertEquals(f1, readBuffer.readFloat());
+   }
+
+   public void testStreamData() throws Exception
+   {
+      final LargeMessageBuffer outBuffer = new LargeMessageBuffer(new FakeConsumerInternal(), 1024 * 11 + 123, 1);
+
+      final PipedOutputStream output = new PipedOutputStream();
+      final PipedInputStream input = new PipedInputStream(output);
+
+      final AtomicInteger errors = new AtomicInteger(0);
+
+      // Done reading 3 elements
+      final CountDownLatch done1 = new CountDownLatch(1);
+      // Done with the thread
+      final CountDownLatch done2 = new CountDownLatch(1);
+
+      final AtomicInteger count = new AtomicInteger(0);
+      final AtomicInteger totalBytes = new AtomicInteger(0);
+
+      Thread treader = new Thread("treader")
+      {
+         public void run()
+         {
+            try
+            {
+
+               byte line[] = new byte[1024];
+               int dataRead = 0;
+               while (dataRead >= 0)
+               {
+                  dataRead = input.read(line);
+                  if (dataRead > 0)
+                  {
+                     System.out.println("Read one line with " + dataRead + " bytes");
+                     totalBytes.addAndGet(dataRead);
+                     if (count.incrementAndGet() == 3)
+                     {
+                        done1.countDown();
+                     }
+                  }
+               }
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+               errors.incrementAndGet();
+            }
+            finally
+            {
+               done1.countDown();
+               done2.countDown();
+            }
+         }
+      };
+
+      treader.setDaemon(true);
+      treader.start();
+
+      for (int i = 0; i < 3; i++)
+      {
+         outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[1024], true, false));
+      }
+
+      outBuffer.setOutputStream(output);
+
+      final CountDownLatch waiting = new CountDownLatch(1);
+
+      Thread twaiter = new Thread("twaiter")
+      {
+         public void run()
+         {
+            try
+            {
+               outBuffer.waitCompletion(0);
+               waiting.countDown();
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+               errors.incrementAndGet();
+            }
+         }
+      };
+
+      twaiter.setDaemon(true);
+      twaiter.start();
+
+      assertTrue(done1.await(10, TimeUnit.SECONDS));
+
+      assertEquals(3, count.get());
+      assertEquals(1024 * 3, totalBytes.get());
+
+      for (int i = 0; i < 8; i++)
+      {
+         outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[1024], true, false));
+      }
+
+      assertEquals(1, waiting.getCount());
+
+      outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, new byte[123], false, false));
+
+      assertTrue(done2.await(10, TimeUnit.SECONDS));
+
+      assertTrue(waiting.await(10, TimeUnit.SECONDS));
+
+      assertEquals(12, count.get());
+      assertEquals(1024 * 11 + 123, totalBytes.get());
+
+      treader.join();
+
+      twaiter.join();
+
+      assertEquals(0, errors.get());
+
+   }
+
+   /**
+    * @return
+    */
+   private LargeMessageBuffer 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
+   {
+      ByteArrayOutputStream byteOut = new ByteArrayOutputStream(values.length * 4);
+      DataOutputStream dataOut = new DataOutputStream(byteOut);
+
+      for (int value : values)
+      {
+         dataOut.writeInt(value);
+      }
+
+      return splitBuffer(splitFactor, byteOut.toByteArray());
+   }
+
+   private LargeMessageBuffer createBufferWithLongs(int splitFactor, long... values) throws Exception
+   {
+      ByteArrayOutputStream byteOut = new ByteArrayOutputStream(values.length * 8);
+      DataOutputStream dataOut = new DataOutputStream(byteOut);
+
+      for (long value : values)
+      {
+         dataOut.writeLong(value);
+      }
+
+      return splitBuffer(splitFactor, byteOut.toByteArray());
+   }
+
+   private LargeMessageBuffer splitBuffer(int splitFactor, byte[] bytes) throws Exception
+   {
+      LargeMessageBuffer outBuffer = new LargeMessageBuffer(new FakeConsumerInternal(), bytes.length, 5);
+
+      ByteArrayInputStream input = new ByteArrayInputStream(bytes);
+
+      while (true)
+      {
+         byte[] splitElement = new byte[splitFactor];
+         int size = input.read(splitElement);
+         if (size <= 0)
+         {
+            break;
+         }
+
+         if (size < splitFactor)
+         {
+            byte[] newSplit = new byte[size];
+            System.arraycopy(splitElement, 0, newSplit, 0, size);
+
+            outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, newSplit, input.available() > 0, false));
+         }
+         else
+         {
+            outBuffer.addPacket(new SessionReceiveContinuationMessage(-1, splitElement, input.available() > 0, false));
+         }
+      }
+
+      return outBuffer;
+
+   }
+
+   /**
+       * @param bytes
+       */
+   private void validateAgainstSample(byte[] bytes)
+   {
+      for (int i = 1; i <= 15; i++)
+      {
+         assertEquals(i, bytes[i - 1]);
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+   static class FakeConsumerInternal implements ClientConsumerInternal
+   {
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#acknowledge(org.jboss.messaging.core.client.ClientMessage)
+       */
+      public void acknowledge(ClientMessage message) throws MessagingException
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#cleanUp()
+       */
+      public void cleanUp() throws MessagingException
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#clear()
+       */
+      public void clear()
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#flowControl(int, boolean)
+       */
+      public void flowControl(int messageBytes, boolean isLargeMessage) throws MessagingException
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#flushAcks()
+       */
+      public void flushAcks() throws MessagingException
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#getBufferSize()
+       */
+      public int getBufferSize()
+      {
+
+         return 0;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#getClientWindowSize()
+       */
+      public int getClientWindowSize()
+      {
+
+         return 0;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#getCreditsToSend()
+       */
+      public int getCreditsToSend()
+      {
+
+         return 0;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#getID()
+       */
+      public long getID()
+      {
+
+         return 0;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#handleLargeMessage(org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveMessage)
+       */
+      public void handleLargeMessage(SessionReceiveMessage largeMessageHeader) throws Exception
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#handleLargeMessageContinuation(org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage)
+       */
+      public void handleLargeMessageContinuation(SessionReceiveContinuationMessage continuation) throws Exception
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#handleMessage(org.jboss.messaging.core.client.impl.ClientMessageInternal)
+       */
+      public void handleMessage(ClientMessageInternal message) throws Exception
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#isFileConsumer()
+       */
+      public boolean isFileConsumer()
+      {
+
+         return false;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#start()
+       */
+      public void start()
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.impl.ClientConsumerInternal#stop()
+       */
+      public void stop() throws MessagingException
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.ClientConsumer#close()
+       */
+      public void close() throws MessagingException
+      {
+
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.ClientConsumer#getLastException()
+       */
+      public Exception getLastException()
+      {
+
+         return null;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.ClientConsumer#getMessageHandler()
+       */
+      public MessageHandler getMessageHandler() throws MessagingException
+      {
+
+         return null;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.ClientConsumer#isClosed()
+       */
+      public boolean isClosed()
+      {
+
+         return false;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.ClientConsumer#receive()
+       */
+      public ClientMessage receive() throws MessagingException
+      {
+
+         return null;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.ClientConsumer#receive(long)
+       */
+      public ClientMessage receive(long timeout) throws MessagingException
+      {
+
+         return null;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.ClientConsumer#receiveImmediate()
+       */
+      public ClientMessage receiveImmediate() throws MessagingException
+      {
+
+         return null;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.client.ClientConsumer#setMessageHandler(org.jboss.messaging.core.client.MessageHandler)
+       */
+      public void setMessageHandler(MessageHandler handler) throws MessagingException
+      {
+
+      }
+
+   }
+
+}

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/postoffice/impl/BindingImplTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -22,6 +22,7 @@
 
 package org.jboss.messaging.tests.unit.core.postoffice.impl;
 
+import java.io.InputStream;
 import java.util.Set;
 
 import javax.transaction.xa.Xid;
@@ -724,6 +725,21 @@
 
       }
 
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.message.Message#getBodyInputStream()
+       */
+      public InputStream getBodyInputStream()
+      {
+         return null;
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.message.Message#setBodyInputStream(java.io.InputStream)
+       */
+      public void setBodyInputStream(InputStream stream)
+      {
+      }
+
    }
 
    class FakeFilter implements Filter

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -46,19 +46,19 @@
 
       public void connectionCreated(Connection connection)
       {
-         // TODO Auto-generated method stub
+        
          
       }
 
       public void connectionDestroyed(Object connectionID)
       {
-         // TODO Auto-generated method stub
+        
          
       }
 
       public void connectionException(Object connectionID, MessagingException me)
       {
-         // TODO Auto-generated method stub
+        
          
       }
       

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeConsumer.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeConsumer.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeConsumer.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -60,7 +60,7 @@
 
    public Filter getFilter()
    {
-      // TODO Auto-generated method stub
+     
       return null;
    }
 

Modified: branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java
===================================================================
--- branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java	2009-04-09 15:30:31 UTC (rev 6381)
+++ branches/Branch_Temp_Clebert_LargeMessage/tests/src/org/jboss/messaging/tests/util/ServiceTestBase.java	2009-04-09 15:36:58 UTC (rev 6382)
@@ -22,7 +22,12 @@
 
 package org.jboss.messaging.tests.util;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
 import java.lang.ref.WeakReference;
 import java.util.HashMap;
 import java.util.Map;
@@ -81,7 +86,7 @@
 
    public static void forceGC()
    {
-      WeakReference dumbReference = new WeakReference(new Object());
+      WeakReference<Object> dumbReference = new WeakReference<Object>(new Object());
       // A loopt that will wait GC, using the minimal time as possible
       while (dumbReference.get() != null)
       {
@@ -367,7 +372,9 @@
       }
       return messageCount;
    }
+   
 
+
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------




More information about the jboss-cvs-commits mailing list