[jboss-cvs] JBoss Messaging SVN: r5821 - in trunk: src/config and 31 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 5 12:39:26 EST 2009


Author: timfox
Date: 2009-02-05 12:39:25 -0500 (Thu, 05 Feb 2009)
New Revision: 5821

Added:
   trunk/src/main/org/jboss/messaging/core/remoting/server/
   trunk/src/main/org/jboss/messaging/core/remoting/server/DelayedResult.java
   trunk/src/main/org/jboss/messaging/core/remoting/server/RemotingService.java
   trunk/src/main/org/jboss/messaging/core/remoting/server/impl/
   trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java
   trunk/src/main/org/jboss/messaging/core/server/cluster/MessageFlowRecord.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SymmetricClusterTest.java
Removed:
   trunk/src/main/org/jboss/messaging/core/client/ServerPinger.java
   trunk/src/main/org/jboss/messaging/core/remoting/DelayedResult.java
   trunk/src/main/org/jboss/messaging/core/remoting/RemotingService.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingServiceImpl.java
Modified:
   trunk/.classpath
   trunk/src/config/jbm-cluster-standalone-beans.xml
   trunk/src/config/jbm-jboss-beans.xml
   trunk/src/config/jbm-standalone-beans.xml
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionFactoryImpl.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionInternal.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManager.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java
   trunk/src/main/org/jboss/messaging/core/client/management/impl/ManagementHelper.java
   trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java
   trunk/src/main/org/jboss/messaging/core/filter/impl/Operator.java
   trunk/src/main/org/jboss/messaging/core/management/ManagementService.java
   trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
   trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
   trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
   trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java
   trunk/src/main/org/jboss/messaging/core/postoffice/Bindings.java
   trunk/src/main/org/jboss/messaging/core/postoffice/QueueInfo.java
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingsImpl.java
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/DivertBinding.java
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/LocalQueueBinding.java
   trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/Channel.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConnectionImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMAcceptor.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnection.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnector.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnectorFactory.java
   trunk/src/main/org/jboss/messaging/core/server/Messaging.java
   trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
   trunk/src/main/org/jboss/messaging/core/server/cluster/impl/BridgeImpl.java
   trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterConnectionImpl.java
   trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterManagerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/cluster/impl/RemoteQueueBindingImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerPacketHandler.java
   trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServiceImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
   trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
   trunk/src/main/org/jboss/messaging/integration/transports/netty/MessagingChannelHandler.java
   trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyAcceptor.java
   trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyConnection.java
   trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyConnector.java
   trunk/src/main/org/jboss/messaging/util/SimpleString.java
   trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/MessageChunkTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/BridgeStartTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/ClusterTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/OnewayTwoNodeClusterTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ActivationTimeoutTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/AutomaticFailoverWithDiscoveryTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailBackupServerTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverExpiredMessageTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverManagementTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverNoSessionsFailoverTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverPreAcknowledgeTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverScheduledMessageTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailureListenerOnFailoverTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailureOnCreateConnectionTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/RandomFailoverTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReconnectTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReconnectWithBackupTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReplicateConnectionFailureTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleAutomaticFailoverTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleManualFailoverTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/cluster/management/ReplicationAwareTestBase.java
   trunk/tests/src/org/jboss/messaging/tests/integration/jms/cluster/JMSFailoverTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/paging/PageCrashTest.java
   trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServiceImplTest.java
Log:
more clustering

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/.classpath	2009-02-05 17:39:25 UTC (rev 5821)
@@ -61,7 +61,6 @@
 	<classpathentry kind="lib" path="tests/tmpfiles"/>
 	<classpathentry kind="lib" path="thirdparty/netty/lib/netty-3.1.0.ALPHA2.jar"/>
 	<classpathentry kind="lib" path="thirdparty/apache-mina/lib/mina-core-2.0.0-M4.jar"/>
-	<classpathentry kind="lib" path="thirdparty/slf4j/api/lib/slf4j-api-1.5.2.jar"/>
 	<classpathentry kind="lib" path="thirdparty/slf4j/log4j/lib/slf4j-log4j12-1.5.2.jar"/>
 	<classpathentry kind="output" path="eclipse-output"/>
 </classpath>

Modified: trunk/src/config/jbm-cluster-standalone-beans.xml
===================================================================
--- trunk/src/config/jbm-cluster-standalone-beans.xml	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/config/jbm-cluster-standalone-beans.xml	2009-02-05 17:39:25 UTC (rev 5821)
@@ -72,7 +72,7 @@
       </constructor>
    </bean>
 
-   <bean name="RemotingService" class="org.jboss.messaging.core.remoting.impl.RemotingServiceImpl">
+   <bean name="RemotingService" class="org.jboss.messaging.core.remoting.server.impl.RemotingServiceImpl">
       <constructor>
          <parameter>
             <inject bean="Configuration"/>

Modified: trunk/src/config/jbm-jboss-beans.xml
===================================================================
--- trunk/src/config/jbm-jboss-beans.xml	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/config/jbm-jboss-beans.xml	2009-02-05 17:39:25 UTC (rev 5821)
@@ -57,7 +57,7 @@
       </constructor>
    </bean>
 
-   <bean name="RemotingService" class="org.jboss.messaging.core.remoting.impl.RemotingServiceImpl">
+   <bean name="RemotingService" class="org.jboss.messaging.core.remoting.server.impl.RemotingServiceImpl">
       <constructor>
          <parameter>
             <inject bean="Configuration"/>

Modified: trunk/src/config/jbm-standalone-beans.xml
===================================================================
--- trunk/src/config/jbm-standalone-beans.xml	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/config/jbm-standalone-beans.xml	2009-02-05 17:39:25 UTC (rev 5821)
@@ -72,7 +72,7 @@
       </constructor>
    </bean>
 
-   <bean name="RemotingService" class="org.jboss.messaging.core.remoting.impl.RemotingServiceImpl">
+   <bean name="RemotingService" class="org.jboss.messaging.core.remoting.server.impl.RemotingServiceImpl">
       <constructor>
          <parameter>
             <inject bean="Configuration"/>

Deleted: trunk/src/main/org/jboss/messaging/core/client/ServerPinger.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ServerPinger.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/client/ServerPinger.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -1,30 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */ 
-
-package org.jboss.messaging.core.client;
-
-/**
- * @author <a href="ataylor at redhat.com">Andy Taylor</a>
- */
-public interface ServerPinger extends Runnable
-{
-}

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientConsumerInternal.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -53,7 +53,7 @@
 
    int getCreditsToSend();
 
-   void cleanUp() throws Exception;
+   void cleanUp() throws MessagingException;
    
    void acknowledge(ClientMessage message) throws MessagingException;
    

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionFactoryImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionFactoryImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionFactoryImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -752,8 +752,15 @@
             log.error("Failed to stop discovery group", e);
          }
       }
+      
+      for (ConnectionManager connectionManager : connectionManagerMap.values())
+      {
+         connectionManager.close();
+      }
+      
+      connectionManagerMap.clear();
    }
-
+   
    // DiscoveryListener implementation --------------------------------------------------------
 
    public synchronized void connectorsChanged()

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionInternal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionInternal.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientSessionInternal.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -48,4 +48,6 @@
    void handleFailover(RemotingConnection backupConnection);
 
    RemotingConnection getConnection();
+   
+   void cleanUp() throws Exception;
 }

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManager.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManager.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -58,4 +58,6 @@
    int numConnections();
 
    int numSessions();
+   
+   void close();
 }

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionManagerImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -32,8 +32,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.Collection;
-import java.util.ConcurrentModificationException;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.locks.Lock;
 
@@ -127,6 +125,8 @@
 
    private final int maxRetriesAfterFailover;
 
+   private volatile boolean closed;
+
    // Static
    // ---------------------------------------------------------------------------------------
 
@@ -191,7 +191,7 @@
       // being returned from the client side so we need to fail the conn and
       // call it's listeners
       if (connections.containsKey(connectionID))
-      {
+      {        
          MessagingException me = new MessagingException(MessagingException.OBJECT_CLOSED,
                                                         "The conn has been closed by the server");
 
@@ -200,12 +200,12 @@
    }
 
    public void connectionException(final Object connectionID, final MessagingException me)
-   {            
+   {
       failConnection(me);
    }
 
    // ConnectionManager implementation ------------------------------------------------------------------
-   
+
    public ClientSession createSession(final String username,
                                       final String password,
                                       final boolean xa,
@@ -243,6 +243,12 @@
                synchronized (failoverLock)
                {
                   connection = getConnectionForCreateSession();
+                  
+                  if (connection == null)
+                  {
+                     //This can happen if the connection manager gets closed - e.g. the server gets shut down
+                     return null;
+                  }
 
                   channel1 = connection.getChannel(1, -1, false);
 
@@ -394,6 +400,11 @@
       return sessions.size();
    }
 
+   public void close()
+   {
+      closed = true;
+   }
+
    // FailureListener implementation --------------------------------------------------------
 
    public boolean connectionFailed(final MessagingException me)
@@ -404,10 +415,10 @@
          // The server has closed the connection. We don't want failover to occur in this case -
          // either the server has booted off the connection, or it didn't receive a ping in time
          // in either case server side resources on both live and backup will be removed so the client
-         // can't failover anyway
+         // can't failover automatically anyway
          return true;
       }
-      
+
       return !failover();
    }
 
@@ -424,37 +435,53 @@
    // --------------------------------------------------------------------------------------
 
    private RemotingConnection getConnectionForCreateSession() throws MessagingException
-   {      
+   {
+      boolean retried = false;
+
       while (true)
-      {         
+      {
+         if (closed)
+         {
+            log.warn("ConnectionManager is now closed");
+
+            return null;
+         }
+
          RemotingConnection connection = getConnection(1);
-   
+
          if (connection == null)
          {
             // Connection is dead - failover/reconnect
             boolean failedOver = failover();
-                               
+
             if (!failedOver)
             {
-               //Nothing we can do here
-               throw new MessagingException(MessagingException.NOT_CONNECTED, "Unabled to create session - server is unavailable and no backup server or backup is unavailable");
+               // Nothing we can do here
+               throw new MessagingException(MessagingException.NOT_CONNECTED,
+                                            "Unabled to create session - server is unavailable and no backup server or backup is unavailable");
             }
-            
+
             try
             {
                Thread.sleep(retryInterval);
             }
             catch (Exception ignore)
-            {              
+            {
             }
+
+            retried = true;
          }
          else
          {
+            if (retried)
+            {
+               log.info("Reconnected successfully");
+            }
             return connection;
          }
       }
    }
-   
+
    private boolean failover()
    {
       synchronized (failoverLock)
@@ -589,6 +616,10 @@
                   log.info("Unable to failover/reconnect");
                }
             }
+            else
+            {
+               log.info("succeeded in reconnecting to node");
+            }
 
             for (RemotingConnection connection : oldConnections)
             {
@@ -685,13 +716,20 @@
    }
 
    private RemotingConnection getConnectionWithRetry(final List<ClientSessionInternal> sessions, final int retries)
-   {      
+   {
       long interval = retryInterval;
 
       int count = 0;
 
       while (true)
       {
+         if (closed)
+         {
+            log.warn("ConnectionManager is now closed");
+
+            return null;
+         }
+
          RemotingConnection connection = getConnection(sessions.size());
 
          if (connection == null)
@@ -699,9 +737,9 @@
             // Failed to get backup connection
 
             if (retries != 0)
-            {              
+            {
                count++;
-               
+
                if (retries != -1 && count == retries)
                {
                   log.warn("Retried " + retries + " times to reconnect. Now giving up.");
@@ -733,7 +771,7 @@
          }
       }
    }
-   
+
    private void checkCloseConnections()
    {
       if (refCount == 0)
@@ -762,42 +800,46 @@
    }
 
    private RemotingConnection getConnection(final int count)
-   {      
+   {
       RemotingConnection conn;
-           
+
       if (connections.size() < maxConnections)
       {
          // Create a new one
-         
+
          DelegatingBufferHandler handler = new DelegatingBufferHandler();
-                 
-         Connector connector;
-         
-         Connection tc;
-         
+
+         Connector connector = null;
+
+         Connection tc = null;
+
          try
          {
             connector = connectorFactory.createConnector(transportParams, handler, this);
 
-            connector.start();
-                        
-            tc = connector.createConnection();
+            if (connector != null)
+            {
+               connector.start();
+
+               tc = connector.createConnection();
+            }
          }
          catch (Exception e)
          {
-            //Sanity catch for badly behaved remoting plugins
-            
-            log.warn("connector.create or connectorFactory.createConnector should never throw an exception, implementation is badly behaved, but we'll deal with it anyway.");
-            
+            // Sanity catch for badly behaved remoting plugins
+
+            log.warn("connector.create or connectorFactory.createConnector should never throw an exception, implementation is badly behaved, but we'll deal with it anyway.",
+                     e);
+
             tc = null;
-            
+
             connector = null;
          }
 
          if (tc == null)
          {
             return null;
-         }                 
+         }
 
          conn = new RemotingConnectionImpl(tc, callTimeout, pingPeriod, connectionTTL, pingExecutor, null);
 
@@ -932,6 +974,4 @@
       }
    }
 
-
-  
 }

Modified: trunk/src/main/org/jboss/messaging/core/client/management/impl/ManagementHelper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/management/impl/ManagementHelper.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/client/management/impl/ManagementHelper.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -71,6 +71,8 @@
    public static final SimpleString HDR_BINDING_ID = new SimpleString("_JBM_Binding_ID");
    
    public static final SimpleString HDR_FILTERSTRING = new SimpleString("_JBM_FilterString");
+   
+   public static final SimpleString HDR_ORIGINATING_NODE = new SimpleString("_JBM_OrigNode");
 
    // Attributes ----------------------------------------------------
 

Modified: trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -156,7 +156,7 @@
             id.setValue(val);
 
          }
-
+         
          // Compute the result of this operator
          
          boolean res = (Boolean)operator.apply();

Modified: trunk/src/main/org/jboss/messaging/core/filter/impl/Operator.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/filter/impl/Operator.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/filter/impl/Operator.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -607,6 +607,7 @@
    Object different() throws Exception
    {
       computeArgument1();
+      
       if (arg1 == null)
       {
          computeArgument2();
@@ -979,7 +980,7 @@
       computeArgument1();
       if (arg1 == null)
       {
-         return null;
+         return false;
       }
       if (class1 != SIMPLE_STRING)
       {
@@ -1001,7 +1002,7 @@
       computeArgument1();
       if (arg1 == null)
       {
-         return null;
+         return true;
       }
       if (class1 != SIMPLE_STRING)
       {

Modified: trunk/src/main/org/jboss/messaging/core/management/ManagementService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/ManagementService.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/management/ManagementService.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -37,7 +37,7 @@
 import org.jboss.messaging.core.messagecounter.MessageCounterManager;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.PostOffice;
-import org.jboss.messaging.core.remoting.RemotingService;
+import org.jboss.messaging.core.remoting.server.RemotingService;
 import org.jboss.messaging.core.remoting.spi.Acceptor;
 import org.jboss.messaging.core.security.Role;
 import org.jboss.messaging.core.server.MessagingComponent;

Modified: trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -67,8 +67,8 @@
 import org.jboss.messaging.core.messagecounter.impl.MessageCounterManagerImpl;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.PostOffice;
-import org.jboss.messaging.core.remoting.RemotingService;
 import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
+import org.jboss.messaging.core.remoting.server.RemotingService;
 import org.jboss.messaging.core.remoting.spi.Acceptor;
 import org.jboss.messaging.core.security.Role;
 import org.jboss.messaging.core.server.MessagingServer;

Modified: trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -56,7 +56,7 @@
 import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.postoffice.impl.LocalQueueBinding;
 import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.RemotingService;
+import org.jboss.messaging.core.remoting.server.RemotingService;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.QueueFactory;
@@ -296,7 +296,7 @@
       if (postOffice.getBinding(sName) == null)
       {
          Queue queue = queueFactory.createQueue(-1, sAddress, sName, null, true, false);
-         Binding binding = new LocalQueueBinding(sAddress, queue);
+         Binding binding = new LocalQueueBinding(sAddress, queue, server.getNodeID());
          storageManager.addQueueBinding(binding);
          postOffice.addBinding(binding);
       }
@@ -315,7 +315,7 @@
       if (postOffice.getBinding(sName) == null)
       {
          Queue queue = queueFactory.createQueue(-1, sAddress, sName, filter, durable, false);
-         Binding binding = new LocalQueueBinding(sAddress, queue);
+         Binding binding = new LocalQueueBinding(sAddress, queue, server.getNodeID());
          if (durable)
          {
             storageManager.addQueueBinding(binding);

Modified: trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -140,7 +140,7 @@
    private volatile boolean started;
 
    private final ExecutorService executor;
-    
+
    public JournalStorageManager(final Configuration config)
    {
       this.executor = Executors.newCachedThreadPool(new JBMThreadFactory("JBM-journal-storage-manager"));
@@ -215,6 +215,8 @@
       largeMessagesFactory = new NIOSequentialFileFactory(config.getLargeMessagesDirectory());
    }
 
+  
+
    /* This constructor is only used for testing */
    public JournalStorageManager(final Journal messageJournal,
                                 final Journal bindingsJournal,
@@ -230,7 +232,7 @@
    {
       return idGenerator.generateID();
    }
-   
+
    public LargeServerMessage createLargeMessage()
    {
       return new JournalLargeServerMessage(this);
@@ -558,7 +560,7 @@
                {
                   throw new IllegalStateException("Cannot find message " + messageID);
                }
-               
+
                rec.deliveryCount = encoding.count;
 
                break;
@@ -572,7 +574,7 @@
                pageTransactionInfo.setRecordID(record.id);
 
                PagingManager pagingManager = postOffice.getPagingManager();
-               
+
                pagingManager.addTransaction(pageTransactionInfo);
 
                break;
@@ -598,7 +600,7 @@
                {
                   throw new IllegalStateException("Cannot find message " + messageID);
                }
-               
+
                rec.scheduledDeliveryTime = encoding.scheduledDeliveryTime;
 
                break;
@@ -628,28 +630,28 @@
             }
          }
       }
-      
-      for (Map.Entry<Long, Map<Long, AddMessageRecord>> entry: queueMap.entrySet())
+
+      for (Map.Entry<Long, Map<Long, AddMessageRecord>> entry : queueMap.entrySet())
       {
          long queueID = entry.getKey();
-         
+
          Map<Long, AddMessageRecord> queueRecords = entry.getValue();
-         
+
          Queue queue = queues.get(queueID);
-         
-         for (AddMessageRecord record: queueRecords.values())
+
+         for (AddMessageRecord record : queueRecords.values())
          {
             long scheduledDeliveryTime = record.scheduledDeliveryTime;
-            
+
             if (scheduledDeliveryTime != 0)
             {
                record.message.putLongProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME, scheduledDeliveryTime);
             }
-            
+
             MessageReference ref = queue.reroute(record.message, null);
-            
+
             ref.setDeliveryCount(record.deliveryCount);
-            
+
             if (scheduledDeliveryTime != 0)
             {
                record.message.removeProperty(MessageImpl.HDR_SCHEDULED_DELIVERY_TIME);
@@ -665,7 +667,7 @@
                                preparedTransactions,
                                duplicateIDMap);
    }
-   
+
    private void loadPreparedTransactions(final PostOffice postOffice,
                                          final StorageManager storageManager,
                                          final HierarchicalRepository<AddressSettings> queueSettingsRepository,
@@ -688,10 +690,10 @@
          List<MessageReference> referencesToAck = new ArrayList<MessageReference>();
 
          Map<Long, ServerMessage> messages = new HashMap<Long, ServerMessage>();
-           
-         //Use same method as load message journal to prune out acks, so they don't get added.
-         //Then have reacknowledge(tx) methods on queue, which needs to add the page size
 
+         // Use same method as load message journal to prune out acks, so they don't get added.
+         // Then have reacknowledge(tx) methods on queue, which needs to add the page size
+
          // first get any sent messages for this tx and recreate
          for (RecordInfo record : preparedTransaction.records)
          {
@@ -756,7 +758,7 @@
                      throw new IllegalStateException("Cannot find queue with id " + encoding.queueID);
                   }
 
-                  //TODO - this involves a scan - we should find a quicker qay of doing it
+                  // TODO - this involves a scan - we should find a quicker qay of doing it
                   MessageReference removed = queue.removeReferenceWithID(messageID);
 
                   referencesToAck.add(removed);
@@ -779,7 +781,7 @@
                   tx.putProperty(TransactionPropertyIndexes.PAGE_TRANSACTION, pageTransactionInfo);
 
                   pagingManager.addTransaction(pageTransactionInfo);
-                  
+
                   tx.addOperation(new FinishPageMessageOperation());
 
                   break;
@@ -973,9 +975,9 @@
       {
          return;
       }
-
+           
       cleanupIncompleteFiles();
-
+      
       bindingsJournal.start();
 
       messageJournal.start();
@@ -1059,8 +1061,6 @@
 
    // Private ----------------------------------------------------------------------------------
 
-  
-
    private void checkAndCreateDir(final String dir, final boolean create)
    {
       File f = new File(dir);
@@ -1239,7 +1239,7 @@
       }
 
    }
-   
+
    private static class LargeMessageEncoding implements EncodingSupport
    {
       private final LargeServerMessage message;
@@ -1423,9 +1423,9 @@
          address = buffer.getSimpleString();
 
          int size = buffer.getInt();
-         
+
          duplID = new byte[size];
-         
+
          buffer.getBytes(duplID);
       }
 
@@ -1434,7 +1434,7 @@
          buffer.putSimpleString(address);
 
          buffer.putInt(duplID.length);
-         
+
          buffer.putBytes(duplID);
       }
 
@@ -1443,7 +1443,7 @@
          return SimpleString.sizeofString(address) + DataConstants.SIZE_INT + duplID.length;
       }
    }
-   
+
    private class FinishPageMessageOperation implements TransactionOperation
    {
 
@@ -1452,9 +1452,9 @@
          // If part of the transaction goes to the queue, and part goes to paging, we can't let depage start for the
          // transaction until all the messages were added to the queue
          // or else we could deliver the messages out of order
-         
+
          PageTransactionInfo pageTransaction = (PageTransactionInfo)tx.getProperty(TransactionPropertyIndexes.PAGE_TRANSACTION);
-         
+
          if (pageTransaction != null)
          {
             pageTransaction.commit();
@@ -1492,6 +1492,5 @@
       }
 
    }
-   
 
 }

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/Binding.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -46,8 +46,6 @@
 
    SimpleString getRoutingName();
 
-   //boolean filterMatches(ServerMessage message) throws Exception;
-   
    Filter getFilter();
    
    boolean isHighAcceptPriority(ServerMessage message);
@@ -60,4 +58,6 @@
    int getID();
    
    void setID(int id);
+   
+   SimpleString getOriginatingNodeID();
 }

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/Bindings.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/Bindings.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/Bindings.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -46,5 +46,5 @@
    
    void removeBinding(Binding binding);
    
-   void setRouteWhenNoConsumers(boolean routeWhenNoConsumers);
+   void setRouteWhenNoConsumers(boolean takePriorityIntoAccount);
 }

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/QueueInfo.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/QueueInfo.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/QueueInfo.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -52,13 +52,16 @@
    private List<SimpleString> filterStrings;
    
    private int numberOfConsumers;
+   
+   private final SimpleString origNode;
 
-   public QueueInfo(final SimpleString queueName, final SimpleString address, final SimpleString filterString, final int id)
+   public QueueInfo(final SimpleString queueName, final SimpleString address, final SimpleString filterString, final int id, final SimpleString origNode)
    {
       this.queueName = queueName;
       this.address = address;      
       this.filterString = filterString;
       this.id = id;
+      this.origNode = origNode;
    }
 
    public SimpleString getQueueName()
@@ -76,6 +79,11 @@
       return filterString;
    }
    
+   public SimpleString getOriginatingNode()
+   {
+      return origNode;
+   }
+   
    public int getID()
    {
       return id;

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingsImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingsImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/BindingsImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -181,7 +181,7 @@
       else
       {
          if (message.getProperty(MessageImpl.HDR_FROM_CLUSTER) != null)
-         {
+         {            
             routeFromCluster(message, tx);
          }
          else

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/DivertBinding.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/DivertBinding.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/DivertBinding.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -54,8 +54,10 @@
    private final boolean exclusive;
    
    private int id;
+   
+   private final SimpleString origNodeID;
       
-   public DivertBinding(final SimpleString address, final Divert divert)
+   public DivertBinding(final SimpleString address, final Divert divert, final SimpleString origNodeID)
    {
       this.address = address;
       
@@ -68,6 +70,8 @@
       this.routingName = divert.getRoutingName();
       
       this.exclusive = divert.isExclusive();
+      
+      this.origNodeID = origNodeID;
    }
    
    public int getID()
@@ -122,6 +126,11 @@
    public boolean isQueueBinding()
    {
       return false;
+   }   
+   
+   public SimpleString getOriginatingNodeID()
+   {
+      return origNodeID;
    }
 
 }

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/LocalQueueBinding.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/LocalQueueBinding.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/LocalQueueBinding.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -56,8 +56,10 @@
    private final SimpleString name;
    
    private int id;
+   
+   private final SimpleString originatingNodeID;
       
-   public LocalQueueBinding(final SimpleString address, final Queue queue)
+   public LocalQueueBinding(final SimpleString address, final Queue queue, final SimpleString originatingNodeID)
    {
       this.address = address;
       
@@ -66,6 +68,8 @@
       this.filter = queue.getFilter();
       
       this.name = queue.getName();
+      
+      this.originatingNodeID = originatingNodeID;
    }
    
    public int getID()
@@ -107,6 +111,11 @@
    {
       return false;
    }
+   
+   public SimpleString getOriginatingNodeID()
+   {
+      return originatingNodeID;
+   }
 
    public boolean isHighAcceptPriority(final ServerMessage message)
    {

Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -81,9 +81,9 @@
 public class PostOfficeImpl implements PostOffice, NotificationListener
 {
    private static final Logger log = Logger.getLogger(PostOfficeImpl.class);
-   
+
    public static final SimpleString HDR_RESET_QUEUE_DATA = new SimpleString("_JBM_RESET_QUEUE_DATA");
-   
+
    private static final List<MessageReference> emptyList = Collections.<MessageReference> emptyList();
 
    private final AddressManager addressManager;
@@ -115,19 +115,21 @@
    private final int idCacheSize;
 
    private final boolean persistIDCache;
-   
-   //Each queue has a transient ID which lasts the lifetime of its binding. This is used in clustering when routing messages to particular queues on nodes. We could
-   //use the queue name on the node to identify it. But sometimes we need to route to maybe 10s of thousands of queues on a particular node, and all would
-   //have to be specified in the message. Specify 10000 ints takes up a lot less space than 10000 arbitrary queue names
-   //The drawback of this approach is we only allow up to 2^32 queues in memory at any one time
+
+   // Each queue has a transient ID which lasts the lifetime of its binding. This is used in clustering when routing
+   // messages to particular queues on nodes. We could
+   // use the queue name on the node to identify it. But sometimes we need to route to maybe 10s of thousands of queues
+   // on a particular node, and all would
+   // have to be specified in the message. Specify 10000 ints takes up a lot less space than 10000 arbitrary queue names
+   // The drawback of this approach is we only allow up to 2^32 queues in memory at any one time
    private int transientIDSequence;
-   
+
    private Set<Integer> transientIDs = new HashSet<Integer>();
-   
-   private Map<SimpleString, QueueInfo> queueInfos = new HashMap<SimpleString, QueueInfo>();
-   
+
+   private Map<SimpleString, Map<SimpleString, QueueInfo>> queueInfos = new HashMap<SimpleString, Map<SimpleString, QueueInfo>>();
+
    private final Object notificationLock = new Object();
-      
+
    public PostOfficeImpl(final StorageManager storageManager,
                          final PagingManager pagingManager,
                          final QueueFactory bindableFactory,
@@ -167,7 +169,7 @@
 
       this.idCacheSize = idCacheSize;
 
-      this.persistIDCache = persistIDCache;            
+      this.persistIDCache = persistIDCache;
    }
 
    // MessagingComponent implementation ---------------------------------------
@@ -175,7 +177,7 @@
    public void start() throws Exception
    {
       managementService.addNotificationListener(this);
-      
+
       if (pagingManager != null)
       {
          pagingManager.setPostOffice(this);
@@ -201,7 +203,7 @@
    public void stop() throws Exception
    {
       managementService.removeNotificationListener(this);
-      
+
       if (messageExpiryExecutor != null)
       {
          messageExpiryExecutor.shutdown();
@@ -224,82 +226,139 @@
    {
       return started;
    }
-   
+
    // NotificationListener implementation -------------------------------------
-   
-   
+
    public void onNotification(final Notification notification)
-   {      
+   {
       synchronized (notificationLock)
       {
          NotificationType type = notification.getType();
-         
+
          if (type == NotificationType.BINDING_ADDED)
          {
             TypedProperties props = notification.getProperties();
-            
+
             SimpleString queueName = (SimpleString)props.getProperty(ManagementHelper.HDR_QUEUE_NAME);
-               
+
             SimpleString address = (SimpleString)props.getProperty(ManagementHelper.HDR_ADDRESS);
-            
+
             Integer transientID = (Integer)props.getProperty(ManagementHelper.HDR_BINDING_ID);
-            
+
             SimpleString filterString = (SimpleString)props.getProperty(ManagementHelper.HDR_FILTERSTRING);
-            
-            QueueInfo info = new QueueInfo(queueName, address, filterString, transientID);
-            
-            queueInfos.put(queueName, info);
+
+            SimpleString origNode = (SimpleString)props.getProperty(ManagementHelper.HDR_ORIGINATING_NODE);
+
+            QueueInfo info = new QueueInfo(queueName, address, filterString, transientID, origNode);
+
+            Map<SimpleString, QueueInfo> queueInfoMap = queueInfos.get(origNode);
+
+            if (queueInfoMap == null)
+            {
+               queueInfoMap = new HashMap<SimpleString, QueueInfo>();
+
+               queueInfos.put(origNode, queueInfoMap);
+            }
+
+            queueInfoMap.put(queueName, info);
          }
          else if (type == NotificationType.BINDING_REMOVED)
          {
             TypedProperties props = notification.getProperties();
-            
+
             SimpleString queueName = (SimpleString)props.getProperty(ManagementHelper.HDR_QUEUE_NAME);
-                     
-            queueInfos.remove(queueName);  
+
+            SimpleString origNode = (SimpleString)props.getProperty(ManagementHelper.HDR_ORIGINATING_NODE);
+
+            Map<SimpleString, QueueInfo> queueInfoMap = queueInfos.get(origNode);
+
+            if (queueInfoMap == null)
+            {
+               throw new IllegalStateException("Cannot find map for node " + origNode);
+            }
+
+            QueueInfo info = queueInfoMap.remove(queueName);
+
+            if (info == null)
+            {
+               throw new IllegalStateException("Cannot find queue info for queue " + queueName);
+            }
+
+            if (queueInfoMap.isEmpty())
+            {
+               queueInfos.remove(origNode);
+            }
          }
          else if (type == NotificationType.CONSUMER_CREATED)
          {
             TypedProperties props = notification.getProperties();
-            
-            SimpleString queueName = (SimpleString)props.getProperty(ManagementHelper.HDR_QUEUE_NAME); 
-            
+
+            SimpleString queueName = (SimpleString)props.getProperty(ManagementHelper.HDR_QUEUE_NAME);
+
             SimpleString filterString = (SimpleString)props.getProperty(ManagementHelper.HDR_FILTERSTRING);
-            
-            QueueInfo info = queueInfos.get(queueName);
-            
+
+            SimpleString origNode = (SimpleString)props.getProperty(ManagementHelper.HDR_ORIGINATING_NODE);
+
+            Map<SimpleString, QueueInfo> queueInfoMap = queueInfos.get(origNode);
+
+            if (queueInfoMap == null)
+            {
+               throw new IllegalStateException("Cannot find map for node " + origNode);
+            }
+
+            QueueInfo info = queueInfoMap.get(queueName);
+
+            if (info == null)
+            {
+               throw new IllegalStateException("Cannot find queue info for queue " + queueName);
+            }
+
             info.incrementConsumers();
-            
+
             if (filterString != null)
             {
                List<SimpleString> filterStrings = info.getFilterStrings();
-               
+
                if (filterStrings == null)
                {
                   filterStrings = new ArrayList<SimpleString>();
-                  
+
                   info.setFilterStrings(filterStrings);
                }
-            }         
+            }
          }
          else if (type == NotificationType.CONSUMER_CLOSED)
          {
             TypedProperties props = notification.getProperties();
-            
-            SimpleString queueName = (SimpleString)props.getProperty(ManagementHelper.HDR_QUEUE_NAME); 
-            
+
+            SimpleString queueName = (SimpleString)props.getProperty(ManagementHelper.HDR_QUEUE_NAME);
+
             SimpleString filterString = (SimpleString)props.getProperty(ManagementHelper.HDR_FILTERSTRING);
-            
-            QueueInfo info = queueInfos.get(queueName);
-            
+
+            SimpleString origNode = (SimpleString)props.getProperty(ManagementHelper.HDR_ORIGINATING_NODE);
+
+            Map<SimpleString, QueueInfo> queueInfoMap = queueInfos.get(origNode);
+
+            if (queueInfoMap == null)
+            {
+               throw new IllegalStateException("Cannot find map for node " + origNode);
+            }
+
+            QueueInfo info = queueInfoMap.get(queueName);
+
+            if (info == null)
+            {
+               throw new IllegalStateException("Cannot find queue info for queue " + queueName);
+            }
+
             info.decrementConsumers();
-            
+
             if (filterString != null)
             {
                List<SimpleString> filterStrings = info.getFilterStrings();
-               
+
                filterStrings.remove(filterString);
-            }             
+            }
          }
          else
          {
@@ -308,7 +367,6 @@
       }
    }
 
-
    // PostOffice implementation -----------------------------------------------
 
    public synchronized boolean addDestination(final SimpleString address, final boolean durable) throws Exception
@@ -362,46 +420,52 @@
    // and post office is activated but queue remains unactivated after failover so delivery never occurs
    // even though failover is complete
    public synchronized void addBinding(final Binding binding) throws Exception
-   {      
+   {
       binding.setID(generateTransientID());
-      
+
       addBindingInMemory(binding);
-           
+
       TypedProperties props = new TypedProperties();
-      
+
       props.putStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());
       props.putStringProperty(ManagementHelper.HDR_QUEUE_NAME, binding.getRoutingName());
       props.putIntProperty(ManagementHelper.HDR_BINDING_ID, binding.getID());
+      if (binding.getOriginatingNodeID() == null)
+      {
+         throw new IllegalStateException("null originating node");
+      }
+      props.putStringProperty(ManagementHelper.HDR_ORIGINATING_NODE, binding.getOriginatingNodeID());
       Filter filter = binding.getFilter();
       if (filter != null)
       {
          props.putStringProperty(ManagementHelper.HDR_FILTERSTRING, filter.getFilterString());
       }
-      
+
       managementService.sendNotification(new Notification(NotificationType.BINDING_ADDED, props));
    }
 
    public synchronized Binding removeBinding(final SimpleString uniqueName) throws Exception
    {
       Binding binding = removeBindingInMemory(uniqueName);
-      
+
       if (binding.isQueueBinding())
       {
          managementService.unregisterQueue(uniqueName, binding.getAddress());
       }
-                        
+
       TypedProperties props = new TypedProperties();
-      
+
       props.putStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());
       props.putStringProperty(ManagementHelper.HDR_QUEUE_NAME, binding.getRoutingName());
+      props.putStringProperty(ManagementHelper.HDR_ORIGINATING_NODE, binding.getOriginatingNodeID());
 
       managementService.sendNotification(new Notification(NotificationType.BINDING_REMOVED, props));
-      
+
       releaseTransientID(binding.getID());
 
       return binding;
    }
-   
+
    public Bindings getBindingsForAddress(final SimpleString address)
    {
       Bindings bindings = addressManager.getBindings(address);
@@ -420,7 +484,7 @@
    }
 
    public void route(final ServerMessage message, Transaction tx) throws Exception
-   {            
+   {
       SimpleString address = message.getDestination();
 
       if (checkAllowable)
@@ -472,7 +536,7 @@
             startedTx = true;
          }
       }
-      
+
       if (tx == null)
       {
          if (pagingManager.page(message, true))
@@ -483,19 +547,19 @@
       else
       {
          SimpleString destination = message.getDestination();
-         
+
          boolean depage = tx.getProperty(TransactionPropertyIndexes.IS_DEPAGE) != null;
-         
+
          if (!depage && pagingManager.isPaging(destination))
          {
             getPageOperation(tx).addMessageToPage(message);
-            
+
             return;
          }
       }
 
       Bindings bindings = addressManager.getBindings(address);
-      
+
       if (bindings != null)
       {
          bindings.route(message, tx);
@@ -520,7 +584,7 @@
    public List<Queue> activate()
    {
       backup = false;
-      
+
       pagingManager.activate();
 
       Map<SimpleString, Binding> nameMap = addressManager.getBindings();
@@ -577,131 +641,147 @@
 
       return cache;
    }
-     
+
    public void sendQueueInfoToQueue(final SimpleString queueName, final SimpleString address) throws Exception
    {
-      //We send direct to the queue so we can send it to the same queue that is bound to the notifications adress - this is crucial for ensuring
-      //that queue infos and notifications are received in a contiguous consistent stream
+      // We send direct to the queue so we can send it to the same queue that is bound to the notifications adress -
+      // this is crucial for ensuring
+      // that queue infos and notifications are received in a contiguous consistent stream
       Binding binding = addressManager.getBinding(queueName);
-      
+
       if (binding == null)
       {
          throw new IllegalStateException("Cannot find queue " + queueName);
       }
-      
+
       Queue queue = (Queue)binding.getBindable();
-      
-      //Need to lock to make sure all queue info and notifications are in the correct order with no gaps
+
+      // Need to lock to make sure all queue info and notifications are in the correct order with no gaps
       synchronized (notificationLock)
       {
-         //First send a reset message
-         
-         ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID()); 
+         // First send a reset message
+
+         ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID());
          message.setBody(new ByteBufferWrapper(ByteBuffer.allocate(0)));
          message.setDestination(queueName);
          message.putBooleanProperty(HDR_RESET_QUEUE_DATA, true);
-         
-         queue.preroute(message, null);            
+         queue.preroute(message, null);
          queue.route(message, null);
-                  
-         for (QueueInfo info: queueInfos.values())
-         {            
-            if (info.getAddress().startsWith(address))
+
+         for (Map<SimpleString, QueueInfo> queueInfoMap : queueInfos.values())
+         {
+            for (QueueInfo info : queueInfoMap.values())
             {
-               message = createQueueInfoMessage(NotificationType.BINDING_ADDED, queueName);
-               
-               message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
-               message.putStringProperty(ManagementHelper.HDR_QUEUE_NAME, info.getQueueName());
-               message.putIntProperty(ManagementHelper.HDR_BINDING_ID, info.getID());
-               message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, info.getFilterString());
-               
-               queue.preroute(message, null);            
-               queue.route(message, null);
-               
-               int consumersWithFilters = info.getFilterStrings() != null ? info.getFilterStrings().size() : 0;
-               
-               for (int i = 0; i < info.getNumberOfConsumers() - consumersWithFilters; i++)
+               if (info.getAddress().startsWith(address))
                {
-                  message = createQueueInfoMessage(NotificationType.CONSUMER_CREATED, queueName);
+                  message = createQueueInfoMessage(NotificationType.BINDING_ADDED, queueName);
                   
-                  message.putStringProperty(ManagementHelper.HDR_QUEUE_NAME, info.getQueueName()); 
-                  
-                  queue.preroute(message, null);            
-                  queue.route(message, null);
-               }
-               
-               if (info.getFilterStrings() != null)
-               {
-                  for (SimpleString filterString: info.getFilterStrings())
+                  message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
+                  message.putStringProperty(ManagementHelper.HDR_QUEUE_NAME, info.getQueueName());
+                  message.putIntProperty(ManagementHelper.HDR_BINDING_ID, info.getID());
+                  message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, info.getFilterString());
+
+                  if (info.getOriginatingNode() == null)
                   {
+                     throw new IllegalStateException("orig node is null");
+                  }
+
+                  message.putStringProperty(ManagementHelper.HDR_ORIGINATING_NODE, info.getOriginatingNode());
+
+                  routeDirect(queue, message);
+
+                  int consumersWithFilters = info.getFilterStrings() != null ? info.getFilterStrings().size() : 0;
+
+                  for (int i = 0; i < info.getNumberOfConsumers() - consumersWithFilters; i++)
+                  {
                      message = createQueueInfoMessage(NotificationType.CONSUMER_CREATED, queueName);
-                     
+
                      message.putStringProperty(ManagementHelper.HDR_QUEUE_NAME, info.getQueueName());
-                     message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString); 
-                     
+                     message.putStringProperty(ManagementHelper.HDR_ORIGINATING_NODE, info.getOriginatingNode());
 
-                     queue.preroute(message, null);            
-                     queue.route(message, null);
+                     routeDirect(queue, message);
                   }
-               }     
+
+                  if (info.getFilterStrings() != null)
+                  {
+                     for (SimpleString filterString : info.getFilterStrings())
+                     {
+                        message = createQueueInfoMessage(NotificationType.CONSUMER_CREATED, queueName);
+
+                        message.putStringProperty(ManagementHelper.HDR_QUEUE_NAME, info.getQueueName());
+                        message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
+                        message.putStringProperty(ManagementHelper.HDR_ORIGINATING_NODE, info.getOriginatingNode());
+
+                        routeDirect(queue, message);
+                     }
+                  }
+               }
             }
          }
       }
    }
-   
+
    // Private -----------------------------------------------------------------
-   
+
+   private void routeDirect(final Queue queue, final ServerMessage message) throws Exception
+   {
+      if (queue.getFilter() == null || queue.getFilter().match(message))
+      {
+         queue.preroute(message, null);
+         queue.route(message, null);
+      }
+   }
+
    private ServerMessage createQueueInfoMessage(final NotificationType type, final SimpleString queueName)
    {
       ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID());
       message.setBody(new ByteBufferWrapper(ByteBuffer.allocate(0)));
-      
+
       message.setDestination(queueName);
-      
-      message.putStringProperty(ManagementHelper.HDR_NOTIFICATION_TYPE, new SimpleString(type.toString()));        
+
+      message.putStringProperty(ManagementHelper.HDR_NOTIFICATION_TYPE, new SimpleString(type.toString()));
       message.putLongProperty(ManagementHelper.HDR_NOTIFICATION_TIMESTAMP, System.currentTimeMillis());
-      
+
       return message;
    }
-   
-   
+
    private int generateTransientID()
    {
       int start = transientIDSequence;
       do
       {
          int id = transientIDSequence++;
-         
+
          if (!transientIDs.contains(id))
          {
             transientIDs.add(id);
-            
+
             return id;
          }
       }
       while (transientIDSequence != start);
-      
+
       throw new IllegalStateException("Run out of queue ids!");
    }
-   
+
    private void releaseTransientID(final int id)
    {
       transientIDs.remove(id);
    }
-   
+
    private final PageMessageOperation getPageOperation(final Transaction tx)
    {
       PageMessageOperation oper = (PageMessageOperation)tx.getProperty(TransactionPropertyIndexes.PAGE_MESSAGES_OPERATION);
-      
+
       if (oper == null)
-      {         
+      {
          oper = new PageMessageOperation();
-         
+
          tx.putProperty(TransactionPropertyIndexes.PAGE_MESSAGES_OPERATION, oper);
-         
+
          tx.addOperation(oper);
       }
-      
+
       return oper;
    }
 
@@ -724,7 +804,7 @@
          }
 
          managementService.registerQueue(queue, binding.getAddress(), storageManager);
-      }            
+      }
    }
 
    private Binding removeBindingInMemory(final SimpleString bindingName) throws Exception
@@ -774,7 +854,7 @@
    private class PageMessageOperation implements TransactionOperation
    {
       private final List<ServerMessage> messagesToPage = new ArrayList<ServerMessage>();
-      
+
       void addMessageToPage(final ServerMessage message)
       {
          messagesToPage.add(message);
@@ -785,9 +865,9 @@
          // If part of the transaction goes to the queue, and part goes to paging, we can't let depage start for the
          // transaction until all the messages were added to the queue
          // or else we could deliver the messages out of order
-         
+
          PageTransactionInfo pageTransaction = (PageTransactionInfo)tx.getProperty(TransactionPropertyIndexes.PAGE_TRANSACTION);
-         
+
          if (pageTransaction != null)
          {
             pageTransaction.commit();
@@ -813,7 +893,7 @@
          if (tx.getState() != Transaction.State.PREPARED)
          {
             pageMessages(tx);
-         }                
+         }
       }
 
       public void beforePrepare(final Transaction tx) throws Exception

Modified: trunk/src/main/org/jboss/messaging/core/remoting/Channel.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/Channel.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/remoting/Channel.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -14,6 +14,7 @@
 import java.util.concurrent.locks.Lock;
 
 import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.server.DelayedResult;
 
 /**
  * A Channel A Channel *does not* support concurrent access by more than one thread!

Deleted: trunk/src/main/org/jboss/messaging/core/remoting/DelayedResult.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/DelayedResult.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/remoting/DelayedResult.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -1,70 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-
-package org.jboss.messaging.core.remoting;
-
-
-/**
- * A DelayedResult
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * 
- * Created 16 Oct 2008 10:39:10
- *
- *
- */
-public class DelayedResult
-{
-   private boolean replicated;
-   
-   private Runnable resultRunner;
-   
-   public synchronized void setResultRunner(final Runnable resultRunner)
-   {
-      if (replicated)
-      {
-         resultRunner.run();
-         
-         replicated = false;
-      }
-      else
-      {
-         this.resultRunner = resultRunner;
-      }
-   }
-   
-   public synchronized void replicated()
-   {
-      if (resultRunner != null)
-      {
-         resultRunner.run();                  
-      }
-      else
-      {
-         replicated = true;
-      }
-   }
-   
-   
-
-}

Deleted: trunk/src/main/org/jboss/messaging/core/remoting/RemotingService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/RemotingService.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/remoting/RemotingService.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.core.remoting;
-
-import java.util.Set;
-
-import org.jboss.messaging.core.management.ManagementService;
-import org.jboss.messaging.core.server.MessagingComponent;
-import org.jboss.messaging.core.server.MessagingServer;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * @author <a href="mailto:ataylor at redhat.com">Andy Taylor</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- */
-public interface RemotingService extends MessagingComponent
-{
-   RemotingConnection getConnection(Object remotingConnectionID);
-
-   Set<RemotingConnection> getConnections();
-   
-   void setMessagingServer(MessagingServer server);
-   
-   void addInterceptor(Interceptor interceptor);
-   
-   boolean removeInterceptor(Interceptor interceptor);
-   
-   void setBackup(boolean backup);
-
-   void setManagementService(ManagementService managementService);
-}

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConnectionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConnectionImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingConnectionImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -84,7 +84,6 @@
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.Channel;
 import org.jboss.messaging.core.remoting.ChannelHandler;
-import org.jboss.messaging.core.remoting.DelayedResult;
 import org.jboss.messaging.core.remoting.FailureListener;
 import org.jboss.messaging.core.remoting.Interceptor;
 import org.jboss.messaging.core.remoting.Packet;
@@ -133,6 +132,7 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAStartMessage;
+import org.jboss.messaging.core.remoting.server.DelayedResult;
 import org.jboss.messaging.core.remoting.spi.Connection;
 import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
 import org.jboss.messaging.core.remoting.spi.Connector;

Deleted: trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingServiceImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingServiceImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -1,370 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors by
- * the @authors tag. See the copyright.txt in the distribution for a full listing of individual contributors. This is
- * free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
- * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details. You should have received a copy of the GNU Lesser General Public License along with this software; if not,
- * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
- * site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.core.remoting.impl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.TransportConfiguration;
-import org.jboss.messaging.core.exception.MessagingException;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.management.ManagementService;
-import org.jboss.messaging.core.remoting.Channel;
-import org.jboss.messaging.core.remoting.ChannelHandler;
-import org.jboss.messaging.core.remoting.Interceptor;
-import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.RemotingService;
-import org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory;
-import org.jboss.messaging.core.remoting.spi.Acceptor;
-import org.jboss.messaging.core.remoting.spi.AcceptorFactory;
-import org.jboss.messaging.core.remoting.spi.BufferHandler;
-import org.jboss.messaging.core.remoting.spi.Connection;
-import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
-import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
-import org.jboss.messaging.core.server.MessagingServer;
-import org.jboss.messaging.core.server.impl.MessagingServerPacketHandler;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * @author <a href="mailto:ataylor at redhat.com">Andy Taylor</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- */
-public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycleListener
-{
-   // Constants -----------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(RemotingServiceImpl.class);
-
-   // Attributes ----------------------------------------------------
-
-   private volatile boolean started = false;
-
-   private final Set<TransportConfiguration> transportConfigs;
-
-   private final List<Interceptor> interceptors = new ArrayList<Interceptor>();
-
-   private final Set<Acceptor> acceptors = new HashSet<Acceptor>();
-
-   private final Map<Object, RemotingConnection> connections = new ConcurrentHashMap<Object, RemotingConnection>();
-
-   private Timer failedConnectionTimer;
-
-   private TimerTask failedConnectionsTask;
-
-   private final long connectionScanPeriod;
-   
-   private final long connectionTTL;
-
-   private final boolean jmxEnabled;
-
-   private final BufferHandler bufferHandler = new DelegatingBufferHandler();
-
-   private volatile boolean backup;
-
-   private volatile MessagingServer server;
-
-   private ManagementService managementService;
-
-   
-   // Static --------------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   public RemotingServiceImpl(final Configuration config)
-   {
-      transportConfigs = config.getAcceptorConfigurations();
-
-      ClassLoader loader = Thread.currentThread().getContextClassLoader();
-      for (String interceptorClass : config.getInterceptorClassNames())
-      {
-         try
-         {
-            Class<?> clazz = loader.loadClass(interceptorClass);
-            interceptors.add((Interceptor)clazz.newInstance());
-         }
-         catch (Exception e)
-         {
-            log.warn("Error instantiating interceptor \"" + interceptorClass + "\"", e);
-         }
-      }
-
-      connectionScanPeriod = config.getConnectionScanPeriod();
-      
-      connectionTTL = config.getConnectionTTLOverride();
-
-      backup = config.isBackup();  
-      
-      jmxEnabled= config.isJMXManagementEnabled();
-   }
-
-   // RemotingService implementation -------------------------------
-
-   public void setManagementService(final ManagementService managementService)
-   {
-      this.managementService = managementService;
-   }
-   
-   public synchronized void start() throws Exception
-   {
-      if (started)
-      {
-         return;
-      }
-      
-
-      // when JMX is enabled, it requires a INVM acceptor to send the core messages
-      // corresponding to the JMX management operations (@see ReplicationAwareStandardMBeanWrapper)
-      if (jmxEnabled)
-      {
-         boolean invmAcceptorConfigured = false;
-         for (TransportConfiguration config : transportConfigs)
-         {
-            if (InVMAcceptorFactory.class.getName().equals(config.getFactoryClassName()))
-            {
-               invmAcceptorConfigured = true;
-            }
-         }
-         if (!invmAcceptorConfigured)
-         {
-            transportConfigs.add(new TransportConfiguration(InVMAcceptorFactory.class.getName(), new HashMap<String, Object>(), "in-vm"));
-         }
-      }
-
-      ClassLoader loader = Thread.currentThread().getContextClassLoader();
-
-      for (TransportConfiguration info : transportConfigs)
-      {
-         try
-         {
-            Class<?> clazz = loader.loadClass(info.getFactoryClassName());
-
-            AcceptorFactory factory = (AcceptorFactory)clazz.newInstance();
-
-            Acceptor acceptor = factory.createAcceptor(info.getParams(), bufferHandler, this);
-
-            acceptors.add(acceptor);
-
-            if (managementService != null)
-            {
-               managementService.registerAcceptor(acceptor, info);
-            }
-         }
-         catch (Exception e)
-         {
-            log.warn("Error instantiating acceptor \"" + info.getFactoryClassName() + "\"", e);
-         }
-      }
-
-      for (Acceptor a : acceptors)
-      {
-         a.start();
-      }
-      
-      failedConnectionTimer = new Timer(true);
-
-      failedConnectionsTask = new FailedConnectionsTask();
-   
-      failedConnectionTimer.schedule(failedConnectionsTask, connectionScanPeriod, connectionScanPeriod);
-
-      started = true;
-   }
-
-   public synchronized void stop()
-   {
-      if (!started)
-      {
-         return;
-      }
-
-      if (failedConnectionTimer != null)
-      {
-         failedConnectionsTask.cancel();
-
-         failedConnectionsTask = null;
-         
-         failedConnectionTimer.cancel();
-         
-         failedConnectionTimer = null;
-      }
-
-      for (Acceptor acceptor : acceptors)
-      {
-         acceptor.stop();
-      }
-      
-      acceptors.clear();
-      
-      connections.clear();
-
-      started = false;
-   }
-   
-   public boolean isStarted()
-   {
-      return started;
-   }
-
-   public RemotingConnection getConnection(final Object remotingConnectionID)
-   {
-      return connections.get(remotingConnectionID);
-   }
-
-   public synchronized Set<RemotingConnection> getConnections()
-   {
-      return new HashSet<RemotingConnection>(connections.values());
-   }
-
-   public void setMessagingServer(final MessagingServer server)
-   {
-      this.server = server;
-   }
-
-   public void setBackup(final boolean backup)
-   {
-      this.backup = backup;
-   }
-
-   // ConnectionLifeCycleListener implementation -----------------------------------
-
-   public void connectionCreated(final Connection connection)
-   {
-      if (server == null)
-      {
-         throw new IllegalStateException("Unable to create connection, server hasn't finished starting up");
-      }
-      
-      RemotingConnection replicatingConnection = server.getReplicatingConnection();
-
-      RemotingConnection rc = new RemotingConnectionImpl(connection,                                                                                             
-                                                         interceptors,
-                                                         replicatingConnection,
-                                                         !backup,
-                                                         connectionTTL);
-
-      Channel channel1 = rc.getChannel(1,  -1, false);
-
-      ChannelHandler handler = new MessagingServerPacketHandler(server, channel1, rc);
-
-      channel1.setHandler(handler);
-
-      Object id = connection.getID();
-
-      connections.put(id, rc);
-   }
-
-   public void connectionDestroyed(final Object connectionID)
-   {
-      RemotingConnection conn = connections.remove(connectionID);
-      
-      if (conn != null)
-      {
-         conn.destroy();
-      }      
-   }
-
-   public void connectionException(final Object connectionID, final MessagingException me)
-   {
-      RemotingConnection rc = connections.remove(connectionID);
-
-      if (rc != null)
-      {
-         rc.fail(me);
-      }     
-   }
-
-   public void addInterceptor(final Interceptor interceptor)
-   {
-      interceptors.add(interceptor);
-   }
-
-   public boolean removeInterceptor(final Interceptor interceptor)
-   {
-      return interceptors.remove(interceptor);
-   }
-
-   // Public --------------------------------------------------------
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-
-   private class FailedConnectionsTask extends TimerTask
-   {
-      private boolean cancelled;
-
-      @Override
-      public synchronized void run()
-      {
-         if (cancelled)
-         {
-            return;
-         }
-
-         Set<RemotingConnection> failedConnections = new HashSet<RemotingConnection>();
-
-         long now = System.currentTimeMillis();
-
-         for (RemotingConnection conn : connections.values())
-         {
-            if (conn.isExpired(now))
-            {
-               failedConnections.add(conn);
-            }
-         }
-
-         for (RemotingConnection conn : failedConnections)
-         {
-            MessagingException me = new MessagingException(MessagingException.CONNECTION_TIMEDOUT,
-                                                           "Did not receive ping on connection. It is likely a client has exited or crashed without " + "closing its connection, or the network between the server and client has failed. The connection will now be closed.");
-
-            conn.fail(me);
-         }
-      }
-
-      @Override
-      public synchronized boolean cancel()
-      {
-         cancelled = true;
-
-         return super.cancel();
-      }
-
-   }
-
-   private class DelegatingBufferHandler extends AbstractBufferHandler
-   {
-      public void bufferReceived(final Object connectionID, final MessagingBuffer buffer)
-      {
-         RemotingConnection conn = connections.get(connectionID);
-
-         if (conn != null)
-         {
-            conn.bufferReceived(connectionID, buffer);
-         }
-      }
-   }
-
-}
\ No newline at end of file

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMAcceptor.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMAcceptor.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMAcceptor.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -39,60 +39,61 @@
  *
  */
 public class InVMAcceptor implements Acceptor
-{   
+{
    private final int id;
-   
+
    private final BufferHandler handler;
-   
+
    private final ConnectionLifeCycleListener listener;
-   
+
    private ConcurrentMap<String, Connection> connections = new ConcurrentHashMap<String, Connection>();
-   
+
    private volatile boolean started;
-   
-   public InVMAcceptor(final Map<String, Object> configuration, final BufferHandler handler,
+
+   public InVMAcceptor(final Map<String, Object> configuration,
+                       final BufferHandler handler,
                        final ConnectionLifeCycleListener listener)
    {
       this.handler = handler;
-      
-      this.listener = listener;   
-      
+
+      this.listener = listener;
+
       this.id = ConfigurationHelper.getIntProperty(TransportConstants.SERVER_ID_PROP_NAME, 0, configuration);
    }
-   
+
    public synchronized void start() throws Exception
-   {      
+   {
       if (started)
       {
          return;
       }
-      
+
       InVMRegistry registry = InVMRegistry.instance;
-      
+
       registry.registerAcceptor(id, this);
-      
+
       started = true;
    }
 
    public synchronized void stop()
-   {   
+   {
       if (!started)
       {
          return;
       }
-      
-      for (Connection connection: connections.values())
+
+      InVMRegistry.instance.unregisterAcceptor(id);
+
+      for (Connection connection : connections.values())
       {
          listener.connectionDestroyed(connection.getID());
       }
-      
+
       connections.clear();
-      
-      InVMRegistry.instance.unregisterAcceptor(id);
-      
+
       started = true;
    }
-   
+
    public boolean isStarted()
    {
       return started;
@@ -104,63 +105,68 @@
       {
          throw new IllegalStateException("Acceptor is not started");
       }
-      
+
       return handler;
    }
-   
-   public void connect(final String connectionID, final BufferHandler remoteHandler,
-                       final InVMConnector connector)
+
+   public void connect(final String connectionID, final BufferHandler remoteHandler, final InVMConnector connector)
    {
       if (!started)
       {
          throw new IllegalStateException("Acceptor is not started");
       }
-      
-      new InVMConnection(id, connectionID, remoteHandler, new Listener(connector));               
+
+      new InVMConnection(id, connectionID, remoteHandler, new Listener(connector));
    }
-   
+
    public void disconnect(final String connectionID)
    {
       if (!started)
       {
          throw new IllegalStateException("Acceptor is not started");
       }
-      
+
       Connection conn = connections.get(connectionID);
-      
+
       if (conn != null)
       {
          conn.close();
-      }            
+      }
    }
-   
+
    private class Listener implements ConnectionLifeCycleListener
    {
       private final InVMConnector connector;
-      
+
       Listener(final InVMConnector connector)
       {
          this.connector = connector;
       }
-      
+
       public void connectionCreated(final Connection connection)
       {
          if (connections.putIfAbsent((String)connection.getID(), connection) != null)
          {
             throw new IllegalArgumentException("Connection already exists with id " + connection.getID());
          }
-         
+
          listener.connectionCreated(connection);
       }
 
       public void connectionDestroyed(final Object connectionID)
       {
          if (connections.remove(connectionID) != null)
-         {                    
-            //Remove on the other side too
-            connector.disconnect((String)connectionID);
-            
+         {
             listener.connectionDestroyed(connectionID);
+
+            new Thread()
+            {
+               public void run()
+               {
+                  // Remove on the other side too
+                  connector.disconnect((String)connectionID);
+               }
+            }.start();
          }
       }
 
@@ -168,7 +174,7 @@
       {
          listener.connectionException(connectionID, me);
       }
-      
+
    }
-   
+
 }

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnection.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnection.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnection.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -25,6 +25,7 @@
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 
+import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
 import org.jboss.messaging.core.remoting.spi.BufferHandler;
@@ -140,4 +141,5 @@
    {
       return "invm:" + serverID;
    }
+      
 }

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnector.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnector.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnector.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -27,6 +27,7 @@
 
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.spi.Acceptor;
 import org.jboss.messaging.core.remoting.spi.BufferHandler;
 import org.jboss.messaging.core.remoting.spi.Connection;
 import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
@@ -42,17 +43,21 @@
 public class InVMConnector implements Connector
 {
    public static final Logger log = Logger.getLogger(InVMConnector.class);
-   
-   //Used for testing failure only
+
+   // Used for testing failure only
    public static volatile boolean failOnCreateConnection;
+
    public static volatile int numberOfFailures = -1;
+
    private static volatile int failures;
+
    public static synchronized void resetFailures()
    {
       failures = 0;
       failOnCreateConnection = false;
       numberOfFailures = -1;
    }
+
    private static synchronized void incFailures()
    {
       failures++;
@@ -63,54 +68,59 @@
    }
 
    protected final int id;
-   
+
    private final BufferHandler handler;
-   
+
    private final ConnectionLifeCycleListener listener;
-   
+
    private final InVMAcceptor acceptor;
-   
+
    private ConcurrentMap<String, Connection> connections = new ConcurrentHashMap<String, Connection>();
-   
+
    private volatile boolean started;
-   
+
    public InVMConnector(final Map<String, Object> configuration,
                         final BufferHandler handler,
                         final ConnectionLifeCycleListener listener)
    {
       this.listener = listener;
-      
+
       this.id = ConfigurationHelper.getIntProperty(TransportConstants.SERVER_ID_PROP_NAME, 0, configuration);
-      
+
       this.handler = handler;
-      
+
       InVMRegistry registry = InVMRegistry.instance;
-      
+
       acceptor = registry.getAcceptor(id);
-      
+
       if (acceptor == null)
       {
-         throw new IllegalStateException("Cannot connect to invm acceptor with id " + id + " has it been started?");
+         log.warn("Cannot connect to invm acceptor with id " + id + " has it been started?");
       }
    }
 
+   public Acceptor getAcceptor()
+   {
+      return acceptor;
+   }
+
    public synchronized void close()
-   {      
+   {
       if (!started)
       {
          return;
       }
-      
-      for (Connection connection: connections.values())
+
+      for (Connection connection : connections.values())
       {
          listener.connectionDestroyed(connection.getID());
       }
-      
+
       connections.clear();
-      
+
       started = false;
    }
-   
+
    public boolean isStarted()
    {
       return started;
@@ -121,35 +131,36 @@
       if (failOnCreateConnection)
       {
          incFailures();
-         //For testing only
+         // For testing only
          return null;
       }
-      
+
       Connection conn = internalCreateConnection(acceptor.getHandler(), new Listener());
-      
+
       acceptor.connect((String)conn.getID(), handler, this);
-           
+
       return conn;
    }
+
    public synchronized void start()
-   {          
+   {
       started = true;
    }
-   
+
    public BufferHandler getHandler()
    {
       return handler;
    }
-   
+
    public void disconnect(final String connectionID)
    {
       if (!started)
       {
-         throw new IllegalStateException("Acceptor is not started");
+         return;
       }
-      
+
       Connection conn = connections.get(connectionID);
-      
+
       if (conn != null)
       {
          conn.close();
@@ -161,27 +172,33 @@
    {
       return new InVMConnection(id, handler, listener);
    }
-      
+
    private class Listener implements ConnectionLifeCycleListener
    {
       public void connectionCreated(final Connection connection)
-      {         
+      {
          if (connections.putIfAbsent((String)connection.getID(), connection) != null)
          {
             throw new IllegalArgumentException("Connection already exists with id " + connection.getID());
          }
-           
+
          listener.connectionCreated(connection);
       }
 
       public void connectionDestroyed(final Object connectionID)
-      {         
+      {
          if (connections.remove(connectionID) != null)
-         {                     
-            //Close the correspond connection on the other side
-            acceptor.disconnect((String)connectionID);
-            
+         {
             listener.connectionDestroyed(connectionID);
+
+            new Thread()
+            {
+               public void run()
+               {
+                  // Close the corresponding connection on the other side
+                  acceptor.disconnect((String)connectionID);
+               }
+            }.start();
          }
       }
 
@@ -189,7 +206,7 @@
       {
          listener.connectionException(connectionID, me);
       }
-      
+
    }
 
 }

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnectorFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnectorFactory.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/invm/InVMConnectorFactory.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -40,7 +40,16 @@
                                     final BufferHandler handler,
                                     final ConnectionLifeCycleListener listener)
    {      
-      return new InVMConnector(configuration, handler, listener);
+      InVMConnector connector = new InVMConnector(configuration, handler, listener);
+      
+      if (connector.getAcceptor() == null)
+      {
+         return null;
+      }
+      else
+      {         
+         return connector;
+      }
    }
 
 }

Copied: trunk/src/main/org/jboss/messaging/core/remoting/server/DelayedResult.java (from rev 5800, trunk/src/main/org/jboss/messaging/core/remoting/DelayedResult.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/server/DelayedResult.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/server/DelayedResult.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.messaging.core.remoting.server;
+
+
+/**
+ * A DelayedResult
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * Created 16 Oct 2008 10:39:10
+ *
+ *
+ */
+public class DelayedResult
+{
+   private boolean replicated;
+   
+   private Runnable resultRunner;
+   
+   public synchronized void setResultRunner(final Runnable resultRunner)
+   {
+      if (replicated)
+      {
+         resultRunner.run();
+         
+         replicated = false;
+      }
+      else
+      {
+         this.resultRunner = resultRunner;
+      }
+   }
+   
+   public synchronized void replicated()
+   {
+      if (resultRunner != null)
+      {
+         resultRunner.run();                  
+      }
+      else
+      {
+         replicated = true;
+      }
+   }
+   
+   
+
+}

Copied: trunk/src/main/org/jboss/messaging/core/remoting/server/RemotingService.java (from rev 5800, trunk/src/main/org/jboss/messaging/core/remoting/RemotingService.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/server/RemotingService.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/server/RemotingService.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.remoting.server;
+
+import java.util.Set;
+
+import org.jboss.messaging.core.management.ManagementService;
+import org.jboss.messaging.core.remoting.Interceptor;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.server.MessagingComponent;
+import org.jboss.messaging.core.server.MessagingServer;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * @author <a href="mailto:ataylor at redhat.com">Andy Taylor</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision$</tt>
+ */
+public interface RemotingService extends MessagingComponent
+{
+   RemotingConnection getConnection(Object remotingConnectionID);
+
+   Set<RemotingConnection> getConnections();
+   
+   void setMessagingServer(MessagingServer server);
+   
+   void addInterceptor(Interceptor interceptor);
+   
+   boolean removeInterceptor(Interceptor interceptor);
+   
+   void setBackup(boolean backup);
+
+   void setManagementService(ManagementService managementService);
+}

Copied: trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java (from rev 5800, trunk/src/main/org/jboss/messaging/core/remoting/impl/RemotingServiceImpl.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/server/impl/RemotingServiceImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -0,0 +1,372 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors by
+ * the @authors tag. See the copyright.txt in the distribution for a full listing of individual contributors. This is
+ * free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
+ * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details. You should have received a copy of the GNU Lesser General Public License along with this software; if not,
+ * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.remoting.server.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.management.ManagementService;
+import org.jboss.messaging.core.remoting.Channel;
+import org.jboss.messaging.core.remoting.ChannelHandler;
+import org.jboss.messaging.core.remoting.Interceptor;
+import org.jboss.messaging.core.remoting.RemotingConnection;
+import org.jboss.messaging.core.remoting.impl.AbstractBufferHandler;
+import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
+import org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory;
+import org.jboss.messaging.core.remoting.server.RemotingService;
+import org.jboss.messaging.core.remoting.spi.Acceptor;
+import org.jboss.messaging.core.remoting.spi.AcceptorFactory;
+import org.jboss.messaging.core.remoting.spi.BufferHandler;
+import org.jboss.messaging.core.remoting.spi.Connection;
+import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerPacketHandler;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * @author <a href="mailto:ataylor at redhat.com">Andy Taylor</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision$</tt>
+ */
+public class RemotingServiceImpl implements RemotingService, ConnectionLifeCycleListener
+{
+   // Constants -----------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(RemotingServiceImpl.class);
+
+   // Attributes ----------------------------------------------------
+
+   private volatile boolean started = false;
+
+   private final Set<TransportConfiguration> transportConfigs;
+
+   private final List<Interceptor> interceptors = new ArrayList<Interceptor>();
+
+   private final Set<Acceptor> acceptors = new HashSet<Acceptor>();
+
+   private final Map<Object, RemotingConnection> connections = new ConcurrentHashMap<Object, RemotingConnection>();
+
+   private Timer failedConnectionTimer;
+
+   private TimerTask failedConnectionsTask;
+
+   private final long connectionScanPeriod;
+   
+   private final long connectionTTL;
+
+   private final boolean jmxEnabled;
+
+   private final BufferHandler bufferHandler = new DelegatingBufferHandler();
+
+   private volatile boolean backup;
+
+   private volatile MessagingServer server;
+
+   private ManagementService managementService;
+
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public RemotingServiceImpl(final Configuration config)
+   {
+      transportConfigs = config.getAcceptorConfigurations();
+
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      for (String interceptorClass : config.getInterceptorClassNames())
+      {
+         try
+         {
+            Class<?> clazz = loader.loadClass(interceptorClass);
+            interceptors.add((Interceptor)clazz.newInstance());
+         }
+         catch (Exception e)
+         {
+            log.warn("Error instantiating interceptor \"" + interceptorClass + "\"", e);
+         }
+      }
+
+      connectionScanPeriod = config.getConnectionScanPeriod();
+      
+      connectionTTL = config.getConnectionTTLOverride();
+
+      backup = config.isBackup();  
+      
+      jmxEnabled= config.isJMXManagementEnabled();
+   }
+
+   // RemotingService implementation -------------------------------
+
+   public void setManagementService(final ManagementService managementService)
+   {
+      this.managementService = managementService;
+   }
+   
+   public synchronized void start() throws Exception
+   {
+      if (started)
+      {
+         return;
+      }
+      
+
+      // when JMX is enabled, it requires a INVM acceptor to send the core messages
+      // corresponding to the JMX management operations (@see ReplicationAwareStandardMBeanWrapper)
+      if (jmxEnabled)
+      {
+         boolean invmAcceptorConfigured = false;
+         for (TransportConfiguration config : transportConfigs)
+         {
+            if (InVMAcceptorFactory.class.getName().equals(config.getFactoryClassName()))
+            {
+               invmAcceptorConfigured = true;
+            }
+         }
+         if (!invmAcceptorConfigured)
+         {
+            transportConfigs.add(new TransportConfiguration(InVMAcceptorFactory.class.getName(), new HashMap<String, Object>(), "in-vm"));
+         }
+      }
+
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+      for (TransportConfiguration info : transportConfigs)
+      {
+         try
+         {
+            Class<?> clazz = loader.loadClass(info.getFactoryClassName());
+
+            AcceptorFactory factory = (AcceptorFactory)clazz.newInstance();
+
+            Acceptor acceptor = factory.createAcceptor(info.getParams(), bufferHandler, this);
+
+            acceptors.add(acceptor);
+
+            if (managementService != null)
+            {
+               managementService.registerAcceptor(acceptor, info);
+            }
+         }
+         catch (Exception e)
+         {
+            log.warn("Error instantiating acceptor \"" + info.getFactoryClassName() + "\"", e);
+         }
+      }
+
+      for (Acceptor a : acceptors)
+      {
+         a.start();
+      }
+      
+      failedConnectionTimer = new Timer(true);
+
+      failedConnectionsTask = new FailedConnectionsTask();
+   
+      failedConnectionTimer.schedule(failedConnectionsTask, connectionScanPeriod, connectionScanPeriod);
+
+      started = true;
+   }
+
+   public synchronized void stop()
+   {
+      if (!started)
+      {
+         return;
+      }
+
+      if (failedConnectionTimer != null)
+      {
+         failedConnectionsTask.cancel();
+
+         failedConnectionsTask = null;
+         
+         failedConnectionTimer.cancel();
+         
+         failedConnectionTimer = null;
+      }
+
+      for (Acceptor acceptor : acceptors)
+      {
+         acceptor.stop();
+      }
+      
+      acceptors.clear();
+      
+      connections.clear();
+
+      started = false;
+   }
+   
+   public boolean isStarted()
+   {
+      return started;
+   }
+
+   public RemotingConnection getConnection(final Object remotingConnectionID)
+   {
+      return connections.get(remotingConnectionID);
+   }
+
+   public synchronized Set<RemotingConnection> getConnections()
+   {
+      return new HashSet<RemotingConnection>(connections.values());
+   }
+
+   public void setMessagingServer(final MessagingServer server)
+   {
+      this.server = server;
+   }
+
+   public void setBackup(final boolean backup)
+   {
+      this.backup = backup;
+   }
+
+   // ConnectionLifeCycleListener implementation -----------------------------------
+
+   public void connectionCreated(final Connection connection)
+   {
+      if (server == null)
+      {
+         throw new IllegalStateException("Unable to create connection, server hasn't finished starting up");
+      }
+      
+      RemotingConnection replicatingConnection = server.getReplicatingConnection();
+
+      RemotingConnection rc = new RemotingConnectionImpl(connection,                                                                                             
+                                                         interceptors,
+                                                         replicatingConnection,
+                                                         !backup,
+                                                         connectionTTL);
+
+      Channel channel1 = rc.getChannel(1,  -1, false);
+
+      ChannelHandler handler = new MessagingServerPacketHandler(server, channel1, rc);
+
+      channel1.setHandler(handler);
+
+      Object id = connection.getID();
+
+      connections.put(id, rc);
+   }
+
+   public void connectionDestroyed(final Object connectionID)
+   {
+      RemotingConnection conn = connections.remove(connectionID);
+      
+      if (conn != null)
+      {
+         conn.destroy();
+      }      
+   }
+
+   public void connectionException(final Object connectionID, final MessagingException me)
+   {
+      RemotingConnection rc = connections.remove(connectionID);
+
+      if (rc != null)
+      {
+         rc.fail(me);
+      }     
+   }
+
+   public void addInterceptor(final Interceptor interceptor)
+   {
+      interceptors.add(interceptor);
+   }
+
+   public boolean removeInterceptor(final Interceptor interceptor)
+   {
+      return interceptors.remove(interceptor);
+   }
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+   private class FailedConnectionsTask extends TimerTask
+   {
+      private boolean cancelled;
+
+      @Override
+      public synchronized void run()
+      {
+         if (cancelled)
+         {
+            return;
+         }
+
+         Set<RemotingConnection> failedConnections = new HashSet<RemotingConnection>();
+
+         long now = System.currentTimeMillis();
+
+         for (RemotingConnection conn : connections.values())
+         {
+            if (conn.isExpired(now))
+            {
+               failedConnections.add(conn);
+            }
+         }
+
+         for (RemotingConnection conn : failedConnections)
+         {
+            MessagingException me = new MessagingException(MessagingException.CONNECTION_TIMEDOUT,
+                                                           "Did not receive ping on connection. It is likely a client has exited or crashed without " + "closing its connection, or the network between the server and client has failed. The connection will now be closed.");
+
+            conn.fail(me);
+         }
+      }
+
+      @Override
+      public synchronized boolean cancel()
+      {
+         cancelled = true;
+
+         return super.cancel();
+      }
+
+   }
+
+   private class DelegatingBufferHandler extends AbstractBufferHandler
+   {
+      public void bufferReceived(final Object connectionID, final MessagingBuffer buffer)
+      {
+         RemotingConnection conn = connections.get(connectionID);
+
+         if (conn != null)
+         {
+            conn.bufferReceived(connectionID, buffer);
+         }
+      }
+   }
+
+}
\ No newline at end of file

Modified: trunk/src/main/org/jboss/messaging/core/server/Messaging.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/Messaging.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/Messaging.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -34,8 +34,8 @@
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.persistence.impl.journal.JournalStorageManager;
 import org.jboss.messaging.core.persistence.impl.nullpm.NullStorageManager;
-import org.jboss.messaging.core.remoting.RemotingService;
-import org.jboss.messaging.core.remoting.impl.RemotingServiceImpl;
+import org.jboss.messaging.core.remoting.server.RemotingService;
+import org.jboss.messaging.core.remoting.server.impl.RemotingServiceImpl;
 import org.jboss.messaging.core.security.JBMSecurityManager;
 import org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl;
 import org.jboss.messaging.core.server.impl.MessagingServerImpl;

Modified: trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/MessagingServer.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -21,9 +21,9 @@
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.RemotingService;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateSessionResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ReattachSessionResponseMessage;
+import org.jboss.messaging.core.remoting.server.RemotingService;
 import org.jboss.messaging.core.security.JBMSecurityManager;
 import org.jboss.messaging.core.security.Role;
 import org.jboss.messaging.core.server.cluster.ClusterManager;
@@ -31,6 +31,7 @@
 import org.jboss.messaging.core.settings.impl.AddressSettings;
 import org.jboss.messaging.core.transaction.ResourceManager;
 import org.jboss.messaging.core.version.Version;
+import org.jboss.messaging.util.SimpleString;
 
 /**
  * This interface defines the internal interface of the Messaging Server exposed to other components of the server. The
@@ -115,4 +116,6 @@
    ClusterManager getClusterManager();
    
    QueueFactory getQueueFactory();
+   
+   SimpleString getNodeID();
 }

Added: trunk/src/main/org/jboss/messaging/core/server/cluster/MessageFlowRecord.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/cluster/MessageFlowRecord.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/server/cluster/MessageFlowRecord.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.messaging.core.server.cluster;
+
+import org.jboss.messaging.core.client.MessageHandler;
+
+/**
+ * A MessageFlowRecord
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * Created 5 Feb 2009 11:39:36
+ *
+ *
+ */
+public interface MessageFlowRecord extends MessageHandler
+{
+   String getAddress();
+   
+   String getNodeID();
+   
+   void reset() throws Exception;
+   
+   void close() throws Exception;
+}

Modified: trunk/src/main/org/jboss/messaging/core/server/cluster/impl/BridgeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/cluster/impl/BridgeImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/cluster/impl/BridgeImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -35,11 +35,10 @@
 import org.jboss.messaging.core.client.ClientConsumer;
 import org.jboss.messaging.core.client.ClientMessage;
 import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientSession;
 import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.MessageHandler;
 import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
 import org.jboss.messaging.core.client.impl.ClientSessionImpl;
+import org.jboss.messaging.core.client.impl.ClientSessionInternal;
 import org.jboss.messaging.core.client.management.impl.ManagementHelper;
 import org.jboss.messaging.core.config.TransportConfiguration;
 import org.jboss.messaging.core.config.impl.ConfigurationImpl;
@@ -58,6 +57,7 @@
 import org.jboss.messaging.core.server.Queue;
 import org.jboss.messaging.core.server.ServerMessage;
 import org.jboss.messaging.core.server.cluster.Bridge;
+import org.jboss.messaging.core.server.cluster.MessageFlowRecord;
 import org.jboss.messaging.core.server.cluster.Transformer;
 import org.jboss.messaging.core.transaction.Transaction;
 import org.jboss.messaging.core.transaction.impl.TransactionImpl;
@@ -115,7 +115,7 @@
 
    private volatile ClientSessionFactory csf;
 
-   private volatile ClientSession session;
+   private volatile ClientSessionInternal session;
 
    private volatile ClientProducer producer;
 
@@ -137,13 +137,9 @@
 
    private final int maxRetriesAfterFailover;
 
-   private final MessageHandler queueInfoMessageHandler;
-
-   private final String queueDataAddress;
-
    private final SimpleString idsHeaderName;
 
-   private final boolean forClusterConnector;
+   private MessageFlowRecord flowRecord;
 
    // Static --------------------------------------------------------
 
@@ -166,11 +162,45 @@
                      final double retryIntervalMultiplier,
                      final int maxRetriesBeforeFailover,
                      final int maxRetriesAfterFailover,
+                     final boolean useDuplicateDetection) throws Exception
+   {
+      this(name,
+           queue,
+           connectorPair,
+           executor,
+           maxBatchSize,
+           maxBatchTime,
+           filterString,
+           forwardingAddress,
+           storageManager,
+           scheduledExecutor,
+           transformer,
+           retryInterval,
+           retryIntervalMultiplier,
+           maxRetriesBeforeFailover,
+           maxRetriesAfterFailover,
+           useDuplicateDetection,
+           null);
+   }
+
+   public BridgeImpl(final SimpleString name,
+                     final Queue queue,
+                     final Pair<TransportConfiguration, TransportConfiguration> connectorPair,
+                     final Executor executor,
+                     final int maxBatchSize,
+                     final long maxBatchTime,
+                     final SimpleString filterString,
+                     final SimpleString forwardingAddress,
+                     final StorageManager storageManager,
+                     final ScheduledExecutorService scheduledExecutor,
+                     final Transformer transformer,
+                     final long retryInterval,
+                     final double retryIntervalMultiplier,
+                     final int maxRetriesBeforeFailover,
+                     final int maxRetriesAfterFailover,
                      final boolean useDuplicateDetection,
-                     final MessageHandler queueInfoMessageHandler,
-                     final String queueDataAddress,
-                     final boolean forClusterConnector) throws Exception
-   {      
+                     final MessageFlowRecord flowRecord) throws Exception
+   {
       this.name = name;
 
       this.queue = queue;
@@ -210,14 +240,10 @@
 
       this.maxRetriesAfterFailover = maxRetriesAfterFailover;
 
-      this.queueInfoMessageHandler = queueInfoMessageHandler;
+      this.idsHeaderName = MessageImpl.HDR_ROUTE_TO_IDS.concat(name);
 
-      this.queueDataAddress = queueDataAddress;
+      this.flowRecord = flowRecord;
 
-      this.forClusterConnector = forClusterConnector;
-
-      this.idsHeaderName = MessageImpl.HDR_ROUTE_TO_IDS.concat(name);
-
       if (maxBatchTime != -1)
       {
          future = scheduledExecutor.scheduleAtFixedRate(new BatchTimeout(),
@@ -238,101 +264,13 @@
          return;
       }
 
+      started = true;
+            
       executor.execute(new CreateObjectsRunnable());
-
-      started = true;
    }
-
-   private class CreateObjectsRunnable implements Runnable
+   
+   public void stop() throws Exception
    {
-      public synchronized void run()
-      {
-         try
-         {
-            createTx();
-
-            queue.addConsumer(BridgeImpl.this);
-
-            csf = new ClientSessionFactoryImpl(connectorPair.a,
-                                               connectorPair.b,
-                                               retryInterval,
-                                               retryIntervalMultiplier,
-                                               maxRetriesBeforeFailover,
-                                               maxRetriesAfterFailover);
-
-            session = csf.createSession(false, false, false);
-
-            producer = session.createProducer();
-
-            session.addFailureListener(BridgeImpl.this);
-
-            // TODO - we should move this code to the ClusterConnectorImpl - and just execute it when the bridge
-            // connection is opened and closed - we can use
-            // a callback to tell us that
-            if (queueInfoMessageHandler != null)
-            {
-               // Get the queue data
-
-               SimpleString notifQueueName = new SimpleString("notif-").concat(UUIDGenerator.getInstance()
-                                                                                            .generateSimpleStringUUID());
-
-               SimpleString filter = new SimpleString(ManagementHelper.HDR_NOTIFICATION_TYPE + " IN (" +
-                                                      "'" +
-                                                      NotificationType.BINDING_ADDED +
-                                                      "'," +
-                                                      "'" +
-                                                      NotificationType.BINDING_REMOVED +
-                                                      "'," +
-                                                      "'" +
-                                                      NotificationType.CONSUMER_CREATED +
-                                                      "'," +
-                                                      "'" +
-                                                      NotificationType.CONSUMER_CLOSED +
-                                                      "') AND " +
-                                                      "("+ ManagementHelper.HDR_ADDRESS + " IS NULL OR " +                                                      
-                                                      ManagementHelper.HDR_ADDRESS +
-                                                      " LIKE '" +
-                                                      queueDataAddress +
-                                                      "%')");
-
-               session.createQueue(DEFAULT_MANAGEMENT_NOTIFICATION_ADDRESS, notifQueueName, filter, false, true);
-
-               ClientConsumer notifConsumer = session.createConsumer(notifQueueName);
-
-               notifConsumer.setMessageHandler(queueInfoMessageHandler);
-
-               session.start();
-
-               ClientMessage message = session.createClientMessage(false);
-
-               ManagementHelper.putOperationInvocation(message,
-                                                       ManagementServiceImpl.getMessagingServerObjectName(),
-                                                       "sendQueueInfoToQueue",
-                                                       notifQueueName.toString(),
-                                                       queueDataAddress);
-
-               ClientProducer prod = session.createProducer(ConfigurationImpl.DEFAULT_MANAGEMENT_ADDRESS);
-
-               prod.send(message);
-            }
-
-            active = true;
-
-            queue.deliverAsync(executor);
-         }
-         catch (Exception e)
-         {
-            log.warn("Unable to connect. Bridge is now disabled.", e);
-
-            active = false;
-
-            started = false;
-         }
-      }
-   }
-
-   public synchronized void stop() throws Exception
-   {
       if (!started)
       {
          return;
@@ -348,6 +286,9 @@
       {
          future.cancel(false);
       }
+     
+      // We close the session factory here - this will cause any connection retries to stop
+      csf.close();
 
       // Wait until all batches are complete
 
@@ -361,17 +302,59 @@
       {
          log.warn("Timed out waiting for batch to be sent");
       }
-      
-      session.close();
 
-      csf.close();
+      if (session != null)
+      {
+         session.close();
+      }
    }
 
    public boolean isStarted()
    {
       return started;
    }
+   
+   public SimpleString getName()
+   {
+      return name;
+   }
 
+   public Queue getQueue()
+   {
+      return queue;
+   }
+
+   public int getMaxBatchSize()
+   {
+      return maxBatchSize;
+   }
+
+   public long getMaxBatchTime()
+   {
+      return maxBatchTime;
+   }
+
+   public Filter getFilter()
+   {
+      return filter;
+   }
+
+   public SimpleString getForwardingAddress()
+   {
+      return forwardingAddress;
+   }
+
+   public Transformer getTransformer()
+   {
+      return transformer;
+   }
+
+   public boolean isUseDuplicateDetection()
+   {
+      return useDuplicateDetection;
+   }
+
+
    // For testing only
    public RemotingConnection getForwardingConnection()
    {
@@ -430,27 +413,58 @@
 
    // FailureListener implementation --------------------------------
 
-   public synchronized boolean connectionFailed(final MessagingException me)
+   public boolean connectionFailed(final MessagingException me)
    {
+      if (flowRecord != null)
+      {
+         try
+         {
+            flowRecord.reset();
+         }
+         catch (Exception e)
+         {
+            log.error("Failed to reset", e);
+         }
+      }
+
       fail();
 
       return true;
    }
 
-   private void fail()
+   private synchronized void fail()
    {
       if (!started)
       {
          return;
       }
+      
+      log.warn(System.identityHashCode(this) + " Bridge connection to target failed. Will try to reconnect");
 
-      log.warn("Bridge connection to target failed. Will try to reconnect");
-
       try
       {
          tx.rollback();
+         
+         active = false;
 
-         stop();
+         queue.removeConsumer(this);
+
+         // Wait until all batches are complete
+
+         Future future = new Future();
+
+         executor.execute(future);
+
+         boolean ok = future.await(10000);
+
+         if (!ok)
+         {
+            log.warn("Timed out waiting for batch to be sent");
+         }
+
+         session.cleanUp();         
+         
+         csf.close();
       }
       catch (Exception e)
       {
@@ -493,7 +507,8 @@
             return;
          }
 
-         // TODO - if batch size = 1 then don't need tx - actually we should use asynch send acknowledgement stream - then we don't need a transaction at all
+         // TODO - if batch size = 1 then don't need tx - actually we should use asynch send acknowledgement stream -
+         // then we don't need a transaction at all
 
          while (true)
          {
@@ -507,30 +522,32 @@
             ref.getQueue().acknowledge(tx, ref);
 
             ServerMessage message = ref.getMessage();
-            
-            if (this.forClusterConnector)
+
+            if (flowRecord != null)
             {
-               //We make a shallow copy of the message, then we strip out the unwanted routing id headers and leave only
-               //the one pertinent for the destination node - this is important since different queues on different nodes could have same queue ids
-               //Note we must copy since same message may get routed to other nodes which require different headers
+               // We make a shallow copy of the message, then we strip out the unwanted routing id headers and leave
+               // only
+               // the one pertinent for the destination node - this is important since different queues on different
+               // nodes could have same queue ids
+               // Note we must copy since same message may get routed to other nodes which require different headers
                message = message.copy();
-               
-               //TODO - we can optimise this
-              
+
+               // TODO - we can optimise this
+
                Set<SimpleString> propNames = new HashSet<SimpleString>(message.getPropertyNames());
-               
+
                byte[] queueIds = (byte[])message.getProperty(idsHeaderName);
-               
-               for (SimpleString propName: propNames)
+
+               for (SimpleString propName : propNames)
                {
                   if (propName.startsWith(MessageImpl.HDR_ROUTE_TO_IDS))
                   {
                      message.removeProperty(propName);
                   }
                }
-               
+
                message.putBytesProperty(MessageImpl.HDR_ROUTE_TO_IDS, queueIds);
-               
+
                message.putBooleanProperty(MessageImpl.HDR_FROM_CLUSTER, Boolean.TRUE);
             }
 
@@ -596,45 +613,116 @@
          timeoutBatch();
       }
    }
-
-   public SimpleString getName()
+   
+   private class CreateObjectsRunnable implements Runnable
    {
-      return name;
-   }
+      public synchronized void run()
+      {
+         if (!started)
+         {
+            return;
+         }
 
-   public Queue getQueue()
-   {
-      return queue;
-   }
+         try
+         {
+            createTx();
 
-   public int getMaxBatchSize()
-   {
-      return maxBatchSize;
-   }
+            queue.addConsumer(BridgeImpl.this);
 
-   public long getMaxBatchTime()
-   {
-      return maxBatchTime;
-   }
+            csf = new ClientSessionFactoryImpl(connectorPair.a,
+                                               connectorPair.b,
+                                               retryInterval,
+                                               retryIntervalMultiplier,
+                                               maxRetriesBeforeFailover,
+                                               maxRetriesAfterFailover);
 
-   public Filter getFilter()
-   {
-      return filter;
-   }
+            
+            session = (ClientSessionInternal)csf.createSession(false, false, false);
+            
+            if (session == null)
+            {
+               //This can happen if the bridge is shutdown 
+               return;
+            }
+            
+            producer = session.createProducer();
 
-   public SimpleString getForwardingAddress()
-   {
-      return forwardingAddress;
-   }
+            session.addFailureListener(BridgeImpl.this);
 
-   public Transformer getTransformer()
-   {
-      return transformer;
-   }
+            // TODO - we should move this code to the ClusterConnectorImpl - and just execute it when the bridge
+            // connection is opened and closed - we can use
+            // a callback to tell us that
+            if (flowRecord != null)
+            {
+               // Get the queue data
 
-   public boolean isUseDuplicateDetection()
-   {
-      return useDuplicateDetection;
+               SimpleString notifQueueName = new SimpleString("notif-").concat(UUIDGenerator.getInstance()
+                                                                                            .generateSimpleStringUUID());
+
+               // TODO - simplify this
+               SimpleString filter = new SimpleString(ManagementHelper.HDR_NOTIFICATION_TYPE + " IN (" +
+                                                      "'" +
+                                                      NotificationType.BINDING_ADDED +
+                                                      "'," +
+                                                      "'" +
+                                                      NotificationType.BINDING_REMOVED +
+                                                      "'," +
+                                                      "'" +
+                                                      NotificationType.CONSUMER_CREATED +
+                                                      "'," +
+                                                      "'" +
+                                                      NotificationType.CONSUMER_CLOSED +
+                                                      "') AND " +
+                                                      "(" +
+                                                      ManagementHelper.HDR_ADDRESS +
+                                                      " IS NULL OR " +
+                                                      ManagementHelper.HDR_ADDRESS +
+                                                      " LIKE '" +
+                                                      flowRecord.getAddress() +
+                                                      "%') AND " +
+                                                      ManagementHelper.HDR_ORIGINATING_NODE +
+                                                      "<>'" +
+                                                      flowRecord.getNodeID() +
+                                                      "'");
+
+               session.createQueue(DEFAULT_MANAGEMENT_NOTIFICATION_ADDRESS, notifQueueName, filter, false, true);
+
+               ClientConsumer notifConsumer = session.createConsumer(notifQueueName);
+
+               notifConsumer.setMessageHandler(flowRecord);
+
+               session.start();
+
+               ClientMessage message = session.createClientMessage(false);
+
+               ManagementHelper.putOperationInvocation(message,
+                                                       ManagementServiceImpl.getMessagingServerObjectName(),
+                                                       "sendQueueInfoToQueue",
+                                                       notifQueueName.toString(),
+                                                       flowRecord.getAddress());
+
+               ClientProducer prod = session.createProducer(ConfigurationImpl.DEFAULT_MANAGEMENT_ADDRESS);
+
+               prod.send(message);
+            }
+
+            active = true;
+
+            queue.deliverAsync(executor);
+            
+         }
+         catch (Exception e)
+         {
+            log.warn("Unable to connect. Bridge is now disabled.", e);
+
+            active = false;
+
+            started = false;
+         }
+
+         log.info("Bridge " + name + " connected successfully");
+      }
    }
 
+   
 }

Modified: trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterConnectionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterConnectionImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterConnectionImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -33,7 +33,6 @@
 import java.util.concurrent.ScheduledExecutorService;
 
 import org.jboss.messaging.core.client.ClientMessage;
-import org.jboss.messaging.core.client.MessageHandler;
 import org.jboss.messaging.core.client.management.impl.ManagementHelper;
 import org.jboss.messaging.core.cluster.DiscoveryGroup;
 import org.jboss.messaging.core.cluster.DiscoveryListener;
@@ -50,6 +49,7 @@
 import org.jboss.messaging.core.server.QueueFactory;
 import org.jboss.messaging.core.server.cluster.Bridge;
 import org.jboss.messaging.core.server.cluster.ClusterConnection;
+import org.jboss.messaging.core.server.cluster.MessageFlowRecord;
 import org.jboss.messaging.core.server.cluster.RemoteQueueBinding;
 import org.jboss.messaging.util.ExecutorFactory;
 import org.jboss.messaging.util.Pair;
@@ -94,6 +94,8 @@
 
    private final QueueFactory queueFactory;
 
+   private final SimpleString nodeID;
+
    private volatile boolean started;
 
    /*
@@ -109,7 +111,8 @@
                                 final PostOffice postOffice,
                                 final ScheduledExecutorService scheduledExecutor,
                                 final QueueFactory queueFactory,
-                                final List<Pair<TransportConfiguration, TransportConfiguration>> connectors) throws Exception
+                                final List<Pair<TransportConfiguration, TransportConfiguration>> connectors,
+                                final SimpleString nodeID) throws Exception
    {
       this.name = name;
 
@@ -133,6 +136,8 @@
 
       this.queueFactory = queueFactory;
 
+      this.nodeID = nodeID;
+
       this.updateConnectors(connectors);
    }
 
@@ -149,7 +154,8 @@
                                 final PostOffice postOffice,
                                 final ScheduledExecutorService scheduledExecutor,
                                 final QueueFactory queueFactory,
-                                final DiscoveryGroup discoveryGroup) throws Exception
+                                final DiscoveryGroup discoveryGroup,
+                                final SimpleString nodeID) throws Exception
    {
       this.name = name;
 
@@ -172,6 +178,8 @@
       this.useDuplicateDetection = useDuplicateDetection;
 
       this.routeWhenNoConsumers = routeWhenNoConsumers;
+
+      this.nodeID = nodeID;
    }
 
    public synchronized void start() throws Exception
@@ -282,12 +290,12 @@
                // Add binding in storage so the queue will get reloaded on startup and we can find it - it's never
                // actually routed to at that address though
 
-               Binding storeBinding = new LocalQueueBinding(queue.getName(), queue);
+               Binding storeBinding = new LocalQueueBinding(queue.getName(), queue, nodeID);
 
                storageManager.addQueueBinding(storeBinding);
             }
 
-            MessageFlowRecord record = new MessageFlowRecord(queue);
+            MessageFlowRecordImpl record = new MessageFlowRecordImpl(queue);
 
             Bridge bridge = new BridgeImpl(queueName,
                                            queue,
@@ -306,9 +314,7 @@
                                            bridgeConfig.getMaxRetriesBeforeFailover(),
                                            bridgeConfig.getMaxRetriesAfterFailover(),
                                            false, // Duplicate detection is handled in the RemoteQueueBindingImpl
-                                           record,
-                                           address.toString(),
-                                           true);
+                                           record);
 
             record.setBridge(bridge);
 
@@ -368,29 +374,36 @@
 
    // Inner classes -----------------------------------------------------------------------------------
 
-   private class MessageFlowRecord implements MessageHandler
+   private class MessageFlowRecordImpl implements MessageFlowRecord
    {
       private Bridge bridge;
 
       private final Queue queue;
 
-      private final Map<SimpleString, RemoteQueueBinding> bindings = new HashMap<SimpleString, RemoteQueueBinding>();
+      private final Map<SimpleString, Map<SimpleString, RemoteQueueBinding>> bindings = new HashMap<SimpleString, Map<SimpleString, RemoteQueueBinding>>();
 
       private boolean firstReset = false;
 
-      public MessageFlowRecord(final Queue queue)
+      public MessageFlowRecordImpl(final Queue queue)
       {
          this.queue = queue;
       }
 
+      public String getAddress()
+      {
+         return address.toString();
+      }
+
+      public String getNodeID()
+      {
+         return nodeID.toString();
+      }
+
       public void close() throws Exception
       {
          bridge.stop();
 
-         for (RemoteQueueBinding binding : bindings.values())
-         {
-            postOffice.removeBinding(binding.getUniqueName());
-         }
+         clearBindings();
       }
 
       public void setBridge(final Bridge bridge)
@@ -398,6 +411,12 @@
          this.bridge = bridge;
       }
 
+      public void reset() throws Exception
+      {
+         log.info(System.identityHashCode(ClusterConnectionImpl.this) + " calling reset");
+         clearBindings();
+      }
+
       public void onMessage(final ClientMessage message)
       {
          try
@@ -405,12 +424,9 @@
             // Reset the bindings
             if (message.getProperty(HDR_RESET_QUEUE_DATA) != null)
             {
-               for (RemoteQueueBinding binding : bindings.values())
-               {
-                  postOffice.removeBinding(binding.getUniqueName());
-               }
+               log.info("*** GOT RESET");
 
-               bindings.clear();
+               clearBindings();
 
                firstReset = true;
 
@@ -424,43 +440,88 @@
 
             NotificationType type = NotificationType.valueOf(message.getProperty(ManagementHelper.HDR_NOTIFICATION_TYPE)
                                                                     .toString());
-            
+
+            log.info(System.identityHashCode(ClusterConnectionImpl.this) + " Got notification " + type);
+
             if (type == NotificationType.BINDING_ADDED)
-            {               
+            {
                SimpleString uniqueName = UUIDGenerator.getInstance().generateSimpleStringUUID();
 
                SimpleString queueAddress = (SimpleString)message.getProperty(ManagementHelper.HDR_ADDRESS);
 
                SimpleString queueName = (SimpleString)message.getProperty(ManagementHelper.HDR_QUEUE_NAME);
-               
+
                SimpleString filterString = (SimpleString)message.getProperty(ManagementHelper.HDR_FILTERSTRING);
-               
+
                Integer queueID = (Integer)message.getProperty(ManagementHelper.HDR_BINDING_ID);
 
+               SimpleString origNodeID = (SimpleString)message.getProperty(ManagementHelper.HDR_ORIGINATING_NODE);
+
+               if (origNodeID.equals(nodeID))
+               {
+                  throw new IllegalStateException("Should not get a notification originating from this node " + nodeID);
+               }
+
+               log.info("Received a remote binding added, queue name " + queueName + " orig node id " + origNodeID);
+
                RemoteQueueBinding binding = new RemoteQueueBindingImpl(queueAddress,
                                                                        uniqueName,
                                                                        queueName,
                                                                        queueID,
                                                                        filterString,
                                                                        queue,
-                                                                       useDuplicateDetection,                                                           
-                                                                       bridge.getName());
+                                                                       useDuplicateDetection,
+                                                                       bridge.getName(),
+                                                                       origNodeID);
 
-               bindings.put(queueName, binding);
+               Map<SimpleString, RemoteQueueBinding> bindingMap = bindings.get(origNodeID);
 
+               if (bindingMap == null)
+               {
+                  bindingMap = new HashMap<SimpleString, RemoteQueueBinding>();
+
+                  bindings.put(origNodeID, bindingMap);
+               }
+
+               bindingMap.put(queueName, binding);
+
                postOffice.addBinding(binding);
-               
+
                Bindings theBindings = postOffice.getBindingsForAddress(queueAddress);
-               
+
                theBindings.setRouteWhenNoConsumers(routeWhenNoConsumers);
             }
             else if (type == NotificationType.BINDING_REMOVED)
             {
                SimpleString queueName = (SimpleString)message.getProperty(ManagementHelper.HDR_QUEUE_NAME);
 
-               RemoteQueueBinding binding = bindings.remove(queueName);
+               SimpleString origNodeID = (SimpleString)message.getProperty(ManagementHelper.HDR_ORIGINATING_NODE);
 
+               if (origNodeID.equals(nodeID))
+               {
+                  throw new IllegalStateException("Should not get a notification originating from this node");
+               }
+
+               Map<SimpleString, RemoteQueueBinding> bindingMap = bindings.get(origNodeID);
+
+               if (bindingMap == null)
+               {
+                  throw new IllegalStateException("Cannot find map for node " + origNodeID);
+               }
+
+               RemoteQueueBinding binding = bindingMap.remove(queueName);
+
+               if (binding == null)
+               {
+                  throw new IllegalStateException("Cannot find binding for queue " + queueName);
+               }
+
                postOffice.removeBinding(binding.getUniqueName());
+
+               if (bindingMap.isEmpty())
+               {
+                  bindings.remove(origNodeID);
+               }
             }
             else if (type == NotificationType.CONSUMER_CREATED)
             {
@@ -468,14 +529,27 @@
 
                SimpleString filterString = (SimpleString)message.getProperty(ManagementHelper.HDR_FILTERSTRING);
 
-               RemoteQueueBinding binding = bindings.get(queueName);
-               
-               if (binding != null)
+               SimpleString origNodeID = (SimpleString)message.getProperty(ManagementHelper.HDR_ORIGINATING_NODE);
+
+               if (origNodeID.equals(nodeID))
                {
-                  //Can legitimately be null if there are multiple cluster connections which will all receive create consumers for different addresses since
-                  //the address isn't checked on the filter when it's an add or create consumer message
-                  binding.addConsumer(filterString);
+                  throw new IllegalStateException("Should not get a notification originating from this node");
                }
+
+               Map<SimpleString, RemoteQueueBinding> bindingMap = bindings.get(origNodeID);
+
+               if (bindingMap != null)
+               {
+                  // Can legitimately be null if there are multiple cluster connections which will all receive create
+                  // consumers for different addresses since
+                  // the address isn't checked on the filter when it's an add or create consumer message
+                  RemoteQueueBinding binding = bindingMap.get(queueName);
+
+                  if (binding != null)
+                  {
+                     binding.addConsumer(filterString);
+                  }
+               }
             }
             else if (type == NotificationType.CONSUMER_CLOSED)
             {
@@ -483,14 +557,26 @@
 
                SimpleString filterString = (SimpleString)message.getProperty(ManagementHelper.HDR_FILTERSTRING);
 
-               RemoteQueueBinding binding = bindings.get(queueName);
-               
-               if (binding != null)
+               SimpleString origNodeID = (SimpleString)message.getProperty(ManagementHelper.HDR_ORIGINATING_NODE);
+
+               if (origNodeID.equals(nodeID))
                {
-                  //Can legitimately be null if there are multiple cluster connections which will all receive create consumers for different addresses since
-                  //the address isn't checked on the filter when it's an add or create consumer message
+                  throw new IllegalStateException("Should not get a notification originating from this node");
+               }
 
-                  binding.removeConsumer(filterString);
+               Map<SimpleString, RemoteQueueBinding> bindingMap = bindings.get(origNodeID);
+
+               if (bindingMap != null)
+               {
+                  // Can legitimately be null if there are multiple cluster connections which will all receive create
+                  // consumers for different addresses since
+                  // the address isn't checked on the filter when it's an add or create consumer message
+                  RemoteQueueBinding binding = bindingMap.get(queueName);
+
+                  if (binding != null)
+                  {
+                     binding.removeConsumer(filterString);
+                  }
                }
             }
          }
@@ -500,6 +586,23 @@
          }
       }
 
+      private void clearBindings() throws Exception
+      {
+         log.info("** clearing bindings " + bindings.size() + " node id " + nodeID);
+
+         for (Map<SimpleString, RemoteQueueBinding> bindingMap : bindings.values())
+         {
+            for (RemoteQueueBinding binding : bindingMap.values())
+            {
+               log.info("**** removed binding");
+
+               postOffice.removeBinding(binding.getUniqueName());
+            }
+         }
+
+         bindings.clear();
+      }
+
    }
 
 }

Modified: trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterManagerImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/cluster/impl/ClusterManagerImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -90,6 +90,8 @@
    private final Configuration configuration;
 
    private final QueueFactory queueFactory;
+   
+   private final SimpleString nodeID;
 
    private volatile boolean started;
 
@@ -99,7 +101,8 @@
                              final ScheduledExecutorService scheduledExecutor,
                              final ManagementService managementService,
                              final Configuration configuration,
-                             final QueueFactory queueFactory)
+                             final QueueFactory queueFactory,
+                             final SimpleString nodeID)
    {
       this.executorFactory = executorFactory;
 
@@ -114,6 +117,8 @@
       this.configuration = configuration;
 
       this.queueFactory = queueFactory;
+      
+      this.nodeID = nodeID;
    }
 
    public synchronized void start() throws Exception
@@ -396,10 +401,7 @@
                                  config.getRetryIntervalMultiplier(),
                                  config.getMaxRetriesBeforeFailover(),
                                  config.getMaxRetriesAfterFailover(),
-                                 config.isUseDuplicateDetection(),
-                                 null,
-                                 null,
-                                 false);
+                                 config.isUseDuplicateDetection());
 
          bridges.put(config.getName(), bridge);
 
@@ -474,7 +476,8 @@
                                                        postOffice,
                                                        scheduledExecutor,
                                                        queueFactory,
-                                                       connectors);
+                                                       connectors,
+                                                       nodeID);
       }
       else
       {
@@ -496,7 +499,8 @@
                                                        postOffice,
                                                        scheduledExecutor,
                                                        queueFactory,
-                                                       dg);
+                                                       dg,
+                                                       nodeID);
       }
 
       managementService.registerCluster(clusterConnection, config);

Modified: trunk/src/main/org/jboss/messaging/core/server/cluster/impl/RemoteQueueBindingImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/cluster/impl/RemoteQueueBindingImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/cluster/impl/RemoteQueueBindingImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -75,7 +75,9 @@
    private final SimpleString idsHeaderName;
    
    private int id;
-   
+      
+   private final SimpleString originatingNodeID;
+      
    public RemoteQueueBindingImpl(final SimpleString address,
                                  final SimpleString uniqueName,
                                  final SimpleString routingName,
@@ -83,7 +85,8 @@
                                  final SimpleString filterString,
                                  final Queue storeAndForwardQueue,
                                  final boolean duplicateDetection,                      
-                                 final SimpleString bridgeName) throws Exception
+                                 final SimpleString bridgeName,
+                                 final SimpleString origNodeID) throws Exception
    {
       this.address = address;
 
@@ -107,6 +110,8 @@
       }
       
       this.idsHeaderName = MessageImpl.HDR_ROUTE_TO_IDS.concat(bridgeName);
+      
+      this.originatingNodeID = origNodeID;
    }
    
    public int getID()
@@ -153,6 +158,11 @@
    {
       return queueFilter;
    }
+   
+   public SimpleString getOriginatingNodeID()
+   {
+      return originatingNodeID;
+   }
 
    public boolean isHighAcceptPriority(final ServerMessage message)
    {      

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -51,10 +51,10 @@
 import org.jboss.messaging.core.remoting.Channel;
 import org.jboss.messaging.core.remoting.ChannelHandler;
 import org.jboss.messaging.core.remoting.RemotingConnection;
-import org.jboss.messaging.core.remoting.RemotingService;
 import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateSessionResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ReattachSessionResponseMessage;
+import org.jboss.messaging.core.remoting.server.RemotingService;
 import org.jboss.messaging.core.remoting.spi.Connection;
 import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
 import org.jboss.messaging.core.remoting.spi.ConnectorFactory;
@@ -81,6 +81,7 @@
 import org.jboss.messaging.util.OrderedExecutorFactory;
 import org.jboss.messaging.util.Pair;
 import org.jboss.messaging.util.SimpleString;
+import org.jboss.messaging.util.UUIDGenerator;
 import org.jboss.messaging.util.VersionLoader;
 
 /**
@@ -103,6 +104,8 @@
    // Attributes
    // -----------------------------------------------------------------------------------
 
+   private SimpleString nodeID;
+   
    private final Version version;
 
    private volatile boolean started;
@@ -171,6 +174,10 @@
          return;
       }
 
+      nodeID = UUIDGenerator.getInstance().generateSimpleStringUUID();
+      
+      log.info("*** Starting " + this.nodeID);
+      
       asyncDeliveryPool = Executors.newCachedThreadPool(new JBMThreadFactory("JBM-async-session-delivery-threads"));
 
       executorFactory = new OrderedExecutorFactory(asyncDeliveryPool);
@@ -290,7 +297,7 @@
                                                 true,
                                                 false);
 
-         Binding binding = new LocalQueueBinding(queueBindingInfo.getAddress(), queue);
+         Binding binding = new LocalQueueBinding(queueBindingInfo.getAddress(), queue, nodeID);
 
          queues.put(queueBindingInfo.getPersistenceID(), queue);
 
@@ -373,7 +380,8 @@
                                                  scheduledExecutor,
                                                  managementService,
                                                  configuration,
-                                                 queueFactory);
+                                                 queueFactory,
+                                                 nodeID);
 
          clusterManager.start();
       }
@@ -427,6 +435,8 @@
       queueFactory = null;
       resourceManager = null;
       serverManagement = null;
+      
+      sessions.clear();
 
       managementService.stop();
       started = false;
@@ -598,6 +608,8 @@
       // will never get back
 
       checkActivate(connection);
+      
+      log.info("Got reattach session " + this.nodeID + " session is " + session);
 
       if (session == null)
       {
@@ -740,6 +752,11 @@
    {
       return queueFactory;
    }
+   
+   public SimpleString getNodeID()
+   {
+      return nodeID;
+   }
 
    // Public
    // ---------------------------------------------------------------------------------------
@@ -803,7 +820,7 @@
 
             Queue queue = queueFactory.createQueue(-1, address, name, filter, config.isDurable(), false);
 
-            Binding queueBinding = new LocalQueueBinding(new SimpleString(config.getAddress()), queue);
+            Binding queueBinding = new LocalQueueBinding(new SimpleString(config.getAddress()), queue, nodeID);
             
             binding = queueBinding;
 
@@ -872,7 +889,7 @@
                                         pagingManager,
                                         storageManager);
 
-         Binding binding = new DivertBinding(sAddress, divert);
+         Binding binding = new DivertBinding(sAddress, divert, nodeID);
 
          postOffice.addBinding(binding);
       }

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerPacketHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerPacketHandler.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServerPacketHandler.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -20,7 +20,6 @@
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.Channel;
 import org.jboss.messaging.core.remoting.ChannelHandler;
-import org.jboss.messaging.core.remoting.DelayedResult;
 import org.jboss.messaging.core.remoting.Packet;
 import org.jboss.messaging.core.remoting.RemotingConnection;
 import org.jboss.messaging.core.remoting.impl.wireformat.CreateSessionMessage;
@@ -28,6 +27,7 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
 import org.jboss.messaging.core.remoting.impl.wireformat.ReattachSessionMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.ReplicateCreateSessionMessage;
+import org.jboss.messaging.core.remoting.server.DelayedResult;
 import org.jboss.messaging.core.server.MessagingServer;
 
 /**

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServiceImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/MessagingServiceImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -21,21 +21,9 @@
   */
 package org.jboss.messaging.core.server.impl;
 
-import java.lang.management.ManagementFactory;
-
-import javax.management.MBeanServer;
-
-import org.jboss.messaging.core.config.Configuration;
-import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.management.ManagementService;
-import org.jboss.messaging.core.management.impl.ManagementServiceImpl;
+import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.persistence.StorageManager;
-import org.jboss.messaging.core.persistence.impl.journal.JournalStorageManager;
-import org.jboss.messaging.core.persistence.impl.nullpm.NullStorageManager;
-import org.jboss.messaging.core.remoting.RemotingService;
-import org.jboss.messaging.core.remoting.impl.RemotingServiceImpl;
-import org.jboss.messaging.core.security.JBMSecurityManager;
-import org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl;
+import org.jboss.messaging.core.remoting.server.RemotingService;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.core.server.MessagingService;
 
@@ -47,8 +35,10 @@
  */
 public class MessagingServiceImpl implements MessagingService
 {
-      private final MessagingServer server;
+   private static final Logger log = Logger.getLogger(MessagingServiceImpl.class);
 
+   private final MessagingServer server;
+
    private final StorageManager storageManager;
 
    private final RemotingService remotingService;
@@ -64,10 +54,11 @@
 
    public void start() throws Exception
    {
-      storageManager.start();      
+      storageManager.start();
       server.start();
-      //Remoting service should always be started last, otherwise create session packets can be received before the message server packet handler has been registered
-      //resulting in create session attempts to "hang" since response will never be sent back.
+      // Remoting service should always be started last, otherwise create session packets can be received before the
+      // message server packet handler has been registered
+      // resulting in create session attempts to "hang" since response will never be sent back.
       remotingService.start();
    }
 

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/QueueImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -12,6 +12,7 @@
 
 package org.jboss.messaging.core.server.impl;
 
+import org.jboss.messaging.core.client.management.impl.ManagementHelper;
 import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.list.PriorityLinkedList;
 import org.jboss.messaging.core.list.impl.PriorityLinkedListImpl;
@@ -198,6 +199,14 @@
 
    public void route(final ServerMessage message, final Transaction tx) throws Exception
    {
+//      SimpleString filterString = null;
+//      if (filter != null)
+//      {
+//         filterString = filter.getFilterString();
+//      }
+      
+      //log.info("Adding message to queue " + name + " with filter " + filterString + " message has orig node " + message.getProperty(ManagementHelper.HDR_ORIGINATING_NODE));
+      
       boolean durableRef = message.isDurable() && durable;
 
       // If durable, must be persisted before anything is routed

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -42,7 +42,6 @@
 import org.jboss.messaging.core.paging.PagingStore;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.remoting.Channel;
-import org.jboss.messaging.core.remoting.DelayedResult;
 import org.jboss.messaging.core.remoting.Packet;
 import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
 import org.jboss.messaging.core.remoting.impl.wireformat.MessagingExceptionMessage;
@@ -50,6 +49,7 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionReceiveMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionReplicateDeliveryMessage;
+import org.jboss.messaging.core.remoting.server.DelayedResult;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.core.server.HandleStatus;
 import org.jboss.messaging.core.server.LargeServerMessage;
@@ -62,6 +62,7 @@
 import org.jboss.messaging.core.transaction.impl.TransactionImpl;
 import org.jboss.messaging.util.SimpleString;
 import org.jboss.messaging.util.TypedProperties;
+import org.jboss.messaging.util.UUIDGenerator;
 
 /**
  * Concrete implementation of a ClientConsumer.
@@ -134,6 +135,8 @@
    private final boolean preAcknowledge;
    
    private final ManagementService managementService;
+   
+   private final SimpleString nodeID;
 
    // Constructors ---------------------------------------------------------------------------------
 
@@ -149,7 +152,8 @@
                              final Channel channel,
                              final boolean preAcknowledge,
                              final Executor executor,
-                             final ManagementService managementService)
+                             final ManagementService managementService,
+                             final SimpleString nodeID)
    {
       this.id = id;
 
@@ -176,6 +180,8 @@
       this.pagingManager = pagingManager;
       
       this.managementService = managementService;
+      
+      this.nodeID = nodeID;
 
       messageQueue.addConsumer(this);
 
@@ -191,7 +197,7 @@
    }
 
    public HandleStatus handle(final MessageReference ref) throws Exception
-   {
+   {      
       return doHandle(ref);
    }
    
@@ -293,6 +299,7 @@
          TypedProperties props = new TypedProperties();
          
          props.putStringProperty(ManagementHelper.HDR_QUEUE_NAME, messageQueue.getName());
+         props.putStringProperty(ManagementHelper.HDR_ORIGINATING_NODE, nodeID);
          
          Notification notification = new Notification(NotificationType.CONSUMER_CLOSED, props);
          

Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -41,7 +41,6 @@
 import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.postoffice.impl.LocalQueueBinding;
 import org.jboss.messaging.core.remoting.Channel;
-import org.jboss.messaging.core.remoting.DelayedResult;
 import org.jboss.messaging.core.remoting.FailureListener;
 import org.jboss.messaging.core.remoting.Packet;
 import org.jboss.messaging.core.remoting.RemotingConnection;
@@ -78,6 +77,7 @@
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutResponseMessage;
 import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAStartMessage;
+import org.jboss.messaging.core.remoting.server.DelayedResult;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.core.security.CheckType;
 import org.jboss.messaging.core.security.SecurityStore;
@@ -1413,7 +1413,8 @@
                                                           channel,
                                                           preAcknowledge,
                                                           executor,
-                                                          managementService);
+                                                          managementService,
+                                                          server.getNodeID());
 
          consumers.put(consumer.getID(), consumer);
          
@@ -1422,6 +1423,7 @@
             TypedProperties props = new TypedProperties();
             
             props.putStringProperty(ManagementHelper.HDR_QUEUE_NAME, name);
+            props.putStringProperty(ManagementHelper.HDR_ORIGINATING_NODE, binding.getOriginatingNodeID());
             
             if (filterString != null)
             {
@@ -1492,7 +1494,7 @@
 
          final Queue queue = queueFactory.createQueue(-1, address, name, filter, durable, temporary);
 
-         binding = new LocalQueueBinding(address, queue);
+         binding = new LocalQueueBinding(address, queue, server.getNodeID());
 
          if (durable)
          {

Modified: trunk/src/main/org/jboss/messaging/integration/transports/netty/MessagingChannelHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/integration/transports/netty/MessagingChannelHandler.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/integration/transports/netty/MessagingChannelHandler.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -84,8 +84,6 @@
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception
    {
-      log.error("caught exception " + e.getCause() + " for channel " + e.getChannel(), e.getCause());
-
       synchronized (this)
       {
          if (!active)

Modified: trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyAcceptor.java
===================================================================
--- trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyAcceptor.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyAcceptor.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -24,12 +24,11 @@
 
 import static org.jboss.netty.channel.Channels.pipeline;
 
-import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.net.NetworkInterface;
-import java.util.Enumeration;
 import java.util.Map;
 import java.util.Timer;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
@@ -37,7 +36,9 @@
 import javax.net.ssl.SSLContext;
 
 import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnector;
 import org.jboss.messaging.core.remoting.impl.ssl.SSLSupport;
 import org.jboss.messaging.core.remoting.spi.Acceptor;
 import org.jboss.messaging.core.remoting.spi.BufferHandler;
@@ -119,6 +120,8 @@
    private final Timer httpKeepAliveTimer;
 
    private final HttpKeepAliveTask httpKeepAliveTask;
+   
+   private ConcurrentMap<Object, Connection> connections = new ConcurrentHashMap<Object, Connection>();
 
    public NettyAcceptor(final Map<String, Object> configuration,
                         final BufferHandler handler,
@@ -315,6 +318,13 @@
          }
       }
       channelFactory = null;
+      
+      for (Connection connection : connections.values())
+      {
+         listener.connectionDestroyed(connection.getID());
+      }
+
+      connections.clear();
    }
    
    public boolean isStarted()
@@ -334,9 +344,9 @@
 
       @Override
       public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
-      {
-         final Connection tc = new NettyConnection(e.getChannel());
-
+      {         
+         final Connection tc = new NettyConnection(e.getChannel(), new Listener());
+         
          SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
          if (sslHandler != null)
          {
@@ -363,4 +373,28 @@
          }
       }
    }
+   
+   private class Listener implements ConnectionLifeCycleListener
+   {
+      public void connectionCreated(final Connection connection)
+      {
+         if (connections.putIfAbsent(connection.getID(), connection) != null)
+         {
+            throw new IllegalArgumentException("Connection already exists with id " + connection.getID());
+         }
+      }
+
+      public void connectionDestroyed(final Object connectionID)
+      {
+         if (connections.remove(connectionID) != null)
+         {
+            listener.connectionDestroyed(connectionID);
+         }
+      }
+
+      public void connectionException(final Object connectionID, final MessagingException me)
+      {
+         listener.connectionException(connectionID, me);
+      }
+   }
 }

Modified: trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyConnection.java
===================================================================
--- trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyConnection.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyConnection.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -22,7 +22,9 @@
 
 package org.jboss.messaging.integration.transports.netty;
 
+import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.spi.Connection;
+import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.netty.channel.Channel;
 import org.jboss.netty.channel.ChannelFutureListener;
@@ -38,20 +40,29 @@
 public class NettyConnection implements Connection
 {
    // Constants -----------------------------------------------------
+   
+   private static final Logger log = Logger.getLogger(NettyConnection.class);
 
+
    // Attributes ----------------------------------------------------
 
    private final Channel channel;
 
    private boolean closed;
+   
+   private final ConnectionLifeCycleListener listener;
 
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
 
-   public NettyConnection(final Channel channel)
-   {
+   public NettyConnection(final Channel channel, final ConnectionLifeCycleListener listener)
+   {      
       this.channel = channel;
+      
+      this.listener = listener;
+      
+      listener.connectionCreated(this);
    }
 
    // Public --------------------------------------------------------
@@ -97,6 +108,8 @@
       // }
 
       closed = true;
+      
+      listener.connectionDestroyed(getID());
    }
 
    public MessagingBuffer createBuffer(int size)

Modified: trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyConnector.java
===================================================================
--- trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyConnector.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/integration/transports/netty/NettyConnector.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -28,6 +28,8 @@
 import java.util.Map;
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
@@ -35,6 +37,7 @@
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLException;
 
+import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.remoting.impl.ssl.SSLSupport;
 import org.jboss.messaging.core.remoting.spi.BufferHandler;
@@ -117,6 +120,8 @@
    private final int tcpSendBufferSize;
 
    private final int tcpReceiveBufferSize;
+   
+   private ConcurrentMap<Object, Connection> connections = new ConcurrentHashMap<Object, Connection>();
 
    // Static --------------------------------------------------------
 
@@ -148,7 +153,7 @@
       this.httpEnabled = ConfigurationHelper.getBooleanProperty(TransportConstants.HTTP_ENABLED_PROP_NAME,
                                                                 TransportConstants.DEFAULT_HTTP_ENABLED,
                                                                 configuration);
-
+      
       if (httpEnabled)
       {
          this.httpMaxClientIdleTime = ConfigurationHelper.getLongProperty(TransportConstants.HTTP_CLIENT_IDLE_PROP_NAME,
@@ -206,7 +211,7 @@
       {
          return;
       }
-
+      
       workerExecutor = Executors.newCachedThreadPool(new JBMThreadFactory("jbm-netty-connector-worker-threads"));
       if (useNio)
       {
@@ -304,6 +309,13 @@
             }
          }
       }
+      
+      for (Connection connection : connections.values())
+      {
+         listener.connectionDestroyed(connection.getID());
+      }
+
+      connections.clear();
    }
    
    public boolean isStarted()
@@ -352,8 +364,10 @@
          {
             ch.getPipeline().get(MessagingChannelHandler.class).active = true;
          }
-
-         return new NettyConnection(ch);
+         
+         NettyConnection conn =  new NettyConnection(ch, new Listener());
+         
+         return conn;
       }
       else
       {
@@ -381,7 +395,7 @@
    }
 
    @ChannelPipelineCoverage("all")
-   class HttpHandler extends SimpleChannelHandler
+   private class HttpHandler extends SimpleChannelHandler
    {
       private Channel channel;
 
@@ -413,6 +427,7 @@
 
             idleClientTimer.cancel();
          }
+         
          super.channelClosed(ctx, e);
       }
 
@@ -466,5 +481,26 @@
          }
       }
    }
+   
+   private class Listener implements ConnectionLifeCycleListener
+   {
+      public void connectionCreated(final Connection connection)
+      {
+         if (connections.putIfAbsent(connection.getID(), connection) != null)
+         {
+            throw new IllegalArgumentException("Connection already exists with id " + connection.getID());
+         }
+      }
 
+      public void connectionDestroyed(final Object connectionID)
+      {
+         connections.remove(connectionID);
+      }
+
+      public void connectionException(final Object connectionID, final MessagingException me)
+      {
+         listener.connectionException(connectionID, me);
+      }
+   }
+
 }

Modified: trunk/src/main/org/jboss/messaging/util/SimpleString.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/SimpleString.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/src/main/org/jboss/messaging/util/SimpleString.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -38,6 +38,11 @@
  * this minimises expensive copying between String objects
  * 
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * TODO - implement an intern() method like in java.lang.String, since many Strings e.g. addresses, queue names, remote node ids are duplicated heavily
+ * in bindings taking up more memory than they should
+ * Intern can be called when receiving a sent message at the server (destination)
+ * Also when receiving bindings remotely via bridge, the address, queue name and node id can be interned
  *
  */
 public class SimpleString implements CharSequence, Serializable, Comparable<SimpleString>

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/MessageChunkTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/MessageChunkTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/chunkmessage/MessageChunkTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -44,7 +44,7 @@
 import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
 import org.jboss.messaging.core.remoting.impl.RemotingConnectionImpl;
-import org.jboss.messaging.core.remoting.impl.RemotingServiceImpl;
+import org.jboss.messaging.core.remoting.server.impl.RemotingServiceImpl;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.core.settings.impl.AddressSettings;
 import org.jboss.messaging.tests.integration.chunkmessage.mock.MockConnector;

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/BridgeStartTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/BridgeStartTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/bridge/BridgeStartTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -84,7 +84,7 @@
       Pair<String, String> connectorPair = new Pair<String, String>(server1tc.getName(), null);
 
       final String bridgeName = "bridge1";
-      
+
       BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
                                                                         queueName0,
                                                                         forwardAddress,
@@ -96,7 +96,7 @@
                                                                         1d,
                                                                         0,
                                                                         0,
-                                                                        false,                                                                        
+                                                                        false,
                                                                         connectorPair);
 
       List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
@@ -155,11 +155,11 @@
       }
 
       assertNull(consumer1.receive(200));
-      
+
       Bridge bridge = service0.getServer().getClusterManager().getBridges().get(bridgeName);
-      
+
       bridge.stop();
-      
+
       for (int i = 0; i < numMessages; i++)
       {
          ClientMessage message = session0.createClientMessage(false);
@@ -168,14 +168,14 @@
 
          producer0.send(message);
       }
-      
+
       assertNull(consumer1.receive(500));
-      
+
       bridge.start();
-      
+
       for (int i = 0; i < numMessages; i++)
       {
-         ClientMessage message = consumer1.receive(200);
+         ClientMessage message = consumer1.receive(1000);
 
          assertNotNull(message);
 
@@ -183,7 +183,7 @@
 
          message.acknowledge();
       }
-      
+
       assertNull(consumer1.receive(200));
 
       session0.close();
@@ -198,7 +198,7 @@
 
       service1.stop();
    }
-   
+
    public void testTargetServerUpAndDown() throws Exception
    {
       Map<String, Object> service0Params = new HashMap<String, Object>();
@@ -225,7 +225,7 @@
       Pair<String, String> connectorPair = new Pair<String, String>(server1tc.getName(), null);
 
       final String bridgeName = "bridge1";
-      
+
       BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
                                                                         queueName0,
                                                                         forwardAddress,
@@ -237,7 +237,7 @@
                                                                         1d,
                                                                         -1,
                                                                         -1,
-                                                                        false,                                                                        
+                                                                        false,
                                                                         connectorPair);
 
       List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
@@ -254,12 +254,11 @@
       queueConfigs1.add(queueConfig1);
       service1.getServer().getConfiguration().setQueueConfigurations(queueConfigs1);
 
-      try{
-         //Don't start service 1 yet
+      try
+      {
+         // Don't start service 1 yet
 
-         log.info("starting 0");
-         service0.start();      
-         log.info("started 0");
+         service0.start();
 
          ClientSessionFactory sf0 = new ClientSessionFactoryImpl(server0tc);
 
@@ -280,12 +279,10 @@
             producer0.send(message);
          }
 
-         //Wait a bit
+         // Wait a bit
          Thread.sleep(1000);
 
-         log.info("starting 1");
          service1.start();
-         log.info("started server 1");
 
          ClientSessionFactory sf1 = new ClientSessionFactoryImpl(server1tc);
 
@@ -308,8 +305,6 @@
 
          assertNull(consumer1.receive(200));
 
-         log.info("consumed messages");
-
          for (int i = 0; i < numMessages; i++)
          {
             ClientMessage message = session0.createClientMessage(false);
@@ -336,9 +331,7 @@
 
          sf1.close();
 
-         log.info("stipping 1");
          service1.stop();
-         log.info("stopped 1");
 
          for (int i = 0; i < numMessages; i++)
          {
@@ -349,19 +342,16 @@
             producer0.send(message);
          }
 
-         log.info("Sent more messages");
 
          service1.start();
 
-         log.info("started service1");
-
          sf1 = new ClientSessionFactoryImpl(server1tc);
 
          session1 = sf1.createSession(false, true, true);
 
          consumer1 = session1.createConsumer(queueName1);
 
-         log.info("**** started session");
+
          session1.start();
 
          for (int i = 0; i < numMessages; i++)
@@ -377,7 +367,6 @@
 
          assertNull(consumer1.receive(200));
 
-         log.info("received all messages again");
 
          session1.close();
 
@@ -387,7 +376,6 @@
 
          sf0.close();
 
-
       }
       finally
       {
@@ -396,7 +384,7 @@
          service1.stop();
       }
    }
-   
+
    public void testTargetServerNotAvailableNoReconnectTries() throws Exception
    {
       Map<String, Object> service0Params = new HashMap<String, Object>();
@@ -423,7 +411,7 @@
       Pair<String, String> connectorPair = new Pair<String, String>(server1tc.getName(), null);
 
       final String bridgeName = "bridge1";
-      
+
       BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
                                                                         queueName0,
                                                                         forwardAddress,
@@ -435,7 +423,7 @@
                                                                         1d,
                                                                         0,
                                                                         0,
-                                                                        false,                                                                        
+                                                                        false,
                                                                         connectorPair);
 
       List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
@@ -451,19 +439,17 @@
       List<QueueConfiguration> queueConfigs1 = new ArrayList<QueueConfiguration>();
       queueConfigs1.add(queueConfig1);
       service1.getServer().getConfiguration().setQueueConfigurations(queueConfigs1);
-      
-      //Don't start service 1 yet
-      
-      log.info("starting 0");
-      service0.start();      
-      log.info("started 0");
 
+      // Don't start service 1 yet
+
+      service0.start();
+
       ClientSessionFactory sf0 = new ClientSessionFactoryImpl(server0tc);
-      
+
       ClientSession session0 = sf0.createSession(false, true, true);
-      
+
       ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
-                 
+
       final int numMessages = 10;
 
       final SimpleString propKey = new SimpleString("testkey");
@@ -476,61 +462,59 @@
 
          producer0.send(message);
       }
-      
-      //Wait a bit
+
+      // Wait a bit
       Thread.sleep(1000);
-      
-      //Bridge should be stopped since retries = 0
-      
-      log.info("starting 1");
+
+      // Bridge should be stopped since retries = 0
+;
       service1.start();
-      log.info("started server 1");
-      
+
       ClientSessionFactory sf1 = new ClientSessionFactoryImpl(server1tc);
-      
+
       ClientSession session1 = sf1.createSession(false, true, true);
-     
+
       ClientConsumer consumer1 = session1.createConsumer(queueName1);
 
       session1.start();
 
-      //Won't be received since the bridge was deactivated
+      // Won't be received since the bridge was deactivated
       assertNull(consumer1.receive(200));
-      
-      //Now start the bridge manually
-      
+
+      // Now start the bridge manually
+
       Bridge bridge = service0.getServer().getClusterManager().getBridges().get(bridgeName);
-      
+
       bridge.start();
-      
-      //Messages should now be received
-      
+
+      // Messages should now be received
+
       for (int i = 0; i < numMessages; i++)
       {
          ClientMessage message = consumer1.receive(1000);
-
+         
          assertNotNull(message);
 
          assertEquals((Integer)i, (Integer)message.getProperty(propKey));
 
          message.acknowledge();
       }
-      
+
       assertNull(consumer1.receive(200));
-                 
+
       session1.close();
-      
+
       sf1.close();
-      
+
       session0.close();
 
       sf0.close();
-      
+
       service0.stop();
 
       service1.stop();
    }
-   
+
    public void testManualStopStart() throws Exception
    {
       Map<String, Object> service0Params = new HashMap<String, Object>();
@@ -557,7 +541,7 @@
       Pair<String, String> connectorPair = new Pair<String, String>(server1tc.getName(), null);
 
       final String bridgeName = "bridge1";
-      
+
       BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
                                                                         queueName0,
                                                                         forwardAddress,
@@ -569,7 +553,7 @@
                                                                         1d,
                                                                         0,
                                                                         0,
-                                                                        false,                                                                        
+                                                                        false,
                                                                         connectorPair);
 
       List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
@@ -585,17 +569,17 @@
       List<QueueConfiguration> queueConfigs1 = new ArrayList<QueueConfiguration>();
       queueConfigs1.add(queueConfig1);
       service1.getServer().getConfiguration().setQueueConfigurations(queueConfigs1);
-      
+
       service1.start();
-      
-      service0.start();      
 
+      service0.start();
+
       ClientSessionFactory sf0 = new ClientSessionFactoryImpl(server0tc);
-      
+
       ClientSession session0 = sf0.createSession(false, true, true);
-      
+
       ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
-                 
+
       final int numMessages = 10;
 
       final SimpleString propKey = new SimpleString("testkey");
@@ -608,15 +592,15 @@
 
          producer0.send(message);
       }
-      
+
       ClientSessionFactory sf1 = new ClientSessionFactoryImpl(server1tc);
-      
+
       ClientSession session1 = sf1.createSession(false, true, true);
-     
+
       ClientConsumer consumer1 = session1.createConsumer(queueName1);
 
       session1.start();
-      
+
       for (int i = 0; i < numMessages; i++)
       {
          ClientMessage message = consumer1.receive(1000);
@@ -627,15 +611,15 @@
 
          message.acknowledge();
       }
-      
+
       assertNull(consumer1.receive(200));
-      
-      //Now stop the bridge manually
-      
+
+      // Now stop the bridge manually
+
       Bridge bridge = service0.getServer().getClusterManager().getBridges().get(bridgeName);
-      
+
       bridge.stop();
-      
+
       for (int i = 0; i < numMessages; i++)
       {
          ClientMessage message = session0.createClientMessage(false);
@@ -644,11 +628,11 @@
 
          producer0.send(message);
       }
-      
+
       assertNull(consumer1.receive(200));
-      
+
       bridge.start();
-      
+
       for (int i = 0; i < numMessages; i++)
       {
          ClientMessage message = consumer1.receive(1000);
@@ -659,11 +643,11 @@
 
          message.acknowledge();
       }
-                 
+
       assertNull(consumer1.receive(200));
-      
+
       bridge.stop();
-      
+
       for (int i = 0; i < numMessages; i++)
       {
          ClientMessage message = session0.createClientMessage(false);
@@ -672,11 +656,11 @@
 
          producer0.send(message);
       }
-      
+
       assertNull(consumer1.receive(200));
-      
+
       bridge.start();
-      
+
       for (int i = 0; i < numMessages; i++)
       {
          ClientMessage message = consumer1.receive(1000);
@@ -687,21 +671,20 @@
 
          message.acknowledge();
       }
-                 
+
       assertNull(consumer1.receive(200));
-                 
+
       session1.close();
-      
+
       sf1.close();
-      
+
       session0.close();
 
       sf0.close();
-      
+
       service0.stop();
 
       service1.stop();
    }
 
-
 }

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/ClusterTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/ClusterTestBase.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/ClusterTestBase.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -67,7 +67,7 @@
    private static final Logger log = Logger.getLogger(ClusterTestBase.class);
 
    private static final long WAIT_TIMEOUT = 10000;
-  
+
    @Override
    protected void setUp() throws Exception
    {
@@ -86,21 +86,20 @@
 
    private static final int MAX_CONSUMERS = 100;
 
-   
    private static class ConsumerHolder
    {
       final ClientConsumer consumer;
-      
+
       final ClientSession session;
-      
+
       ConsumerHolder(final ClientConsumer consumer, final ClientSession session)
       {
          this.consumer = consumer;
-         
+
          this.session = session;
       }
    }
-   
+
    private ConsumerHolder[] consumers = new ConsumerHolder[MAX_CONSUMERS];
 
    private static final SimpleString COUNT_PROP = new SimpleString("count_prop");
@@ -112,14 +111,22 @@
    private MessagingService[] services = new MessagingService[MAX_SERVERS];
 
    private ClientSessionFactory[] sfs = new ClientSessionFactory[MAX_SERVERS];
-   
+
    protected void waitForBindings(int node,
-                                final String address,
-                                final int count,
-                                final int consumerCount,
-                                final boolean local) throws Exception
+                                  final String address,
+                                  final int count,
+                                  final int consumerCount,
+                                  final boolean local) throws Exception
    {
-      //log.info("waiting for bindings on node " + node + " address " + address + " count " + count + " consumerCount " + consumerCount + " local " + local);
+//      log.info("waiting for bindings on node " + node +
+//               " address " +
+//               address +
+//               " count " +
+//               count +
+//               " consumerCount " +
+//               consumerCount +
+//               " local " +
+//               local);
       MessagingService service = this.services[node];
 
       if (service == null)
@@ -134,7 +141,7 @@
       do
       {
          Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
-         
+
          int bindingCount = 0;
 
          int totConsumers = 0;
@@ -150,9 +157,9 @@
                totConsumers += qBinding.consumerCount();
             }
          }
-         
-         log.info("binding count " + bindingCount + " consumer Count " + totConsumers);
 
+         //log.info("binding count " + bindingCount + " consumer Count " + totConsumers);
+
          if (bindingCount == count && totConsumers == consumerCount)
          {
             log.info("Waited " + (System.currentTimeMillis() - start));
@@ -204,11 +211,9 @@
 
       session.close();
    }
-   
-   
 
    protected void addConsumer(int consumerID, int node, String queueName, String filterVal) throws Exception
-   {      
+   {
       if (consumers[consumerID] != null)
       {
          throw new IllegalArgumentException("Already a consumer at " + node);
@@ -248,41 +253,55 @@
 
       holder.consumer.close();
       holder.session.close();
-      
+
       consumers[consumerID] = null;
    }
-   
+
    protected void closeAllConsumers() throws Exception
    {
       for (int i = 0; i < consumers.length; i++)
       {
          ConsumerHolder holder = consumers[i];
-         
+
          if (holder != null)
          {
             holder.consumer.close();
             holder.session.close();
-            
+
             consumers[i] = null;
          }
       }
    }
-   
+
    protected void closeAllSessionFactories() throws Exception
    {
       for (int i = 0; i < sfs.length; i++)
       {
          ClientSessionFactory sf = sfs[i];
-         
+
          if (sf != null)
          {
             sf.close();
-            
+
             sfs[i] = null;
          }
       }
    }
 
+   protected void closeSessionFactory(int node)
+   {
+      ClientSessionFactory sf = this.sfs[node];
+
+      if (sf == null)
+      {
+         throw new IllegalArgumentException("No sf at " + node);
+      }
+
+      sf.close();
+
+      sfs[node] = null;
+   }
+
    protected void send(int node, String address, int numMessages, boolean durable, String filterVal) throws Exception
    {
       ClientSessionFactory sf = this.sfs[node];
@@ -399,7 +418,7 @@
       }
 
       ClientSessionFactory sf = new ClientSessionFactoryImpl(serverTotc);
-      
+
       sf.setBlockOnNonPersistentSend(true);
       sf.setBlockOnPersistentSend(true);
 
@@ -450,7 +469,7 @@
       services[node] = service;
    }
 
-   private Map<String, Object> generateParams(int node, boolean netty)
+   protected Map<String, Object> generateParams(int node, boolean netty)
    {
       Map<String, Object> params = new HashMap<String, Object>();
       params.put(SERVER_ID_PROP_NAME, node);
@@ -472,17 +491,17 @@
          {
             throw new IllegalArgumentException("No service at node " + nodes[i]);
          }
-   
+
          services[nodes[i]] = null;
       }
    }
 
    protected void setupClusterConnection(String name,
-                                       int nodeFrom,
-                                       int nodeTo,
-                                       String address,
-                                       boolean forwardWhenNoConsumers,
-                                       boolean netty)
+                                         int nodeFrom,
+                                         int nodeTo,
+                                         String address,
+                                         boolean forwardWhenNoConsumers,
+                                         boolean netty)
    {
       MessagingService serviceFrom = services[nodeFrom];
 
@@ -519,7 +538,7 @@
                                                                         1,
                                                                         -1,
                                                                         null,
-                                                                        10,
+                                                                        1000,
                                                                         1d,
                                                                         -1,
                                                                         -1,
@@ -553,7 +572,9 @@
    {
       for (int i = 0; i < nodes.length; i++)
       {
+         log.info("stopping service " + nodes[i]);
          services[nodes[i]].stop();
+         log.info("stopped service");
       }
    }
 

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/OnewayTwoNodeClusterTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/OnewayTwoNodeClusterTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/OnewayTwoNodeClusterTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -114,7 +114,74 @@
       send(0, "queues.testaddress", 10, false, null);
       verifyNotReceive(0);
    }
+   
+   public void testStopAndStartTarget() throws Exception
+   {
+      setupClusterConnection("cluster1", 0, 1, "queues", false, isNetty());
+      startServers(0, 1);
 
+      setupSessionFactory(0, isNetty());
+      setupSessionFactory(1, isNetty());
+      
+      String myFilter = "bison";
+
+      createQueue(1, "queues.testaddress", "queue0", myFilter, false);
+      addConsumer(0, 1, "queue0", null);
+          
+      waitForBindings(0, "queues.testaddress", 1, 1, false);
+
+      send(0, "queues.testaddress", 10, false, myFilter);
+      verifyReceiveAll(10, 0);
+      verifyNotReceive(0);
+      
+      send(0, "queues.testaddress", 10, false, null);
+      verifyNotReceive(0);
+      
+      removeConsumer(0);
+      closeSessionFactory(1);
+      
+      long start = System.currentTimeMillis();
+      
+      stopServers(1);
+      
+      log.info("*** stopped service 1");
+      
+      log.info("** starting server 1");
+      
+      startServers(1);
+      
+      log.info("*** started service 1");
+      
+      long end = System.currentTimeMillis();
+      
+      //We time how long it takes to restart, since it has been known to hang in the past and wait for a timeout
+      //Shutting down and restarting should be pretty quick
+      
+      assertTrue("Took too long to restart", end - start <= 5000);
+      
+      setupSessionFactory(1, isNetty());
+      
+      waitForBindings(0, "queues.testaddress", 0, 0, false);
+      
+      createQueue(1, "queues.testaddress", "queue0", myFilter, false);
+      
+      log.info("** adding consumer");
+      
+      addConsumer(0, 1, "queue0", null);
+      
+      log.info("** added consumer");
+          
+      waitForBindings(1, "queues.testaddress", 1, 1, true);
+      waitForBindings(0, "queues.testaddress", 1, 1, false);
+
+      send(0, "queues.testaddress", 10, false, myFilter);
+      verifyReceiveAll(10, 0);
+      verifyNotReceive(0);
+      
+      send(0, "queues.testaddress", 10, false, null);
+      verifyNotReceive(0);
+   }
+
    public void testBasicLocalReceive() throws Exception
    {
       setupClusterConnection("cluster1", 0, 1, "queues", false, isNetty());

Added: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SymmetricClusterTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SymmetricClusterTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/distribution/SymmetricClusterTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -0,0 +1,227 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.messaging.tests.integration.cluster.distribution;
+
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_AUTO_GROUP;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_ACKNOWLEDGE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_NON_PERSISTENT_SEND;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_BLOCK_ON_PERSISTENT_SEND;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CALL_TIMEOUT;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONNECTION_TTL;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONSUMER_MAX_RATE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_CONSUMER_WINDOW_SIZE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MAX_CONNECTIONS;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MAX_RETRIES_AFTER_FAILOVER;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MAX_RETRIES_BEFORE_FAILOVER;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_PRE_ACKNOWLEDGE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_PRODUCER_MAX_RATE;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_RETRY_INTERVAL_MULTIPLIER;
+import static org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl.DEFAULT_SEND_WINDOW_SIZE;
+
+import java.util.Map;
+
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.MessagingService;
+
+/**
+ * A SymmetricClusterTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * Created 3 Feb 2009 09:10:43
+ *
+ *
+ */
+public class SymmetricClusterTest extends ClusterTestBase
+{
+   private static final Logger log = Logger.getLogger(SymmetricClusterTest.class);
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      setupServer(0, isFileStorage(), isNetty());
+      setupServer(1, isFileStorage(), isNetty());            
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      closeAllConsumers();
+      
+      closeAllSessionFactories();
+      
+      stopServers(0, 1);
+      
+      super.tearDown();
+   }
+   
+   protected boolean isNetty()
+   {
+      return false;
+   }
+   
+   protected boolean isFileStorage()
+   {
+      return false;
+   }
+   
+   public void testStartOneBeforeOther() throws Exception
+   {
+      setupClusterConnection("cluster1", 0, 1, "queues", false, isNetty());
+      setupClusterConnection("cluster2", 1, 0, "queues", false, isNetty());
+      
+      startServers(0);
+      
+      setupSessionFactory(0, isNetty());
+     
+      createQueue(0, "queues.testaddress", "queue0", null, false);
+     
+      addConsumer(0, 0, "queue0", null);
+      
+      waitForBindings(0, "queues.testaddress", 1, 1, true);
+            
+      setupSessionFactory(1, isNetty());
+      
+      startServers(1);
+      
+      createQueue(1, "queues.testaddress", "queue0", null, false);
+
+      addConsumer(1, 1, "queue0", null);
+            
+      waitForBindings(0, "queues.testaddress", 1, 1, false);
+      
+      waitForBindings(1, "queues.testaddress", 1, 1, true);
+      waitForBindings(1, "queues.testaddress", 1, 1, false);
+      
+      send(0, "queues.testaddress", 10, false, null);
+      
+      verifyReceiveRoundRobin(10, 0, 1);
+      verifyNotReceive(0, 1);      
+   }
+   
+   public void testStopAndStart() throws Exception
+   {
+      setupClusterConnection("cluster1", 0, 1, "queues", false, isNetty());
+      setupClusterConnection("cluster2", 1, 0, "queues", false, isNetty());
+      
+      startServers(0, 1);
+      
+      setupSessionFactory(0, isNetty());
+      setupSessionFactory(1, isNetty());
+
+      createQueue(0, "queues.testaddress", "queue0", null, false);
+
+      createQueue(1, "queues.testaddress", "queue0", null, false);
+
+      addConsumer(0, 0, "queue0", null);
+
+      addConsumer(1, 1, "queue0", null);
+      
+      waitForBindings(0, "queues.testaddress", 1, 1, true);
+      waitForBindings(0, "queues.testaddress", 1, 1, false);
+      
+      waitForBindings(1, "queues.testaddress", 1, 1, true);
+      waitForBindings(1, "queues.testaddress", 1, 1, false);
+      
+      send(0, "queues.testaddress", 10, false, null);
+      
+      verifyReceiveRoundRobin(10, 0, 1);
+      verifyNotReceive(0, 1);      
+      
+      removeConsumer(0);
+      closeSessionFactory(0);
+                  
+      long start = System.currentTimeMillis();
+      
+      stopServers(0);
+                 
+      startServers(0);
+        
+      long end = System.currentTimeMillis();
+      
+      //We time how long it takes to restart, since it has been known to hang in the past and wait for a timeout
+      //Shutting down and restarting should be pretty quick
+      
+      assertTrue("Took too long to restart", end - start <= 5000);
+      
+      setupSessionFactory(0, isNetty());
+      
+      waitForBindings(0, "queues.testaddress", 1, 1, false);
+      
+      createQueue(0, "queues.testaddress", "queue0", null, false);
+                  
+      addConsumer(0, 0, "queue0", null);
+      
+      send(0, "queues.testaddress", 10, false, null);
+      
+      verifyReceiveRoundRobin(10, 1, 0);
+      verifyNotReceive(0, 1);      
+   }
+   
+   
+   
+   public void testBasicRoundRobin() throws Exception
+   {
+      setupClusterConnection("cluster1", 0, 1, "queues", false, isNetty());
+      setupClusterConnection("cluster2", 1, 0, "queues", false, isNetty());
+      
+      startServers(0, 1);
+      
+      setupSessionFactory(0, isNetty());
+      setupSessionFactory(1, isNetty());
+
+      createQueue(0, "queues.testaddress", "queue0", null, false);
+
+      createQueue(1, "queues.testaddress", "queue0", null, false);
+
+      addConsumer(0, 0, "queue0", null);
+
+      addConsumer(1, 1, "queue0", null);
+      
+      waitForBindings(0, "queues.testaddress", 1, 1, true);
+      waitForBindings(0, "queues.testaddress", 1, 1, false);
+      
+      waitForBindings(1, "queues.testaddress", 1, 1, true);
+      waitForBindings(1, "queues.testaddress", 1, 1, false);
+      
+      send(0, "queues.testaddress", 10, false, null);
+      
+      verifyReceiveRoundRobin(10, 0, 1);
+      verifyNotReceive(0, 1);      
+   }
+   
+}

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ActivationTimeoutTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ActivationTimeoutTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ActivationTimeoutTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -294,12 +294,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/AutomaticFailoverWithDiscoveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/AutomaticFailoverWithDiscoveryTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/AutomaticFailoverWithDiscoveryTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -224,12 +224,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailBackupServerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailBackupServerTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailBackupServerTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -209,12 +209,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverExpiredMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverExpiredMessageTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverExpiredMessageTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -219,12 +219,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverManagementTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverManagementTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverManagementTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -295,12 +295,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverNoSessionsFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverNoSessionsFailoverTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverNoSessionsFailoverTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -211,12 +211,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverPreAcknowledgeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverPreAcknowledgeTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverPreAcknowledgeTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -194,12 +194,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverScheduledMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverScheduledMessageTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverScheduledMessageTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -213,12 +213,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverTestBase.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailoverTestBase.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -157,8 +157,6 @@
    {
       if (backupService != null && backupService.isStarted())
       {
-         assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-   
          backupService.stop();
          
          backupService = null;
@@ -166,8 +164,6 @@
       
       if (liveService != null && liveService.isStarted())
       {
-         assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-   
          liveService.stop();
          
          liveService = null;

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailureListenerOnFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailureListenerOnFailoverTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailureListenerOnFailoverTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -360,12 +360,8 @@
    {
       InVMConnector.resetFailures();
       
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailureOnCreateConnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailureOnCreateConnectionTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/FailureOnCreateConnectionTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -104,8 +104,6 @@
    {
       InVMConnector.resetFailures();
       
-      assertEquals(0, service.getServer().getRemotingService().getConnections().size());
-
       service.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTestBase.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/MultiThreadRandomFailoverTestBase.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -1390,12 +1390,8 @@
 
    private void stop() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/RandomFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/RandomFailoverTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/RandomFailoverTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -1502,12 +1502,8 @@
 
    private void stop() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReconnectTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReconnectTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReconnectTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -630,8 +630,6 @@
    {
       InVMConnector.resetFailures();
       
-      assertEquals(0, service.getServer().getRemotingService().getConnections().size());
-
       service.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReconnectWithBackupTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReconnectWithBackupTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReconnectWithBackupTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -306,12 +306,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReplicateConnectionFailureTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReplicateConnectionFailureTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/ReplicateConnectionFailureTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -91,7 +91,7 @@
    // Constructors --------------------------------------------------
 
    // Public --------------------------------------------------------
-
+   
    public void testFailConnection() throws Exception
    {
       final long pingPeriod = 500;
@@ -139,16 +139,8 @@
 
       log.info("recreating");
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       session1 = sf1.createSession(false, true, true);
 
-      assertEquals(1, liveService.getServer().getRemotingService().getConnections().size());
-
-      assertEquals(1, backupService.getServer().getRemotingService().getConnections().size());
-
       final RemotingConnectionImpl conn1 = (RemotingConnectionImpl)((ClientSessionImpl)session1).getConnection();
 
       conn1.stopPingingAfterOne();

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleAutomaticFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleAutomaticFailoverTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleAutomaticFailoverTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -734,12 +734,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleManualFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleManualFailoverTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/failover/SimpleManualFailoverTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -198,12 +198,8 @@
 
    protected void tearDown() throws Exception
    {
-      assertEquals(0, server1Service.getServer().getRemotingService().getConnections().size());
-
       server1Service.stop();
 
-      assertEquals(0, server0Service.getServer().getRemotingService().getConnections().size());
-
       server0Service.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/cluster/management/ReplicationAwareTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/cluster/management/ReplicationAwareTestBase.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/cluster/management/ReplicationAwareTestBase.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -126,12 +126,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/jms/cluster/JMSFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/jms/cluster/JMSFailoverTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/jms/cluster/JMSFailoverTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -349,12 +349,8 @@
    @Override
    protected void tearDown() throws Exception
    {
-      assertEquals(0, backupService.getServer().getRemotingService().getConnections().size());
-
       backupService.stop();
 
-      assertEquals(0, liveService.getServer().getRemotingService().getConnections().size());
-
       liveService.stop();
 
       assertEquals(0, InVMRegistry.instance.size());

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/paging/PageCrashTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/paging/PageCrashTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/paging/PageCrashTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -47,9 +47,9 @@
 import org.jboss.messaging.core.paging.impl.PagingStoreImpl;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.persistence.impl.journal.JournalStorageManager;
-import org.jboss.messaging.core.remoting.RemotingService;
 import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
-import org.jboss.messaging.core.remoting.impl.RemotingServiceImpl;
+import org.jboss.messaging.core.remoting.server.RemotingService;
+import org.jboss.messaging.core.remoting.server.impl.RemotingServiceImpl;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.core.security.JBMSecurityManager;
 import org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl;

Modified: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakeBinding.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -36,6 +36,12 @@
 public class FakeBinding implements Binding
 {
    
+   public SimpleString getOriginatingNodeID()
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
    public Filter getFilter()
    {
       // TODO Auto-generated method stub

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -46,7 +46,7 @@
 import org.jboss.messaging.core.management.impl.MessagingServerControl;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.PostOffice;
-import org.jboss.messaging.core.remoting.RemotingService;
+import org.jboss.messaging.core.remoting.server.RemotingService;
 import org.jboss.messaging.core.security.Role;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.core.server.QueueFactory;

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -50,7 +50,7 @@
 import org.jboss.messaging.core.messagecounter.MessageCounterManager;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.PostOffice;
-import org.jboss.messaging.core.remoting.RemotingService;
+import org.jboss.messaging.core.remoting.server.RemotingService;
 import org.jboss.messaging.core.security.Role;
 import org.jboss.messaging.core.server.JournalType;
 import org.jboss.messaging.core.server.MessagingServer;

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -24,6 +24,9 @@
 import java.util.UUID;
 
 import org.easymock.EasyMock;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.remoting.spi.Connection;
+import org.jboss.messaging.core.remoting.spi.ConnectionLifeCycleListener;
 import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
 import org.jboss.messaging.integration.transports.netty.NettyConnection;
 import org.jboss.messaging.tests.util.UnitTestCase;
@@ -38,6 +41,29 @@
  */
 public class NettyConnectionTest extends UnitTestCase
 {
+   class MyListener implements ConnectionLifeCycleListener
+   {
+
+      public void connectionCreated(Connection connection)
+      {
+         // TODO Auto-generated method stub
+         
+      }
+
+      public void connectionDestroyed(Object connectionID)
+      {
+         // TODO Auto-generated method stub
+         
+      }
+
+      public void connectionException(Object connectionID, MessagingException me)
+      {
+         // TODO Auto-generated method stub
+         
+      }
+      
+   }
+   
    public void testGetID() throws Exception
    {
       Channel channel = EasyMock.createStrictMock(Channel.class);
@@ -46,7 +72,7 @@
 
       EasyMock.expect(channel.getId()).andReturn(id);
 
-      NettyConnection conn = new NettyConnection(channel);
+      NettyConnection conn = new NettyConnection(channel, new MyListener());
 
       EasyMock.replay(channel);
 
@@ -67,7 +93,7 @@
 
       EasyMock.expect(channel.write(underlying)).andReturn(null);
 
-      NettyConnection conn = new NettyConnection(channel);
+      NettyConnection conn = new NettyConnection(channel, new MyListener());
 
       EasyMock.replay(channel, buff);
 
@@ -80,7 +106,7 @@
    {
       Channel channel = EasyMock.createStrictMock(Channel.class);
 
-      NettyConnection conn = new NettyConnection(channel);
+      NettyConnection conn = new NettyConnection(channel, new MyListener());
 
       EasyMock.replay(channel);
 

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServiceImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServiceImplTest.java	2009-02-05 16:40:18 UTC (rev 5820)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/MessagingServiceImplTest.java	2009-02-05 17:39:25 UTC (rev 5821)
@@ -26,7 +26,7 @@
 import org.jboss.messaging.core.config.impl.ConfigurationImpl;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.persistence.impl.nullpm.NullStorageManager;
-import org.jboss.messaging.core.remoting.RemotingService;
+import org.jboss.messaging.core.remoting.server.RemotingService;
 import org.jboss.messaging.core.server.Messaging;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.core.server.MessagingService;




More information about the jboss-cvs-commits mailing list