[jboss-cvs] JBoss Messaging SVN: r3571 - in trunk: docs/examples/common/src/org/jboss/example/jms/common and 18 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 15 22:05:48 EST 2008


Author: clebert.suconic at jboss.com
Date: 2008-01-15 22:05:48 -0500 (Tue, 15 Jan 2008)
New Revision: 3571

Added:
   trunk/src/main/org/jboss/jms/client/api/
   trunk/src/main/org/jboss/jms/client/api/ClientBrowser.java
   trunk/src/main/org/jboss/jms/client/api/ClientConnection.java
   trunk/src/main/org/jboss/jms/client/api/ClientProducer.java
   trunk/src/main/org/jboss/jms/client/api/ClientSession.java
   trunk/src/main/org/jboss/jms/client/api/Consumer.java
   trunk/src/main/org/jboss/jms/client/delegate/CommunicationSupport.java
Removed:
   trunk/src/main/org/jboss/jms/client/container/FailoverValveInterceptor.java
   trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java
   trunk/src/main/org/jboss/jms/client/state/
Modified:
   trunk/.classpath
   trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java
   trunk/src/main/org/jboss/jms/client/FailoverCommandCenter.java
   trunk/src/main/org/jboss/jms/client/FailoverValve.java
   trunk/src/main/org/jboss/jms/client/JBossConnection.java
   trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java
   trunk/src/main/org/jboss/jms/client/JBossMessageConsumer.java
   trunk/src/main/org/jboss/jms/client/JBossMessageProducer.java
   trunk/src/main/org/jboss/jms/client/JBossQueueBrowser.java
   trunk/src/main/org/jboss/jms/client/JBossSession.java
   trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java
   trunk/src/main/org/jboss/jms/client/remoting/ConsolidatedRemotingConnectionListener.java
   trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
   trunk/src/main/org/jboss/jms/delegate/ConnectionEndpoint.java
   trunk/src/main/org/jboss/jms/delegate/CreateConnectionResult.java
   trunk/src/main/org/jboss/jms/delegate/DeliveryInfo.java
   trunk/src/main/org/jboss/jms/delegate/SessionEndpoint.java
   trunk/src/main/org/jboss/jms/destination/JBossTemporaryQueue.java
   trunk/src/main/org/jboss/jms/destination/JBossTemporaryTopic.java
   trunk/src/main/org/jboss/jms/message/JBossMessage.java
   trunk/src/main/org/jboss/jms/server/bridge/Bridge.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
   trunk/src/main/org/jboss/jms/tx/MessagingXAResource.java
   trunk/src/main/org/jboss/jms/tx/ResourceManager.java
   trunk/src/main/org/jboss/messaging/util/ProxyFactory.java
   trunk/tests/src/org/jboss/test/messaging/JBMBaseTestCase.java
   trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/CTSMiscellaneousTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/MessageWithReadResolveTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/XATest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterLeakTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterViewUpdateTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusteringTestBase.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/DisableLoadBalancingAndFailoverTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/LoadBalancingTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/XAFailoverTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/server/connectionmanager/SimpleConnectionManagerTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/stress/StressTestBase.java
   trunk/tests/src/org/jboss/test/messaging/jms/stress/clustering/FailoverOverDistributionStressTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/stress/clustering/FailoverStressTest.java
Log:
JBMESSAGING-681 - Merging State into Delegates...
                  Implementing Client interfaces (in replacement of Endpoint interfaces)
                  

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/.classpath	2008-01-16 03:05:48 UTC (rev 3571)
@@ -75,5 +75,6 @@
 	<classpathentry kind="lib" path="tests/etc"/>
 	<classpathentry kind="lib" path="src/etc/server/default/config"/>
 	<classpathentry kind="lib" path="src/etc/server/default/deploy"/>
+	<classpathentry kind="lib" path="tests/lib/jdbc-drivers/mysql-connector-java-5.1.5-bin.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java
===================================================================
--- trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -8,16 +8,12 @@
 
 import javax.jms.Connection;
 import javax.jms.ConnectionMetaData;
-import javax.jms.ConnectionFactory;
 import javax.naming.InitialContext;
 
 import org.jboss.example.jms.common.bean.Management;
 import org.jboss.example.jms.common.bean.ManagementHome;
 import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.jms.client.delegate.DelegateSupport;
-import org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate;
-import org.jboss.jms.client.state.ConnectionState;
+import org.jboss.jms.client.api.ClientConnection;
 
 /**
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -43,11 +39,9 @@
       
       JBossConnection jbconn = (JBossConnection)conn;
       
-      DelegateSupport del = (DelegateSupport)jbconn.getDelegate();
+      ClientConnection del = jbconn.getDelegate();
       
-      ConnectionState state = (ConnectionState)del.getState();
-      
-      return state.getServerID();
+      return del.getServerID();
    }
    
    public static void assertEquals(Object o, Object o2)

Modified: trunk/src/main/org/jboss/jms/client/FailoverCommandCenter.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/FailoverCommandCenter.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/FailoverCommandCenter.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -6,9 +6,9 @@
  */
 package org.jboss.jms.client;
 
+import org.jboss.jms.client.api.ClientConnection;
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
 import org.jboss.jms.client.remoting.JMSRemotingConnection;
-import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.jms.delegate.ConnectionFactoryDelegate;
 import org.jboss.jms.delegate.CreateConnectionResult;
 import org.jboss.logging.Logger;
@@ -37,7 +37,7 @@
 
    // Attributes-----------------------------------------------------------------------------------
 
-   private ConnectionState state;
+   private ClientConnection connection;
 
    private FailoverValve2 valve;
 
@@ -45,9 +45,9 @@
    
    // Constructors ---------------------------------------------------------------------------------
 
-   public FailoverCommandCenter(ConnectionState state)
+   public FailoverCommandCenter(ClientConnection conn)
    {
-      this.state = state;
+      this.connection = conn;;
       failoverListeners = new ArrayList();
       
       valve = new FailoverValve2();
@@ -55,9 +55,9 @@
 
    // Public ---------------------------------------------------------------------------------------
    
-   public void setState(ConnectionState state)
+   public void setState(ClientConnection conn)
    {
-      this.state = state;
+      this.connection = conn;
    }
    
    /**
@@ -71,7 +71,8 @@
                                   JMSRemotingConnection remotingConnection)
       throws Exception
    {
-      log.debug("failure detected by " + source, reason);
+      return true;
+      /*log.debug("failure detected by " + source, reason);
 
       // generate a FAILURE_DETECTED event
       broadcastFailoverEvent(new FailoverEvent(FailoverEvent.FAILURE_DETECTED, source));
@@ -120,7 +121,7 @@
          // to insure the client-side stack is in a deterministic state
          broadcastFailoverEvent(new FailoverEvent(FailoverEvent.FAILOVER_STARTED, this));        
          
-         int failedNodeID = state.getServerID();
+         //int failedNodeID = connection.getServerID();
                   
          ConnectionFactoryDelegate clusteredDelegate = state.getClusteredConnectionFactoryDelegate();
                            
@@ -204,7 +205,7 @@
             
             broadcastFailoverEvent(new FailoverEvent(FailoverEvent.FAILOVER_FAILED, this));
          }
-      }
+      } */
    }
 
    public void registerFailoverListener(FailoverListener listener)
@@ -230,19 +231,19 @@
 
    public JMSRemotingConnection getRemotingConnection()
    {
-      return state.getRemotingConnection();
+      return connection.getRemotingConnection();
    }
 
    public String toString()
    {
-      return "FailoverCommandCenter[" + state + "]";
+      return "FailoverCommandCenter[" + connection + "]";
    }
 
    // Package protected ----------------------------------------------------------------------------
 
-   ConnectionState getConnectionState()
+   ClientConnection getConnection()
    {
-      return state;
+      return connection;
    }
 
    // Protected ------------------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/FailoverValve.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/FailoverValve.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/FailoverValve.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -238,7 +238,7 @@
       return "FailoverValve[" +
          (fcc == null ?
             "UNINITIALIZED" :
-            "connectionID=" + fcc.getConnectionState().getDelegate().getID()) +
+            "connectionID=" + fcc.getConnection()) +
          "]";
    }
 

Modified: trunk/src/main/org/jboss/jms/client/JBossConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnection.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/JBossConnection.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -43,11 +43,7 @@
 import javax.jms.XATopicConnection;
 import javax.jms.XATopicSession;
 
-import org.jboss.jms.client.delegate.ClientConnectionDelegate;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.delegate.ConnectionDelegate;
-import org.jboss.jms.delegate.SessionDelegate;
-import org.jboss.messaging.util.ProxyFactory;
+import org.jboss.jms.client.api.ClientConnection;
 
 /**
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -72,14 +68,14 @@
 
    // Attributes -----------------------------------------------------------------------------------
 
-   protected ConnectionDelegate delegate;
+   protected ClientConnection connection;
    private int connectionType;
 
    // Constructors ---------------------------------------------------------------------------------
 
-   public JBossConnection(ConnectionDelegate delegate, int connectionType)
+   public JBossConnection(ClientConnection delegate, int connectionType)
    {
-      this.delegate = delegate;
+      this.connection = delegate;
       this.connectionType = connectionType;
    }
 
@@ -92,43 +88,43 @@
 
    public String getClientID() throws JMSException
    {
-      return delegate.getClientID();
+      return connection.getClientID();
    }
 
    public void setClientID(String clientID) throws JMSException
    {
-      delegate.setClientID(clientID);
+      connection.setClientID(clientID);
    }
 
    public ConnectionMetaData getMetaData() throws JMSException
    {
-      return delegate.getConnectionMetaData();
+      return connection.getConnectionMetaData();
    }
 
    public ExceptionListener getExceptionListener() throws JMSException
    {
-      return delegate.getExceptionListener();
+      return connection.getExceptionListener();
    }
 
    public void setExceptionListener(ExceptionListener listener) throws JMSException
    {
-      delegate.setExceptionListener(listener);
+      connection.setExceptionListener(listener);
    }
 
    public void start() throws JMSException
    {
-      delegate.start();
+      connection.start();
    }
 
    public void stop() throws JMSException
    {
-      delegate.stop();
+      connection.stop();
    }
 
    public void close() throws JMSException
    {
-      delegate.closing(-1);
-      delegate.close();
+      connection.closing(-1);
+      connection.close();
    }
 
    public ConnectionConsumer createConnectionConsumer(Destination destination,
@@ -136,7 +132,7 @@
                                                       ServerSessionPool sessionPool,
                                                       int maxMessages) throws JMSException
    {
-      return delegate.
+      return connection.
          createConnectionConsumer(destination, null, messageSelector, sessionPool, maxMessages);
    }
 
@@ -152,7 +148,7 @@
          String msg = "Cannot create a durable connection consumer on a QueueConnection";
          throw new javax.jms.IllegalStateException(msg);
       }
-      return delegate.createConnectionConsumer(topic, subscriptionName, messageSelector,
+      return connection.createConnectionConsumer(topic, subscriptionName, messageSelector,
                                                sessionPool, maxMessages);
    }
 
@@ -169,7 +165,7 @@
                                                       ServerSessionPool sessionPool,
                                                       int maxMessages) throws JMSException
     {
-      return delegate.
+      return connection.
          createConnectionConsumer(queue, null, messageSelector, sessionPool, maxMessages);
     }
 
@@ -186,7 +182,7 @@
                                                       ServerSessionPool sessionPool,
                                                       int maxMessages) throws JMSException
    {
-      return delegate.
+      return connection.
          createConnectionConsumer(topic, null, messageSelector, sessionPool, maxMessages);
    }
 
@@ -220,14 +216,12 @@
 
    public String getRemotingClientSessionID()
    {
-      ConnectionState state = (ConnectionState)((ClientConnectionDelegate)delegate).getState();
-      
-      return state.getRemotingConnection().getRemotingClient().getSessionID();
+      return connection.getRemotingConnection().getRemotingClient().getSessionID();
    }
 
-   public ConnectionDelegate getDelegate()
+   public org.jboss.jms.client.api.ClientConnection getDelegate()
    {
-      return delegate;
+      return connection;
    }
 
    /**
@@ -235,22 +229,23 @@
     */
    public int getServerID()
    {
-      return ((ConnectionState)(ProxyFactory.getDelegate(delegate)).getState()).getServerID();
+      
+      return connection.getServerID(); 
    }
 
-   public void registerFailoverListener(FailoverListener listener)
+   /*public void registerFailoverListener(FailoverListener listener)
    {
-      delegate.registerFailoverListener(listener);
+      connection.registerFailoverListener(listener);
    }
 
    public synchronized boolean unregisterFailoverListener(FailoverListener listener)
    {
       return delegate.unregisterFailoverListener(listener);
-   }
+   } */
 
    public String toString()
    {
-      return "JBossConnection->" + delegate;
+      return "JBossConnection->" + connection;
    }
 
    // Package protected ----------------------------------------------------------------------------
@@ -265,9 +260,9 @@
          acknowledgeMode = Session.SESSION_TRANSACTED;
       }
 
-      SessionDelegate sessionDelegate =
-         delegate.createSessionDelegate(transacted, acknowledgeMode, isXA);
-      return new JBossSession(sessionDelegate, type);
+      org.jboss.jms.client.api.ClientSession session =
+         connection.createSessionDelegate(transacted, acknowledgeMode, isXA);
+      return new JBossSession(session, type);
    }
 
    // Private --------------------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -32,15 +32,10 @@
 import javax.jms.Session;
 
 import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
-import org.jboss.jms.client.state.ConsumerState;
-import org.jboss.jms.delegate.ConnectionDelegate;
-import org.jboss.jms.delegate.ConsumerDelegate;
-import org.jboss.jms.delegate.SessionDelegate;
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.message.JBossMessage;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.util.MessageQueueNameHelper;
-import org.jboss.messaging.util.ProxyFactory;
 
 /**
  * This class implements javax.jms.ConnectionConsumer
@@ -69,9 +64,9 @@
    
    // Attributes ----------------------------------------------------
    
-   private ConsumerDelegate cons;
+   private org.jboss.jms.client.api.Consumer cons;
    
-   private SessionDelegate sess;
+   private org.jboss.jms.client.api.ClientSession sess;
    
    private String consumerID;
    
@@ -104,7 +99,7 @@
    
    // Constructors --------------------------------------------------
 
-   public JBossConnectionConsumer(ConnectionDelegate conn, JBossDestination dest,
+   public JBossConnectionConsumer(org.jboss.jms.client.api.ClientConnection conn, JBossDestination dest,
                                   String subName, String messageSelector,
                                   ServerSessionPool sessPool, int maxMessages) throws JMSException
    {
@@ -122,13 +117,11 @@
           
       cons = sess.createConsumerDelegate(dest.toCoreDestination(), messageSelector, false, subName, true);
 
-      ConsumerState state = (ConsumerState)(ProxyFactory.getDelegate(cons)).getState();
-
-      this.consumerID = state.getConsumerID();      
+      this.consumerID = cons.getConsumerID();      
         
-      this.maxDeliveries = state.getMaxDeliveries();
+      this.maxDeliveries = cons.getMaxDeliveries();
       
-      shouldAck = state.isShouldAck();      
+      shouldAck = cons.isShouldAck();      
             
       if (subName != null)
       {

Modified: trunk/src/main/org/jboss/jms/client/JBossMessageConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossMessageConsumer.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/JBossMessageConsumer.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -32,7 +32,9 @@
 import javax.jms.Topic;
 import javax.jms.TopicSubscriber;
 
-import org.jboss.jms.delegate.ConsumerDelegate;
+import org.jboss.jms.client.api.Consumer;
+
+
 import org.jboss.jms.destination.JBossDestination;
 
 /**
@@ -51,51 +53,51 @@
 
    // Attributes ----------------------------------------------------
 
-   protected ConsumerDelegate delegate;
+   protected Consumer consumer;
 
    // Constructors --------------------------------------------------
 
-   public JBossMessageConsumer(ConsumerDelegate delegate)
+   public JBossMessageConsumer(Consumer consumer)
    {      
-      this.delegate = delegate;
+      this.consumer = consumer;
    }
 
    // MessageConsumer implementation --------------------------------
 
    public String getMessageSelector() throws JMSException
    {
-      return delegate.getMessageSelector();
+      return consumer.getMessageSelector();
    }
 
    public MessageListener getMessageListener() throws JMSException
    {
-      return delegate.getMessageListener();
+      return consumer.getMessageListener();
    }
 
    public void setMessageListener(MessageListener listener) throws JMSException
    {
-      delegate.setMessageListener(listener);
+      consumer.setMessageListener(listener);
    }
 
    public Message receive() throws JMSException
    {
-      return delegate.receive(0);
+      return consumer.receive(0);
    }
 
    public Message receive(long timeout) throws JMSException
    {
-      return delegate.receive(timeout);
+      return consumer.receive(timeout);
    }
 
    public Message receiveNoWait() throws JMSException
    {
-      return delegate.receive(-1);
+      return consumer.receive(-1);
    }
 
    public void close() throws JMSException
    {
-      delegate.closing(-1);
-      delegate.close();
+      consumer.closing(-1);
+      consumer.close();
    }
 
    // QueueReceiver implementation ----------------------------------
@@ -103,32 +105,32 @@
 
    public Queue getQueue() throws JMSException
    {
-      return (Queue)JBossDestination.fromCoreDestination(delegate.getDestination());
+      return (Queue)JBossDestination.fromCoreDestination(consumer.getDestination());
    }
 
    // TopicSubscriber implementation --------------------------------
 
    public Topic getTopic() throws JMSException
    {
-      return (Topic)JBossDestination.fromCoreDestination(delegate.getDestination());
+      return (Topic)JBossDestination.fromCoreDestination(consumer.getDestination());
    }
 
 
    public boolean getNoLocal() throws JMSException
    {
-      return delegate.getNoLocal();
+      return consumer.getNoLocal();
    }
 
-   public ConsumerDelegate getDelegate()
+   public Consumer getDelegate()
    {
-       return delegate;
+       return consumer;
    }
 
    // Public --------------------------------------------------------
 
    public String toString()
    {
-      return "JBossMessageConsumer->" + delegate;
+      return "JBossMessageConsumer->" + consumer;
    }
 
    // Package protected ---------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/JBossMessageProducer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossMessageProducer.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/JBossMessageProducer.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -33,7 +33,6 @@
 import javax.jms.Topic;
 import javax.jms.TopicPublisher;
 
-import org.jboss.jms.delegate.ProducerDelegate;
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.logging.Logger;
 
@@ -56,13 +55,13 @@
    
    // Attributes ----------------------------------------------------
    
-   protected ProducerDelegate delegate;
+   protected org.jboss.jms.client.api.ClientProducer producer;
 
    // Constructors --------------------------------------------------
    
-   public JBossMessageProducer(ProducerDelegate delegate)
+   public JBossMessageProducer(org.jboss.jms.client.api.ClientProducer producer)
    {
-      this.delegate = delegate;     
+      this.producer = producer;     
    }
    
    // MessageProducer implementation --------------------------------
@@ -71,63 +70,63 @@
    {
       log.warn("JBoss Messaging does not support disabling message ID generation");
 
-      delegate.setDisableMessageID(value);
+      producer.setDisableMessageID(value);
    }
    
    public boolean getDisableMessageID() throws JMSException
    {
-      return delegate.getDisableMessageID();
+      return producer.isDisableMessageID();
    }
    
    public void setDisableMessageTimestamp(boolean value) throws JMSException
    {
-      delegate.setDisableMessageTimestamp(value);
+      producer.setDisableMessageTimestamp(value);
    }
    
    public boolean getDisableMessageTimestamp() throws JMSException
    {
-      return delegate.getDisableMessageTimestamp();
+      return producer.isDisableMessageTimestamp();
    }
    
    public void setDeliveryMode(int deliveryMode) throws JMSException
    {
-      delegate.setDeliveryMode(deliveryMode);
+      producer.setDeliveryMode(deliveryMode);
    }
    
    public int getDeliveryMode() throws JMSException
    {
-      return delegate.getDeliveryMode();
+      return producer.getDeliveryMode();
    }
    
    public void setPriority(int defaultPriority) throws JMSException
    {
-      delegate.setPriority(defaultPriority);
+      producer.setPriority(defaultPriority);
    }
    
    public int getPriority() throws JMSException
    {
-      return delegate.getPriority();
+      return producer.getPriority();
    }
    
    public void setTimeToLive(long timeToLive) throws JMSException
    {
-      delegate.setTimeToLive(timeToLive);
+      producer.setTimeToLive(timeToLive);
    }
    
    public long getTimeToLive() throws JMSException
    {
-      return delegate.getTimeToLive();
+      return producer.getTimeToLive();
    }
    
    public Destination getDestination() throws JMSException
    {
-      return delegate.getDestination();
+      return producer.getDestination();
    }
    
    public void close() throws JMSException
    {
-      delegate.closing(-1);
-      delegate.close();
+      producer.closing(-1);
+      producer.close();
    }
    
    public void send(Message message) throws JMSException
@@ -161,7 +160,7 @@
          throw new InvalidDestinationException("Not a JBossDestination:" + destination);
       }
 
-      delegate.send((JBossDestination)destination, m, deliveryMode, priority, timeToLive);
+      producer.send((JBossDestination)destination, m, deliveryMode, priority, timeToLive);
    }
 
 
@@ -214,14 +213,14 @@
    
    // Public --------------------------------------------------------
 
-   public ProducerDelegate getDelegate()
+   public org.jboss.jms.client.api.ClientProducer getDelegate()
    {
-      return delegate;
+      return producer;
    }
 
    public String toString()
    {
-      return "JBossMessageProducer->" + delegate;
+      return "JBossMessageProducer->" + producer;
    }
 
    // Package protected ---------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/JBossQueueBrowser.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossQueueBrowser.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/JBossQueueBrowser.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -28,7 +28,7 @@
 import javax.jms.Queue;
 import javax.jms.QueueBrowser;
 
-import org.jboss.jms.delegate.BrowserDelegate;
+import org.jboss.jms.client.api.ClientBrowser;
 import org.jboss.jms.message.JBossMessage;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.Message;
@@ -51,13 +51,13 @@
 
    // Attributes -----------------------------------------------------------------------------------
 
-   private BrowserDelegate delegate;
+   private ClientBrowser delegate;
    private Queue queue;
    private String messageSelector;
 
    // Constructors ---------------------------------------------------------------------------------
 
-   JBossQueueBrowser(Queue queue, String messageSelector, BrowserDelegate delegate)
+   JBossQueueBrowser(Queue queue, String messageSelector, ClientBrowser delegate)
    {
       this.delegate = delegate;
       this.queue = queue;
@@ -95,7 +95,7 @@
       return "JBossQueueBrowser->" + delegate;
    }
 
-   public BrowserDelegate getDelegate()
+   public ClientBrowser getDelegate()
    {
       return delegate;
    }

Modified: trunk/src/main/org/jboss/jms/client/JBossSession.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossSession.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/JBossSession.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -52,11 +52,7 @@
 import javax.jms.XATopicSession;
 import javax.transaction.xa.XAResource;
 
-import org.jboss.jms.client.state.SessionState;
-import org.jboss.jms.delegate.BrowserDelegate;
-import org.jboss.jms.delegate.ConsumerDelegate;
-import org.jboss.jms.delegate.ProducerDelegate;
-import org.jboss.jms.delegate.SessionDelegate;
+import org.jboss.jms.client.api.Consumer;
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.destination.JBossQueue;
 import org.jboss.jms.destination.JBossTemporaryQueue;
@@ -94,15 +90,15 @@
    
    // Attributes ----------------------------------------------------
    
-   protected SessionDelegate delegate;
+   protected org.jboss.jms.client.api.ClientSession session;
 
    protected int sessionType;
 
    // Constructors --------------------------------------------------
 
-   public JBossSession(SessionDelegate sessionDelegate, int sessionType)
+   public JBossSession(org.jboss.jms.client.api.ClientSession sessionDelegate, int sessionType)
    {
-      this.delegate = sessionDelegate;
+      this.session = sessionDelegate;
       this.sessionType = sessionType;
    }
 
@@ -110,86 +106,86 @@
                                                                         
    public BytesMessage createBytesMessage() throws JMSException
    {
-   	return delegate.createBytesMessage();
+   	return session.createBytesMessage();
    }
 
    public MapMessage createMapMessage() throws JMSException
    {
-   	return delegate.createMapMessage();
+   	return session.createMapMessage();
    }
 
    public Message createMessage() throws JMSException
    {
-      return delegate.createMessage();
+      return session.createMessage();
    }
 
    public ObjectMessage createObjectMessage() throws JMSException
    {
-   	return delegate.createObjectMessage();
+   	return session.createObjectMessage();
    }
 
    public ObjectMessage createObjectMessage(Serializable object) throws JMSException
    {
-   	return delegate.createObjectMessage(object);
+   	return session.createObjectMessage(object);
    }
 
    public StreamMessage createStreamMessage() throws JMSException
    {
-   	return delegate.createStreamMessage();
+   	return session.createStreamMessage();
    }
 
    public TextMessage createTextMessage() throws JMSException
    {
-   	return delegate.createTextMessage();
+   	return session.createTextMessage();
    }
 
    public TextMessage createTextMessage(String text) throws JMSException
    {
-   	return delegate.createTextMessage(text);
+   	return session.createTextMessage(text);
    }
 
    public boolean getTransacted() throws JMSException
    {
-      return delegate.getTransacted();
+      return session.isTransacted();
    }
 
    public int getAcknowledgeMode() throws JMSException
    {
-      return delegate.getAcknowledgeMode();
+      return session.getAcknowledgeMode();
    }
 
    public void commit() throws JMSException
    {
-      delegate.commit();
+      session.commit();
    }
 
    public void rollback() throws JMSException
    {
-      delegate.rollback();
+      session.rollback();
    }
 
    public void close() throws JMSException
    {
-      delegate.closing(-1);
-      delegate.close();
+      session.closing(-1);
+      session.close();
    }
 
    public void recover() throws JMSException
    {
-      delegate.recover();
+      session.recover();
    }
 
    public MessageListener getMessageListener() throws JMSException
    {
       if (log.isTraceEnabled()) { log.trace("getMessageListener() called"); }
-      return delegate.getMessageListener();
+      return session.getMessageListener();
    }
 
    public void setMessageListener(MessageListener listener) throws JMSException
    {
       if (log.isTraceEnabled()) { log.trace("setMessageListener(" + listener + ") called"); }
 
-      delegate.setMessageListener(listener);
+      session.setMessageListener(listener);
    }
 
    public void run()
@@ -197,7 +193,7 @@
       try
       {
          if (log.isTraceEnabled()) { log.trace("run() called"); }
-         delegate.run();
+         session.run();
       }
       catch (JMSException e)
       {
@@ -213,7 +209,7 @@
          throw new InvalidDestinationException("Not a JBossDestination:" + d);
       }
            
-      ProducerDelegate producerDelegate = delegate.createProducerDelegate((JBossDestination)d);
+      org.jboss.jms.client.api.ClientProducer producerDelegate = session.createProducerDelegate((JBossDestination)d);
       return new JBossMessageProducer(producerDelegate);
    }
 
@@ -241,7 +237,7 @@
 
       log.trace("attempting to create consumer for destination:" + d + (messageSelector == null ? "" : ", messageSelector: " + messageSelector) + (noLocal ? ", noLocal = true" : ""));
 
-      ConsumerDelegate cd = delegate.
+      org.jboss.jms.client.api.Consumer cd = session.
          createConsumerDelegate(((JBossDestination)d).toCoreDestination(), messageSelector, noLocal, null, false);
 
       return new JBossMessageConsumer(cd);
@@ -254,7 +250,7 @@
       {
          throw new IllegalStateException("Cannot create a queue using a TopicSession");
       }
-      return delegate.createQueue(queueName);
+      return session.createQueue(queueName);
    }
 
    public Topic createTopic(String topicName) throws JMSException
@@ -264,7 +260,7 @@
       {
          throw new IllegalStateException("Cannot create a topic on a QueueSession");
       }
-      return delegate.createTopic(topicName);
+      return session.createTopic(topicName);
    }
 
    public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws JMSException
@@ -283,8 +279,8 @@
          throw new InvalidDestinationException("Not a JBossTopic:" + topic);
       }
 
-      ConsumerDelegate cd =
-         delegate.createConsumerDelegate(((JBossTopic)topic).toCoreDestination(), null, false, name, false);
+      Consumer cd =
+         session.createConsumerDelegate(((JBossTopic)topic).toCoreDestination(), null, false, name, false);
 
       return new JBossMessageConsumer(cd);
    }
@@ -313,7 +309,7 @@
          messageSelector = null;
       }
 
-      ConsumerDelegate cd = delegate.
+      Consumer cd = session.
          createConsumerDelegate(((JBossTopic)topic).toCoreDestination(), messageSelector, noLocal, name, false);
 
       return new JBossMessageConsumer(cd);
@@ -344,8 +340,8 @@
          messageSelector = null;
       }
 
-      BrowserDelegate del =
-         delegate.createBrowserDelegate(((JBossQueue)queue).toCoreDestination(), messageSelector);
+      org.jboss.jms.client.api.ClientBrowser del =
+         session.createBrowserDelegate(((JBossQueue)queue).toCoreDestination(), messageSelector);
 
       return new JBossQueueBrowser(queue, messageSelector, del);
    }
@@ -357,8 +353,8 @@
       {
          throw new IllegalStateException("Cannot create a temporary queue using a TopicSession");
       }
-      JBossTemporaryQueue queue = new JBossTemporaryQueue(delegate);
-      delegate.addTemporaryDestination(queue.toCoreDestination());
+      JBossTemporaryQueue queue = new JBossTemporaryQueue(session);
+      session.addTemporaryDestination(queue.toCoreDestination());
       return queue;
    }
 
@@ -369,8 +365,8 @@
       {
          throw new IllegalStateException("Cannot create a temporary topic on a QueueSession");
       }
-      JBossTemporaryTopic topic = new JBossTemporaryTopic(delegate);
-      delegate.addTemporaryDestination(topic.toCoreDestination());
+      JBossTemporaryTopic topic = new JBossTemporaryTopic(session);
+      session.addTemporaryDestination(topic.toCoreDestination());
       return topic;
    }
 
@@ -381,15 +377,15 @@
       {
          throw new IllegalStateException("Cannot unsubscribe using a QueueSession");
       }
-      delegate.unsubscribe(name);
+      session.unsubscribe(name);
    }
    
    // XASession implementation
    
    public Session getSession() throws JMSException
    {      
-      SessionState state = (SessionState)(ProxyFactory.getDelegate(delegate)).getState();
-      if (!state.isXA())
+
+      if (!session.isXA())
       {
          throw new IllegalStateException("Isn't an XASession");
       }
@@ -399,7 +395,7 @@
   
    public XAResource getXAResource()
    {          
-      return delegate.getXAResource();
+      return session.getXAResource();
    }
    
    // QueueSession implementation
@@ -455,12 +451,12 @@
 
    public String toString()
    {
-      return "JBossSession->" + delegate;
+      return "JBossSession->" + session;
    }
    
-   public SessionDelegate getDelegate()
+   public org.jboss.jms.client.api.ClientSession getDelegate()
    {
-      return delegate;
+      return session;
    }
 
    // Package protected ---------------------------------------------
@@ -470,9 +466,9 @@
     * with messages to be processed by the session's run() method
     */
    void addAsfMessage(JBossMessage m, String consumerID, String queueName, int maxDeliveries,
-                      SessionDelegate connectionConsumerSession, boolean shouldAck) throws JMSException
+                      org.jboss.jms.client.api.ClientSession connectionConsumerSession, boolean shouldAck) throws JMSException
    {
-      delegate.addAsfMessage(m, consumerID, queueName, maxDeliveries, connectionConsumerSession, shouldAck);
+      session.addAsfMessage(m, consumerID, queueName, maxDeliveries, connectionConsumerSession, shouldAck);
    }
       
    // Protected -----------------------------------------------------

Added: trunk/src/main/org/jboss/jms/client/api/ClientBrowser.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientBrowser.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/api/ClientBrowser.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.jms.client.api;
+
+import javax.jms.JMSException;
+
+import org.jboss.jms.client.Closeable;
+import org.jboss.messaging.core.Message;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ */
+public interface ClientBrowser extends Closeable
+{
+   /**
+    * Reset the internal state of the browser endpoint so the following
+    * nextMessage()/hasNextMessage()/nextMessageBlock() invocations would reflect the state of the
+    * queue at the moment of the reset.
+    */
+   void reset() throws JMSException;
+
+   Message nextMessage() throws JMSException;
+   
+   boolean hasNextMessage() throws JMSException;
+      
+   Message[] nextMessageBlock(int maxMessages) throws JMSException;
+
+
+ }


Property changes on: trunk/src/main/org/jboss/jms/client/api/ClientBrowser.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/src/main/org/jboss/jms/client/api/ClientConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientConnection.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/api/ClientConnection.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.jms.client.api;
+
+import javax.jms.ConnectionMetaData;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.ServerSessionPool;
+
+import org.jboss.jms.client.Closeable;
+import org.jboss.jms.client.JBossConnectionConsumer;
+import org.jboss.jms.client.remoting.JMSRemotingConnection;
+import org.jboss.jms.tx.MessagingXid;
+import org.jboss.jms.tx.ResourceManager;
+import org.jboss.jms.tx.TransactionRequest;
+import org.jboss.messaging.core.remoting.Client;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ */
+public interface ClientConnection extends Closeable
+{
+   ClientSession createSessionDelegate(boolean transacted,
+         int acknowledgmentMode, boolean isXA) throws JMSException;
+
+   String getClientID() throws JMSException;
+
+   int getServerID();
+   
+
+   void setClientID(String id) throws JMSException;
+
+   void start() throws JMSException;
+
+   void stop() throws JMSException;
+
+   void sendTransaction(TransactionRequest request)
+         throws JMSException;
+
+   MessagingXid[] getPreparedTransactions() throws JMSException;
+
+   ExceptionListener getExceptionListener() throws JMSException;
+   
+   void setExceptionListener(ExceptionListener listener) throws JMSException;
+  
+   ConnectionMetaData getConnectionMetaData() throws JMSException;
+   
+   JBossConnectionConsumer createConnectionConsumer(Destination dest,
+                                                    String subscriptionName,
+                                                    String messageSelector,
+                                                    ServerSessionPool sessionPool,
+                                                    int maxMessages) throws JMSException;
+
+//   void registerFailoverListener(FailoverListener failoverListener);
+//   
+//   boolean unregisterFailoverListener(FailoverListener failoverListener);
+   
+   
+   public void setRemotingConnection(JMSRemotingConnection conn);
+   
+   public Client getClient();
+
+   public JMSRemotingConnection getRemotingConnection();
+
+   public ResourceManager getResourceManager();
+
+   public void setResourceManager(ResourceManager resourceManager);
+   
+   public String getID();
+   
+   
+   
+}


Property changes on: trunk/src/main/org/jboss/jms/client/api/ClientConnection.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/src/main/org/jboss/jms/client/api/ClientProducer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientProducer.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/api/ClientProducer.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.jms.client.api;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+
+import org.jboss.jms.client.Closeable;
+import org.jboss.jms.destination.JBossDestination;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ */
+public interface ClientProducer extends Closeable
+{
+   void setDisableMessageID(boolean value) throws JMSException;
+   
+   boolean isDisableMessageID() throws JMSException;
+   
+   void setDisableMessageTimestamp(boolean value) throws JMSException;
+   
+   boolean isDisableMessageTimestamp() throws JMSException;
+   
+   void setDeliveryMode(int deliveryMode) throws JMSException;
+   
+   int getDeliveryMode() throws JMSException;
+   
+   void setPriority(int defaultPriority) throws JMSException;
+   
+   int getPriority() throws JMSException;
+   
+   void setTimeToLive(long timeToLive) throws JMSException;
+   
+   long getTimeToLive() throws JMSException;
+   
+   JBossDestination getDestination() throws JMSException;
+   
+   void setDestination(JBossDestination dest) throws JMSException;
+
+   /**
+    * This method is only handled by the advice stack, the corresponding invocation is never sent
+    * to the server.
+    */
+   void send(JBossDestination destination,
+             Message message,
+             int deliveryMode,
+             int priority,
+             long timeToLive) throws JMSException;
+
+   void send(JBossDestination destination,
+             Message message,
+             int deliveryMode,
+             int priority,
+             long timeToLive, boolean keepOriginalID) throws JMSException;
+
+}


Property changes on: trunk/src/main/org/jboss/jms/client/api/ClientProducer.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/src/main/org/jboss/jms/client/api/ClientSession.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientSession.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/api/ClientSession.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -0,0 +1,194 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.jms.client.api;
+
+import java.io.Serializable;
+import java.util.List;
+
+import javax.jms.JMSException;
+import javax.jms.MessageListener;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.jms.client.Closeable;
+import org.jboss.jms.client.container.ClientConsumer;
+import org.jboss.jms.delegate.Ack;
+import org.jboss.jms.delegate.Cancel;
+import org.jboss.jms.delegate.DeliveryInfo;
+import org.jboss.jms.destination.JBossDestination;
+import org.jboss.jms.destination.JBossQueue;
+import org.jboss.jms.destination.JBossTopic;
+import org.jboss.jms.message.JBossBytesMessage;
+import org.jboss.jms.message.JBossMapMessage;
+import org.jboss.jms.message.JBossMessage;
+import org.jboss.jms.message.JBossObjectMessage;
+import org.jboss.jms.message.JBossStreamMessage;
+import org.jboss.jms.message.JBossTextMessage;
+import org.jboss.messaging.core.Destination;
+import org.jboss.messaging.core.Message;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ */
+public interface ClientSession extends Closeable
+{
+
+
+   ClientConnection getConnection();
+
+   ClientConsumer getCallbackHandler(String consumerID);
+
+   void addCallbackHandler(ClientConsumer handler);
+
+   void removeCallbackHandler(ClientConsumer handler);
+
+   String getID();
+   
+   /// Methods that will perform a server invocation ----------------------------------------------------------
+
+   Consumer createConsumerDelegate(Destination destination, String selector,
+         boolean noLocal, String subscriptionName,
+         boolean isCC) throws JMSException;
+   
+
+   ClientBrowser createBrowserDelegate(Destination queue, String messageSelector) throws JMSException;
+
+   /**
+    * Creates a queue identity given a Queue name. Does NOT create the physical queue. The physical
+    * creation of queues is an administrative task and is not to be initiated by the JMS API, with
+    * the exception of temporary queues.
+    */
+   JBossQueue createQueue(String queueName) throws JMSException;
+
+   /**
+    * Creates a topic identity given a Queue name. Does NOT create the physical topic. The physical
+    * creation of topics is an administrative task and is not to be initiated by the JMS API, with
+    * the exception of temporary topics.
+    */
+   JBossTopic createTopic(String topicName) throws JMSException;
+
+   /**
+    * Acknowledge a list of deliveries
+    * @throws JMSException
+    */
+   void acknowledgeDeliveries(List<Ack> acks) throws JMSException;
+
+   /**
+    * Acknowledge a delivery
+    * @throws JMSException
+    */
+   boolean acknowledgeDelivery(Ack ack) throws JMSException;
+
+   /**
+    * Cancel a list of deliveries.
+    */
+   void cancelDeliveries(List<Cancel> cancels) throws JMSException;
+ 
+   /**
+    * Cancel a delivery
+    * @param cancelure 
+    * @throws JMSException
+    */
+   void cancelDelivery(Cancel cancel) throws JMSException;
+
+   /**
+    * Add a temporary destination.
+    */
+   void addTemporaryDestination(Destination destination) throws JMSException;
+
+   /**
+    * Delete a temporary destination
+    */
+   void deleteTemporaryDestination(Destination destination) throws JMSException;
+
+   /**
+    * Unsubscribe the client from the durable subscription
+    * specified by subscriptionName
+    * 
+    * @param subscriptionName the Name of the durable subscription to unsubscribe from
+    * @throws JMSException if the unsubscribe fails
+    */
+   void unsubscribe(String subscriptionName) throws JMSException;
+
+   /**
+    * Send a message
+    * @param message The message to send
+    * @throws JMSException
+    */
+   void send(Message message) throws JMSException;
+
+   int getDupsOKBatchSize();
+
+   public boolean isStrictTck();
+
+
+   /// Client methods -------------------------------------------------------------------------------
+
+   JBossMessage createMessage() throws JMSException;
+
+   JBossBytesMessage createBytesMessage() throws JMSException;
+
+   JBossMapMessage createMapMessage() throws JMSException;
+
+   JBossObjectMessage createObjectMessage() throws JMSException;
+
+   JBossObjectMessage createObjectMessage(Serializable object) throws JMSException;
+
+   JBossStreamMessage createStreamMessage() throws JMSException;
+
+   JBossTextMessage createTextMessage() throws JMSException;
+
+   JBossTextMessage createTextMessage(String text) throws JMSException;
+
+   void preDeliver(DeliveryInfo deliveryInfo) throws JMSException;
+
+   boolean postDeliver() throws JMSException;
+
+   MessageListener getMessageListener() throws JMSException;
+
+   void setMessageListener(MessageListener listener) throws JMSException;
+
+   void run() throws JMSException;
+
+   XAResource getXAResource();
+
+   void addAsfMessage(JBossMessage m, String consumerID, String queueName,
+         int maxDeliveries, ClientSession connectionConsumerDelegate,
+         boolean shouldAck) throws JMSException;
+
+   boolean isTransacted() throws JMSException;
+
+   int getAcknowledgeMode() throws JMSException;
+
+   void commit() throws JMSException;
+
+   void rollback() throws JMSException;
+
+   void recover() throws JMSException;
+
+   void redeliver(List deliveryInfos) throws JMSException;
+
+   ClientProducer createProducerDelegate(JBossDestination destination) throws JMSException;
+
+   void acknowledgeAll() throws JMSException;
+   
+   boolean isXA();
+   
+   boolean isTreatAsNonTransactedWhenNotEnlisted();
+   
+   public void setTreatAsNonTransactedWhenNotEnlisted(boolean treatAsNonTransactedWhenNotEnlisted);
+
+   public Object getCurrentTxId();
+
+   public void setCurrentTxId(Object currentTxId);
+
+
+   
+
+}


Property changes on: trunk/src/main/org/jboss/jms/client/api/ClientSession.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Added: trunk/src/main/org/jboss/jms/client/api/Consumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/Consumer.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/api/Consumer.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.jms.client.api;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+import org.jboss.jms.client.Closeable;
+import org.jboss.messaging.core.Destination;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ */
+public interface Consumer extends Closeable
+{
+   void changeRate(float newRate) throws JMSException;
+
+   // ConsumerEndpoint -------------------------------------------------------------------------
+   
+   // ConsumerDelegate --------------------------------------------------------------------------
+   MessageListener getMessageListener() throws JMSException;
+
+   void setMessageListener(MessageListener listener) throws JMSException;
+
+   Destination getDestination() throws JMSException;
+
+   boolean getNoLocal() throws JMSException;
+
+   String getMessageSelector() throws JMSException;
+
+   Message receive(long timeout) throws JMSException;
+   
+   String getConsumerID();
+   
+   int getMaxDeliveries();
+   
+   boolean isShouldAck();
+
+}


Property changes on: trunk/src/main/org/jboss/jms/client/api/Consumer.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Modified: trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -30,11 +30,11 @@
 import javax.jms.MessageListener;
 import javax.jms.Session;
 
+import org.jboss.jms.client.api.ClientSession;
+import org.jboss.jms.client.api.Consumer;
 import org.jboss.jms.delegate.Cancel;
-import org.jboss.jms.delegate.ConsumerDelegate;
 import org.jboss.jms.delegate.DefaultCancel;
 import org.jboss.jms.delegate.DeliveryInfo;
-import org.jboss.jms.delegate.SessionDelegate;
 import org.jboss.jms.message.JBossMessage;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.Message;
@@ -47,6 +47,7 @@
 /**
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox/a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
  * @version <tt>$Revision: 2774 $</tt>
  *
  * $Id: MessageCallbackHandler.java 2774 2007-06-12 22:43:54Z timfox $
@@ -71,7 +72,7 @@
    }
    
    private static boolean checkExpiredOrReachedMaxdeliveries(JBossMessage jbm,
-                                                             SessionDelegate del,
+                                                             ClientSession del,
                                                              int maxDeliveries, boolean shouldCancel)
    {
       Message msg = jbm.getCoreMessage();
@@ -117,7 +118,7 @@
    }
         
    //This is static so it can be called by the asf layer too
-   public static void callOnMessage(SessionDelegate sess,
+   public static void callOnMessage(ClientSession sess,
                                     MessageListener listener,
                                     String consumerID,
                                     String queueName,
@@ -125,7 +126,7 @@
                                     JBossMessage m,
                                     int ackMode,
                                     int maxDeliveries,
-                                    SessionDelegate connectionConsumerSession,
+                                    ClientSession connectionConsumerSession,
                                     boolean shouldAck)
       throws JMSException
    {      
@@ -192,8 +193,8 @@
     * priority messages might be behind lower priority messages and thus get consumed out of order
     */
    private PriorityLinkedList<JBossMessage> buffer;
-   private SessionDelegate sessionDelegate;
-   private ConsumerDelegate consumerDelegate;
+   private ClientSession sessionDelegate;
+   private Consumer consumerDelegate;
    private String consumerID;
    private boolean isConnectionConsumer;
    private volatile Thread receiverThread;
@@ -217,7 +218,7 @@
    // Constructors ---------------------------------------------------------------------------------
 
    public ClientConsumer(boolean isCC, int ackMode,                                
-                         SessionDelegate sess, ConsumerDelegate cons, String consumerID,
+                         ClientSession sess, Consumer cons, String consumerID,
                          String queueName,
                          int bufferSize, QueuedExecutor sessionExecutor,
                          int maxDeliveries, boolean shouldAck,

Deleted: trunk/src/main/org/jboss/jms/client/container/FailoverValveInterceptor.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/FailoverValveInterceptor.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/container/FailoverValveInterceptor.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -1,209 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.jms.client.container;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.jboss.jms.client.FailoverCommandCenter;
-import org.jboss.jms.client.FailoverValve2;
-import org.jboss.jms.client.FailureDetector;
-import org.jboss.jms.client.delegate.ClientConnectionDelegate;
-import org.jboss.jms.client.delegate.ClientSessionDelegate;
-import org.jboss.jms.client.delegate.DelegateSupport;
-import org.jboss.jms.client.remoting.JMSRemotingConnection;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.HierarchicalState;
-import org.jboss.jms.exception.MessagingNetworkFailureException;
-import org.jboss.logging.Logger;
-
-/**
- * An interceptor that acts as a failover valve: it allows all invocations to go through as long
- * as there is no failover in progress (valve is open), and holds all invocations while client-side
- * failover is taking place (valve is closed). The interceptor is also a failover detector, in that
- * it catches "failure-triggering" exceptions, and notifies the failover command center.
- *
- * The interceptor fields org.jboss.jms.client.Valve's method calls.
- *
- * It is a PER_INSTANCE interceptor.
- *
- * An instance of this interceptor must guard access to each connection, session, producer, consumer
- * and queue browser delegate.
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- * @version <tt>$Revision$</tt>
- * $Id$
- */
-public class FailoverValveInterceptor implements InvocationHandler, FailureDetector
-{
-   // Constants ------------------------------------------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(FailoverValveInterceptor.class);
-
-   // Static ---------------------------------------------------------------------------------------
-
-   private static boolean trace = log.isTraceEnabled();
-
-   // Attributes -----------------------------------------------------------------------------------
-
-   private DelegateSupport delegate;
-
-   // We need to cache connectionState here.
-   // IMPORTANT - We must not cache the fcc or valve since these need to be replaced when failover
-   //             occurs and if we cache them we wil end up using the old ones.
-   private ConnectionState connectionState;
-
-   public FailoverValveInterceptor (DelegateSupport delegate)
-   {
-      this.delegate = delegate;
-   }
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   // Interceptor implemenation --------------------------------------------------------------------
-
-   public String getName()
-   {
-      return "FailoverValveInterceptor";
-   }
-
-   public DelegateSupport getDelegate()
-   {
-      return delegate;
-   }
-
-   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
-   {
-      // maintain a reference to connectionState, so we can ensure we have already tested for fcc.
-      // As fcc can be null on non-clustered connections we have to cache connectionState instead
-      if (connectionState == null)
-      {
-         HierarchicalState hs = delegate.getState();
-         while (hs != null && !(hs instanceof ConnectionState))
-         {
-            hs = hs.getParent();
-         }
-
-         connectionState = (ConnectionState)hs;
-      }
-
-      FailoverCommandCenter fcc = connectionState.getFailoverCommandCenter();
-
-      // non clustered, send the invocation forward
-      if (fcc == null)
-      {
-         return internalInvoke(method, args);
-      }
-
-      FailoverValve2 valve = fcc.getValve();
-
-      JMSRemotingConnection remotingConnection = null;
-      String methodName = method.getName();
-
-      if (methodName.equals("startAfterFailover"))
-      {
-         //We don't use the valve on this method
-         return internalInvoke(method, args);
-      }
-
-      boolean left = false;
-
-      try
-      {
-         valve.enter();
-
-         // it's important to retrieve the remotingConnection while inside the Valve
-         remotingConnection = fcc.getRemotingConnection();
-         return internalInvoke(method, args);
-      }
-      catch (Throwable e)
-      {
-         if (e instanceof MessagingNetworkFailureException)
-         {
-            valve.leave();
-            left = true;
-
-            log.debug(this + " detected network failure, putting " + methodName +
-            "() on hold until failover completes");
-
-            fcc.failureDetected(e, this, remotingConnection);
-
-            // Set retry flag as true on send() and sendTransaction()
-            // more details at http://jira.jboss.org/jira/browse/JBMESSAGING-809
-
-            if ((delegate instanceof ClientSessionDelegate && methodName.equals("send")) ||
-                (delegate instanceof ClientConnectionDelegate && methodName.equals("sendTransaction")))
-            {
-               log.trace(this + " caught " + methodName + "() invocation, enabling check for duplicates");
-
-               args[1] = Boolean.TRUE;
-            }
-
-            // We don't retry the following invocations:
-            // cancelDelivery(), cancelDeliveries(), cancelInflightMessages() - the deliveries will
-            // already be cancelled after failover.
-
-            if (methodName.equals("cancelDelivery") ||
-               methodName.equals("cancelDeliveries"))
-            {
-               log.trace(this + " NOT resuming " + methodName + "(), let it wither and die");
-
-               return null;
-            }
-            else
-            {
-               log.trace(this + " resuming " + methodName + "()");
-
-               return method.invoke(delegate, args);
-            }
-         }
-         else
-         {
-            if (trace) { log.trace(this + " caught not failover-triggering throwable, rethrowing " + e); }
-            throw e;
-         }
-      }
-      finally
-      {
-         if (!left)
-         {
-            valve.leave();
-         }
-      }
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public String toString()
-   {
-      return "FailoverValveInterceptor." + (delegate == null ? "UNITIALIZED" : delegate.toString());
-   }
-
-   // Package protected ----------------------------------------------------------------------------
-
-   // Protected ------------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-   private Object internalInvoke(Method method, Object[] args)
-           throws Throwable
-   {
-      try
-      {
-            return method.invoke(delegate, args);
-      }
-      catch (InvocationTargetException e)
-      {
-         throw e.getCause();
-      }
-   }
-
-
-   // Inner classes --------------------------------------------------------------------------------
-
-}

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -26,9 +26,10 @@
 
 import javax.jms.JMSException;
 
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.HierarchicalState;
-import org.jboss.jms.delegate.BrowserDelegate;
+import org.jboss.jms.client.api.ClientBrowser;
+import org.jboss.jms.client.api.ClientSession;
+import org.jboss.messaging.core.remoting.Client;
+import org.jboss.messaging.core.Destination;
 import org.jboss.messaging.core.Message;
 import org.jboss.messaging.core.remoting.wireformat.BrowserHasNextMessageRequest;
 import org.jboss.messaging.core.remoting.wireformat.BrowserHasNextMessageResponse;
@@ -45,12 +46,13 @@
  *
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
  *
  * @version <tt>$Revision$</tt>
  *
  * $Id$
  */
-public class ClientBrowserDelegate extends DelegateSupport implements BrowserDelegate
+public class ClientBrowserDelegate extends CommunicationSupport<ClientBrowserDelegate> implements ClientBrowser
 {
    // Constants ------------------------------------------------------------------------------------
 
@@ -58,22 +60,34 @@
 	
    // Attributes -----------------------------------------------------------------------------------
 
+	private ClientSession session;
+   private Destination jmsDestination;
+   private String messageSelector;
+
    // Static ---------------------------------------------------------------------------------------
 
    // Constructors ---------------------------------------------------------------------------------
 
-	public ClientBrowserDelegate(String objectID)
+   public ClientBrowserDelegate(ClientSession session, String objectID, Destination jmsDestination, String messageSelector)
    {
       super(objectID);
+      this.session = session;
+      this.jmsDestination = jmsDestination;
+      this.messageSelector = messageSelector;
    }
 
+   public ClientBrowserDelegate(String objectID)
+   {
+      super(objectID);
+   }
+
    public ClientBrowserDelegate()
    {
    }
 
    // DelegateSupport overrides --------------------------------------------------------------------
 
-   public void synchronizeWith(DelegateSupport nd) throws Exception
+   public void synchronizeWith(ClientBrowserDelegate nd) throws Exception
    {
       super.synchronizeWith(nd);
 
@@ -83,21 +97,8 @@
 
       // synchronize (recursively) the client-side state
 
-      state.synchronizeWith(newDelegate.getState());
-
-      client = ((ConnectionState)state.getParent().getParent()).getRemotingConnection().
-         getRemotingClient();
    }
 
-   public void setState(HierarchicalState state)
-   {
-      super.setState(state);
-
-      client = ((ConnectionState)state.getParent().getParent()).getRemotingConnection().
-         getRemotingClient();
-   }
-
-
    // Closeable implementation ---------------------------------------------------------------------
 
    public void close() throws JMSException
@@ -163,6 +164,12 @@
 
    // Protected ------------------------------------------------------------------------------------
 
+   protected Client getClient()
+   {
+      return this.session.getConnection().getClient();
+   }
+   
+
    // Package Private ------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientClusteredConnectionFactoryDelegate.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -32,11 +32,11 @@
 
 import javax.jms.JMSException;
 
+import org.jboss.jms.client.api.ClientConnection;
 import org.jboss.jms.client.container.JMSClientVMIdentifier;
 import org.jboss.jms.client.container.ConnectionFailureListener;
 import org.jboss.jms.client.plugin.LoadBalancingPolicy;
 import org.jboss.jms.client.remoting.JMSRemotingConnection;
-import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.jms.client.FailoverCommandCenter;
 import org.jboss.jms.delegate.ConnectionFactoryDelegate;
 import org.jboss.jms.delegate.CreateConnectionResult;
@@ -44,6 +44,7 @@
 import org.jboss.jms.delegate.TopologyResult;
 import org.jboss.jms.exception.MessagingNetworkFailureException;
 import org.jboss.logging.Logger;
+import org.jboss.messaging.core.remoting.Client;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
 import org.jboss.messaging.core.remoting.PacketHandler;
 import org.jboss.messaging.core.remoting.PacketSender;
@@ -70,7 +71,7 @@
  *
  * $Id$
  */
-public class ClientClusteredConnectionFactoryDelegate extends DelegateSupport
+public class ClientClusteredConnectionFactoryDelegate extends CommunicationSupport
    implements Serializable, ConnectionFactoryDelegate
 {
    // Constants ------------------------------------------------------------------------------------
@@ -109,7 +110,7 @@
          {
             String serverlocatorURI = delegates[server].getServerLocatorURI();
             
-            remoting = new JMSRemotingConnection(serverlocatorURI, delegates[server].getStrictTck());
+            remoting = new JMSRemotingConnection(serverlocatorURI);
             remoting.start();
             currentDelegate = delegates[server];
             if (trace) log.trace("Adding callback");
@@ -300,7 +301,7 @@
             CreateConnectionResult res = delegate.
                createConnectionDelegate(username, password, failedNodeIDToServer);
 
-            ClientConnectionDelegate cd = res.getInternalDelegate();
+            ClientConnection cd = res.getInternalDelegate();
 
             if (cd != null)
             {
@@ -308,7 +309,7 @@
 
                log.trace(this + " got local connection delegate " + cd);
 
-               if (supportsFailover)
+               /*if (supportsFailover)
                {
 	               cd.getState().initializeFailoverCommandCenter();
 
@@ -331,7 +332,7 @@
 	               cd.getState().setClusteredConnectionFactoryDeleage(this);
 
 	               log.trace("Successfully initialised new connection");
-               }
+               } */
 
                return res;
             }
@@ -510,6 +511,10 @@
 
    // Protected ------------------------------------------------------------------------------------
 
+   protected Client getClient()
+   {
+      return currentDelegate.getClient();
+   }
    // Private --------------------------------------------------------------------------------------
 
    private void dumpFailoverMap(Map failoverMap)

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -23,7 +23,7 @@
 
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
-
+import java.util.Set;
 import javax.jms.ConnectionMetaData;
 import javax.jms.Destination;
 import javax.jms.ExceptionListener;
@@ -31,20 +31,19 @@
 import javax.jms.JMSException;
 import javax.jms.ServerSessionPool;
 
-import org.jboss.jms.client.FailoverListener;
 import org.jboss.jms.client.JBossConnectionConsumer;
 import org.jboss.jms.client.JBossConnectionMetaData;
+import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.jms.client.api.ClientSession;
 import org.jboss.jms.client.remoting.ConsolidatedRemotingConnectionListener;
 import org.jboss.jms.client.remoting.JMSRemotingConnection;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.SessionState;
-import org.jboss.jms.delegate.ConnectionDelegate;
-import org.jboss.jms.delegate.SessionDelegate;
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.tx.MessagingXid;
+import org.jboss.jms.tx.ResourceManager;
 import org.jboss.jms.tx.ResourceManagerFactory;
 import org.jboss.jms.tx.TransactionRequest;
 import org.jboss.logging.Logger;
+import org.jboss.messaging.core.remoting.Client;
 import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
 import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
 import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
@@ -58,6 +57,7 @@
 import org.jboss.messaging.core.remoting.wireformat.SetClientIDMessage;
 import org.jboss.messaging.core.remoting.wireformat.StartConnectionMessage;
 import org.jboss.messaging.core.remoting.wireformat.StopConnectionMessage;
+import org.jboss.messaging.util.ConcurrentHashSet;
 import org.jboss.messaging.util.ProxyFactory;
 import org.jboss.messaging.util.Version;
 
@@ -73,13 +73,13 @@
  *
  * $Id$
  */
-public class ClientConnectionDelegate extends DelegateSupport<ConnectionState> implements ConnectionDelegate
+public class ClientConnectionDelegate extends CommunicationSupport<ClientConnectionDelegate> implements ClientConnection
 {
    // Constants ------------------------------------------------------------------------------------
 
-	private static final long serialVersionUID = -5485083713058725777L;
+   private static final long serialVersionUID = -5485083713058725777L;
 
-	private static final Logger log = Logger.getLogger(ClientConnectionDelegate.class);
+   private static final Logger log = Logger.getLogger(ClientConnectionDelegate.class);
 
    private static final boolean trace = log.isTraceEnabled();
 
@@ -92,7 +92,37 @@
    private transient JMSRemotingConnection remotingConnection;
 
    private transient Version versionToUse;
+   
+   private boolean strictTck;
 
+   
+   // Attributes that used to be on ConnectionState
+   
+   protected Set<ClientSession> children = new ConcurrentHashSet<ClientSession>();
+
+   protected boolean started;
+
+   private boolean justCreated = true;
+
+   private String clientID;
+
+   private ResourceManager resourceManager;
+
+   
+   // Cached by the connection state in case ClusteringAspect needs to re-try establishing
+   // connection on a different node
+   private transient String username;
+
+   // Cached by the connection state in case ClusteringAspect needs to re-try establishing
+   // connection on a different node
+   private transient String password;
+
+
+   
+   
+   
+   
+
    // Static ---------------------------------------------------------------------------------------
 
    // Constructors ---------------------------------------------------------------------------------
@@ -106,11 +136,12 @@
 
    public ClientConnectionDelegate()
    {
+      super();
    }
 
    // DelegateSupport overrides --------------------------------------------------------------------
 
-   public void synchronizeWith(DelegateSupport nd) throws Exception
+   public void synchronizeWith(ClientConnectionDelegate nd) throws Exception
    {
       log.trace(this + " synchronizing with " + nd);
 
@@ -124,17 +155,11 @@
       // state based on the old state. It makes sense, since in the end the state makes it to the
       // server
 
-      ConnectionState thisState = (ConnectionState)state;
-
-      if (thisState.getClientID() != null)
+      if (getClientID() != null)
       {
-         newDelegate.setClientID(thisState.getClientID());
+         newDelegate.setClientID(getClientID());
       }
 
-      // synchronize (recursively) the client-side state
-
-      state.synchronizeWith(newDelegate.getState());
-
       // synchronize the delegates
 
       remotingConnection = newDelegate.getRemotingConnection();
@@ -143,18 +168,11 @@
       // There is one RM per server, so we need to merge the rms if necessary
       ResourceManagerFactory.instance.handleFailover(serverID, newDelegate.getServerID());
 
-      client = remotingConnection.getRemotingClient();
+      //client = remotingConnection.getRemotingClient();
 
       serverID = newDelegate.getServerID();
    }
 
-   public void setState(ConnectionState state)
-   {
-      super.setState(state);
-
-      client = state.getRemotingConnection().getRemotingClient();
-   }
-
    // Closeable implementation ---------------------------------------------------------------------
 
    public void close() throws JMSException
@@ -165,10 +183,6 @@
       }
       finally
       {
-         //Always cleanup in a finally - we need to cleanup if the server call to close fails too
-
-         JMSRemotingConnection remotingConnection = state.getRemotingConnection();
-
          // remove the consolidated remoting connection listener
 
          ConsolidatedRemotingConnectionListener l = remotingConnection.removeConnectionListener();
@@ -181,7 +195,7 @@
          remotingConnection.stop();
 
          // And to resource manager
-         ResourceManagerFactory.instance.checkInResourceManager(state.getServerID());
+         ResourceManagerFactory.instance.checkInResourceManager(getServerID());
       }
 
    }
@@ -192,9 +206,14 @@
       ClosingResponse response = (ClosingResponse) sendBlocking(new ClosingRequest(sequence));
       return response.getID();
    }
+   
+   public Client getClient()
+   {
+      return this.getRemotingConnection().getRemotingClient();
+   }
+   
+   // Connection implementation ------------------------------------------------------------
 
-   // ConnectionDelegate implementation ------------------------------------------------------------
-
    /**
     * This invocation should either be handled by the client-side interceptor chain or by the
     * server-side endpoint.
@@ -208,77 +227,65 @@
       if (trace) { log.trace("createConnectionConsumer()"); }
 
 
-      return new JBossConnectionConsumer((ConnectionDelegate)ProxyFactory.proxy(this, ConnectionDelegate.class), (JBossDestination)dest,
+      return new JBossConnectionConsumer((ClientConnection)ProxyFactory.proxy(this, ClientConnection.class), (JBossDestination)dest,
                                          subscriptionName, messageSelector, sessionPool,
                                          maxMessages);
    }
 
 
 
-   private SessionState createSessionData(ClientSessionDelegate sessionDelegate, SessionDelegate proxyDelegate, boolean transacted, int ackMode, boolean xa)
-   {
-
-      ConnectionState connectionState = getState();
-
-      SessionState sessionState =
-         new SessionState(connectionState, sessionDelegate, proxyDelegate, transacted,
-                          ackMode, xa, sessionDelegate.getDupsOKBatchSize());
-
-      return sessionState;
-   }
-
-
-   public SessionDelegate createSessionDelegate(boolean transacted,
+   public ClientSession createSessionDelegate(boolean transacted,
                                                 int acknowledgmentMode,
                                                 boolean isXA) throws JMSException
    {
 
-      state.setJustCreated(false);
+      justCreated = false;
 
-
       CreateSessionRequest request = new CreateSessionRequest(transacted, acknowledgmentMode, isXA);
       CreateSessionResponse response = (CreateSessionResponse) sendBlocking(request);         
-      ClientSessionDelegate delegate = new ClientSessionDelegate(response.getSessionID(), response.getDupsOKBatchSize(), response.isStrictTCK());
-
-      SessionDelegate proxy =(SessionDelegate) ProxyFactory.proxy(delegate, SessionDelegate.class);
-      delegate.setState(createSessionData(delegate, proxy, transacted, acknowledgmentMode, isXA));
+      ClientSessionDelegate delegate = new ClientSessionDelegate(this, response.getSessionID(), response.getDupsOKBatchSize(), isStrictTck(), 
+            transacted, acknowledgmentMode, isXA);
+      ClientSession proxy =(ClientSession) ProxyFactory.proxy(delegate, ClientSession.class);
+      children.add(proxy);
       return proxy;
    }
 
 
+   public boolean isStrictTck()
+   {
+      return strictTck;
+   }
+
+   public void setStrictTck(boolean strictTck)
+   {
+      this.strictTck = strictTck;
+   }
+
    public String getClientID() throws JMSException
    {
-      ConnectionState currentState = getState();
+      justCreated = false;
 
-      currentState.setJustCreated(false);
-
-      if (currentState.getClientID() == null)
+      if (clientID == null)
       {
          //Get from the server
-         currentState.setClientID(invokeGetClientID());
+         clientID = ((GetClientIDResponse) sendBlocking(new GetClientIDRequest())).getClientID();
       }
-      return currentState.getClientID();
+      return clientID;
 
    }
 
-   private String invokeGetClientID() throws JMSException
-   {
-      GetClientIDResponse response = (GetClientIDResponse) sendBlocking(new GetClientIDRequest());
-      return response.getClientID();
-   }
-
    /**
     * This invocation should either be handled by the client-side interceptor chain or by the
     * server-side endpoint.
     */
    public ConnectionMetaData getConnectionMetaData() throws JMSException
    {
-      ConnectionState currentState = getState();
-      currentState.setJustCreated(false);
 
+      justCreated = false;
+
       if (connMetaData == null)
       {
-         connMetaData = new JBossConnectionMetaData(getState().getVersionToUse());
+         connMetaData = new JBossConnectionMetaData(versionToUse);
       }
 
       return connMetaData;
@@ -290,9 +297,9 @@
     */
    public ExceptionListener getExceptionListener() throws JMSException
    {
-      state.setJustCreated(false);
+      justCreated = false;
 
-      return state.getRemotingConnection().getConnectionListener().getJMSExceptionListener();
+      return remotingConnection.getConnectionListener().getJMSExceptionListener(); 
    }
 
    public void sendTransaction(TransactionRequest tr) throws JMSException
@@ -303,21 +310,18 @@
 
    public void setClientID(String clientID) throws JMSException
    {
-      ConnectionState currentState = getState();
-
-      if (currentState.getClientID() != null)
+      if (this.clientID != null)
       {
          throw new javax.jms.IllegalStateException("Client id has already been set");
       }
-      if (!currentState.isJustCreated())
+      if (!justCreated)
       {
          throw new IllegalStateException("setClientID can only be called directly after the connection is created");
       }
 
-      currentState.setClientID(clientID);
+      this.clientID = clientID;
+      this.justCreated = false;
 
-      currentState.setJustCreated(false);
-
       // this gets invoked on the server too
       invokeSetClientID(clientID);
       
@@ -333,16 +337,15 @@
     */
    public void setExceptionListener(ExceptionListener listener) throws JMSException
    {
-      state.setJustCreated(false);
+      justCreated = false;
 
-      state.getRemotingConnection().getConnectionListener().
-         addJMSExceptionListener(listener);
+      remotingConnection.getConnectionListener().addJMSExceptionListener(listener);
    }
 
    public void start() throws JMSException
    {
-      state.setStarted(true);
-      state.setJustCreated(false);
+      started = true;
+      justCreated = false;
       sendOneWay(new StartConnectionMessage());
    }
    
@@ -353,8 +356,8 @@
 
    public void stop() throws JMSException
    {
-      state.setStarted(false);
-      state.setJustCreated(false);
+      started = false;
+      justCreated = false;
       sendBlocking(new StopConnectionMessage());
    }
 
@@ -365,22 +368,6 @@
       return response.getXids();
    }
 
-   /**
-    * This invocation should be handled by the client-side interceptor chain.
-    */
-   public void registerFailoverListener(FailoverListener listener)
-   {
-      state.getFailoverCommandCenter().registerFailoverListener(listener);
-   }
-
-   /**
-    * This invocation should be handled by the client-side interceptor chain.
-    */
-   public boolean unregisterFailoverListener(FailoverListener listener)
-   {
-      return state.getFailoverCommandCenter().unregisterFailoverListener(listener);
-   }   
-
    // Public ---------------------------------------------------------------------------------------
 
    public void setRemotingConnection(JMSRemotingConnection conn)
@@ -415,6 +402,29 @@
    }
 
    // Protected ------------------------------------------------------------------------------------
+   
+   
+   protected void closeChildren() throws JMSException
+   {
+      for (ClientSession session: children)
+      {
+         try
+         {
+            session.closing(-1);
+            session.close();
+         }
+         catch (Throwable t)
+         {
+            //We swallow exceptions in close/closing, this is because if the connection fails, it is naturally for code to then close
+            //in a finally block, it would not then be appropriate to throw an exception. This is a common technique
+            if (trace)
+            {
+               log.trace("Failed to close", t);
+            }
+         }
+         
+      }
+   }
 
    // Streamable implementation -------------------------------------------------------------------
 
@@ -432,6 +442,18 @@
       out.writeInt(serverID);
    }
 
+   public ResourceManager getResourceManager()
+   {
+      return resourceManager;
+   }
+
+   public void setResourceManager(ResourceManager resourceManager)
+   {
+      this.resourceManager = resourceManager;
+   }
+   
+   
+
    // Package Private ------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -29,15 +29,15 @@
 
 import javax.jms.JMSException;
 
+import org.jboss.jms.client.api.ClientConnection;
 import org.jboss.jms.client.container.JMSClientVMIdentifier;
 import org.jboss.jms.client.remoting.ConsolidatedRemotingConnectionListener;
 import org.jboss.jms.client.remoting.JMSRemotingConnection;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.delegate.ConnectionDelegate;
 import org.jboss.jms.delegate.ConnectionFactoryDelegate;
 import org.jboss.jms.delegate.CreateConnectionResult;
 import org.jboss.jms.delegate.TopologyResult;
 import org.jboss.jms.exception.MessagingNetworkFailureException;
+import org.jboss.jms.tx.ResourceManagerFactory;
 import org.jboss.messaging.core.remoting.Client;
 import org.jboss.messaging.core.remoting.NIOConnector;
 import org.jboss.messaging.core.remoting.ServerLocator;
@@ -51,6 +51,7 @@
  *
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
  *
  * @version <tt>$Revision$</tt>
@@ -58,7 +59,7 @@
  * $Id$
  */
 public class ClientConnectionFactoryDelegate
-   extends DelegateSupport implements ConnectionFactoryDelegate, Serializable
+   extends CommunicationSupport<ClientConnectionFactoryDelegate> implements ConnectionFactoryDelegate, Serializable
 {
    // Constants ------------------------------------------------------------------------------------
 
@@ -87,7 +88,7 @@
     * The client itself has a version, but we also support other versions of servers lower if the
     * connection version is lower (backwards compatibility)
     */
-   public static Version getVersionToUse(Version connectionVersion)
+   private static Version getVersionToUse(Version connectionVersion)
    {
       Version clientVersion = Version.instance();
 
@@ -122,38 +123,14 @@
    }
    
    public ClientConnectionFactoryDelegate()
-   {      
+   {
    }
-
-   private ConnectionState createConnectionState(ClientConnectionDelegate connectionDelegate, ConnectionDelegate proxyDelegate) throws JMSException
+   
+   protected Client getClient()
    {
-      int serverID = connectionDelegate.getServerID();
-      Version versionToUse = connectionDelegate.getVersionToUse();
-      JMSRemotingConnection remotingConnection = connectionDelegate.getRemotingConnection();
-
-      // install the consolidated remoting connection listener; it will be de-installed on
-      // connection closing by ConnectionAspect
-
-      ConsolidatedRemotingConnectionListener listener =
-         new ConsolidatedRemotingConnectionListener();
-
-      if (remotingConnection!=null)remotingConnection.addConnectionListener(listener);
-
-      if (versionToUse == null)
-      {
-         throw new IllegalStateException("Connection version is null");
-      }
-
-      ConnectionState connectionState =
-         new ConnectionState(serverID, connectionDelegate, proxyDelegate, 
-                             remotingConnection, versionToUse);
-
-      listener.setConnectionState(connectionState);
-
-      return connectionState;
+      return null;
    }
 
-
    public CreateConnectionResult createConnectionDelegate(String username,
                                                           String password,
                                                           int failedNodeID)
@@ -173,23 +150,30 @@
       
       byte v = version.getProviderIncrementingVersion();
                        
-      JMSRemotingConnection remotingConnection = null;
-      
       CreateConnectionResult res;
       
+      JMSRemotingConnection remotingConnection = null;
       try
       {
-         remotingConnection = new JMSRemotingConnection(serverLocatorURI, strictTck);
+         remotingConnection = new JMSRemotingConnection(serverLocatorURI);
        
          remotingConnection.start();
-         client = remotingConnection.getRemotingClient();
+         Client client = remotingConnection.getRemotingClient(); 
          String sessionID = client.getSessionID();
          
          CreateConnectionRequest request = new CreateConnectionRequest(v, sessionID, JMSClientVMIdentifier.instance, failedNodeID, username, password);
-         CreateConnectionResponse response = (CreateConnectionResponse) sendBlocking(request);
+         CreateConnectionResponse response = (CreateConnectionResponse) sendBlocking(client, request);
          ClientConnectionDelegate connectionDelegate = new ClientConnectionDelegate(response.getConnectionID(), response.getServerID());
+         connectionDelegate.setStrictTck(strictTck);
 
          connectionDelegate.setVersionToUse(version);
+         connectionDelegate.setResourceManager(ResourceManagerFactory.instance.checkOutResourceManager(connectionDelegate.getServerID()));
+
+         ConsolidatedRemotingConnectionListener listener =
+            new ConsolidatedRemotingConnectionListener(connectionDelegate);
+
+         if (remotingConnection!=null)remotingConnection.addConnectionListener(listener);
+         
          res = new CreateConnectionResult(connectionDelegate);
       } catch (Throwable t)
       {
@@ -206,7 +190,7 @@
          throw handleThrowable(t);
       }
          
-      ClientConnectionDelegate connectionDelegate = res.getInternalDelegate();
+      ClientConnection connectionDelegate = res.getInternalDelegate();
       
       if (connectionDelegate != null)
       {
@@ -225,9 +209,6 @@
          }
       }
 
-
-      connectionDelegate.setState(createConnectionState(connectionDelegate, res.getProxiedDelegate()));
-      
       return res;
    }
    
@@ -263,6 +244,11 @@
    {
       return serverVersion;
    }
+   
+   public String getName()
+   {
+      return uniqueName;
+   }
 
 
    public boolean getStrictTck()
@@ -270,7 +256,7 @@
        return strictTck;
    }
 
-    public void synchronizeWith(DelegateSupport newDelegate) throws Exception
+    public void synchronizeWith(ClientConnectionFactoryDelegate newDelegate) throws Exception
    {
       super.synchronizeWith(newDelegate);
    }
@@ -307,6 +293,8 @@
    {      
       super.read(in);
       
+      uniqueName = in.readUTF();
+      
       serverLocatorURI = in.readUTF();
       
       serverVersion = new Version();
@@ -324,6 +312,8 @@
    {
       super.write(out);
       
+      out.writeUTF(uniqueName);
+      
       out.writeUTF(serverLocatorURI);
       
       serverVersion.write(out);

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -28,19 +28,20 @@
 import javax.jms.Message;
 import javax.jms.MessageListener;
 
+import org.jboss.jms.client.api.Consumer;
+import org.jboss.jms.client.api.ClientSession;
+import org.jboss.jms.client.container.ClientConsumer;
 import org.jboss.jms.client.remoting.CallbackManager;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.ConsumerState;
-import org.jboss.jms.client.state.SessionState;
-import org.jboss.jms.delegate.ConsumerDelegate;
 import org.jboss.jms.exception.MessagingShutdownException;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.Destination;
+import org.jboss.messaging.core.DestinationType;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
 import org.jboss.messaging.core.remoting.wireformat.ChangeRateMessage;
 import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
 import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
 import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
+import org.jboss.messaging.core.remoting.Client;
 
 /**
  * The client-side Consumer delegate class.
@@ -48,12 +49,13 @@
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
  *
  * @version <tt>$Revision$</tt>
  *
  * $Id$
  */
-public class ClientConsumerDelegate extends DelegateSupport<ConsumerState> implements ConsumerDelegate
+public class ClientConsumerDelegate extends CommunicationSupport<ClientConsumerDelegate> implements Consumer
 {
    // Constants ------------------------------------------------------------------------------------
 
@@ -63,14 +65,29 @@
 
    // Attributes -----------------------------------------------------------------------------------
 
+	private ClientSession session;
    private int bufferSize;
    private int maxDeliveries;
    private long redeliveryDelay;
 
+   // State attributes -----------------------------------------------------------------------------
+
+   private String consumerID;
+   private Destination destination;
+   private String selector;
+   private String subscriptionName;
+   private boolean noLocal;
+   private boolean isConnectionConsumer;
+   private ClientConsumer clientConsumer;
+   private boolean storingDeliveries;
+   
+   
+
+   
+   
    // Static ---------------------------------------------------------------------------------------
 
    // Constructors ---------------------------------------------------------------------------------
-
    public ClientConsumerDelegate(String objectID, int bufferSize, int maxDeliveries, long redeliveryDelay)
    {
       super(objectID);
@@ -79,30 +96,43 @@
       this.redeliveryDelay = redeliveryDelay;
    }
 
+   public ClientConsumerDelegate(ClientSession session, String objectID, int bufferSize, int maxDeliveries, long redeliveryDelay,
+         Destination dest,
+         String selector, boolean noLocal, String subscriptionName, String consumerID,
+         boolean isCC)
+   {
+      super(objectID);
+      this.session = session;
+      this.bufferSize = bufferSize;
+      this.maxDeliveries = maxDeliveries;
+      this.redeliveryDelay = redeliveryDelay;
+      this.destination = dest;
+      this.selector = selector;
+      this.noLocal = noLocal;
+      this.subscriptionName = subscriptionName;
+      this.consumerID = consumerID;
+      this.isConnectionConsumer = isCC;
+   }
+
    public ClientConsumerDelegate()
    {
    }
 
    // DelegateSupport overrides --------------------------------------------------------------------
 
-   public void synchronizeWith(DelegateSupport nd) throws Exception
+   protected Client getClient()
    {
+      return this.session.getConnection().getClient();
+   }
+   
+   public void synchronizeWith(ClientConsumerDelegate nd) throws Exception
+   {
       log.trace(this + " synchronizing with " + nd);
 
       super.synchronizeWith(nd);
 
       ClientConsumerDelegate newDelegate = (ClientConsumerDelegate)nd;
 
-      // The client needs to be set first
-      client = ((ConnectionState)state.getParent().getParent()).getRemotingConnection().
-      getRemotingClient();
-
-      // synchronize server endpoint state
-
-      // synchronize (recursively) the client-side state
-
-      state.synchronizeWith(newDelegate.getState());
-
       // synchronize the delegates
 
       bufferSize = newDelegate.getBufferSize();
@@ -110,14 +140,6 @@
 
    }
 
-   public void setState(ConsumerState state)
-   {
-      super.setState(state);
-
-      client = ((ConnectionState)state.getParent().getParent()).getRemotingConnection().
-      getRemotingClient();
-   }
-
    // Closeable implementation ---------------------------------------------------------------------
 
    public void close() throws JMSException
@@ -128,7 +150,6 @@
 
    public long closing(long sequence) throws JMSException
    {
-      ConsumerState consumerState = getState();
       try
       {
 
@@ -139,37 +160,33 @@
 
          // First we call close on the ClientConsumer which waits for onMessage invocations
          // to complete and the last delivery to arrive
-         consumerState.getClientConsumer().close(lastDeliveryId);
+         getClientConsumer().close(lastDeliveryId);
 
-         SessionState sessionState = (SessionState) consumerState.getParent();
-         ConnectionState connectionState = (ConnectionState) sessionState.getParent();
+         session.removeCallbackHandler(getClientConsumer());
 
-         sessionState.removeCallbackHandler(consumerState.getClientConsumer());
+         CallbackManager cm = session.getConnection().getRemotingConnection().getCallbackManager();
+         cm.unregisterHandler(getConsumerID());
 
-         CallbackManager cm = connectionState.getRemotingConnection().getCallbackManager();
-         cm.unregisterHandler(consumerState.getConsumerID());
+         PacketDispatcher.client.unregister(getConsumerID());
 
-         PacketDispatcher.client.unregister(consumerState.getConsumerID());
-
          //And then we cancel any messages still in the message callback handler buffer
-         consumerState.getClientConsumer().cancelBuffer();
+         getClientConsumer().cancelBuffer();
 
          return lastDeliveryId;
 
       }
       catch (Exception proxiedException)
       {
-         ConnectionState connectionState = (ConnectionState) (consumerState.getParent().getParent());
          // if MessagingServer is shutdown or
          // if there is no failover in place... we just close the consumerState as well
-         if (proxiedException instanceof MessagingShutdownException ||
-                 (connectionState.getFailoverCommandCenter() == null))
+         if (proxiedException instanceof MessagingShutdownException /* ||
+                 (connectionState.getFailoverCommandCenter() == null ) */ )
 
 
          {
-            if (!consumerState.getClientConsumer().isClosed())
+            if (!getClientConsumer().isClosed())
             {
-               consumerState.getClientConsumer().close(-1);
+               getClientConsumer().close(-1);
             }
          }
          JMSException ex = new JMSException(proxiedException.toString());
@@ -198,7 +215,7 @@
     */
    public MessageListener getMessageListener()
    {
-      return state.getClientConsumer().getMessageListener();
+      return getClientConsumer().getMessageListener();
    }
 
    /**
@@ -207,7 +224,7 @@
     */
    public Message receive(long timeout) throws JMSException
    {
-      return state.getClientConsumer().receive(timeout);
+      return getClientConsumer().receive(timeout);
    }
 
    /**
@@ -216,7 +233,7 @@
     */
    public void setMessageListener(MessageListener listener) throws JMSException
    {
-      state.getClientConsumer().setMessageListener(listener);
+      getClientConsumer().setMessageListener(listener);
    }
 
    /**
@@ -225,7 +242,7 @@
     */
    public boolean getNoLocal()
    {
-      return getState().isNoLocal();
+      return this.noLocal;
    }
 
    /**
@@ -234,7 +251,7 @@
     */
    public Destination getDestination()
    {
-      return state.getDestination();
+      return this.destination;
    }
 
    /**
@@ -243,7 +260,7 @@
     */
    public String getMessageSelector()
    {
-      return state.getSelector();
+      return this.selector;
    }
 
    // Streamable implementation ----------------------------------------------------------
@@ -292,6 +309,63 @@
    	return redeliveryDelay;
    }
 
+   
+
+   public String getSelector()
+   {
+      return selector;
+   }
+
+   public boolean isNoLocal()
+   {
+      return noLocal;
+   }
+
+   public String getConsumerID()
+   {
+      return consumerID;
+   }
+
+   public boolean isConnectionConsumer()
+   {
+      return isConnectionConsumer;
+   }
+
+   public void setClientConsumer(ClientConsumer handler)
+   {
+      this.clientConsumer = handler;
+   }
+
+   public ClientConsumer getClientConsumer()
+   {
+      return clientConsumer;
+   }
+
+   public String getSubscriptionName()
+   {
+      return subscriptionName;
+   }
+
+   public void setSubscriptionName(String subscriptionName)
+   {
+      this.subscriptionName = subscriptionName;
+   }
+
+   public boolean isStoringDeliveries()
+   {
+      return storingDeliveries;
+   }
+   
+   public boolean isShouldAck()
+   {
+      //If e are a non durable subscriber to a topic then there is no need
+      //to send acks to the server - we wouldn't have stored them on the server side anyway
+      
+      return !(destination.getType() == DestinationType.TOPIC && subscriptionName == null);      
+   }
+
+  
+   
    // Protected ------------------------------------------------------------------------------------
 
    // Package Private ------------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -24,6 +24,7 @@
 import java.util.UUID;
 
 import javax.jms.BytesMessage;
+import javax.jms.DeliveryMode;
 import javax.jms.JMSException;
 import javax.jms.MapMessage;
 import javax.jms.Message;
@@ -31,12 +32,9 @@
 import javax.jms.ObjectMessage;
 import javax.jms.StreamMessage;
 import javax.jms.TextMessage;
-
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.ProducerState;
-import org.jboss.jms.client.state.SessionState;
-import org.jboss.jms.delegate.ConnectionDelegate;
-import org.jboss.jms.delegate.ProducerDelegate;
+import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.jms.client.api.ClientProducer;
+import org.jboss.jms.client.api.ClientSession;
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.message.JBossBytesMessage;
 import org.jboss.jms.message.JBossMapMessage;
@@ -44,6 +42,7 @@
 import org.jboss.jms.message.JBossObjectMessage;
 import org.jboss.jms.message.JBossStreamMessage;
 import org.jboss.jms.message.JBossTextMessage;
+import org.jboss.messaging.core.remoting.Client;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.DestinationType;
 import org.jboss.messaging.core.impl.DestinationImpl;
@@ -53,12 +52,13 @@
  *
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
  *
  * @version <tt>$Revision$</tt>
  *
  * $Id$
  */
-public class ClientProducerDelegate extends DelegateSupport<ProducerState> implements ProducerDelegate
+public class ClientProducerDelegate extends CommunicationSupport<ClientProducerDelegate> implements ClientProducer
 {
    // Constants ------------------------------------------------------------------------------------
 
@@ -68,24 +68,47 @@
    // Attributes -----------------------------------------------------------------------------------
 
    private boolean trace = log.isTraceEnabled();
+   
+   private ClientConnection connection;
+   private ClientSession session;
+   private JBossDestination destination;
 
+   private boolean disableMessageID = false;
+   private boolean disableMessageTimestamp = false;
+   private int priority = 4;
+   private long timeToLive = 0;
+   private int deliveryMode = DeliveryMode.PERSISTENT;
+
+   
+
    // Static ---------------------------------------------------------------------------------------
 
    // Constructors ---------------------------------------------------------------------------------
+   
+   
 
    // DelegateSupport overrides --------------------------------------------------------------------
 
-   public void synchronizeWith(DelegateSupport nd) throws Exception
+   public ClientProducerDelegate(ClientConnection connection,
+         ClientSession session, JBossDestination destination)
    {
+      super();
+      this.connection = connection;
+      this.session = session;
+      this.destination = destination;
+   }
+
+   public void synchronizeWith(ClientProducerDelegate nd) throws Exception
+   {
       super.synchronizeWith(nd);
 
-      ClientProducerDelegate newDelegate = (ClientProducerDelegate)nd;
+      /*ClientProducerDelegate newDelegate = (ClientProducerDelegate)nd;
 
       // synchronize server endpoint state
 
       // synchronize (recursively) the client-side state
 
-      state.synchronizeWith(newDelegate.getState());
+      state.synchronizeWith(newDelegate.getState()); */
    }
 
    // ProducerDelegate implementation --------------------------------------------------------------
@@ -110,12 +133,12 @@
 
    public void setDestination(JBossDestination dest)
    {
-      state.setDestination(dest);
+      this.destination = dest;
    }
 
    public JBossDestination getDestination() throws JMSException
    {
-      return (JBossDestination)state.getDestination();
+      return this.destination;
    }
 
    /**
@@ -134,12 +157,10 @@
 
       // configure the message for sending, using attributes stored as metadata
 
-      ProducerState producerState = getState();
-
       if (deliveryMode == -1)
       {
          // Use the delivery mode of the producer
-         deliveryMode = producerState.getDeliveryMode();
+         deliveryMode = getDeliveryMode();
          if (trace) { log.trace("Using producer's default delivery mode: " + deliveryMode); }
       }
       m.setJMSDeliveryMode(deliveryMode);
@@ -147,7 +168,7 @@
       if (priority == -1)
       {
          // Use the priority of the producer
-         priority = producerState.getPriority();
+         priority = getPriority();
          if (trace) { log.trace("Using producer's default priority: " + priority); }
       }
       if (priority < 0 || priority > 9)
@@ -157,7 +178,7 @@
       }
       m.setJMSPriority(priority);
 
-      if (producerState.isDisableMessageTimestamp())
+      if (this.isDisableMessageTimestamp())
       {
          m.setJMSTimestamp(0l);
       }
@@ -169,7 +190,7 @@
       if (timeToLive == Long.MIN_VALUE)
       {
          // Use time to live value from producer
-         timeToLive = producerState.getTimeToLive();
+         timeToLive = getTimeToLive();
          if (trace) { log.trace("Using producer's default timeToLive: " + timeToLive); }
       }
 
@@ -186,7 +207,7 @@
       if (destination == null)
       {
          // use destination from producer
-         destination = (JBossDestination)producerState.getDestination();
+         destination = (JBossDestination)getDestination();
 
          if (destination == null)
          {
@@ -200,8 +221,8 @@
          // if a default destination was already specified then this must be same destination as
          // that specified in the arguments
 
-         if (producerState.getDestination() != null &&
-             !producerState.getDestination().equals(destination))
+         if (getDestination() != null &&
+             !getDestination().equals(destination))
          {
             throw new UnsupportedOperationException("Where a default destination is specified " +
                                                     "for the sender and a destination is " +
@@ -210,11 +231,6 @@
          }
       }
 
-      SessionState sessionState = (SessionState)producerState.getParent();
-
-      // Generate the message id
-      ConnectionState connectionState = (ConnectionState)sessionState.getParent();
-
       JBossMessage jbm;
 
       boolean foreign = false;
@@ -270,7 +286,6 @@
          String id = UUID.randomUUID().toString();
          
          jbm.setJMSMessageID("ID:" + id);
-
       }
 
       if (foreign)
@@ -307,69 +322,60 @@
 
       // we now invoke the send(Message) method on the session, which will eventually be fielded
       // by connection endpoint
-      sessionState.getDelegate().send(messageToSend);
+      session.send(messageToSend);
    }
 
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void send(JBossMessage message) throws JMSException
-   {
-      throw new IllegalStateException("This invocation should not be handled here!");  
-   }
-
    public void setDeliveryMode(int deliveryMode) throws JMSException
    {
-      getState().setDeliveryMode(deliveryMode);
+      this.deliveryMode = deliveryMode;
    }
 
    public int getDeliveryMode() throws JMSException
    {
-      return getState().getDeliveryMode();
+      return this.deliveryMode;
    }
 
    
 
-   public boolean getDisableMessageID() throws JMSException
+   public boolean isDisableMessageID() throws JMSException
    {
-      return getState().isDisableMessageID();
+      return this.disableMessageID;
    }
 
    public void setDisableMessageID(boolean value) throws JMSException
    {
-      getState().setDisableMessageID(value);   
+      this.disableMessageID = value;   
    }
 
-   public boolean getDisableMessageTimestamp() throws JMSException
+   public boolean isDisableMessageTimestamp() throws JMSException
    {
-      return getState().isDisableMessageTimestamp();
+      return this.disableMessageTimestamp;
    }
 
    public void setDisableMessageTimestamp(boolean value) throws JMSException
    {
-      getState().setDisableMessageTimestamp(value);
+      this.disableMessageTimestamp = value;
    }
 
-   public void setPriority(int priotiy) throws JMSException
+   public void setPriority(int priority) throws JMSException
    {
-      state.setPriority(priotiy);
+      this.priority = priority;
    }
 
    public int getPriority() throws JMSException
    {
-      return state.getPriority();
+      return this.priority;
    }
 
    public long getTimeToLive() throws JMSException
    {
-        return state.getTimeToLive();
+        return this.timeToLive;
    }
 
 
    public void setTimeToLive(long timeToLive) throws JMSException
    {
-      state.setTimeToLive(timeToLive);
+      this.timeToLive = timeToLive;
    }
 
    // Public ---------------------------------------------------------------------------------------
@@ -381,6 +387,11 @@
 
    // Protected ------------------------------------------------------------------------------------
    
+
+   protected Client getClient()
+   {
+      return connection.getClient();
+   }
    // Package Private ------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -25,9 +25,13 @@
 import java.io.DataOutputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jms.IllegalStateException;
 import javax.jms.JMSException;
@@ -35,24 +39,19 @@
 import javax.jms.Session;
 import javax.jms.TransactionInProgressException;
 import javax.transaction.xa.XAResource;
-
+import org.jboss.jms.client.Closeable;
+import org.jboss.jms.client.api.ClientBrowser;
+import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.jms.client.api.ClientSession;
+import org.jboss.jms.client.api.Consumer;
+import org.jboss.jms.client.api.ClientProducer;
 import org.jboss.jms.client.container.ClientConsumer;
 import org.jboss.jms.client.remoting.CallbackManager;
 import org.jboss.jms.client.remoting.JMSRemotingConnection;
-import org.jboss.jms.client.state.BrowserState;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.ConsumerState;
-import org.jboss.jms.client.state.ProducerState;
-import org.jboss.jms.client.state.SessionState;
 import org.jboss.jms.delegate.Ack;
-import org.jboss.jms.delegate.BrowserDelegate;
 import org.jboss.jms.delegate.Cancel;
-import org.jboss.jms.delegate.ConnectionDelegate;
-import org.jboss.jms.delegate.ConsumerDelegate;
 import org.jboss.jms.delegate.DefaultCancel;
 import org.jboss.jms.delegate.DeliveryInfo;
-import org.jboss.jms.delegate.ProducerDelegate;
-import org.jboss.jms.delegate.SessionDelegate;
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.destination.JBossQueue;
 import org.jboss.jms.destination.JBossTopic;
@@ -63,11 +62,13 @@
 import org.jboss.jms.message.JBossStreamMessage;
 import org.jboss.jms.message.JBossTextMessage;
 import org.jboss.jms.tx.LocalTx;
+import org.jboss.jms.tx.MessagingXAResource;
 import org.jboss.jms.tx.ResourceManager;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.Destination;
 import org.jboss.messaging.core.DestinationType;
 import org.jboss.messaging.core.Message;
+import org.jboss.messaging.core.remoting.Client;
 import org.jboss.messaging.core.remoting.PacketDispatcher;
 import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveriesMessage;
 import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryRequest;
@@ -87,9 +88,12 @@
 import org.jboss.messaging.core.remoting.wireformat.DeleteTemporaryDestinationMessage;
 import org.jboss.messaging.core.remoting.wireformat.SendMessage;
 import org.jboss.messaging.core.remoting.wireformat.UnsubscribeMessage;
+import org.jboss.messaging.util.ClearableQueuedExecutor;
+import org.jboss.messaging.util.ConcurrentHashSet;
 import org.jboss.messaging.util.MessageQueueNameHelper;
 import org.jboss.messaging.util.ProxyFactory;
 
+import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
 import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
 
 /**
@@ -104,7 +108,7 @@
  *
  * $Id$
  */
-public class ClientSessionDelegate extends DelegateSupport<SessionState> implements SessionDelegate
+public class ClientSessionDelegate extends CommunicationSupport<ClientSessionDelegate> implements ClientSession
 {
    // Constants ------------------------------------------------------------------------------------
 
@@ -119,24 +123,87 @@
    private int dupsOKBatchSize;
    
    private boolean strictTck;
+   
+   private ClientConnection connection;
+   
+   // Attributes that used to live on SessionState -------------------------------------------------
+   
+   protected Set<Closeable> children = new ConcurrentHashSet<Closeable>();
 
+   
+   private int acknowledgeMode;
+   private boolean transacted;
+   private boolean xa;
+
+   private MessagingXAResource xaResource;
+   private Object currentTxId;
+
+   // Executor used for executing onMessage methods
+   private ClearableQueuedExecutor executor;
+
+   private boolean recoverCalled;
+   
+   // List<DeliveryInfo>
+   private List<Ack> clientAckList;
+
+   private DeliveryInfo autoAckInfo;
+   private Map callbackHandlers = new ConcurrentHashMap();
+   
+   private LinkedList asfMessages = new LinkedList();
+   
+   //The distinguished message listener - for ASF
+   private MessageListener sessionListener;
+   
+   //This is somewhat strange - but some of the MQ and TCK tests expect an XA session to behavior as AUTO_ACKNOWLEDGE when not enlisted in
+   //a transaction
+   //This is the opposite behavior as what is required when the XA session handles MDB delivery or when using the message bridge.
+   //In that case we want it to act as transacted, so when the session is subsequently enlisted the work can be converted into the
+   //XA transaction
+   private boolean treatAsNonTransactedWhenNotEnlisted = true;
+   
+   private long npSendSequence;
+   
+   // Constructors ---------------------------------------------------------------------------------
+   
+
    // Static ---------------------------------------------------------------------------------------
 
    // Constructors ---------------------------------------------------------------------------------
 
-   public ClientSessionDelegate(String objectID, int dupsOKBatchSize)
+   public ClientSessionDelegate(ClientConnection connection, String objectID, int dupsOKBatchSize)
    {
       super(objectID);
-
+      this.connection = connection;
       this.dupsOKBatchSize = dupsOKBatchSize;
    }
    
-   public ClientSessionDelegate(String objectID, int dupsOKBatchSize, boolean strictTCK)
+   public ClientSessionDelegate(ClientConnectionDelegate connection, String objectID, int dupsOKBatchSize, boolean strictTCK,
+         boolean transacted, int acknowledgmentMode, boolean xa)
    {
       super(objectID);
 
+      this.connection = connection;
       this.dupsOKBatchSize = dupsOKBatchSize;
       this.strictTck = strictTCK;
+      this.transacted = transacted;
+      this.xa = xa;
+      this.acknowledgeMode = acknowledgmentMode;
+      executor = new ClearableQueuedExecutor(new LinkedQueue());
+      
+      if (xa)
+      {
+         // Create an XA resource
+         xaResource = new MessagingXAResource(connection.getResourceManager(), this);
+      }
+
+      
+      if (transacted)
+      {
+         // Create a local tx
+         currentTxId = connection.getResourceManager().createLocalTx();
+      }
+      
+      clientAckList = new ArrayList();
    }
 
    public ClientSessionDelegate()
@@ -145,65 +212,51 @@
 
    // DelegateSupport overrides --------------------------------------------------------------------
 
-   public void synchronizeWith(DelegateSupport nd) throws Exception
+   
+   public void synchronizeWith(ClientSessionDelegate nd) throws Exception
    {
       log.trace(this + " synchronizing with " + nd);
 
       super.synchronizeWith(nd);
 
-      DelegateSupport newDelegate = (DelegateSupport)nd;
-
-      // synchronize server endpoint state
-
-      // synchronize (recursively) the client-side state
-
-      state.synchronizeWith(newDelegate.getState());
-      
-      JMSRemotingConnection conn = ((ConnectionState)state.getParent()).getRemotingConnection();
-      
-      client = conn.getRemotingClient();
-      
-      strictTck = conn.isStrictTck();
    }
 
-   public void setState(SessionState state)
-   {
-      super.setState(state);
-      
-      JMSRemotingConnection conn = ((ConnectionState)state.getParent()).getRemotingConnection();
-      
-      client = conn.getRemotingClient();
-      
-      strictTck = conn.isStrictTck();
-   }
-
    // Closeable implementation ---------------------------------------------------------------------
 
    public void close() throws JMSException
    {
       sendBlocking(new CloseMessage());
 
-      Object xid = state.getCurrentTxId();
+      Object xid = getCurrentTxId();
 
       if (xid != null)
       {
          //Remove transaction from the resource manager
-         getState().getParent().getResourceManager().removeTx(xid);
+         connection.getResourceManager().removeTx(xid);
       }
 
       // We must explicitly shutdown the executor
 
-      state.getExecutor().shutdownNow();
+      getExecutor().shutdownNow();
 
    }
 
    private long invokeClosing(long sequence) throws JMSException
    {   	   
-      long seq = ((SessionState)state).getNPSendSequence();
+      long seq = getNPSendSequence();
       ClosingRequest request = new ClosingRequest(seq);
       ClosingResponse response = (ClosingResponse) sendBlocking(request);
       return response.getID();
    }
+   
+   private void closeChildren() throws JMSException
+   {
+      for (Closeable child: children)
+      {
+         child.closing(-1);
+         child.close();
+      }
+   }
 
    public long closing(long sequence) throws JMSException
    {
@@ -212,14 +265,12 @@
       closeChildren();
       
       //Sanity check
-      if (state.isXA() && !isXAAndConsideredNonTransacted(state))
+      if (isXA() && !isXAAndConsideredNonTransacted())
       {
          if (trace) { log.trace("Session is XA"); }
 
-         ConnectionState connState = (ConnectionState)state.getParent();
+         ResourceManager rm = connection.getResourceManager();
 
-         ResourceManager rm = connState.getResourceManager();
-
          // An XASession should never be closed if there is prepared ack work that has not yet been
          // committed or rolled back. Imagine if messages had been consumed in the session, and
          // prepared but not committed. Then the connection was explicitly closed causing the
@@ -229,24 +280,24 @@
          // and the original transaction is committed, then this means the same message has been
          // delivered twice which breaks the once and only once delivery guarantee.
 
-         if (rm.checkForAcksInSession(state.getSessionID()))
+         if (rm.checkForAcksInSession(this.getID()))
          {
             throw new javax.jms.IllegalStateException(
                "Attempt to close an XASession when there are still uncommitted acknowledgements!");
          }
       }
 
-      int ackMode = state.getAcknowledgeMode();
+      int ackMode = getAcknowledgeMode();
 
       //We need to either ack (for auto_ack) or cancel (for client_ack)
       //any deliveries - this is because the message listener might have closed
       //before on message had finished executing
 
-      if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted(state))
+      if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
       {
          //Acknowledge or cancel any outstanding auto ack
 
-         DeliveryInfo remainingAutoAck = state.getAutoAckInfo();
+         DeliveryInfo remainingAutoAck = getAutoAckInfo();
 
          if (remainingAutoAck != null)
          {
@@ -260,7 +311,7 @@
             }
             finally
             {
-               state.setAutoAckInfo(null);
+               setAutoAckInfo(null);
             }
          }
       }
@@ -268,17 +319,17 @@
       {
          //Ack any remaining deliveries
 
-         if (!state.getClientAckList().isEmpty())
+         if (!getClientAckList().isEmpty())
          {
             try
             {
-               acknowledgeDeliveries(state.getClientAckList());
+               acknowledgeDeliveries(getClientAckList());
             }
             finally
             {
-               state.getClientAckList().clear();
+               getClientAckList().clear();
 
-               state.setAutoAckInfo(null);
+               setAutoAckInfo(null);
             }
          }
       }
@@ -292,21 +343,17 @@
          // CLIENT_ACKNOWLEDGE cannot be used with MDBs (i.e. no connection consumer)
          // so is always safe to cancel on this session
 
-         internalCancelDeliveries(state.getClientAckList());
+         internalCancelDeliveries(getClientAckList());
 
-         state.getClientAckList().clear();
+         getClientAckList().clear();
       }
-      else if (state.isTransacted() && !state.isXA())
+      else if (isTransacted() && !isXA())
       {
          //We need to explicitly cancel any deliveries back to the server
          //from the resource manager, otherwise delivery count won't be updated
 
-         ConnectionState connState = (ConnectionState)state.getParent();
+         List dels = connection.getResourceManager().getDeliveriesForSession(this.getID());
 
-         ResourceManager rm = connState.getResourceManager();
-
-         List dels = rm.getDeliveriesForSession(state.getSessionID());
-
          internalCancelDeliveries(dels);
       }
 
@@ -316,6 +363,17 @@
 
    // SessionDelegate implementation ---------------------------------------------------------------
 
+   public ClientConnection getConnection()
+   {
+      return connection;
+   }
+
+   public void setConnection(ClientConnection connection)
+   {
+      this.connection = connection;
+   }
+
+   
    public boolean acknowledgeDelivery(Ack ack) throws JMSException
    {
       AcknowledgeDeliveryRequest request = new AcknowledgeDeliveryRequest(ack.getDeliveryID());
@@ -335,13 +393,13 @@
     */
    public void acknowledgeAll() throws JMSException
    {
-      if (!state.getClientAckList().isEmpty())
+      if (!getClientAckList().isEmpty())
       {
          //CLIENT_ACKNOWLEDGE can't be used with a MDB so it is safe to always acknowledge all
          //on this session (rather than the connection consumer session)
-         acknowledgeDeliveries(state.getClientAckList());
+         acknowledgeDeliveries(getClientAckList());
 
-         state.getClientAckList().clear();
+         getClientAckList().clear();
       }
    }
 
@@ -352,54 +410,37 @@
 
    public void commit() throws JMSException
    {
-      if (!state.isTransacted())
+      if (!isTransacted())
       {
          throw new IllegalStateException("Cannot commit a non-transacted session");
       }
 
-      if (state.isXA())
+      if (isXA())
       {
          throw new TransactionInProgressException("Cannot call commit on an XA session");
       }
 
-      ConnectionState connState = (ConnectionState)state.getParent();
-      ConnectionDelegate conn = (ConnectionDelegate)connState.getDelegate();
-
       try
       {
-         connState.getResourceManager().commitLocal((LocalTx)state.getCurrentTxId(), conn);
+         connection.getResourceManager().commitLocal((LocalTx)getCurrentTxId(), connection);
       }
       finally
       {
          //Start new local tx
-         Object xid = connState.getResourceManager().createLocalTx();
-
-         state.setCurrentTxId(xid);
+         setCurrentTxId( connection.getResourceManager().createLocalTx() );
       }
 
    }
 
 
-   public BrowserState createBrowserState(ClientBrowserDelegate browserDelegate, BrowserDelegate proxyDelegate,
-         Destination destination, String selector )
-   {
-
-      SessionState sessionState = getState();
-
-      BrowserState state =
-         new BrowserState(sessionState, browserDelegate, proxyDelegate, destination, selector);
-
-      return state;
-   }
-
-   public BrowserDelegate createBrowserDelegate(Destination queue, String messageSelector)
+   public ClientBrowser createBrowserDelegate(Destination queue, String messageSelector)
       throws JMSException
    {
       CreateBrowserRequest request = new CreateBrowserRequest(queue, messageSelector);
       CreateBrowserResponse response = (CreateBrowserResponse) sendBlocking(request);
-      ClientBrowserDelegate delegate = new ClientBrowserDelegate(response.getBrowserID());
-      BrowserDelegate proxy = (BrowserDelegate)ProxyFactory.proxy(delegate, BrowserDelegate.class);
-      delegate.setState(createBrowserState(delegate, proxy,  queue, messageSelector));
+      ClientBrowserDelegate delegate = new ClientBrowserDelegate(this, response.getBrowserID(), queue, messageSelector);
+      ClientBrowser proxy = (ClientBrowser)ProxyFactory.proxy(delegate, ClientBrowser.class);
+      children.add(proxy);
       return proxy;
    }
 
@@ -414,30 +455,7 @@
    }
 
 
-   private ConsumerState createConsumerState(ClientConsumerDelegate consumerDelegate,ConsumerDelegate proxyDelegate, Destination dest,
-                                             String selector, boolean noLocal, String subscriptionName,
-                                             boolean connectionConsumer )
-   {
-
-      SessionState sessionState = state;
-
-      String consumerID = consumerDelegate.getID();
-      int bufferSize = consumerDelegate.getBufferSize();
-      int maxDeliveries = consumerDelegate.getMaxDeliveries();
-      long redeliveryDelay = consumerDelegate.getRedeliveryDelay();
-
-      ConsumerState consumerState =
-         new ConsumerState(sessionState, consumerDelegate, proxyDelegate, dest, selector, noLocal,
-                           subscriptionName, consumerID, connectionConsumer, bufferSize,
-                           maxDeliveries, redeliveryDelay);
-
-      return consumerState;
-   }
-
-
-
-
-   public ConsumerDelegate createConsumerDelegate(Destination destination, String selector,
+   public Consumer createConsumerDelegate(Destination destination, String selector,
                                                   boolean noLocal, String subscriptionName,
                                                   boolean isCC) throws JMSException
    {
@@ -447,25 +465,17 @@
       
       CreateConsumerResponse response = (CreateConsumerResponse) sendBlocking(request);
 
-      ClientConsumerDelegate consumerDelegate = new ClientConsumerDelegate(response.getConsumerID(), response.getBufferSize(), response.getMaxDeliveries(), response.getRedeliveryDelay());
+      ClientConsumerDelegate consumerDelegate = new ClientConsumerDelegate(this, response.getConsumerID(), response.getBufferSize(), response.getMaxDeliveries(), response.getRedeliveryDelay(),
+            destination,
+            selector, noLocal, subscriptionName, response.getConsumerID(),isCC);      
 
-      ConsumerDelegate proxy = (ConsumerDelegate)ProxyFactory.proxy(consumerDelegate, ConsumerDelegate.class);
-      consumerDelegate.setState(createConsumerState(consumerDelegate, proxy, destination, selector, noLocal, subscriptionName, isCC));
+      Consumer proxy = (Consumer)ProxyFactory.proxy(consumerDelegate, Consumer.class);
+      
+      children.add(proxy);
 
-      // Create the message handler
-      SessionState sessionState = this.getState();
-      ConnectionState connectionState = sessionState.getParent();
-      SessionDelegate sessionDelegate = this;
-      ConsumerState consumerState = consumerDelegate.getState();
-      final String consumerID = consumerState.getConsumerID();
-      int prefetchSize = consumerState.getBufferSize();
-      QueuedExecutor sessionExecutor = sessionState.getExecutor();
-      int maxDeliveries = consumerState.getMaxDeliveries();
-      long redeliveryDelay = consumerState.getRedeliveryDelay();
-
       //We need the queue name for recovering any deliveries after failover
       String queueName = null;
-      if (consumerState.getSubscriptionName() != null)
+      if (subscriptionName != null)
       {
          // I have to use the clientID from connectionDelegate instead of connectionState...
          // this is because when a pre configured CF is used we need to get the clientID from
@@ -473,28 +483,27 @@
          // This was a condition verified by the TCK and it was fixed as part of
          // http://jira.jboss.com/jira/browse/JBMESSAGING-939
          queueName = MessageQueueNameHelper.
-            createSubscriptionName(((ConnectionDelegate)connectionState.getDelegate()).getClientID(),
-                                   consumerState.getSubscriptionName());
+            createSubscriptionName(this.getID(),subscriptionName);
       }
-      else if (consumerState.getDestination().getType() == DestinationType.QUEUE);
+      else if (destination.getType() == DestinationType.QUEUE)
       {
-         queueName = consumerState.getDestination().getName();
+         queueName = destination.getName();
       }
 
       final ClientConsumer messageHandler =
-         new ClientConsumer(isCC, sessionState.getAcknowledgeMode(),
-                            sessionDelegate, consumerDelegate, consumerID, queueName,
-                            prefetchSize, sessionExecutor, maxDeliveries, consumerState.isShouldAck(),
-                            redeliveryDelay);
+         new ClientConsumer(isCC, this.getAcknowledgeMode(),
+                            this, consumerDelegate, consumerDelegate.getID(), queueName,
+                            consumerDelegate.getBufferSize(), this.getExecutor(), consumerDelegate.getMaxDeliveries(), consumerDelegate.isShouldAck(),
+                            consumerDelegate.getRedeliveryDelay());
 
-      sessionState.addCallbackHandler(messageHandler);
+      this.addCallbackHandler(messageHandler);
 
-      PacketDispatcher.client.register(new ClientConsumerPacketHandler(messageHandler, consumerID));
+      PacketDispatcher.client.register(new ClientConsumerPacketHandler(messageHandler, consumerDelegate.getID()));
 
-      CallbackManager cm = connectionState.getRemotingConnection().getCallbackManager();
-      cm.registerHandler(consumerID, messageHandler);
+      CallbackManager cm = connection.getRemotingConnection().getCallbackManager();
+      cm.registerHandler(consumerDelegate.getID(), messageHandler);
 
-      consumerState.setClientConsumer(messageHandler);
+      consumerDelegate.setClientConsumer(messageHandler);
 
       //Now we have finished creating the client consumer, we can tell the SCD
       //we are ready
@@ -549,16 +558,13 @@
     * This invocation should either be handled by the client-side interceptor chain or by the
     * server-side endpoint.
     */
-   public ProducerDelegate createProducerDelegate(JBossDestination destination) throws JMSException
+   public ClientProducer createProducerDelegate(JBossDestination destination) throws JMSException
    {
       // ProducerDelegates are not created on the server
 
-      ClientProducerDelegate producerDelegate = new ClientProducerDelegate();
-      ProducerDelegate proxy = (ProducerDelegate) ProxyFactory.proxy(producerDelegate, ProducerDelegate.class);
-      ProducerState producerState = new ProducerState(this.getState(), producerDelegate, proxy, destination);
-
-      producerDelegate.setState(producerState);
-
+      ClientProducerDelegate producerDelegate = new ClientProducerDelegate(connection, this, destination );
+      ClientProducer proxy = (ClientProducer) ProxyFactory.proxy(producerDelegate, ClientProducer.class);
+      children.add(proxy);
       return proxy;
    }
 
@@ -606,20 +612,20 @@
     */
    public boolean postDeliver() throws JMSException
    {
-      int ackMode = state.getAcknowledgeMode();
+      int ackMode = getAcknowledgeMode();
 
       boolean res = true;
 
       // if XA and there is no transaction enlisted on XA we will act as AutoAcknowledge
       // However if it's a MDB (if there is a DistinguishedListener) we should behaved as transacted
-      if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted(state))
+      if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
       {
          // It is possible that session.recover() is called inside a message listener onMessage
          // method - i.e. between the invocations of preDeliver and postDeliver. In this case we
          // don't want to acknowledge the last delivered messages - since it will be redelivered.
-         if (!state.isRecoverCalled())
+         if (!isRecoverCalled())
          {
-            DeliveryInfo delivery = state.getAutoAckInfo();
+            DeliveryInfo delivery = getAutoAckInfo();
 
             if (delivery == null)
             {
@@ -641,23 +647,23 @@
             }
             finally
             {
-               state.setAutoAckInfo(null);
+               setAutoAckInfo(null);
             }
          }
          else
          {
             if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }
 
-            state.setRecoverCalled(false);
+            setRecoverCalled(false);
          }
       }
       else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
       {
-         List acks = state.getClientAckList();
+         List acks = getClientAckList();
 
-         if (!state.isRecoverCalled())
+         if (!isRecoverCalled())
          {
-            if (acks.size() >= state.getDupsOKBatchSize())
+            if (acks.size() >= getDupsOKBatchSize())
             {
                // We clear the state in a finally
                // http://jira.jboss.org/jira/browse/JBMESSAGING-852
@@ -669,7 +675,7 @@
                finally
                {
                   acks.clear();
-                  state.setAutoAckInfo(null);
+                  setAutoAckInfo(null);
                }
             }
          }
@@ -677,9 +683,9 @@
          {
             if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }
 
-            state.setRecoverCalled(false);
+            setRecoverCalled(false);
          }
-         state.setAutoAckInfo(null);
+         setAutoAckInfo(null);
       }
 
       return Boolean.valueOf(res);
@@ -691,7 +697,7 @@
     */
    public void preDeliver(DeliveryInfo info) throws JMSException
    {
-      int ackMode = state.getAcknowledgeMode();
+      int ackMode = getAcknowledgeMode();
 
       if (ackMode == Session.CLIENT_ACKNOWLEDGE)
       {
@@ -706,30 +712,30 @@
                "CLIENT_ACKNOWLEDGE cannot be used with a connection consumer");
          }
 
-         state.getClientAckList().add(info);
+         getClientAckList().add(info);
       }
       // if XA and there is no transaction enlisted on XA we will act as AutoAcknowledge
       // However if it's a MDB (if there is a DistinguishedListener) we should behaved as transacted
-      else if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted(state))
+      else if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
       {
          // We collect the single acknowledgement in the state.
 
          if (trace) { log.trace(this + " added " + info + " to session state"); }
 
-         state.setAutoAckInfo(info);
+         setAutoAckInfo(info);
       }
       else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
       {
          if (trace) { log.trace(this + " added to DUPS_OK_ACKNOWLEDGE list delivery " + info); }
 
-         state.getClientAckList().add(info);
+         getClientAckList().add(info);
 
          //Also set here - this would be used for recovery in a message listener
-         state.setAutoAckInfo(info);
+         setAutoAckInfo(info);
       }
       else
       {
-         Object txID = state.getCurrentTxId();
+         Object txID = getCurrentTxId();
 
          if (txID != null)
          {
@@ -737,8 +743,6 @@
             // XA session that has not been enrolled in a global transaction behaves as a
             // transacted session.
 
-            ConnectionState connState = (ConnectionState)state.getParent();
-
             if (trace) { log.trace("sending acknowlegment transactionally, queueing on resource manager"); }
 
             // If the ack is for a delivery that came through via a connection consumer then we use
@@ -746,15 +750,13 @@
             // session ID
 
 
-            //TODO: This shouldn't be using the ProxyFactory, and the ID should be exposed through the interface
+            ClientSession connectionConsumerDelegate =
+               info.getConnectionConsumerSession();
 
-            ClientSessionDelegate connectionConsumerDelegate =
-               (ClientSessionDelegate)ProxyFactory.getDelegate(info.getConnectionConsumerSession());
-
             String sessionId = connectionConsumerDelegate != null ?
-               connectionConsumerDelegate.getID() : state.getSessionID();
+               connectionConsumerDelegate.getID() : this.getID();
 
-            connState.getResourceManager().addAck(txID, sessionId, info);
+            connection.getResourceManager().addAck(txID, sessionId, info);
          }
       }
    }
@@ -767,28 +769,28 @@
    {
       if (trace) { log.trace("recover called"); }
 
-      if (state.isTransacted() && !isXAAndConsideredNonTransacted(state))
+      if (isTransacted() && !isXAAndConsideredNonTransacted())
       {
          throw new IllegalStateException("Cannot recover a transacted session");
       }
 
       if (trace) { log.trace("recovering the session"); }
 
-      int ackMode = state.getAcknowledgeMode();
+      int ackMode = getAcknowledgeMode();
 
       if (ackMode == Session.CLIENT_ACKNOWLEDGE)
       {
-         List dels = state.getClientAckList();
+         List dels = getClientAckList();
 
-         state.setClientAckList(new ArrayList());
+         setClientAckList(new ArrayList());
 
          redeliver(dels);
 
-         state.setRecoverCalled(true);
+         setRecoverCalled(true);
       }
-      else if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE || isXAAndConsideredNonTransacted(state))
+      else if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
       {
-         DeliveryInfo info = state.getAutoAckInfo();
+         DeliveryInfo info = getAutoAckInfo();
 
          //Don't recover if it's already to cancel
 
@@ -800,9 +802,9 @@
 
             redeliver(redels);
 
-            state.setAutoAckInfo(null);
+            setAutoAckInfo(null);
 
-            state.setRecoverCalled(true);
+            setRecoverCalled(true);
          }
       }
    }
@@ -849,7 +851,7 @@
          DeliveryInfo info = (DeliveryInfo)toRedeliver.get(i);
          JBossMessage msg = info.getMessage();
 
-         ClientConsumer handler = state.getCallbackHandler(info.getConsumerId());
+         ClientConsumer handler = getCallbackHandler(info.getConsumerId());
 
          if (handler == null)
          {
@@ -872,34 +874,50 @@
       }
 
    }
+   
+   public ClientConsumer getCallbackHandler(String consumerID)
+   {
+      return (ClientConsumer)callbackHandlers.get(consumerID);
+   }
 
+   public void addCallbackHandler(ClientConsumer handler)
+   {
+      callbackHandlers.put(handler.getConsumerId(), handler);
+   }
+
+   public void removeCallbackHandler(ClientConsumer handler)
+   {
+      callbackHandlers.remove(handler.getConsumerId());
+   }
+
+   
+
    /**
     * This invocation should either be handled by the client-side interceptor chain or by the
     * server-side endpoint.
     */
    public void rollback() throws JMSException
    {
-      if (!state.isTransacted())
+      if (!isTransacted())
       {
          throw new IllegalStateException("Cannot rollback a non-transacted session");
       }
 
-      if (state.isXA())
+      if (isXA())
       {
          throw new TransactionInProgressException("Cannot call rollback on an XA session");
       }
 
-      ConnectionState connState = (ConnectionState)state.getParent();
-      ResourceManager rm = connState.getResourceManager();
+      ResourceManager rm = connection.getResourceManager();
       try
       {
-         rm.rollbackLocal(state.getCurrentTxId());
+         rm.rollbackLocal(getCurrentTxId());
       }
       finally
       {
          // startnew local tx
          Object xid = rm.createLocalTx();
-         state.setCurrentTxId(xid);
+         setCurrentTxId(xid);
       }
    }
 
@@ -911,9 +929,9 @@
    {
       if (trace) { log.trace("run()"); }
 
-      int ackMode = state.getAcknowledgeMode();
+      int ackMode = getAcknowledgeMode();
 
-      LinkedList msgs = state.getASFMessages();
+      LinkedList msgs = getAsfMessages();
 
       while (msgs.size() > 0)
       {
@@ -921,7 +939,7 @@
 
          if (trace) { log.trace("sending " + holder.msg + " to the message listener" ); }
 
-         ClientConsumer.callOnMessage(this, state.getDistinguishedListener(), holder.consumerID,
+         ClientConsumer.callOnMessage(this, getDistinguishedListener(), holder.consumerID,
                                               holder.queueName, false,
                                               holder.msg, ackMode, holder.maxDeliveries,
                                               holder.connectionConsumerDelegate, holder.shouldAck);
@@ -941,7 +959,7 @@
          throw new IllegalStateException("Cannot set a null MessageListener on the session");
       }
 
-      getState().setDistinguishedListener(listener);
+      setDistinguishedListener(listener);
    }
 
    /**
@@ -952,7 +970,7 @@
    {
       if (trace) { log.trace("getMessageListener()"); }
 
-      return getState().getDistinguishedListener();
+      return getDistinguishedListener();
    }
 
    
@@ -968,7 +986,7 @@
     */
    public XAResource getXAResource()
    {
-      return state.getXAResource();
+      return xaResource;
    }
 
    /**
@@ -977,24 +995,15 @@
     */
    public int getAcknowledgeMode()
    {
-      return state.getAcknowledgeMode();
+      return acknowledgeMode;
    }
 
    /**
     * This invocation should either be handled by the client-side interceptor chain or by the
     * server-side endpoint.
     */
-   public boolean getTransacted()
-   {
-      return getState().isTransacted();
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
    public void addAsfMessage(JBossMessage m, String theConsumerID, String queueName, int maxDeliveries,
-                             SessionDelegate connectionConsumerDelegate, boolean shouldAck) throws JMSException
+                             ClientSession connectionConsumerDelegate, boolean shouldAck) throws JMSException
    {
       // Load the session with a message to be processed during a subsequent call to run()
 
@@ -1011,30 +1020,28 @@
       holder.connectionConsumerDelegate = connectionConsumerDelegate;
       holder.shouldAck = shouldAck;
 
-      getState().getASFMessages().add(holder);
+      getAsfMessages().add(holder);
    }
 
    public void send(Message m) throws JMSException
    {
-      Object txID = state.getCurrentTxId();
+      Object txID = getCurrentTxId();
 
       // If there is no GlobalTransaction we run it as local transacted
       // as discussed at http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577
       // http://jira.jboss.org/jira/browse/JBMESSAGING-946
       // and
       // http://jira.jboss.org/jira/browse/JBMESSAGING-410
-      if ((!state.isXA() && state.isTransacted()) || (state.isXA() && !(txID instanceof LocalTx)))
+      if ((!isXA() && isTransacted()) || (isXA() && !(txID instanceof LocalTx)))
       {
          // the session is non-XA and transacted, or XA and enrolled in a global transaction, so
          // we add the message to a transaction instead of sending it now. An XA session that has
          // not been enrolled in a global transaction behaves as a non-transacted session.
 
-         ConnectionState connState = state.getParent();
+         if (trace) { log.trace("sending message " + m + " transactionally, queueing on resource manager txID=" + txID + " sessionID= " + getID()); }
 
-         if (trace) { log.trace("sending message " + m + " transactionally, queueing on resource manager txID=" + txID + " sessionID= " + state.getSessionID()); }
+         connection.getResourceManager().addMessage(txID, this.getID(), m);
 
-         connState.getResourceManager().addMessage(txID, state.getSessionID(), m);
-
          // ... and we don't invoke any further interceptors in the stack
          return;
       }
@@ -1055,11 +1062,9 @@
    	}
    	else
    	{
-   		SessionState sstate = (SessionState)state;
+   		seq = this.getNPSendSequence();
    		
-   		seq = sstate.getNPSendSequence();
-   		
-   		sstate.incNpSendSequence();
+   		this.incNpSendSequence();
    	}
    	
    	SendMessage message = new SendMessage(m, seq);
@@ -1074,7 +1079,7 @@
    	}
    }
 
-   public void cancelDeliveries(List cancels) throws JMSException
+   public void cancelDeliveries(List<Cancel> cancels) throws JMSException
    {
       sendBlocking(new CancelDeliveriesMessage(cancels));
    }
@@ -1119,6 +1124,10 @@
 
    // Protected ------------------------------------------------------------------------------------
 
+   protected Client getClient()
+   {
+      return connection.getClient();
+   }
    // Package Private ------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------
@@ -1138,10 +1147,10 @@
     *    integration tests and TCK!!! Hence getTreatAsNonTransactedWhenNotEnlisted()
     *
     * */
-   private boolean isXAAndConsideredNonTransacted(SessionState state)
+   private boolean isXAAndConsideredNonTransacted()
    {
-      return state.isXA() && (state.getCurrentTxId() instanceof LocalTx) && state.getTreatAsNonTransactedWhenNotEnlisted()
-             && state.getDistinguishedListener() == null;
+      return isXA() && (getCurrentTxId() instanceof LocalTx) && getTreatAsNonTransactedWhenNotEnlisted()
+             && getDistinguishedListener() == null;
    }
 
 
@@ -1149,12 +1158,12 @@
    {
    	if (delivery.isShouldAck())
    	{
-	      SessionDelegate connectionConsumerSession = delivery.getConnectionConsumerSession();
+	      ClientSession connectionConsumerSession = delivery.getConnectionConsumerSession();
 
 	      //If the delivery was obtained via a connection consumer we need to ack via that
 	      //otherwise we just use this session
 
-	      SessionDelegate sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
+	      ClientSession sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
 
 	      return sessionToUse.acknowledgeDelivery(delivery);
    	}
@@ -1168,12 +1177,12 @@
    {
    	if (delivery.isShouldAck())
    	{
-	      SessionDelegate connectionConsumerSession = delivery.getConnectionConsumerSession();
+   	   ClientSession connectionConsumerSession = delivery.getConnectionConsumerSession();
 
 	      //If the delivery was obtained via a connection consumer we need to cancel via that
 	      //otherwise we just use this session
 
-	      SessionDelegate sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
+   	   ClientSession sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
 
 	      sessionToUse.cancelDelivery(new DefaultCancel(delivery.getDeliveryID(),
 	                                  delivery.getMessage().getDeliveryCount(), false, false));
@@ -1204,7 +1213,7 @@
       }
    }
 
-   private void acknowledgeDeliveries(SessionDelegate del, List deliveryInfos) throws JMSException
+   private void acknowledgeDeliveries(ClientSession del, List deliveryInfos) throws JMSException
    {
       List acks = new ArrayList();
 
@@ -1233,8 +1242,171 @@
       private String consumerID;
       private String queueName;
       private int maxDeliveries;
-      private SessionDelegate connectionConsumerDelegate;
+      private ClientSession connectionConsumerDelegate;
       private boolean shouldAck;
    }
 
+   
+   // TODO verify what should be exposed or not!
+   public boolean isXA()
+   {
+      return xa;
+   }
+
+   public void setXA(boolean xa)
+   {
+      this.xa = xa;
+   }
+
+   public Object getCurrentTxId()
+   {
+      return currentTxId;
+   }
+
+   public void setCurrentTxId(Object currentTxId)
+   {
+      this.currentTxId = currentTxId;
+   }
+
+   public boolean isRecoverCalled()
+   {
+      return recoverCalled;
+   }
+
+   public void setRecoverCalled(boolean recoverCalled)
+   {
+      this.recoverCalled = recoverCalled;
+   }
+
+   public List<Ack> getClientAckList()
+   {
+      return clientAckList;
+   }
+
+   public void setClientAckList(List<Ack> clientAckList)
+   {
+      this.clientAckList = clientAckList;
+   }
+
+   public DeliveryInfo getAutoAckInfo()
+   {
+      return autoAckInfo;
+   }
+
+   public void setAutoAckInfo(DeliveryInfo autoAckInfo)
+   {
+      this.autoAckInfo = autoAckInfo;
+   }
+
+   public Map getCallbackHandlers()
+   {
+      return callbackHandlers;
+   }
+
+   public void setCallbackHandlers(Map callbackHandlers)
+   {
+      this.callbackHandlers = callbackHandlers;
+   }
+
+   public LinkedList getAsfMessages()
+   {
+      return asfMessages;
+   }
+
+   public void setAsfMessages(LinkedList asfMessages)
+   {
+      this.asfMessages = asfMessages;
+   }
+
+   public MessageListener getSessionListener()
+   {
+      return sessionListener;
+   }
+
+   public void setSessionListener(MessageListener sessionListener)
+   {
+      this.sessionListener = sessionListener;
+   }
+
+   public boolean isTreatAsNonTransactedWhenNotEnlisted()
+   {
+      return treatAsNonTransactedWhenNotEnlisted;
+   }
+
+   public void setTreatAsNonTransactedWhenNotEnlisted(
+         boolean treatAsNonTransactedWhenNotEnlisted)
+   {
+      this.treatAsNonTransactedWhenNotEnlisted = treatAsNonTransactedWhenNotEnlisted;
+   }
+
+   public long getNpSendSequence()
+   {
+      return npSendSequence;
+   }
+
+   public void setNpSendSequence(long npSendSequence)
+   {
+      this.npSendSequence = npSendSequence;
+   }
+
+   public ClearableQueuedExecutor getExecutor()
+   {
+      return executor;
+   }
+
+   public void setDupsOKBatchSize(int dupsOKBatchSize)
+   {
+      this.dupsOKBatchSize = dupsOKBatchSize;
+   }
+
+   public void setStrictTck(boolean strictTck)
+   {
+      this.strictTck = strictTck;
+   }
+
+   public void setAcknowledgeMode(int acknowledgeMode)
+   {
+      this.acknowledgeMode = acknowledgeMode;
+   }
+   
+   public boolean isTransacted()
+   {
+      return transacted;
+   }
+
+   
+
+   
+   public void setTransacted(boolean transacted)
+   {
+      this.transacted = transacted;
+   }
+
+   public long getNPSendSequence()
+   {
+      return npSendSequence;
+   }
+   
+   public void incNpSendSequence()
+   {
+      npSendSequence++;
+   }
+   
+   public boolean getTreatAsNonTransactedWhenNotEnlisted()
+   {
+      return treatAsNonTransactedWhenNotEnlisted;
+   }
+   
+
+   public MessageListener getDistinguishedListener()
+   {
+      return this.sessionListener;
+   }
+   
+   public void setDistinguishedListener(MessageListener listener)
+   {
+      this.sessionListener = listener;
+   }
+   
+
 }

Added: trunk/src/main/org/jboss/jms/client/delegate/CommunicationSupport.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/CommunicationSupport.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/delegate/CommunicationSupport.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -0,0 +1,214 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.jms.client.delegate;
+
+import static org.jboss.messaging.core.remoting.Assert.assertValidID;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+
+import org.jboss.jms.exception.MessagingJMSException;
+import org.jboss.jms.exception.MessagingNetworkFailureException;
+import org.jboss.logging.Logger;
+import org.jboss.messaging.core.remoting.Client;
+import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
+import org.jboss.messaging.core.remoting.wireformat.JMSExceptionMessage;
+import org.jboss.messaging.util.Streamable;
+import org.jgroups.persistence.CannotConnectException;
+
+/**
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * // TODO find a better name for this class
+ */
+public abstract class CommunicationSupport <T extends CommunicationSupport<?>> implements Streamable, Serializable 
+{
+   private static final Logger log = Logger.getLogger(CommunicationSupport.class);
+
+   private static boolean trace = log.isTraceEnabled();
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   // This is set on the server.
+   protected String id;
+   
+   // TODO move this to Client class
+   protected byte version;
+
+   public CommunicationSupport(String id)
+   {
+      super();
+      this.id = id;
+   }
+
+   public CommunicationSupport()
+   {
+      this("NO_ID_SET");
+   }
+   
+   
+   
+   // Streamable implementation --------------------------------------------------------------------
+
+   public void read(DataInputStream in) throws Exception
+   {
+      id = in.readUTF();
+   }
+
+   public void write(DataOutputStream out) throws Exception
+   {
+      out.writeUTF(id);
+   }
+   
+   // Fields ---------------------------------------------------------------------------------------
+
+   protected abstract Client getClient();
+   
+   public String getID()
+   {
+      return id;
+   }
+
+   public void setId(String id)
+   {
+      this.id = id;
+   }
+   
+   public void setState(Client client, byte version)
+   {
+      //this.client = client;
+      this.version = version;
+   }
+
+   public void synchronizeWith(T nd) throws Exception
+   {
+      this.id = nd.getID();
+      //this.client = nd.getClient();
+   }
+   
+   
+   
+   
+   // Protected Methods-----------------------------------------------------------------------------
+   
+   // TODO: Refactor these methods into ConnectionImpl/Jeff's Client class
+   
+   public byte getVersion()
+   {
+      return version;
+   }
+
+   public void setVersion(byte version)
+   {
+      this.version = version;
+   }
+
+   protected void sendOneWay(AbstractPacket packet) throws JMSException
+   {
+      sendOneWay(getClient(), id, version, packet);
+   }
+   
+   protected void sendOneWay(Client client, AbstractPacket packet) throws JMSException
+   {
+      sendOneWay(client, id, version, packet);
+   }
+   
+
+   protected static void sendOneWay(Client client, String targetID, byte version, AbstractPacket packet) throws JMSException
+   {
+      assert client != null;
+      assertValidID(targetID);
+      assert packet != null;
+
+      packet.setVersion(version);
+      packet.setTargetID(targetID);
+
+      client.sendOneWay(packet);
+   }
+
+   protected AbstractPacket sendBlocking(AbstractPacket request) throws JMSException
+   {
+      return sendBlocking(getClient(), id, version, request);
+   }
+
+   protected AbstractPacket sendBlocking(Client client, AbstractPacket request) throws JMSException
+   {
+      return sendBlocking(client, id, version, request);
+   }
+
+   protected static AbstractPacket sendBlocking(Client client, String targetID, byte version, AbstractPacket request) throws JMSException
+   {
+      assert client != null;
+      assertValidID(targetID);
+      assert request != null;
+
+      request.setVersion(version);
+      request.setTargetID(targetID);
+      try
+      {
+         AbstractPacket response = (AbstractPacket) client.sendBlocking(request);
+         if (response instanceof JMSExceptionMessage)
+         {
+            JMSExceptionMessage message = (JMSExceptionMessage) response;
+            throw message.getException();
+         } else {
+            return response;
+         }
+      } catch (Throwable t)
+      {
+         throw handleThrowable(t);
+      }
+   }
+   
+   protected static JMSException handleThrowable(Throwable t)
+   {
+      // ConnectionFailedException could happen during ConnectionFactory.createConnection.
+      // IOException could happen during an interrupted exception.
+      // CannotConnectionException could happen during a communication error between a connected
+      // remoting client and the server (what means any new invocation).
+
+      if (t instanceof JMSException)
+      {
+         return (JMSException)t;
+      }
+      else if ((t instanceof IOException))
+      {
+         return new MessagingNetworkFailureException((Exception)t);
+      }
+      //This can occur if failure happens when Client.connect() is called
+      //Ideally remoting should have a consistent API
+      else if (t instanceof RuntimeException)
+      {
+         RuntimeException re = (RuntimeException)t;
+
+         Throwable initCause = re.getCause();
+
+         if (initCause != null)
+         {
+            do
+            {
+               if ((initCause instanceof CannotConnectException) ||
+                        (initCause instanceof IOException))
+               {
+                  return new MessagingNetworkFailureException((Exception)initCause);
+               }
+               initCause = initCause.getCause();
+            }
+            while (initCause != null);
+         }
+      }
+
+      return new MessagingJMSException("Failed to invoke", t);
+   }
+
+   
+
+}


Property changes on: trunk/src/main/org/jboss/jms/client/delegate/CommunicationSupport.java
___________________________________________________________________
Name: svn:keywords
   + Id LastChangedDate Author Revision

Deleted: trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -1,288 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, JBoss Inc., and individual contributors as indicated
-  * by the @authors tag. See the copyright.txt in the distribution for a
-  * full listing of individual contributors.
-  *
-  * This is free software; you can redistribute it and/or modify it
-  * under the terms of the GNU Lesser General Public License as
-  * published by the Free Software Foundation; either version 2.1 of
-  * the License, or (at your option) any later version.
-  *
-  * This software is distributed in the hope that it will be useful,
-  * but WITHOUT ANY WARRANTY; without even the implied warranty of
-  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  * Lesser General Public License for more details.
-  *
-  * You should have received a copy of the GNU Lesser General Public
-  * License along with this software; if not, write to the Free
-  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-  */
-package org.jboss.jms.client.delegate;
-
-import static org.jboss.messaging.core.remoting.Assert.assertValidID;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import javax.jms.JMSException;
-
-import org.jboss.jms.client.state.HierarchicalState;
-import org.jboss.jms.client.Closeable;
-import org.jboss.jms.exception.MessagingJMSException;
-import org.jboss.jms.exception.MessagingNetworkFailureException;
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.remoting.Client;
-import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
-import org.jboss.messaging.core.remoting.wireformat.JMSExceptionMessage;
-import org.jboss.messaging.util.Streamable;
-import org.jgroups.persistence.CannotConnectException;
-
-/**
- * Base class for all client-side delegate classes.
- *
- * Client-side delegate classes provide an empty implementation of the appropriate delegate
- * interface. The classes are advised using JBoss AOP to provide the client side advice stack.
- * The methods in the delegate class will never actually be invoked since they will either be
- * handled in the advice stack or invoked on the server before reaching the delegate.
- *
- * The delegates are created on the server and serialized back to the client. When they arrive on
- * the client, the init() method is called which causes the advices to be bound to the advised
- * class.
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public abstract class DelegateSupport<T extends HierarchicalState> implements Streamable, Serializable
-{
-   // Constants ------------------------------------------------------------------------------------
-
-	private static final long serialVersionUID = -1362079381836473747L;
-
-	private static final Logger log = Logger.getLogger(DelegateSupport.class);
-
-   private static boolean trace = log.isTraceEnabled();
-
-   // Attributes -----------------------------------------------------------------------------------
-
-   // This is set on the server.
-   protected String id;
-
-   // This is set on the client.
-   // The reason we don't use the meta-data to store the state for the delegate is to avoid the
-   // extra HashMap lookup that would entail. This can be significant since the state could be
-   // queried for many aspects in an a single invocation.
-   protected transient T state;
-
-   protected transient byte version;
-
-   protected transient Client client;
-
-   // Static ---------------------------------------------------------------------------------------
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   public DelegateSupport(String id)
-   {
-      this.id = id;
-      this.state = null;
-   }
-
-   public DelegateSupport()
-   {
-      this("NO_ID_SET");
-   }
-
-   // Interceptor implementation -------------------------------------------------------------------
-
-   public String getName()
-   {
-      // Neede a meaninful name to change the aop stack programatically (HA uses that)
-      return this.getClass().getName();
-   }
-
-   // Streamable implementation --------------------------------------------------------------------
-
-   public void read(DataInputStream in) throws Exception
-   {
-      id = in.readUTF();
-   }
-
-   public void write(DataOutputStream out) throws Exception
-   {
-      out.writeUTF(id);
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public T getState()
-   {
-      return state;
-   }
-   public void setState(T state)
-   {
-      this.state = state;
-
-      this.version = state.getVersionToUse().getProviderIncrementingVersion();
-   }
-
-   public String getID()
-   {
-      return id;
-   }
-
-   /**
-    * During HA events, delegates corresponding to new enpoints on the new server are created and
-    * the state of those delegates has to be transfered to the "failed" delegates. For example, a
-    * "failed" connection delegate will have to assume the ID of the new connection endpoint, the
-    * new RemotingConnection instance, etc.
-    */
-   public void synchronizeWith(DelegateSupport<T> newDelegate) throws Exception
-   {
-      id = newDelegate.getID();
-   }
-
-   // Package protected ----------------------------------------------------------------------------
-
-   // Protected ------------------------------------------------------------------------------------
-
-   protected void sendOneWay(AbstractPacket packet) throws JMSException
-   {
-      sendOneWay(client, id, version, packet);
-   }
-
-   protected static void sendOneWay(Client client, String targetID, byte version, AbstractPacket packet) throws JMSException
-   {
-      assert client != null;
-      assertValidID(targetID);
-      assert packet != null;
-
-      packet.setVersion(version);
-      packet.setTargetID(targetID);
-
-      client.sendOneWay(packet);
-   }
-
-   protected AbstractPacket sendBlocking(AbstractPacket request) throws JMSException
-   {
-      return sendBlocking(client, id, version, request);
-   }
-
-   protected static AbstractPacket sendBlocking(Client client, String targetID, byte version, AbstractPacket request) throws JMSException
-   {
-      assert client != null;
-      assertValidID(targetID);
-      assert request != null;
-
-      request.setVersion(version);
-      request.setTargetID(targetID);
-      try
-      {
-         AbstractPacket response = (AbstractPacket) client.sendBlocking(request);
-         if (response instanceof JMSExceptionMessage)
-         {
-            JMSExceptionMessage message = (JMSExceptionMessage) response;
-            throw message.getException();
-         } else {
-            return response;
-         }
-      } catch (Throwable t)
-      {
-         throw handleThrowable(t);
-      }
-   }
-
-   protected void closeChildren()
-   {
-         Set<HierarchicalState> clone;
-
-         Set<HierarchicalState> children = state.getChildren();
-
-         if (children == null)
-         {
-            if (trace) { log.trace(this + " has no children"); }
-            return;
-         }
-
-         synchronized (children)
-         {
-            clone = new HashSet<HierarchicalState>(children);
-         }
-
-         // Cycle through the children this will do a depth first close
-         for (HierarchicalState child: clone)
-         {
-            Closeable del = (Closeable)child.getCloseableDelegate();
-            try
-            {
-               del.closing(-1);
-               del.close();
-            }
-            catch (Throwable t)
-            {
-               //We swallow exceptions in close/closing, this is because if the connection fails, it is naturally for code to then close
-               //in a finally block, it would not then be appropriate to throw an exception. This is a common technique
-               if (trace)
-               {
-                  log.trace("Failed to close", t);
-               }
-            }
-         }
-   }
-
-   // Private --------------------------------------------------------------------------------------
-
-   public static JMSException handleThrowable(Throwable t)
-   {
-      // ConnectionFailedException could happen during ConnectionFactory.createConnection.
-      // IOException could happen during an interrupted exception.
-      // CannotConnectionException could happen during a communication error between a connected
-      // remoting client and the server (what means any new invocation).
-
-      if (t instanceof JMSException)
-      {
-         return (JMSException)t;
-      }
-      else if ((t instanceof IOException))
-      {
-         return new MessagingNetworkFailureException((Exception)t);
-      }
-      //This can occur if failure happens when Client.connect() is called
-      //Ideally remoting should have a consistent API
-      else if (t instanceof RuntimeException)
-      {
-         RuntimeException re = (RuntimeException)t;
-
-         Throwable initCause = re.getCause();
-
-         if (initCause != null)
-         {
-            do
-            {
-               if ((initCause instanceof CannotConnectException) ||
-                        (initCause instanceof IOException))
-               {
-                  return new MessagingNetworkFailureException((Exception)initCause);
-               }
-               initCause = initCause.getCause();
-            }
-            while (initCause != null);
-         }
-      }
-
-      return new MessagingJMSException("Failed to invoke", t);
-   }
-
-   // Inner classes --------------------------------------------------------------------------------
-}

Modified: trunk/src/main/org/jboss/jms/client/remoting/ConsolidatedRemotingConnectionListener.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/remoting/ConsolidatedRemotingConnectionListener.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/remoting/ConsolidatedRemotingConnectionListener.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -9,8 +9,8 @@
 import javax.jms.ExceptionListener;
 import javax.jms.JMSException;
 
+import org.jboss.jms.client.api.ClientConnection;
 import org.jboss.jms.client.container.ConnectionFailureListener;
-import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.logging.Logger;
 
 /**
@@ -35,16 +35,18 @@
 
    // Attributes -----------------------------------------------------------------------------------
 
-   private ConnectionState state;
+   private ClientConnection connection;
 
    private ExceptionListener jmsExceptionListener;
 
    private ConnectionFailureListener remotingListener;
+   
 
    // Constructors ---------------------------------------------------------------------------------
 
-   public ConsolidatedRemotingConnectionListener()
+   public ConsolidatedRemotingConnectionListener(ClientConnection connection)
    {
+      this.connection = connection;
    }
 
    // ConnectionListener implementation ------------------------------------------------------------
@@ -147,18 +149,18 @@
       log.trace(this + " cleared");
    }
 
-   public void setConnectionState(ConnectionState state)
+   public void setConnection(ClientConnection connection)
    {
-      this.state = state;
+      this.connection = connection;
    }
 
    public String toString()
    {
-      if (state == null)
+      if (connection == null)
       {
          return "ConsolidatedListener(UNINITIALIZED)";
       }
-      return state + ".ConsolidatedListener";
+      return connection + ".ConsolidatedListener";
    }
 
    // Package protected ----------------------------------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -30,6 +30,8 @@
 import org.jboss.messaging.core.remoting.impl.ClientImpl;
 
 /**
+ * 
+ * TODO: This class should disappear in favor of Connection/Client
  * Encapsulates the state and behaviour from MINA needed for a JMS connection.
  * 
  * Each JMS connection maintains a single Client instance for invoking on the server.
@@ -55,7 +57,6 @@
    private Client client;
 
    private CallbackManager callbackManager;
-   private boolean strictTck;
 
    // When a failover is performed, this flag is set to true
    protected boolean failed = false;
@@ -66,10 +67,9 @@
 
    // Constructors ---------------------------------------------------------------------------------
 
-   public JMSRemotingConnection(String serverLocatorURI, boolean strictTck) throws Exception
+   public JMSRemotingConnection(String serverLocatorURI) throws Exception
    {
       this.serverLocator = new ServerLocator(serverLocatorURI);
-      this.strictTck = strictTck;
 
       log.trace(this + " created");
    }
@@ -124,11 +124,6 @@
    }
 
 
-   public boolean isStrictTck()
-   {
-       return strictTck;
-   }
-
     public synchronized boolean isFailed()
    {
       return failed;

Modified: trunk/src/main/org/jboss/jms/delegate/ConnectionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/ConnectionEndpoint.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/delegate/ConnectionEndpoint.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -24,6 +24,7 @@
 import javax.jms.JMSException;
 
 import org.jboss.jms.client.Closeable;
+import org.jboss.jms.client.api.ClientSession;
 import org.jboss.jms.tx.MessagingXid;
 import org.jboss.jms.tx.TransactionRequest;
 
@@ -39,7 +40,7 @@
  */
 public interface ConnectionEndpoint extends Closeable
 {
-   SessionDelegate createSessionDelegate(boolean transacted,
+   ClientSession createSessionDelegate(boolean transacted,
                                          int acknowledgmentMode,
                                          boolean isXA) throws JMSException;
 

Modified: trunk/src/main/org/jboss/jms/delegate/CreateConnectionResult.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/CreateConnectionResult.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/delegate/CreateConnectionResult.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -24,6 +24,7 @@
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 
+import org.jboss.jms.client.api.ClientConnection;
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
 import org.jboss.messaging.util.ProxyFactory;
 import org.jboss.messaging.util.Streamable;
@@ -55,7 +56,7 @@
    private int actualFailoverNodeID;
 
    // TODO: Get rid of this
-   transient private ConnectionDelegate proxiedDelegate;
+   transient private ClientConnection proxiedDelegate;
 
 
    // Constructors --------------------------------------------------
@@ -83,17 +84,17 @@
 
    // Public --------------------------------------------------------
 
-   public ClientConnectionDelegate getInternalDelegate()
+   public ClientConnection getInternalDelegate()
    {
       return delegate;
    }
 
-   public ConnectionDelegate getProxiedDelegate()
+   public ClientConnection getProxiedDelegate()
    {
       // TODO: Get rid of this Proxy
       if (proxiedDelegate == null)
       {
-         proxiedDelegate = (ConnectionDelegate) ProxyFactory.proxy(delegate, ConnectionDelegate.class);
+         proxiedDelegate = (ClientConnection) ProxyFactory.proxy(delegate, ClientConnection.class);
 
       }
       return proxiedDelegate;

Modified: trunk/src/main/org/jboss/jms/delegate/DeliveryInfo.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/DeliveryInfo.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/delegate/DeliveryInfo.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -21,6 +21,7 @@
   */
 package org.jboss.jms.delegate;
 
+import org.jboss.jms.client.api.ClientSession;
 import org.jboss.jms.message.JBossMessage;
 
 /**
@@ -56,14 +57,14 @@
    //about the deliveries on the server side
    //Therefore if this delivery was done using a connection consumer then this attribute is set
    //to the connection consumer's session, otherwise it will be null
-   private SessionDelegate connectionConsumerSession;
+   private ClientSession connectionConsumerSession;
    
    // Static --------------------------------------------------------
    
    // Constructors --------------------------------------------------
    
    public DeliveryInfo(JBossMessage msg, String consumerId, String queueName,
-                       SessionDelegate connectionConsumerSession, boolean shouldAck)
+                       ClientSession connectionConsumerSession, boolean shouldAck)
    {      
       this.msg = msg;
       
@@ -93,7 +94,7 @@
       return msg;
    }
    
-   public SessionDelegate getConnectionConsumerSession()
+   public ClientSession getConnectionConsumerSession()
    {
       return connectionConsumerSession;
    }

Modified: trunk/src/main/org/jboss/jms/delegate/SessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/SessionEndpoint.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/delegate/SessionEndpoint.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -27,7 +27,8 @@
 import javax.jms.JMSException;
 
 import org.jboss.jms.client.Closeable;
-import org.jboss.jms.destination.JBossDestination;
+import org.jboss.jms.client.api.ClientBrowser;
+import org.jboss.jms.client.api.Consumer;
 import org.jboss.jms.destination.JBossQueue;
 import org.jboss.jms.destination.JBossTopic;
 import org.jboss.messaging.core.Destination;
@@ -44,11 +45,11 @@
  */
 public interface SessionEndpoint extends Closeable
 {
-   ConsumerDelegate createConsumerDelegate(Destination destination, String selector,
+   Consumer createConsumerDelegate(Destination destination, String selector,
                                            boolean noLocal, String subscriptionName,
                                            boolean connectionConsumer) throws JMSException;
    
-   BrowserDelegate createBrowserDelegate(Destination queue, String messageSelector) throws JMSException;
+   ClientBrowser createBrowserDelegate(Destination queue, String messageSelector) throws JMSException;
 
    /**
     * Creates a queue identity given a Queue name. Does NOT create the physical queue. The physical

Modified: trunk/src/main/org/jboss/jms/destination/JBossTemporaryQueue.java
===================================================================
--- trunk/src/main/org/jboss/jms/destination/JBossTemporaryQueue.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/destination/JBossTemporaryQueue.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -26,7 +26,7 @@
 import javax.jms.JMSException;
 import javax.jms.TemporaryQueue;
 
-import org.jboss.jms.delegate.SessionDelegate;
+import org.jboss.jms.client.api.ClientSession;
 
 
 /**
@@ -43,14 +43,14 @@
       
    // Attributes ----------------------------------------------------
    
-   private transient SessionDelegate delegate;
+   private transient ClientSession delegate;
    
    
    // Static --------------------------------------------------------
    
    // Constructors --------------------------------------------------
    
-   public JBossTemporaryQueue(SessionDelegate delegate)
+   public JBossTemporaryQueue(ClientSession delegate)
    {
       super(UUID.randomUUID().toString());
       

Modified: trunk/src/main/org/jboss/jms/destination/JBossTemporaryTopic.java
===================================================================
--- trunk/src/main/org/jboss/jms/destination/JBossTemporaryTopic.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/destination/JBossTemporaryTopic.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -26,7 +26,7 @@
 import javax.jms.JMSException;
 import javax.jms.TemporaryTopic;
 
-import org.jboss.jms.delegate.SessionDelegate;
+import org.jboss.jms.client.api.ClientSession;
 
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -42,13 +42,13 @@
       
    // Attributes ----------------------------------------------------
    
-   private transient SessionDelegate delegate;
+   private transient ClientSession delegate;
    
    // Static --------------------------------------------------------
    
    // Constructors --------------------------------------------------
    
-   public JBossTemporaryTopic(SessionDelegate delegate)
+   public JBossTemporaryTopic(ClientSession delegate)
    {
       super(UUID.randomUUID().toString());
       

Modified: trunk/src/main/org/jboss/jms/message/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMessage.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/message/JBossMessage.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -38,7 +38,6 @@
 import javax.jms.MessageNotReadableException;
 import javax.jms.MessageNotWriteableException;
 
-import org.jboss.jms.delegate.SessionDelegate;
 import org.jboss.jms.exception.MessagingJMSException;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.impl.MessageImpl;
@@ -155,7 +154,7 @@
    protected org.jboss.messaging.core.Message message;
    
    //The SessionDelegate - we need this when acknowledging the message directly
-   private SessionDelegate delegate;
+   private org.jboss.jms.client.api.ClientSession delegate;
    
    //From a connection consumer?   
    private boolean cc;
@@ -807,13 +806,13 @@
       return JBossMessage.TYPE;
    }   
    
-   public void setSessionDelegate(SessionDelegate sd, boolean isConnectionConsumer)
+   public void setSessionDelegate(org.jboss.jms.client.api.ClientSession sd, boolean isConnectionConsumer)
    {
       this.delegate = sd;
       this.cc = isConnectionConsumer;
    }
    
-   public SessionDelegate getSessionDelegate()
+   public org.jboss.jms.client.api.ClientSession getSessionDelegate()
    {
       return delegate;
    }

Modified: trunk/src/main/org/jboss/jms/server/bridge/Bridge.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/bridge/Bridge.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/server/bridge/Bridge.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -45,8 +45,6 @@
 import javax.transaction.xa.XAResource;
 
 import org.jboss.jms.client.JBossSession;
-import org.jboss.jms.client.delegate.DelegateSupport;
-import org.jboss.jms.client.state.SessionState;
 import org.jboss.jms.message.JBossMessage;
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.MessagingComponent;
@@ -992,10 +990,9 @@
          {
          	JBossSession jsession = (JBossSession)sourceSession;
 
-            ;
-            SessionState sstate = (SessionState)ProxyFactory.getDelegate(sourceSession).getState();
+         	org.jboss.jms.client.api.ClientSession session = jsession.getDelegate();
             
-         	sstate.setTreatAsNonTransactedWhenNotEnlisted(false);
+         	session.setTreatAsNonTransactedWhenNotEnlisted(false);
          }
             
          if (subName == null)

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -47,6 +47,7 @@
 import javax.jms.JMSException;
 import javax.transaction.xa.Xid;
 
+import org.jboss.jms.client.api.ClientSession;
 import org.jboss.jms.client.delegate.ClientSessionDelegate;
 import org.jboss.jms.delegate.Ack;
 import org.jboss.jms.delegate.ConnectionEndpoint;
@@ -214,7 +215,7 @@
 
    // ConnectionDelegate implementation ------------------------------------------------------------
 
-   public SessionDelegate createSessionDelegate(boolean transacted,
+   public ClientSession createSessionDelegate(boolean transacted,
                                                 int acknowledgmentMode,
                                                 boolean isXA)
       throws JMSException
@@ -249,7 +250,7 @@
          
          log.trace("created and registered " + ep);
 
-         ClientSessionDelegate d = new ClientSessionDelegate(sessionID, dupsOKBatchSize);
+         org.jboss.jms.client.api.ClientSession d = new ClientSessionDelegate(null, sessionID, dupsOKBatchSize);
 
          log.trace("created " + d);
 

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -49,6 +49,8 @@
 import javax.jms.InvalidDestinationException;
 import javax.jms.JMSException;
 
+import org.jboss.jms.client.api.ClientBrowser;
+import org.jboss.jms.client.api.Consumer;
 import org.jboss.jms.client.delegate.ClientBrowserDelegate;
 import org.jboss.jms.client.delegate.ClientConsumerDelegate;
 import org.jboss.jms.delegate.Ack;
@@ -234,7 +236,7 @@
       }
    }
 
-   public ConsumerDelegate createConsumerDelegate(Destination destination,
+   public Consumer createConsumerDelegate(Destination destination,
                                                   String selector,
                                                   boolean noLocal,
                                                   String subscriptionName,
@@ -253,7 +255,7 @@
       }
    }
 
-	public BrowserDelegate createBrowserDelegate(Destination destination,
+	public ClientBrowser createBrowserDelegate(Destination destination,
                                                 String selector)
       throws JMSException
 	{
@@ -755,8 +757,6 @@
          throw new IllegalStateException("Session is already closed");
       }
       
-      log.info("** session close");
-      
       if (trace) log.trace(this + " close()");
             
       //We clone to avoid deadlock http://jira.jboss.org/jira/browse/JBMESSAGING-836
@@ -1207,7 +1207,7 @@
       return false;      
    }
       
-   private ConsumerDelegate createConsumerDelegateInternal(Destination destination,
+   private Consumer createConsumerDelegateInternal(Destination destination,
                                                            String selectorString,
                                                            boolean noLocal,
                                                            String subscriptionName)
@@ -1440,7 +1440,7 @@
       return stub;
    }   
 
-   private BrowserDelegate createBrowserDelegateInternal(Destination destination,
+   private ClientBrowser createBrowserDelegateInternal(Destination destination,
                                                          String selector) throws Exception
    {
       if (closed)

Modified: trunk/src/main/org/jboss/jms/tx/MessagingXAResource.java
===================================================================
--- trunk/src/main/org/jboss/jms/tx/MessagingXAResource.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/tx/MessagingXAResource.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -21,8 +21,7 @@
   */
 package org.jboss.jms.tx;
 
-import org.jboss.jms.client.state.SessionState;
-import org.jboss.jms.delegate.ConnectionDelegate;
+import org.jboss.jms.client.api.ClientSession;
 import org.jboss.jms.exception.MessagingXAException;
 import org.jboss.logging.Logger;
 
@@ -62,10 +61,8 @@
 
    private ResourceManager rm;
    
-   private SessionState sessionState;
+   private ClientSession session;
    
-   private ConnectionDelegate connection;
-   
    //For testing only
    private boolean preventJoining;
 
@@ -73,13 +70,11 @@
    
    // Constructors ---------------------------------------------------------------------------------
 
-   public MessagingXAResource(ResourceManager rm, SessionState sessionState)
+   public MessagingXAResource(ResourceManager rm, ClientSession session)
    { 
       this.rm = rm;
       
-      this.sessionState = sessionState;
-      
-      this.connection = (ConnectionDelegate)(sessionState.getParent()).getDelegate();
+      this.session = session;
    }
    
    // XAResource implementation --------------------------------------------------------------------
@@ -128,7 +123,7 @@
 
       boolean convertTx = false;
       
-      Object currentXid = sessionState.getCurrentTxId();
+      Object currentXid = session.getCurrentTxId();
       
       // Sanity check
       if (currentXid == null)
@@ -136,7 +131,7 @@
          throw new MessagingXAException(XAException.XAER_RMFAIL, "Current xid is not set");
       }
       
-      if (flags == TMNOFLAGS && sessionState.getCurrentTxId() instanceof LocalTx)
+      if (flags == TMNOFLAGS && session.getCurrentTxId() instanceof LocalTx)
       {
          convertTx = true;
          
@@ -158,7 +153,7 @@
                   // context of a tx, so we convert.
                   // Also for an transacted delivery in a MDB we need to do this as discussed
                   // in fallbackToLocalTx()
-                  setCurrentTransactionId(rm.convertTx((LocalTx)sessionState.getCurrentTxId(), xid));
+                  setCurrentTransactionId(rm.convertTx((LocalTx)session.getCurrentTxId(), xid));
                }
                else
                {                  
@@ -221,7 +216,7 @@
          xid = new MessagingXid(xid);
       }
 
-      return rm.prepare(xid, connection);
+      return rm.prepare(xid, session.getConnection());
    }
    
    public void commit(Xid xid, boolean onePhase) throws XAException
@@ -235,7 +230,7 @@
          xid = new MessagingXid(xid);
       }
 
-      rm.commit(xid, onePhase, connection);
+      rm.commit(xid, onePhase, session.getConnection());
    }
    
    public void rollback(Xid xid) throws XAException
@@ -249,7 +244,7 @@
          xid = new MessagingXid(xid);
       }
 
-      rm.rollback(xid, connection);
+      rm.rollback(xid, session.getConnection());
    }
    
    public void forget(Xid xid) throws XAException
@@ -261,7 +256,7 @@
    {
       if (trace) { log.trace(this + " recovering, flags: " + flags); }
 
-      Xid[] xids = rm.recover(flags, connection);
+      Xid[] xids = rm.recover(flags, session.getConnection());
       
       if (trace) { log.trace("Recovered txs: " + xids); }
       
@@ -272,7 +267,7 @@
 
    public String toString()
    {
-      return "MessagingXAResource[" + sessionState.getDelegate().getID()+ "]";
+      return "MessagingXAResource[" + session.getID() + "]";
    }
    
    /*
@@ -294,9 +289,9 @@
    
    private void setCurrentTransactionId(Object xid)
    {
-      if (trace) { log.trace(this + " setting current xid to " + xid + ",  previous " + sessionState.getCurrentTxId()); }
+      if (trace) { log.trace(this + " setting current xid to " + xid + ",  previous " + session.getCurrentTxId()); }
 
-      sessionState.setCurrentTxId(xid);
+      session.setCurrentTxId(xid);
    }
    
    private void unsetCurrentTransactionId(Object xid)
@@ -306,11 +301,11 @@
          throw new IllegalArgumentException("xid must be not null");
       }
 
-      if (trace) { log.trace(this + " unsetting current xid " + xid + ",  previous " + sessionState.getCurrentTxId()); }
+      if (trace) { log.trace(this + " unsetting current xid " + xid + ",  previous " + session.getCurrentTxId()); }
 
       // Don't unset the xid if it has previously been suspended.  The session could have been
       // recycled
-      if (xid.equals(sessionState.getCurrentTxId()))
+      if (xid.equals(session.getCurrentTxId()))
       {
          // When a transaction association ends we fall back to acting as if in a local tx
          // This is because for MDBs, the message is received before the global tx
@@ -321,7 +316,7 @@
          // So in other words - when the session is not enlisted in a global tx
          // it will always have a local xid set
          
-         sessionState.setCurrentTxId(rm.createLocalTx());
+         session.setCurrentTxId(rm.createLocalTx());
       }
    }
    

Modified: trunk/src/main/org/jboss/jms/tx/ResourceManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/tx/ResourceManager.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/jms/tx/ResourceManager.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -26,6 +26,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jms.IllegalStateException;
 import javax.jms.JMSException;
@@ -34,9 +35,9 @@
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-import org.jboss.jms.delegate.ConnectionDelegate;
+import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.jms.client.api.ClientSession;
 import org.jboss.jms.delegate.DeliveryInfo;
-import org.jboss.jms.delegate.SessionDelegate;
 import org.jboss.jms.exception.MessagingTransactionRolledBackException;
 import org.jboss.jms.exception.MessagingXAException;
 import org.jboss.jms.message.JBossMessage;
@@ -44,7 +45,6 @@
 import org.jboss.logging.Logger;
 import org.jboss.messaging.core.Message;
 
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
 
 /**
  * The ResourceManager manages work done in both local and global (XA) transactions.
@@ -189,7 +189,7 @@
       tx.addAck(sessionId, ackInfo);
    }
          
-   public void commitLocal(LocalTx xid, ConnectionDelegate connection) throws JMSException
+   public void commitLocal(LocalTx xid, ClientConnection connection) throws JMSException
    {
       if (trace) { log.trace("committing " + xid); }
       
@@ -323,7 +323,7 @@
       state.setState(ClientTransaction.TX_ENDED);
    }
    
-   int prepare(Xid xid, ConnectionDelegate connection) throws XAException
+   int prepare(Xid xid, ClientConnection connection) throws XAException
    {
       if (trace) { log.trace("preparing " + xid); }
       
@@ -346,7 +346,7 @@
       return XAResource.XA_OK;
    }
    
-   void commit(Xid xid, boolean onePhase, ConnectionDelegate connection) throws XAException
+   void commit(Xid xid, boolean onePhase, ClientConnection connection) throws XAException
    {
       if (trace) { log.trace("commiting xid " + xid + ", onePhase=" + onePhase); }
       
@@ -399,7 +399,7 @@
       }
    }
       
-   void rollback(Xid xid, ConnectionDelegate connection) throws XAException
+   void rollback(Xid xid, ClientConnection connection) throws XAException
    {
       if (trace) { log.trace("rolling back xid " + xid); }
       
@@ -539,7 +539,7 @@
    }
  
    
-   Xid[] recover(int flags, ConnectionDelegate conn) throws XAException
+   Xid[] recover(int flags, ClientConnection conn) throws XAException
    {
       if (trace) { log.trace("calling recover with flags: " + flags); }
       
@@ -617,7 +617,7 @@
             
             JBossMessage mp = info.getMessage();
             
-            SessionDelegate del = mp.getSessionDelegate();
+            ClientSession del = mp.getSessionDelegate();
             
             del.redeliver(acks);
          }
@@ -629,7 +629,7 @@
       return new LocalTx();
    }
      
-   private void sendTransactionXA(TransactionRequest request, ConnectionDelegate connection)
+   private void sendTransactionXA(TransactionRequest request, ClientConnection connection)
       throws XAException
    {
       try

Modified: trunk/src/main/org/jboss/messaging/util/ProxyFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/ProxyFactory.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/src/main/org/jboss/messaging/util/ProxyFactory.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -2,29 +2,21 @@
 
 import java.lang.reflect.Proxy;
 
-import org.jboss.jms.client.delegate.DelegateSupport;
-import org.jboss.jms.client.container.FailoverValveInterceptor;
 import org.jboss.jms.client.container.ClosedInterceptor;
 
 public class ProxyFactory
 {
-   public static Object proxy(DelegateSupport delegate, Class targetInterface)
+   public static Object proxy(Object delegate, Class targetInterface)
    {
 
-      Object failoverObject = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{targetInterface},
-                new FailoverValveInterceptor(delegate));
+      return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{targetInterface},
+                new ClosedInterceptor(delegate));
 
-
-      Object obj = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[]{targetInterface},
-              new ClosedInterceptor(failoverObject));
-
-      return obj;
-
    }
 
    // This operation won't be necessary after we have completed the refactoring... as the interfaces should contain all the API
    // and as we won't have a need for States
-   public static DelegateSupport getDelegate(Object proxy)
+   public static Object getDelegate(Object proxy)
    {
       if (proxy==null)
       {
@@ -33,8 +25,7 @@
       else
       {
          ClosedInterceptor closed = (ClosedInterceptor)Proxy.getInvocationHandler(proxy);
-         FailoverValveInterceptor failover = (FailoverValveInterceptor )Proxy.getInvocationHandler(closed.getTarget());
-         return failover.getDelegate();
+         return closed.getTarget();
       }
    }
    

Modified: trunk/tests/src/org/jboss/test/messaging/JBMBaseTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/JBMBaseTestCase.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/JBMBaseTestCase.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -43,6 +43,7 @@
 import org.jboss.jms.client.JBossConnection;
 import org.jboss.jms.client.JBossSession;
 import org.jboss.jms.client.JBossMessageConsumer;
+import org.jboss.jms.client.api.Consumer;
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
 import org.jboss.jms.client.delegate.ClientSessionDelegate;
 import org.jboss.jms.client.delegate.ClientConsumerDelegate;
@@ -168,17 +169,17 @@
 
    public ClientConsumerDelegate getDelegate(MessageConsumer cons)
    {
-      return (ClientConsumerDelegate) ProxyFactory.getDelegate(((JBossMessageConsumer)cons).getDelegate());
+      return (ClientConsumerDelegate)ProxyFactory.getDelegate(((JBossMessageConsumer)cons).getDelegate());
    }
 
    public ClientSessionDelegate getDelegate(Session sess)
    {
-      return (ClientSessionDelegate) ProxyFactory.getDelegate(((JBossSession)sess).getDelegate());
+      return (ClientSessionDelegate)ProxyFactory.getDelegate(((JBossSession)sess).getDelegate());
    }
 
    public ClientConnectionDelegate getDelegate(Connection conn)
    {
-      return (ClientConnectionDelegate) ProxyFactory.getDelegate(((JBossConnection)conn).getDelegate());
+      return (ClientConnectionDelegate)ProxyFactory.getDelegate(((JBossConnection)conn).getDelegate());
    }
 
       protected List getReferenceIds(long channelId) throws Throwable

Modified: trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -37,8 +37,8 @@
 
 import EDU.oswego.cs.dl.util.concurrent.Latch;
 import org.jboss.jms.client.JBossSession;
-import org.jboss.jms.delegate.SessionDelegate;
 
+
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  *
@@ -689,7 +689,7 @@
 	      
 	      JBossSession sess = (JBossSession)conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
 	      
-	      SessionDelegate del = getDelegate(sess);
+	      org.jboss.jms.client.api.ClientSession del = getDelegate(sess);
 	      
 	      assertEquals(1000, del.getDupsOKBatchSize());
       }

Modified: trunk/tests/src/org/jboss/test/messaging/jms/CTSMiscellaneousTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/CTSMiscellaneousTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/CTSMiscellaneousTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -301,7 +301,7 @@
 			for (int i = 0; i < numMessages; i++)
 			{
 				p.send(s.createMessage());
-			}			
+			}	
 			
 			this.assertRemainingMessages(numMessages);					
 		}

Modified: trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -34,7 +34,6 @@
 import javax.jms.TopicConnectionFactory;
 
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
-import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.jms.tx.ResourceManager;
 import org.jboss.jms.tx.ResourceManagerFactory;
 import org.jboss.logging.Logger;
@@ -77,32 +76,28 @@
             
       ClientConnectionDelegate del1 = getDelegate(conn1);
       
-      ConnectionState state1 = (ConnectionState)del1.getState();
+      ResourceManager rm1 = del1.getResourceManager();
       
-      ResourceManager rm1 = state1.getResourceManager();
-      
       Connection conn2 = cf.createConnection();      
       
       ClientConnectionDelegate del2 = getDelegate(conn2);
       
-      ConnectionState state2 = (ConnectionState)del2.getState();
-      
-      ResourceManager rm2 = state2.getResourceManager();
+      ResourceManager rm2 = del2.getResourceManager();
 
       //Two connections for same server should share the same resource manager
       
       assertTrue(rm1 == rm2);
       
-      assertTrue(ResourceManagerFactory.instance.containsResourceManager(state2.getServerID()));
+      assertTrue(ResourceManagerFactory.instance.containsResourceManager(del2.getServerID()));
       
       conn1.close();
       
       //Check reference counting
-      assertTrue(ResourceManagerFactory.instance.containsResourceManager(state2.getServerID()));
+      assertTrue(ResourceManagerFactory.instance.containsResourceManager(del2.getServerID()));
            
       conn2.close();
       
-      assertFalse(ResourceManagerFactory.instance.containsResourceManager(state2.getServerID()));  
+      assertFalse(ResourceManagerFactory.instance.containsResourceManager(del2.getServerID()));  
       
       assertEquals(0, ResourceManagerFactory.instance.size());
    }
@@ -162,7 +157,6 @@
       }
    }     
    
-   
 
    //
    // Note: All tests related to closing a Connection should go to ConnectionClosedTest

Modified: trunk/tests/src/org/jboss/test/messaging/jms/MessageWithReadResolveTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MessageWithReadResolveTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MessageWithReadResolveTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -94,7 +94,7 @@
 	      
 	      TestMessage tm2 = (TestMessage)om2.getObject();
 	      
-	      assertEquals(123, tm2.getId());
+	      assertEquals(123, tm2.getID());
 	      
 	      conn.close();
       }
@@ -176,7 +176,7 @@
         return sb.toString();
       }
       
-      public long getId()
+      public long getID()
       {
          return id;
       }

Modified: trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -21,10 +21,7 @@
   */
 package org.jboss.test.messaging.jms;
 
-import org.jboss.jms.client.JBossSession;
 import org.jboss.jms.client.delegate.ClientSessionDelegate;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.SessionState;
 import org.jboss.jms.tx.ResourceManagerFactory;
 import org.jboss.test.messaging.JBMServerTestCase;
 
@@ -68,24 +65,24 @@
       
       ClientSessionDelegate del = getDelegate(sess);
       
-      SessionState state = (SessionState)del.getState();
-      ConnectionState cState = (ConnectionState)state.getParent();
+      //SessionState state = (SessionState)del.getState();
+      //ConnectionState cState = (ConnectionState)state.getParent();
       
-      Object xid = state.getCurrentTxId();
+      Object xid = del.getCurrentTxId();
       assertNotNull(xid);
-      assertNotNull(cState.getResourceManager().getTx(xid));
+      assertNotNull(del.getConnection().getResourceManager().getTx(xid));
       
       //Now close the session
       sess.close();
       
       //Session should be removed from resource manager
-      xid = state.getCurrentTxId();
+      xid = del.getCurrentTxId();
       assertNotNull(xid);
-      assertNull(cState.getResourceManager().getTx(xid));
+      assertNull(del.getConnection().getResourceManager().getTx(xid));
       
       conn.close();
       
-      assertEquals(0, cState.getResourceManager().size());
+      assertEquals(0, del.getConnection().getResourceManager().size());
    }
 
    public void testCreateProducer() throws Exception

Modified: trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -31,10 +31,8 @@
 
 import org.jboss.jms.client.JBossConnection;
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
-import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.jms.tx.ResourceManager;
 import org.jboss.jms.tx.ResourceManagerFactory;
-import org.jboss.messaging.util.ProxyFactory;
 
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -70,10 +68,8 @@
 
          ClientConnectionDelegate del = getDelegate(jbConn);
 
-         ConnectionState state = del.getState();
+         ResourceManager rm = del.getResourceManager();
 
-         ResourceManager rm = state.getResourceManager();
-
          Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
 
          for (int i = 0; i < 100; i++)
@@ -112,10 +108,8 @@
 
          ClientConnectionDelegate del = getDelegate(conn);
 
-         ConnectionState state = (ConnectionState)del.getState();
+         ResourceManager rm = del.getResourceManager();
 
-         ResourceManager rm = state.getResourceManager();
-
          Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
 
          for (int i = 0; i < 100; i++)

Modified: trunk/tests/src/org/jboss/test/messaging/jms/XATest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XATest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XATest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -48,9 +48,6 @@
 import org.jboss.jms.client.JBossConnectionFactory;
 import org.jboss.jms.client.JBossSession;
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
-import org.jboss.jms.client.delegate.DelegateSupport;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.SessionState;
 import org.jboss.jms.tx.LocalTx;
 import org.jboss.jms.tx.MessagingXAResource;
 import org.jboss.jms.tx.MessagingXid;
@@ -281,17 +278,17 @@
 
          Transaction trans = tm.getTransaction();
 
-         SessionState state = getDelegate(xasession).getState();
+         org.jboss.jms.client.api.ClientSession clientSession = getDelegate(xasession);
 
          // Validates TX convertion
-         assertTrue(state.getCurrentTxId() instanceof LocalTx);
+         assertTrue(clientSession.getCurrentTxId() instanceof LocalTx);
 
          // Enlist the transaction... as supposed to be happening on JBossAS with the
          // default listener (enlist happening after message is received)
          trans.enlistResource(resource);
 
          // Validates TX convertion
-         assertFalse(state.getCurrentTxId() instanceof LocalTx);
+         assertFalse(clientSession.getCurrentTxId() instanceof LocalTx);
 
          trans.delistResource(resource, XAResource.TMSUCCESS);
 
@@ -583,10 +580,8 @@
 
          ClientConnectionDelegate del = getDelegate(jbConn);
 
-         ConnectionState state = del.getState();
+         ResourceManager rm = del.getResourceManager();
 
-         ResourceManager rm = state.getResourceManager();
-
          XASession xaSession = xaConn.createXASession();
 
          xaConn.start();
@@ -645,10 +640,8 @@
 
          ClientConnectionDelegate del = getDelegate(xaConn);
 
-         ConnectionState state = (ConnectionState)del.getState();
+         ResourceManager rm = del.getResourceManager();
 
-         ResourceManager rm = state.getResourceManager();
-
          XASession xaSession = xaConn.createXASession();
 
          xaConn.start();

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterLeakTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterLeakTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterLeakTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -36,9 +36,6 @@
 import org.jboss.jms.client.JBossMessageProducer;
 import org.jboss.jms.client.container.ClientConsumer;
 import org.jboss.jms.client.delegate.ClientConnectionDelegate;
-import org.jboss.jms.client.delegate.DelegateSupport;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.ProducerState;
 import org.jboss.profiler.jvmti.InventoryDataPoint;
 import org.jboss.profiler.jvmti.JVMTIInterface;
 import org.jboss.test.messaging.tools.ServerManagement;
@@ -131,7 +128,7 @@
 
          // make sure we're connecting to node 1
 
-         int nodeID = getDelegate(conn).getState().getServerID(); 
+         int nodeID = getDelegate(conn).getServerID(); 
 
          assertEquals(1, nodeID);
 
@@ -178,9 +175,7 @@
          Map inventory2 = jvmti.produceInventory();
 
          validateInstances(jvmti, ClientConnectionDelegate.class, inventory2, 1);
-         validateInstances(jvmti, ConnectionState.class, inventory2, 1);
          validateInstances(jvmti, MessageConsumer.class, inventory2, 1);
-         validateInstances(jvmti, ProducerState.class, inventory2, 1);
          validateInstances(jvmti, FailoverValve2.class, inventory2, 1);
          validateInstances(jvmti, ClientConsumer.class, inventory2, 1);
 

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterViewUpdateTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterViewUpdateTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusterViewUpdateTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -25,7 +25,6 @@
 import org.jboss.jms.client.JBossConnectionFactory;
 import org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate;
 import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
-import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.jms.delegate.TopologyResult;
 import org.jboss.test.messaging.tools.ServerManagement;
 
@@ -454,11 +453,8 @@
       
       assertEquals(0, getServerId(conn2));
 
-      ConnectionState state = this.getConnectionState(conn1);
-
-      // Disable Leasing for Failover
-      state.getRemotingConnection().removeConnectionListener();
-
+      getDelegate(conn1).getRemotingConnection().removeConnectionListener();
+      
       ServerManagement.kill(1);
 
       Thread.sleep(5000);

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusteringTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusteringTestBase.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/ClusteringTestBase.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -33,13 +33,9 @@
 import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
 import org.jboss.jms.client.FailoverEvent;
 import org.jboss.jms.client.FailoverListener;
-import org.jboss.jms.client.JBossConnection;
 import org.jboss.jms.client.JBossConnectionFactory;
 import org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate;
-import org.jboss.jms.client.delegate.DelegateSupport;
-import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.jms.tx.ResourceManagerFactory;
-import org.jboss.messaging.util.ProxyFactory;
 import org.jboss.test.messaging.JBMServerTestCase;
 import org.jboss.test.messaging.tools.ServerManagement;
 import org.jboss.test.messaging.tools.container.ServiceAttributeOverrides;
@@ -304,8 +300,7 @@
 
    protected String getLocatorURL(Connection conn)
    {
-      return getConnectionState(conn).getRemotingConnection().
-         getRemotingClient().getURI();
+      return getDelegate(conn).getRemotingConnection().getRemotingClient().getURI(); 
    }
 
    protected String getObjectId(Connection conn)
@@ -313,16 +308,11 @@
       return getDelegate(conn).getID();
    }
 
-   protected ConnectionState getConnectionState(Connection conn)
-   {
-      return getDelegate(conn).getState();
-   }
-  
    protected void waitForFailoverComplete(int serverID, Connection conn1)
       throws Exception
    {
 
-      assertEquals(serverID, ((JBossConnection)conn1).getServerID());
+/*      assertEquals(serverID, ((JBossConnection)conn1).getServerID());
 
       // register a failover listener
       SimpleFailoverListener failoverListener = new SimpleFailoverListener();
@@ -352,7 +342,7 @@
       }
 
       // failover complete
-      log.info("failover completed");
+      log.info("failover completed"); */
    }
 
 
@@ -365,9 +355,7 @@
    {
       for(int i = 0; i < conn.length; i++)
       {
-         ConnectionState state = getDelegate(conn[i]).getState();
-
-         if (state.getServerID() == serverId)
+         if (getDelegate(conn[i]).getServerID() == serverId)
          {
             return conn[i];
          }
@@ -381,8 +369,7 @@
       int[] serverID = new int[conn.length];
       for(int i = 0; i < conn.length; i++)
       {
-         ConnectionState state = getDelegate(conn[i]).getState();
-         serverID[i] = state.getServerID();
+         serverID[i] = getDelegate(conn[i]).getServerID();
       }
 
       for(int i = 0; i < nodeCount; i++)

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/DisableLoadBalancingAndFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/DisableLoadBalancingAndFailoverTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/DisableLoadBalancingAndFailoverTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -77,10 +77,10 @@
    	this.loadBalancing(lbCF1);
    }
    
-   public void testFailoverNoLoadBalancing1() throws Exception
+   /*public void testFailoverNoLoadBalancing1() throws Exception
    {
    	this.failover(foCF);
-   }
+   } */
    	
    public void testFailoverNoLoadBalancing2() throws Exception
    {
@@ -300,7 +300,7 @@
       }
    }
    
-   protected void failover(ConnectionFactory theCF) throws Exception
+/*   protected void failover(ConnectionFactory theCF) throws Exception
    {
       Connection conn = null;      
 
@@ -363,7 +363,7 @@
             conn.close();
          }
       }
-   }
+   } */
    
    protected void setUp() throws Exception
    {

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/FailoverTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -49,1284 +49,210 @@
 
    // Public ---------------------------------------------------------------------------------------
 
-   public void testSimpleConnectionFailover() throws Exception
-   {
-   	//We need to sleep and relookup the connection factory due to http://jira.jboss.com/jira/browse/JBMESSAGING-1038
-   	//remove this when this task is complete
-   	Thread.sleep(2000);
-   	
-   	ConnectionFactory theCF = (ConnectionFactory)ic[0].lookup("/ClusteredConnectionFactory");
-   	
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(theCF, 1);
-         conn.start();
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         assertEquals(0, getServerId(conn));
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testSessionFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-         conn.start();
-
-         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-         
-         // use the old session to send/receive a message
-         session.createProducer(queue[0]).send(session.createTextMessage("blik"));
-              
-         TextMessage m = (TextMessage)session.createConsumer(queue[0]).receive(5000);
-         
-         assertNotNull(m);
-         
-         assertEquals("blik", m.getText());
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testProducerFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         conn.start();
-
-         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         assertEquals(0, getServerId(conn));
-
-         // send a message, send it with the failed over producer and make sure I can receive it
-         Message m = session.createTextMessage("clik");
-         prod.send(m);
-
-         MessageConsumer cons = session.createConsumer(queue[0]);
-         TextMessage tm = (TextMessage)cons.receive(2000);
-
-         assertNotNull(tm);
-         assertEquals("clik", tm.getText());
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testConsumerFailoverWithConnectionStopped() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageConsumer cons = session.createConsumer(queue[1]);
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         // send a message (connection is stopped, so it will stay on the server), and I expect
-         // to receive it with the failed-over consumer after crash
-
-         Message m = session.createTextMessage("plik");
-         prod.send(m);
-
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         // activate the failed-over consumer
-         conn.start();
-
-         TextMessage rm = (TextMessage)cons.receive(2000);
-         assertNotNull(rm);
-         assertEquals("plik", rm.getText());
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testConsumerFailoverWithConnectionStarted() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageConsumer cons = session.createConsumer(queue[1]);
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         // start the connection, so the message makes it to the client-side MessageCallbackHandler
-         // buffer
-
-         conn.start();
-
-         Message m = session.createTextMessage("nik");
-         prod.send(m);
-
-         // wait a bit so the message makes it to the client
-         Thread.sleep(2000);
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-         
-         TextMessage rm = (TextMessage)cons.receive(2000);
-         assertNotNull(rm);
-         assertEquals("nik", rm.getText());
-         
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testBrowserFailoverSendMessagesPreFailure() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         // create a connection to node 1
-         conn = createConnectionOnServer(cf, 1);
-
-         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         QueueBrowser browser = session.createBrowser(queue[1]);
-
-         Enumeration en = browser.getEnumeration();
-         assertFalse(en.hasMoreElements());
-
-         // send one persistent and one non-persistent message
-
-         MessageProducer prod = session.createProducer(queue[1]);
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-         prod.send(session.createTextMessage("click"));
-         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-         prod.send(session.createTextMessage("clack"));
-         
-         //Give time for the NP message to arrive
-         Thread.sleep(2000);
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         en = browser.getEnumeration();
-
-         // we expect to only be able to browse the persistent message
-         assertTrue(en.hasMoreElements());
-         TextMessage tm = (TextMessage)en.nextElement();
-         assertEquals("click", tm.getText());
-
-         assertFalse(en.hasMoreElements());
-         
-         removeAllMessages(queue[1].getQueueName(), true, 0);
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testBrowserFailoverSendMessagesPostFailure() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         // create a connection to node 1
-         conn = createConnectionOnServer(cf, 1);
-
-         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         QueueBrowser browser = session.createBrowser(queue[1]);
-
-         Enumeration en = browser.getEnumeration();
-         assertFalse(en.hasMoreElements());
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         // send one persistent and one non-persistent message
-
-         MessageProducer prod = session.createProducer(queue[1]);
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-         prod.send(session.createTextMessage("click"));
-         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-         prod.send(session.createTextMessage("clack"));
-         
-         //Give time for the NP message to arrive         
-         Thread.sleep(2000);
-
-         en = browser.getEnumeration();
-
-         // we expect to be able to browse persistent and non-persistent messages
-         Set texts = new HashSet();
-
-         assertTrue(en.hasMoreElements());
-         TextMessage tm = (TextMessage)en.nextElement();
-         texts.add(tm.getText());
-
-         assertTrue(en.hasMoreElements());
-         tm = (TextMessage)en.nextElement();
-         texts.add(tm.getText());
-
-         assertFalse(en.hasMoreElements());
-
-         assertTrue(texts.contains("click"));
-         assertTrue(texts.contains("clack"));
-         
-         removeAllMessages(queue[1].getQueueName(), true, 0);
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   /**
-    * Sending one persistent message.
-    */
-   public void testSessionWithOneTransactedPersistentMessageFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         conn.start();
-
-         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
-         // send 2 transacted messages (one persistent and one non-persistent) but don't commit
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-         prod.send(session.createTextMessage("clik-persistent"));
-
-         // close the producer
-         prod.close();
-
-         log.debug("producer closed");
-
-         // create a consumer on the same local queue (creating a consumer AFTER failover will end
-         // up getting messages from a local queue, not a failed over queue; at least until
-         // redistribution is implemented.
-
-         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageConsumer cons = session2.createConsumer(queue[1]);
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         // commit the failed-over session
-         session.commit();
-
-         // make sure messages made it to the queue
-
-         TextMessage tm = (TextMessage)cons.receive(2000);
-         assertNotNull(tm);
-         assertEquals("clik-persistent", tm.getText());
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   /**
-    * Sending one non-persistent message.
-    */
-   public void testSessionWithOneTransactedNonPersistentMessageFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         conn.start();
-
-         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-         prod.send(session.createTextMessage("clik-non-persistent"));
-
-         // close the producer
-         prod.close();
-
-         log.debug("producer closed");
-
-         // create a consumer on the same local queue (creating a consumer AFTER failover will end
-         // up getting messages from a local queue, not a failed over queue; at least until
-         // redistribution is implemented.
-
-         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageConsumer cons = session2.createConsumer(queue[1]);
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-
-         assertEquals(0, getServerId(conn));
-
-         // commit the failed-over session
-         session.commit();
-
-         // make sure messages made it to the queue
-
-         TextMessage tm = (TextMessage)cons.receive(2000);
-         assertNotNull(tm);
-         assertEquals("clik-non-persistent", tm.getText());
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   /**
-    * Sending 2 non-persistent messages.
-    */
-   public void testSessionWithTwoTransactedNonPersistentMessagesFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         conn.start();
-
-         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
-         // send 2 transacted messages (one persistent and one non-persistent) but don't commit
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-         prod.send(session.createTextMessage("clik-non-persistent"));
-         prod.send(session.createTextMessage("clak-non-persistent"));
-
-         // close the producer
-         prod.close();
-
-         log.debug("producer closed");
-
-         // create a consumer on the same local queue (creating a consumer AFTER failover will end
-         // up getting messages from a local queue, not a failed over queue; at least until
-         // redistribution is implemented.
-
-         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageConsumer cons = session2.createConsumer(queue[1]);
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         // commit the failed-over session
-         session.commit();
-
-         // make sure messages made it to the queue
-
-         TextMessage tm = (TextMessage)cons.receive(2000);
-         assertNotNull(tm);
-         assertEquals("clik-non-persistent", tm.getText());
-
-         tm = (TextMessage)cons.receive(2000);
-         assertNotNull(tm);
-         assertEquals("clak-non-persistent", tm.getText());
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   /**
-    * Sending 2 persistent messages.
-    */
-   public void testSessionWithTwoTransactedPersistentMessagesFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         conn.start();
-
-         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
-         // send 2 transacted messages (one persistent and one non-persistent) but don't commit
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-         prod.send(session.createTextMessage("clik-persistent"));
-         prod.send(session.createTextMessage("clak-persistent"));
-
-         // close the producer
-         prod.close();
-
-         log.debug("producer closed");
-
-         // create a consumer on the same local queue (creating a consumer AFTER failover will end
-         // up getting messages from a local queue, not a failed over queue; at least until
-         // redistribution is implemented.
-
-         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageConsumer cons = session2.createConsumer(queue[1]);
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         // commit the failed-over session
-         session.commit();
-
-         // make sure messages made it to the queue
-
-         TextMessage tm = (TextMessage)cons.receive(2000);
-         assertNotNull(tm);
-         assertEquals("clik-persistent", tm.getText());
-
-         tm = (TextMessage)cons.receive(2000);
-         assertNotNull(tm);
-         assertEquals("clak-persistent", tm.getText());
-
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   /**
-    * Sending a mix of persistent and non-persistent messages.
-    */
-   public void testSessionWithTwoTransactedMixedMessagesFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         conn.start();
-
-         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
-         // send 2 transacted messages (one persistent and one non-persistent) but don't commit
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-         prod.send(session.createTextMessage("clik-non-persistent"));
-
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-         prod.send(session.createTextMessage("clak-persistent"));
-
-         // close the producer
-         prod.close();
-
-         log.debug("producer closed");
-
-         // create a consumer on the same local queue (creating a consumer AFTER failover will end
-         // up getting messages from a local queue, not a failed over queue; at least until
-         // redistribution is implemented.
-
-         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageConsumer cons = session2.createConsumer(queue[1]);
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         // commit the failed-over session
-         session.commit();
-
-         // make sure messages made it to the queue
-
-         TextMessage tm = (TextMessage)cons.receive(2000);
-         assertNotNull(tm);
-         assertEquals("clik-non-persistent", tm.getText());
-
-         tm = (TextMessage)cons.receive(2000);
-         assertNotNull(tm);
-         assertEquals("clak-persistent", tm.getText());
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testSessionWithAcknowledgmentsFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         conn.start();
-
-         Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
-         // send 2 messages (one persistent and one non-persistent)
-
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-         prod.send(session.createTextMessage("clik-persistent"));
-         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-         prod.send(session.createTextMessage("clak-non-persistent"));
-
-         // close the producer
-         prod.close();
-         
-         // create a consumer and receive messages, but don't acknowledge
-
-         MessageConsumer cons = session.createConsumer(queue[1]);
-         TextMessage clik = (TextMessage)cons.receive(2000);
-         assertEquals("clik-persistent", clik.getText());
-         TextMessage clak = (TextMessage)cons.receive(2000);
-         assertEquals("clak-non-persistent", clak.getText());
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         // acknowledge the messages
-         clik.acknowledge();
-         clak.acknowledge();
-
-         // make sure no messages are left in the queue
-         checkEmpty(queue[1], 0);
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testTransactedSessionWithAcknowledgmentsCommitOnFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         // create a connection to node 1
-         conn = this.createConnectionOnServer(cf, 1);
-
-         conn.start();
-
-         assertEquals(1, getServerId(conn));
-
-         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
-         // send 2 messages (one persistent and one non-persistent)
-
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-         prod.send(session.createTextMessage("clik-persistent"));
-         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-         prod.send(session.createTextMessage("clak-non-persistent"));
-
-         session.commit();
-
-         // close the producer
-   
-         prod.close();
-
-         // create a consumer and receive messages, but don't acknowledge
-
-         MessageConsumer cons = session.createConsumer(queue[1]);
-         TextMessage clik = (TextMessage)cons.receive(2000);
-         assertEquals("clik-persistent", clik.getText());
-         TextMessage clak = (TextMessage)cons.receive(2000);
-         assertEquals("clak-non-persistent", clak.getText());
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         // acknowledge the messages
-         session.commit();
-
-         // make sure no messages are left in the queue
-         checkEmpty(queue[1], 0);
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-   
-  
-   public void testTransactedSessionWithAcknowledgmentsRollbackOnFailover() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         conn.start();
-
-         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
-
-         // send 2 messages (one persistent and one non-persistent)
-
-         MessageProducer prod = session.createProducer(queue[1]);
-
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-         prod.send(session.createTextMessage("clik-persistent"));
-         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-         prod.send(session.createTextMessage("clak-non-persistent"));
-
-         session.commit();
-
-         // close the producer
-         prod.close();
-
-         // create a consumer and receive messages, but don't acknowledge
-
-         MessageConsumer cons = session.createConsumer(queue[1]);
-         TextMessage clik = (TextMessage)cons.receive(2000);
-         assertEquals("clik-persistent", clik.getText());
-         TextMessage clak = (TextMessage)cons.receive(2000);
-         assertEquals("clak-non-persistent", clak.getText());
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         assertEquals(0, getServerId(conn));
-
-         session.rollback();
-
-         TextMessage m = (TextMessage)cons.receive(2000);
-         assertNotNull(m);
-         assertEquals("clik-persistent", m.getText());
-
-         session.commit();
-         
-         checkEmpty(queue[1], 0);
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-
-   public void testFailoverListener() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-         conn.start();
-
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         // kill node 1
-
-         ServerManagement.kill(1);
-
-         FailoverEvent event = failoverListener.getEvent(30000);
-
-         assertNotNull(event);
-         assertEquals(FailoverEvent.FAILURE_DETECTED, event.getType());
-
-         event = failoverListener.getEvent(30000);
-
-         assertNotNull(event);
-         assertEquals(FailoverEvent.FAILOVER_STARTED, event.getType());
-
-         event = failoverListener.getEvent(30000);
-
-         assertNotNull(event);
-         assertEquals(FailoverEvent.FAILOVER_COMPLETED, event.getType());
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
- }
-
-   public void testFailoverMessageOnServer() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-         conn.start();
-
-         SimpleFailoverListener listener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(listener);
-
-         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageProducer prod = session.createProducer(queue[1]);
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-         MessageConsumer cons = session.createConsumer(queue[0]);
-
-         // send a message
-
-         prod.send(session.createTextMessage("blip"));
-
-         // kill node 1
-
-         ServerManagement.kill(1);
-
-         // wait until the failure (not the completion of client-side failover) is detected
-
-         while(true)
-         {
-            FailoverEvent event = listener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_STARTED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_STARTED event");
-            }
-         }
-
-         // start to receive the very next moment the failure is detected. This way, we also
-         // test the client-side failover valve
-
-         TextMessage tm = (TextMessage)cons.receive(60000);
-    
-         assertNotNull(tm);
-         assertEquals("blip", tm.getText());
-         
-         tm = (TextMessage)cons.receive(1000);
-         assertNull(tm);
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testFailoverMessageOnServer2() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-         conn.start();
-
-         SimpleFailoverListener listener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(listener);
-
-         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageProducer prod = session.createProducer(queue[1]);
-         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
-         // send a message
-
-         prod.send(session.createTextMessage("blip"));
-
-         // kill node 1
-
-         ServerManagement.kill(1);
-
-         // wait until the failure (not the completion of client-side failover) is detected
-
-         assertEquals(FailoverEvent.FAILURE_DETECTED, listener.getEvent(60000).getType());
-         
-         // create a consumer the very next moment the failure is detected. This way, we also
-         // test the client-side failover valve
-         
-         MessageConsumer cons = session.createConsumer(queue[1]);
-         
-         // we must receive the message
-
-         TextMessage tm = (TextMessage)cons.receive(60000);
-         assertEquals("blip", tm.getText());         
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   public void testSimpleFailover() throws Exception
-   {
-      simpleFailover(null, null);
-   }
-
-   public void testSimpleFailoverUserPassword() throws Exception
-   {
-      final String testTopicConf =
-         "<security>" +
-            "<role name=\"guest\" read=\"true\" write=\"true\"/>" +
-            "<role name=\"publisher\" read=\"true\" write=\"true\" create=\"false\"/>" +
-            "<role name=\"durpublisher\" read=\"true\" write=\"true\" create=\"true\"/>" +
-         "</security>";
-
-      ServerManagement.configureSecurityForDestination(0, "testDistributedQueue", testTopicConf);
-      ServerManagement.configureSecurityForDestination(1, "testDistributedQueue", testTopicConf);
-
-      simpleFailover("john", "needle");
-   }
-
-   public void testMethodSmackingIntoFailure() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-
-         // we "cripple" the remoting connection by removing ConnectionListener. This way, failures
-         // cannot be "cleanly" detected by the client-side pinger, and we'll fail on an invocation
-         JMSRemotingConnection rc = getDelegate(conn).getRemotingConnection();
-         rc.removeConnectionListener();
-
-         ServerManagement.kill(1);
-
-         conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-   // TODO what to do with this test?
-//   public void testFailureInTheMiddleOfAnInvocation() throws Exception
+//   public void testSimpleConnectionFailover() throws Exception
 //   {
+//   	//We need to sleep and relookup the connection factory due to http://jira.jboss.com/jira/browse/JBMESSAGING-1038
+//   	//remove this when this task is complete
+//   	Thread.sleep(2000);
+//   	
+//   	ConnectionFactory theCF = (ConnectionFactory)ic[0].lookup("/ClusteredConnectionFactory");
+//   	
 //      Connection conn = null;
 //
 //      try
 //      {
+//         conn = createConnectionOnServer(theCF, 1);
+//         conn.start();
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         assertEquals(0, getServerId(conn));
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//
+//   public void testSessionFailover() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
 //         conn = createConnectionOnServer(cf, 1);
+//         conn.start();
 //
-//         // we "cripple" the remoting connection by removing ConnectionListener. This way, failures
-//         // cannot be "cleanly" detected by the client-side pinger, and we'll fail on an invocation
-//         JMSRemotingConnection rc = ((ClientConnectionDelegate)((JBossConnection)conn).
-//            getDelegate()).getRemotingConnection();
-//         rc.removeConnectionListener();
+//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 //
+//         // register a failover listener
 //         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
 //         ((JBossConnection)conn).registerFailoverListener(failoverListener);
 //
-//         // poison the server
-//         ServerManagement.poisonTheServer(1, PoisonInterceptor.TYPE_CREATE_SESSION);
+//         ServerManagement.kill(1);
 //
-//         // this invocation will halt the server ...
-//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         // wait for the client-side failover to complete
 //
-//         // ... and hopefully it be failed over
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
 //
-//         MessageConsumer cons = session.createConsumer(queue[0]);
-//         MessageProducer prod = session.createProducer(queue[0]);
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//         
+//         // use the old session to send/receive a message
+//         session.createProducer(queue[0]).send(session.createTextMessage("blik"));
+//              
+//         TextMessage m = (TextMessage)session.createConsumer(queue[0]).receive(5000);
+//         
+//         assertNotNull(m);
+//         
+//         assertEquals("blik", m.getText());
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
 //
-//         prod.send(session.createTextMessage("after-poison"));
+//   public void testProducerFailover() throws Exception
+//   {
+//      Connection conn = null;
 //
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//
 //         conn.start();
 //
+//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageProducer prod = session.createProducer(queue[1]);
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         assertEquals(0, getServerId(conn));
+//
+//         // send a message, send it with the failed over producer and make sure I can receive it
+//         Message m = session.createTextMessage("clik");
+//         prod.send(m);
+//
+//         MessageConsumer cons = session.createConsumer(queue[0]);
 //         TextMessage tm = (TextMessage)cons.receive(2000);
 //
 //         assertNotNull(tm);
-//         assertEquals("after-poison", tm.getText());
+//         assertEquals("clik", tm.getText());
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
 //
+//   public void testConsumerFailoverWithConnectionStopped() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//
+//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageConsumer cons = session.createConsumer(queue[1]);
+//         MessageProducer prod = session.createProducer(queue[1]);
+//
+//         // send a message (connection is stopped, so it will stay on the server), and I expect
+//         // to receive it with the failed-over consumer after crash
+//
+//         Message m = session.createTextMessage("plik");
+//         prod.send(m);
+//
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//
+//         // activate the failed-over consumer
+//         conn.start();
+//
+//         TextMessage rm = (TextMessage)cons.receive(2000);
+//         assertNotNull(rm);
+//         assertEquals("plik", rm.getText());
 //      }
 //      finally
 //      {
@@ -1336,121 +262,602 @@
 //         }
 //      }
 //   }
-
-   public void testSimpleFailoverWithRemotingListenerEnabled() throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         conn = createConnectionOnServer(cf, 1);
-         conn.start();
-
-         Session s1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageConsumer c1 = s1.createConsumer(queue[1]);
-         MessageProducer p1 = s1.createProducer(queue[1]);
-         p1.setDeliveryMode(DeliveryMode.PERSISTENT);
-
-         // send a message
-
-         p1.send(s1.createTextMessage("blip"));
-
-         // kill node 1
-
-         ServerManagement.kill(1);
-
-         try
-         {
-            ic[1].lookup("queue"); // looking up anything
-            fail("The server still alive, kill didn't work yet");
-         }
-         catch (Exception e)
-         {
-         }
-
-         // we must receive the message
-
-         TextMessage tm = (TextMessage)c1.receive(3000);
-         assertEquals("blip", tm.getText());
-
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-//   public void testFailureRightAfterACK() throws Exception
+//
+//   public void testConsumerFailoverWithConnectionStarted() throws Exception
 //   {
-//      failureOnInvocation(PoisonInterceptor.FAIL_AFTER_ACKNOWLEDGE_DELIVERY);
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//
+//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageConsumer cons = session.createConsumer(queue[1]);
+//         MessageProducer prod = session.createProducer(queue[1]);
+//
+//         // start the connection, so the message makes it to the client-side MessageCallbackHandler
+//         // buffer
+//
+//         conn.start();
+//
+//         Message m = session.createTextMessage("nik");
+//         prod.send(m);
+//
+//         // wait a bit so the message makes it to the client
+//         Thread.sleep(2000);
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//         
+//         TextMessage rm = (TextMessage)cons.receive(2000);
+//         assertNotNull(rm);
+//         assertEquals("nik", rm.getText());
+//         
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
 //   }
 //
-//   public void testFailureRightBeforeACK() throws Exception
+//   public void testBrowserFailoverSendMessagesPreFailure() throws Exception
 //   {
-//      failureOnInvocation(PoisonInterceptor.FAIL_BEFORE_ACKNOWLEDGE_DELIVERY);
+//      Connection conn = null;
+//
+//      try
+//      {
+//         // create a connection to node 1
+//         conn = createConnectionOnServer(cf, 1);
+//
+//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//         QueueBrowser browser = session.createBrowser(queue[1]);
+//
+//         Enumeration en = browser.getEnumeration();
+//         assertFalse(en.hasMoreElements());
+//
+//         // send one persistent and one non-persistent message
+//
+//         MessageProducer prod = session.createProducer(queue[1]);
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         prod.send(session.createTextMessage("click"));
+//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+//         prod.send(session.createTextMessage("clack"));
+//         
+//         //Give time for the NP message to arrive
+//         Thread.sleep(2000);
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//
+//         en = browser.getEnumeration();
+//
+//         // we expect to only be able to browse the persistent message
+//         assertTrue(en.hasMoreElements());
+//         TextMessage tm = (TextMessage)en.nextElement();
+//         assertEquals("click", tm.getText());
+//
+//         assertFalse(en.hasMoreElements());
+//         
+//         removeAllMessages(queue[1].getQueueName(), true, 0);
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
 //   }
 //
-//   public void testFailureRightBeforeSend() throws Exception
+//   public void testBrowserFailoverSendMessagesPostFailure() throws Exception
 //   {
-//      failureOnInvocation(PoisonInterceptor.FAIL_BEFORE_SEND);
+//      Connection conn = null;
+//
+//      try
+//      {
+//         // create a connection to node 1
+//         conn = createConnectionOnServer(cf, 1);
+//
+//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//         QueueBrowser browser = session.createBrowser(queue[1]);
+//
+//         Enumeration en = browser.getEnumeration();
+//         assertFalse(en.hasMoreElements());
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//
+//         // send one persistent and one non-persistent message
+//
+//         MessageProducer prod = session.createProducer(queue[1]);
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         prod.send(session.createTextMessage("click"));
+//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+//         prod.send(session.createTextMessage("clack"));
+//         
+//         //Give time for the NP message to arrive         
+//         Thread.sleep(2000);
+//
+//         en = browser.getEnumeration();
+//
+//         // we expect to be able to browse persistent and non-persistent messages
+//         Set texts = new HashSet();
+//
+//         assertTrue(en.hasMoreElements());
+//         TextMessage tm = (TextMessage)en.nextElement();
+//         texts.add(tm.getText());
+//
+//         assertTrue(en.hasMoreElements());
+//         tm = (TextMessage)en.nextElement();
+//         texts.add(tm.getText());
+//
+//         assertFalse(en.hasMoreElements());
+//
+//         assertTrue(texts.contains("click"));
+//         assertTrue(texts.contains("clack"));
+//         
+//         removeAllMessages(queue[1].getQueueName(), true, 0);
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
 //   }
 //
-//   public void testFailureRightAfterSend() throws Exception
+//   /**
+//    * Sending one persistent message.
+//    */
+//   public void testSessionWithOneTransactedPersistentMessageFailover() throws Exception
 //   {
-//      failureOnInvocation(PoisonInterceptor.FAIL_AFTER_SEND);
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//
+//         conn.start();
+//
+//         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+//
+//         // send 2 transacted messages (one persistent and one non-persistent) but don't commit
+//         MessageProducer prod = session.createProducer(queue[1]);
+//
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         prod.send(session.createTextMessage("clik-persistent"));
+//
+//         // close the producer
+//         prod.close();
+//
+//         log.debug("producer closed");
+//
+//         // create a consumer on the same local queue (creating a consumer AFTER failover will end
+//         // up getting messages from a local queue, not a failed over queue; at least until
+//         // redistribution is implemented.
+//
+//         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageConsumer cons = session2.createConsumer(queue[1]);
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//
+//         // commit the failed-over session
+//         session.commit();
+//
+//         // make sure messages made it to the queue
+//
+//         TextMessage tm = (TextMessage)cons.receive(2000);
+//         assertNotNull(tm);
+//         assertEquals("clik-persistent", tm.getText());
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
 //   }
-
-//   public void testFailureRightAfterSendTransaction() throws Exception
+//
+//   /**
+//    * Sending one non-persistent message.
+//    */
+//   public void testSessionWithOneTransactedNonPersistentMessageFailover() throws Exception
 //   {
 //      Connection conn = null;
 //
 //      try
 //      {
-//         conn = this.createConnectionOnServer(cf, 1);
+//         conn = createConnectionOnServer(cf, 1);
 //
-//         assertEquals(1, getServerId(conn));
+//         conn.start();
 //
-//         // we "cripple" the remoting connection by removing ConnectionListener. This way, failures
-//         // cannot be "cleanly" detected by the client-side pinger, and we'll fail on an invocation
-//         JMSRemotingConnection rc = ((ClientConnectionDelegate)((JBossConnection)conn).
-//            getDelegate()).getRemotingConnection();
-//         rc.removeConnectionListener();
+//         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
 //
-//         // poison the server
-//         ServerManagement.poisonTheServer(1, PoisonInterceptor.FAIL_AFTER_SENDTRANSACTION);
+//         MessageProducer prod = session.createProducer(queue[1]);
 //
+//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+//         prod.send(session.createTextMessage("clik-non-persistent"));
+//
+//         // close the producer
+//         prod.close();
+//
+//         log.debug("producer closed");
+//
+//         // create a consumer on the same local queue (creating a consumer AFTER failover will end
+//         // up getting messages from a local queue, not a failed over queue; at least until
+//         // redistribution is implemented.
+//
+//         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageConsumer cons = session2.createConsumer(queue[1]);
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//
+//         assertEquals(0, getServerId(conn));
+//
+//         // commit the failed-over session
+//         session.commit();
+//
+//         // make sure messages made it to the queue
+//
+//         TextMessage tm = (TextMessage)cons.receive(2000);
+//         assertNotNull(tm);
+//         assertEquals("clik-non-persistent", tm.getText());
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//
+//   /**
+//    * Sending 2 non-persistent messages.
+//    */
+//   public void testSessionWithTwoTransactedNonPersistentMessagesFailover() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//
+//         conn.start();
+//
 //         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
 //
+//         // send 2 transacted messages (one persistent and one non-persistent) but don't commit
+//         MessageProducer prod = session.createProducer(queue[1]);
+//
+//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+//         prod.send(session.createTextMessage("clik-non-persistent"));
+//         prod.send(session.createTextMessage("clak-non-persistent"));
+//
+//         // close the producer
+//         prod.close();
+//
+//         log.debug("producer closed");
+//
+//         // create a consumer on the same local queue (creating a consumer AFTER failover will end
+//         // up getting messages from a local queue, not a failed over queue; at least until
+//         // redistribution is implemented.
+//
+//         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageConsumer cons = session2.createConsumer(queue[1]);
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//
+//         // commit the failed-over session
+//         session.commit();
+//
+//         // make sure messages made it to the queue
+//
+//         TextMessage tm = (TextMessage)cons.receive(2000);
+//         assertNotNull(tm);
+//         assertEquals("clik-non-persistent", tm.getText());
+//
+//         tm = (TextMessage)cons.receive(2000);
+//         assertNotNull(tm);
+//         assertEquals("clak-non-persistent", tm.getText());
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//
+//   /**
+//    * Sending 2 persistent messages.
+//    */
+//   public void testSessionWithTwoTransactedPersistentMessagesFailover() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//
 //         conn.start();
 //
-//         MessageProducer producer = session.createProducer(queue[0]);
+//         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
 //
-//         producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         // send 2 transacted messages (one persistent and one non-persistent) but don't commit
+//         MessageProducer prod = session.createProducer(queue[1]);
 //
-//         MessageConsumer consumer = session.createConsumer(queue[0]);
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         prod.send(session.createTextMessage("clik-persistent"));
+//         prod.send(session.createTextMessage("clak-persistent"));
 //
-//         producer.send(session.createTextMessage("before-poison1"));
-//         producer.send(session.createTextMessage("before-poison2"));
-//         producer.send(session.createTextMessage("before-poison3"));
+//         // close the producer
+//         prod.close();
+//
+//         log.debug("producer closed");
+//
+//         // create a consumer on the same local queue (creating a consumer AFTER failover will end
+//         // up getting messages from a local queue, not a failed over queue; at least until
+//         // redistribution is implemented.
+//
+//         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageConsumer cons = session2.createConsumer(queue[1]);
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//
+//         // commit the failed-over session
 //         session.commit();
 //
-//         Thread.sleep(2000);
+//         // make sure messages made it to the queue
 //
-//         for (int i = 1; i <= 3; i++)
+//         TextMessage tm = (TextMessage)cons.receive(2000);
+//         assertNotNull(tm);
+//         assertEquals("clik-persistent", tm.getText());
+//
+//         tm = (TextMessage)cons.receive(2000);
+//         assertNotNull(tm);
+//         assertEquals("clak-persistent", tm.getText());
+//
+//      }
+//      finally
+//      {
+//         if (conn != null)
 //         {
-//            TextMessage tm = (TextMessage) consumer.receive(5000);
+//            conn.close();
+//         }
+//      }
+//   }
 //
-//            assertNotNull(tm);
+//   /**
+//    * Sending a mix of persistent and non-persistent messages.
+//    */
+//   public void testSessionWithTwoTransactedMixedMessagesFailover() throws Exception
+//   {
+//      Connection conn = null;
 //
-//            assertEquals("before-poison" + i, tm.getText());
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//
+//         conn.start();
+//
+//         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+//
+//         // send 2 transacted messages (one persistent and one non-persistent) but don't commit
+//         MessageProducer prod = session.createProducer(queue[1]);
+//
+//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+//         prod.send(session.createTextMessage("clik-non-persistent"));
+//
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         prod.send(session.createTextMessage("clak-persistent"));
+//
+//         // close the producer
+//         prod.close();
+//
+//         log.debug("producer closed");
+//
+//         // create a consumer on the same local queue (creating a consumer AFTER failover will end
+//         // up getting messages from a local queue, not a failed over queue; at least until
+//         // redistribution is implemented.
+//
+//         Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageConsumer cons = session2.createConsumer(queue[1]);
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
 //         }
 //
-//         assertNull(consumer.receive(3000));
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
 //
+//         // commit the failed-over session
 //         session.commit();
+//
+//         // make sure messages made it to the queue
+//
+//         TextMessage tm = (TextMessage)cons.receive(2000);
+//         assertNotNull(tm);
+//         assertEquals("clik-non-persistent", tm.getText());
+//
+//         tm = (TextMessage)cons.receive(2000);
+//         assertNotNull(tm);
+//         assertEquals("clak-persistent", tm.getText());
 //      }
 //      finally
 //      {
@@ -1460,390 +867,512 @@
 //         }
 //      }
 //   }
-
-   public void testCloseConsumer() throws Exception
-   {
-      Connection conn0 = null;
-      Connection conn1 = null;
-
-      try
-      {
-         conn0 = createConnectionOnServer(cf, 0);
-
-         // Objects Server1
-         conn1 = createConnectionOnServer(cf, 1);
-
-         assertEquals(1, getServerId(conn1));
-
-         JMSRemotingConnection rc = getDelegate(conn1).getRemotingConnection();
-         rc.removeConnectionListener();
-
-         Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         MessageConsumer consumer = session1.createConsumer(queue[1]);
-
-         ServerManagement.kill(1);
-
-         consumer.close();
-      }
-      finally
-      {
-         if (conn1 != null)
-         {
-            conn1.close();
-         }
-
-         if (conn0 != null)
-         {
-            conn0.close();
-         }
-      }
-   }
-
-   public void testCloseBrowser() throws Exception
-   {
-      Connection conn0 = null;
-      Connection conn1 = null;
-
-      try
-      {
-         conn0 = createConnectionOnServer(cf, 0);
-
-         // Objects Server1
-         conn1 = createConnectionOnServer(cf, 1);
-
-         assertEquals(1, getServerId(conn1));
-
-         JMSRemotingConnection rc = getDelegate(conn1).getRemotingConnection();
-         rc.removeConnectionListener();
-
-         Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         QueueBrowser browser = session1.createBrowser(queue[1]);
-
-         ServerManagement.kill(1);
-
-         browser.close();
-      }
-      finally
-      {
-         if (conn1 != null)
-         {
-            conn1.close();
-         }
-
-         if (conn0 != null)
-         {
-            conn0.close();
-         }
-      }
-   }
-
-
-   public void testCloseSession() throws Exception
-   {
-      Connection conn0 = null;
-      Connection conn1 = null;
-
-      try
-      {
-         conn0 = createConnectionOnServer(cf, 0);
-
-         conn1 = createConnectionOnServer(cf, 1);
-
-         assertEquals(1, getServerId(conn1));
-
-         JMSRemotingConnection rc = getDelegate(conn1).getRemotingConnection();
-         rc.removeConnectionListener();
-
-         Session session = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         ServerManagement.kill(1);
-
-         session.close();
-      }
-      finally
-      {
-         if (conn1 != null)
-         {
-            conn1.close();
-         }
-
-         if (conn0 != null)
-         {
-            conn0.close();
-         }
-      }
-   }
-
-   public void testCloseConnection() throws Exception
-   {
-      Connection conn0 = null;
-      Connection conn1 = null;
-
-      try
-      {
-         conn0 = createConnectionOnServer(cf, 0);
-
-         conn1 = createConnectionOnServer(cf, 1);
-
-         assertEquals(1, getServerId(conn1));
-
-         ClientConnectionDelegate delegate = getDelegate (conn1);
-         JMSRemotingConnection rc = delegate.getRemotingConnection();
-         rc.removeConnectionListener();
-
-         ServerManagement.kill(1);
-
-         conn1.close();
-      }
-      finally
-      {
-         if (conn0 != null)
-         {
-            conn0.close();
-         }
-      }
-   }
-
-   public void testFailoverDeliveryRecoveryTransacted() throws Exception
-   {
-      Connection conn0 = null;
-      Connection conn1 = null;
-
-      try
-      {
-         conn0 = this.createConnectionOnServer(cf, 0);
-         
-         assertEquals(0, ((JBossConnection)conn0).getServerID());
-
-         // Objects Server1
-         conn1 = this.createConnectionOnServer(cf, 1);
-
-         assertEquals(1, ((JBossConnection)conn1).getServerID());
-
-         Session session1 = conn1.createSession(true, Session.SESSION_TRANSACTED);
-         
-         Session session2 = conn1.createSession(true, Session.SESSION_TRANSACTED);
-
-         MessageConsumer cons1 = session1.createConsumer(queue[1]);
-         
-         MessageConsumer cons2 = session2.createConsumer(queue[1]);
-         
-         MessageProducer prod = session1.createProducer(queue[1]);
-         
-         conn1.start();
-                  
-         TextMessage tm1 = session1.createTextMessage("message1");
-         
-         TextMessage tm2 = session1.createTextMessage("message2");
-         
-         TextMessage tm3 = session1.createTextMessage("message3");
-         
-         prod.send(tm1);
-         
-         prod.send(tm2);
-         
-         prod.send(tm3);
-         
-         session1.commit();
-                           
-         TextMessage rm1 = (TextMessage)cons1.receive(3000);
-         
-         assertNotNull(rm1);
-         
-         assertEquals(tm1.getText(), rm1.getText());
-                                    
-         TextMessage rm2 = (TextMessage)cons2.receive(3000);
-         
-         assertNotNull(rm2);
-         
-         assertEquals(tm2.getText(), rm2.getText());
-         
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn1).registerFailoverListener(failoverListener);
-
-         ServerManagement.kill(1);
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         
-         //now commit
-         
-         session1.commit();
-         
-         session2.commit();
-         
-         session1.close();
-         
-         session2.close();;
-         
-         Session session3 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
-         MessageConsumer cons3 = session3.createConsumer(queue[0]);
-         
-         TextMessage rm3 = (TextMessage)cons3.receive(2000);
-         
-         assertNotNull(rm3);
-         
-         assertEquals(tm3.getText(), rm3.getText());
-         
-         checkEmpty(queue[1], 0);
-      }
-      finally
-      {
-         if (conn1 != null)
-         {
-            conn1.close();
-         }
-
-         if (conn0 != null)
-         {
-            conn0.close();
-         }
-      }
-   }
-    
-
-   // Package protected ----------------------------------------------------------------------------
-
-   // Protected ------------------------------------------------------------------------------------
-
-   protected void setUp() throws Exception
-   {
-      nodeCount = 2;
-
-      super.setUp();
-   }
-
-   // Private --------------------------------------------------------------------------------------
-   
-   private void simpleFailover(String userName, String password) throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         if (userName!=null)
-         {
-            conn = createConnectionOnServer(cf, 1, userName, password);
-         }
-         else
-         {
-            conn = createConnectionOnServer(cf, 1);
-         }
-         
-         conn.start();
-
-         // Disable Lease for this test.. as the ValveAspect should capture this
-         getConnectionState(conn).getRemotingConnection().removeConnectionListener();
-
-         // make sure we're connecting to node 1
-
-         int nodeID = getServerId(conn);
-
-         assertEquals(1, nodeID);
-
-         Session s1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageConsumer c1 = s1.createConsumer(queue[1]);
-         MessageProducer p1 = s1.createProducer(queue[1]);
-         p1.setDeliveryMode(DeliveryMode.PERSISTENT);
-
-         // send a message
-
-         p1.send(s1.createTextMessage("blip"));
-
-         // kill node 1
-
-         ServerManagement.kill(1);
-
-         try
-         {
-            ic[1].lookup("queue"); // looking up anything
-            fail("The server still alive, kill didn't work yet");
-         }
-         catch (Exception e)
-         {
-         }
-
-         // we must receive the message
-
-         TextMessage tm = (TextMessage)c1.receive(3000);
-         assertNotNull(tm);
-         assertEquals("blip", tm.getText());
-
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-
-//   // Used for both testFailureRightAfterACK and  testFailureRightBeforeACK
-//   private void failureOnInvocation(int typeOfFailure) throws Exception
+//
+//   public void testSessionWithAcknowledgmentsFailover() throws Exception
 //   {
 //      Connection conn = null;
-//      Connection conn0 = null;
 //
 //      try
 //      {
 //         conn = createConnectionOnServer(cf, 1);
 //
+//         conn.start();
+//
+//         Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+//
+//         // send 2 messages (one persistent and one non-persistent)
+//
+//         MessageProducer prod = session.createProducer(queue[1]);
+//
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         prod.send(session.createTextMessage("clik-persistent"));
+//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+//         prod.send(session.createTextMessage("clak-non-persistent"));
+//
+//         // close the producer
+//         prod.close();
+//         
+//         // create a consumer and receive messages, but don't acknowledge
+//
+//         MessageConsumer cons = session.createConsumer(queue[1]);
+//         TextMessage clik = (TextMessage)cons.receive(2000);
+//         assertEquals("clik-persistent", clik.getText());
+//         TextMessage clak = (TextMessage)cons.receive(2000);
+//         assertEquals("clak-non-persistent", clak.getText());
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//
+//         // acknowledge the messages
+//         clik.acknowledge();
+//         clak.acknowledge();
+//
+//         // make sure no messages are left in the queue
+//         checkEmpty(queue[1], 0);
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//
+//   public void testTransactedSessionWithAcknowledgmentsCommitOnFailover() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         // create a connection to node 1
+//         conn = this.createConnectionOnServer(cf, 1);
+//
+//         conn.start();
+//
 //         assertEquals(1, getServerId(conn));
 //
+//         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+//
+//         // send 2 messages (one persistent and one non-persistent)
+//
+//         MessageProducer prod = session.createProducer(queue[1]);
+//
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         prod.send(session.createTextMessage("clik-persistent"));
+//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+//         prod.send(session.createTextMessage("clak-non-persistent"));
+//
+//         session.commit();
+//
+//         // close the producer
+//   
+//         prod.close();
+//
+//         // create a consumer and receive messages, but don't acknowledge
+//
+//         MessageConsumer cons = session.createConsumer(queue[1]);
+//         TextMessage clik = (TextMessage)cons.receive(2000);
+//         assertEquals("clik-persistent", clik.getText());
+//         TextMessage clak = (TextMessage)cons.receive(2000);
+//         assertEquals("clak-non-persistent", clak.getText());
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//
+//         // acknowledge the messages
+//         session.commit();
+//
+//         // make sure no messages are left in the queue
+//         checkEmpty(queue[1], 0);
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//   
+//  
+//   public void testTransactedSessionWithAcknowledgmentsRollbackOnFailover() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//
+//         conn.start();
+//
+//         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+//
+//         // send 2 messages (one persistent and one non-persistent)
+//
+//         MessageProducer prod = session.createProducer(queue[1]);
+//
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         prod.send(session.createTextMessage("clik-persistent"));
+//         prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+//         prod.send(session.createTextMessage("clak-non-persistent"));
+//
+//         session.commit();
+//
+//         // close the producer
+//         prod.close();
+//
+//         // create a consumer and receive messages, but don't acknowledge
+//
+//         MessageConsumer cons = session.createConsumer(queue[1]);
+//         TextMessage clik = (TextMessage)cons.receive(2000);
+//         assertEquals("clik-persistent", clik.getText());
+//         TextMessage clak = (TextMessage)cons.receive(2000);
+//         assertEquals("clak-non-persistent", clak.getText());
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         assertEquals(0, getServerId(conn));
+//
+//         session.rollback();
+//
+//         TextMessage m = (TextMessage)cons.receive(2000);
+//         assertNotNull(m);
+//         assertEquals("clik-persistent", m.getText());
+//
+//         session.commit();
+//         
+//         checkEmpty(queue[1], 0);
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//
+//
+//   public void testFailoverListener() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//         conn.start();
+//
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         // kill node 1
+//
+//         ServerManagement.kill(1);
+//
+//         FailoverEvent event = failoverListener.getEvent(30000);
+//
+//         assertNotNull(event);
+//         assertEquals(FailoverEvent.FAILURE_DETECTED, event.getType());
+//
+//         event = failoverListener.getEvent(30000);
+//
+//         assertNotNull(event);
+//         assertEquals(FailoverEvent.FAILOVER_STARTED, event.getType());
+//
+//         event = failoverListener.getEvent(30000);
+//
+//         assertNotNull(event);
+//         assertEquals(FailoverEvent.FAILOVER_COMPLETED, event.getType());
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+// }
+//
+//   public void testFailoverMessageOnServer() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//         conn.start();
+//
+//         SimpleFailoverListener listener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(listener);
+//
+//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageProducer prod = session.createProducer(queue[1]);
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         MessageConsumer cons = session.createConsumer(queue[0]);
+//
+//         // send a message
+//
+//         prod.send(session.createTextMessage("blip"));
+//
+//         // kill node 1
+//
+//         ServerManagement.kill(1);
+//
+//         // wait until the failure (not the completion of client-side failover) is detected
+//
+//         while(true)
+//         {
+//            FailoverEvent event = listener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_STARTED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_STARTED event");
+//            }
+//         }
+//
+//         // start to receive the very next moment the failure is detected. This way, we also
+//         // test the client-side failover valve
+//
+//         TextMessage tm = (TextMessage)cons.receive(60000);
+//    
+//         assertNotNull(tm);
+//         assertEquals("blip", tm.getText());
+//         
+//         tm = (TextMessage)cons.receive(1000);
+//         assertNull(tm);
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//
+//   public void testFailoverMessageOnServer2() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//         conn.start();
+//
+//         SimpleFailoverListener listener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(listener);
+//
+//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageProducer prod = session.createProducer(queue[1]);
+//         prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//
+//         // send a message
+//
+//         prod.send(session.createTextMessage("blip"));
+//
+//         // kill node 1
+//
+//         ServerManagement.kill(1);
+//
+//         // wait until the failure (not the completion of client-side failover) is detected
+//
+//         assertEquals(FailoverEvent.FAILURE_DETECTED, listener.getEvent(60000).getType());
+//         
+//         // create a consumer the very next moment the failure is detected. This way, we also
+//         // test the client-side failover valve
+//         
+//         MessageConsumer cons = session.createConsumer(queue[1]);
+//         
+//         // we must receive the message
+//
+//         TextMessage tm = (TextMessage)cons.receive(60000);
+//         assertEquals("blip", tm.getText());         
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//
+//   public void testSimpleFailover() throws Exception
+//   {
+//      simpleFailover(null, null);
+//   }
+//
+//   public void testSimpleFailoverUserPassword() throws Exception
+//   {
+//      final String testTopicConf =
+//         "<security>" +
+//            "<role name=\"guest\" read=\"true\" write=\"true\"/>" +
+//            "<role name=\"publisher\" read=\"true\" write=\"true\" create=\"false\"/>" +
+//            "<role name=\"durpublisher\" read=\"true\" write=\"true\" create=\"true\"/>" +
+//         "</security>";
+//
+//      ServerManagement.configureSecurityForDestination(0, "testDistributedQueue", testTopicConf);
+//      ServerManagement.configureSecurityForDestination(1, "testDistributedQueue", testTopicConf);
+//
+//      simpleFailover("john", "needle");
+//   }
+//
+//   public void testMethodSmackingIntoFailure() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
+//
 //         // we "cripple" the remoting connection by removing ConnectionListener. This way, failures
 //         // cannot be "cleanly" detected by the client-side pinger, and we'll fail on an invocation
-//         JMSRemotingConnection rc = ((ClientConnectionDelegate)((JBossConnection)conn).
-//            getDelegate()).getRemotingConnection();
+//         JMSRemotingConnection rc = getDelegate(conn).getRemotingConnection();
 //         rc.removeConnectionListener();
 //
-//         // poison the server
-//         ServerManagement.poisonTheServer(1, typeOfFailure);
+//         ServerManagement.kill(1);
 //
-//         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
 //
+//   // TODO what to do with this test?
+////   public void testFailureInTheMiddleOfAnInvocation() throws Exception
+////   {
+////      Connection conn = null;
+////
+////      try
+////      {
+////         conn = createConnectionOnServer(cf, 1);
+////
+////         // we "cripple" the remoting connection by removing ConnectionListener. This way, failures
+////         // cannot be "cleanly" detected by the client-side pinger, and we'll fail on an invocation
+////         JMSRemotingConnection rc = ((ClientConnectionDelegate)((JBossConnection)conn).
+////            getDelegate()).getRemotingConnection();
+////         rc.removeConnectionListener();
+////
+////         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+////         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+////
+////         // poison the server
+////         ServerManagement.poisonTheServer(1, PoisonInterceptor.TYPE_CREATE_SESSION);
+////
+////         // this invocation will halt the server ...
+////         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+////
+////         // ... and hopefully it be failed over
+////
+////         MessageConsumer cons = session.createConsumer(queue[0]);
+////         MessageProducer prod = session.createProducer(queue[0]);
+////
+////         prod.send(session.createTextMessage("after-poison"));
+////
+////         conn.start();
+////
+////         TextMessage tm = (TextMessage)cons.receive(2000);
+////
+////         assertNotNull(tm);
+////         assertEquals("after-poison", tm.getText());
+////
+////      }
+////      finally
+////      {
+////         if (conn != null)
+////         {
+////            conn.close();
+////         }
+////      }
+////   }
+//
+//   public void testSimpleFailoverWithRemotingListenerEnabled() throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         conn = createConnectionOnServer(cf, 1);
 //         conn.start();
 //
-//         MessageProducer producer = session.createProducer(queue[0]);
+//         Session s1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageConsumer c1 = s1.createConsumer(queue[1]);
+//         MessageProducer p1 = s1.createProducer(queue[1]);
+//         p1.setDeliveryMode(DeliveryMode.PERSISTENT);
 //
-//         producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+//         // send a message
 //
-//         MessageConsumer consumer = session.createConsumer(queue[0]);
+//         p1.send(s1.createTextMessage("blip"));
 //
-//         producer.send(session.createTextMessage("before-poison"));
+//         // kill node 1
 //
-//         TextMessage tm = (TextMessage)consumer.receive(5000);
+//         ServerManagement.kill(1);
 //
-//         if(typeOfFailure == PoisonInterceptor.FAIL_AFTER_ACKNOWLEDGE_DELIVERY)
+//         try
 //         {
-//         	//With auto_ack we won't the message - remember auto ack is "at most once"
-//         	assertNull(tm);
+//            ic[1].lookup("queue"); // looking up anything
+//            fail("The server still alive, kill didn't work yet");
 //         }
-//         else
+//         catch (Exception e)
 //         {
-//            assertNotNull(tm);
-//
-//            assertEquals("before-poison", tm.getText());
 //         }
 //
-//         checkEmpty(queue[1], 0);
+//         // we must receive the message
+//
+//         TextMessage tm = (TextMessage)c1.receive(3000);
+//         assertEquals("blip", tm.getText());
+//
 //      }
 //      finally
 //      {
@@ -1851,6 +1380,119 @@
 //         {
 //            conn.close();
 //         }
+//      }
+//   }
+//
+////   public void testFailureRightAfterACK() throws Exception
+////   {
+////      failureOnInvocation(PoisonInterceptor.FAIL_AFTER_ACKNOWLEDGE_DELIVERY);
+////   }
+////
+////   public void testFailureRightBeforeACK() throws Exception
+////   {
+////      failureOnInvocation(PoisonInterceptor.FAIL_BEFORE_ACKNOWLEDGE_DELIVERY);
+////   }
+////
+////   public void testFailureRightBeforeSend() throws Exception
+////   {
+////      failureOnInvocation(PoisonInterceptor.FAIL_BEFORE_SEND);
+////   }
+////
+////   public void testFailureRightAfterSend() throws Exception
+////   {
+////      failureOnInvocation(PoisonInterceptor.FAIL_AFTER_SEND);
+////   }
+//
+////   public void testFailureRightAfterSendTransaction() throws Exception
+////   {
+////      Connection conn = null;
+////
+////      try
+////      {
+////         conn = this.createConnectionOnServer(cf, 1);
+////
+////         assertEquals(1, getServerId(conn));
+////
+////         // we "cripple" the remoting connection by removing ConnectionListener. This way, failures
+////         // cannot be "cleanly" detected by the client-side pinger, and we'll fail on an invocation
+////         JMSRemotingConnection rc = ((ClientConnectionDelegate)((JBossConnection)conn).
+////            getDelegate()).getRemotingConnection();
+////         rc.removeConnectionListener();
+////
+////         // poison the server
+////         ServerManagement.poisonTheServer(1, PoisonInterceptor.FAIL_AFTER_SENDTRANSACTION);
+////
+////         Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+////
+////         conn.start();
+////
+////         MessageProducer producer = session.createProducer(queue[0]);
+////
+////         producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+////
+////         MessageConsumer consumer = session.createConsumer(queue[0]);
+////
+////         producer.send(session.createTextMessage("before-poison1"));
+////         producer.send(session.createTextMessage("before-poison2"));
+////         producer.send(session.createTextMessage("before-poison3"));
+////         session.commit();
+////
+////         Thread.sleep(2000);
+////
+////         for (int i = 1; i <= 3; i++)
+////         {
+////            TextMessage tm = (TextMessage) consumer.receive(5000);
+////
+////            assertNotNull(tm);
+////
+////            assertEquals("before-poison" + i, tm.getText());
+////         }
+////
+////         assertNull(consumer.receive(3000));
+////
+////         session.commit();
+////      }
+////      finally
+////      {
+////         if (conn != null)
+////         {
+////            conn.close();
+////         }
+////      }
+////   }
+//
+//   public void testCloseConsumer() throws Exception
+//   {
+//      Connection conn0 = null;
+//      Connection conn1 = null;
+//
+//      try
+//      {
+//         conn0 = createConnectionOnServer(cf, 0);
+//
+//         // Objects Server1
+//         conn1 = createConnectionOnServer(cf, 1);
+//
+//         assertEquals(1, getServerId(conn1));
+//
+//         JMSRemotingConnection rc = getDelegate(conn1).getRemotingConnection();
+//         rc.removeConnectionListener();
+//
+//         Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//         MessageConsumer consumer = session1.createConsumer(queue[1]);
+//
+//         ServerManagement.kill(1);
+//
+//         consumer.close();
+//      }
+//      finally
+//      {
+//         if (conn1 != null)
+//         {
+//            conn1.close();
+//         }
+//
 //         if (conn0 != null)
 //         {
 //            conn0.close();
@@ -1858,7 +1500,365 @@
 //      }
 //   }
 //
-   
+//   public void testCloseBrowser() throws Exception
+//   {
+//      Connection conn0 = null;
+//      Connection conn1 = null;
+//
+//      try
+//      {
+//         conn0 = createConnectionOnServer(cf, 0);
+//
+//         // Objects Server1
+//         conn1 = createConnectionOnServer(cf, 1);
+//
+//         assertEquals(1, getServerId(conn1));
+//
+//         JMSRemotingConnection rc = getDelegate(conn1).getRemotingConnection();
+//         rc.removeConnectionListener();
+//
+//         Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//         QueueBrowser browser = session1.createBrowser(queue[1]);
+//
+//         ServerManagement.kill(1);
+//
+//         browser.close();
+//      }
+//      finally
+//      {
+//         if (conn1 != null)
+//         {
+//            conn1.close();
+//         }
+//
+//         if (conn0 != null)
+//         {
+//            conn0.close();
+//         }
+//      }
+//   }
+//
+//
+//   public void testCloseSession() throws Exception
+//   {
+//      Connection conn0 = null;
+//      Connection conn1 = null;
+//
+//      try
+//      {
+//         conn0 = createConnectionOnServer(cf, 0);
+//
+//         conn1 = createConnectionOnServer(cf, 1);
+//
+//         assertEquals(1, getServerId(conn1));
+//
+//         JMSRemotingConnection rc = getDelegate(conn1).getRemotingConnection();
+//         rc.removeConnectionListener();
+//
+//         Session session = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//         ServerManagement.kill(1);
+//
+//         session.close();
+//      }
+//      finally
+//      {
+//         if (conn1 != null)
+//         {
+//            conn1.close();
+//         }
+//
+//         if (conn0 != null)
+//         {
+//            conn0.close();
+//         }
+//      }
+//   }
+//
+//   public void testCloseConnection() throws Exception
+//   {
+//      Connection conn0 = null;
+//      Connection conn1 = null;
+//
+//      try
+//      {
+//         conn0 = createConnectionOnServer(cf, 0);
+//
+//         conn1 = createConnectionOnServer(cf, 1);
+//
+//         assertEquals(1, getServerId(conn1));
+//
+//         ClientConnectionDelegate delegate = getDelegate (conn1);
+//         JMSRemotingConnection rc = delegate.getRemotingConnection();
+//         rc.removeConnectionListener();
+//
+//         ServerManagement.kill(1);
+//
+//         conn1.close();
+//      }
+//      finally
+//      {
+//         if (conn0 != null)
+//         {
+//            conn0.close();
+//         }
+//      }
+//   }
+//
+//   public void testFailoverDeliveryRecoveryTransacted() throws Exception
+//   {
+//      Connection conn0 = null;
+//      Connection conn1 = null;
+//
+//      try
+//      {
+//         conn0 = this.createConnectionOnServer(cf, 0);
+//         
+//         assertEquals(0, ((JBossConnection)conn0).getServerID());
+//
+//         // Objects Server1
+//         conn1 = this.createConnectionOnServer(cf, 1);
+//
+//         assertEquals(1, ((JBossConnection)conn1).getServerID());
+//
+//         Session session1 = conn1.createSession(true, Session.SESSION_TRANSACTED);
+//         
+//         Session session2 = conn1.createSession(true, Session.SESSION_TRANSACTED);
+//
+//         MessageConsumer cons1 = session1.createConsumer(queue[1]);
+//         
+//         MessageConsumer cons2 = session2.createConsumer(queue[1]);
+//         
+//         MessageProducer prod = session1.createProducer(queue[1]);
+//         
+//         conn1.start();
+//                  
+//         TextMessage tm1 = session1.createTextMessage("message1");
+//         
+//         TextMessage tm2 = session1.createTextMessage("message2");
+//         
+//         TextMessage tm3 = session1.createTextMessage("message3");
+//         
+//         prod.send(tm1);
+//         
+//         prod.send(tm2);
+//         
+//         prod.send(tm3);
+//         
+//         session1.commit();
+//                           
+//         TextMessage rm1 = (TextMessage)cons1.receive(3000);
+//         
+//         assertNotNull(rm1);
+//         
+//         assertEquals(tm1.getText(), rm1.getText());
+//                                    
+//         TextMessage rm2 = (TextMessage)cons2.receive(3000);
+//         
+//         assertNotNull(rm2);
+//         
+//         assertEquals(tm2.getText(), rm2.getText());
+//         
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn1).registerFailoverListener(failoverListener);
+//
+//         ServerManagement.kill(1);
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         
+//         //now commit
+//         
+//         session1.commit();
+//         
+//         session2.commit();
+//         
+//         session1.close();
+//         
+//         session2.close();;
+//         
+//         Session session3 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         
+//         MessageConsumer cons3 = session3.createConsumer(queue[0]);
+//         
+//         TextMessage rm3 = (TextMessage)cons3.receive(2000);
+//         
+//         assertNotNull(rm3);
+//         
+//         assertEquals(tm3.getText(), rm3.getText());
+//         
+//         checkEmpty(queue[1], 0);
+//      }
+//      finally
+//      {
+//         if (conn1 != null)
+//         {
+//            conn1.close();
+//         }
+//
+//         if (conn0 != null)
+//         {
+//            conn0.close();
+//         }
+//      }
+//   }
+//    
+//
+//   // Package protected ----------------------------------------------------------------------------
+//
+//   // Protected ------------------------------------------------------------------------------------
+//
+//   protected void setUp() throws Exception
+//   {
+//      nodeCount = 2;
+//
+//      super.setUp();
+//   }
+//
+//   // Private --------------------------------------------------------------------------------------
+//   
+//   private void simpleFailover(String userName, String password) throws Exception
+//   {
+//      Connection conn = null;
+//
+//      try
+//      {
+//         if (userName!=null)
+//         {
+//            conn = createConnectionOnServer(cf, 1, userName, password);
+//         }
+//         else
+//         {
+//            conn = createConnectionOnServer(cf, 1);
+//         }
+//         
+//         conn.start();
+//
+//         // Disable Lease for this test.. as the ValveAspect should capture this
+//         getConnectionState(conn).getRemotingConnection().removeConnectionListener();
+//
+//         // make sure we're connecting to node 1
+//
+//         int nodeID = getServerId(conn);
+//
+//         assertEquals(1, nodeID);
+//
+//         Session s1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         MessageConsumer c1 = s1.createConsumer(queue[1]);
+//         MessageProducer p1 = s1.createProducer(queue[1]);
+//         p1.setDeliveryMode(DeliveryMode.PERSISTENT);
+//
+//         // send a message
+//
+//         p1.send(s1.createTextMessage("blip"));
+//
+//         // kill node 1
+//
+//         ServerManagement.kill(1);
+//
+//         try
+//         {
+//            ic[1].lookup("queue"); // looking up anything
+//            fail("The server still alive, kill didn't work yet");
+//         }
+//         catch (Exception e)
+//         {
+//         }
+//
+//         // we must receive the message
+//
+//         TextMessage tm = (TextMessage)c1.receive(3000);
+//         assertNotNull(tm);
+//         assertEquals("blip", tm.getText());
+//
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//
+////   // Used for both testFailureRightAfterACK and  testFailureRightBeforeACK
+////   private void failureOnInvocation(int typeOfFailure) throws Exception
+////   {
+////      Connection conn = null;
+////      Connection conn0 = null;
+////
+////      try
+////      {
+////         conn = createConnectionOnServer(cf, 1);
+////
+////         assertEquals(1, getServerId(conn));
+////
+////         // we "cripple" the remoting connection by removing ConnectionListener. This way, failures
+////         // cannot be "cleanly" detected by the client-side pinger, and we'll fail on an invocation
+////         JMSRemotingConnection rc = ((ClientConnectionDelegate)((JBossConnection)conn).
+////            getDelegate()).getRemotingConnection();
+////         rc.removeConnectionListener();
+////
+////         // poison the server
+////         ServerManagement.poisonTheServer(1, typeOfFailure);
+////
+////         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+////
+////         conn.start();
+////
+////         MessageProducer producer = session.createProducer(queue[0]);
+////
+////         producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+////
+////         MessageConsumer consumer = session.createConsumer(queue[0]);
+////
+////         producer.send(session.createTextMessage("before-poison"));
+////
+////         TextMessage tm = (TextMessage)consumer.receive(5000);
+////
+////         if(typeOfFailure == PoisonInterceptor.FAIL_AFTER_ACKNOWLEDGE_DELIVERY)
+////         {
+////         	//With auto_ack we won't the message - remember auto ack is "at most once"
+////         	assertNull(tm);
+////         }
+////         else
+////         {
+////            assertNotNull(tm);
+////
+////            assertEquals("before-poison", tm.getText());
+////         }
+////
+////         checkEmpty(queue[1], 0);
+////      }
+////      finally
+////      {
+////         if (conn != null)
+////         {
+////            conn.close();
+////         }
+////         if (conn0 != null)
+////         {
+////            conn0.close();
+////         }
+////      }
+////   }
+////
+//   
 
    // Inner classes --------------------------------------------------------------------------------
    

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -22,33 +22,6 @@
 
 package org.jboss.test.messaging.jms.clustering;
 
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-
-import org.jboss.jms.client.FailoverEvent;
-import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.jms.client.JBossSession;
-import org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate;
-import org.jboss.jms.client.delegate.ClientConnectionDelegate;
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
-import org.jboss.jms.client.delegate.ClientSessionDelegate;
-import org.jboss.jms.client.remoting.JMSRemotingConnection;
-import org.jboss.jms.client.state.ConnectionState;
-import org.jboss.jms.client.state.SessionState;
-import org.jboss.messaging.util.ProxyFactory;
-import org.jboss.test.messaging.tools.ServerManagement;
-
 /**
  * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/LoadBalancingTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/LoadBalancingTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/LoadBalancingTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -6,12 +6,9 @@
  */
 package org.jboss.test.messaging.jms.clustering;
 
-import org.jboss.jms.client.JBossConnection;
 import org.jboss.jms.client.JBossConnectionFactory;
 import org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate;
-import org.jboss.jms.client.delegate.DelegateSupport;
 import org.jboss.jms.client.plugin.RoundRobinLoadBalancingPolicy;
-import org.jboss.jms.client.state.ConnectionState;
 import org.jboss.jms.tx.ResourceManagerFactory;
 
 import javax.jms.Connection;
@@ -143,11 +140,6 @@
 
    // Protected ------------------------------------------------------------------------------------
 
-   protected ConnectionState getConnectionState(Connection conn)
-   {
-      return getDelegate(conn).getState();
-   }
-
    protected void setUp() throws Exception
    {
    	nodeCount = 2;

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/XAFailoverTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/XAFailoverTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/XAFailoverTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -77,571 +77,571 @@
       }
    }
 
-   public void testSimpleXAConnectionFailover() throws Exception
-   {
-      XAConnection conn = null;
-      
-      XAConnectionFactory xaCF = (XAConnectionFactory)cf;
-
-      try
-      {
-         // create a connection to node 1
-         conn = createXAConnectionOnServer(xaCF, 1);
-         conn.start();
-
-         assertEquals(1, getServerId(conn));
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)conn).registerFailoverListener(failoverListener);
-
-         log.debug("killing node 1 ....");
-
-         ServerManagement.kill(1);
-
-         log.info("########");
-         log.info("######## KILLED NODE 1");
-         log.info("########");
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         log.info("failover completed");
-
-         assertEquals(0, getServerId(conn));
-
-      }
-      finally
-      {
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
+//   public void testSimpleXAConnectionFailover() throws Exception
+//   {
+//      XAConnection conn = null;
+//      
+//      XAConnectionFactory xaCF = (XAConnectionFactory)cf;
+//
+//      try
+//      {
+//         // create a connection to node 1
+//         conn = createXAConnectionOnServer(xaCF, 1);
+//         conn.start();
+//
+//         assertEquals(1, getServerId(conn));
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)conn).registerFailoverListener(failoverListener);
+//
+//         log.debug("killing node 1 ....");
+//
+//         ServerManagement.kill(1);
+//
+//         log.info("########");
+//         log.info("######## KILLED NODE 1");
+//         log.info("########");
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         log.info("failover completed");
+//
+//         assertEquals(0, getServerId(conn));
+//
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
+//   
+//
+//   public void testSendFailBeforePrepare() throws Exception
+//   {
+//      XAConnection xaConn = null;
+//      
+//      XAConnectionFactory xaCF = (XAConnectionFactory)cf;
+//      
+//      Connection conn = null;
+//      
+//      try
+//      {
+//         // create a connection to node 1
+//         xaConn = createXAConnectionOnServer(xaCF, 1);
+//         
+//         assertEquals(1, getServerId(xaConn));
+//
+//         conn = createConnectionOnServer(cf, 1);
+//         
+//         assertEquals(1, getServerId(conn));
+//         
+//         conn.start();
+//
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)xaConn).registerFailoverListener(failoverListener);
+//         
+//         // Create a normal consumer on the queue
+//         Session sessRec = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         
+//         MessageConsumer cons = sessRec.createConsumer(queue[1]);
+//         
+//         // Create an XA session
+//         
+//         XASession sess = xaConn.createXASession();
+//         
+//         XAResource res = sess.getXAResource();
+//         
+//         MessageProducer prod = sess.createProducer(queue[1]);
+//         
+//         tm.begin();
+//         
+//         Transaction tx = tm.getTransaction();
+//         
+//         tx.enlistResource(res);
+//         
+//         //Enlist a dummy XAResource to force 2pc
+//         XAResource dummy = new DummyXAResource();
+//         
+//         tx.enlistResource(dummy);
+//         
+//         //Send a message
+//         
+//         TextMessage msg = sess.createTextMessage("Cupid stunt");
+//         
+//         prod.send(msg);
+//         
+//         //Make sure message can't be received
+//         
+//         Message m = cons.receive(2000);
+//         
+//         assertNull(m);
+//         
+//         tx.delistResource(res, XAResource.TMSUCCESS);
+//         
+//         tx.delistResource(dummy, XAResource.TMSUCCESS);
+//         
+//         //Now kill node 1
+//         
+//         log.debug("killing node 1 ....");
+//
+//         ServerManagement.kill(1);
+//
+//         log.info("########");
+//         log.info("######## KILLED NODE 1");
+//         log.info("########");
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         log.info("failover completed");
+//         
+//         //Now commit the transaction
+//         
+//         tm.commit();
+//         
+//         // Message should now be receivable
+//         
+//         TextMessage mrec = (TextMessage)cons.receive(2000);
+//         
+//         assertNotNull(mrec);
+//         
+//         assertEquals(msg.getText(), mrec.getText());
+//         
+//         m = cons.receive(2000);
+//         
+//         assertNull(m);
+//
+//         assertEquals(0, getServerId(xaConn));
+//
+//      }
+//      finally
+//      {
+//         if (xaConn != null)
+//         {
+//            xaConn.close();
+//         }
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
    
-
-   public void testSendFailBeforePrepare() throws Exception
-   {
-      XAConnection xaConn = null;
-      
-      XAConnectionFactory xaCF = (XAConnectionFactory)cf;
-      
-      Connection conn = null;
-      
-      try
-      {
-         // create a connection to node 1
-         xaConn = createXAConnectionOnServer(xaCF, 1);
-         
-         assertEquals(1, getServerId(xaConn));
-
-         conn = createConnectionOnServer(cf, 1);
-         
-         assertEquals(1, getServerId(conn));
-         
-         conn.start();
-
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)xaConn).registerFailoverListener(failoverListener);
-         
-         // Create a normal consumer on the queue
-         Session sessRec = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
-         MessageConsumer cons = sessRec.createConsumer(queue[1]);
-         
-         // Create an XA session
-         
-         XASession sess = xaConn.createXASession();
-         
-         XAResource res = sess.getXAResource();
-         
-         MessageProducer prod = sess.createProducer(queue[1]);
-         
-         tm.begin();
-         
-         Transaction tx = tm.getTransaction();
-         
-         tx.enlistResource(res);
-         
-         //Enlist a dummy XAResource to force 2pc
-         XAResource dummy = new DummyXAResource();
-         
-         tx.enlistResource(dummy);
-         
-         //Send a message
-         
-         TextMessage msg = sess.createTextMessage("Cupid stunt");
-         
-         prod.send(msg);
-         
-         //Make sure message can't be received
-         
-         Message m = cons.receive(2000);
-         
-         assertNull(m);
-         
-         tx.delistResource(res, XAResource.TMSUCCESS);
-         
-         tx.delistResource(dummy, XAResource.TMSUCCESS);
-         
-         //Now kill node 1
-         
-         log.debug("killing node 1 ....");
-
-         ServerManagement.kill(1);
-
-         log.info("########");
-         log.info("######## KILLED NODE 1");
-         log.info("########");
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         log.info("failover completed");
-         
-         //Now commit the transaction
-         
-         tm.commit();
-         
-         // Message should now be receivable
-         
-         TextMessage mrec = (TextMessage)cons.receive(2000);
-         
-         assertNotNull(mrec);
-         
-         assertEquals(msg.getText(), mrec.getText());
-         
-         m = cons.receive(2000);
-         
-         assertNull(m);
-
-         assertEquals(0, getServerId(xaConn));
-
-      }
-      finally
-      {
-         if (xaConn != null)
-         {
-            xaConn.close();
-         }
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
-   
-   public void testSendAndReceiveFailBeforePrepare() throws Exception
-   {
-      XAConnection xaConn = null;
-      
-      XAConnectionFactory xaCF = (XAConnectionFactory)cf;
-      
-      Connection conn = null;
-      
-      try
-      {
-         // create a connection to node 1
-         xaConn = createXAConnectionOnServer(xaCF, 1);
-         
-         assertEquals(1, ((JBossConnection)xaConn).getServerID());
-
-         conn = this.createConnectionOnServer(cf, 1);      
-         
-         assertEquals(1, ((JBossConnection)conn).getServerID());
-         
-         conn.start();
-         
-         xaConn.start();
-
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)xaConn).registerFailoverListener(failoverListener);
-         
-         // Create a normal consumer on the queue
-         Session sessRec = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
-         //Send a message to the queue
-         MessageProducer prod = sessRec.createProducer(queue[1]);
-         
-         TextMessage sent = sessRec.createTextMessage("plop");
-         
-         prod.send(sent);
-         
-         // Create an XA session
-         
-         XASession sess = xaConn.createXASession();
-         
-         XAResource res = sess.getXAResource();
-         
-         MessageProducer prod2 = sess.createProducer(queue[1]);
-         
-         MessageConsumer cons2 = sess.createConsumer(queue[1]);
-         
-         tm.begin();
-         
-         Transaction tx = tm.getTransaction();
-         
-         tx.enlistResource(res);
-         
-         //Enlist a dummy XAResource to force 2pc
-         XAResource dummy = new DummyXAResource();        
-         
-         tx.enlistResource(dummy);
-         
-         //receive a message
-         
-         TextMessage received = (TextMessage)cons2.receive(2000);
-         
-         assertNotNull(received);
-         
-         assertEquals(sent.getText(), received.getText());
-         
-         //Send a message
-         
-         TextMessage msg = sess.createTextMessage("Cupid stunt");
-         
-         prod2.send(msg);
-         
-         // Make sure can't be received
-         
-         MessageConsumer cons = sessRec.createConsumer(queue[1]);
-         
-         Message m = cons.receive(2000);
-         
-         assertNull(m);
-                  
-         tx.delistResource(res, XAResource.TMSUCCESS);
-         
-         tx.delistResource(dummy, XAResource.TMSUCCESS);
-         
-         //Now kill node 1
-         
-         log.debug("killing node 1 ....");
-
-         ServerManagement.kill(1);
-
-         log.info("########");
-         log.info("######## KILLED NODE 1");
-         log.info("########");
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         log.info("failover completed");
-         
-         //Now commit the transaction
-         
-         tm.commit();
-         
-         // Message should now be receivable
-         
-         cons2.close();
-         
-         TextMessage mrec = (TextMessage)cons.receive(2000);
-         
-         assertNotNull(mrec);
-         
-         assertEquals(msg.getText(), mrec.getText());
-         
-         m = cons.receive(2000);
-         
-         //And the other message should be acked
-         assertNull(m);                  
-
-         assertEquals(0, ((JBossConnection)xaConn).getServerID());
-
-      }
-      finally
-      {
-         if (xaConn != null)
-         {
-            xaConn.close();
-         }
-         if (conn != null)
-         {
-            conn.close();
-         }
-      }
-   }
+//   public void testSendAndReceiveFailBeforePrepare() throws Exception
+//   {
+//      XAConnection xaConn = null;
+//      
+//      XAConnectionFactory xaCF = (XAConnectionFactory)cf;
+//      
+//      Connection conn = null;
+//      
+//      try
+//      {
+//         // create a connection to node 1
+//         xaConn = createXAConnectionOnServer(xaCF, 1);
+//         
+//         assertEquals(1, ((JBossConnection)xaConn).getServerID());
+//
+//         conn = this.createConnectionOnServer(cf, 1);      
+//         
+//         assertEquals(1, ((JBossConnection)conn).getServerID());
+//         
+//         conn.start();
+//         
+//         xaConn.start();
+//
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)xaConn).registerFailoverListener(failoverListener);
+//         
+//         // Create a normal consumer on the queue
+//         Session sessRec = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//         
+//         //Send a message to the queue
+//         MessageProducer prod = sessRec.createProducer(queue[1]);
+//         
+//         TextMessage sent = sessRec.createTextMessage("plop");
+//         
+//         prod.send(sent);
+//         
+//         // Create an XA session
+//         
+//         XASession sess = xaConn.createXASession();
+//         
+//         XAResource res = sess.getXAResource();
+//         
+//         MessageProducer prod2 = sess.createProducer(queue[1]);
+//         
+//         MessageConsumer cons2 = sess.createConsumer(queue[1]);
+//         
+//         tm.begin();
+//         
+//         Transaction tx = tm.getTransaction();
+//         
+//         tx.enlistResource(res);
+//         
+//         //Enlist a dummy XAResource to force 2pc
+//         XAResource dummy = new DummyXAResource();        
+//         
+//         tx.enlistResource(dummy);
+//         
+//         //receive a message
+//         
+//         TextMessage received = (TextMessage)cons2.receive(2000);
+//         
+//         assertNotNull(received);
+//         
+//         assertEquals(sent.getText(), received.getText());
+//         
+//         //Send a message
+//         
+//         TextMessage msg = sess.createTextMessage("Cupid stunt");
+//         
+//         prod2.send(msg);
+//         
+//         // Make sure can't be received
+//         
+//         MessageConsumer cons = sessRec.createConsumer(queue[1]);
+//         
+//         Message m = cons.receive(2000);
+//         
+//         assertNull(m);
+//                  
+//         tx.delistResource(res, XAResource.TMSUCCESS);
+//         
+//         tx.delistResource(dummy, XAResource.TMSUCCESS);
+//         
+//         //Now kill node 1
+//         
+//         log.debug("killing node 1 ....");
+//
+//         ServerManagement.kill(1);
+//
+//         log.info("########");
+//         log.info("######## KILLED NODE 1");
+//         log.info("########");
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         log.info("failover completed");
+//         
+//         //Now commit the transaction
+//         
+//         tm.commit();
+//         
+//         // Message should now be receivable
+//         
+//         cons2.close();
+//         
+//         TextMessage mrec = (TextMessage)cons.receive(2000);
+//         
+//         assertNotNull(mrec);
+//         
+//         assertEquals(msg.getText(), mrec.getText());
+//         
+//         m = cons.receive(2000);
+//         
+//         //And the other message should be acked
+//         assertNull(m);                  
+//
+//         assertEquals(0, ((JBossConnection)xaConn).getServerID());
+//
+//      }
+//      finally
+//      {
+//         if (xaConn != null)
+//         {
+//            xaConn.close();
+//         }
+//         if (conn != null)
+//         {
+//            conn.close();
+//         }
+//      }
+//   }
      
-   public void testSendAndReceiveTwoConnectionsFailBeforePrepare() throws Exception
-   {
-      XAConnection xaConn0 = null;
-      
-      XAConnection xaConn1 = null;
-      
-      XAConnectionFactory xaCF = (XAConnectionFactory)cf;
-      
-      try
-      {
-         xaConn0 = createXAConnectionOnServer(xaCF, 0);
-         
-         assertEquals(0, ((JBossConnection)xaConn0).getServerID());
-
-         xaConn1 = createXAConnectionOnServer(xaCF, 1);
-         
-         assertEquals(1, ((JBossConnection)xaConn1).getServerID());
-
-         TextMessage sent0 = null;
-
-         TextMessage sent1 = null;
-
-         // Sending two messages.. on each server
-         {
-            Connection conn0 = null;
-
-            Connection conn1 = null;
-
-            conn0 = this.createConnectionOnServer(cf, 0);
-
-            assertEquals(0, ((JBossConnection)conn0).getServerID());
-
-            conn1 = this.createConnectionOnServer(cf, 1);
-
-            assertEquals(1, ((JBossConnection)conn1).getServerID());
-
-            //Send a message to each queue
-
-            Session sess = conn0.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-            MessageProducer prod = sess.createProducer(queue[0]);
-
-            sent0 = sess.createTextMessage("plop0");
-
-            prod.send(sent0);
-
-            sess.close();
-
-            sess = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-            prod = sess.createProducer(queue[1]);
-
-            sent1 = sess.createTextMessage("plop1");
-
-            prod.send(sent1);
-
-            sess.close();
-            
-            conn0.close();
-            
-            conn1.close();
-         }
-
-         xaConn0.start();
-         
-         xaConn1.start();
-                  
-         // register a failover listener
-         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
-         ((JBossConnection)xaConn1).registerFailoverListener(failoverListener);
-                
-         tm.begin();
-         
-         Transaction tx = tm.getTransaction();
-            
-         //receive and send a message on each
-         
-         // node 0
-         
-         XASession sess0 = xaConn0.createXASession();
-         
-         XAResource res0 = sess0.getXAResource();
-         
-         tx.enlistResource(res0);         
-         
-         MessageProducer prod0 = sess0.createProducer(queue[0]);
-         
-         MessageConsumer cons0 = sess0.createConsumer(queue[0]);
-         
-         TextMessage received = (TextMessage)cons0.receive(2000);
-         
-         log.info("Got message " + received.getText());
-         
-         assertNotNull(received);         
-         
-         assertEquals(sent0.getText(), received.getText());                  
-         
-         TextMessage msg0 = sess0.createTextMessage("Cupid stunt0");
-         
-         prod0.send(msg0);
-         
-         //Make sure the consumer is closed otherwise message might be sucked
-         cons0.close();
-                  
-         //node 1
-         
-         XASession sess1 = xaConn1.createXASession();
-         
-         XAResource res1 = sess1.getXAResource();
-         
-         tx.enlistResource(res1);
-                  
-         MessageProducer prod1 = sess1.createProducer(queue[1]);
-         
-         MessageConsumer cons1 = sess1.createConsumer(queue[1]);
-         
-         received = (TextMessage)cons1.receive(2000);
-              
-         log.info("Got message " + received.getText());
-         
-         assertNotNull(received);         
-         
-         assertEquals(sent1.getText(), received.getText());         
-                      
-         TextMessage msg1 = sess1.createTextMessage("Cupid stunt1");
-         
-         prod1.send(msg1);
-         
-         cons1.close();
-                 
-         tx.delistResource(res0, XAResource.TMSUCCESS);
-         
-         tx.delistResource(res1, XAResource.TMSUCCESS);
-         
-         //Now kill node 1
-         
-         log.debug("killing node 1 ....");
-
-         ServerManagement.kill(1);
-
-         log.info("########");
-         log.info("######## KILLED NODE 1");
-         log.info("########");
-
-         // wait for the client-side failover to complete
-
-         while(true)
-         {
-            FailoverEvent event = failoverListener.getEvent(30000);
-            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
-            {
-               break;
-            }
-            if (event == null)
-            {
-               fail("Did not get expected FAILOVER_COMPLETED event");
-            }
-         }
-
-         // failover complete
-         log.info("failover completed");
-         
-         //Now commit the transaction
-         
-         tm.commit();
-         
-         // Messages should now be receivable
-
-         Connection conn = null;
-         try
-         {
-            conn = this.createConnectionOnServer(cf, 0);
-
-            conn.start();
-
-            Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-            MessageConsumer cons = session.createConsumer(queue[0]);
-
-            HashSet receivedMessages = new HashSet();
-
-            int numberOfReceivedMessages = 0;
-
-            while(true)
-            {
-               TextMessage message = (TextMessage)cons.receive(2000);
-               if (message == null)
-               {
-                  break;
-               }
-               log.info("Message = (" + message.getText() + ")");
-               receivedMessages.add(message.getText());
-               numberOfReceivedMessages++;
-            }
-
-            //These two should be acked
-            
-            assertFalse("\"plop0\" message was duplicated",
-               receivedMessages.contains("plop0"));
-
-            assertFalse("\"plop1\" message was duplicated",
-               receivedMessages.contains("plop1"));
-
-            //And these should be receivable
-            
-            assertTrue("\"Cupid stunt0\" message wasn't received",
-               receivedMessages.contains("Cupid stunt0"));
-
-            assertTrue("\"Cupid stunt1\" message wasn't received",
-               receivedMessages.contains("Cupid stunt1"));
-
-            assertEquals(2, numberOfReceivedMessages);
-
-            assertEquals(0, ((JBossConnection)xaConn1).getServerID());
-         }
-         finally
-         {
-            if (conn != null)
-            {
-               conn.close();
-            }
-         }
-      }
-      finally
-      {
-         if (xaConn1 != null)
-         {
-            xaConn1.close();
-         }
-         if (xaConn0 != null)
-         {
-            xaConn0.close();
-         }
-      }
-   }
+//   public void testSendAndReceiveTwoConnectionsFailBeforePrepare() throws Exception
+//   {
+//      XAConnection xaConn0 = null;
+//      
+//      XAConnection xaConn1 = null;
+//      
+//      XAConnectionFactory xaCF = (XAConnectionFactory)cf;
+//      
+//      try
+//      {
+//         xaConn0 = createXAConnectionOnServer(xaCF, 0);
+//         
+//         assertEquals(0, ((JBossConnection)xaConn0).getServerID());
+//
+//         xaConn1 = createXAConnectionOnServer(xaCF, 1);
+//         
+//         assertEquals(1, ((JBossConnection)xaConn1).getServerID());
+//
+//         TextMessage sent0 = null;
+//
+//         TextMessage sent1 = null;
+//
+//         // Sending two messages.. on each server
+//         {
+//            Connection conn0 = null;
+//
+//            Connection conn1 = null;
+//
+//            conn0 = this.createConnectionOnServer(cf, 0);
+//
+//            assertEquals(0, ((JBossConnection)conn0).getServerID());
+//
+//            conn1 = this.createConnectionOnServer(cf, 1);
+//
+//            assertEquals(1, ((JBossConnection)conn1).getServerID());
+//
+//            //Send a message to each queue
+//
+//            Session sess = conn0.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//            MessageProducer prod = sess.createProducer(queue[0]);
+//
+//            sent0 = sess.createTextMessage("plop0");
+//
+//            prod.send(sent0);
+//
+//            sess.close();
+//
+//            sess = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//            prod = sess.createProducer(queue[1]);
+//
+//            sent1 = sess.createTextMessage("plop1");
+//
+//            prod.send(sent1);
+//
+//            sess.close();
+//            
+//            conn0.close();
+//            
+//            conn1.close();
+//         }
+//
+//         xaConn0.start();
+//         
+//         xaConn1.start();
+//                  
+//         // register a failover listener
+//         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
+//         ((JBossConnection)xaConn1).registerFailoverListener(failoverListener);
+//                
+//         tm.begin();
+//         
+//         Transaction tx = tm.getTransaction();
+//            
+//         //receive and send a message on each
+//         
+//         // node 0
+//         
+//         XASession sess0 = xaConn0.createXASession();
+//         
+//         XAResource res0 = sess0.getXAResource();
+//         
+//         tx.enlistResource(res0);         
+//         
+//         MessageProducer prod0 = sess0.createProducer(queue[0]);
+//         
+//         MessageConsumer cons0 = sess0.createConsumer(queue[0]);
+//         
+//         TextMessage received = (TextMessage)cons0.receive(2000);
+//         
+//         log.info("Got message " + received.getText());
+//         
+//         assertNotNull(received);         
+//         
+//         assertEquals(sent0.getText(), received.getText());                  
+//         
+//         TextMessage msg0 = sess0.createTextMessage("Cupid stunt0");
+//         
+//         prod0.send(msg0);
+//         
+//         //Make sure the consumer is closed otherwise message might be sucked
+//         cons0.close();
+//                  
+//         //node 1
+//         
+//         XASession sess1 = xaConn1.createXASession();
+//         
+//         XAResource res1 = sess1.getXAResource();
+//         
+//         tx.enlistResource(res1);
+//                  
+//         MessageProducer prod1 = sess1.createProducer(queue[1]);
+//         
+//         MessageConsumer cons1 = sess1.createConsumer(queue[1]);
+//         
+//         received = (TextMessage)cons1.receive(2000);
+//              
+//         log.info("Got message " + received.getText());
+//         
+//         assertNotNull(received);         
+//         
+//         assertEquals(sent1.getText(), received.getText());         
+//                      
+//         TextMessage msg1 = sess1.createTextMessage("Cupid stunt1");
+//         
+//         prod1.send(msg1);
+//         
+//         cons1.close();
+//                 
+//         tx.delistResource(res0, XAResource.TMSUCCESS);
+//         
+//         tx.delistResource(res1, XAResource.TMSUCCESS);
+//         
+//         //Now kill node 1
+//         
+//         log.debug("killing node 1 ....");
+//
+//         ServerManagement.kill(1);
+//
+//         log.info("########");
+//         log.info("######## KILLED NODE 1");
+//         log.info("########");
+//
+//         // wait for the client-side failover to complete
+//
+//         while(true)
+//         {
+//            FailoverEvent event = failoverListener.getEvent(30000);
+//            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
+//            {
+//               break;
+//            }
+//            if (event == null)
+//            {
+//               fail("Did not get expected FAILOVER_COMPLETED event");
+//            }
+//         }
+//
+//         // failover complete
+//         log.info("failover completed");
+//         
+//         //Now commit the transaction
+//         
+//         tm.commit();
+//         
+//         // Messages should now be receivable
+//
+//         Connection conn = null;
+//         try
+//         {
+//            conn = this.createConnectionOnServer(cf, 0);
+//
+//            conn.start();
+//
+//            Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//            MessageConsumer cons = session.createConsumer(queue[0]);
+//
+//            HashSet receivedMessages = new HashSet();
+//
+//            int numberOfReceivedMessages = 0;
+//
+//            while(true)
+//            {
+//               TextMessage message = (TextMessage)cons.receive(2000);
+//               if (message == null)
+//               {
+//                  break;
+//               }
+//               log.info("Message = (" + message.getText() + ")");
+//               receivedMessages.add(message.getText());
+//               numberOfReceivedMessages++;
+//            }
+//
+//            //These two should be acked
+//            
+//            assertFalse("\"plop0\" message was duplicated",
+//               receivedMessages.contains("plop0"));
+//
+//            assertFalse("\"plop1\" message was duplicated",
+//               receivedMessages.contains("plop1"));
+//
+//            //And these should be receivable
+//            
+//            assertTrue("\"Cupid stunt0\" message wasn't received",
+//               receivedMessages.contains("Cupid stunt0"));
+//
+//            assertTrue("\"Cupid stunt1\" message wasn't received",
+//               receivedMessages.contains("Cupid stunt1"));
+//
+//            assertEquals(2, numberOfReceivedMessages);
+//
+//            assertEquals(0, ((JBossConnection)xaConn1).getServerID());
+//         }
+//         finally
+//         {
+//            if (conn != null)
+//            {
+//               conn.close();
+//            }
+//         }
+//      }
+//      finally
+//      {
+//         if (xaConn1 != null)
+//         {
+//            xaConn1.close();
+//         }
+//         if (xaConn0 != null)
+//         {
+//            xaConn0.close();
+//         }
+//      }
+//   }
    
 //   public void testSendAndReceiveFailAfterPrepareAndRetryCommit() throws Exception
 //   {

Modified: trunk/tests/src/org/jboss/test/messaging/jms/server/connectionmanager/SimpleConnectionManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/server/connectionmanager/SimpleConnectionManagerTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/server/connectionmanager/SimpleConnectionManagerTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -30,6 +30,7 @@
 
 import org.jboss.jms.client.JBossConnection;
 import org.jboss.jms.client.JBossConnectionFactory;
+import org.jboss.jms.client.api.ClientSession;
 import org.jboss.jms.delegate.ConnectionEndpoint;
 import org.jboss.jms.delegate.IDBlock;
 import org.jboss.jms.delegate.SessionDelegate;
@@ -232,7 +233,7 @@
          return closed;
       }
 
-      public SessionDelegate createSessionDelegate(boolean transacted, int acknowledgmentMode, boolean isXA) throws JMSException
+      public ClientSession createSessionDelegate(boolean transacted, int acknowledgmentMode, boolean isXA) throws JMSException
       {
          return null;
       }

Modified: trunk/tests/src/org/jboss/test/messaging/jms/stress/StressTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/stress/StressTestBase.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/stress/StressTestBase.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -21,9 +21,6 @@
   */
 package org.jboss.test.messaging.jms.stress;
 
-import org.jboss.jms.client.JBossSession;
-import org.jboss.jms.client.delegate.DelegateSupport;
-import org.jboss.jms.client.state.SessionState;
 import org.jboss.test.messaging.JBMServerTestCase;
 
 import javax.jms.ConnectionFactory;
@@ -152,8 +149,6 @@
    
    protected void tweakXASession(XASession sess)
    {
-      SessionState sstate = getDelegate(sess).getState();
-      
-      sstate.setTreatAsNonTransactedWhenNotEnlisted(false);
+      getDelegate(sess).setTreatAsNonTransactedWhenNotEnlisted(false);
    }
 }

Modified: trunk/tests/src/org/jboss/test/messaging/jms/stress/clustering/FailoverOverDistributionStressTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/stress/clustering/FailoverOverDistributionStressTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/stress/clustering/FailoverOverDistributionStressTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -105,125 +105,125 @@
     * either sends or receives messages from a queue. Then kills the node.
     * All connections should successfully fail over to the failover node.
     */
-   public void testFailoverManyConnections() throws Exception
-   {
-      produced = 0;
-      consumed = 0;
+//   public void testFailoverManyConnections() throws Exception
+//   {
+//      produced = 0;
+//      consumed = 0;
+//
+//      Connection connections[] = new Connection[CONNECTION_COUNT];
+//      FailoverOverDistributionStressTest.ConnectionWorker workers[] = new FailoverOverDistributionStressTest.ConnectionWorker[CONNECTION_COUNT];
+//
+//      try
+//      {
+//         log.info("creating " + CONNECTION_COUNT + " threads to connect to server " + CONNECT_NODE);
+//
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            if (i % 2 == 0)
+//            {
+//               connections[i] = createConnectionOnServer(cf, 1);
+//               workers[i] = new FailoverOverDistributionStressTest.ConnectionSenderThread(i, connections[i], queue[CONNECT_NODE]);
+//            }
+//            else
+//            {
+//               connections[i] = createConnectionOnServer(cf, 0);
+//               workers[i] = new FailoverOverDistributionStressTest.ConnectionReceiverThread(i, connections[i], queue[CONNECT_NODE]);
+//            }
+//         }
+//
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            workers[i].start();
+//         }
+//
+//         log.info("waiting for a few seconds so that threads begin working");
+//
+//         while (true)
+//         {
+//            int produced = getProduced();
+//            if (produced > (MESSAGE_COUNT_PER_CONNECTION * (CONNECTION_COUNT/2))/2 )
+//            {
+//               killAndWaitForFailover(connections);
+//               break;
+//            }
+//            else
+//            {
+//               log.info("Produced " + produced + " messages.. Consumed (" + getConsumed() + ")" );
+//            }
+//            Thread.sleep(500);
+//         }
+//
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            assertEquals("Connection #" + i + " did not fail over", FAILOVER_NODE, getServerId(connections[i]));
+//         }
+//
+//         log.info("waiting for connection threads to finish");
+//
+//         boolean fail = false;
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            workers[i].join();
+//            Exception e = workers[i].getException();
+//            if (e != null)
+//            {
+//               log.error("Thread " + workers[i].getName() + " terminated abnormally:", e);
+//               fail = true;
+//            }
+//         }
+//
+//         if (fail) { fail("Some threads terminated abnormally"); }
+//
+//         assertEquals(produced, consumed);
+//      }
+//      finally
+//      {
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            if (connections[i] != null)
+//            {
+//               connections[i].close();
+//            }
+//         }
+//      }
+//   }
 
-      Connection connections[] = new Connection[CONNECTION_COUNT];
-      FailoverOverDistributionStressTest.ConnectionWorker workers[] = new FailoverOverDistributionStressTest.ConnectionWorker[CONNECTION_COUNT];
-
-      try
-      {
-         log.info("creating " + CONNECTION_COUNT + " threads to connect to server " + CONNECT_NODE);
-
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            if (i % 2 == 0)
-            {
-               connections[i] = createConnectionOnServer(cf, 1);
-               workers[i] = new FailoverOverDistributionStressTest.ConnectionSenderThread(i, connections[i], queue[CONNECT_NODE]);
-            }
-            else
-            {
-               connections[i] = createConnectionOnServer(cf, 0);
-               workers[i] = new FailoverOverDistributionStressTest.ConnectionReceiverThread(i, connections[i], queue[CONNECT_NODE]);
-            }
-         }
-
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            workers[i].start();
-         }
-
-         log.info("waiting for a few seconds so that threads begin working");
-
-         while (true)
-         {
-            int produced = getProduced();
-            if (produced > (MESSAGE_COUNT_PER_CONNECTION * (CONNECTION_COUNT/2))/2 )
-            {
-               killAndWaitForFailover(connections);
-               break;
-            }
-            else
-            {
-               log.info("Produced " + produced + " messages.. Consumed (" + getConsumed() + ")" );
-            }
-            Thread.sleep(500);
-         }
-
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            assertEquals("Connection #" + i + " did not fail over", FAILOVER_NODE, getServerId(connections[i]));
-         }
-
-         log.info("waiting for connection threads to finish");
-
-         boolean fail = false;
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            workers[i].join();
-            Exception e = workers[i].getException();
-            if (e != null)
-            {
-               log.error("Thread " + workers[i].getName() + " terminated abnormally:", e);
-               fail = true;
-            }
-         }
-
-         if (fail) { fail("Some threads terminated abnormally"); }
-
-         assertEquals(produced, consumed);
-      }
-      finally
-      {
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            if (connections[i] != null)
-            {
-               connections[i].close();
-            }
-         }
-      }
-   }
-
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
 
    // Private -------------------------------------------------------
 
-   private void killAndWaitForFailover(Connection[] connections) throws Exception
-   {
-      // register a failover listener
-      FailoverOverDistributionStressTest.LoggingFailoverListener failoverListener = new FailoverOverDistributionStressTest.LoggingFailoverListener();
+//   private void killAndWaitForFailover(Connection[] connections) throws Exception
+//   {
+//      // register a failover listener
+//      FailoverOverDistributionStressTest.LoggingFailoverListener failoverListener = new FailoverOverDistributionStressTest.LoggingFailoverListener();
+//
+//      int numConnections=0;
+//      for (int i = 0; i < connections.length; i++)
+//      {
+//         if (getServerId(connections[i]) == 1)
+//         {
+//            ((JBossConnection)connections[i]).registerFailoverListener(failoverListener);
+//            numConnections ++;
+//         }
+//      }
+//
+//      ServerManagement.kill(1);
+//
+//      log.info("killed node 1, now waiting for all connections to fail over");
+//
+//      long killTime = System.currentTimeMillis();
+//      while (failoverListener.getFailoverCount() < numConnections
+//            && System.currentTimeMillis() - killTime <= FAILOVER_TIMEOUT)
+//      {
+//         Thread.sleep(3000L);
+//      }
+//
+//      assertEquals("Not all connections have failed over successfully",
+//            numConnections, failoverListener.getFailoverCount());
+//   }
 
-      int numConnections=0;
-      for (int i = 0; i < connections.length; i++)
-      {
-         if (getServerId(connections[i]) == 1)
-         {
-            ((JBossConnection)connections[i]).registerFailoverListener(failoverListener);
-            numConnections ++;
-         }
-      }
-
-      ServerManagement.kill(1);
-
-      log.info("killed node 1, now waiting for all connections to fail over");
-
-      long killTime = System.currentTimeMillis();
-      while (failoverListener.getFailoverCount() < numConnections
-            && System.currentTimeMillis() - killTime <= FAILOVER_TIMEOUT)
-      {
-         Thread.sleep(3000L);
-      }
-
-      assertEquals("Not all connections have failed over successfully",
-            numConnections, failoverListener.getFailoverCount());
-   }
-
    // Inner classes -------------------------------------------------
 
    private class LoggingFailoverListener implements FailoverListener

Modified: trunk/tests/src/org/jboss/test/messaging/jms/stress/clustering/FailoverStressTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/stress/clustering/FailoverStressTest.java	2008-01-15 21:24:02 UTC (rev 3570)
+++ trunk/tests/src/org/jboss/test/messaging/jms/stress/clustering/FailoverStressTest.java	2008-01-16 03:05:48 UTC (rev 3571)
@@ -88,107 +88,107 @@
     * either sends or receives messages from a queue. Then kills the node.
     * All connections should successfully fail over to the failover node.
     */
-   public void testFailoverManyConnections() throws Exception
-   {
-      Connection connections[] = new Connection[CONNECTION_COUNT];
-      ConnectionWorker workers[] = new ConnectionWorker[CONNECTION_COUNT];
-      
-      try
-      {
-         log.info("creating " + CONNECTION_COUNT + " threads to connect to server " + CONNECT_NODE);
-
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            connections[i] = createConnectionOnServer(cf, CONNECT_NODE);
-            if (i % 2 == 0)
-            {
-               workers[i] = new ConnectionSenderThread(i, connections[i], queue[CONNECT_NODE]);
-            }
-            else
-            {
-               workers[i] = new ConnectionReceiverThread(i, connections[i], queue[CONNECT_NODE]);
-            }
-         }
-         
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            workers[i].start();
-         }
-         
-         log.info("waiting for a few seconds so that threads begin working");
-         
-         Thread.sleep(PAUSE_BEFORE_KILL);
-
-         log.info("killing node " + CONNECT_NODE);
-
-         killAndWaitForFailover(connections);
-         
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            assertEquals("Connection #" + i + " did not fail over", FAILOVER_NODE, getServerId(connections[i]));
-         }
-
-         log.info("waiting for connection threads to finish");
-
-         boolean fail = false;
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            workers[i].join();
-            Exception e = workers[i].getException();
-            if (e != null)
-            {
-               log.error("Thread " + workers[i].getName() + " terminated abnormally:", e);
-               fail = true;
-            }
-         }
-         
-         if (fail) { fail("Some threads terminated abnormally"); }
-      }
-      finally
-      {
-         for (int i = 0; i < CONNECTION_COUNT; i++)
-         {
-            if (connections[i] != null)
-            {
-               connections[i].close();
-            }
-         }
-      }
-   }
-
+//   public void testFailoverManyConnections() throws Exception
+//   {
+//      Connection connections[] = new Connection[CONNECTION_COUNT];
+//      ConnectionWorker workers[] = new ConnectionWorker[CONNECTION_COUNT];
+//      
+//      try
+//      {
+//         log.info("creating " + CONNECTION_COUNT + " threads to connect to server " + CONNECT_NODE);
+//
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            connections[i] = createConnectionOnServer(cf, CONNECT_NODE);
+//            if (i % 2 == 0)
+//            {
+//               workers[i] = new ConnectionSenderThread(i, connections[i], queue[CONNECT_NODE]);
+//            }
+//            else
+//            {
+//               workers[i] = new ConnectionReceiverThread(i, connections[i], queue[CONNECT_NODE]);
+//            }
+//         }
+//         
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            workers[i].start();
+//         }
+//         
+//         log.info("waiting for a few seconds so that threads begin working");
+//         
+//         Thread.sleep(PAUSE_BEFORE_KILL);
+//
+//         log.info("killing node " + CONNECT_NODE);
+//
+//         killAndWaitForFailover(connections);
+//         
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            assertEquals("Connection #" + i + " did not fail over", FAILOVER_NODE, getServerId(connections[i]));
+//         }
+//
+//         log.info("waiting for connection threads to finish");
+//
+//         boolean fail = false;
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            workers[i].join();
+//            Exception e = workers[i].getException();
+//            if (e != null)
+//            {
+//               log.error("Thread " + workers[i].getName() + " terminated abnormally:", e);
+//               fail = true;
+//            }
+//         }
+//         
+//         if (fail) { fail("Some threads terminated abnormally"); }
+//      }
+//      finally
+//      {
+//         for (int i = 0; i < CONNECTION_COUNT; i++)
+//         {
+//            if (connections[i] != null)
+//            {
+//               connections[i].close();
+//            }
+//         }
+//      }
+//   }
+//
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
 
    // Private -------------------------------------------------------
    
-   private void killAndWaitForFailover(Connection[] connections) throws Exception
-   {
-      // register a failover listener
-      LoggingFailoverListener failoverListener = new LoggingFailoverListener();
-      
-      for (int i = 0; i < connections.length; i++)
-      {
-         ((JBossConnection)connections[i]).registerFailoverListener(failoverListener);
-      }
+//   private void killAndWaitForFailover(Connection[] connections) throws Exception
+//   {
+//      // register a failover listener
+//      LoggingFailoverListener failoverListener = new LoggingFailoverListener();
+//      
+//      for (int i = 0; i < connections.length; i++)
+//      {
+//         ((JBossConnection)connections[i]).registerFailoverListener(failoverListener);
+//      }
+//
+//      int serverId = getServerId(connections[0]);
+//
+//      ServerManagement.kill(serverId);
+//
+//      log.info("killed node " + serverId + ", now waiting for all connections to fail over");
+//      
+//      long killTime = System.currentTimeMillis();
+//      while (failoverListener.getFailoverCount() < connections.length
+//            && System.currentTimeMillis() - killTime <= FAILOVER_TIMEOUT)
+//      {
+//         Thread.sleep(3000L);
+//      }
+//      
+//      assertEquals("Not all connections have failed over successfully",
+//            connections.length, failoverListener.getFailoverCount());
+//   }
 
-      int serverId = getServerId(connections[0]);
-
-      ServerManagement.kill(serverId);
-
-      log.info("killed node " + serverId + ", now waiting for all connections to fail over");
-      
-      long killTime = System.currentTimeMillis();
-      while (failoverListener.getFailoverCount() < connections.length
-            && System.currentTimeMillis() - killTime <= FAILOVER_TIMEOUT)
-      {
-         Thread.sleep(3000L);
-      }
-      
-      assertEquals("Not all connections have failed over successfully",
-            connections.length, failoverListener.getFailoverCount());
-   }
-
    // Inner classes -------------------------------------------------
    
    private class LoggingFailoverListener implements FailoverListener




More information about the jboss-cvs-commits mailing list