[jboss-cvs] JBoss Messaging SVN: r3827 - in trunk: src/main/org/jboss/messaging/core and 38 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 28 05:54:04 EST 2008


Author: timfox
Date: 2008-02-28 05:54:03 -0500 (Thu, 28 Feb 2008)
New Revision: 3827

Added:
   trunk/src/main/org/jboss/messaging/core/filter/Filter.java
   trunk/src/main/org/jboss/messaging/core/message/
   trunk/src/main/org/jboss/messaging/core/message/Message.java
   trunk/src/main/org/jboss/messaging/core/message/MessageReference.java
   trunk/src/main/org/jboss/messaging/core/message/impl/
   trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java
   trunk/src/main/org/jboss/messaging/core/message/impl/MessageReferenceImpl.java
   trunk/src/main/org/jboss/messaging/core/paging/
   trunk/src/main/org/jboss/messaging/core/paging/PagingManager.java
   trunk/src/main/org/jboss/messaging/core/persistence/PersistenceManager.java
   trunk/src/main/org/jboss/messaging/core/postoffice/
   trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java
   trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingImpl.java
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConsumerDeliverMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ConsumerDeliverMessage.java
   trunk/src/main/org/jboss/messaging/core/transaction/
   trunk/src/main/org/jboss/messaging/core/transaction/ResourceManager.java
   trunk/src/main/org/jboss/messaging/core/transaction/Transaction.java
   trunk/src/main/org/jboss/messaging/core/transaction/TransactionSynchronization.java
   trunk/src/main/org/jboss/messaging/core/transaction/impl/
   trunk/src/main/org/jboss/messaging/core/transaction/impl/ResourceManagerImpl.java
   trunk/src/main/org/jboss/messaging/core/transaction/impl/TransactionImpl.java
   trunk/src/main/org/jboss/messaging/core/transaction/impl/XidImpl.java
Removed:
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/DeliverMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/DeliverMessage.java
   trunk/src/main/org/jboss/messaging/core/server/Binding.java
   trunk/src/main/org/jboss/messaging/core/server/Filter.java
   trunk/src/main/org/jboss/messaging/core/server/Message.java
   trunk/src/main/org/jboss/messaging/core/server/MessageReference.java
   trunk/src/main/org/jboss/messaging/core/server/PagingManager.java
   trunk/src/main/org/jboss/messaging/core/server/PersistenceManager.java
   trunk/src/main/org/jboss/messaging/core/server/PostOffice.java
   trunk/src/main/org/jboss/messaging/core/server/ResourceManager.java
   trunk/src/main/org/jboss/messaging/core/server/Transaction.java
   trunk/src/main/org/jboss/messaging/core/server/TransactionSynchronization.java
   trunk/src/main/org/jboss/messaging/core/server/impl/BindingImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessageImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/PostOfficeImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ResourceManagerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/TransactionImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/XidImpl.java
Modified:
   trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java
   trunk/src/main/org/jboss/messaging/core/client/ClientBrowser.java
   trunk/src/main/org/jboss/messaging/core/client/ClientConsumer.java
   trunk/src/main/org/jboss/messaging/core/client/ClientProducer.java
   trunk/src/main/org/jboss/messaging/core/client/MessageHandler.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientBrowserImpl.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerPacketHandler.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionInternal.java
   trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java
   trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java
   trunk/src/main/org/jboss/messaging/core/management/MessagingServerManagement.java
   trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerManagementImpl.java
   trunk/src/main/org/jboss/messaging/core/persistence/impl/bdbje/BDBJEPersistenceManager.java
   trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullPersistenceManager.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerSendMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserNextMessageBlockResponseMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserNextMessageResponseMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerResponseMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaHandler.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/PacketType.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ProducerSendMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionBrowserNextMessageBlockResponseMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionBrowserNextMessageResponseMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionCreateProducerResponseMessage.java
   trunk/src/main/org/jboss/messaging/core/server/Consumer.java
   trunk/src/main/org/jboss/messaging/core/server/Delivery.java
   trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
   trunk/src/main/org/jboss/messaging/core/server/Queue.java
   trunk/src/main/org/jboss/messaging/core/server/QueueFactory.java
   trunk/src/main/org/jboss/messaging/core/server/ServerProducer.java
   trunk/src/main/org/jboss/messaging/core/server/ServerSession.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ConnectionManagerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/DeliveryImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/QueueFactoryImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerBrowserImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerConnectionImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossMapMessage.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossMessageConsumer.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossObjectMessage.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossQueueBrowser.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java
   trunk/src/main/org/jboss/messaging/jms/client/JBossTextMessage.java
   trunk/src/main/org/jboss/messaging/jms/client/JMSMessageListenerWrapper.java
   trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerManagerImpl.java
   trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/QueueSettingsDeployerTest.java
   trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterTest.java
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java
   trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/integration/DummyInterceptor.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java
   trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java
   trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSL.java
   trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSLTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/concurrent/QueueTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/timing/QueueTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessageTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessagingXidTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/PostOfficeTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/QueueTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/TransactionTest.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeConsumer.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeFilter.java
   trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeQueueFactory.java
   trunk/tests/src/org/jboss/messaging/test/unit/UnitTestCase.java
   trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/XATest.java
   trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCReceiver.java
   trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCSender.java
   trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java
Log:
Moved more core classes around and started flow controller


Modified: trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java
===================================================================
--- trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -23,14 +23,17 @@
 
 import static org.jboss.messaging.core.remoting.TransportType.TCP;
 
-import org.jboss.messaging.core.client.*;
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
-import org.jboss.messaging.core.server.Message;
 import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.messaging.core.server.impl.MessagingServerImpl;
-import org.jboss.messaging.core.version.impl.VersionImpl;
 import org.jboss.messaging.jms.client.JBossTextMessage;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/client/ClientBrowser.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ClientBrowser.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/ClientBrowser.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -7,7 +7,7 @@
 
 package org.jboss.messaging.core.client;
 
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/client/ClientConsumer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ClientConsumer.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/ClientConsumer.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -7,7 +7,7 @@
 
 package org.jboss.messaging.core.client;
 
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**
@@ -16,6 +16,8 @@
  */
 public interface ClientConsumer
 {      
+	Message receive() throws MessagingException;
+	
    Message receive(long timeout) throws MessagingException;
    
    Message receiveImmediate() throws MessagingException;

Modified: trunk/src/main/org/jboss/messaging/core/client/ClientProducer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ClientProducer.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/ClientProducer.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -7,7 +7,7 @@
 
 package org.jboss.messaging.core.client;
 
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/client/MessageHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/MessageHandler.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/MessageHandler.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -21,7 +21,7 @@
    */
 package org.jboss.messaging.core.client;
 
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 
 /**
  * 

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientBrowserImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientBrowserImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientBrowserImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -22,6 +22,7 @@
 package org.jboss.messaging.core.client.impl;
 
 import org.jboss.messaging.core.client.ClientBrowser;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.remoting.impl.wireformat.CloseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserHasNextMessageMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserHasNextMessageResponseMessage;
@@ -30,7 +31,6 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserNextMessageMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserNextMessageResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserResetMessage;
-import org.jboss.messaging.core.server.Message;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -29,10 +29,10 @@
 import org.jboss.messaging.core.list.PriorityLinkedList;
 import org.jboss.messaging.core.list.impl.PriorityLinkedListImpl;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.remoting.impl.wireformat.CloseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerFlowTokenMessage;
-import org.jboss.messaging.core.remoting.impl.wireformat.DeliverMessage;
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerDeliverMessage;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**
@@ -71,7 +71,7 @@
    
    private final int tokenBatchSize;
    
-   private final PriorityLinkedList<DeliverMessage> buffer = new PriorityLinkedListImpl<DeliverMessage>(10);
+   private final PriorityLinkedList<ConsumerDeliverMessage> buffer = new PriorityLinkedListImpl<ConsumerDeliverMessage>(10);
    
    private volatile Thread receiverThread;
    
@@ -153,7 +153,7 @@
                     
             if (!closed && !buffer.isEmpty())
             {                              
-               DeliverMessage m = buffer.removeFirst();
+               ConsumerDeliverMessage m = buffer.removeFirst();
                
                boolean expired = m.getMessage().isExpired();
                
@@ -187,6 +187,11 @@
       }      
    }
 
+   public Message receive() throws MessagingException
+   {
+   	return receive(0);
+   }
+   
    public Message receiveImmediate() throws MessagingException
    {
       return receive(-1);
@@ -263,7 +268,7 @@
       return id;
    }
 
-   public void handleMessage(final DeliverMessage message) throws Exception
+   public void handleMessage(final ConsumerDeliverMessage message) throws Exception
    {
       if (closed)
       {
@@ -418,7 +423,7 @@
    		//ordering. If we just added a Runnable with the message to the executor immediately as we get it
    		//we could not do that
    		
-   		DeliverMessage message;
+   		ConsumerDeliverMessage message;
    		
    		synchronized (this)
    		{

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -7,7 +7,7 @@
 package org.jboss.messaging.core.client.impl;
 
 import org.jboss.messaging.core.client.ClientConsumer;
-import org.jboss.messaging.core.remoting.impl.wireformat.DeliverMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerDeliverMessage;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**
@@ -21,7 +21,7 @@
 {   
    String getID();
    
-   void handleMessage(DeliverMessage message) throws Exception;
+   void handleMessage(ConsumerDeliverMessage message) throws Exception;
    
    void recover(long lastDeliveryID) throws MessagingException;
 }

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerPacketHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerPacketHandler.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerPacketHandler.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -3,7 +3,7 @@
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.PacketHandler;
 import org.jboss.messaging.core.remoting.PacketSender;
-import org.jboss.messaging.core.remoting.impl.wireformat.DeliverMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerDeliverMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.Packet;
 import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
 
@@ -15,7 +15,7 @@
  */
 public class ClientConsumerPacketHandler implements PacketHandler
 {
-   private static final Logger log = Logger.getLogger(ClientConsumerImpl.class);
+   private static final Logger log = Logger.getLogger(ClientConsumerPacketHandler.class);
 
    private final ClientConsumerInternal clientConsumer;
 
@@ -38,12 +38,18 @@
       try
       {
          PacketType type = packet.getType();
-         if (type == PacketType.SESS_DELIVER)
+         
+         if (type == PacketType.CONS_DELIVER)
          {
-            DeliverMessage message = (DeliverMessage) packet;
+            ConsumerDeliverMessage message = (ConsumerDeliverMessage) packet;
             
             clientConsumer.handleMessage(message);
          }
+         else
+         {
+         	throw new IllegalStateException("Invalid packet: " + type);
+         }
+         	
       }
       catch (Exception e)
       {

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -22,10 +22,10 @@
 package org.jboss.messaging.core.client.impl;
 
 import org.jboss.messaging.core.client.AcknowledgementHandler;
-import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.remoting.PacketDispatcher;
 import org.jboss.messaging.core.remoting.impl.wireformat.ProducerSendMessage;
-import org.jboss.messaging.core.server.Message;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**
@@ -38,7 +38,7 @@
  *
  * $Id$
  */
-public class ClientProducerImpl implements ClientProducer
+public class ClientProducerImpl implements ClientProducerInternal
 {
    // Constants ------------------------------------------------------------------------------------
 
@@ -58,12 +58,14 @@
    
    private volatile boolean closed;
    
+   private volatile int availableTokens;
+   
    // Static ---------------------------------------------------------------------------------------
 
    // Constructors ---------------------------------------------------------------------------------
       
    public ClientProducerImpl(final ClientSessionInternal session, final String id, final String address,
-   		                    final RemotingConnection remotingConnection)
+   		                    final RemotingConnection remotingConnection, final int availableTokens)
    {   	
       this.session = session;
       
@@ -72,6 +74,8 @@
       this.address = address;
       
       this.remotingConnection = remotingConnection;
+      
+      this.availableTokens = availableTokens;
    }
    
    // ClientProducer implementation ----------------------------------------------------------------
@@ -85,20 +89,46 @@
    {
       checkClosed();
       
-      ProducerSendMessage message = new ProducerSendMessage(null, msg.copy());
-      
-      remotingConnection.send(id, message, !msg.isDurable());
+      doSend(null, msg);
    }
    
    public void send(final String address, final Message msg) throws MessagingException
    {
       checkClosed();
       
-      ProducerSendMessage message = new ProducerSendMessage(address, msg.copy());
-      
-      remotingConnection.send(id, message, !msg.isDurable());
+      doSend(address, msg);
    }
-         
+   
+   private void doSend(final String address, final Message msg) throws MessagingException
+   {
+   	ProducerSendMessage message = new ProducerSendMessage(address, msg.copy());
+   	
+//   	if (address == null)
+//   	{
+//   		//flow control
+//   		
+//   		//TODO guard against waiting for ever - interrupt the thread???
+//   		
+//   		while (availableTokens == 0)
+//   		{
+//				synchronized (this)
+//				{
+//					try
+//					{						
+//					   wait();						
+//					}
+//					catch (InterruptedException e)
+//					{   						
+//					}
+//				}		
+//   		}
+//   	}
+   	
+   	remotingConnection.send(id, message, !msg.isDurable());
+   	
+   	//availableTokens--;
+   }
+            
    public void registerAcknowledgementHandler(final AcknowledgementHandler handler)
    {
       // TODO      
@@ -117,6 +147,8 @@
       }
       session.removeProducer(this);
       
+      remotingConnection.getPacketDispatcher().unregister(id);
+      
       closed = true;
    }
 
@@ -125,6 +157,15 @@
       return closed;
    }
    
+   // ClientProducerInternal implementation --------------------------------------------------------
+   
+   public synchronized void receiveTokens(int tokens)
+   {
+   	availableTokens += tokens;
+   	
+   	notify();
+   }
+   
    // Public ---------------------------------------------------------------------------------------
 
    // Protected ------------------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -37,6 +37,7 @@
 import org.jboss.messaging.core.client.ClientConsumer;
 import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.PacketDispatcher;
 import org.jboss.messaging.core.remoting.impl.wireformat.AbstractPacket;
 import org.jboss.messaging.core.remoting.impl.wireformat.CloseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerFlowTokenMessage;
@@ -129,7 +130,7 @@
    
    private final Map<String, ClientConsumerInternal> consumers = new HashMap<String, ClientConsumerInternal>();
    
-   private final Map<String, ClientProducer> producerCache;
+   private final Map<String, ClientProducerInternal> producerCache;
    
    //For testing only
    private boolean forceNotSameRM;
@@ -153,7 +154,7 @@
       
       if (cacheProducers)
       {
-      	producerCache = new HashMap<String, ClientProducer>();
+      	producerCache = new HashMap<String, ClientProducerInternal>();
       }
       else
       {
@@ -241,22 +242,15 @@
 
       remotingConnection.getPacketDispatcher().register(new ClientConsumerPacketHandler(consumer, response.getConsumerID()));
 
-      if (prefetchSize > 0) // 0 ==> flow control is disabled
+      if (prefetchSize > 0) 
       {
-         //Now give the server consumer some initial tokens (1.5 * prefetchSize)
+      	//Consumer flow control is enabled so give the server consumer some initial tokens (1.5 * prefetchSize)
          
          int initialTokens = prefetchSize + prefetchSize >>> 1;
          
          remotingConnection.send(response.getConsumerID(), new ConsumerFlowTokenMessage(initialTokens), true);
       }
-      else
-      {
-         //FIXME
-         //FIXME - for now we need to send a flow control token to ensure the return packet sender gets set
-         //FIXME
-         remotingConnection.send(response.getConsumerID(), new ConsumerFlowTokenMessage(1), true);
-      }
-      
+            
       return consumer;
    }
    
@@ -281,7 +275,7 @@
    {
       checkClosed();
       
-      ClientProducer producer = null;
+      ClientProducerInternal producer = null;
       
       if (cacheProducers)
       {
@@ -295,7 +289,10 @@
       	SessionCreateProducerResponseMessage response =
       		(SessionCreateProducerResponseMessage)remotingConnection.send(id, request);
       	
-      	producer = new ClientProducerImpl(this, response.getProducerID(), address, remotingConnection);      	
+      	producer = new ClientProducerImpl(this, response.getProducerID(), address,
+      			                            remotingConnection, response.getInitialTokens());  
+      	
+      	remotingConnection.getPacketDispatcher().register(new ClientProducerPacketHandler(producer, response.getProducerID()));
       }
 
       producers.add(producer);
@@ -384,6 +381,11 @@
          
          if (cacheProducers)
          {
+         	for (ClientProducer producer: producerCache.values())
+         	{
+         		producer.close();
+         	}
+         	
          	producerCache.clear();
          }
          
@@ -393,11 +395,7 @@
          
          remotingConnection.send(id, new CloseMessage());
    
-         executor.shutdownNow();
-         // executor.shutdownNow() makes a best-effort to cancel threads using Thread.interrupt().
-         // we call Thread.interrupted() to reset the thread status.
-         // without this call, JBMESSAGING-542 happens when closing a connection from a message listener.
-         Thread.interrupted();
+         executor.shutdown();
       }
       finally
       {
@@ -449,7 +447,7 @@
       remotingConnection.send(id, new SessionCancelMessage(-1, false));
    }
    
-   public void removeProducer(final ClientProducer producer)
+   public void removeProducer(final ClientProducerInternal producer)
    {
       producers.remove(producer);
       

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionInternal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionInternal.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionInternal.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -7,9 +7,7 @@
 package org.jboss.messaging.core.client.impl;
 
 import org.jboss.messaging.core.client.ClientBrowser;
-import org.jboss.messaging.core.client.ClientProducer;
 import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.server.Message;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**
@@ -31,7 +29,7 @@
    
    void removeConsumer(ClientConsumerInternal consumer) throws MessagingException;
    
-   void removeProducer(ClientProducer producer);
+   void removeProducer(ClientProducerInternal producer);
    
    void removeBrowser(ClientBrowser browser);  
 }

Modified: trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/deployers/impl/QueueSettingsDeployer.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -22,7 +22,7 @@
 package org.jboss.messaging.core.deployers.impl;
 
 import org.jboss.messaging.core.deployers.Deployer;
-import org.jboss.messaging.core.server.PostOffice;
+import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
 import org.jboss.messaging.core.settings.impl.QueueSettings;
 import org.w3c.dom.Node;

Copied: trunk/src/main/org/jboss/messaging/core/filter/Filter.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/Filter.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/filter/Filter.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/filter/Filter.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.filter;
+
+import org.jboss.messaging.core.message.Message;
+
+/**
+ * 
+ * A Filter
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface Filter
+{
+   boolean match(Message message);
+   
+   String getFilterString();
+}

Modified: trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -24,9 +24,9 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/management/MessagingServerManagement.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/MessagingServerManagement.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/management/MessagingServerManagement.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -25,10 +25,10 @@
 import java.util.List;
 
 import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.messagecounter.MessageCounter;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.ServerConnection;
 

Modified: trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerManagementImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerManagementImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerManagementImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -35,13 +35,13 @@
 import org.jboss.aop.microcontainer.aspects.jmx.JMX;
 import org.jboss.messaging.core.client.ClientConnectionFactory;
 import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
 import org.jboss.messaging.core.management.MessagingServerManagement;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.messagecounter.MessageCounter;
-import org.jboss.messaging.core.server.Binding;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.postoffice.Binding;
 import org.jboss.messaging.core.server.MessagingComponent;
 import org.jboss.messaging.core.server.MessagingException;
 import org.jboss.messaging.core.server.MessagingServer;

Copied: trunk/src/main/org/jboss/messaging/core/message/Message.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/Message.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/Message.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/message/Message.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,243 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.message;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.util.Streamable;
+
+/**
+ * A message is a routable instance that has a payload.
+ * 
+ * The payload is opaque to the messaging system.
+ *
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox"jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 3341 $</tt>
+ *
+ * $Id: Message.java 3341 2007-11-19 14:34:57Z timfox $
+ */
+public interface Message extends Streamable
+{
+   public static final String HDR_ACTUAL_EXPIRY_TIME = "JBMActualExpiryTime";
+   
+   /**    
+    * @return The unique id of the message
+    */
+   long getMessageID();
+   
+   /**
+    * Set the message id
+    * 
+    * @param id
+    */
+   void setMessageID(long id);
+
+   /**
+    * @return Whether the message is durable
+    */
+   boolean isDurable();
+   
+   /**
+    * Set whether message is durable
+    * @param reliable
+    */
+   void setDurable(boolean durable);
+   
+   /**
+    * @return the time when this routable expires and must be removed
+    *         from the system. A zero value means this routable never expires.
+    */
+   long getExpiration();
+
+   /**
+    * 
+    * @return true if the message has expired
+    */
+   boolean isExpired();
+   
+   /**
+    * Set the expiration for this message
+    * 
+    * @param expiration
+    */
+   void setExpiration(long expiration);
+   
+   /**
+    * @return the time (in GMT milliseconds) when this routable was delivered to the provider.
+    */
+   long getTimestamp();
+   
+   /**
+    * Set the timestamp for this message
+    * @param timestamp The timestamp
+    */
+   void setTimestamp(long timestamp);
+   
+   /**
+    * 
+    * @return The priority (0-9) of the message
+    */
+   byte getPriority();
+   
+   /**
+    * Get the priority of the message. Priorities range from 0 to 9.
+    * Where 0 is the lowest priority and 9 is the highest priority
+    * @param priority
+    */
+   void setPriority(byte priority);
+
+   /**
+    * Binds a header. If the header map previously contained a mapping for this name, the old value
+    * is replaced by the specified value.
+    *
+    * @return the value associated with the name or null if there is no mapping for the name. A null
+    *         can also indicate that the header map previously associated null with the specified
+    *         name.
+    */
+   Object putHeader(String name, Object value);
+
+   /**
+    * Returns the value corresponding to the header name. Returns null if the map contains no
+    * mapping for the name. A return value of null does not necessarily indicate that the map
+    * contains no mapping for the name; it's also possible that the map explicitly maps the name to
+    * null. The containsHeader() operation may be used to distinguish these two cases.
+    *
+    * @return the value associated with the header, or null if there is no mapping for the header.
+    */
+   Object getHeader(String name);
+
+   /**
+    * Removes the header.
+    *
+    * @return previous value associated with the header, or null if there was no mapping.
+    */
+   Object removeHeader(String name);
+
+   /**
+    * Returns true if the Routable contains the specified header.
+    */
+   boolean containsHeader(String name);
+      
+   /**
+    * 
+    * @return The message's headers
+    */
+   Map<String, Object> getHeaders();
+   
+   /**
+    * 
+    * @return The message's payload
+    */
+   byte[] getPayload();
+   
+   
+   /**
+    * Set the payload
+    * 
+    * @param payload
+    */
+   void setPayload(byte[] payload);
+   
+   /**
+    * 
+    * @return The message's headers as byte array
+    */
+   byte[] getHeaderBytes() throws Exception;
+    
+   /**
+    * 
+    * @return the type of the message
+    */
+   int getType();   
+   
+   /**
+    * 
+    * @return The delivery count of the message - only available on the client side
+    */
+   int getDeliveryCount();
+   
+   /**
+    * Set the delivery count of the message
+    * @param count
+    */
+   void setDeliveryCount(int count);
+   
+   /**
+    * Get the connection id
+    * @return
+    */
+   String getConnectionID();
+   
+   /**
+    * Set the connection id
+    * @param connectionID
+    */
+   void setConnectionID(String connectionID);
+   
+   
+   /**
+    * @return a reference for this message
+    */
+   MessageReference createReference(Queue queue);   
+   
+   /**
+    * 
+    * @return List of persisted references for this message
+    */
+   List<MessageReference> getReferences();
+   
+   /**
+    * 
+    * @return The number of durable references for this message
+    */
+   int getNumDurableReferences();
+   
+   /**
+    * 
+    * @param reference durable from the specified position
+    * @param pos
+    */
+   void removeDurableReference(MessageReference reference, int pos) throws Exception;
+   
+   /**
+    * 
+    * @param reference
+    * @return The position of the reference over all durable references
+    */
+   int getDurableReferencePos(MessageReference reference);
+   
+   void addBackDurableReference(MessageReference ref);
+
+   
+   /**
+    * Make a copy of the message
+    * 
+    * @return The copy
+    */
+   Message copy();   
+   
+   void send() throws Exception;
+   
+}

Copied: trunk/src/main/org/jboss/messaging/core/message/MessageReference.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/MessageReference.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/MessageReference.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/message/MessageReference.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,73 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.message;
+
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.server.Queue;
+
+/**
+ * A reference to a message.
+ * 
+ * Channels store message references rather than the messages themselves.
+ * 
+ * If many channels have contain the same reference this makes a lot of sense
+ * 
+ * @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: 3020 $</tt>
+ *
+ * $Id: MessageReference.java 3020 2007-08-21 15:46:38Z timfox $
+ */
+public interface MessageReference
+{      
+   Message getMessage();
+   
+   MessageReference copy(Queue queue);
+   
+   /**
+    * 
+    * @return The time in the future that delivery will be delayed until, or zero if
+    * no scheduled delivery will occur
+    */
+   long getScheduledDeliveryTime();
+   
+   void setScheduledDeliveryTime(long scheduledDeliveryTime);
+   
+   /**
+    * @return the number of times delivery has been attempted for this routable
+    */
+   int getDeliveryCount();
+   
+   void setDeliveryCount(int deliveryCount);        
+   
+   void incrementDeliveryCount();
+   
+   Queue getQueue();
+   
+   void acknowledge(PersistenceManager persistenceManager) throws Exception;  
+   
+   boolean cancel(PersistenceManager persistenceManager) throws Exception;  
+   
+   void expire(PersistenceManager persistenceManager) throws Exception;
+}
+
+

Copied: trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/impl/MessageImpl.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,495 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.message.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Semaphore;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.util.StreamUtils;
+
+/**
+ * A concrete implementation of a message
+ * 
+ * All messages handled by JBM core are of this type
+ * 
+ * @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: 2740 $</tt>
+ * 
+ * For normal message transportation serialization is not used
+ * 
+ * $Id: MessageSupport.java 2740 2007-05-30 11:36:28Z timfox $
+ */
+public class MessageImpl implements Message
+{
+   // Constants -----------------------------------------------------
+   
+   private static final Logger log = Logger.getLogger(MessageImpl.class);
+
+   // Attributes ----------------------------------------------------
+
+   private long messageID;
+   
+   private int type;
+   
+   private boolean durable;
+
+   /** GMT milliseconds at which this message expires. 0 means never expires * */
+   private long expiration;
+
+   private long timestamp;
+
+   private Map<String, Object> headers;
+   
+   private byte priority;
+
+   //The payload of MessageImpl instances is opaque
+   private byte[] payload;
+   
+   //We keep track of the persisted references for this message
+   private final List<MessageReference> references = new ArrayList<MessageReference>();
+   
+   private String connectionID;
+   
+   private volatile int numDurableReferences;
+   
+   private int deliveryCount;
+   
+   /*
+    * We use a semaphore of size 1, i.e. a mutex to synchronize access to the refs rather than
+    * use the synchronized keyword since java.util.Semaphore uses compareAndSet to maintain the semaphore
+    * i.e. no locking which should give better performance under high contention
+    */
+   private Semaphore refsLock = new Semaphore(1);
+   
+   // Constructors --------------------------------------------------
+
+   /*
+    * Construct a message for deserialization or streaming
+    */
+   public MessageImpl()
+   {
+      this.headers = new HashMap<String, Object>();
+   }
+
+   /*
+    * Construct a message before sending
+    */
+   public MessageImpl(final int type, final boolean durable, final long expiration,
+                      final long timestamp, final byte priority)
+   {
+      this();
+      this.type = type;
+      this.durable = durable;
+      this.expiration = expiration;
+      this.timestamp = timestamp;
+      this.priority = priority;            
+   }
+
+   /*
+    * Construct a MessageImpl from storage
+    */
+   public MessageImpl(final long messageID, final int type, final boolean durable, final long expiration,
+                      final long timestamp, final byte priority, final byte[] headers, final byte[] payload)
+      throws Exception
+   {
+      this.messageID = messageID;
+      this.type = type;
+      this.durable = durable;
+      this.expiration = expiration;
+      this.timestamp = timestamp;
+      this.priority = priority;
+      
+      if (headers == null)
+      {
+         this.headers = new HashMap<String, Object>();
+      }
+      else
+      {
+         //TODO keep headers opaque on server
+         ByteArrayInputStream bis = new ByteArrayInputStream(headers);
+
+         DataInputStream dais = new DataInputStream(bis);
+
+         this.headers = StreamUtils.readMap(dais, true);
+
+         dais.close();
+      }
+      this.payload = payload;
+   }
+   
+   /**
+    * Copy constructor
+    * 
+    * @param other
+    */
+   public MessageImpl(final MessageImpl other)
+   {
+      this.messageID = other.messageID;
+      this.type = other.type;
+      this.durable = other.durable;
+      this.expiration = other.expiration;
+      this.timestamp = other.timestamp;
+      this.priority = other.priority;
+      this.headers = new HashMap<String, Object>(other.headers);
+      this.payload = other.payload;
+   }
+   
+   // Message implementation ----------------------------------------
+
+   public long getMessageID()
+   {
+      return messageID;
+   }
+   
+   public void setMessageID(final long id)
+   {
+      this.messageID = id;
+   }
+   
+   public int getType()
+   {
+      return type;
+   }
+
+   public boolean isDurable()
+   {
+      return durable;
+   }
+   
+   public void setDurable(final boolean durable)
+   {
+      this.durable = durable;
+   }
+
+   public long getExpiration()
+   {
+      return expiration;
+   }
+
+   public void setExpiration(final long expiration)
+   {
+      this.expiration = expiration;
+   }
+
+   public long getTimestamp()
+   {
+      return timestamp;
+   }
+   
+   public void setTimestamp(final long timestamp)
+   {
+      this.timestamp = timestamp;
+   }
+
+   public Object putHeader(final String name, final Object value)
+   {
+      return headers.put(name, value);
+   }
+
+   public Object getHeader(final String name)
+   {
+      return headers.get(name);
+   }
+
+   public Object removeHeader(final String name)
+   {
+      return headers.remove(name);
+   }
+
+   public boolean containsHeader(final String name)
+   {
+      return headers.containsKey(name);
+   }
+
+   public Map<String, Object> getHeaders()
+   {
+      return headers;
+   }
+
+   public byte getPriority()
+   {
+      return priority;
+   }
+
+   public void setPriority(final byte priority)
+   {
+      this.priority = priority;
+   }
+
+   // TODO - combine with getPayloadAsByteArray to get one big blob
+   public byte[] getHeaderBytes() throws Exception
+   {
+      ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
+
+      DataOutputStream oos = new DataOutputStream(bos);
+
+      StreamUtils.writeMap(oos, headers, true);
+
+      oos.close();
+
+      return bos.toByteArray();
+   }
+         
+   public byte[] getPayload()
+   {     
+      return payload;
+   }
+   
+   public void setPayload(final byte[] payload)
+   {
+      this.payload = payload;
+   }
+   
+   public String getConnectionID()
+   {
+      return connectionID;
+   }
+   
+   public void setConnectionID(final String connectionID)
+   {
+      this.connectionID = connectionID;
+   }
+   
+   public void setDeliveryCount(final int deliveryCount)
+   {
+      this.deliveryCount = deliveryCount;
+   }
+   
+   public int getDeliveryCount()
+   {
+      return this.deliveryCount;
+   }
+
+   public boolean isExpired()
+   {
+      if (expiration == 0)
+      {
+         return false;
+      }
+      
+      return System.currentTimeMillis() - expiration >= 0;
+   }
+   
+   public MessageReference createReference(final Queue queue)
+   {
+      MessageReference ref = new MessageReferenceImpl(this, queue);
+      
+      references.add(ref);
+      
+      if (durable && queue.isDurable())
+      {
+         numDurableReferences++;
+      }
+      
+      return ref;
+   }
+   
+   public int getNumDurableReferences()
+   {
+      return numDurableReferences;
+   }
+   
+   public List<MessageReference> getReferences()
+   {
+      return references;
+   }
+   
+   public void removeDurableReference(final MessageReference reference, final int pos) throws Exception
+   {
+      refsLock.acquire();
+      
+      try
+      {      
+         references.remove(pos);
+               
+         numDurableReferences--;                     
+      }
+      finally
+      {
+         refsLock.release();
+      }
+   }
+   
+   //TODO optimise to avoid scan
+   public int getDurableReferencePos(final MessageReference reference)
+   {
+      int pos = 0;
+      
+      for (MessageReference ref: references)
+      {
+         if (ref == reference)
+         {
+            break;
+         }
+         
+         if (ref.getQueue().isDurable())
+         {
+            pos++;
+         }         
+      }
+      
+      return pos;
+   }
+   
+   public void addBackDurableReference(final MessageReference reference)
+   {
+      references.add(reference);
+      
+      numDurableReferences++;
+   }
+   
+   public Message copy()
+   {
+      return new MessageImpl(this);
+   }
+
+   public void send() throws Exception
+   {
+      refsLock.acquire();
+      
+      try
+      {      
+         for (MessageReference ref: references)
+         {
+            ref.getQueue().addLast(ref);
+         }
+      }
+      finally
+      {
+         refsLock.release();
+      }
+   }
+    
+   // Public --------------------------------------------------------
+
+   public boolean equals(Object o)
+   {
+      if (this == o)
+      {
+         return true;
+      }
+      
+      if (!(o instanceof MessageImpl))
+      {
+         return false;
+      }
+      
+      MessageImpl that = (MessageImpl) o;
+      
+      return that.messageID == this.messageID;
+   }
+
+   public int hashCode()
+   {
+      return (int) ((this.messageID >>> 32) ^ this.messageID);
+   }
+
+   public String toString()
+   {
+      return "M[" + messageID + "]@" + System.identityHashCode(this);
+   }
+
+   // Streamable implementation ---------------------------------
+
+   public void write(final DataOutputStream out) throws Exception
+   {
+      out.writeLong(messageID);
+      
+      out.writeInt(type);
+
+      out.writeBoolean(durable);
+
+      out.writeLong(expiration);
+
+      out.writeLong(timestamp);
+
+      StreamUtils.writeMap(out, headers, true);
+
+      out.writeByte(priority);
+      
+      out.writeInt(deliveryCount);
+
+      if (payload != null)
+      {
+         out.writeInt(payload.length);
+
+         out.write(payload);
+      }
+      else
+      {
+         out.writeInt(0);
+      }
+   }
+
+   public void read(final DataInputStream in) throws Exception
+   {
+      messageID = in.readLong();
+      
+      type = in.readInt();
+
+      durable = in.readBoolean();
+
+      expiration = in.readLong();
+
+      timestamp = in.readLong();
+
+      headers = StreamUtils.readMap(in, true);
+
+      priority = in.readByte();
+
+      deliveryCount = in.readInt();
+      
+      int length = in.readInt();
+
+      if (length == 0)
+      {
+         // no payload
+         payload = null;
+      }
+      else
+      {
+         payload = new byte[length];
+
+         in.readFully(payload);
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------  
+}

Copied: trunk/src/main/org/jboss/messaging/core/message/impl/MessageReferenceImpl.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/impl/MessageReferenceImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/message/impl/MessageReferenceImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,247 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.message.impl;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.transaction.impl.TransactionImpl;
+
+/**
+ * Implementation of a MessageReference
+ *
+ * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
+ * @version <tt>1.3</tt>
+ *
+ * MessageReferenceImpl.java,v 1.3 2006/02/23 17:45:57 timfox Exp
+ */
+public class MessageReferenceImpl implements MessageReference
+{   
+   private static final Logger log = Logger.getLogger(MessageReferenceImpl.class);
+   
+   // Attributes ----------------------------------------------------
+
+   private boolean trace = log.isTraceEnabled();
+   
+   private volatile int deliveryCount;   
+   
+   private long scheduledDeliveryTime;
+   
+   private Message message;
+   
+   private Queue queue;
+   
+   // Constructors --------------------------------------------------
+
+   public MessageReferenceImpl()
+   {
+   }
+
+   public MessageReferenceImpl(final MessageReferenceImpl other, final Queue queue)
+   {
+      this.deliveryCount = other.deliveryCount;
+      
+      this.scheduledDeliveryTime = other.scheduledDeliveryTime;       
+      
+      this.message = other.message;
+      
+      this.queue = queue;
+   }
+   
+   protected MessageReferenceImpl(final Message message, final Queue queue)
+   {
+   	this.message = message;
+   	
+   	this.queue = queue;
+   }   
+   
+   // MessageReference implementation -------------------------------
+   
+   public MessageReference copy(final Queue queue)
+   {
+   	return new MessageReferenceImpl(this, queue);
+   }
+   
+   public int getDeliveryCount()
+   {
+      return deliveryCount;
+   }
+   
+   public void setDeliveryCount(final int deliveryCount)
+   {
+      this.deliveryCount = deliveryCount;
+   }
+   
+   public void incrementDeliveryCount()
+   {
+      deliveryCount++;
+   }
+   
+   public long getScheduledDeliveryTime()
+   {
+      return scheduledDeliveryTime;
+   }
+
+   public void setScheduledDeliveryTime(final long scheduledDeliveryTime)
+   {
+      this.scheduledDeliveryTime = scheduledDeliveryTime;
+   }
+      
+   public Message getMessage()
+   {
+      return message;
+   }         
+   
+   public Queue getQueue()
+   {
+      return queue;
+   }
+   
+   public void acknowledge(final PersistenceManager persistenceManager) throws Exception
+   {
+      if (message.isDurable())
+      {
+         persistenceManager.deleteReference(this);
+      }
+      
+      queue.decrementDeliveringCount();
+   }
+   
+   public boolean cancel(final PersistenceManager persistenceManager) throws Exception
+   {      
+      if (message.isDurable() && queue.isDurable())
+      {
+         persistenceManager.updateDeliveryCount(queue, this);
+      }
+              
+      queue.decrementDeliveringCount();
+
+      int maxDeliveries = queue.getQueueSettings().getMatch(queue.getName()).getMaxDeliveryAttempts();
+      
+      if (maxDeliveries > 0 && deliveryCount >= maxDeliveries)
+      {
+      	
+      	
+         Queue DLQ = queue.getQueueSettings().getMatch(queue.getName()).getDLQ();
+         
+         if (DLQ != null)
+         {
+            Message copyMessage = makeCopyForDLQOrExpiry(false, persistenceManager);
+            
+            moveInTransaction(DLQ, copyMessage, persistenceManager);
+         }
+         else
+         {
+            //No DLQ
+            
+            log.warn("Message has reached maximum delivery attempts, no DLQ is configured so dropping it");
+            
+            acknowledge(persistenceManager);
+         }       
+         
+         return false;
+      }
+      else
+      {
+         return true;
+      }
+   }
+   
+   public void expire(final PersistenceManager persistenceManager) throws Exception
+   {
+      Queue expiryQueue = queue.getQueueSettings().getMatch(queue.getName()).getExpiryQueue();
+      if (expiryQueue != null)
+      {
+         Message copyMessage = makeCopyForDLQOrExpiry(false, persistenceManager);
+         
+         moveInTransaction(expiryQueue, copyMessage, persistenceManager);
+      }
+      else
+      {
+         log.warn("Message has expired, no expiry queue is configured so dropping it");
+         
+         acknowledge(persistenceManager);
+      }
+   }
+         
+   // Public --------------------------------------------------------
+
+   public String toString()
+   {
+      return "Reference[" + getMessage().getMessageID() + "]:" + (getMessage().isDurable() ? "RELIABLE" : "NON-RELIABLE");
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------   
+   
+   // Private -------------------------------------------------------
+   
+   private void moveInTransaction(final Queue destinationQueue, final Message copyMessage,
+                                  final PersistenceManager persistenceManager) throws Exception
+   {
+      copyMessage.createReference(destinationQueue);
+      
+      TransactionImpl tx = new TransactionImpl();
+      
+      tx.addMessage(copyMessage);
+      
+      tx.addAcknowledgement(this);
+      
+      tx.commit(true, persistenceManager);
+   }
+   
+   private Message makeCopyForDLQOrExpiry(final boolean expiry, final PersistenceManager pm) throws Exception
+   {
+      /*
+       We copy the message and send that to the dlq/expiry queue - this is
+       because otherwise we may end up with a ref with the same message id in the
+       queue more than once which would barf - this might happen if the same message had been
+       expire from multiple subscriptions of a topic for example
+       We set headers that hold the original message destination, expiry time
+       and original message id
+      */
+
+      Message copy = message.copy();
+      
+      long newMessageId = pm.generateMessageID();
+      
+      copy.setMessageID(newMessageId);
+      
+      // reset expiry
+      copy.setExpiration(0);
+      
+      if (expiry)
+      {
+         long actualExpiryTime = System.currentTimeMillis();
+      
+         copy.putHeader(Message.HDR_ACTUAL_EXPIRY_TIME, actualExpiryTime);
+      }
+      
+      return copy;
+   }
+
+   // Inner classes -------------------------------------------------
+   
+}
\ No newline at end of file

Copied: trunk/src/main/org/jboss/messaging/core/paging/PagingManager.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/PagingManager.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/paging/PagingManager.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/paging/PagingManager.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,19 @@
+package org.jboss.messaging.core.paging;
+
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.server.MessagingComponent;
+import org.jboss.messaging.core.server.Queue;
+
+/**
+ * 
+ * A PagingManager
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface PagingManager extends MessagingComponent
+{
+   void pageReference(Queue queue, MessageReference ref);
+   
+   MessageReference depageReference(Queue queue);
+}

Copied: trunk/src/main/org/jboss/messaging/core/persistence/PersistenceManager.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/PersistenceManager.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/PersistenceManager.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/persistence/PersistenceManager.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,170 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.persistence;
+
+import java.util.List;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.server.MessagingComponent;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.QueueFactory;
+
+/**
+ * 
+ * A PersistenceManager
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface PersistenceManager extends MessagingComponent
+{
+   // Operations for maintaining message state
+   // ========================================
+   
+   /**
+    * Generate a new message id - unique per store
+    * @return The new message id
+    */
+   public long generateMessageID();
+   
+   /**
+    * A single message, possible with many message references needs to be added to storage
+    * This would occur when a single reliable messages arrives on the server and needs to be routed
+    * to 1 or more queues.
+    * @param message
+    */
+   public void addMessage(Message message) throws Exception;
+   
+   /**
+    * Delete a single reference. This would also delete the message if it is no longer referenced by any other
+    * references.
+    * This would occur on acknowledgement of a single reference
+    * @param message
+    */
+   void deleteReference(MessageReference reference) throws Exception;
+      
+   /**
+    * Commit a transaction containing messages to add and references to remove
+    * @param messagesToAdd List of messages to add, or null if none
+    * @param referencesToRemove List of references to remove, or null if none
+    * @throws Exception
+    */
+   public void commitTransaction(List<Message> messagesToAdd, List<MessageReference> referencesToRemove) throws Exception;
+   
+   /**
+    * Prepare a transaction containing messages to add and references to remove
+    * @param xid The Xid of the XA transaction
+    * @param messagesToAdd List of messages to add, or null if none
+    * @param referencesToRemove List of references to remove, or null if none
+    * @throws Exception
+    */
+   public void prepareTransaction(Xid xid, List<Message> messagesToAdd,
+                                  List<MessageReference> referencesToRemove) throws Exception;
+   
+   /**
+    * Commit a prepared transaction
+    * 
+    * @param xid
+    * @throws Exception
+    */
+   public void commitPreparedTransaction(Xid xid) throws Exception;
+   
+   
+   /**
+    * Unprepare a transaction containing messages to add and references to remove
+    * @param xid The Xid of the XA transaction
+    * @param messagesToAdd List of messages to add, or null if none
+    * @param referencesToRemove List of references to remove, or null if none
+    * @throws Exception
+    */
+   public void unprepareTransaction(Xid xid, List<Message> messagesToAdd,
+                                    List<MessageReference> referencesToRemove) throws Exception;
+   
+
+   /**
+    * Update the delivery count of a reference
+    * @param queue
+    * @param ref
+    * @throws Exception
+    */
+   void updateDeliveryCount(Queue queue, MessageReference ref) throws Exception;
+   
+   /**
+    * Deletes all references from storage for the specifie Queue
+    * @param queue
+    * @throws Exception
+    */
+   void deleteAllReferences(Queue queue) throws Exception;
+   
+  
+   // Recovery related operations
+   // ===========================
+   
+   /**
+    * Get a list of in doubt (prepared) transaction ids
+    * Can only be called in recovery mode
+    * @return the list of ids
+    */
+   List<Xid> getInDoubtXids() throws Exception;
+   
+   /**
+    * 
+    * @return true if the PersistenceManager is in recovery mode
+    */
+   boolean isInRecoveryMode() throws Exception;
+   
+   /**
+    * 
+    * @param recoveryMode Set the PersistenceManager in recovery mode
+    */
+   void setInRecoveryMode(boolean recoveryMode);
+   
+   // Operations for maintaining post office state
+   // ============================================
+   
+   /**
+    * Load the bindings from the store to populate the post office at startup
+    * @param QueueFactory The factory used to create the queues
+    * @return List of bindings
+    * @throws Exception
+    */
+   List<Binding> loadBindings(QueueFactory queueFactory) throws Exception;
+   
+   /**
+    * Add a binding into the store
+    * @param binding The binding to add
+    * @throws Exception
+    */
+   void addBinding(Binding binding) throws Exception;
+   
+   /**
+    * Delete a binding from the store
+    * @param binding The binding to delete
+    * @throws Exception
+    */
+   void deleteBinding(Binding binding) throws Exception;
+    
+}

Modified: trunk/src/main/org/jboss/messaging/core/persistence/impl/bdbje/BDBJEPersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/impl/bdbje/BDBJEPersistenceManager.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/bdbje/BDBJEPersistenceManager.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -34,17 +34,17 @@
 
 import javax.transaction.xa.Xid;
 
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
 import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Binding;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.PersistenceManager;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.postoffice.impl.BindingImpl;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
-import org.jboss.messaging.core.server.impl.BindingImpl;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.messaging.util.Pair;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullPersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullPersistenceManager.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullPersistenceManager.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -23,10 +23,10 @@
 
 import javax.transaction.xa.Xid;
 
-import org.jboss.messaging.core.server.Binding;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.PersistenceManager;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.postoffice.Binding;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
 

Copied: trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/Binding.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,41 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.postoffice;
+
+import org.jboss.messaging.core.server.Queue;
+
+
+/**
+ * 
+ * A Binding
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface Binding
+{
+   int getNodeID();
+   
+   String getAddress();
+   
+   Queue getQueue();
+}

Copied: trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/PostOffice.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,75 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.postoffice;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.server.MessagingComponent;
+
+/**
+ * 
+ * A PostOffice instance maintains a mapping of a String address to a Queue. Multiple Queue instances can be bound
+ * with the same String address.
+ * 
+ * Given a message and an address a PostOffice instance will route that message to all the Queue instances that are
+ * registered with that address.
+ * 
+ * Addresses can be any String instance.
+ * 
+ * A Queue instance can only be bound against a single address in the post office.
+ * 
+ * The PostOffice also maintains a set of "allowable addresses". These are the addresses that it is legal to
+ * route to.
+ *  
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface PostOffice extends MessagingComponent
+{   
+   void addAllowableAddress(String address);
+   
+   boolean removeAllowableAddress(String address);
+   
+   boolean containsAllowableAddress(String address);
+
+   Binding addBinding(String address, String queueName, Filter filter,
+                      boolean durable, boolean temporary) throws Exception;
+   
+   Binding removeBinding(String queueName) throws Exception;
+   
+   List<Binding> getBindingsForAddress(String address) throws Exception;
+   
+   Binding getBinding(String queueName) throws Exception;
+      
+   void route(String address, Message message) throws Exception;
+   
+   void routeFromCluster(String address, Message message) throws Exception;
+     
+   //For testing only
+   Map<String, List<Binding>> getMappings();
+
+   Set<String> listAvailableAddresses();
+}

Copied: trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingImpl.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/impl/BindingImpl.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,97 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.postoffice.impl;
+
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.server.Queue;
+
+/**
+ * 
+ * A BindingImpl
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class BindingImpl implements Binding
+{
+   private final int nodeID;
+   
+   private final String address;
+   
+   private final Queue queue;
+   
+   private boolean hashAssigned;
+   
+   private int hash;
+      
+   public BindingImpl(final int nodeID, final String address, final Queue queue)
+   {
+      this.nodeID = nodeID;
+      
+      this.address = address;
+      
+      this.queue = queue;
+   }
+   
+   public String getAddress()
+   {
+      return address;
+   }
+
+   public int getNodeID()
+   {
+      return nodeID;
+   }
+
+   public Queue getQueue()
+   {
+      return queue;
+   }
+
+   public boolean equals(Object other)
+   {
+      if (this == other)
+      {
+         return true;
+      }
+      Binding bother = (Binding)other;
+      
+      return (this.nodeID == bother.getNodeID()) &&
+              this.address.equals(bother.getAddress()) &&
+              this.queue.equals(bother.getQueue());
+   }
+   
+   public int hashCode()
+   {
+      if (!hashAssigned)
+      {
+         hash = 17;
+         hash = 37 * hash + nodeID;
+         hash = 37 * hash + address.hashCode();
+         hash = 37 * hash + queue.hashCode();
+                
+         hashAssigned = true;
+      }
+
+      return hash;
+   }
+}

Copied: trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/impl/PostOfficeImpl.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,329 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.postoffice.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.postoffice.PostOffice;
+import org.jboss.messaging.core.server.MessagingException;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.server.QueueFactory;
+import org.jboss.messaging.util.ConcurrentHashSet;
+
+/**
+ * 
+ * A PostOfficeImpl
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class PostOfficeImpl implements PostOffice
+{  
+   private static final Logger log = Logger.getLogger(PostOfficeImpl.class);
+   
+   private final int nodeID;
+   
+   private final ConcurrentMap<String, List<Binding>> mappings = new ConcurrentHashMap<String, List<Binding>>();
+   
+   private final Set<String> allowableAddresses = new ConcurrentHashSet<String>();
+   
+   private final ConcurrentMap<String, Binding> nameMap = new ConcurrentHashMap<String, Binding>();
+   
+   private final PersistenceManager persistenceManager;
+   
+   private final QueueFactory queueFactory;
+   
+   private final boolean checkAllowable;
+    
+   public PostOfficeImpl(final int nodeID, final PersistenceManager persistenceManager,
+   		                final QueueFactory queueFactory, final boolean checkAllowable)
+   {
+      this.nodeID = nodeID;
+      
+      this.persistenceManager = persistenceManager;
+      
+      this.queueFactory = queueFactory;
+      
+      this.checkAllowable = checkAllowable;
+   }
+      
+   // MessagingComponent implementation ---------------------------------------
+   
+   public void start() throws Exception
+   {
+      loadBindings();
+   }
+
+   public void stop() throws Exception
+   {
+      mappings.clear();
+      
+      allowableAddresses.clear();
+   }
+   
+   // PostOffice implementation -----------------------------------------------
+
+   public void addAllowableAddress(final String address)
+   {      
+      allowableAddresses.add(address);
+   }
+   
+   public boolean removeAllowableAddress(final String address)
+   {      
+      return allowableAddresses.remove(address);
+   }
+   
+   public boolean containsAllowableAddress(final String address)
+   {
+      return allowableAddresses.contains(address);
+   }
+
+
+   public Set<String> listAvailableAddresses()
+   {
+      return allowableAddresses;
+   }
+
+   public Binding addBinding(final String address, final String queueName, final Filter filter, 
+                             final boolean durable, final boolean temporary) throws Exception
+   {
+      Binding binding = createBinding(address, queueName, filter, durable, temporary);
+
+      addBindingInMemory(binding);
+      
+      if (durable)
+      {
+         persistenceManager.addBinding(binding);
+      }
+      
+      return binding;      
+   }
+         
+   public Binding removeBinding(final String queueName) throws Exception
+   {
+      Binding binding = removeQueueInMemory(queueName);
+      
+      if (binding.getQueue().isDurable())
+      {
+         persistenceManager.deleteBinding(binding);
+      }
+      
+      return binding;
+   }
+   
+   public List<Binding> getBindingsForAddress(final String address)
+   {
+      List<Binding> list = new ArrayList<Binding>();
+      
+      List<Binding> bindings = mappings.get(address);
+      
+      if (bindings != null)
+      {
+         for (Binding binding: bindings)
+         {
+            if (binding.getNodeID() == nodeID)
+            {
+               list.add(binding);
+            }
+         }
+      }         
+         
+      return list;
+   }
+   
+   public Binding getBinding(final String queueName)
+   {
+      return nameMap.get(queueName);
+   }
+         
+   public void route(final String address, final Message message) throws Exception
+   {
+     // boolean routeRemote = false;
+      
+      if (checkAllowable)
+      {
+         if (!allowableAddresses.contains(address))
+         {
+            throw new MessagingException(MessagingException.ADDRESS_DOES_NOT_EXIST,
+                                         "Cannot route to address " + address);
+         }
+      }
+           
+      List<Binding> bindings = mappings.get(address);
+      
+      if (bindings != null)
+      {
+         for (Binding binding: bindings)
+         {
+            Queue queue = binding.getQueue();
+            
+            if (queue.getFilter() == null || queue.getFilter().match(message))
+            {         
+               if (binding.getNodeID() == nodeID)
+               {
+                  //Local queue
+                                 
+                  message.createReference(queue);              
+               }
+               else
+               {
+//                  if (!queue.isDurable())
+//                  {
+//                     //Remote queue - we never route to remote durable queues since we will lose atomicity in event
+//                     //of crash - for moving between durable queues we use message redistribution
+//                     
+//                     routeRemote = true;                  
+//                  }               
+               }
+            }
+         }
+      }
+
+      
+//      if (routeRemote)
+//      {
+//         tx.addSynchronization(new CastMessageCallback(new MessageRequest(address, message)));
+//      }
+   }
+   
+   public void routeFromCluster(final String address, final Message message) throws Exception
+   {     
+      List<Binding> bindings = mappings.get(address);
+      
+      for (Binding binding: bindings)
+      {
+         Queue queue = binding.getQueue();
+         
+         if (binding.getNodeID() == nodeID)
+         {         
+            if (queue.getFilter() == null || queue.getFilter().match(message))
+            {         
+               MessageReference ref = message.createReference(queue);
+
+               //We never route durably from other nodes - so no need to persist
+
+               queue.addLast(ref);             
+            }
+         }
+      }
+   }
+
+   public Map<String, List<Binding>> getMappings()
+   {
+      return mappings;
+   }
+
+
+
+   // Private -----------------------------------------------------------------
+   
+   private Binding createBinding(final String address, final String name, final Filter filter,
+                                 final boolean durable, final boolean temporary)
+   {
+      Queue queue = queueFactory.createQueue(-1, name, filter, durable, temporary);
+      
+      Binding binding = new BindingImpl(this.nodeID, address, queue);
+      
+      return binding;
+   }
+   
+   private void addBindingInMemory(final Binding binding)
+   {              
+      List<Binding> bindings = new CopyOnWriteArrayList<Binding>();
+      
+      List<Binding> prevBindings = mappings.putIfAbsent(binding.getAddress(), bindings);
+      
+      if (prevBindings != null)
+      {
+         bindings = prevBindings;
+      }
+                     
+      bindings.add(binding);  
+
+      if (nameMap.putIfAbsent(binding.getQueue().getName(), binding) != null)
+      {
+         throw new IllegalStateException("Binding already exists " + binding);
+      }     
+   }
+   
+   private Binding removeQueueInMemory(final String queueName) throws Exception
+   {
+      Binding binding = nameMap.remove(queueName);
+      
+      if (binding == null)
+      {
+         throw new IllegalStateException("Queue is not bound " + queueName);
+      }
+                  
+      List<Binding> bindings = mappings.get(binding.getAddress());
+                  
+      for (Iterator<Binding> iter = bindings.iterator(); iter.hasNext();)
+      {
+         Binding b = iter.next();
+         
+         if (b.getQueue().getName().equals(queueName))
+         {
+            binding = b;
+                                          
+            break;
+         }
+      }
+      
+      if (binding == null)
+      {
+         throw new IllegalStateException("Cannot find binding " + queueName);
+      }
+      
+      bindings.remove(binding);      
+      
+      if (bindings.isEmpty())
+      {
+         mappings.remove(binding.getAddress());
+      }
+               
+      return binding;
+   }
+   
+   private void loadBindings() throws Exception
+   {
+      List<Binding> bindings = persistenceManager.loadBindings(queueFactory);
+      
+      for (Binding binding: bindings)
+      {
+         addBindingInMemory(binding);                    
+      }
+   }
+
+}

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -18,7 +18,7 @@
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.impl.wireformat.AbstractPacket;
 import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.

Copied: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConsumerDeliverMessageCodec.java (from rev 3806, trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/DeliverMessageCodec.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConsumerDeliverMessageCodec.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConsumerDeliverMessageCodec.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.impl.codec;
+
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONS_DELIVER;
+
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerDeliverMessage;
+import org.jboss.messaging.util.StreamUtils;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
+ */
+public class ConsumerDeliverMessageCodec extends AbstractPacketCodec<ConsumerDeliverMessage>
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public ConsumerDeliverMessageCodec()
+   {
+      super(CONS_DELIVER);
+   }
+
+   // Public --------------------------------------------------------
+
+   // AbstractPacketCodec overrides ---------------------------------
+
+   @Override
+   protected void encodeBody(ConsumerDeliverMessage message, RemotingBuffer out) throws Exception
+   {
+      byte[] encodedMsg = StreamUtils.toBytes(message.getMessage());
+      long deliveryID = message.getDeliveryID();
+
+      int bodyLength = encodedMsg.length
+            + LONG_LENGTH + INT_LENGTH;
+      out.putInt(bodyLength);
+
+      out.putInt(encodedMsg.length);
+      out.put(encodedMsg);
+      out.putLong(deliveryID);
+   }
+
+   @Override
+   protected ConsumerDeliverMessage decodeBody(RemotingBuffer in)
+         throws Exception
+   {
+      int bodyLength = in.getInt();
+      if (in.remaining() < bodyLength)
+      {
+         return null;
+      }
+
+      int msgLength = in.getInt();
+      byte[] encodedMsg = new byte[msgLength];
+      in.get(encodedMsg);
+      Message message = new MessageImpl();
+      StreamUtils.fromBytes(message, encodedMsg);
+      long deliveryID = in.getLong();
+
+      return new ConsumerDeliverMessage(message, deliveryID);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private ----------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Deleted: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/DeliverMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/DeliverMessageCodec.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/DeliverMessageCodec.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,80 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.impl.codec;
-
-import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_DELIVER;
-
-import org.jboss.messaging.core.remoting.impl.wireformat.DeliverMessage;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.impl.MessageImpl;
-import org.jboss.messaging.util.StreamUtils;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class DeliverMessageCodec extends AbstractPacketCodec<DeliverMessage>
-{
-   // Constants -----------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   public DeliverMessageCodec()
-   {
-      super(SESS_DELIVER);
-   }
-
-   // Public --------------------------------------------------------
-
-   // AbstractPacketCodec overrides ---------------------------------
-
-   @Override
-   protected void encodeBody(DeliverMessage message, RemotingBuffer out) throws Exception
-   {
-      byte[] encodedMsg = StreamUtils.toBytes(message.getMessage());
-      long deliveryID = message.getDeliveryID();
-
-      int bodyLength = encodedMsg.length
-            + LONG_LENGTH + INT_LENGTH;
-      out.putInt(bodyLength);
-
-      out.putInt(encodedMsg.length);
-      out.put(encodedMsg);
-      out.putLong(deliveryID);
-   }
-
-   @Override
-   protected DeliverMessage decodeBody(RemotingBuffer in)
-         throws Exception
-   {
-      int bodyLength = in.getInt();
-      if (in.remaining() < bodyLength)
-      {
-         return null;
-      }
-
-      int msgLength = in.getInt();
-      byte[] encodedMsg = new byte[msgLength];
-      in.get(encodedMsg);
-      Message message = new MessageImpl();
-      StreamUtils.fromBytes(message, encodedMsg);
-      long deliveryID = in.getLong();
-
-      return new DeliverMessage(message, deliveryID);
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private ----------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-}

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerSendMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerSendMessageCodec.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerSendMessageCodec.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -8,9 +8,9 @@
 
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PROD_SEND;
 
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.remoting.impl.wireformat.ProducerSendMessage;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.messaging.util.StreamUtils;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserNextMessageBlockResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserNextMessageBlockResponseMessageCodec.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserNextMessageBlockResponseMessageCodec.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -13,9 +13,9 @@
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserNextMessageBlockResponseMessage;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserNextMessageResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserNextMessageResponseMessageCodec.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserNextMessageResponseMessageCodec.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -8,9 +8,9 @@
 
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BROWSER_NEXTMESSAGE_RESP;
 
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserNextMessageResponseMessage;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.messaging.util.StreamUtils;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerResponseMessageCodec.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerResponseMessageCodec.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -43,10 +43,11 @@
    {
       String producerID = response.getProducerID();
 
-      int bodyLength = sizeof(producerID);
+      int bodyLength = sizeof(producerID) + INT_LENGTH;
        
       out.putInt(bodyLength);
       out.putNullableString(producerID);
+      out.putInt(response.getInitialTokens());
    }
 
    @Override
@@ -60,8 +61,9 @@
       }
 
       String producerID = in.getNullableString();
+      int initialTokens = in.getInt();
  
-      return new SessionCreateProducerResponseMessage(producerID);
+      return new SessionCreateProducerResponseMessage(producerID, initialTokens);
    }
 
    // Package protected ---------------------------------------------

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaHandler.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaHandler.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -97,7 +97,10 @@
          throw new IllegalArgumentException("Unknown message type: " + message);
       }
 
+      
+      
       AbstractPacket packet = (AbstractPacket) message;
+
       PacketSender sender = new PacketSender()
       {
          public void send(Packet p) throws Exception

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -14,13 +14,14 @@
 import org.jboss.messaging.core.remoting.impl.codec.BytesPacketCodec;
 import org.jboss.messaging.core.remoting.impl.codec.ConnectionCreateSessionMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.ConnectionCreateSessionResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.ConsumerDeliverMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.ConsumerFlowTokenMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.CreateConnectionMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.CreateConnectionResponseMessageCodec;
-import org.jboss.messaging.core.remoting.impl.codec.DeliverMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.MessagingExceptionMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.PingCodec;
 import org.jboss.messaging.core.remoting.impl.codec.PongCodec;
+import org.jboss.messaging.core.remoting.impl.codec.ProducerReceiveTokensMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.ProducerSendMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.RemotingBuffer;
 import org.jboss.messaging.core.remoting.impl.codec.SessionAcknowledgeMessageCodec;
@@ -64,15 +65,16 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionStartMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionStopMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerDeliverMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerFlowTokenMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionRequest;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionResponse;
-import org.jboss.messaging.core.remoting.impl.wireformat.DeliverMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.MessagingExceptionMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.NullPacket;
 import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
 import org.jboss.messaging.core.remoting.impl.wireformat.Ping;
 import org.jboss.messaging.core.remoting.impl.wireformat.Pong;
+import org.jboss.messaging.core.remoting.impl.wireformat.ProducerReceiveTokensMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ProducerSendMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionAcknowledgeMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionAddAddressMessage;
@@ -177,7 +179,7 @@
 
       addCodec(ConsumerFlowTokenMessage.class, ConsumerFlowTokenMessageCodec.class);
 
-      addCodec(DeliverMessage.class, DeliverMessageCodec.class);
+      addCodec(ConsumerDeliverMessage.class, ConsumerDeliverMessageCodec.class);
 
       addCodec(SessionAcknowledgeMessage.class,
             SessionAcknowledgeMessageCodec.class);
@@ -264,6 +266,8 @@
       addCodec(SessionDeleteQueueMessage.class, SessionDeleteQueueMessageCodec.class);
       
       addCodec(ProducerSendMessage.class, ProducerSendMessageCodec.class);
+      
+      addCodec(ProducerReceiveTokensMessage.class, ProducerReceiveTokensMessageCodec.class);
 
    }
 

Copied: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ConsumerDeliverMessage.java (from rev 3806, trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/DeliverMessage.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ConsumerDeliverMessage.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ConsumerDeliverMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.impl.wireformat;
+
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONS_DELIVER;
+
+import org.jboss.messaging.core.message.Message;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class ConsumerDeliverMessage extends AbstractPacket
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private final Message message;
+
+   private final long deliveryID;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public ConsumerDeliverMessage(final Message message, final long deliveryID)
+   {
+      super(CONS_DELIVER);
+
+      assert message != null;
+
+      this.message = message;
+      this.deliveryID = deliveryID;
+   }
+
+   // Public --------------------------------------------------------
+
+   public Message getMessage()
+   {
+      return message;
+   }
+
+   public long getDeliveryID()
+   {
+      return deliveryID;
+   }
+
+   @Override
+   public String toString()
+   {
+      StringBuffer buf = new StringBuffer(getParentString());
+      buf.append(", message=" + message);
+      buf.append(", deliveryID=" + deliveryID);   
+      buf.append("]");
+      return buf.toString();
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Deleted: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/DeliverMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/DeliverMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/DeliverMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,73 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.impl.wireformat;
-
-import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_DELIVER;
-
-import org.jboss.messaging.core.server.Message;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * 
- * @version <tt>$Revision$</tt>
- */
-public class DeliverMessage extends AbstractPacket
-{
-   // Constants -----------------------------------------------------
-
-   // Attributes ----------------------------------------------------
-
-   private final Message message;
-
-   private final long deliveryID;
-
-   // Static --------------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   public DeliverMessage(final Message message, final long deliveryID)
-   {
-      super(SESS_DELIVER);
-
-      assert message != null;
-
-      this.message = message;
-      this.deliveryID = deliveryID;
-   }
-
-   // Public --------------------------------------------------------
-
-   public Message getMessage()
-   {
-      return message;
-   }
-
-   public long getDeliveryID()
-   {
-      return deliveryID;
-   }
-
-   @Override
-   public String toString()
-   {
-      StringBuffer buf = new StringBuffer(getParentString());
-      buf.append(", message=" + message);
-      buf.append(", deliveryID=" + deliveryID);   
-      buf.append("]");
-      return buf.toString();
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-}

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/PacketType.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/PacketType.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/PacketType.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -35,55 +35,56 @@
    CONN_STOP                           ((byte)33),
 
    // Session   
-   SESS_CREATECONSUMER                 ((byte)41),
-   SESS_CREATECONSUMER_RESP            ((byte)42),
-   SESS_CREATEPRODUCER                 ((byte)43),
-   SESS_CREATEPRODUCER_RESP            ((byte)44),
-   SESS_CREATEBROWSER                  ((byte)45),
-   SESS_CREATEBROWSER_RESP             ((byte)46),   
-   SESS_DELIVER                        ((byte)47),  
-   SESS_ACKNOWLEDGE                    ((byte)48),
-   SESS_RECOVER                        ((byte)49),
-   SESS_COMMIT                         ((byte)50),
-   SESS_ROLLBACK                       ((byte)51),
-   SESS_CANCEL                         ((byte)52),
-   SESS_QUEUEQUERY                     ((byte)53),
-   SESS_QUEUEQUERY_RESP                ((byte)54),
-   SESS_CREATEQUEUE                    ((byte)55),
-   SESS_DELETE_QUEUE                   ((byte)56),   
-   SESS_ADD_ADDRESS                    ((byte)57),
-   SESS_REMOVE_ADDRESS                 ((byte)58),
-   SESS_BINDINGQUERY                   ((byte)59),
-   SESS_BINDINGQUERY_RESP              ((byte)60),  
-   SESS_BROWSER_RESET                  ((byte)61),
-   SESS_BROWSER_HASNEXTMESSAGE         ((byte)62),
-   SESS_BROWSER_HASNEXTMESSAGE_RESP    ((byte)63),
-   SESS_BROWSER_NEXTMESSAGEBLOCK       ((byte)64),
-   SESS_BROWSER_NEXTMESSAGEBLOCK_RESP  ((byte)65),
-   SESS_BROWSER_NEXTMESSAGE            ((byte)66),
-   SESS_BROWSER_NEXTMESSAGE_RESP       ((byte)67),      
-   SESS_XA_START                       ((byte)68),
-   SESS_XA_END                         ((byte)69),
-   SESS_XA_COMMIT                      ((byte)70),
-   SESS_XA_PREPARE                     ((byte)71),
-   SESS_XA_RESP                        ((byte)72),
-   SESS_XA_ROLLBACK                    ((byte)73),
-   SESS_XA_JOIN                        ((byte)74),
-   SESS_XA_SUSPEND                     ((byte)75),
-   SESS_XA_RESUME                      ((byte)76),
-   SESS_XA_FORGET                      ((byte)77),
-   SESS_XA_INDOUBT_XIDS                ((byte)78),
-   SESS_XA_INDOUBT_XIDS_RESP           ((byte)79),
-   SESS_XA_SET_TIMEOUT                 ((byte)80),
-   SESS_XA_SET_TIMEOUT_RESP            ((byte)81),
-   SESS_XA_GET_TIMEOUT                 ((byte)82),
-   SESS_XA_GET_TIMEOUT_RESP            ((byte)83),
+   SESS_CREATECONSUMER                 ((byte)40),
+   SESS_CREATECONSUMER_RESP            ((byte)41),
+   SESS_CREATEPRODUCER                 ((byte)42),
+   SESS_CREATEPRODUCER_RESP            ((byte)43),
+   SESS_CREATEBROWSER                  ((byte)44),
+   SESS_CREATEBROWSER_RESP             ((byte)45),      
+   SESS_ACKNOWLEDGE                    ((byte)46),
+   SESS_RECOVER                        ((byte)47),
+   SESS_COMMIT                         ((byte)48),
+   SESS_ROLLBACK                       ((byte)49),
+   SESS_CANCEL                         ((byte)50),
+   SESS_QUEUEQUERY                     ((byte)51),
+   SESS_QUEUEQUERY_RESP                ((byte)52),
+   SESS_CREATEQUEUE                    ((byte)53),
+   SESS_DELETE_QUEUE                   ((byte)54),   
+   SESS_ADD_ADDRESS                    ((byte)55),
+   SESS_REMOVE_ADDRESS                 ((byte)56),
+   SESS_BINDINGQUERY                   ((byte)57),
+   SESS_BINDINGQUERY_RESP              ((byte)58),  
+   SESS_BROWSER_RESET                  ((byte)59),
+   SESS_BROWSER_HASNEXTMESSAGE         ((byte)60),
+   SESS_BROWSER_HASNEXTMESSAGE_RESP    ((byte)61),
+   SESS_BROWSER_NEXTMESSAGEBLOCK       ((byte)62),
+   SESS_BROWSER_NEXTMESSAGEBLOCK_RESP  ((byte)63),
+   SESS_BROWSER_NEXTMESSAGE            ((byte)64),
+   SESS_BROWSER_NEXTMESSAGE_RESP       ((byte)65),      
+   SESS_XA_START                       ((byte)66),
+   SESS_XA_END                         ((byte)67),
+   SESS_XA_COMMIT                      ((byte)68),
+   SESS_XA_PREPARE                     ((byte)69),
+   SESS_XA_RESP                        ((byte)70),
+   SESS_XA_ROLLBACK                    ((byte)71),
+   SESS_XA_JOIN                        ((byte)72),
+   SESS_XA_SUSPEND                     ((byte)73),
+   SESS_XA_RESUME                      ((byte)74),
+   SESS_XA_FORGET                      ((byte)75),
+   SESS_XA_INDOUBT_XIDS                ((byte)76),
+   SESS_XA_INDOUBT_XIDS_RESP           ((byte)77),
+   SESS_XA_SET_TIMEOUT                 ((byte)78),
+   SESS_XA_SET_TIMEOUT_RESP            ((byte)79),
+   SESS_XA_GET_TIMEOUT                 ((byte)80),
+   SESS_XA_GET_TIMEOUT_RESP            ((byte)81),
        
    // Consumer 
    CONS_FLOWTOKEN                      ((byte)90),
+   CONS_DELIVER                        ((byte)91),
    
    //Producer
-   PROD_SEND                           ((byte)91);
+   PROD_SEND                           ((byte)100),
+   PROD_RECEIVETOKENS                  ((byte)101);
    
 
    private final byte type;

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ProducerSendMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ProducerSendMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ProducerSendMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -8,7 +8,7 @@
 
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PROD_SEND;
 
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionBrowserNextMessageBlockResponseMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionBrowserNextMessageBlockResponseMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionBrowserNextMessageBlockResponseMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -10,7 +10,7 @@
 
 import java.util.Arrays;
 
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionBrowserNextMessageResponseMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionBrowserNextMessageResponseMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionBrowserNextMessageResponseMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -6,7 +6,7 @@
  */
 package org.jboss.messaging.core.remoting.impl.wireformat;
 
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionCreateProducerResponseMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionCreateProducerResponseMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/SessionCreateProducerResponseMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -21,16 +21,20 @@
    // Attributes ----------------------------------------------------
 
    private final String producerID;
+   
+   private final int initialTokens;
 
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
 
-   public SessionCreateProducerResponseMessage(final String producerID)
+   public SessionCreateProducerResponseMessage(final String producerID, final int initialTokens)
    {
       super(SESS_CREATEPRODUCER_RESP);
 
       this.producerID = producerID;
+      
+      this.initialTokens = initialTokens;
    }
 
    // Public --------------------------------------------------------
@@ -39,12 +43,18 @@
    {
       return producerID;
    }
+   
+   public int getInitialTokens()
+   {
+   	return initialTokens;
+   }
 
    @Override
    public String toString()
    {
       StringBuffer buf = new StringBuffer(getParentString());
       buf.append(", producerID=" + producerID);
+      buf.append(", initialTokens=" + initialTokens);
       buf.append("]");
       return buf.toString();
    }

Deleted: trunk/src/main/org/jboss/messaging/core/server/Binding.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Binding.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/Binding.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,39 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.messaging.core.server;
-
-
-/**
- * 
- * A Binding
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public interface Binding
-{
-   int getNodeID();
-   
-   String getAddress();
-   
-   Queue getQueue();
-}

Modified: trunk/src/main/org/jboss/messaging/core/server/Consumer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Consumer.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/Consumer.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -21,7 +21,9 @@
   */
 package org.jboss.messaging.core.server;
 
+import org.jboss.messaging.core.message.MessageReference;
 
+
 /**
  * 
  * A ClientConsumer

Modified: trunk/src/main/org/jboss/messaging/core/server/Delivery.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Delivery.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/Delivery.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -21,6 +21,8 @@
   */
 package org.jboss.messaging.core.server;
 
+import org.jboss.messaging.core.message.MessageReference;
+
 /**
  * 
  * A Delivery

Deleted: trunk/src/main/org/jboss/messaging/core/server/Filter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Filter.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/Filter.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.server;
-
-/**
- * 
- * A Filter
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public interface Filter
-{
-   boolean match(Message message);
-   
-   String getFilterString();
-}

Deleted: trunk/src/main/org/jboss/messaging/core/server/Message.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Message.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/Message.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,242 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.messaging.core.server;
-
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.messaging.util.Streamable;
-
-/**
- * A message is a routable instance that has a payload.
- * 
- * The payload is opaque to the messaging system.
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox"jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 3341 $</tt>
- *
- * $Id: Message.java 3341 2007-11-19 14:34:57Z timfox $
- */
-public interface Message extends Streamable
-{
-   public static final String HDR_ACTUAL_EXPIRY_TIME = "JBMActualExpiryTime";
-   
-   /**    
-    * @return The unique id of the message
-    */
-   long getMessageID();
-   
-   /**
-    * Set the message id
-    * 
-    * @param id
-    */
-   void setMessageID(long id);
-
-   /**
-    * @return Whether the message is durable
-    */
-   boolean isDurable();
-   
-   /**
-    * Set whether message is durable
-    * @param reliable
-    */
-   void setDurable(boolean durable);
-   
-   /**
-    * @return the time when this routable expires and must be removed
-    *         from the system. A zero value means this routable never expires.
-    */
-   long getExpiration();
-
-   /**
-    * 
-    * @return true if the message has expired
-    */
-   boolean isExpired();
-   
-   /**
-    * Set the expiration for this message
-    * 
-    * @param expiration
-    */
-   void setExpiration(long expiration);
-   
-   /**
-    * @return the time (in GMT milliseconds) when this routable was delivered to the provider.
-    */
-   long getTimestamp();
-   
-   /**
-    * Set the timestamp for this message
-    * @param timestamp The timestamp
-    */
-   void setTimestamp(long timestamp);
-   
-   /**
-    * 
-    * @return The priority (0-9) of the message
-    */
-   byte getPriority();
-   
-   /**
-    * Get the priority of the message. Priorities range from 0 to 9.
-    * Where 0 is the lowest priority and 9 is the highest priority
-    * @param priority
-    */
-   void setPriority(byte priority);
-
-   /**
-    * Binds a header. If the header map previously contained a mapping for this name, the old value
-    * is replaced by the specified value.
-    *
-    * @return the value associated with the name or null if there is no mapping for the name. A null
-    *         can also indicate that the header map previously associated null with the specified
-    *         name.
-    */
-   Object putHeader(String name, Object value);
-
-   /**
-    * Returns the value corresponding to the header name. Returns null if the map contains no
-    * mapping for the name. A return value of null does not necessarily indicate that the map
-    * contains no mapping for the name; it's also possible that the map explicitly maps the name to
-    * null. The containsHeader() operation may be used to distinguish these two cases.
-    *
-    * @return the value associated with the header, or null if there is no mapping for the header.
-    */
-   Object getHeader(String name);
-
-   /**
-    * Removes the header.
-    *
-    * @return previous value associated with the header, or null if there was no mapping.
-    */
-   Object removeHeader(String name);
-
-   /**
-    * Returns true if the Routable contains the specified header.
-    */
-   boolean containsHeader(String name);
-      
-   /**
-    * 
-    * @return The message's headers
-    */
-   Map<String, Object> getHeaders();
-   
-   /**
-    * 
-    * @return The message's payload
-    */
-   byte[] getPayload();
-   
-   
-   /**
-    * Set the payload
-    * 
-    * @param payload
-    */
-   void setPayload(byte[] payload);
-   
-   /**
-    * 
-    * @return The message's headers as byte array
-    */
-   byte[] getHeaderBytes() throws Exception;
-    
-   /**
-    * 
-    * @return the type of the message
-    */
-   int getType();   
-   
-   /**
-    * 
-    * @return The delivery count of the message - only available on the client side
-    */
-   int getDeliveryCount();
-   
-   /**
-    * Set the delivery count of the message
-    * @param count
-    */
-   void setDeliveryCount(int count);
-   
-   /**
-    * Get the connection id
-    * @return
-    */
-   String getConnectionID();
-   
-   /**
-    * Set the connection id
-    * @param connectionID
-    */
-   void setConnectionID(String connectionID);
-   
-   
-   /**
-    * @return a reference for this message
-    */
-   MessageReference createReference(Queue queue);   
-   
-   /**
-    * 
-    * @return List of persisted references for this message
-    */
-   List<MessageReference> getReferences();
-   
-   /**
-    * 
-    * @return The number of durable references for this message
-    */
-   int getNumDurableReferences();
-   
-   /**
-    * 
-    * @param reference durable from the specified position
-    * @param pos
-    */
-   void removeDurableReference(MessageReference reference, int pos) throws Exception;
-   
-   /**
-    * 
-    * @param reference
-    * @return The position of the reference over all durable references
-    */
-   int getDurableReferencePos(MessageReference reference);
-   
-   void addBackDurableReference(MessageReference ref);
-
-   
-   /**
-    * Make a copy of the message
-    * 
-    * @return The copy
-    */
-   Message copy();   
-   
-   void send() throws Exception;
-   
-}

Deleted: trunk/src/main/org/jboss/messaging/core/server/MessageReference.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/MessageReference.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/MessageReference.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,70 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.messaging.core.server;
-
-/**
- * A reference to a message.
- * 
- * Channels store message references rather than the messages themselves.
- * 
- * If many channels have contain the same reference this makes a lot of sense
- * 
- * @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: 3020 $</tt>
- *
- * $Id: MessageReference.java 3020 2007-08-21 15:46:38Z timfox $
- */
-public interface MessageReference
-{      
-   Message getMessage();
-   
-   MessageReference copy(Queue queue);
-   
-   /**
-    * 
-    * @return The time in the future that delivery will be delayed until, or zero if
-    * no scheduled delivery will occur
-    */
-   long getScheduledDeliveryTime();
-   
-   void setScheduledDeliveryTime(long scheduledDeliveryTime);
-   
-   /**
-    * @return the number of times delivery has been attempted for this routable
-    */
-   int getDeliveryCount();
-   
-   void setDeliveryCount(int deliveryCount);        
-   
-   void incrementDeliveryCount();
-   
-   Queue getQueue();
-   
-   void acknowledge(PersistenceManager persistenceManager) throws Exception;  
-   
-   boolean cancel(PersistenceManager persistenceManager) throws Exception;  
-   
-   void expire(PersistenceManager persistenceManager) throws Exception;
-}
-
-

Modified: trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -23,6 +23,8 @@
 
 import java.util.HashSet;
 
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.remoting.RemotingService;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionResponse;
 import org.jboss.messaging.core.security.Role;
@@ -31,6 +33,7 @@
 import org.jboss.messaging.core.settings.impl.QueueSettings;
 import org.jboss.messaging.core.version.Version;
 import org.jboss.messaging.core.deployers.DeploymentManager;
+import org.jboss.messaging.core.filter.Filter;
 
 /**
  * This interface defines the internal interface of the Messaging Server exposed

Deleted: trunk/src/main/org/jboss/messaging/core/server/PagingManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/PagingManager.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/PagingManager.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,15 +0,0 @@
-package org.jboss.messaging.core.server;
-
-/**
- * 
- * A PagingManager
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public interface PagingManager extends MessagingComponent
-{
-   void pageReference(Queue queue, MessageReference ref);
-   
-   MessageReference depageReference(Queue queue);
-}

Deleted: trunk/src/main/org/jboss/messaging/core/server/PersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/PersistenceManager.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/PersistenceManager.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,163 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.messaging.core.server;
-
-import java.util.List;
-
-import javax.transaction.xa.Xid;
-
-/**
- * 
- * A PersistenceManager
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public interface PersistenceManager extends MessagingComponent
-{
-   // Operations for maintaining message state
-   // ========================================
-   
-   /**
-    * Generate a new message id - unique per store
-    * @return The new message id
-    */
-   public long generateMessageID();
-   
-   /**
-    * A single message, possible with many message references needs to be added to storage
-    * This would occur when a single reliable messages arrives on the server and needs to be routed
-    * to 1 or more queues.
-    * @param message
-    */
-   public void addMessage(Message message) throws Exception;
-   
-   /**
-    * Delete a single reference. This would also delete the message if it is no longer referenced by any other
-    * references.
-    * This would occur on acknowledgement of a single reference
-    * @param message
-    */
-   void deleteReference(MessageReference reference) throws Exception;
-      
-   /**
-    * Commit a transaction containing messages to add and references to remove
-    * @param messagesToAdd List of messages to add, or null if none
-    * @param referencesToRemove List of references to remove, or null if none
-    * @throws Exception
-    */
-   public void commitTransaction(List<Message> messagesToAdd, List<MessageReference> referencesToRemove) throws Exception;
-   
-   /**
-    * Prepare a transaction containing messages to add and references to remove
-    * @param xid The Xid of the XA transaction
-    * @param messagesToAdd List of messages to add, or null if none
-    * @param referencesToRemove List of references to remove, or null if none
-    * @throws Exception
-    */
-   public void prepareTransaction(Xid xid, List<Message> messagesToAdd,
-                                  List<MessageReference> referencesToRemove) throws Exception;
-   
-   /**
-    * Commit a prepared transaction
-    * 
-    * @param xid
-    * @throws Exception
-    */
-   public void commitPreparedTransaction(Xid xid) throws Exception;
-   
-   
-   /**
-    * Unprepare a transaction containing messages to add and references to remove
-    * @param xid The Xid of the XA transaction
-    * @param messagesToAdd List of messages to add, or null if none
-    * @param referencesToRemove List of references to remove, or null if none
-    * @throws Exception
-    */
-   public void unprepareTransaction(Xid xid, List<Message> messagesToAdd,
-                                    List<MessageReference> referencesToRemove) throws Exception;
-   
-
-   /**
-    * Update the delivery count of a reference
-    * @param queue
-    * @param ref
-    * @throws Exception
-    */
-   void updateDeliveryCount(Queue queue, MessageReference ref) throws Exception;
-   
-   /**
-    * Deletes all references from storage for the specifie Queue
-    * @param queue
-    * @throws Exception
-    */
-   void deleteAllReferences(Queue queue) throws Exception;
-   
-  
-   // Recovery related operations
-   // ===========================
-   
-   /**
-    * Get a list of in doubt (prepared) transaction ids
-    * Can only be called in recovery mode
-    * @return the list of ids
-    */
-   List<Xid> getInDoubtXids() throws Exception;
-   
-   /**
-    * 
-    * @return true if the PersistenceManager is in recovery mode
-    */
-   boolean isInRecoveryMode() throws Exception;
-   
-   /**
-    * 
-    * @param recoveryMode Set the PersistenceManager in recovery mode
-    */
-   void setInRecoveryMode(boolean recoveryMode);
-   
-   // Operations for maintaining post office state
-   // ============================================
-   
-   /**
-    * Load the bindings from the store to populate the post office at startup
-    * @param QueueFactory The factory used to create the queues
-    * @return List of bindings
-    * @throws Exception
-    */
-   List<Binding> loadBindings(QueueFactory queueFactory) throws Exception;
-   
-   /**
-    * Add a binding into the store
-    * @param binding The binding to add
-    * @throws Exception
-    */
-   void addBinding(Binding binding) throws Exception;
-   
-   /**
-    * Delete a binding from the store
-    * @param binding The binding to delete
-    * @throws Exception
-    */
-   void deleteBinding(Binding binding) throws Exception;
-    
-}

Deleted: trunk/src/main/org/jboss/messaging/core/server/PostOffice.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/PostOffice.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/PostOffice.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,71 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.messaging.core.server;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * 
- * A PostOffice instance maintains a mapping of a String address to a Queue. Multiple Queue instances can be bound
- * with the same String address.
- * 
- * Given a message and an address a PostOffice instance will route that message to all the Queue instances that are
- * registered with that address.
- * 
- * Addresses can be any String instance.
- * 
- * A Queue instance can only be bound against a single address in the post office.
- * 
- * The PostOffice also maintains a set of "allowable addresses". These are the addresses that it is legal to
- * route to.
- *  
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public interface PostOffice extends MessagingComponent
-{   
-   void addAllowableAddress(String address);
-   
-   boolean removeAllowableAddress(String address);
-   
-   boolean containsAllowableAddress(String address);
-
-   Binding addBinding(String address, String queueName, Filter filter,
-                      boolean durable, boolean temporary) throws Exception;
-   
-   Binding removeBinding(String queueName) throws Exception;
-   
-   List<Binding> getBindingsForAddress(String address) throws Exception;
-   
-   Binding getBinding(String queueName) throws Exception;
-      
-   void route(String address, Message message) throws Exception;
-   
-   void routeFromCluster(String address, Message message) throws Exception;
-     
-   //For testing only
-   Map<String, List<Binding>> getMappings();
-
-   Set<String> listAvailableAddresses();
-}

Modified: trunk/src/main/org/jboss/messaging/core/server/Queue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Queue.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/Queue.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -21,7 +21,9 @@
   */
 package org.jboss.messaging.core.server;
 
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
 import org.jboss.messaging.core.settings.impl.QueueSettings;
 

Modified: trunk/src/main/org/jboss/messaging/core/server/QueueFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/QueueFactory.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/QueueFactory.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -21,8 +21,10 @@
   */
 package org.jboss.messaging.core.server;
 
+import org.jboss.messaging.core.filter.Filter;
 
 
+
 /**
  * 
  * A QueueFactory

Deleted: trunk/src/main/org/jboss/messaging/core/server/ResourceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/ResourceManager.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/ResourceManager.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.server;
-
-import javax.transaction.xa.Xid;
-
-/**
- * 
- * A ResourceManager
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public interface ResourceManager
-{
-   boolean putTransaction(Xid xid, Transaction tx);
-   
-   Transaction getTransaction(Xid xid);
-   
-   boolean removeTransaction(Xid xid);
-   
-   int getTimeoutSeconds();
-   
-   boolean setTimeoutSeconds(int timeoutSeconds);
-}

Modified: trunk/src/main/org/jboss/messaging/core/server/ServerProducer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/ServerProducer.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/ServerProducer.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,5 +1,6 @@
 package org.jboss.messaging.core.server;
 
+import org.jboss.messaging.core.message.Message;
 
 /**
  * 
@@ -16,7 +17,7 @@
 	
 	void send(String address, Message msg) throws Exception;
 	
-	void sendCredits(int credits);
+	void sendCredits(int credits) throws Exception;
 	
 	int getNumCredits();
 }

Modified: trunk/src/main/org/jboss/messaging/core/server/ServerSession.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/ServerSession.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/ServerSession.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -25,6 +25,8 @@
 
 import javax.transaction.xa.Xid;
 
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateBrowserResponseMessage;

Deleted: trunk/src/main/org/jboss/messaging/core/server/Transaction.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Transaction.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/Transaction.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,60 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.server;
-
-import javax.transaction.xa.Xid;
-
-
-
-/**
- * 
- * A JBoss Messaging internal transaction
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public interface Transaction
-{   
-   void addSynchronization(TransactionSynchronization sync);
-   
-   void prepare(PersistenceManager persistenceManager) throws Exception;
-   
-   void commit(boolean onePhase, PersistenceManager persistenceManager) throws Exception;
-   
-   void rollback(PersistenceManager persistenceManager) throws Exception;   
-   
-   void addMessage(Message message);
-   
-   void addAcknowledgement(MessageReference acknowledgement);   
-   
-   int getAcknowledgementsCount();
-   
-   Xid getXid();
-   
-   boolean isEmpty();
-   
-   void suspend();
-   
-   void resume();
-   
-   boolean isSuspended();
-}

Deleted: trunk/src/main/org/jboss/messaging/core/server/TransactionSynchronization.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/TransactionSynchronization.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/TransactionSynchronization.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.server;
-
-/**
- * 
- * A TransactionSynchronization
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public interface TransactionSynchronization
-{
-   void beforeCommit() throws Exception;
-   
-   void afterCommit() throws Exception;
-   
-   void beforeRollback() throws Exception;
-   
-   void afterRollback() throws Exception;
-}

Deleted: trunk/src/main/org/jboss/messaging/core/server/impl/BindingImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/BindingImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/BindingImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,97 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.messaging.core.server.impl;
-
-import org.jboss.messaging.core.server.Binding;
-import org.jboss.messaging.core.server.Queue;
-
-/**
- * 
- * A BindingImpl
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class BindingImpl implements Binding
-{
-   private final int nodeID;
-   
-   private final String address;
-   
-   private final Queue queue;
-   
-   private boolean hashAssigned;
-   
-   private int hash;
-      
-   public BindingImpl(final int nodeID, final String address, final Queue queue)
-   {
-      this.nodeID = nodeID;
-      
-      this.address = address;
-      
-      this.queue = queue;
-   }
-   
-   public String getAddress()
-   {
-      return address;
-   }
-
-   public int getNodeID()
-   {
-      return nodeID;
-   }
-
-   public Queue getQueue()
-   {
-      return queue;
-   }
-
-   public boolean equals(Object other)
-   {
-      if (this == other)
-      {
-         return true;
-      }
-      Binding bother = (Binding)other;
-      
-      return (this.nodeID == bother.getNodeID()) &&
-              this.address.equals(bother.getAddress()) &&
-              this.queue.equals(bother.getQueue());
-   }
-   
-   public int hashCode()
-   {
-      if (!hashAssigned)
-      {
-         hash = 17;
-         hash = 37 * hash + nodeID;
-         hash = 37 * hash + address.hashCode();
-         hash = 37 * hash + queue.hashCode();
-                
-         hashAssigned = true;
-      }
-
-      return hash;
-   }
-}

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ConnectionManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ConnectionManagerImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ConnectionManagerImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -252,6 +252,7 @@
             }
          }
          buff.append("*** Dumped connections");
+         
          log.debug(buff);
       }
    }

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/DeliveryImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/DeliveryImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/DeliveryImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -22,11 +22,11 @@
 package org.jboss.messaging.core.server.impl;
 
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.remoting.PacketSender;
-import org.jboss.messaging.core.remoting.impl.wireformat.DeliverMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerDeliverMessage;
 import org.jboss.messaging.core.server.Delivery;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
 
 /**
  * 
@@ -79,7 +79,7 @@
       
       copy.setDeliveryCount(reference.getDeliveryCount() + 1);
       
-      DeliverMessage message = new DeliverMessage(copy, deliveryID);
+      ConsumerDeliverMessage message = new ConsumerDeliverMessage(copy, deliveryID);
       
       message.setTargetID(consumerID);
       

Deleted: trunk/src/main/org/jboss/messaging/core/server/impl/MessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessageImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessageImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,495 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.server.impl;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Semaphore;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.util.StreamUtils;
-
-/**
- * A concrete implementation of a message
- * 
- * All messages handled by JBM core are of this type
- * 
- * @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: 2740 $</tt>
- * 
- * For normal message transportation serialization is not used
- * 
- * $Id: MessageSupport.java 2740 2007-05-30 11:36:28Z timfox $
- */
-public class MessageImpl implements Message
-{
-   // Constants -----------------------------------------------------
-   
-   private static final Logger log = Logger.getLogger(MessageImpl.class);
-
-   // Attributes ----------------------------------------------------
-
-   private long messageID;
-   
-   private int type;
-   
-   private boolean durable;
-
-   /** GMT milliseconds at which this message expires. 0 means never expires * */
-   private long expiration;
-
-   private long timestamp;
-
-   private Map<String, Object> headers;
-   
-   private byte priority;
-
-   //The payload of MessageImpl instances is opaque
-   private byte[] payload;
-   
-   //We keep track of the persisted references for this message
-   private final List<MessageReference> references = new ArrayList<MessageReference>();
-   
-   private String connectionID;
-   
-   private volatile int numDurableReferences;
-   
-   private int deliveryCount;
-   
-   /*
-    * We use a semaphore of size 1, i.e. a mutex to synchronize access to the refs rather than
-    * use the synchronized keyword since java.util.Semaphore uses compareAndSet to maintain the semaphore
-    * i.e. no locking which should give better performance under high contention
-    */
-   private Semaphore refsLock = new Semaphore(1);
-   
-   // Constructors --------------------------------------------------
-
-   /*
-    * Construct a message for deserialization or streaming
-    */
-   public MessageImpl()
-   {
-      this.headers = new HashMap<String, Object>();
-   }
-
-   /*
-    * Construct a message before sending
-    */
-   public MessageImpl(final int type, final boolean durable, final long expiration,
-                      final long timestamp, final byte priority)
-   {
-      this();
-      this.type = type;
-      this.durable = durable;
-      this.expiration = expiration;
-      this.timestamp = timestamp;
-      this.priority = priority;            
-   }
-
-   /*
-    * Construct a MessageImpl from storage
-    */
-   public MessageImpl(final long messageID, final int type, final boolean durable, final long expiration,
-                      final long timestamp, final byte priority, final byte[] headers, final byte[] payload)
-      throws Exception
-   {
-      this.messageID = messageID;
-      this.type = type;
-      this.durable = durable;
-      this.expiration = expiration;
-      this.timestamp = timestamp;
-      this.priority = priority;
-      
-      if (headers == null)
-      {
-         this.headers = new HashMap<String, Object>();
-      }
-      else
-      {
-         //TODO keep headers opaque on server
-         ByteArrayInputStream bis = new ByteArrayInputStream(headers);
-
-         DataInputStream dais = new DataInputStream(bis);
-
-         this.headers = StreamUtils.readMap(dais, true);
-
-         dais.close();
-      }
-      this.payload = payload;
-   }
-   
-   /**
-    * Copy constructor
-    * 
-    * @param other
-    */
-   public MessageImpl(final MessageImpl other)
-   {
-      this.messageID = other.messageID;
-      this.type = other.type;
-      this.durable = other.durable;
-      this.expiration = other.expiration;
-      this.timestamp = other.timestamp;
-      this.priority = other.priority;
-      this.headers = new HashMap<String, Object>(other.headers);
-      this.payload = other.payload;
-   }
-   
-   // Message implementation ----------------------------------------
-
-   public long getMessageID()
-   {
-      return messageID;
-   }
-   
-   public void setMessageID(final long id)
-   {
-      this.messageID = id;
-   }
-   
-   public int getType()
-   {
-      return type;
-   }
-
-   public boolean isDurable()
-   {
-      return durable;
-   }
-   
-   public void setDurable(final boolean durable)
-   {
-      this.durable = durable;
-   }
-
-   public long getExpiration()
-   {
-      return expiration;
-   }
-
-   public void setExpiration(final long expiration)
-   {
-      this.expiration = expiration;
-   }
-
-   public long getTimestamp()
-   {
-      return timestamp;
-   }
-   
-   public void setTimestamp(final long timestamp)
-   {
-      this.timestamp = timestamp;
-   }
-
-   public Object putHeader(final String name, final Object value)
-   {
-      return headers.put(name, value);
-   }
-
-   public Object getHeader(final String name)
-   {
-      return headers.get(name);
-   }
-
-   public Object removeHeader(final String name)
-   {
-      return headers.remove(name);
-   }
-
-   public boolean containsHeader(final String name)
-   {
-      return headers.containsKey(name);
-   }
-
-   public Map<String, Object> getHeaders()
-   {
-      return headers;
-   }
-
-   public byte getPriority()
-   {
-      return priority;
-   }
-
-   public void setPriority(final byte priority)
-   {
-      this.priority = priority;
-   }
-
-   // TODO - combine with getPayloadAsByteArray to get one big blob
-   public byte[] getHeaderBytes() throws Exception
-   {
-      ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
-
-      DataOutputStream oos = new DataOutputStream(bos);
-
-      StreamUtils.writeMap(oos, headers, true);
-
-      oos.close();
-
-      return bos.toByteArray();
-   }
-         
-   public byte[] getPayload()
-   {     
-      return payload;
-   }
-   
-   public void setPayload(final byte[] payload)
-   {
-      this.payload = payload;
-   }
-   
-   public String getConnectionID()
-   {
-      return connectionID;
-   }
-   
-   public void setConnectionID(final String connectionID)
-   {
-      this.connectionID = connectionID;
-   }
-   
-   public void setDeliveryCount(final int deliveryCount)
-   {
-      this.deliveryCount = deliveryCount;
-   }
-   
-   public int getDeliveryCount()
-   {
-      return this.deliveryCount;
-   }
-
-   public boolean isExpired()
-   {
-      if (expiration == 0)
-      {
-         return false;
-      }
-      
-      return System.currentTimeMillis() - expiration >= 0;
-   }
-   
-   public MessageReference createReference(final Queue queue)
-   {
-      MessageReference ref =  new MessageReferenceImpl(this, queue);
-      
-      references.add(ref);
-      
-      if (durable && queue.isDurable())
-      {
-         numDurableReferences++;
-      }
-      
-      return ref;
-   }
-   
-   public int getNumDurableReferences()
-   {
-      return numDurableReferences;
-   }
-   
-   public List<MessageReference> getReferences()
-   {
-      return references;
-   }
-   
-   public void removeDurableReference(final MessageReference reference, final int pos) throws Exception
-   {
-      refsLock.acquire();
-      
-      try
-      {      
-         references.remove(pos);
-               
-         numDurableReferences--;                     
-      }
-      finally
-      {
-         refsLock.release();
-      }
-   }
-   
-   //TODO optimise to avoid scan
-   public int getDurableReferencePos(final MessageReference reference)
-   {
-      int pos = 0;
-      
-      for (MessageReference ref: references)
-      {
-         if (ref == reference)
-         {
-            break;
-         }
-         
-         if (ref.getQueue().isDurable())
-         {
-            pos++;
-         }         
-      }
-      
-      return pos;
-   }
-   
-   public void addBackDurableReference(final MessageReference reference)
-   {
-      references.add(reference);
-      
-      numDurableReferences++;
-   }
-   
-   public Message copy()
-   {
-      return new MessageImpl(this);
-   }
-
-   public void send() throws Exception
-   {
-      refsLock.acquire();
-      
-      try
-      {      
-         for (MessageReference ref: references)
-         {
-            ref.getQueue().addLast(ref);
-         }
-      }
-      finally
-      {
-         refsLock.release();
-      }
-   }
-    
-   // Public --------------------------------------------------------
-
-   public boolean equals(Object o)
-   {
-      if (this == o)
-      {
-         return true;
-      }
-      
-      if (!(o instanceof MessageImpl))
-      {
-         return false;
-      }
-      
-      MessageImpl that = (MessageImpl) o;
-      
-      return that.messageID == this.messageID;
-   }
-
-   public int hashCode()
-   {
-      return (int) ((this.messageID >>> 32) ^ this.messageID);
-   }
-
-   public String toString()
-   {
-      return "M[" + messageID + "]@" + System.identityHashCode(this);
-   }
-
-   // Streamable implementation ---------------------------------
-
-   public void write(final DataOutputStream out) throws Exception
-   {
-      out.writeLong(messageID);
-      
-      out.writeInt(type);
-
-      out.writeBoolean(durable);
-
-      out.writeLong(expiration);
-
-      out.writeLong(timestamp);
-
-      StreamUtils.writeMap(out, headers, true);
-
-      out.writeByte(priority);
-      
-      out.writeInt(deliveryCount);
-
-      if (payload != null)
-      {
-         out.writeInt(payload.length);
-
-         out.write(payload);
-      }
-      else
-      {
-         out.writeInt(0);
-      }
-   }
-
-   public void read(final DataInputStream in) throws Exception
-   {
-      messageID = in.readLong();
-      
-      type = in.readInt();
-
-      durable = in.readBoolean();
-
-      expiration = in.readLong();
-
-      timestamp = in.readLong();
-
-      headers = StreamUtils.readMap(in, true);
-
-      priority = in.readByte();
-
-      deliveryCount = in.readInt();
-      
-      int length = in.readInt();
-
-      if (length == 0)
-      {
-         // no payload
-         payload = null;
-      }
-      else
-      {
-         payload = new byte[length];
-
-         in.readFully(payload);
-      }
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------  
-}

Deleted: trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessageReferenceImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,249 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.messaging.core.server.impl;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.Queue;
-
-/**
- * Implementation of a MessageReference
- *
- * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
- * @version <tt>1.3</tt>
- *
- * MessageReferenceImpl.java,v 1.3 2006/02/23 17:45:57 timfox Exp
- */
-public class MessageReferenceImpl implements MessageReference
-{   
-   private static final Logger log = Logger.getLogger(MessageReferenceImpl.class);
-   
-   // Attributes ----------------------------------------------------
-
-   private boolean trace = log.isTraceEnabled();
-   
-   private volatile int deliveryCount;   
-   
-   private long scheduledDeliveryTime;
-   
-   private Message message;
-   
-   private Queue queue;
-   
-   // Constructors --------------------------------------------------
-
-   public MessageReferenceImpl()
-   {
-   }
-
-   public MessageReferenceImpl(final MessageReferenceImpl other, final Queue queue)
-   {
-      this.deliveryCount = other.deliveryCount;
-      
-      this.scheduledDeliveryTime = other.scheduledDeliveryTime;       
-      
-      this.message = other.message;
-      
-      this.queue = queue;
-   }
-   
-   protected MessageReferenceImpl(final Message message, final Queue queue)
-   {
-   	this.message = message;
-   	
-   	this.queue = queue;
-   }   
-   
-   // MessageReference implementation -------------------------------
-   
-   public MessageReference copy(final Queue queue)
-   {
-   	return new MessageReferenceImpl(this, queue);
-   }
-   
-   public int getDeliveryCount()
-   {
-      return deliveryCount;
-   }
-   
-   public void setDeliveryCount(final int deliveryCount)
-   {
-      this.deliveryCount = deliveryCount;
-   }
-   
-   public void incrementDeliveryCount()
-   {
-      deliveryCount++;
-   }
-   
-   public long getScheduledDeliveryTime()
-   {
-      return scheduledDeliveryTime;
-   }
-
-   public void setScheduledDeliveryTime(final long scheduledDeliveryTime)
-   {
-      this.scheduledDeliveryTime = scheduledDeliveryTime;
-   }
-      
-   public Message getMessage()
-   {
-      return message;
-   }         
-   
-   public Queue getQueue()
-   {
-      return queue;
-   }
-   
-   public void acknowledge(final PersistenceManager persistenceManager) throws Exception
-   {
-      if (message.isDurable())
-      {
-         persistenceManager.deleteReference(this);
-      }
-      
-      queue.decrementDeliveringCount();
-   }
-   
-   public boolean cancel(final PersistenceManager persistenceManager) throws Exception
-   {      
-      if (message.isDurable() && queue.isDurable())
-      {
-         persistenceManager.updateDeliveryCount(queue, this);
-      }
-            
-      log.info("Queue settings is " + queue.getQueueSettings());
-   	
-      
-      queue.decrementDeliveringCount();
-
-      int maxDeliveries = queue.getQueueSettings().getMatch(queue.getName()).getMaxDeliveryAttempts();
-      
-      if (maxDeliveries > 0 && deliveryCount >= maxDeliveries)
-      {
-      	
-      	
-         Queue DLQ = queue.getQueueSettings().getMatch(queue.getName()).getDLQ();
-         
-         if (DLQ != null)
-         {
-            Message copyMessage = makeCopyForDLQOrExpiry(false, persistenceManager);
-            
-            moveInTransaction(DLQ, copyMessage, persistenceManager);
-         }
-         else
-         {
-            //No DLQ
-            
-            log.warn("Message has reached maximum delivery attempts, no DLQ is configured so dropping it");
-            
-            acknowledge(persistenceManager);
-         }       
-         
-         return false;
-      }
-      else
-      {
-         return true;
-      }
-   }
-   
-   public void expire(final PersistenceManager persistenceManager) throws Exception
-   {
-      Queue expiryQueue = queue.getQueueSettings().getMatch(queue.getName()).getExpiryQueue();
-      if (expiryQueue != null)
-      {
-         Message copyMessage = makeCopyForDLQOrExpiry(false, persistenceManager);
-         
-         moveInTransaction(expiryQueue, copyMessage, persistenceManager);
-      }
-      else
-      {
-         log.warn("Message has expired, no expiry queue is configured so dropping it");
-         
-         acknowledge(persistenceManager);
-      }
-   }
-         
-   // Public --------------------------------------------------------
-
-   public String toString()
-   {
-      return "Reference[" + getMessage().getMessageID() + "]:" + (getMessage().isDurable() ? "RELIABLE" : "NON-RELIABLE");
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------   
-   
-   // Private -------------------------------------------------------
-   
-   private void moveInTransaction(final Queue destinationQueue, final Message copyMessage,
-                                  final PersistenceManager persistenceManager) throws Exception
-   {
-      copyMessage.createReference(destinationQueue);
-      
-      TransactionImpl tx = new TransactionImpl();
-      
-      tx.addMessage(copyMessage);
-      
-      tx.addAcknowledgement(this);
-      
-      tx.commit(true, persistenceManager);
-   }
-   
-   private Message makeCopyForDLQOrExpiry(final boolean expiry, final PersistenceManager pm) throws Exception
-   {
-      /*
-       We copy the message and send that to the dlq/expiry queue - this is
-       because otherwise we may end up with a ref with the same message id in the
-       queue more than once which would barf - this might happen if the same message had been
-       expire from multiple subscriptions of a topic for example
-       We set headers that hold the original message destination, expiry time
-       and original message id
-      */
-
-      Message copy = message.copy();
-      
-      long newMessageId = pm.generateMessageID();
-      
-      copy.setMessageID(newMessageId);
-      
-      // reset expiry
-      copy.setExpiration(0);
-      
-      if (expiry)
-      {
-         long actualExpiryTime = System.currentTimeMillis();
-      
-         copy.putHeader(Message.HDR_ACTUAL_EXPIRY_TIME, actualExpiryTime);
-      }
-      
-      return copy;
-   }
-
-   // Inner classes -------------------------------------------------
-   
-}
\ No newline at end of file

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -34,10 +34,16 @@
 import org.jboss.messaging.core.deployers.impl.FileDeploymentManager;
 import org.jboss.messaging.core.deployers.DeploymentManager;
 import org.jboss.messaging.core.deployers.Deployer;
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.memory.MemoryManager;
 import org.jboss.messaging.core.memory.impl.SimpleMemoryManager;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.messagecounter.MessageCounterManager;
+import org.jboss.messaging.core.persistence.PersistenceManager;
 import org.jboss.messaging.core.persistence.impl.nullpm.NullPersistenceManager;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.postoffice.PostOffice;
+import org.jboss.messaging.core.postoffice.impl.PostOfficeImpl;
 import org.jboss.messaging.core.remoting.Interceptor;
 import org.jboss.messaging.core.remoting.RemotingService;
 import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
@@ -47,21 +53,17 @@
 import org.jboss.messaging.core.security.SecurityStore;
 import org.jboss.messaging.core.security.impl.NullAuthenticationManager;
 import org.jboss.messaging.core.security.impl.SecurityStoreImpl;
-import org.jboss.messaging.core.server.Binding;
 import org.jboss.messaging.core.server.Configuration;
 import org.jboss.messaging.core.server.ConnectionManager;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.MessageReference;
 import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.PostOffice;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
-import org.jboss.messaging.core.server.ResourceManager;
 import org.jboss.messaging.core.server.ServerConnection;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
 import org.jboss.messaging.core.settings.impl.HierarchicalObjectRepository;
 import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.core.transaction.ResourceManager;
+import org.jboss.messaging.core.transaction.impl.ResourceManagerImpl;
 import org.jboss.messaging.core.version.Version;
 import org.jboss.messaging.core.version.impl.VersionImpl;
 import org.jboss.security.AuthenticationManager;
@@ -348,7 +350,6 @@
       this.authenticationManager = authenticationManager;
    }
 
-
    public String toString()
    {
       return "MessagingServer[" + configuration.getMessagingServerID() + "]";

Deleted: trunk/src/main/org/jboss/messaging/core/server/impl/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/PostOfficeImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/PostOfficeImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,329 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.messaging.core.server.impl;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Binding;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.MessagingException;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.PostOffice;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.QueueFactory;
-import org.jboss.messaging.util.ConcurrentHashSet;
-
-/**
- * 
- * A PostOfficeImpl
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class PostOfficeImpl implements PostOffice
-{  
-   private static final Logger log = Logger.getLogger(PostOfficeImpl.class);
-   
-   private final int nodeID;
-   
-   private final ConcurrentMap<String, List<Binding>> mappings = new ConcurrentHashMap<String, List<Binding>>();
-   
-   private final Set<String> allowableAddresses = new ConcurrentHashSet<String>();
-   
-   private final ConcurrentMap<String, Binding> nameMap = new ConcurrentHashMap<String, Binding>();
-   
-   private final PersistenceManager persistenceManager;
-   
-   private final QueueFactory queueFactory;
-   
-   private final boolean checkAllowable;
-    
-   public PostOfficeImpl(final int nodeID, final PersistenceManager persistenceManager,
-   		                final QueueFactory queueFactory, final boolean checkAllowable)
-   {
-      this.nodeID = nodeID;
-      
-      this.persistenceManager = persistenceManager;
-      
-      this.queueFactory = queueFactory;
-      
-      this.checkAllowable = checkAllowable;
-   }
-      
-   // MessagingComponent implementation ---------------------------------------
-   
-   public void start() throws Exception
-   {
-      loadBindings();
-   }
-
-   public void stop() throws Exception
-   {
-      mappings.clear();
-      
-      allowableAddresses.clear();
-   }
-   
-   // PostOffice implementation -----------------------------------------------
-
-   public void addAllowableAddress(final String address)
-   {      
-      allowableAddresses.add(address);
-   }
-   
-   public boolean removeAllowableAddress(final String address)
-   {      
-      return allowableAddresses.remove(address);
-   }
-   
-   public boolean containsAllowableAddress(final String address)
-   {
-      return allowableAddresses.contains(address);
-   }
-
-
-   public Set<String> listAvailableAddresses()
-   {
-      return allowableAddresses;
-   }
-
-   public Binding addBinding(final String address, final String queueName, final Filter filter, 
-                             final boolean durable, final boolean temporary) throws Exception
-   {
-      Binding binding = createBinding(address, queueName, filter, durable, temporary);
-
-      addBindingInMemory(binding);
-      
-      if (durable)
-      {
-         persistenceManager.addBinding(binding);
-      }
-      
-      return binding;      
-   }
-         
-   public Binding removeBinding(final String queueName) throws Exception
-   {
-      Binding binding = removeQueueInMemory(queueName);
-      
-      if (binding.getQueue().isDurable())
-      {
-         persistenceManager.deleteBinding(binding);
-      }
-      
-      return binding;
-   }
-   
-   public List<Binding> getBindingsForAddress(final String address)
-   {
-      List<Binding> list = new ArrayList<Binding>();
-      
-      List<Binding> bindings = mappings.get(address);
-      
-      if (bindings != null)
-      {
-         for (Binding binding: bindings)
-         {
-            if (binding.getNodeID() == nodeID)
-            {
-               list.add(binding);
-            }
-         }
-      }         
-         
-      return list;
-   }
-   
-   public Binding getBinding(final String queueName)
-   {
-      return nameMap.get(queueName);
-   }
-         
-   public void route(final String address, final Message message) throws Exception
-   {
-     // boolean routeRemote = false;
-      
-      if (checkAllowable)
-      {
-         if (!allowableAddresses.contains(address))
-         {
-            throw new MessagingException(MessagingException.ADDRESS_DOES_NOT_EXIST,
-                                         "Cannot route to address " + address);
-         }
-      }
-           
-      List<Binding> bindings = mappings.get(address);
-      
-      if (bindings != null)
-      {
-         for (Binding binding: bindings)
-         {
-            Queue queue = binding.getQueue();
-            
-            if (queue.getFilter() == null || queue.getFilter().match(message))
-            {         
-               if (binding.getNodeID() == nodeID)
-               {
-                  //Local queue
-                                 
-                  message.createReference(queue);              
-               }
-               else
-               {
-//                  if (!queue.isDurable())
-//                  {
-//                     //Remote queue - we never route to remote durable queues since we will lose atomicity in event
-//                     //of crash - for moving between durable queues we use message redistribution
-//                     
-//                     routeRemote = true;                  
-//                  }               
-               }
-            }
-         }
-      }
-
-      
-//      if (routeRemote)
-//      {
-//         tx.addSynchronization(new CastMessageCallback(new MessageRequest(address, message)));
-//      }
-   }
-   
-   public void routeFromCluster(final String address, final Message message) throws Exception
-   {     
-      List<Binding> bindings = mappings.get(address);
-      
-      for (Binding binding: bindings)
-      {
-         Queue queue = binding.getQueue();
-         
-         if (binding.getNodeID() == nodeID)
-         {         
-            if (queue.getFilter() == null || queue.getFilter().match(message))
-            {         
-               MessageReference ref = message.createReference(queue);
-
-               //We never route durably from other nodes - so no need to persist
-
-               queue.addLast(ref);             
-            }
-         }
-      }
-   }
-
-   public Map<String, List<Binding>> getMappings()
-   {
-      return mappings;
-   }
-
-
-
-   // Private -----------------------------------------------------------------
-   
-   private Binding createBinding(final String address, final String name, final Filter filter,
-                                 final boolean durable, final boolean temporary)
-   {
-      Queue queue = queueFactory.createQueue(-1, name, filter, durable, temporary);
-      
-      Binding binding = new BindingImpl(this.nodeID, address, queue);
-      
-      return binding;
-   }
-   
-   private void addBindingInMemory(final Binding binding)
-   {              
-      List<Binding> bindings = new CopyOnWriteArrayList<Binding>();
-      
-      List<Binding> prevBindings = mappings.putIfAbsent(binding.getAddress(), bindings);
-      
-      if (prevBindings != null)
-      {
-         bindings = prevBindings;
-      }
-                     
-      bindings.add(binding);  
-
-      if (nameMap.putIfAbsent(binding.getQueue().getName(), binding) != null)
-      {
-         throw new IllegalStateException("Binding already exists " + binding);
-      }     
-   }
-   
-   private Binding removeQueueInMemory(final String queueName) throws Exception
-   {
-      Binding binding = nameMap.remove(queueName);
-      
-      if (binding == null)
-      {
-         throw new IllegalStateException("Queue is not bound " + queueName);
-      }
-                  
-      List<Binding> bindings = mappings.get(binding.getAddress());
-                  
-      for (Iterator<Binding> iter = bindings.iterator(); iter.hasNext();)
-      {
-         Binding b = iter.next();
-         
-         if (b.getQueue().getName().equals(queueName))
-         {
-            binding = b;
-                                          
-            break;
-         }
-      }
-      
-      if (binding == null)
-      {
-         throw new IllegalStateException("Cannot find binding " + queueName);
-      }
-      
-      bindings.remove(binding);      
-      
-      if (bindings.isEmpty())
-      {
-         mappings.remove(binding.getAddress());
-      }
-               
-      return binding;
-   }
-   
-   private void loadBindings() throws Exception
-   {
-      List<Binding> bindings = persistenceManager.loadBindings(queueFactory);
-      
-      for (Binding binding: bindings)
-      {
-         addBindingInMemory(binding);                    
-      }
-   }
-
-}

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/QueueFactoryImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/QueueFactoryImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/QueueFactoryImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -23,7 +23,7 @@
 
 import java.util.concurrent.ScheduledExecutorService;
 
-import org.jboss.messaging.core.server.Filter;
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
 import org.jboss.messaging.core.settings.HierarchicalRepository;

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -32,14 +32,14 @@
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.list.PriorityLinkedList;
 import org.jboss.messaging.core.list.impl.PriorityLinkedListImpl;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.server.Consumer;
 import org.jboss.messaging.core.server.DistributionPolicy;
-import org.jboss.messaging.core.server.Filter;
 import org.jboss.messaging.core.server.HandleStatus;
-import org.jboss.messaging.core.server.MessageReference;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
 import org.jboss.messaging.core.settings.impl.QueueSettings;

Deleted: trunk/src/main/org/jboss/messaging/core/server/impl/ResourceManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ResourceManagerImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ResourceManagerImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,90 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.server.impl;
-
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.transaction.xa.Xid;
-
-import org.jboss.messaging.core.server.ResourceManager;
-import org.jboss.messaging.core.server.Transaction;
-
-/**
- * 
- * A ResourceManagerImpl
- * 
- * TODO - implement timeouts
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class ResourceManagerImpl implements ResourceManager
-{
-   private ConcurrentMap<Xid, Transaction> transactions = new ConcurrentHashMap<Xid, Transaction>();
-   
-   private final int defaultTimeoutSeconds;
-   
-   private volatile int timeoutSeconds;
-   
-   public ResourceManagerImpl(final int defaultTimeoutSeconds)
-   {      
-      this.defaultTimeoutSeconds = defaultTimeoutSeconds;
-   }
-   
-   // ResourceManager implementation ---------------------------------------------
-   
-   public Transaction getTransaction(final Xid xid)
-   {
-      return transactions.get(xid);
-   }
-
-   public boolean putTransaction(final Xid xid, final Transaction tx)
-   {
-      return transactions.putIfAbsent(xid, tx) == null;
-   }
-
-   public boolean removeTransaction(final Xid xid)
-   {
-      return transactions.remove(xid) != null;
-   }
-   
-   public int getTimeoutSeconds()
-   {
-      return this.timeoutSeconds;
-   }
-   
-   public boolean setTimeoutSeconds(final int timeoutSeconds)
-   {
-      if (timeoutSeconds == 0)
-      {
-         //reset to default
-         this.timeoutSeconds = defaultTimeoutSeconds;
-      }
-      else
-      {
-         this.timeoutSeconds = timeoutSeconds;
-      }      
-      
-      return true;
-   }
-}

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerBrowserImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerBrowserImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerBrowserImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -31,8 +31,11 @@
 import java.util.List;
 import java.util.UUID;
 
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.remoting.PacketHandler;
 import org.jboss.messaging.core.remoting.PacketSender;
 import org.jboss.messaging.core.remoting.impl.wireformat.NullPacket;
@@ -40,9 +43,6 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserHasNextMessageResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserNextMessageResponseMessage;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
 import org.jboss.messaging.core.server.MessagingException;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.ServerSession;

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerConnectionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerConnectionImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerConnectionImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -26,19 +26,19 @@
 import java.util.concurrent.ConcurrentMap;
 
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
 import org.jboss.messaging.core.remoting.PacketHandler;
 import org.jboss.messaging.core.remoting.PacketSender;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionResponseMessage;
 import org.jboss.messaging.core.security.SecurityStore;
-import org.jboss.messaging.core.server.Binding;
 import org.jboss.messaging.core.server.ConnectionManager;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.PostOffice;
 import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.ResourceManager;
 import org.jboss.messaging.core.server.ServerConnection;
 import org.jboss.messaging.core.server.ServerSession;
+import org.jboss.messaging.core.transaction.ResourceManager;
 import org.jboss.messaging.util.ConcurrentHashSet;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -24,14 +24,14 @@
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.remoting.PacketHandler;
-import org.jboss.messaging.core.server.Filter;
 import org.jboss.messaging.core.server.HandleStatus;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.PostOffice;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.ServerConsumer;
 import org.jboss.messaging.core.server.ServerSession;
@@ -90,10 +90,10 @@
    // Constructors ---------------------------------------------------------------------------------
 
    ServerConsumerImpl(final Queue messageQueue, final boolean noLocal, final Filter filter,
-   		                 final boolean autoDeleteQueue, final boolean enableFlowControl,
-   		                 final String connectionID, final ServerSession sessionEndpoint,
-					           final PersistenceManager persistenceManager, final PostOffice postOffice,
-					           final boolean started)
+   		             final boolean autoDeleteQueue, final boolean enableFlowControl,
+   		             final String connectionID, final ServerSession sessionEndpoint,
+					       final PersistenceManager persistenceManager, final PostOffice postOffice,
+					       final boolean started)
    {
    	id = UUID.randomUUID().toString();
       

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -23,7 +23,12 @@
 
 import java.util.UUID;
 
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.remoting.PacketSender;
+import org.jboss.messaging.core.remoting.impl.wireformat.Packet;
+import org.jboss.messaging.core.remoting.impl.wireformat.ProducerReceiveTokensMessage;
+import org.jboss.messaging.core.server.FlowController;
 import org.jboss.messaging.core.server.ServerProducer;
 import org.jboss.messaging.core.server.ServerSession;
 
@@ -36,21 +41,38 @@
  */
 public class ServerProducerImpl implements ServerProducer
 {
+	private static final Logger log = Logger.getLogger(ServerProducerImpl.class);
+	
 	private final String id;
 	
 	private final ServerSession session;
 	
 	private final String address;
-		
+	
+	private final FlowController flowController;
+	
+	private final PacketSender sender;
+	
+	private volatile int numberSent;
+	
+	private final int batchSize = 10;
+			
+	
 	// Constructors ----------------------------------------------------------------
 	
-	public ServerProducerImpl(final ServerSession session, final String address)
+	public ServerProducerImpl(final ServerSession session, final String address, 
+			                    final PacketSender sender,
+			                    final FlowController flowController) throws Exception
 	{
 		id = UUID.randomUUID().toString();
       
 		this.session = session;
 		
 		this.address = address;
+		
+		this.sender = sender;
+		
+		this.flowController = flowController;				
 	}
 	
 	// ServerProducer implementation --------------------------------------------
@@ -65,8 +87,9 @@
 		session.removeProducer(id);
 	}
 	
+	
 	public void send(final String address, final Message message) throws Exception
-	{
+	{		
 		if (address != null)
 		{
 			//Anonymous producer - no flow control
@@ -75,6 +98,15 @@
 		else
 		{			
 			session.send(this.address, message);
+			
+//			numberSent++;
+//			
+//			if (numberSent == batchSize)
+//			{
+//				numberSent = 0;
+//						
+//				flowController.checkTokens(this);
+//			}
 		}
 	}
 	
@@ -84,9 +116,12 @@
 		return 0;
 	}
 
-	public void sendCredits(final int credits)
+	public void sendCredits(final int credits) throws Exception
 	{
-		// TODO Auto-generated method stub
+		Packet packet = new ProducerReceiveTokensMessage(credits);
 		
+		packet.setTargetID(id);
+			
+		sender.send(packet);		
 	}
 }

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -36,8 +36,14 @@
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
 import org.jboss.messaging.core.remoting.PacketSender;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryMessage;
@@ -50,21 +56,17 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAResponseMessage;
 import org.jboss.messaging.core.security.CheckType;
 import org.jboss.messaging.core.security.SecurityStore;
-import org.jboss.messaging.core.server.Binding;
 import org.jboss.messaging.core.server.Delivery;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.server.FlowController;
 import org.jboss.messaging.core.server.MessagingException;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.PostOffice;
 import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.ResourceManager;
 import org.jboss.messaging.core.server.ServerConnection;
 import org.jboss.messaging.core.server.ServerConsumer;
 import org.jboss.messaging.core.server.ServerProducer;
 import org.jboss.messaging.core.server.ServerSession;
-import org.jboss.messaging.core.server.Transaction;
+import org.jboss.messaging.core.transaction.ResourceManager;
+import org.jboss.messaging.core.transaction.Transaction;
+import org.jboss.messaging.core.transaction.impl.TransactionImpl;
 
 /**
  * Session implementation
@@ -302,7 +304,7 @@
       securityStore.check(address, CheckType.WRITE, connection);
       // Assign the message an internal id - this is used to key it in the store
       msg.setMessageID(persistenceManager.generateMessageID());
-
+      
       // This allows the no-local consumers to filter out the messages that come
       // from the same
       // connection.
@@ -310,7 +312,7 @@
       msg.setConnectionID(connection.getID());
 
       postOffice.route(address, msg);
-
+      
       if (!msg.getReferences().isEmpty())
       {
          if (autoCommitSends)
@@ -331,13 +333,10 @@
 
    public synchronized void acknowledge(final long deliveryID, final boolean allUpTo) throws Exception
    {
-      // Note that we do not consider it an error if the deliveries cannot be
-      // found to be acked.
-      // This can legitimately occur if a connection/session/consumer is closed
-      // from inside a MessageHandlers
-      // onMessage method. In this situation the close will cancel any unacked
-      // deliveries, but the subsequent
-      // call to delivered() will try and ack again and not find the last
+      // Note that we do not consider it an error if the deliveries cannot be found to be acked.
+   	// This can legitimately occur if a connection/session/consumer is closed
+      // from inside a MessageHandlers onMessage method. In this situation the close will cancel any unacked
+      // deliveries, but the subsequent call to delivered() will try and ack again and not find the last
       // delivery on the server.
       if (allUpTo)
       {
@@ -1002,14 +1001,18 @@
    }
    
    public SessionCreateProducerResponseMessage createProducer(final String address) throws Exception
-   {
-   	ServerProducerImpl producer = new ServerProducerImpl(this, address);
+   { 	
+   	//FlowController flowController = new FlowControllerImpl(address, postOffice, 10);		
    	
+   	ServerProducerImpl producer = new ServerProducerImpl(this, address, sender, null);
+   	
    	producers.put(producer.getID(), producer);
    	
    	dispatcher.register(new ServerProducerPacketHandler(producer));
    	
-   	return new SessionCreateProducerResponseMessage(producer.getID());
+   	int initialTokens = 10;
+   	
+   	return new SessionCreateProducerResponseMessage(producer.getID(), initialTokens);
    }
    
    // Public ---------------------------------------------------------------------------------------------

Deleted: trunk/src/main/org/jboss/messaging/core/server/impl/TransactionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/TransactionImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/TransactionImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,279 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.server.impl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import javax.transaction.xa.Xid;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.Transaction;
-import org.jboss.messaging.core.server.TransactionSynchronization;
-
-/**
- * 
- * A TransactionImpl
- * 
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class TransactionImpl implements Transaction
-{
-   private static final Logger log = Logger.getLogger(TransactionImpl.class);
-   
-   private final List<Message> messagesToAdd = new ArrayList<Message>();
-   
-   private final List<MessageReference> acknowledgements = new ArrayList<MessageReference>();  
-   
-   private final List<TransactionSynchronization> synchronizations = new ArrayList<TransactionSynchronization>();
-   
-   private final Xid xid;
-   
-   private volatile boolean containsPersistent;
-   
-   private volatile boolean prepared;
-   
-   private volatile boolean suspended;
-   
-   public TransactionImpl()
-   {       
-   	this.xid = null;
-   }
-   
-   public TransactionImpl(final Xid xid)
-   {
-      this.xid = xid;      
-   }
-   
-   // Transaction implementation -----------------------------------------------------------
-   
-   public void addMessage(final Message message)
-   {
-      messagesToAdd.add(message);
-      
-      if (message.getNumDurableReferences() != 0)
-      {
-         containsPersistent = true;
-      }
-   }
-   
-   public void addAcknowledgement(final MessageReference acknowledgement)
-   {
-      acknowledgements.add(acknowledgement);
-       
-      if (acknowledgement.getMessage().isDurable() && acknowledgement.getQueue().isDurable())
-      {
-         containsPersistent = true;
-      }
-   }
-      
-   public void addSynchronization(final TransactionSynchronization sync)
-   {
-      synchronizations.add(sync);
-   }
-   
-   public void prepare(final PersistenceManager persistenceManager) throws Exception
-   {
-      if (xid == null)
-      {
-         throw new IllegalStateException("Cannot call prepare() on a non XA transaction");
-      }
-      else if (containsPersistent)
-      {
-         persistenceManager.prepareTransaction(xid, messagesToAdd, acknowledgements);
-      }
-            
-      prepared = true;
-   }
-   
-   public void commit(final boolean onePhase, final PersistenceManager persistenceManager) throws Exception
-   {
-      callSynchronizations(SyncType.BEFORE_COMMIT);
-      
-      if (containsPersistent)
-      {
-         if (xid == null || onePhase)
-         {
-            //1PC commit
-            
-            persistenceManager.commitTransaction(messagesToAdd, acknowledgements);
-         }
-         else
-         {
-            //2PC commit
-            
-            if (!prepared)
-            {
-               throw new IllegalStateException("Transaction is not prepared");
-            }
-            
-            persistenceManager.commitPreparedTransaction(xid);                        
-         } 
-      }
-            
-      for (Message msg: messagesToAdd)
-      {
-         msg.send();
-      }
-      
-      for (MessageReference reference: acknowledgements)
-      {
-         reference.getQueue().decrementDeliveringCount();
-      }
-      
-      callSynchronizations(SyncType.AFTER_COMMIT);
-      
-      clear();      
-   }
-   
-   public void rollback(final PersistenceManager persistenceManager) throws Exception
-   {
-      callSynchronizations(SyncType.BEFORE_ROLLBACK);
-        
-      if (prepared)
-      {
-         persistenceManager.unprepareTransaction(xid, messagesToAdd, acknowledgements);             
-      }
-      
-      cancelDeliveries(persistenceManager);
-                        
-      callSynchronizations(SyncType.AFTER_ROLLBACK);  
-      
-      clear();      
-   }      
-   
-   public int getAcknowledgementsCount()
-   {
-      return acknowledgements.size();
-   }
-   
-   public void suspend()
-   {
-      suspended = true;
-   }
-   
-   public void resume()
-   {
-      suspended = false;
-   }
-   
-   public boolean isSuspended()
-   {
-      return suspended;
-   }
-   
-   public Xid getXid()
-   {
-      return xid;
-   }
-   
-   public boolean isEmpty()
-   {
-      return messagesToAdd.isEmpty() && acknowledgements.isEmpty();
-   }
-   
-   // Private -------------------------------------------------------------------
-   
-   private void callSynchronizations(final SyncType type) throws Exception
-   {
-      for (TransactionSynchronization sync: synchronizations)
-      {
-         if (type == SyncType.BEFORE_COMMIT)
-         {
-            sync.beforeCommit();
-         }
-         else if (type == SyncType.AFTER_COMMIT)
-         {
-            sync.afterCommit();
-         }
-         else if (type == SyncType.BEFORE_ROLLBACK)
-         {
-            sync.beforeRollback();
-         }
-         else if (type == SyncType.AFTER_ROLLBACK)
-         {
-            sync.afterRollback();
-         }            
-      }
-   }
-
-   private void clear()
-   {
-      messagesToAdd.clear();
-      
-      acknowledgements.clear();
-      
-      synchronizations.clear();
-      
-      containsPersistent = false;
-   }
-   
-   private void cancelDeliveries(final PersistenceManager persistenceManager) throws Exception
-   {
-      Map<Queue, LinkedList<MessageReference>> queueMap = new HashMap<Queue, LinkedList<MessageReference>>();
-      
-      //Need to sort into lists - one for each queue involved.
-      //Then cancelling back atomicly for each queue adding list on front to guarantee ordering is preserved      
-      
-      for (MessageReference ref: acknowledgements)
-      {
-         Queue queue = ref.getQueue();
-         
-         LinkedList<MessageReference> list = queueMap.get(queue);
-         
-         if (list == null)
-         {
-            list = new LinkedList<MessageReference>();
-            
-            queueMap.put(queue, list);
-         }
-                 
-         if (ref.cancel(persistenceManager))
-         {
-            list.add(ref);
-         }
-      }
-      
-      for (Map.Entry<Queue, LinkedList<MessageReference>> entry: queueMap.entrySet())
-      {                  
-         LinkedList<MessageReference> refs = entry.getValue();
-                
-         entry.getKey().addListFirst(refs);
-      }
-   }
-   
-   // Inner Enums -------------------------------------------------------------------------------
-   
-   private enum SyncType
-   {
-      BEFORE_COMMIT, AFTER_COMMIT, BEFORE_ROLLBACK, AFTER_ROLLBACK;
-   }
-         
-}

Deleted: trunk/src/main/org/jboss/messaging/core/server/impl/XidImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/XidImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/XidImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -1,197 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.messaging.core.server.impl;
-
-import java.io.Serializable;
-
-import javax.transaction.xa.Xid;
-
-/**
- * 
- * Xid implementation
- * 
- * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
- * 
- * @version $Revision 1.1 $
- */
-public class XidImpl implements Xid, Serializable
-{
-   private static final long serialVersionUID = 407053232840068514L;
-
-   private byte[] branchQualifier;
-   
-   private int formatId;
-   
-   private byte[] globalTransactionId;
-   
-   private int hash;
-   
-   private boolean hashCalculated;
-   
-   /**
-    * Standard constructor
-    * @param branchQualifier
-    * @param formatId
-    * @param globalTransactionId
-    */
-   public XidImpl(final byte[] branchQualifier, final int formatId, final byte[] globalTransactionId)
-   {
-      this.branchQualifier = branchQualifier;
-      this.formatId = formatId;
-      this.globalTransactionId = globalTransactionId;          
-   }
-   
-   /**
-    * Copy constructor
-    * @param other
-    */
-   public XidImpl(final Xid other)
-   {
-      this.branchQualifier = copyBytes(other.getBranchQualifier());
-      this.formatId = other.getFormatId();
-      this.globalTransactionId = copyBytes(other.getGlobalTransactionId());
-   }
-
-   // Xid implementation ------------------------------------------------------------------
-   
-   public byte[] getBranchQualifier()
-   {
-      return branchQualifier;
-   }
-
-   public int getFormatId()
-   {
-      return formatId;
-   }
-
-   public byte[] getGlobalTransactionId()
-   {
-      return globalTransactionId;
-   }
-   
-   // Public -------------------------------------------------------------------------------
-            
-   public int hashCode()
-   {
-      if (!hashCalculated)
-      {
-         calcHash();
-      }
-      return hash;
-   }
-   
-   public boolean equals(Object other)
-   {
-      if (this == other)
-      {
-         return true;
-      }
-      if (!(other instanceof Xid))
-      {
-         return false;
-      }
-      Xid xother = (Xid)other;
-      if (xother.getFormatId() != formatId)
-      {
-         return false;
-      }
-      if (xother.getBranchQualifier().length != this.branchQualifier.length)
-      {
-         return false;
-      }
-      if (xother.getGlobalTransactionId().length != this.globalTransactionId.length)
-      {
-         return false;
-      }
-      for (int i = 0; i < this.branchQualifier.length; i++)
-      {
-         byte[] otherBQ = xother.getBranchQualifier();
-         if (this.branchQualifier[i] != otherBQ[i])
-         {
-            return false;
-         }         
-      }
-      for (int i = 0; i < this.globalTransactionId.length; i++)
-      {
-         byte[] otherGtx = xother.getGlobalTransactionId();
-         if (this.globalTransactionId[i] != otherGtx[i])
-         {
-            return false;
-         }
-      }
-      return true;
-   }
-
-   public String toString()
-   {
-     	return "XidImpl (" + System.identityHashCode(this) + " bq:" + stringRep(branchQualifier) +
-     	" formatID:" + formatId + " gtxid:" + stringRep(globalTransactionId);
-   }
-   
-   // Private -------------------------------------------------------------------------------
-   
-   private String stringRep(final byte[] bytes)
-   {
-      StringBuffer buff = new StringBuffer();
-      for (int i = 0; i < bytes.length; i++)
-      {
-         byte b = bytes[i];
-         
-         buff.append(b);
-         
-         if (i != bytes.length - 1)
-         {
-            buff.append('.');
-         }
-      }
-      
-      return buff.toString();
-   }
-   
-   private void calcHash()
-   {
-      byte[] hashBytes = new byte[branchQualifier.length + globalTransactionId.length + 4];
-      System.arraycopy(branchQualifier, 0, hashBytes, 0, branchQualifier.length);
-      System.arraycopy(globalTransactionId, 0, hashBytes, branchQualifier.length, globalTransactionId.length);
-      byte[] intBytes = new byte[4];
-      for (int i = 0; i < 4; i++)
-      {
-         intBytes[i] = (byte)((formatId >> (i * 8)) % 0xFF);
-      }
-      System.arraycopy(intBytes, 0, hashBytes, branchQualifier.length + globalTransactionId.length, 4);
-      String s = new String(hashBytes);
-      hash = s.hashCode();
-      hashCalculated = true;
-   }
-   
-   private byte[] copyBytes(byte[] other)
-   {
-      byte[] bytes = new byte[other.length];
-      
-      System.arraycopy(other, 0, bytes, 0, other.length);
-      
-      return bytes;
-   }
-
-}

Copied: trunk/src/main/org/jboss/messaging/core/transaction/ResourceManager.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/ResourceManager.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/transaction/ResourceManager.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/transaction/ResourceManager.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.transaction;
+
+import javax.transaction.xa.Xid;
+
+
+/**
+ * 
+ * A ResourceManager
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface ResourceManager
+{
+   boolean putTransaction(Xid xid, Transaction tx);
+   
+   Transaction getTransaction(Xid xid);
+   
+   boolean removeTransaction(Xid xid);
+   
+   int getTimeoutSeconds();
+   
+   boolean setTimeoutSeconds(int timeoutSeconds);
+}

Copied: trunk/src/main/org/jboss/messaging/core/transaction/Transaction.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/Transaction.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/transaction/Transaction.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/transaction/Transaction.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.transaction;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+
+
+
+/**
+ * 
+ * A JBoss Messaging internal transaction
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface Transaction
+{   
+   void addSynchronization(TransactionSynchronization sync);
+   
+   void prepare(PersistenceManager persistenceManager) throws Exception;
+   
+   void commit(boolean onePhase, PersistenceManager persistenceManager) throws Exception;
+   
+   void rollback(PersistenceManager persistenceManager) throws Exception;   
+   
+   void addMessage(Message message);
+   
+   void addAcknowledgement(MessageReference acknowledgement);   
+   
+   int getAcknowledgementsCount();
+   
+   Xid getXid();
+   
+   boolean isEmpty();
+   
+   void suspend();
+   
+   void resume();
+   
+   boolean isSuspended();
+}

Copied: trunk/src/main/org/jboss/messaging/core/transaction/TransactionSynchronization.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/TransactionSynchronization.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/transaction/TransactionSynchronization.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/transaction/TransactionSynchronization.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.transaction;
+
+/**
+ * 
+ * A TransactionSynchronization
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface TransactionSynchronization
+{
+   void beforeCommit() throws Exception;
+   
+   void afterCommit() throws Exception;
+   
+   void beforeRollback() throws Exception;
+   
+   void afterRollback() throws Exception;
+}

Copied: trunk/src/main/org/jboss/messaging/core/transaction/impl/ResourceManagerImpl.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/impl/ResourceManagerImpl.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/transaction/impl/ResourceManagerImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/transaction/impl/ResourceManagerImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.transaction.impl;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.transaction.ResourceManager;
+import org.jboss.messaging.core.transaction.Transaction;
+
+/**
+ * 
+ * A ResourceManagerImpl
+ * 
+ * TODO - implement timeouts
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class ResourceManagerImpl implements ResourceManager
+{
+   private ConcurrentMap<Xid, Transaction> transactions = new ConcurrentHashMap<Xid, Transaction>();
+   
+   private final int defaultTimeoutSeconds;
+   
+   private volatile int timeoutSeconds;
+   
+   public ResourceManagerImpl(final int defaultTimeoutSeconds)
+   {      
+      this.defaultTimeoutSeconds = defaultTimeoutSeconds;
+   }
+   
+   // ResourceManager implementation ---------------------------------------------
+   
+   public Transaction getTransaction(final Xid xid)
+   {
+      return transactions.get(xid);
+   }
+
+   public boolean putTransaction(final Xid xid, final Transaction tx)
+   {
+      return transactions.putIfAbsent(xid, tx) == null;
+   }
+
+   public boolean removeTransaction(final Xid xid)
+   {
+      return transactions.remove(xid) != null;
+   }
+   
+   public int getTimeoutSeconds()
+   {
+      return this.timeoutSeconds;
+   }
+   
+   public boolean setTimeoutSeconds(final int timeoutSeconds)
+   {
+      if (timeoutSeconds == 0)
+      {
+         //reset to default
+         this.timeoutSeconds = defaultTimeoutSeconds;
+      }
+      else
+      {
+         this.timeoutSeconds = timeoutSeconds;
+      }      
+      
+      return true;
+   }
+}

Copied: trunk/src/main/org/jboss/messaging/core/transaction/impl/TransactionImpl.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/impl/TransactionImpl.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/transaction/impl/TransactionImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/transaction/impl/TransactionImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,279 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.transaction.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.transaction.xa.Xid;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.server.Queue;
+import org.jboss.messaging.core.transaction.Transaction;
+import org.jboss.messaging.core.transaction.TransactionSynchronization;
+
+/**
+ * 
+ * A TransactionImpl
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class TransactionImpl implements Transaction
+{
+   private static final Logger log = Logger.getLogger(TransactionImpl.class);
+   
+   private final List<Message> messagesToAdd = new ArrayList<Message>();
+   
+   private final List<MessageReference> acknowledgements = new ArrayList<MessageReference>();  
+   
+   private final List<TransactionSynchronization> synchronizations = new ArrayList<TransactionSynchronization>();
+   
+   private final Xid xid;
+   
+   private volatile boolean containsPersistent;
+   
+   private volatile boolean prepared;
+   
+   private volatile boolean suspended;
+   
+   public TransactionImpl()
+   {       
+   	this.xid = null;
+   }
+   
+   public TransactionImpl(final Xid xid)
+   {
+      this.xid = xid;      
+   }
+   
+   // Transaction implementation -----------------------------------------------------------
+   
+   public void addMessage(final Message message)
+   {
+      messagesToAdd.add(message);
+      
+      if (message.getNumDurableReferences() != 0)
+      {
+         containsPersistent = true;
+      }
+   }
+   
+   public void addAcknowledgement(final MessageReference acknowledgement)
+   {
+      acknowledgements.add(acknowledgement);
+       
+      if (acknowledgement.getMessage().isDurable() && acknowledgement.getQueue().isDurable())
+      {
+         containsPersistent = true;
+      }
+   }
+      
+   public void addSynchronization(final TransactionSynchronization sync)
+   {
+      synchronizations.add(sync);
+   }
+   
+   public void prepare(final PersistenceManager persistenceManager) throws Exception
+   {
+      if (xid == null)
+      {
+         throw new IllegalStateException("Cannot call prepare() on a non XA transaction");
+      }
+      else if (containsPersistent)
+      {
+         persistenceManager.prepareTransaction(xid, messagesToAdd, acknowledgements);
+      }
+            
+      prepared = true;
+   }
+   
+   public void commit(final boolean onePhase, final PersistenceManager persistenceManager) throws Exception
+   {
+      callSynchronizations(SyncType.BEFORE_COMMIT);
+      
+      if (containsPersistent)
+      {
+         if (xid == null || onePhase)
+         {
+            //1PC commit
+            
+            persistenceManager.commitTransaction(messagesToAdd, acknowledgements);
+         }
+         else
+         {
+            //2PC commit
+            
+            if (!prepared)
+            {
+               throw new IllegalStateException("Transaction is not prepared");
+            }
+            
+            persistenceManager.commitPreparedTransaction(xid);                        
+         } 
+      }
+            
+      for (Message msg: messagesToAdd)
+      {
+         msg.send();
+      }
+      
+      for (MessageReference reference: acknowledgements)
+      {
+         reference.getQueue().decrementDeliveringCount();
+      }
+      
+      callSynchronizations(SyncType.AFTER_COMMIT);
+      
+      clear();      
+   }
+   
+   public void rollback(final PersistenceManager persistenceManager) throws Exception
+   {
+      callSynchronizations(SyncType.BEFORE_ROLLBACK);
+        
+      if (prepared)
+      {
+         persistenceManager.unprepareTransaction(xid, messagesToAdd, acknowledgements);             
+      }
+      
+      cancelDeliveries(persistenceManager);
+                        
+      callSynchronizations(SyncType.AFTER_ROLLBACK);  
+      
+      clear();      
+   }      
+   
+   public int getAcknowledgementsCount()
+   {
+      return acknowledgements.size();
+   }
+   
+   public void suspend()
+   {
+      suspended = true;
+   }
+   
+   public void resume()
+   {
+      suspended = false;
+   }
+   
+   public boolean isSuspended()
+   {
+      return suspended;
+   }
+   
+   public Xid getXid()
+   {
+      return xid;
+   }
+   
+   public boolean isEmpty()
+   {
+      return messagesToAdd.isEmpty() && acknowledgements.isEmpty();
+   }
+   
+   // Private -------------------------------------------------------------------
+   
+   private void callSynchronizations(final SyncType type) throws Exception
+   {
+      for (TransactionSynchronization sync: synchronizations)
+      {
+         if (type == SyncType.BEFORE_COMMIT)
+         {
+            sync.beforeCommit();
+         }
+         else if (type == SyncType.AFTER_COMMIT)
+         {
+            sync.afterCommit();
+         }
+         else if (type == SyncType.BEFORE_ROLLBACK)
+         {
+            sync.beforeRollback();
+         }
+         else if (type == SyncType.AFTER_ROLLBACK)
+         {
+            sync.afterRollback();
+         }            
+      }
+   }
+
+   private void clear()
+   {
+      messagesToAdd.clear();
+      
+      acknowledgements.clear();
+      
+      synchronizations.clear();
+      
+      containsPersistent = false;
+   }
+   
+   private void cancelDeliveries(final PersistenceManager persistenceManager) throws Exception
+   {
+      Map<Queue, LinkedList<MessageReference>> queueMap = new HashMap<Queue, LinkedList<MessageReference>>();
+      
+      //Need to sort into lists - one for each queue involved.
+      //Then cancelling back atomicly for each queue adding list on front to guarantee ordering is preserved      
+      
+      for (MessageReference ref: acknowledgements)
+      {
+         Queue queue = ref.getQueue();
+         
+         LinkedList<MessageReference> list = queueMap.get(queue);
+         
+         if (list == null)
+         {
+            list = new LinkedList<MessageReference>();
+            
+            queueMap.put(queue, list);
+         }
+                 
+         if (ref.cancel(persistenceManager))
+         {
+            list.add(ref);
+         }
+      }
+      
+      for (Map.Entry<Queue, LinkedList<MessageReference>> entry: queueMap.entrySet())
+      {                  
+         LinkedList<MessageReference> refs = entry.getValue();
+                
+         entry.getKey().addListFirst(refs);
+      }
+   }
+   
+   // Inner Enums -------------------------------------------------------------------------------
+   
+   private enum SyncType
+   {
+      BEFORE_COMMIT, AFTER_COMMIT, BEFORE_ROLLBACK, AFTER_ROLLBACK;
+   }
+         
+}

Copied: trunk/src/main/org/jboss/messaging/core/transaction/impl/XidImpl.java (from rev 3822, trunk/src/main/org/jboss/messaging/core/server/impl/XidImpl.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/transaction/impl/XidImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/transaction/impl/XidImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -0,0 +1,197 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.transaction.impl;
+
+import java.io.Serializable;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * 
+ * Xid implementation
+ * 
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
+ * 
+ * @version $Revision 1.1 $
+ */
+public class XidImpl implements Xid, Serializable
+{
+   private static final long serialVersionUID = 407053232840068514L;
+
+   private byte[] branchQualifier;
+   
+   private int formatId;
+   
+   private byte[] globalTransactionId;
+   
+   private int hash;
+   
+   private boolean hashCalculated;
+   
+   /**
+    * Standard constructor
+    * @param branchQualifier
+    * @param formatId
+    * @param globalTransactionId
+    */
+   public XidImpl(final byte[] branchQualifier, final int formatId, final byte[] globalTransactionId)
+   {
+      this.branchQualifier = branchQualifier;
+      this.formatId = formatId;
+      this.globalTransactionId = globalTransactionId;          
+   }
+   
+   /**
+    * Copy constructor
+    * @param other
+    */
+   public XidImpl(final Xid other)
+   {
+      this.branchQualifier = copyBytes(other.getBranchQualifier());
+      this.formatId = other.getFormatId();
+      this.globalTransactionId = copyBytes(other.getGlobalTransactionId());
+   }
+
+   // Xid implementation ------------------------------------------------------------------
+   
+   public byte[] getBranchQualifier()
+   {
+      return branchQualifier;
+   }
+
+   public int getFormatId()
+   {
+      return formatId;
+   }
+
+   public byte[] getGlobalTransactionId()
+   {
+      return globalTransactionId;
+   }
+   
+   // Public -------------------------------------------------------------------------------
+            
+   public int hashCode()
+   {
+      if (!hashCalculated)
+      {
+         calcHash();
+      }
+      return hash;
+   }
+   
+   public boolean equals(Object other)
+   {
+      if (this == other)
+      {
+         return true;
+      }
+      if (!(other instanceof Xid))
+      {
+         return false;
+      }
+      Xid xother = (Xid)other;
+      if (xother.getFormatId() != formatId)
+      {
+         return false;
+      }
+      if (xother.getBranchQualifier().length != this.branchQualifier.length)
+      {
+         return false;
+      }
+      if (xother.getGlobalTransactionId().length != this.globalTransactionId.length)
+      {
+         return false;
+      }
+      for (int i = 0; i < this.branchQualifier.length; i++)
+      {
+         byte[] otherBQ = xother.getBranchQualifier();
+         if (this.branchQualifier[i] != otherBQ[i])
+         {
+            return false;
+         }         
+      }
+      for (int i = 0; i < this.globalTransactionId.length; i++)
+      {
+         byte[] otherGtx = xother.getGlobalTransactionId();
+         if (this.globalTransactionId[i] != otherGtx[i])
+         {
+            return false;
+         }
+      }
+      return true;
+   }
+
+   public String toString()
+   {
+     	return "XidImpl (" + System.identityHashCode(this) + " bq:" + stringRep(branchQualifier) +
+     	" formatID:" + formatId + " gtxid:" + stringRep(globalTransactionId);
+   }
+   
+   // Private -------------------------------------------------------------------------------
+   
+   private String stringRep(final byte[] bytes)
+   {
+      StringBuffer buff = new StringBuffer();
+      for (int i = 0; i < bytes.length; i++)
+      {
+         byte b = bytes[i];
+         
+         buff.append(b);
+         
+         if (i != bytes.length - 1)
+         {
+            buff.append('.');
+         }
+      }
+      
+      return buff.toString();
+   }
+   
+   private void calcHash()
+   {
+      byte[] hashBytes = new byte[branchQualifier.length + globalTransactionId.length + 4];
+      System.arraycopy(branchQualifier, 0, hashBytes, 0, branchQualifier.length);
+      System.arraycopy(globalTransactionId, 0, hashBytes, branchQualifier.length, globalTransactionId.length);
+      byte[] intBytes = new byte[4];
+      for (int i = 0; i < 4; i++)
+      {
+         intBytes[i] = (byte)((formatId >> (i * 8)) % 0xFF);
+      }
+      System.arraycopy(intBytes, 0, hashBytes, branchQualifier.length + globalTransactionId.length, 4);
+      String s = new String(hashBytes);
+      hash = s.hashCode();
+      hashCalculated = true;
+   }
+   
+   private byte[] copyBytes(byte[] other)
+   {
+      byte[] bytes = new byte[other.length];
+      
+      System.arraycopy(other, 0, bytes, 0, other.length);
+      
+      return bytes;
+   }
+
+}

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -76,7 +76,7 @@
       super(JBossBytesMessage.TYPE);
    }
 
-   public JBossBytesMessage(org.jboss.messaging.core.server.Message message, ClientSession session)
+   public JBossBytesMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
    {
       super(message, session);
    }

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossMapMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossMapMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossMapMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -70,7 +70,7 @@
       super(JBossMapMessage.TYPE);
    }
    
-   public JBossMapMessage(org.jboss.messaging.core.server.Message message, ClientSession session)
+   public JBossMapMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
    {
       super(message, session);
    }

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -40,8 +40,8 @@
 
 import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.server.MessagingException;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 
 /**
  * 
@@ -117,7 +117,7 @@
    private static final Logger log = Logger.getLogger(JBossMessage.class);
 
    
-   public static JBossMessage createMessage(org.jboss.messaging.core.server.Message message, ClientSession session)
+   public static JBossMessage createMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
    {
       int type = message.getType();
       
@@ -155,7 +155,7 @@
    // Attributes ----------------------------------------------------
 
    //The underlying message
-   protected org.jboss.messaging.core.server.Message message;
+   protected org.jboss.messaging.core.message.Message message;
    
    private ClientSession session;
    
@@ -177,7 +177,7 @@
    /**
     * Constructor for when receiving a message from the server
     */
-   public JBossMessage(org.jboss.messaging.core.server.Message message, ClientSession session)
+   public JBossMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
    {
       this.message = message;
       
@@ -757,7 +757,7 @@
     
    // Public --------------------------------------------------------
    
-   public org.jboss.messaging.core.server.Message getCoreMessage()
+   public org.jboss.messaging.core.message.Message getCoreMessage()
    {
       return message;
    }

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossMessageConsumer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossMessageConsumer.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossMessageConsumer.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -200,7 +200,7 @@
    {
       try
       {
-         org.jboss.messaging.core.server.Message message =  consumer.receive(timeout);
+         org.jboss.messaging.core.message.Message message =  consumer.receive(timeout);
                
          JBossMessage jbm = null;
          

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossObjectMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossObjectMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossObjectMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -64,7 +64,7 @@
       super(JBossObjectMessage.TYPE);
    }
    
-   public JBossObjectMessage(org.jboss.messaging.core.server.Message message, ClientSession session)
+   public JBossObjectMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
    {
       super(message, session);
    }

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossQueueBrowser.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossQueueBrowser.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossQueueBrowser.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -29,7 +29,7 @@
 
 import org.jboss.messaging.core.client.ClientBrowser;
 import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -74,7 +74,7 @@
       super(JBossStreamMessage.TYPE);
    }
    
-   public JBossStreamMessage(org.jboss.messaging.core.server.Message message, ClientSession session)
+   public JBossStreamMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
    {
       super(message, session);
    }

Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossTextMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossTextMessage.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossTextMessage.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -69,7 +69,7 @@
       super(JBossTextMessage.TYPE);
    }
    
-   public JBossTextMessage(org.jboss.messaging.core.server.Message message, ClientSession session)
+   public JBossTextMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
    {
       super(message, session);
    }

Modified: trunk/src/main/org/jboss/messaging/jms/client/JMSMessageListenerWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JMSMessageListenerWrapper.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/client/JMSMessageListenerWrapper.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -26,7 +26,7 @@
 
 import org.jboss.messaging.core.client.MessageHandler;
 import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.server.MessagingException;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerManagerImpl.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerManagerImpl.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -36,17 +36,17 @@
 
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
 import org.jboss.messaging.core.management.MessagingServerManagement;
 import org.jboss.messaging.core.messagecounter.MessageCounter;
-import org.jboss.messaging.core.server.Filter;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.ServerConnection;
 import org.jboss.messaging.core.server.ServerSession;
 import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.JBossTemporaryQueue;
+import org.jboss.messaging.jms.JBossTemporaryTopic;
 import org.jboss.messaging.jms.JBossTopic;
-import org.jboss.messaging.jms.JBossTemporaryTopic;
-import org.jboss.messaging.jms.JBossTemporaryQueue;
 import org.jboss.messaging.jms.client.JBossConnectionFactory;
 import org.jboss.messaging.jms.client.JBossMessage;
 import org.jboss.messaging.jms.server.ConnectionInfo;
@@ -591,8 +591,8 @@
             filter = new FilterImpl("JBMDurable='NON_DURABLE'");
             break;
       }
-      List<org.jboss.messaging.core.server.Message> messageList = messagingServerManagement.listMessages(queue, filter);
-      for (org.jboss.messaging.core.server.Message message : messageList)
+      List<org.jboss.messaging.core.message.Message> messageList = messagingServerManagement.listMessages(queue, filter);
+      for (org.jboss.messaging.core.message.Message message : messageList)
       {
          messages.add(JBossMessage.createMessage(message, null));
       }

Modified: trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/QueueSettingsDeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/QueueSettingsDeployerTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/deployers/impl/test/unit/QueueSettingsDeployerTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -26,9 +26,9 @@
 import org.easymock.EasyMock;
 import org.easymock.IArgumentMatcher;
 import org.jboss.messaging.core.deployers.impl.QueueSettingsDeployer;
-import org.jboss.messaging.core.server.PostOffice;
+import org.jboss.messaging.core.postoffice.PostOffice;
+import org.jboss.messaging.core.postoffice.impl.BindingImpl;
 import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.impl.BindingImpl;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
 import org.jboss.messaging.core.settings.impl.QueueSettings;
 import org.jboss.messaging.util.XMLUtil;

Modified: trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/filter/impl/test/unit/FilterTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -21,11 +21,11 @@
   */
 package org.jboss.messaging.core.filter.impl.test.unit;
 
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.server.MessagingException;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.test.messaging.JBMBaseTestCase;
 
 /**

Modified: trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEEnvironmentTestBase.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -29,7 +29,7 @@
 import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEDatabase;
 import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
 import org.jboss.messaging.core.persistence.impl.bdbje.BDBJETransaction;
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 import org.jboss.messaging.test.unit.UnitTestCase;
 
 import com.sleepycat.je.DatabaseException;

Modified: trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/persistence/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -30,16 +30,16 @@
 import javax.transaction.xa.Xid;
 
 import org.jboss.messaging.core.filter.impl.FilterImpl;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEDatabase;
 import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEEnvironment;
 import org.jboss.messaging.core.persistence.impl.bdbje.BDBJEPersistenceManager;
 import org.jboss.messaging.core.persistence.impl.bdbje.test.unit.fakes.FakeBDBJEEnvironment;
-import org.jboss.messaging.core.server.Binding;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.postoffice.impl.BindingImpl;
 import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.impl.BindingImpl;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.messaging.core.server.impl.QueueImpl;
 import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeQueueFactory;
 import org.jboss.messaging.test.unit.UnitTestCase;

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/impl/integration/DummyInterceptor.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/integration/DummyInterceptor.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/integration/DummyInterceptor.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -11,7 +11,7 @@
 
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.Interceptor;
-import org.jboss.messaging.core.remoting.impl.wireformat.DeliverMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerDeliverMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.Packet;
 import org.jboss.messaging.core.server.MessagingException;
 
@@ -43,9 +43,9 @@
       }
       if (changeMessage)
       {
-         if (packet instanceof DeliverMessage)
+         if (packet instanceof ConsumerDeliverMessage)
          {
-            DeliverMessage deliver = (DeliverMessage)packet;
+            ConsumerDeliverMessage deliver = (ConsumerDeliverMessage)packet;
             log.info("msg = " + deliver.getMessage().getClass().getName());
             deliver.getMessage().getHeaders().put("DummyInterceptor", "was here");
          }

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/CodecAssert.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -8,7 +8,7 @@
 
 import junit.framework.Assert;
 
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/impl/wireformat/test/unit/PacketTypeTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -23,6 +23,7 @@
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONN_CREATESESSION_RESP;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONN_START;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONN_STOP;
+import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONS_DELIVER;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONS_FLOWTOKEN;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CREATECONNECTION;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CREATECONNECTION_RESP;
@@ -51,7 +52,6 @@
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEPRODUCER_RESP;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEQUEUE;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_DELETE_QUEUE;
-import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_DELIVER;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_QUEUEQUERY;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_QUEUEQUERY_RESP;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_RECOVER;
@@ -75,7 +75,6 @@
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_XA_SUSPEND;
 import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.TEXT;
 import static org.jboss.messaging.core.remoting.impl.wireformat.test.unit.CodecAssert.assertEqualsByteArrays;
-import static org.jboss.messaging.test.unit.RandomUtil.randomByte;
 import static org.jboss.messaging.test.unit.RandomUtil.randomBytes;
 import static org.jboss.messaging.test.unit.RandomUtil.randomInt;
 import static org.jboss.messaging.test.unit.RandomUtil.randomLong;
@@ -91,16 +90,19 @@
 
 import org.apache.mina.common.IoBuffer;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec;
 import org.jboss.messaging.core.remoting.impl.codec.BytesPacketCodec;
 import org.jboss.messaging.core.remoting.impl.codec.ConnectionCreateSessionMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.ConnectionCreateSessionResponseMessageCodec;
+import org.jboss.messaging.core.remoting.impl.codec.ConsumerDeliverMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.ConsumerFlowTokenMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.CreateConnectionMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.CreateConnectionResponseMessageCodec;
-import org.jboss.messaging.core.remoting.impl.codec.DeliverMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.PingCodec;
 import org.jboss.messaging.core.remoting.impl.codec.PongCodec;
+import org.jboss.messaging.core.remoting.impl.codec.ProducerReceiveTokensMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.ProducerSendMessageCodec;
 import org.jboss.messaging.core.remoting.impl.codec.RemotingBuffer;
 import org.jboss.messaging.core.remoting.impl.codec.SessionAcknowledgeMessageCodec;
@@ -146,14 +148,15 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionStartMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionStopMessage;
+import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerDeliverMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerFlowTokenMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionRequest;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionResponse;
-import org.jboss.messaging.core.remoting.impl.wireformat.DeliverMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.NullPacket;
 import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
 import org.jboss.messaging.core.remoting.impl.wireformat.Ping;
 import org.jboss.messaging.core.remoting.impl.wireformat.Pong;
+import org.jboss.messaging.core.remoting.impl.wireformat.ProducerReceiveTokensMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ProducerSendMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionAcknowledgeMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionAddAddressMessage;
@@ -198,8 +201,6 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAStartMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASuspendMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.TextPacket;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.messaging.test.unit.RandomUtil;
 import org.jboss.messaging.test.unit.UnitTestCase;
 import org.jboss.messaging.util.StreamUtils;
@@ -207,6 +208,8 @@
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
  * 
+ * FIXME - tidy up tests so test names match the actual packets
+ * 
  * @version <tt>$Revision$</tt>
  */
 public class PacketTypeTest extends UnitTestCase
@@ -632,12 +635,13 @@
    
    public void testCreateProducerResponse() throws Exception
    {
-      SessionCreateProducerResponseMessage response = new SessionCreateProducerResponseMessage(randomString());
+      SessionCreateProducerResponseMessage response =
+      	new SessionCreateProducerResponseMessage(randomString(), randomInt());
 
       AbstractPacketCodec codec = new SessionCreateProducerResponseMessageCodec();
       SimpleRemotingBuffer buffer = encode(response, codec);
       checkHeader(buffer, response);
-      checkBody(buffer, response.getProducerID());
+      checkBody(buffer, response.getProducerID(), response.getInitialTokens());
       buffer.rewind();
 
       AbstractPacket decodedPacket = codec.decode(buffer);
@@ -645,7 +649,8 @@
       assertTrue(decodedPacket instanceof SessionCreateProducerResponseMessage);
       SessionCreateProducerResponseMessage decodedResponse = (SessionCreateProducerResponseMessage) decodedPacket;
       assertEquals(SESS_CREATEPRODUCER_RESP, decodedResponse.getType());
-      assertEquals(response.getProducerID(), decodedResponse.getProducerID());;
+      assertEquals(response.getProducerID(), decodedResponse.getProducerID());
+      assertEquals(response.getInitialTokens(), decodedResponse.getInitialTokens());
    }
 
    public void testStartConnectionMessage() throws Exception
@@ -698,13 +703,30 @@
       assertEquals(CONS_FLOWTOKEN, decodedMessage.getType());
       assertEquals(message.getTokens(), decodedMessage.getTokens());
    }
+   
+   public void testProducerReceiveTokensMessage() throws Exception
+   {
+   	ProducerReceiveTokensMessage message = new ProducerReceiveTokensMessage(10);
+      AbstractPacketCodec codec = new ProducerReceiveTokensMessageCodec();
+      SimpleRemotingBuffer buffer = encode(message, codec);
+      checkHeader(buffer, message);
+      checkBody(buffer, message.getTokens());
+      buffer.rewind();
 
+      AbstractPacket decodedPacket = codec.decode(buffer);
+
+      assertTrue(decodedPacket instanceof ProducerReceiveTokensMessage);
+      ProducerReceiveTokensMessage decodedMessage = (ProducerReceiveTokensMessage) decodedPacket;
+      assertEquals(PacketType.PROD_RECEIVETOKENS, decodedMessage.getType());
+      assertEquals(message.getTokens(), decodedMessage.getTokens());
+   }
+
    public void testDeliverMessage() throws Exception
    {
       Message msg = new MessageImpl();
-      DeliverMessage message = new DeliverMessage(msg, randomLong());
+      ConsumerDeliverMessage message = new ConsumerDeliverMessage(msg, randomLong());
 
-      AbstractPacketCodec codec = new DeliverMessageCodec();
+      AbstractPacketCodec codec = new ConsumerDeliverMessageCodec();
       SimpleRemotingBuffer buffer = encode(message, codec);
       checkHeader(buffer, message);
       checkBody(buffer, StreamUtils.toBytes(msg), message.getDeliveryID());
@@ -712,9 +734,9 @@
 
       AbstractPacket decodedPacket = codec.decode(buffer);
 
-      assertTrue(decodedPacket instanceof DeliverMessage);
-      DeliverMessage decodedMessage = (DeliverMessage) decodedPacket;
-      assertEquals(SESS_DELIVER, decodedMessage.getType());
+      assertTrue(decodedPacket instanceof ConsumerDeliverMessage);
+      ConsumerDeliverMessage decodedMessage = (ConsumerDeliverMessage) decodedPacket;
+      assertEquals(CONS_DELIVER, decodedMessage.getType());
       assertEquals(message.getMessage().getMessageID(), decodedMessage
             .getMessage().getMessageID());
       assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
@@ -1446,7 +1468,7 @@
       assertEquals(message.getAddress(), decodedMessage.getAddress());        
    }
    
-   public void testBindingQueryRequest() throws Exception
+   public void testSessionBindingQueryMessage() throws Exception
    {
       SessionBindingQueryMessage message = new SessionBindingQueryMessage(randomString());
 
@@ -1465,7 +1487,7 @@
       assertEquals(message.getAddress(), decodedMessage.getAddress());        
    }
    
-   public void testBindingQueryResponse() throws Exception
+   public void testSessionBindingQueryResponseMessage() throws Exception
    {
       boolean exists = true;
       List<String> queueNames = new ArrayList<String>();

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSL.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSL.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSL.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -33,9 +33,9 @@
 import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
 import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.messaging.core.server.impl.MessagingServerImpl;
 import org.jboss.messaging.jms.client.JBossTextMessage;
 

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSLTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSLTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/ssl/integration/CoreClientOverSSLTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -31,8 +31,8 @@
 import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.remoting.impl.RemotingConfiguration;
-import org.jboss.messaging.core.server.Message;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.core.server.impl.MessagingServerImpl;
 import org.jboss.test.messaging.jms.SerializedClientSupport;

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/concurrent/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/concurrent/QueueTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/concurrent/QueueTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -24,9 +24,9 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.server.HandleStatus;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
 import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeConsumer;

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/timing/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/timing/QueueTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/timing/QueueTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -27,7 +27,7 @@
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 
 import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.impl.QueueImpl;
 import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeConsumer;

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessageTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessageTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -28,11 +28,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
-import org.jboss.messaging.core.server.impl.MessageImpl;
 import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeQueueFactory;
 import org.jboss.messaging.test.unit.UnitTestCase;
 import org.jboss.messaging.util.StreamUtils;

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessagingXidTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessagingXidTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/MessagingXidTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -28,7 +28,7 @@
 
 import javax.transaction.xa.Xid;
 
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 import org.jboss.messaging.test.unit.RandomUtil;
 import org.jboss.messaging.test.unit.UnitTestCase;
 

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/PostOfficeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/PostOfficeTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/PostOfficeTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -25,15 +25,15 @@
 import java.util.Map;
 
 import org.easymock.EasyMock;
-import org.jboss.messaging.core.server.Binding;
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.PersistenceManager;
-import org.jboss.messaging.core.server.PostOffice;
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.persistence.PersistenceManager;
+import org.jboss.messaging.core.postoffice.Binding;
+import org.jboss.messaging.core.postoffice.PostOffice;
+import org.jboss.messaging.core.postoffice.impl.BindingImpl;
+import org.jboss.messaging.core.postoffice.impl.PostOfficeImpl;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
-import org.jboss.messaging.core.server.impl.BindingImpl;
-import org.jboss.messaging.core.server.impl.PostOfficeImpl;
 import org.jboss.messaging.core.server.impl.test.unit.fakes.FakeQueueFactory;
 import org.jboss.messaging.test.unit.UnitTestCase;
 

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/QueueTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/QueueTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -27,11 +27,11 @@
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.server.Consumer;
 import org.jboss.messaging.core.server.DistributionPolicy;
-import org.jboss.messaging.core.server.Filter;
 import org.jboss.messaging.core.server.HandleStatus;
-import org.jboss.messaging.core.server.MessageReference;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.impl.QueueImpl;
 import org.jboss.messaging.core.server.impl.RoundRobinDistributionPolicy;

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/TransactionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/TransactionTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/TransactionTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -8,17 +8,17 @@
 import javax.transaction.xa.Xid;
 
 import org.easymock.EasyMock;
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
-import org.jboss.messaging.core.server.PersistenceManager;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.persistence.PersistenceManager;
 import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.Transaction;
-import org.jboss.messaging.core.server.TransactionSynchronization;
 import org.jboss.messaging.core.server.impl.QueueImpl;
-import org.jboss.messaging.core.server.impl.TransactionImpl;
 import org.jboss.messaging.core.settings.HierarchicalRepository;
 import org.jboss.messaging.core.settings.impl.HierarchicalObjectRepository;
 import org.jboss.messaging.core.settings.impl.QueueSettings;
+import org.jboss.messaging.core.transaction.Transaction;
+import org.jboss.messaging.core.transaction.TransactionSynchronization;
+import org.jboss.messaging.core.transaction.impl.TransactionImpl;
 import org.jboss.messaging.test.unit.UnitTestCase;
 
 /**

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeConsumer.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeConsumer.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeConsumer.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -24,10 +24,10 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.message.MessageReference;
 import org.jboss.messaging.core.server.Consumer;
-import org.jboss.messaging.core.server.Filter;
 import org.jboss.messaging.core.server.HandleStatus;
-import org.jboss.messaging.core.server.MessageReference;
 
 /**
  * 

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeFilter.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeFilter.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeFilter.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -21,8 +21,8 @@
  */
 package org.jboss.messaging.core.server.impl.test.unit.fakes;
 
-import org.jboss.messaging.core.server.Filter;
-import org.jboss.messaging.core.server.Message;
+import org.jboss.messaging.core.filter.Filter;
+import org.jboss.messaging.core.message.Message;
 
 /**
  * 

Modified: trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeQueueFactory.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeQueueFactory.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/core/server/impl/test/unit/fakes/FakeQueueFactory.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -24,7 +24,7 @@
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 
-import org.jboss.messaging.core.server.Filter;
+import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
 import org.jboss.messaging.core.server.impl.QueueImpl;

Modified: trunk/tests/src/org/jboss/messaging/test/unit/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/test/unit/UnitTestCase.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/messaging/test/unit/UnitTestCase.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -34,11 +34,11 @@
 
 import junit.framework.TestCase;
 
-import org.jboss.messaging.core.server.Message;
-import org.jboss.messaging.core.server.MessageReference;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.message.impl.MessageImpl;
 import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.core.server.impl.MessageImpl;
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 
 /**
  * 

Modified: trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/test/messaging/jms/SecurityTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -43,7 +43,7 @@
 
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.security.Role;
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 import org.jboss.messaging.jms.client.JBossConnectionFactory;
 import org.jboss.test.messaging.tools.ServerManagement;
 

Modified: trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -33,7 +33,7 @@
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 
 import com.arjuna.ats.arjuna.common.Uid;
 import com.arjuna.ats.jta.xa.XidImple;

Modified: trunk/tests/src/org/jboss/test/messaging/jms/XATest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XATest.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XATest.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -44,7 +44,7 @@
 
 import org.jboss.messaging.core.client.impl.ClientSessionImpl;
 import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 import org.jboss.messaging.jms.client.JBossConnectionFactory;
 import org.jboss.test.messaging.JBMServerTestCase;
 import org.jboss.test.messaging.tools.ServerManagement;

Modified: trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCReceiver.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCReceiver.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCReceiver.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -27,7 +27,7 @@
 import javax.transaction.xa.XAResource;
 
 import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 import org.jboss.util.id.GUID;
 
 /**

Modified: trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCSender.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCSender.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/test/messaging/jms/stress/Transactional2PCSender.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -27,7 +27,7 @@
 import javax.transaction.xa.XAResource;
 
 import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.impl.XidImpl;
+import org.jboss.messaging.core.transaction.impl.XidImpl;
 import org.jboss.util.id.GUID;
 
 /**

Modified: trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java	2008-02-28 09:54:57 UTC (rev 3826)
+++ trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java	2008-02-28 10:54:03 UTC (rev 3827)
@@ -44,8 +44,8 @@
 import org.jboss.kernel.spi.deployment.KernelDeployment;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.management.MessagingServerManagement;
+import org.jboss.messaging.core.postoffice.Binding;
 import org.jboss.messaging.core.security.Role;
-import org.jboss.messaging.core.server.Binding;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.core.settings.impl.QueueSettings;
 import org.jboss.messaging.jms.server.JMSServerManager;




More information about the jboss-cvs-commits mailing list