[jboss-cvs] JBoss Messaging SVN: r3605 - in trunk: src/main/org/jboss/jms/client/api and 14 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 21 14:19:28 EST 2008


Author: timfox
Date: 2008-01-21 14:19:28 -0500 (Mon, 21 Jan 2008)
New Revision: 3605

Added:
   trunk/src/main/org/jboss/jms/client/impl/
   trunk/src/main/org/jboss/jms/client/impl/Ack.java
   trunk/src/main/org/jboss/jms/client/impl/AckImpl.java
   trunk/src/main/org/jboss/jms/client/impl/Cancel.java
   trunk/src/main/org/jboss/jms/client/impl/CancelImpl.java
   trunk/src/main/org/jboss/jms/client/impl/ClientBrowserImpl.java
   trunk/src/main/org/jboss/jms/client/impl/ClientConnectionFactoryImpl.java
   trunk/src/main/org/jboss/jms/client/impl/ClientConnectionImpl.java
   trunk/src/main/org/jboss/jms/client/impl/ClientConsumer.java
   trunk/src/main/org/jboss/jms/client/impl/ClientConsumerImpl.java
   trunk/src/main/org/jboss/jms/client/impl/ClientConsumerPacketHandler.java
   trunk/src/main/org/jboss/jms/client/impl/ClientProducerImpl.java
   trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java
   trunk/src/main/org/jboss/jms/client/impl/ClosedInterceptor.java
   trunk/src/main/org/jboss/jms/client/impl/CommunicationSupport.java
   trunk/src/main/org/jboss/jms/client/impl/CreateConnectionResult.java
   trunk/src/main/org/jboss/jms/client/impl/DeliveryInfo.java
   trunk/src/main/org/jboss/jms/client/impl/JMSClientVMIdentifier.java
Removed:
   trunk/src/main/org/jboss/jms/client/container/
   trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.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/ClientConsumerPacketHandler.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/delegate/CommunicationSupport.java
   trunk/src/main/org/jboss/jms/client/impl/ClientConsumer.java
   trunk/src/main/org/jboss/jms/client/impl/ClosedInterceptor.java
   trunk/src/main/org/jboss/jms/client/impl/JMSClientVMIdentifier.java
   trunk/src/main/org/jboss/jms/delegate/Ack.java
   trunk/src/main/org/jboss/jms/delegate/Cancel.java
   trunk/src/main/org/jboss/jms/delegate/CreateConnectionResult.java
   trunk/src/main/org/jboss/jms/delegate/DefaultAck.java
   trunk/src/main/org/jboss/jms/delegate/DefaultCancel.java
   trunk/src/main/org/jboss/jms/delegate/DeliveryInfo.java
Modified:
   trunk/src/main/org/jboss/jms/client/JBossConnectionFactory.java
   trunk/src/main/org/jboss/jms/client/api/ClientSession.java
   trunk/src/main/org/jboss/jms/client/plugin/LoadBalancingFactory.java
   trunk/src/main/org/jboss/jms/client/plugin/LoadBalancingPolicy.java
   trunk/src/main/org/jboss/jms/client/plugin/NoLoadBalancingLoadBalancingFactory.java
   trunk/src/main/org/jboss/jms/client/plugin/NoLoadBalancingLoadBalancingPolicy.java
   trunk/src/main/org/jboss/jms/client/plugin/RoundRobinLoadBalancingFactory.java
   trunk/src/main/org/jboss/jms/client/plugin/RoundRobinLoadBalancingPolicy.java
   trunk/src/main/org/jboss/jms/client/remoting/CallbackManager.java
   trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
   trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryEndpoint.java
   trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryInternalEndpoint.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
   trunk/src/main/org/jboss/jms/server/endpoint/SessionEndpoint.java
   trunk/src/main/org/jboss/jms/tx/ClientTransaction.java
   trunk/src/main/org/jboss/jms/tx/ResourceManager.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveriesRequestCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveriesMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveryMessageCodec.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveriesMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveriesMessage.java
   trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveryMessage.java
   trunk/src/main/org/jboss/messaging/util/ProxyFactory.java
   trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java
   trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java
   trunk/tests/src/org/jboss/test/messaging/JBMBaseTestCase.java
   trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.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
Log:
Client side clean up part IV


Modified: trunk/src/main/org/jboss/jms/client/JBossConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnectionFactory.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/JBossConnectionFactory.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -39,8 +39,8 @@
 import javax.naming.NamingException;
 import javax.naming.Reference;
 
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
-import org.jboss.jms.delegate.CreateConnectionResult;
+import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.jms.client.impl.CreateConnectionResult;
 import org.jboss.jms.referenceable.SerializableObjectRefAddr;
 import org.jboss.messaging.util.Logger;
 
@@ -66,11 +66,11 @@
    
    // Attributes -----------------------------------------------------------------------------------
    
-   protected ClientConnectionFactoryDelegate delegate;
+   protected ClientConnectionFactoryImpl delegate;
 
    // Constructors ---------------------------------------------------------------------------------
    
-   public JBossConnectionFactory(ClientConnectionFactoryDelegate delegate)
+   public JBossConnectionFactory(ClientConnectionFactoryImpl delegate)
    {
       this.delegate = delegate;      
    }
@@ -174,7 +174,7 @@
       return "JBossConnectionFactory->" + delegate;
    }
    
-   public ClientConnectionFactoryDelegate getDelegate()
+   public ClientConnectionFactoryImpl getDelegate()
    {
       return delegate;
    }

Modified: trunk/src/main/org/jboss/jms/client/api/ClientSession.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientSession.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/api/ClientSession.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -15,10 +15,10 @@
 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.client.impl.Ack;
+import org.jboss.jms.client.impl.Cancel;
+import org.jboss.jms.client.impl.ClientConsumer;
+import org.jboss.jms.client.impl.DeliveryInfo;
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.destination.JBossQueue;
 import org.jboss.jms.destination.JBossTopic;

Deleted: trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,174 +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 java.io.DataInputStream;
-import java.io.DataOutputStream;
-
-import javax.jms.JMSException;
-
-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;
-import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageBlockRequest;
-import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageBlockResponse;
-import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageResponse;
-import org.jboss.messaging.core.remoting.wireformat.BrowserResetMessage;
-import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
-
-/**
- * The client-side Browser delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
- *
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class ClientBrowserDelegate extends CommunicationSupport<ClientBrowserDelegate> implements ClientBrowser
-{
-   // Constants ------------------------------------------------------------------------------------
-
-	private static final long serialVersionUID = 3048255931412144958L;
-	
-   // Attributes -----------------------------------------------------------------------------------
-
-	private ClientSession session;
-   private Destination jmsDestination;
-   private String messageSelector;
-
-   // Static ---------------------------------------------------------------------------------------
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   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 --------------------------------------------------------------------
-
-   // Closeable implementation ---------------------------------------------------------------------
-
-   public void close() throws JMSException
-   {
-      sendBlocking(new CloseMessage());
-   }
-
-   public long closing(long sequence) throws JMSException
-   {
-      ClosingResponse response = (ClosingResponse) sendBlocking(new ClosingRequest(sequence));
-      return response.getID();
-   }
-
-   // BrowserDelegate implementation ---------------------------------------------------------------
-
-   public void reset() throws JMSException
-   {
-      sendBlocking(new BrowserResetMessage());
-   }
-
-   public boolean hasNextMessage() throws JMSException
-   {
-      BrowserHasNextMessageResponse response = (BrowserHasNextMessageResponse) sendBlocking(new BrowserHasNextMessageRequest());
-      return response.hasNext();
-   }
-
-   public Message nextMessage() throws JMSException
-   {
-      BrowserNextMessageResponse response = (BrowserNextMessageResponse) sendBlocking(new org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageRequest());
-      return response.getMessage();
-   }
-
-   public Message[] nextMessageBlock(int maxMessages) throws JMSException
-   {
-
-      BrowserNextMessageBlockResponse response = (BrowserNextMessageBlockResponse) sendBlocking(new BrowserNextMessageBlockRequest(maxMessages));
-      return response.getMessages();
-   }
-
-   // Streamable implementation ----------------------------------------------------------
-
-   public void read(DataInputStream in) throws Exception
-   {
-      super.read(in);
-   }
-
-   public void write(DataOutputStream out) throws Exception
-   {
-      super.write(out);
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public String getStackName()
-   {
-      return "BrowserStack";
-   }
-
-   public String toString()
-   {
-      return "BrowserDelegate[" + System.identityHashCode(this) + ", ID=" + id + "]";
-   }
-
-   // Protected ------------------------------------------------------------------------------------
-
-   @Override
-   protected Client getClient()
-   {
-      return this.session.getConnection().getClient();
-   }
-
-   @Override
-   protected byte getVersion()
-   {
-      return this.session.getConnection().getVersion();
-   }
-   
-   // Package Private ------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner Classes --------------------------------------------------------------------------------
-
-}

Deleted: trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionDelegate.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,434 +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 java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.util.Set;
-import javax.jms.ConnectionMetaData;
-import javax.jms.Destination;
-import javax.jms.ExceptionListener;
-import javax.jms.IllegalStateException;
-import javax.jms.JMSException;
-import javax.jms.ServerSessionPool;
-
-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.destination.JBossDestination;
-import org.jboss.jms.tx.ResourceManager;
-import org.jboss.jms.tx.ResourceManagerFactory;
-import org.jboss.jms.tx.TransactionRequest;
-import org.jboss.messaging.util.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;
-import org.jboss.messaging.core.remoting.wireformat.CreateSessionRequest;
-import org.jboss.messaging.core.remoting.wireformat.CreateSessionResponse;
-import org.jboss.messaging.core.remoting.wireformat.GetClientIDRequest;
-import org.jboss.messaging.core.remoting.wireformat.GetClientIDResponse;
-import org.jboss.messaging.core.remoting.wireformat.GetPreparedTransactionsRequest;
-import org.jboss.messaging.core.remoting.wireformat.GetPreparedTransactionsResponse;
-import org.jboss.messaging.core.remoting.wireformat.SendTransactionMessage;
-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.core.tx.MessagingXid;
-import org.jboss.messaging.util.ConcurrentHashSet;
-import org.jboss.messaging.util.ProxyFactory;
-import org.jboss.messaging.util.Version;
-
-/**
- * The client-side Connection delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class ClientConnectionDelegate extends CommunicationSupport<ClientConnectionDelegate> implements ClientConnection
-{
-   // Constants ------------------------------------------------------------------------------------
-
-   private static final long serialVersionUID = -5485083713058725777L;
-
-   private static final Logger log = Logger.getLogger(ClientConnectionDelegate.class);
-
-   private static final boolean trace = log.isTraceEnabled();
-
-   // Attributes -----------------------------------------------------------------------------------
-
-   protected JBossConnectionMetaData connMetaData;
-
-   private int serverID;
-
-   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 ---------------------------------------------------------------------------------
-
-   public ClientConnectionDelegate(String objectID, int serverID)
-   {
-      super(objectID);
-
-      this.serverID = serverID;
-   }
-
-   public ClientConnectionDelegate()
-   {
-      super();
-   }
-
-   // DelegateSupport overrides --------------------------------------------------------------------
-  
-   // Closeable implementation ---------------------------------------------------------------------
-
-   public void close() throws JMSException
-   {
-      try
-      {
-         sendBlocking(new CloseMessage());
-      }
-      finally
-      {
-         // remove the consolidated remoting connection listener
-
-         ConsolidatedRemotingConnectionListener l = remotingConnection.removeConnectionListener();
-         if (l != null)
-         {
-            l.clear();
-         }
-
-         // Finished with the connection - we need to shutdown callback server
-         remotingConnection.stop();
-
-         // And to resource manager
-         ResourceManagerFactory.instance.checkInResourceManager(getServerID());
-      }
-
-   }
-
-   public long closing(long sequence) throws JMSException
-   {
-      closeChildren();
-      ClosingResponse response = (ClosingResponse) sendBlocking(new ClosingRequest(sequence));
-      return response.getID();
-   }
-   
-   public Client getClient()
-   {
-      return this.getRemotingConnection().getRemotingClient();
-   }
-   
-   // Connection implementation ------------------------------------------------------------
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public JBossConnectionConsumer createConnectionConsumer(Destination dest,
-                                                           String subscriptionName,
-                                                           String messageSelector,
-                                                           ServerSessionPool sessionPool,
-                                                           int maxMessages) throws JMSException
-   {
-      if (trace) { log.trace("createConnectionConsumer()"); }
-
-
-      return new JBossConnectionConsumer((ClientConnection)ProxyFactory.proxy(this, ClientConnection.class), (JBossDestination)dest,
-                                         subscriptionName, messageSelector, sessionPool,
-                                         maxMessages);
-   }
-
-
-
-   public ClientSession createSessionDelegate(boolean transacted,
-                                                int acknowledgmentMode,
-                                                boolean isXA) throws JMSException
-   {
-
-      justCreated = false;
-
-      CreateSessionRequest request = new CreateSessionRequest(transacted, acknowledgmentMode, isXA);
-      CreateSessionResponse response = (CreateSessionResponse) sendBlocking(request);         
-      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
-   {
-      justCreated = false;
-
-      if (clientID == null)
-      {
-         //Get from the server
-         clientID = ((GetClientIDResponse) sendBlocking(new GetClientIDRequest())).getClientID();
-      }
-      return clientID;
-
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public ConnectionMetaData getConnectionMetaData() throws JMSException
-   {
-
-      justCreated = false;
-
-      if (connMetaData == null)
-      {
-         connMetaData = new JBossConnectionMetaData(versionToUse);
-      }
-
-      return connMetaData;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public ExceptionListener getExceptionListener() throws JMSException
-   {
-      justCreated = false;
-
-      return remotingConnection.getConnectionListener().getJMSExceptionListener(); 
-   }
-
-   public void sendTransaction(TransactionRequest tr) throws JMSException
-   {
-      sendBlocking(new SendTransactionMessage(tr));
-   }
-
-
-   public void setClientID(String clientID) throws JMSException
-   {
-      if (this.clientID != null)
-      {
-         throw new javax.jms.IllegalStateException("Client id has already been set");
-      }
-      if (!justCreated)
-      {
-         throw new IllegalStateException("setClientID can only be called directly after the connection is created");
-      }
-
-      this.clientID = clientID;
-      this.justCreated = false;
-
-      // this gets invoked on the server too
-      invokeSetClientID(clientID);
-      
-   }
-   private void invokeSetClientID(String clientID) throws JMSException
-   {
-      sendBlocking(new SetClientIDMessage(clientID));
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void setExceptionListener(ExceptionListener listener) throws JMSException
-   {
-      justCreated = false;
-
-      remotingConnection.getConnectionListener().addJMSExceptionListener(listener);
-   }
-
-   public void start() throws JMSException
-   {
-      started = true;
-      justCreated = false;
-      sendOneWay(new StartConnectionMessage());
-   }
-   
-   public void startAfterFailover() throws JMSException
-   {
-      sendOneWay(new StartConnectionMessage());
-   }
-
-   public void stop() throws JMSException
-   {
-      started = false;
-      justCreated = false;
-      sendBlocking(new StopConnectionMessage());
-   }
-
-   public MessagingXid[] getPreparedTransactions() throws JMSException
-   {
-      GetPreparedTransactionsResponse response = (GetPreparedTransactionsResponse) sendBlocking(new GetPreparedTransactionsRequest());
-      
-      return response.getXids();
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public void setRemotingConnection(JMSRemotingConnection conn)
-   {
-      this.remotingConnection = conn;
-   }
-
-   public JMSRemotingConnection getRemotingConnection()
-   {
-      return remotingConnection;
-   }
-
-   public int getServerID()
-   {
-      return serverID;
-   }
-
-   public Version getVersionToUse()
-   {
-      return versionToUse;
-   }
-
-   public void setVersionToUse(Version versionToUse)
-   {
-      this.versionToUse = versionToUse;
-   }
-
-   public String toString()
-   {
-      return "ConnectionDelegate[" + System.identityHashCode(this) + ", ID=" + id +
-         ", SID=" + serverID + "]";
-   }
-
-   // 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);
-            }
-         }
-         
-      }
-   }
-
-   
-   @Override
-   public byte getVersion()
-   {
-      if (versionToUse == null)
-      {
-         log.warn("Version to use it null");
-      }
-      return versionToUse.getProviderIncrementingVersion();
-   }
-
-   
-   // Streamable implementation -------------------------------------------------------------------
-
-   public void read(DataInputStream in) throws Exception
-   {
-      super.read(in);
-
-      serverID = in.readInt();
-   }
-
-   public void write(DataOutputStream out) throws Exception
-   {
-      super.write(out);
-
-      out.writeInt(serverID);
-   }
-
-   public ResourceManager getResourceManager()
-   {
-      return resourceManager;
-   }
-
-   public void setResourceManager(ResourceManager resourceManager)
-   {
-      this.resourceManager = resourceManager;
-   }
-   
-   // Package Private ------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner Classes --------------------------------------------------------------------------------
-
-}

Deleted: trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConnectionFactoryDelegate.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,318 +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.ConnectorRegistrySingleton.REGISTRY;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.Serializable;
-
-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.delegate.CreateConnectionResult;
-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;
-import org.jboss.messaging.core.remoting.impl.ClientImpl;
-import org.jboss.messaging.core.remoting.wireformat.CreateConnectionRequest;
-import org.jboss.messaging.core.remoting.wireformat.CreateConnectionResponse;
-import org.jboss.messaging.util.Version;
-
-/**
- * The client-side ConnectionFactory delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class ClientConnectionFactoryDelegate
-   extends CommunicationSupport<ClientConnectionFactoryDelegate> implements Serializable
-{
-   // Constants ------------------------------------------------------------------------------------
-
-   private static final long serialVersionUID = 2512460695662741413L;
-
-   // Attributes -----------------------------------------------------------------------------------
-
-   //This data is needed in order to create a connection
-
-   private String uniqueName;
-
-   private String serverLocatorURI;
-
-   private Version serverVersion;
- 
-   private int serverID;
-   
-   private boolean clientPing;
-
-   private boolean strictTck;
-   
-   // Static ---------------------------------------------------------------------------------------
-   
-   /*
-    * Calculate what version to use.
-    * The client itself has a version, but we also support other versions of servers lower if the
-    * connection version is lower (backwards compatibility)
-    */
-   private static Version getVersionToUse(Version connectionVersion)
-   {
-      Version clientVersion = Version.instance();
-
-      Version versionToUse;
-
-      if (connectionVersion.getProviderIncrementingVersion() <=
-          clientVersion.getProviderIncrementingVersion())
-      {
-         versionToUse = connectionVersion;
-      }
-      else
-      {
-         versionToUse = clientVersion;
-      }
-
-      return versionToUse;
-   }
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   public ClientConnectionFactoryDelegate(String uniqueName, String objectID, int serverID, 
-         String serverLocatorURI, Version serverVersion, boolean clientPing, boolean strictTck)
-   {
-      super(objectID);
-
-      this.uniqueName = uniqueName;
-      this.serverID = serverID;
-      this.serverLocatorURI = serverLocatorURI;
-      this.serverVersion = serverVersion;
-      this.clientPing = clientPing;
-      this.strictTck = strictTck;
-   }
-   
-   public ClientConnectionFactoryDelegate()
-   {
-   }
-   
-   protected Client getClient()
-   {
-      return null;
-   }
-
-   public CreateConnectionResult createConnectionDelegate(String username,
-                                                          String password,
-                                                          int failedNodeID)
-      throws JMSException
-   {
-      // If the method being invoked is createConnectionDelegate() then we must invoke it on the
-      // same remoting client subsequently used by the connection. This is because we need to pass
-      // in the remoting session id in the call to createConnection. All other invocations can be
-      // invoked on an arbitrary client, which can be created for each invocation.
-      //
-      // If we disable pinging on the client then it is a reasonably light weight operation to
-      // create the client since it will use the already existing invoker. This prevents us from
-      // having to maintain a Client instance per connection factory, which gives difficulties in
-      // knowing when to close it.
-      
-      Version version = getVersionToUse(serverVersion);
-      
-      byte v = version.getProviderIncrementingVersion();
-                       
-      CreateConnectionResult res;
-      
-      JMSRemotingConnection remotingConnection = null;
-      try
-      {
-         remotingConnection = new JMSRemotingConnection(serverLocatorURI);
-       
-         remotingConnection.start();
-         Client client = remotingConnection.getRemotingClient(); 
-         String sessionID = client.getSessionID();
-         
-         CreateConnectionRequest request = new CreateConnectionRequest(v, sessionID, JMSClientVMIdentifier.instance, failedNodeID, username, password);
-         CreateConnectionResponse response = (CreateConnectionResponse) sendBlocking(client, this.getID(), this.getVersion(), 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)
-      {
-         if (remotingConnection != null)
-         {
-            try
-            {
-               remotingConnection.stop();
-            }
-            catch (Throwable ignore)
-            {
-            }
-         }
-         throw handleThrowable(t);
-      }
-         
-      ClientConnection connectionDelegate = res.getInternalDelegate();
-      
-      if (connectionDelegate != null)
-      {
-         connectionDelegate.setRemotingConnection(remotingConnection);
-      }
-      else
-      {
-         //Wrong server redirect on failure
-         //close the remoting connection
-         try
-         {
-            remotingConnection.stop();
-         }
-         catch (Throwable ignore)
-         {
-         }
-      }
-
-      return res;
-   }
-   
-   // Public ---------------------------------------------------------------------------------------
-
-   public String toString()
-   {
-      return "ConnectionFactoryDelegate[" + id + ", SID=" + serverID + "]";
-   }
-   
-   public String getServerLocatorURI()
-   {
-      return serverLocatorURI;
-   }
-
-   
-   public int getServerID()
-   {
-      return serverID;
-   }
-   
-   public boolean getClientPing()
-   {
-      return clientPing;
-   }
-   
-   public Version getServerVersion()
-   {
-      return serverVersion;
-   }
-   
-   public String getName()
-   {
-      return uniqueName;
-   }
-
-
-   public boolean getStrictTck()
-   {
-       return strictTck;
-   }
-
-   // Protected ------------------------------------------------------------------------------------
-
-   // Package Private ------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-   
-   private Client createClient() throws JMSException
-   {
-      //We execute this on it's own client
-      Client client;
-      
-      try
-      {
-         ServerLocator locator = new ServerLocator(serverLocatorURI);
-         NIOConnector connector = REGISTRY.getConnector(locator);
-         client = new ClientImpl(connector, locator);
-         client.connect();
-      }
-      catch (Exception e)
-      {
-         throw new MessagingNetworkFailureException("Failed to connect client", e);
-      }
-      
-      return client;
-   }
-   
-   // Streamable implementation --------------------------------------------
-
-   public void read(DataInputStream in) throws Exception
-   {      
-      super.read(in);
-      
-      uniqueName = in.readUTF();
-      
-      serverLocatorURI = in.readUTF();
-      
-      serverVersion = new Version();
-      
-      serverVersion.read(in);
-      
-      serverID = in.readInt();
-      
-      clientPing = in.readBoolean();
-
-      strictTck = in.readBoolean();
-   }
-
-   public void write(DataOutputStream out) throws Exception
-   {
-      super.write(out);
-      
-      out.writeUTF(uniqueName);
-      
-      out.writeUTF(serverLocatorURI);
-      
-      serverVersion.write(out);
-      
-      out.writeInt(serverID);
-      
-      out.writeBoolean(clientPing);
-
-      out.writeBoolean(strictTck);
-   }
-
-   // Inner Classes --------------------------------------------------------------------------------
-
-}

Deleted: trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,349 +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 java.io.DataInputStream;
-import java.io.DataOutputStream;
-
-import javax.jms.JMSException;
-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.exception.MessagingShutdownException;
-import org.jboss.messaging.util.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.
- *
- * @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 CommunicationSupport<ClientConsumerDelegate> implements Consumer
-{
-   // Constants ------------------------------------------------------------------------------------
-
-	private static final long serialVersionUID = 3253922610778321868L;
-
-	private static final Logger log = Logger.getLogger(ClientConsumerDelegate.class);
-
-   // 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);
-      this.bufferSize = bufferSize;
-      this.maxDeliveries = maxDeliveries;
-      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 --------------------------------------------------------------------
-
-   @Override
-   protected byte getVersion()
-   {
-      return session.getConnection().getVersion();
-   }
-
-   protected Client getClient()
-   {
-      return this.session.getConnection().getClient();
-   }
-   
-   // Closeable implementation ---------------------------------------------------------------------
-
-   public void close() throws JMSException
-   {
-      sendBlocking(new CloseMessage());
-   }
-
-
-   public long closing(long sequence) throws JMSException
-   {
-      try
-      {
-         // We make sure closing is called on the ServerConsumerEndpoint.
-         // This returns us the last delivery id sent
-
-         long lastDeliveryId = invokeClosing(sequence);
-
-         // First we call close on the ClientConsumer which waits for onMessage invocations
-         // to complete and the last delivery to arrive
-         getClientConsumer().close(lastDeliveryId);
-
-         session.removeCallbackHandler(getClientConsumer());
-
-         CallbackManager cm = session.getConnection().getRemotingConnection().getCallbackManager();
-         cm.unregisterHandler(getConsumerID());
-
-         PacketDispatcher.client.unregister(getConsumerID());
-
-         //And then we cancel any messages still in the message callback handler buffer
-         getClientConsumer().cancelBuffer();
-
-         return lastDeliveryId;
-
-      }
-      catch (Exception proxiedException)
-      {
-         // 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 (!getClientConsumer().isClosed())
-            {
-               getClientConsumer().close(-1);
-            }
-         }
-         JMSException ex = new JMSException(proxiedException.toString());
-         ex.initCause(proxiedException);
-         throw ex;
-      }
-   }
-
-   private long invokeClosing(long sequence) throws JMSException
-   {
-      ClosingRequest request = new ClosingRequest(sequence);
-      ClosingResponse response = (ClosingResponse) sendBlocking(request);
-      return response.getID();
-   }
-
-   // ConsumerDelegate implementation --------------------------------------------------------------
-
-   public void changeRate(float newRate) throws JMSException
-   {
-      sendOneWay(new ChangeRateMessage(newRate));
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public MessageListener getMessageListener()
-   {
-      return getClientConsumer().getMessageListener();
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public Message receive(long timeout) throws JMSException
-   {
-      return getClientConsumer().receive(timeout);
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void setMessageListener(MessageListener listener) throws JMSException
-   {
-      getClientConsumer().setMessageListener(listener);
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public boolean getNoLocal()
-   {
-      return this.noLocal;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public Destination getDestination()
-   {
-      return this.destination;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public String getMessageSelector()
-   {
-      return this.selector;
-   }
-
-   // Streamable implementation ----------------------------------------------------------
-
-   public void read(DataInputStream in) throws Exception
-   {
-      super.read(in);
-
-      bufferSize = in.readInt();
-
-      maxDeliveries = in.readInt();
-      
-      redeliveryDelay = in.readLong();
-   }
-
-   public void write(DataOutputStream out) throws Exception
-   {
-      super.write(out);
-
-      out.writeInt(bufferSize);
-
-      out.writeInt(maxDeliveries);
-      
-      out.writeLong(redeliveryDelay);
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public String toString()
-   {
-      return "ConsumerDelegate[" + System.identityHashCode(this) + ", ID=" + id + "]";
-   }
-
-   public int getBufferSize()
-   {
-      return bufferSize;
-   }
-
-   public int getMaxDeliveries()
-   {
-      return maxDeliveries;
-   }
-   
-   public long getRedeliveryDelay()
-   {
-   	return redeliveryDelay;
-   }
-   
-   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 ------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner Classes --------------------------------------------------------------------------------
-
-}

Deleted: trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerPacketHandler.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerPacketHandler.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerPacketHandler.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,71 +0,0 @@
-package org.jboss.jms.client.delegate;
-
-import org.jboss.jms.client.container.ClientConsumer;
-import org.jboss.jms.message.JBossMessage;
-import org.jboss.messaging.core.remoting.PacketHandler;
-import org.jboss.messaging.core.remoting.PacketSender;
-import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
-import org.jboss.messaging.core.remoting.wireformat.DeliverMessage;
-import org.jboss.messaging.core.remoting.wireformat.PacketType;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class ClientConsumerPacketHandler implements PacketHandler
-{
-   /**
-    * 
-    */
-   private final ClientConsumer messageHandler;
-   /**
-    * 
-    */
-   private final String consumerID;
-
-   /**
-    * @param messageHandler
-    * @param consumerID
-    */
-   public ClientConsumerPacketHandler(ClientConsumer messageHandler,
-         String consumerID)
-   {
-      this.messageHandler = messageHandler;
-      this.consumerID = consumerID;
-   }
-
-   public String getID()
-   {
-      return consumerID;
-   }
-
-   public void handle(AbstractPacket packet, PacketSender sender)
-   {
-      try
-      {
-         PacketType type = packet.getType();
-         if (type == PacketType.MSG_DELIVERMESSAGE)
-         {
-            DeliverMessage message = (DeliverMessage) packet;
-            
-            JBossMessage msg = JBossMessage.createMessage(message.getMessage(), message.getDeliveryID(), message.getDeliveryCount());
-            
-            msg.doBeforeReceive();
-            
-            messageHandler.handleMessage(msg);
-         }
-      } catch (Exception e)
-      {
-         // TODO Auto-generated catch block
-         e.printStackTrace();
-      }
-   }
-
-   @Override
-   public String toString()
-   {
-      return "ConsumerAspectPacketHandler[id=" + consumerID + "]";
-   }
-}
\ No newline at end of file

Deleted: trunk/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientProducerDelegate.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,395 +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 java.util.UUID;
-
-import javax.jms.BytesMessage;
-import javax.jms.DeliveryMode;
-import javax.jms.JMSException;
-import javax.jms.MapMessage;
-import javax.jms.Message;
-import javax.jms.MessageFormatException;
-import javax.jms.ObjectMessage;
-import javax.jms.StreamMessage;
-import javax.jms.TextMessage;
-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;
-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.remoting.Client;
-import org.jboss.messaging.util.Logger;
-import org.jboss.messaging.core.DestinationType;
-import org.jboss.messaging.core.impl.DestinationImpl;
-
-/**
- * The client-side Producer delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
- *
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class ClientProducerDelegate extends CommunicationSupport<ClientProducerDelegate> implements ClientProducer
-{
-   // Constants ------------------------------------------------------------------------------------
-
-   private static final long serialVersionUID = -6976930316308905681L;
-   private static final Logger log = Logger.getLogger(ClientProducerDelegate.class);
-
-   // 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 ClientProducerDelegate(ClientConnection connection,
-         ClientSession session, JBossDestination destination)
-   {
-      super();
-      this.connection = connection;
-      this.session = session;
-      this.destination = destination;
-   }
-
-   // ProducerDelegate implementation --------------------------------------------------------------
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void close() throws JMSException
-   {
-      return;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public long closing(long sequence) throws JMSException
-   {
-      return -1;
-   }
-
-   public void setDestination(JBossDestination dest)
-   {
-      this.destination = dest;
-   }
-
-   public JBossDestination getDestination() throws JMSException
-   {
-      return this.destination;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void send(JBossDestination destination, Message m, int deliveryMode,
-                    int priority, long timeToLive) throws JMSException
-   {
-      send(destination, m, deliveryMode, priority, timeToLive, false);
-   }
-
-
-   public void send(JBossDestination destination, Message m, int deliveryMode, int priority, long timeToLive, boolean keepID) throws JMSException
-   {
-
-      // configure the message for sending, using attributes stored as metadata
-
-      if (deliveryMode == -1)
-      {
-         // Use the delivery mode of the producer
-         deliveryMode = getDeliveryMode();
-         if (trace) { log.trace("Using producer's default delivery mode: " + deliveryMode); }
-      }
-      m.setJMSDeliveryMode(deliveryMode);
-
-      if (priority == -1)
-      {
-         // Use the priority of the producer
-         priority = getPriority();
-         if (trace) { log.trace("Using producer's default priority: " + priority); }
-      }
-      if (priority < 0 || priority > 9)
-      {
-         throw new MessageFormatException("Invalid message priority (" + priority + "). " +
-                                          "Valid priorities are 0-9");
-      }
-      m.setJMSPriority(priority);
-
-      if (this.isDisableMessageTimestamp())
-      {
-         m.setJMSTimestamp(0l);
-      }
-      else
-      {
-         m.setJMSTimestamp(System.currentTimeMillis());
-      }
-
-      if (timeToLive == Long.MIN_VALUE)
-      {
-         // Use time to live value from producer
-         timeToLive = getTimeToLive();
-         if (trace) { log.trace("Using producer's default timeToLive: " + timeToLive); }
-      }
-
-      if (timeToLive == 0)
-      {
-         // Zero implies never expires
-         m.setJMSExpiration(0);
-      }
-      else
-      {
-         m.setJMSExpiration(System.currentTimeMillis() + timeToLive);
-      }
-
-      if (destination == null)
-      {
-         // use destination from producer
-         destination = (JBossDestination)getDestination();
-
-         if (destination == null)
-         {
-            throw new UnsupportedOperationException("Destination not specified");
-         }
-
-         if (trace) { log.trace("Using producer's default destination: " + destination); }
-      }
-      else
-      {
-         // if a default destination was already specified then this must be same destination as
-         // that specified in the arguments
-
-         if (getDestination() != null &&
-             !getDestination().equals(destination))
-         {
-            throw new UnsupportedOperationException("Where a default destination is specified " +
-                                                    "for the sender and a destination is " +
-                                                    "specified in the arguments to the send, " +
-                                                    "these destinations must be equal");
-         }
-      }
-
-      JBossMessage jbm;
-
-      boolean foreign = false;
-
-      //First convert from foreign message if appropriate
-      if (!(m instanceof JBossMessage))
-      {
-         // it's a foreign message
-
-         // JMS 1.1 Sect. 3.11.4: A provider must be prepared to accept, from a client,
-         // a message whose implementation is not one of its own.
-
-         // create a matching JBossMessage Type from JMS Type
-         if (m instanceof BytesMessage)
-         {
-            jbm = new JBossBytesMessage((BytesMessage)m);
-         }
-         else if (m instanceof MapMessage)
-         {
-            jbm = new JBossMapMessage((MapMessage)m);
-         }
-         else if (m instanceof ObjectMessage)
-         {
-            jbm = new JBossObjectMessage((ObjectMessage)m);
-         }
-         else if (m instanceof StreamMessage)
-         {
-            jbm = new JBossStreamMessage((StreamMessage)m);
-         }
-         else if (m instanceof TextMessage)
-         {
-            jbm = new JBossTextMessage((TextMessage)m);
-         }
-         else
-         {
-            jbm = new JBossMessage(m);
-         }
-
-         //Set the destination on the original message
-         m.setJMSDestination(destination);
-
-         foreign = true;
-      }
-      else
-      {
-         jbm = (JBossMessage)m;
-      }
-
-      if (!keepID)
-      {
-         //Generate an id
-         
-         String id = UUID.randomUUID().toString();
-         
-         jbm.setJMSMessageID("ID:" + id);
-      }
-
-      if (foreign)
-      {
-         m.setJMSMessageID(jbm.getJMSMessageID());
-      }
-
-      jbm.setJMSDestination(destination);
-
-      try
-      {
-         jbm.doBeforeSend();
-      }
-      catch (Exception e)
-      {
-         JMSException exthrown = new JMSException (e.toString());
-         exthrown.initCause(e);
-         throw exthrown;
-      }
-
-      JBossDestination dest = (JBossDestination)destination;
-
-      //Set the destination on the core message - TODO temp for refactoring
-      org.jboss.messaging.core.Destination coreDest =
-         new DestinationImpl(dest.isQueue() ? DestinationType.QUEUE : DestinationType.TOPIC, dest.getName(), dest.isTemporary());
-      
-      //TODO - can optimise this copy to do copy lazily.
-      org.jboss.messaging.core.Message messageToSend = jbm.getCoreMessage().copy();
-
-      //FIXME - temp - for now we set destination as a header - should really be an attribute of the
-      //send packet - along with scheduleddelivery time
-
-      messageToSend.putHeader(org.jboss.messaging.core.Message.TEMP_DEST_HEADER_NAME, coreDest);
-
-      // we now invoke the send(Message) method on the session, which will eventually be fielded
-      // by connection endpoint
-      session.send(messageToSend);
-   }
-
-   public void setDeliveryMode(int deliveryMode) throws JMSException
-   {
-      this.deliveryMode = deliveryMode;
-   }
-
-   public int getDeliveryMode() throws JMSException
-   {
-      return this.deliveryMode;
-   }
-
-   
-
-   public boolean isDisableMessageID() throws JMSException
-   {
-      return this.disableMessageID;
-   }
-
-   public void setDisableMessageID(boolean value) throws JMSException
-   {
-      this.disableMessageID = value;   
-   }
-
-   public boolean isDisableMessageTimestamp() throws JMSException
-   {
-      return this.disableMessageTimestamp;
-   }
-
-   public void setDisableMessageTimestamp(boolean value) throws JMSException
-   {
-      this.disableMessageTimestamp = value;
-   }
-
-   public void setPriority(int priority) throws JMSException
-   {
-      this.priority = priority;
-   }
-
-   public int getPriority() throws JMSException
-   {
-      return this.priority;
-   }
-
-   public long getTimeToLive() throws JMSException
-   {
-        return this.timeToLive;
-   }
-
-
-   public void setTimeToLive(long timeToLive) throws JMSException
-   {
-      this.timeToLive = timeToLive;
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public String toString()
-   {
-      return "ProducerDelegate[" + System.identityHashCode(this) + ", ID=" + id + "]";
-   }
-
-   // Protected ------------------------------------------------------------------------------------
-   
-
-   @Override
-   protected Client getClient()
-   {
-      return connection.getClient();
-   }
-   // Package Private ------------------------------------------------------------------------------
-
-   @Override
-   protected byte getVersion()
-   {
-      return connection.getVersion();
-   }
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner Classes --------------------------------------------------------------------------------
-
-}

Deleted: trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,1413 +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 java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-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;
-import javax.jms.MessageListener;
-import javax.jms.Session;
-import javax.jms.TransactionInProgressException;
-import javax.transaction.xa.XAResource;
-
-import org.jboss.jms.client.Closeable;
-import org.jboss.jms.client.SelectorTranslator;
-import org.jboss.jms.client.api.ClientBrowser;
-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.client.api.Consumer;
-import org.jboss.jms.client.container.ClientConsumer;
-import org.jboss.jms.client.remoting.CallbackManager;
-import org.jboss.jms.delegate.Ack;
-import org.jboss.jms.delegate.Cancel;
-import org.jboss.jms.delegate.DefaultCancel;
-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.jms.tx.LocalTx;
-import org.jboss.jms.tx.MessagingXAResource;
-import org.jboss.jms.tx.ResourceManager;
-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;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryResponse;
-import org.jboss.messaging.core.remoting.wireformat.AddTemporaryDestinationMessage;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveriesMessage;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveryMessage;
-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.wireformat.CreateBrowserRequest;
-import org.jboss.messaging.core.remoting.wireformat.CreateBrowserResponse;
-import org.jboss.messaging.core.remoting.wireformat.CreateConsumerRequest;
-import org.jboss.messaging.core.remoting.wireformat.CreateConsumerResponse;
-import org.jboss.messaging.core.remoting.wireformat.CreateDestinationRequest;
-import org.jboss.messaging.core.remoting.wireformat.CreateDestinationResponse;
-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.Logger;
-import org.jboss.messaging.util.MessageQueueNameHelper;
-import org.jboss.messaging.util.ProxyFactory;
-
-import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
-
-/**
- * The client-side Session delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class ClientSessionDelegate extends CommunicationSupport<ClientSessionDelegate> implements ClientSession
-{
-   // Constants ------------------------------------------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(ClientSessionDelegate.class);
-
-   private boolean trace = log.isTraceEnabled();
-
-   private static final long serialVersionUID = -8096852898620279131L;
-
-   // Attributes -----------------------------------------------------------------------------------
-
-   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(ClientConnection connection, String objectID, int dupsOKBatchSize)
-   {
-      super(objectID);
-      this.connection = connection;
-      this.dupsOKBatchSize = dupsOKBatchSize;
-   }
-   
-   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()
-   {
-   }
-
-   // DelegateSupport overrides --------------------------------------------------------------------
-
-   // Closeable implementation ---------------------------------------------------------------------
-
-   public void close() throws JMSException
-   {
-      sendBlocking(new CloseMessage());
-
-      Object xid = getCurrentTxId();
-
-      if (xid != null)
-      {
-         //Remove transaction from the resource manager
-         connection.getResourceManager().removeTx(xid);
-      }
-
-      // We must explicitly shutdown the executor
-
-      getExecutor().shutdownNow();
-
-   }
-
-   private long invokeClosing(long sequence) throws JMSException
-   {   	   
-      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
-   {
-      if (trace) { log.trace("handleClosing()"); }
-
-      closeChildren();
-      
-      //Sanity check
-      if (isXA() && !isXAAndConsideredNonTransacted())
-      {
-         if (trace) { log.trace("Session is XA"); }
-
-         ResourceManager rm = connection.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
-         // session to close. Closing the session causes any outstanding delivered but unacked
-         // messages to be cancelled to the server which means they would be available for other
-         // consumers to consume. If another consumer then consumes them, then recover() is called
-         // 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(this.getID()))
-         {
-            throw new javax.jms.IllegalStateException(
-               "Attempt to close an XASession when there are still uncommitted acknowledgements!");
-         }
-      }
-
-      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())
-      {
-         //Acknowledge or cancel any outstanding auto ack
-
-         DeliveryInfo remainingAutoAck = getAutoAckInfo();
-
-         if (remainingAutoAck != null)
-         {
-            if (trace) { log.trace(this + " handleClosing(). Found remaining auto ack. Will ack " + remainingAutoAck); }
-
-            try
-            {
-               ackDelivery(remainingAutoAck);
-
-               if (trace) { log.trace(this + " acked it"); }
-            }
-            finally
-            {
-               setAutoAckInfo(null);
-            }
-         }
-      }
-      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
-      {
-         //Ack any remaining deliveries
-
-         if (!getClientAckList().isEmpty())
-         {
-            try
-            {
-               acknowledgeDeliveries(getClientAckList());
-            }
-            finally
-            {
-               getClientAckList().clear();
-
-               setAutoAckInfo(null);
-            }
-         }
-      }
-      else if (ackMode == Session.CLIENT_ACKNOWLEDGE)
-      {
-         // Cancel any oustanding deliveries
-         // We cancel any client ack or transactional, we do this explicitly so we can pass the
-         // updated delivery count information from client to server. We could just do this on the
-         // server but we would lose delivery count info.
-
-         // CLIENT_ACKNOWLEDGE cannot be used with MDBs (i.e. no connection consumer)
-         // so is always safe to cancel on this session
-
-         internalCancelDeliveries(getClientAckList());
-
-         getClientAckList().clear();
-      }
-      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
-
-         List dels = connection.getResourceManager().getDeliveriesForSession(this.getID());
-
-         internalCancelDeliveries(dels);
-      }
-
-      return invokeClosing(sequence);
-
-   }
-
-   // 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());
-         AcknowledgeDeliveryResponse  response = (AcknowledgeDeliveryResponse) sendBlocking(request);
-         
-      return response.isAcknowledged();
-   }
-
-   public void acknowledgeDeliveries(List<Ack> acks) throws JMSException
-   {
-      sendBlocking(new AcknowledgeDeliveriesMessage(acks));
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void acknowledgeAll() throws JMSException
-   {
-      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(getClientAckList());
-
-         getClientAckList().clear();
-      }
-   }
-
-   public void addTemporaryDestination(Destination destination) throws JMSException
-   {
-      sendBlocking(new AddTemporaryDestinationMessage(destination));
-   }
-
-   public void commit() throws JMSException
-   {
-      if (!isTransacted())
-      {
-         throw new IllegalStateException("Cannot commit a non-transacted session");
-      }
-
-      if (isXA())
-      {
-         throw new TransactionInProgressException("Cannot call commit on an XA session");
-      }
-
-      try
-      {
-         connection.getResourceManager().commitLocal((LocalTx)getCurrentTxId(), connection);
-      }
-      finally
-      {
-         //Start new local tx
-         setCurrentTxId( connection.getResourceManager().createLocalTx() );
-      }
-
-   }
-
-
-   public ClientBrowser createBrowserDelegate(Destination queue, String messageSelector)
-      throws JMSException
-   {
-      String coreSelector = SelectorTranslator.convertToJBMFilterString(messageSelector);
-      CreateBrowserRequest request = new CreateBrowserRequest(queue, coreSelector);
-      CreateBrowserResponse response = (CreateBrowserResponse) sendBlocking(request);
-      ClientBrowserDelegate delegate = new ClientBrowserDelegate(this, response.getBrowserID(), queue, messageSelector);
-      ClientBrowser proxy = (ClientBrowser)ProxyFactory.proxy(delegate, ClientBrowser.class);
-      children.add(proxy);
-      return proxy;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public JBossBytesMessage createBytesMessage() throws JMSException
-   {
-      JBossBytesMessage jbm = new JBossBytesMessage();
-      return jbm;
-   }
-
-
-   public Consumer createConsumerDelegate(Destination destination, String selector,
-                                                  boolean noLocal, String subscriptionName,
-                                                  boolean isCC) throws JMSException
-   {
-      String coreSelector = SelectorTranslator.convertToJBMFilterString(selector);
-      CreateConsumerRequest request =
-         new CreateConsumerRequest(destination, coreSelector, noLocal, subscriptionName, isCC);
-      
-      CreateConsumerResponse response = (CreateConsumerResponse) sendBlocking(request);
-
-      ClientConsumerDelegate consumerDelegate = new ClientConsumerDelegate(this, response.getConsumerID(), response.getBufferSize(), response.getMaxDeliveries(), response.getRedeliveryDelay(),
-            destination,
-            selector, noLocal, subscriptionName, response.getConsumerID(),isCC);      
-
-      Consumer proxy = (Consumer)ProxyFactory.proxy(consumerDelegate, Consumer.class);
-      
-      children.add(proxy);
-
-      //We need the queue name for recovering any deliveries after failover
-      String queueName = 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
-         // server side.
-         // 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(this.getID(),subscriptionName);
-      }
-      else if (destination.getType() == DestinationType.QUEUE)
-      {
-         queueName = destination.getName();
-      }
-
-      final ClientConsumer messageHandler =
-         new ClientConsumer(isCC, this.getAcknowledgeMode(),
-                            this, consumerDelegate, consumerDelegate.getID(), queueName,
-                            consumerDelegate.getBufferSize(), this.getExecutor(), consumerDelegate.getMaxDeliveries(), consumerDelegate.isShouldAck(),
-                            consumerDelegate.getRedeliveryDelay());
-
-      this.addCallbackHandler(messageHandler);
-
-      PacketDispatcher.client.register(new ClientConsumerPacketHandler(messageHandler, consumerDelegate.getID()));
-
-      CallbackManager cm = connection.getRemotingConnection().getCallbackManager();
-      cm.registerHandler(consumerDelegate.getID(), messageHandler);
-
-      consumerDelegate.setClientConsumer(messageHandler);
-
-      //Now we have finished creating the client consumer, we can tell the SCD
-      //we are ready
-      consumerDelegate.changeRate(1);
-      
-      return proxy;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public JBossMapMessage createMapMessage() throws JMSException
-   {
-      JBossMapMessage jbm = new JBossMapMessage();
-      return jbm;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public JBossMessage createMessage() throws JMSException
-   {
-      JBossMessage jbm = new JBossMessage();
-      return jbm;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public JBossObjectMessage createObjectMessage() throws JMSException
-   {
-      JBossObjectMessage jbm = new JBossObjectMessage();
-      return jbm;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public JBossObjectMessage createObjectMessage(Serializable object) throws JMSException
-   {
-      JBossObjectMessage jbm = new JBossObjectMessage();
-      jbm.setObject(object);
-      return jbm;
-   }
-
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public ClientProducer createProducerDelegate(JBossDestination destination) throws JMSException
-   {
-      // ProducerDelegates are not created on the server
-
-      ClientProducerDelegate producerDelegate = new ClientProducerDelegate(connection, this, destination );
-      ClientProducer proxy = (ClientProducer) ProxyFactory.proxy(producerDelegate, ClientProducer.class);
-      children.add(proxy);
-      return proxy;
-   }
-
-   public JBossQueue createQueue(String queueName) throws JMSException
-   {
-      CreateDestinationRequest request = new CreateDestinationRequest(queueName, true);      
-      CreateDestinationResponse response = (CreateDestinationResponse) sendBlocking(request);
-      return (JBossQueue) response.getDestination();
-   }
-   
-   public JBossStreamMessage createStreamMessage() throws JMSException
-   {
-      JBossStreamMessage jbm = new JBossStreamMessage();
-      return jbm;
-   }
-
-   public JBossTextMessage createTextMessage() throws JMSException
-   {
-      JBossTextMessage jbm = new JBossTextMessage();
-      return jbm;
-   }
-
-   public JBossTextMessage createTextMessage(String text) throws JMSException
-   {
-      JBossTextMessage jbm = new JBossTextMessage();
-      jbm.setText(text);
-      return jbm;
-   }
-
-   public JBossTopic createTopic(String topicName) throws JMSException
-   {
-      CreateDestinationRequest request = new CreateDestinationRequest(topicName, false);      
-      CreateDestinationResponse response = (CreateDestinationResponse) sendBlocking(request);
-      return (JBossTopic) response.getDestination();
-   }
-
-   public void deleteTemporaryDestination(Destination destination) throws JMSException
-   {
-      sendBlocking(new DeleteTemporaryDestinationMessage(destination));
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public boolean postDeliver() throws JMSException
-   {
-      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())
-      {
-         // 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 (!isRecoverCalled())
-         {
-            DeliveryInfo delivery = getAutoAckInfo();
-
-            if (delivery == null)
-            {
-               throw new IllegalStateException("Cannot find delivery to AUTO_ACKNOWLEDGE");
-            }
-
-            if (trace) { log.trace(this + " auto acknowledging delivery " + delivery); }
-
-            // We clear the state in a finally so then we don't get a knock on
-            // exception on the next ack since we haven't cleared the state. See
-            // http://jira.jboss.org/jira/browse/JBMESSAGING-852
-
-            //This is ok since the message is acked after delivery, then the client
-            //could get duplicates anyway
-
-            try
-            {
-               res = ackDelivery(delivery);
-            }
-            finally
-            {
-               setAutoAckInfo(null);
-            }
-         }
-         else
-         {
-            if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }
-
-            setRecoverCalled(false);
-         }
-      }
-      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
-      {
-         List acks = getClientAckList();
-
-         if (!isRecoverCalled())
-         {
-            if (acks.size() >= getDupsOKBatchSize())
-            {
-               // We clear the state in a finally
-               // http://jira.jboss.org/jira/browse/JBMESSAGING-852
-
-               try
-               {
-                  acknowledgeDeliveries(acks);
-               }
-               finally
-               {
-                  acks.clear();
-                  setAutoAckInfo(null);
-               }
-            }
-         }
-         else
-         {
-            if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }
-
-            setRecoverCalled(false);
-         }
-         setAutoAckInfo(null);
-      }
-
-      return Boolean.valueOf(res);
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void preDeliver(DeliveryInfo info) throws JMSException
-   {
-      int ackMode = getAcknowledgeMode();
-
-      if (ackMode == Session.CLIENT_ACKNOWLEDGE)
-      {
-         // We collect acknowledgments in the list
-
-         if (trace) { log.trace(this + " added to CLIENT_ACKNOWLEDGE list delivery " + info); }
-
-         // Sanity check
-         if (info.getConnectionConsumerSession() != null)
-         {
-            throw new IllegalStateException(
-               "CLIENT_ACKNOWLEDGE cannot be used with a connection consumer");
-         }
-
-         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())
-      {
-         // We collect the single acknowledgement in the state.
-
-         if (trace) { log.trace(this + " added " + info + " to session state"); }
-
-         setAutoAckInfo(info);
-      }
-      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
-      {
-         if (trace) { log.trace(this + " added to DUPS_OK_ACKNOWLEDGE list delivery " + info); }
-
-         getClientAckList().add(info);
-
-         //Also set here - this would be used for recovery in a message listener
-         setAutoAckInfo(info);
-      }
-      else
-      {
-         Object txID = getCurrentTxId();
-
-         if (txID != null)
-         {
-            // the session is non-XA and transacted, or XA and enrolled in a global transaction. An
-            // XA session that has not been enrolled in a global transaction behaves as a
-            // transacted session.
-
-            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
-            // the connectionConsumer session as the session id, otherwise we use this sessions'
-            // session ID
-
-
-            ClientSession connectionConsumerDelegate =
-               info.getConnectionConsumerSession();
-
-            String sessionId = connectionConsumerDelegate != null ?
-               connectionConsumerDelegate.getID() : this.getID();
-
-            connection.getResourceManager().addAck(txID, sessionId, info);
-         }
-      }
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void recover() throws JMSException
-   {
-      if (trace) { log.trace("recover called"); }
-
-      if (isTransacted() && !isXAAndConsideredNonTransacted())
-      {
-         throw new IllegalStateException("Cannot recover a transacted session");
-      }
-
-      if (trace) { log.trace("recovering the session"); }
-
-      int ackMode = getAcknowledgeMode();
-
-      if (ackMode == Session.CLIENT_ACKNOWLEDGE)
-      {
-         List dels = getClientAckList();
-
-         setClientAckList(new ArrayList());
-
-         redeliver(dels);
-
-         setRecoverCalled(true);
-      }
-      else if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
-      {
-         DeliveryInfo info = getAutoAckInfo();
-
-         //Don't recover if it's already to cancel
-
-         if (info != null)
-         {
-            List redels = new ArrayList();
-
-            redels.add(info);
-
-            redeliver(redels);
-
-            setAutoAckInfo(null);
-
-            setRecoverCalled(true);
-         }
-      }
-   }
-
-   /**
-    * Redelivery occurs in two situations:
-    *
-    * 1) When session.recover() is called (JMS1.1 4.4.11)
-    *
-    * "A session's recover method is used to stop a session and restart it with its first
-    * unacknowledged message. In effect, the session's series of delivered messages is reset to the
-    * point after its last acknowledged message."
-    *
-    * An important note here is that session recovery is LOCAL to the session. Session recovery DOES
-    * NOT result in delivered messages being cancelled back to the channel where they can be
-    * redelivered - since that may result in them being picked up by another session, which would
-    * break the semantics of recovery as described in the spec.
-    *
-    * 2) When session rollback occurs (JMS1.1 4.4.7). On rollback of a session the spec is clear
-    * that session recovery occurs:
-    *
-    * "If a transaction rollback is done, its produced messages are destroyed and its consumed
-    * messages are automatically recovered. For more information on session recovery, see Section
-    * 4.4.11 'Message Acknowledgment.'"
-    *
-    * So on rollback we do session recovery (local redelivery) in the same as if session.recover()
-    * was called.
-    *
-    * All cancellation at rollback is driven from the client side - we always attempt to redeliver
-    * messages to their original consumers if they are still open, or then cancel them to the server
-    * if they are not. Cancelling them to the server explicitly allows the delivery count to be updated.
-    *
-    *
-    */
-   public void redeliver(List toRedeliver) throws JMSException
-   {
-      // We put the messages back in the front of their appropriate consumer buffers
-
-      if (trace) { log.trace(this + " handleRedeliver() called: " + toRedeliver); }
-
-      // Need to be redelivered in reverse order.
-      for (int i = toRedeliver.size() - 1; i >= 0; i--)
-      {
-         DeliveryInfo info = (DeliveryInfo)toRedeliver.get(i);
-         JBossMessage msg = info.getMessage();
-
-         ClientConsumer handler = getCallbackHandler(info.getConsumerId());
-
-         if (handler == null)
-         {
-            // This is ok. The original consumer has closed, so we cancel the message
-
-            cancelDelivery(info);
-         }
-         else if (handler.getRedeliveryDelay() != 0)
-         {
-         	//We have a redelivery delay in action - all delayed redeliveries are handled on the server
-
-         	cancelDelivery(info);
-         }
-         else
-         {
-            if (trace) { log.trace("Adding proxy back to front of buffer"); }
-
-            handler.addToFrontOfBuffer(msg);
-         }
-      }
-
-   }
-   
-   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 (!isTransacted())
-      {
-         throw new IllegalStateException("Cannot rollback a non-transacted session");
-      }
-
-      if (isXA())
-      {
-         throw new TransactionInProgressException("Cannot call rollback on an XA session");
-      }
-
-      ResourceManager rm = connection.getResourceManager();
-      try
-      {
-         rm.rollbackLocal(getCurrentTxId());
-      }
-      finally
-      {
-         // startnew local tx
-         Object xid = rm.createLocalTx();
-         setCurrentTxId(xid);
-      }
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void run() throws JMSException
-   {
-      if (trace) { log.trace("run()"); }
-
-      int ackMode = getAcknowledgeMode();
-
-      LinkedList msgs = getAsfMessages();
-
-      while (msgs.size() > 0)
-      {
-         AsfMessageHolder holder = (AsfMessageHolder)msgs.removeFirst();
-
-         if (trace) { log.trace("sending " + holder.msg + " to the message listener" ); }
-
-         ClientConsumer.callOnMessage(this, getDistinguishedListener(), holder.consumerID,
-                                      false,
-                                      holder.msg, ackMode, holder.maxDeliveries,
-                                      holder.connectionConsumerDelegate, holder.shouldAck);
-      }
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public void setMessageListener(MessageListener listener) throws JMSException
-   {
-      if (trace) { log.trace("setMessageListener()"); }
-
-      if (listener == null)
-      {
-         throw new IllegalStateException("Cannot set a null MessageListener on the session");
-      }
-
-      setDistinguishedListener(listener);
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public MessageListener getMessageListener() throws JMSException
-   {
-      if (trace) { log.trace("getMessageListener()"); }
-
-      return getDistinguishedListener();
-   }
-
-   
-
-   public void unsubscribe(String subscriptionName) throws JMSException
-   {
-      sendBlocking(new UnsubscribeMessage(subscriptionName));
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public XAResource getXAResource()
-   {
-      return xaResource;
-   }
-
-   /**
-    * This invocation should either be handled by the client-side interceptor chain or by the
-    * server-side endpoint.
-    */
-   public int getAcknowledgeMode()
-   {
-      return acknowledgeMode;
-   }
-
-   /**
-    * 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,
-                             ClientSession connectionConsumerDelegate, boolean shouldAck) throws JMSException
-   {
-      // Load the session with a message to be processed during a subsequent call to run()
-
-      if (m == null)
-      {
-         throw new IllegalStateException("Cannot add a null message to the session");
-      }
-
-      AsfMessageHolder holder = new AsfMessageHolder();
-      holder.msg = m;
-      holder.consumerID = theConsumerID;
-      holder.queueName = queueName;
-      holder.maxDeliveries = maxDeliveries;
-      holder.connectionConsumerDelegate = connectionConsumerDelegate;
-      holder.shouldAck = shouldAck;
-
-      getAsfMessages().add(holder);
-   }
-
-   public void send(Message m) throws JMSException
-   {
-      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 ((!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.
-
-         if (trace) { log.trace("sending message " + m + " transactionally, queueing on resource manager txID=" + txID + " sessionID= " + getID()); }
-
-         connection.getResourceManager().addMessage(txID, this.getID(), m);
-
-         // ... and we don't invoke any further interceptors in the stack
-         return;
-      }
-
-      if (trace) { log.trace("sending message NON-transactionally"); }
-
-      invokeSend(m);
-
-   }
-   
-   private void invokeSend(Message m) throws JMSException
-   {   	
-   	long seq;
-   	
-   	if (m.isDurable() || strictTck)
-   	{
-   		seq = -1;
-   	}
-   	else
-   	{
-   		seq = this.getNPSendSequence();
-   		
-   		this.incNpSendSequence();
-   	}
-   	
-   	SendMessage message = new SendMessage(m, seq);
-   	
-   	if (seq == -1)
-   	{
-   	   sendBlocking(message);
-   	}
-   	else
-   	{
-   	   sendOneWay(message);
-   	}
-   }
-
-   public void cancelDeliveries(List<Cancel> cancels) throws JMSException
-   {
-      sendBlocking(new CancelDeliveriesMessage(cancels));
-   }
-
-   public void cancelDelivery(Cancel cancel) throws JMSException
-   {
-      sendBlocking(new CancelDeliveryMessage(cancel));
-   }
-
-   // Streamable overrides -------------------------------------------------------------------------
-
-   public void read(DataInputStream in) throws Exception
-   {
-      super.read(in);
-
-      dupsOKBatchSize = in.readInt();
-   }
-
-   public void write(DataOutputStream out) throws Exception
-   {
-      super.write(out);
-
-      out.writeInt(dupsOKBatchSize);
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public int getDupsOKBatchSize()
-   {
-      return dupsOKBatchSize;
-   }
-
-   public boolean isStrictTck()
-   {
-      return strictTck;
-   }
-
-   public String toString()
-   {
-      return "SessionDelegate[" + System.identityHashCode(this) + ", ID=" + id + "]";
-   }
-
-   // Protected ------------------------------------------------------------------------------------
-
-   @Override
-   protected Client getClient()
-   {
-      return connection.getClient();
-   }
-   
-   @Override
-   protected byte getVersion()
-   {
-      return connection.getVersion();
-   }
-
-   
-   
-   // Package Private ------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-
-   /** http://jira.jboss.org/jira/browse/JBMESSAGING-946 - To accomodate TCK and the MQ behavior
-    *    we should behave as non transacted, AUTO_ACK when there is no transaction enlisted
-    *    However when the Session is being used by ASF we should consider the case where
-    *    we will convert LocalTX to GlobalTransactions.
-    *    This function helper will ensure the condition that needs to be tested on this aspect
-    *
-    *    There is a real conundrum here:
-    *
-    *    An XA Session needs to act as transacted when not enlisted for consuming messages for an MDB so when it does
-    *    get enlisted we can transfer the work inside the tx
-    *
-    *    But in needs to act as auto_acknowledge when not enlisted and not in an MDB (or bridge or stress test) to satisfy
-    *    integration tests and TCK!!! Hence getTreatAsNonTransactedWhenNotEnlisted()
-    *
-    * */
-   private boolean isXAAndConsideredNonTransacted()
-   {
-      return isXA() && (getCurrentTxId() instanceof LocalTx) && getTreatAsNonTransactedWhenNotEnlisted()
-             && getDistinguishedListener() == null;
-   }
-
-
-   private boolean ackDelivery(DeliveryInfo delivery) throws JMSException
-   {
-   	if (delivery.isShouldAck())
-   	{
-	      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
-
-	      ClientSession sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
-
-	      return sessionToUse.acknowledgeDelivery(delivery);
-   	}
-   	else
-   	{
-   		return true;
-   	}
-   }
-
-   private void cancelDelivery(DeliveryInfo delivery) throws JMSException
-   {
-   	if (delivery.isShouldAck())
-   	{
-   	   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
-
-   	   ClientSession sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
-
-	      sessionToUse.cancelDelivery(new DefaultCancel(delivery.getDeliveryID(),
-	                                  delivery.getMessage().getDeliveryCount(), false, false));
-   	}
-   }
-
-   private void internalCancelDeliveries( List deliveryInfos) throws JMSException
-   {
-      List cancels = new ArrayList();
-
-      for (Iterator i = deliveryInfos.iterator(); i.hasNext(); )
-      {
-         DeliveryInfo ack = (DeliveryInfo)i.next();
-
-         if (ack.isShouldAck())
-         {
-	         DefaultCancel cancel = new DefaultCancel(ack.getMessage().getDeliveryId(),
-	                                                  ack.getMessage().getDeliveryCount(),
-	                                                  false, false);
-
-	         cancels.add(cancel);
-         }
-      }
-
-      if (!cancels.isEmpty())
-      {
-         this.cancelDeliveries(cancels);
-      }
-   }
-
-   private void acknowledgeDeliveries(ClientSession del, List deliveryInfos) throws JMSException
-   {
-      List acks = new ArrayList();
-
-      for (Iterator i = deliveryInfos.iterator(); i.hasNext(); )
-      {
-         DeliveryInfo ack = (DeliveryInfo)i.next();
-
-         if (ack.isShouldAck())
-         {
-	         acks.add(ack);
-         }
-      }
-
-      if (!acks.isEmpty())
-      {
-         del.acknowledgeDeliveries(acks);
-      }
-   }
-
-   // Inner Classes --------------------------------------------------------------------------------
-
-
-   private static class AsfMessageHolder
-   {
-      private JBossMessage msg;
-      private String consumerID;
-      private String queueName;
-      private int maxDeliveries;
-      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;
-   }
-   
-
-}

Deleted: trunk/src/main/org/jboss/jms/client/delegate/CommunicationSupport.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/CommunicationSupport.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/delegate/CommunicationSupport.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,197 +0,0 @@
-/*
- * 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.messaging.util.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;
-import org.jboss.messaging.util.Version;
-
-/**
- * @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;
-   
-   
-   transient private boolean firstTime = true;
-   
-   
-   // getVersion cached (instead of calling it every time)
-   transient private byte cacheVersion;
-
-   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();
-   
-   protected byte getVersion()
-   {
-      return Version.instance().getProviderIncrementingVersion();
-   }
-   
-   public String getID()
-   {
-      return id;
-   }
-
-   public void setId(String id)
-   {
-      this.id = id;
-   }
-   
-   // Protected Methods-----------------------------------------------------------------------------
-   
-   protected void sendOneWay(AbstractPacket packet) throws JMSException
-   {
-      sendOneWay(getClient(), id, lookupVersion(), 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, lookupVersion(), 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);
-      }
-   }
-   
-   private byte lookupVersion()
-   {
-      if (firstTime)
-      {
-         firstTime=false;
-         cacheVersion = getVersion();
-      }
-      return cacheVersion;
-   }
-   
-   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);
-   }
-
-   
-
-}

Copied: trunk/src/main/org/jboss/jms/client/impl (from rev 3602, trunk/src/main/org/jboss/jms/client/container)

Copied: trunk/src/main/org/jboss/jms/client/impl/Ack.java (from rev 3602, trunk/src/main/org/jboss/jms/delegate/Ack.java)
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/Ack.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/Ack.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,36 @@
+/*
+ * 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.impl;
+
+/**
+ * A Ack
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ *
+ */
+public interface Ack
+{
+   long getDeliveryID();
+}

Added: trunk/src/main/org/jboss/jms/client/impl/AckImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/AckImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/AckImpl.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.client.impl;
+
+/**
+ * A AckImpl
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 2684 $</tt>
+ *
+ * $Id: AckImpl.java 2684 2007-05-15 07:31:30Z timfox $
+ *
+ */
+public class AckImpl implements Ack
+{
+
+   // Constants ------------------------------------------------------------------------------------
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   private long deliveryID;
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public AckImpl(long deliveryId)
+   {
+      this.deliveryID = deliveryId;
+   }
+
+   // Ack implementation ---------------------------------------------------------------------------
+
+   public long getDeliveryID()
+   {
+      return deliveryID;
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public String toString()
+   {
+      return "ACK[" + deliveryID + "]";
+   }
+
+   // Package protected ----------------------------------------------------------------------------
+
+   // Protected ------------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}

Copied: trunk/src/main/org/jboss/jms/client/impl/Cancel.java (from rev 3602, trunk/src/main/org/jboss/jms/delegate/Cancel.java)
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/Cancel.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/Cancel.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,42 @@
+/*
+ * 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.impl;
+
+/**
+ * A Cancel
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ *
+ */
+public interface Cancel
+{
+   long getDeliveryId();
+   
+   int getDeliveryCount();
+   
+   boolean isExpired();
+   
+   boolean isReachedMaxDeliveryAttempts();
+}

Added: trunk/src/main/org/jboss/jms/client/impl/CancelImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/CancelImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/CancelImpl.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,115 @@
+/*
+  * 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.impl;
+
+
+/**
+ * 
+ * A Cancel.
+ * 
+ * Used to send a cancel (NACK) to the server
+ * 
+ * When we cancel we send delivery count info, this means delivery count
+ * can be updated on the server, and into storage if persistent, and the
+ * message can be sent to DLQ if appropriate
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 3047 $</tt>
+ *
+ * $Id: CancelImpl.java 3047 2007-08-23 19:02:05Z clebert.suconic at jboss.com $
+ *
+ */
+public class CancelImpl implements Cancel
+{
+   // Constants -----------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+   
+   private long deliveryId;
+   
+   private int deliveryCount;    
+   
+   private boolean expired;
+   
+   private boolean reachedMaxDeliveryAttempts;
+
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+   
+   public CancelImpl()
+   {      
+   }
+   
+   public CancelImpl(long deliveryId, int deliveryCount, boolean expired, boolean maxDeliveries)
+   {      
+      this.deliveryId = deliveryId;
+      
+      this.deliveryCount = deliveryCount;
+      
+      this.expired = expired;
+      
+      this.reachedMaxDeliveryAttempts = maxDeliveries;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public long getDeliveryId()
+   {
+      return deliveryId;
+   }
+   
+   public int getDeliveryCount()
+   {
+      return deliveryCount;
+   }
+   
+   public boolean isExpired()
+   {
+      return expired;
+   }
+   
+   public boolean isReachedMaxDeliveryAttempts()
+   {
+      return reachedMaxDeliveryAttempts;
+   }
+
+   public String toString()
+   {
+      return "CancelImpl(deliveryId=" + deliveryId +
+             ", deliveryCount=" + deliveryCount +
+             ", expired=" + expired +
+             ", reachedMaxDeliveryAttempts=" + reachedMaxDeliveryAttempts + ")";
+   }
+
+   // Class YYY overrides -------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Package Private -----------------------------------------------
+
+   // Private -------------------------------------------------------
+   
+   // Inner Classes -------------------------------------------------
+   
+}
+

Added: trunk/src/main/org/jboss/jms/client/impl/ClientBrowserImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientBrowserImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientBrowserImpl.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,174 @@
+/*
+  * 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.impl;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+
+import javax.jms.JMSException;
+
+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;
+import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageBlockRequest;
+import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageBlockResponse;
+import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageResponse;
+import org.jboss.messaging.core.remoting.wireformat.BrowserResetMessage;
+import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
+import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
+import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
+
+/**
+ * The client-side Browser delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ * @version <tt>$Revision: 3602 $</tt>
+ *
+ * $Id: ClientBrowserImpl.java 3602 2008-01-21 17:48:32Z timfox $
+ */
+public class ClientBrowserImpl extends CommunicationSupport<ClientBrowserImpl> implements ClientBrowser
+{
+   // Constants ------------------------------------------------------------------------------------
+
+	private static final long serialVersionUID = 3048255931412144958L;
+	
+   // Attributes -----------------------------------------------------------------------------------
+
+	private ClientSession session;
+   private Destination jmsDestination;
+   private String messageSelector;
+
+   // Static ---------------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public ClientBrowserImpl(ClientSession session, String objectID, Destination jmsDestination, String messageSelector)
+   {
+      super(objectID);
+      this.session = session;
+      this.jmsDestination = jmsDestination;
+                  
+      this.messageSelector = messageSelector;
+   }
+
+   public ClientBrowserImpl(String objectID)
+   {
+      super(objectID);
+   }
+
+   public ClientBrowserImpl()
+   {
+   }
+
+   // DelegateSupport overrides --------------------------------------------------------------------
+
+   // Closeable implementation ---------------------------------------------------------------------
+
+   public void close() throws JMSException
+   {
+      sendBlocking(new CloseMessage());
+   }
+
+   public long closing(long sequence) throws JMSException
+   {
+      ClosingResponse response = (ClosingResponse) sendBlocking(new ClosingRequest(sequence));
+      return response.getID();
+   }
+
+   // BrowserDelegate implementation ---------------------------------------------------------------
+
+   public void reset() throws JMSException
+   {
+      sendBlocking(new BrowserResetMessage());
+   }
+
+   public boolean hasNextMessage() throws JMSException
+   {
+      BrowserHasNextMessageResponse response = (BrowserHasNextMessageResponse) sendBlocking(new BrowserHasNextMessageRequest());
+      return response.hasNext();
+   }
+
+   public Message nextMessage() throws JMSException
+   {
+      BrowserNextMessageResponse response = (BrowserNextMessageResponse) sendBlocking(new org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageRequest());
+      return response.getMessage();
+   }
+
+   public Message[] nextMessageBlock(int maxMessages) throws JMSException
+   {
+
+      BrowserNextMessageBlockResponse response = (BrowserNextMessageBlockResponse) sendBlocking(new BrowserNextMessageBlockRequest(maxMessages));
+      return response.getMessages();
+   }
+
+   // Streamable implementation ----------------------------------------------------------
+
+   public void read(DataInputStream in) throws Exception
+   {
+      super.read(in);
+   }
+
+   public void write(DataOutputStream out) throws Exception
+   {
+      super.write(out);
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public String getStackName()
+   {
+      return "BrowserStack";
+   }
+
+   public String toString()
+   {
+      return "BrowserDelegate[" + System.identityHashCode(this) + ", ID=" + id + "]";
+   }
+
+   // Protected ------------------------------------------------------------------------------------
+
+   @Override
+   protected Client getClient()
+   {
+      return this.session.getConnection().getClient();
+   }
+
+   @Override
+   protected byte getVersion()
+   {
+      return this.session.getConnection().getVersion();
+   }
+   
+   // Package Private ------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner Classes --------------------------------------------------------------------------------
+
+}

Added: trunk/src/main/org/jboss/jms/client/impl/ClientConnectionFactoryImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientConnectionFactoryImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConnectionFactoryImpl.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,316 @@
+/*
+ * 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.impl;
+
+import static org.jboss.messaging.core.remoting.ConnectorRegistrySingleton.REGISTRY;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+
+import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.jms.client.remoting.ConsolidatedRemotingConnectionListener;
+import org.jboss.jms.client.remoting.JMSRemotingConnection;
+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;
+import org.jboss.messaging.core.remoting.impl.ClientImpl;
+import org.jboss.messaging.core.remoting.wireformat.CreateConnectionRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateConnectionResponse;
+import org.jboss.messaging.util.Version;
+
+/**
+ * The client-side ConnectionFactory delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision: 3602 $</tt>
+ *
+ * $Id: ClientConnectionFactoryImpl.java 3602 2008-01-21 17:48:32Z timfox $
+ */
+public class ClientConnectionFactoryImpl
+   extends CommunicationSupport<ClientConnectionFactoryImpl> implements Serializable
+{
+   // Constants ------------------------------------------------------------------------------------
+
+   private static final long serialVersionUID = 2512460695662741413L;
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   //This data is needed in order to create a connection
+
+   private String uniqueName;
+
+   private String serverLocatorURI;
+
+   private Version serverVersion;
+ 
+   private int serverID;
+   
+   private boolean clientPing;
+
+   private boolean strictTck;
+   
+   // Static ---------------------------------------------------------------------------------------
+   
+   /*
+    * Calculate what version to use.
+    * The client itself has a version, but we also support other versions of servers lower if the
+    * connection version is lower (backwards compatibility)
+    */
+   private static Version getVersionToUse(Version connectionVersion)
+   {
+      Version clientVersion = Version.instance();
+
+      Version versionToUse;
+
+      if (connectionVersion.getProviderIncrementingVersion() <=
+          clientVersion.getProviderIncrementingVersion())
+      {
+         versionToUse = connectionVersion;
+      }
+      else
+      {
+         versionToUse = clientVersion;
+      }
+
+      return versionToUse;
+   }
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public ClientConnectionFactoryImpl(String uniqueName, String objectID, int serverID, 
+         String serverLocatorURI, Version serverVersion, boolean clientPing, boolean strictTck)
+   {
+      super(objectID);
+
+      this.uniqueName = uniqueName;
+      this.serverID = serverID;
+      this.serverLocatorURI = serverLocatorURI;
+      this.serverVersion = serverVersion;
+      this.clientPing = clientPing;
+      this.strictTck = strictTck;
+   }
+   
+   public ClientConnectionFactoryImpl()
+   {
+   }
+   
+   protected Client getClient()
+   {
+      return null;
+   }
+
+   public CreateConnectionResult createConnectionDelegate(String username,
+                                                          String password,
+                                                          int failedNodeID)
+      throws JMSException
+   {
+      // If the method being invoked is createConnectionDelegate() then we must invoke it on the
+      // same remoting client subsequently used by the connection. This is because we need to pass
+      // in the remoting session id in the call to createConnection. All other invocations can be
+      // invoked on an arbitrary client, which can be created for each invocation.
+      //
+      // If we disable pinging on the client then it is a reasonably light weight operation to
+      // create the client since it will use the already existing invoker. This prevents us from
+      // having to maintain a Client instance per connection factory, which gives difficulties in
+      // knowing when to close it.
+      
+      Version version = getVersionToUse(serverVersion);
+      
+      byte v = version.getProviderIncrementingVersion();
+                       
+      CreateConnectionResult res;
+      
+      JMSRemotingConnection remotingConnection = null;
+      try
+      {
+         remotingConnection = new JMSRemotingConnection(serverLocatorURI);
+       
+         remotingConnection.start();
+         Client client = remotingConnection.getRemotingClient(); 
+         String sessionID = client.getSessionID();
+         
+         CreateConnectionRequest request = new CreateConnectionRequest(v, sessionID, JMSClientVMIdentifier.instance, failedNodeID, username, password);
+         CreateConnectionResponse response = (CreateConnectionResponse) sendBlocking(client, this.getID(), this.getVersion(), request);
+         ClientConnectionImpl connectionDelegate = new ClientConnectionImpl(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)
+      {
+         if (remotingConnection != null)
+         {
+            try
+            {
+               remotingConnection.stop();
+            }
+            catch (Throwable ignore)
+            {
+            }
+         }
+         throw handleThrowable(t);
+      }
+         
+      ClientConnection connectionDelegate = res.getInternalDelegate();
+      
+      if (connectionDelegate != null)
+      {
+         connectionDelegate.setRemotingConnection(remotingConnection);
+      }
+      else
+      {
+         //Wrong server redirect on failure
+         //close the remoting connection
+         try
+         {
+            remotingConnection.stop();
+         }
+         catch (Throwable ignore)
+         {
+         }
+      }
+
+      return res;
+   }
+   
+   // Public ---------------------------------------------------------------------------------------
+
+   public String toString()
+   {
+      return "ConnectionFactoryDelegate[" + id + ", SID=" + serverID + "]";
+   }
+   
+   public String getServerLocatorURI()
+   {
+      return serverLocatorURI;
+   }
+
+   
+   public int getServerID()
+   {
+      return serverID;
+   }
+   
+   public boolean getClientPing()
+   {
+      return clientPing;
+   }
+   
+   public Version getServerVersion()
+   {
+      return serverVersion;
+   }
+   
+   public String getName()
+   {
+      return uniqueName;
+   }
+
+
+   public boolean getStrictTck()
+   {
+       return strictTck;
+   }
+
+   // Protected ------------------------------------------------------------------------------------
+
+   // Package Private ------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+   
+   private Client createClient() throws JMSException
+   {
+      //We execute this on it's own client
+      Client client;
+      
+      try
+      {
+         ServerLocator locator = new ServerLocator(serverLocatorURI);
+         NIOConnector connector = REGISTRY.getConnector(locator);
+         client = new ClientImpl(connector, locator);
+         client.connect();
+      }
+      catch (Exception e)
+      {
+         throw new MessagingNetworkFailureException("Failed to connect client", e);
+      }
+      
+      return client;
+   }
+   
+   // Streamable implementation --------------------------------------------
+
+   public void read(DataInputStream in) throws Exception
+   {      
+      super.read(in);
+      
+      uniqueName = in.readUTF();
+      
+      serverLocatorURI = in.readUTF();
+      
+      serverVersion = new Version();
+      
+      serverVersion.read(in);
+      
+      serverID = in.readInt();
+      
+      clientPing = in.readBoolean();
+
+      strictTck = in.readBoolean();
+   }
+
+   public void write(DataOutputStream out) throws Exception
+   {
+      super.write(out);
+      
+      out.writeUTF(uniqueName);
+      
+      out.writeUTF(serverLocatorURI);
+      
+      serverVersion.write(out);
+      
+      out.writeInt(serverID);
+      
+      out.writeBoolean(clientPing);
+
+      out.writeBoolean(strictTck);
+   }
+
+   // Inner Classes --------------------------------------------------------------------------------
+
+}

Added: trunk/src/main/org/jboss/jms/client/impl/ClientConnectionImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientConnectionImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConnectionImpl.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,434 @@
+/*
+  * 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.impl;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.util.Set;
+import javax.jms.ConnectionMetaData;
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.IllegalStateException;
+import javax.jms.JMSException;
+import javax.jms.ServerSessionPool;
+
+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.destination.JBossDestination;
+import org.jboss.jms.tx.ResourceManager;
+import org.jboss.jms.tx.ResourceManagerFactory;
+import org.jboss.jms.tx.TransactionRequest;
+import org.jboss.messaging.util.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;
+import org.jboss.messaging.core.remoting.wireformat.CreateSessionRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateSessionResponse;
+import org.jboss.messaging.core.remoting.wireformat.GetClientIDRequest;
+import org.jboss.messaging.core.remoting.wireformat.GetClientIDResponse;
+import org.jboss.messaging.core.remoting.wireformat.GetPreparedTransactionsRequest;
+import org.jboss.messaging.core.remoting.wireformat.GetPreparedTransactionsResponse;
+import org.jboss.messaging.core.remoting.wireformat.SendTransactionMessage;
+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.core.tx.MessagingXid;
+import org.jboss.messaging.util.ConcurrentHashSet;
+import org.jboss.messaging.util.ProxyFactory;
+import org.jboss.messaging.util.Version;
+
+/**
+ * The client-side Connection delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision: 3602 $</tt>
+ *
+ * $Id: ClientConnectionImpl.java 3602 2008-01-21 17:48:32Z timfox $
+ */
+public class ClientConnectionImpl extends CommunicationSupport<ClientConnectionImpl> implements ClientConnection
+{
+   // Constants ------------------------------------------------------------------------------------
+
+   private static final long serialVersionUID = -5485083713058725777L;
+
+   private static final Logger log = Logger.getLogger(ClientConnectionImpl.class);
+
+   private static final boolean trace = log.isTraceEnabled();
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   protected JBossConnectionMetaData connMetaData;
+
+   private int serverID;
+
+   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 ---------------------------------------------------------------------------------
+
+   public ClientConnectionImpl(String objectID, int serverID)
+   {
+      super(objectID);
+
+      this.serverID = serverID;
+   }
+
+   public ClientConnectionImpl()
+   {
+      super();
+   }
+
+   // DelegateSupport overrides --------------------------------------------------------------------
+  
+   // Closeable implementation ---------------------------------------------------------------------
+
+   public void close() throws JMSException
+   {
+      try
+      {
+         sendBlocking(new CloseMessage());
+      }
+      finally
+      {
+         // remove the consolidated remoting connection listener
+
+         ConsolidatedRemotingConnectionListener l = remotingConnection.removeConnectionListener();
+         if (l != null)
+         {
+            l.clear();
+         }
+
+         // Finished with the connection - we need to shutdown callback server
+         remotingConnection.stop();
+
+         // And to resource manager
+         ResourceManagerFactory.instance.checkInResourceManager(getServerID());
+      }
+
+   }
+
+   public long closing(long sequence) throws JMSException
+   {
+      closeChildren();
+      ClosingResponse response = (ClosingResponse) sendBlocking(new ClosingRequest(sequence));
+      return response.getID();
+   }
+   
+   public Client getClient()
+   {
+      return this.getRemotingConnection().getRemotingClient();
+   }
+   
+   // Connection implementation ------------------------------------------------------------
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public JBossConnectionConsumer createConnectionConsumer(Destination dest,
+                                                           String subscriptionName,
+                                                           String messageSelector,
+                                                           ServerSessionPool sessionPool,
+                                                           int maxMessages) throws JMSException
+   {
+      if (trace) { log.trace("createConnectionConsumer()"); }
+
+
+      return new JBossConnectionConsumer((ClientConnection)ProxyFactory.proxy(this, ClientConnection.class), (JBossDestination)dest,
+                                         subscriptionName, messageSelector, sessionPool,
+                                         maxMessages);
+   }
+
+
+
+   public ClientSession createSessionDelegate(boolean transacted,
+                                                int acknowledgmentMode,
+                                                boolean isXA) throws JMSException
+   {
+
+      justCreated = false;
+
+      CreateSessionRequest request = new CreateSessionRequest(transacted, acknowledgmentMode, isXA);
+      CreateSessionResponse response = (CreateSessionResponse) sendBlocking(request);         
+      ClientSessionImpl delegate = new ClientSessionImpl(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
+   {
+      justCreated = false;
+
+      if (clientID == null)
+      {
+         //Get from the server
+         clientID = ((GetClientIDResponse) sendBlocking(new GetClientIDRequest())).getClientID();
+      }
+      return clientID;
+
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public ConnectionMetaData getConnectionMetaData() throws JMSException
+   {
+
+      justCreated = false;
+
+      if (connMetaData == null)
+      {
+         connMetaData = new JBossConnectionMetaData(versionToUse);
+      }
+
+      return connMetaData;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public ExceptionListener getExceptionListener() throws JMSException
+   {
+      justCreated = false;
+
+      return remotingConnection.getConnectionListener().getJMSExceptionListener(); 
+   }
+
+   public void sendTransaction(TransactionRequest tr) throws JMSException
+   {
+      sendBlocking(new SendTransactionMessage(tr));
+   }
+
+
+   public void setClientID(String clientID) throws JMSException
+   {
+      if (this.clientID != null)
+      {
+         throw new javax.jms.IllegalStateException("Client id has already been set");
+      }
+      if (!justCreated)
+      {
+         throw new IllegalStateException("setClientID can only be called directly after the connection is created");
+      }
+
+      this.clientID = clientID;
+      this.justCreated = false;
+
+      // this gets invoked on the server too
+      invokeSetClientID(clientID);
+      
+   }
+   private void invokeSetClientID(String clientID) throws JMSException
+   {
+      sendBlocking(new SetClientIDMessage(clientID));
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public void setExceptionListener(ExceptionListener listener) throws JMSException
+   {
+      justCreated = false;
+
+      remotingConnection.getConnectionListener().addJMSExceptionListener(listener);
+   }
+
+   public void start() throws JMSException
+   {
+      started = true;
+      justCreated = false;
+      sendOneWay(new StartConnectionMessage());
+   }
+   
+   public void startAfterFailover() throws JMSException
+   {
+      sendOneWay(new StartConnectionMessage());
+   }
+
+   public void stop() throws JMSException
+   {
+      started = false;
+      justCreated = false;
+      sendBlocking(new StopConnectionMessage());
+   }
+
+   public MessagingXid[] getPreparedTransactions() throws JMSException
+   {
+      GetPreparedTransactionsResponse response = (GetPreparedTransactionsResponse) sendBlocking(new GetPreparedTransactionsRequest());
+      
+      return response.getXids();
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public void setRemotingConnection(JMSRemotingConnection conn)
+   {
+      this.remotingConnection = conn;
+   }
+
+   public JMSRemotingConnection getRemotingConnection()
+   {
+      return remotingConnection;
+   }
+
+   public int getServerID()
+   {
+      return serverID;
+   }
+
+   public Version getVersionToUse()
+   {
+      return versionToUse;
+   }
+
+   public void setVersionToUse(Version versionToUse)
+   {
+      this.versionToUse = versionToUse;
+   }
+
+   public String toString()
+   {
+      return "ConnectionDelegate[" + System.identityHashCode(this) + ", ID=" + id +
+         ", SID=" + serverID + "]";
+   }
+
+   // 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);
+            }
+         }
+         
+      }
+   }
+
+   
+   @Override
+   public byte getVersion()
+   {
+      if (versionToUse == null)
+      {
+         log.warn("Version to use it null");
+      }
+      return versionToUse.getProviderIncrementingVersion();
+   }
+
+   
+   // Streamable implementation -------------------------------------------------------------------
+
+   public void read(DataInputStream in) throws Exception
+   {
+      super.read(in);
+
+      serverID = in.readInt();
+   }
+
+   public void write(DataOutputStream out) throws Exception
+   {
+      super.write(out);
+
+      out.writeInt(serverID);
+   }
+
+   public ResourceManager getResourceManager()
+   {
+      return resourceManager;
+   }
+
+   public void setResourceManager(ResourceManager resourceManager)
+   {
+      this.resourceManager = resourceManager;
+   }
+   
+   // Package Private ------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner Classes --------------------------------------------------------------------------------
+
+}

Deleted: trunk/src/main/org/jboss/jms/client/impl/ClientConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java	2008-01-21 17:48:32 UTC (rev 3602)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConsumer.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,939 +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.container;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.jms.IllegalStateException;
-import javax.jms.JMSException;
-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.DefaultCancel;
-import org.jboss.jms.delegate.DeliveryInfo;
-import org.jboss.jms.message.JBossMessage;
-import org.jboss.messaging.util.Logger;
-import org.jboss.messaging.core.Message;
-import org.jboss.messaging.core.PriorityLinkedList;
-import org.jboss.messaging.core.impl.PriorityLinkedListImpl;
-import org.jboss.messaging.util.Future;
-
-import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
-
-/**
- * @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 $
- */
-public class ClientConsumer
-{
-   // Constants ------------------------------------------------------------------------------------
-   
-   private static final Logger log;
-   
-   // Static ---------------------------------------------------------------------------------------
-   
-   private static boolean trace;      
-   
-   private static final int WAIT_TIMEOUT = 30000;
-   
-   
-   static
-   {
-      log = Logger.getLogger(ClientConsumer.class);
-      trace = log.isTraceEnabled();
-   }
-   
-   private static boolean checkExpiredOrReachedMaxdeliveries(JBossMessage jbm,
-                                                             ClientSession del,
-                                                             int maxDeliveries, boolean shouldCancel)
-   {
-      Message msg = jbm.getCoreMessage();
-      
-      boolean expired = msg.isExpired();
-      
-      boolean reachedMaxDeliveries = jbm.getDeliveryCount() == maxDeliveries;
-      
-      if (expired || reachedMaxDeliveries)
-      {
-         if (trace)
-         {
-            if (expired)
-            {
-               log.trace(msg + " has expired, cancelling to server");
-            }
-            else
-            {
-               log.trace(msg + " has reached maximum delivery number " + maxDeliveries +", cancelling to server");
-            }
-         }
-         
-         if (shouldCancel)
-         {	         
-	         final Cancel cancel = new DefaultCancel(jbm.getDeliveryId(), jbm.getDeliveryCount(),
-	                                                 expired, reachedMaxDeliveries);	         
-	         try
-	         {
-	            del.cancelDelivery(cancel);
-	         }
-	         catch (JMSException e)
-	         {
-	            log.error("Failed to cancel delivery", e);
-	         }   
-         }
-               
-         return true;
-      }
-      else
-      {
-         return false;
-      }
-   }
-        
-   //This is static so it can be called by the asf layer too
-   public static void callOnMessage(ClientSession sess,
-                                    MessageListener listener,
-                                    String consumerID,
-                                    String queueName,
-                                    boolean isConnectionConsumer,
-                                    JBossMessage m,
-                                    int ackMode,
-                                    int maxDeliveries,
-                                    ClientSession connectionConsumerSession,
-                                    boolean shouldAck)
-      throws JMSException
-   {      
-      if (checkExpiredOrReachedMaxdeliveries(m, connectionConsumerSession!=null?connectionConsumerSession:sess, maxDeliveries, shouldAck))
-      {
-         //Message has been cancelled
-         return;
-      }
-      
-      DeliveryInfo deliveryInfo =
-         new DeliveryInfo(m, consumerID, queueName, connectionConsumerSession, shouldAck);
-            
-      m.incDeliveryCount();
-      
-      // If this is the callback-handler for a connection consumer we don't want to acknowledge or
-      // add anything to the tx for this session.
-      if (!isConnectionConsumer)
-      {
-         //We need to call preDeliver, deliver the message then call postDeliver - this is because
-         //it is legal to call session.recover(), or session.rollback() from within the onMessage()
-         //method in which case the last message needs to be delivered so it needs to know about it
-         sess.preDeliver(deliveryInfo);
-      } 
-      
-      try
-      {
-         if (trace) { log.trace("calling listener's onMessage(" + m + ")"); }
-                     
-         listener.onMessage(m);
-
-         if (trace) { log.trace("listener's onMessage() finished"); }
-      }
-      catch (RuntimeException e)
-      {
-         log.error("RuntimeException was thrown from onMessage, " + m.getJMSMessageID() + " will be redelivered", e);
-         
-         // See JMS 1.1 spec 4.5.2
-
-         if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE)
-         {              
-            sess.recover();
-         }
-      }   
-
-      // If this is the callback-handler for a connection consumer we don't want to acknowledge
-      // or add anything to the tx for this session
-      if (!isConnectionConsumer)
-      {
-      	if (trace) { log.trace("Calling postDeliver"); }
-      	
-         sess.postDeliver();
-         
-         if (trace) { log.trace("Called postDeliver"); }
-      }   
-   }
-   
-   // Attributes -----------------------------------------------------------------------------------
-      
-   /*
-    * The buffer is now a priority linked list
-    * This resolves problems whereby messages are delivered from the server side queue in
-    * correct priority order, but because the old consumer list was not a priority list
-    * then if messages were sitting waiting to be consumed on the client side, then higher
-    * priority messages might be behind lower priority messages and thus get consumed out of order
-    */
-   private PriorityLinkedList<JBossMessage> buffer;
-   private ClientSession sessionDelegate;
-   private Consumer consumerDelegate;
-   private String consumerID;
-   private boolean isConnectionConsumer;
-   private volatile Thread receiverThread;
-   private MessageListener listener;
-   private int ackMode;
-   private boolean closed;
-   private Object mainLock;
-   private QueuedExecutor sessionExecutor;
-   private boolean listenerRunning;
-   private int maxDeliveries;
-   private String queueName;
-   private long lastDeliveryId = -1;
-   private boolean waitingForLastDelivery;
-   private boolean shouldAck;
-   private long redeliveryDelay;
-   private boolean paused;      
-   private int consumeCount;
-   private boolean firstTime = true;
-   private int bufferSize;
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   public ClientConsumer(boolean isCC, int ackMode,                                
-                         ClientSession sess, Consumer cons, String consumerID,
-                         String queueName,
-                         int bufferSize, QueuedExecutor sessionExecutor,
-                         int maxDeliveries, boolean shouldAck,
-                         long redeliveryDelay)
-   {
-      if (bufferSize < 1)
-      {
-         throw new IllegalArgumentException(this + " bufferSize must be > 0");
-      }
-              
-      buffer = new PriorityLinkedListImpl<JBossMessage>(10);
-      isConnectionConsumer = isCC;
-      this.ackMode = ackMode;
-      this.sessionDelegate = sess;
-      this.consumerDelegate = cons;
-      this.consumerID = consumerID;
-      this.queueName = queueName;
-      mainLock = new Object();
-      this.sessionExecutor = sessionExecutor;
-      this.maxDeliveries = maxDeliveries;
-      this.shouldAck = shouldAck;
-      this.redeliveryDelay = redeliveryDelay;
-      this.bufferSize = bufferSize;
-   }
-        
-   // Public ---------------------------------------------------------------------------------------
-
-
-   public boolean isClosed()
-   {
-      return closed;
-   }
-
-   /**
-    * Handles a message sent from the server.
-    *
-    * @param message The message
-    */
-   public void handleMessage(final JBossMessage message) throws Exception
-   {
-      synchronized (mainLock)
-      {
-         if (closed)
-         {
-            // Sanity - this should never happen - we should always wait for all deliveries to arrive
-            // when closing
-            throw new IllegalStateException(this + " is closed, so ignoring message");
-         }
-
-         message.setSessionDelegate(sessionDelegate, isConnectionConsumer);
-
-         message.doBeforeReceive();
-
-         //Add it to the buffer
-         buffer.addLast(message, message.getJMSPriority());
-
-         lastDeliveryId = message.getDeliveryId();
-
-         if (trace) { log.trace(this + " added message(s) to the buffer are now " + buffer.size() + " messages"); }
-
-         messageAdded();
-      }
-   }
-
-   public void setMessageListener(MessageListener listener) throws JMSException
-   {     
-      synchronized (mainLock)
-      {
-         if (receiverThread != null)
-         {
-            // Should never happen
-            throw new IllegalStateException("Consumer is currently in receive(..). " +
-               "Cannot set MessageListener");
-         }
-         
-         this.listener = listener;
-                            
-         if (listener != null && !buffer.isEmpty())
-         {  
-            listenerRunning = true;
-            
-            this.queueRunner(new ListenerRunner());
-         }        
-      }   
-   }
-   
-   public void cancelBuffer() throws JMSException
-   {
-   	if (trace) { log.trace("Cancelling buffer: " + buffer.size()); }
-   	
-      synchronized (mainLock)
-      {      
-         // Now we cancel anything left in the buffer. The reason we do this now is that otherwise
-         // the deliveries wouldn't get cancelled until session close (since we don't cancel
-         // consumer's deliveries until then), which is too late - since we need to preserve the
-         // order of messages delivered in a session.
-         
-         if (shouldAck && !buffer.isEmpty())
-         {                        
-            // Now we cancel any deliveries that might be waiting in our buffer. This is because
-            // otherwise the messages wouldn't get cancelled until the corresponding session died.
-            // So if another consumer in another session tried to consume from the channel before
-            // that session died it wouldn't receive those messages.
-            // We can't just cancel all the messages in the SCE since some of those messages might
-            // have actually been delivered (unlike these) and we may want to acknowledge them
-            // later, after this consumer has been closed
-   
-            List cancels = new ArrayList();
-   
-            for(Iterator i = buffer.iterator(); i.hasNext();)
-            {
-               JBossMessage mp = (JBossMessage)i.next();
-               
-               DefaultCancel cancel =
-                  new DefaultCancel(mp.getDeliveryId(), mp.getDeliveryCount(), false, false);
-               
-               cancels.add(cancel);
-            }
-                  
-            if (trace) { log.trace("Calling cancelDeliveries"); }
-            sessionDelegate.cancelDeliveries(cancels);
-            if (trace) { log.trace("Done call"); }
-            
-            buffer.clear();
-         }    
-      }
-   }
-   
-   public void close(long lastDeliveryId) throws JMSException
-   {     
-   	log.trace(this + " close");
-         	
-   	//Wait for the last delivery to arrive
-      waitForLastDelivery(lastDeliveryId);
-      
-      //Important! We set the listener to null so the next ListenerRunner won't run
-      if (listener != null)
-      {
-      	setMessageListener(null);
-      }
-      
-      //Now we wait for any current listener runners to run.
-      waitForOnMessageToComplete();   
-      
-      synchronized (mainLock)
-      {         
-         if (closed)
-         {
-            return;
-         }
-         
-         closed = true;   
-         
-         if (receiverThread != null)
-         {            
-            // Wake up any receive() thread that might be waiting
-            mainLock.notify();
-         }   
-         
-         this.listener = null;
-      }
-                           
-      if (trace) { log.trace(this + " closed"); }
-   }
-     
-   /**
-    * Method used by the client thread to get a Message, if available.
-    *
-    * @param timeout - the timeout value in milliseconds. A zero timeount never expires, and the
-    *        call blocks indefinitely. A -1 timeout means receiveNoWait(): return the next message
-    *        or null if one is not immediately available. Returns null if the consumer is
-    *        concurrently closed.
-    */
-   public JBossMessage receive(long timeout) throws JMSException
-   {                
-      JBossMessage m = null;      
-      
-      synchronized (mainLock)
-      {        
-         if (trace) { log.trace(this + " receiving, timeout = " + timeout); }
-         
-         if (closed)
-         {
-            // If consumer is closed or closing calling receive returns null
-            if (trace) { log.trace(this + " closed, returning null"); }
-            return null;
-         }
-         
-         if (listener != null)
-         {
-            throw new JMSException("The consumer has a MessageListener set, " +
-               "cannot call receive(..)");
-         }
-                       
-         receiverThread = Thread.currentThread();
-               
-         long startTimestamp = System.currentTimeMillis();
-                  
-         try
-         {
-            while(true)
-            {                             
-               if (timeout == 0)
-               {
-                  if (trace) { log.trace(this + ": receive, no timeout"); }
-                  
-                  m = getMessage(0);                     
-                  
-                  if (m == null)
-                  {
-                     return null;
-                  }
-               }
-               else if (timeout == -1)
-               {
-                  //ReceiveNoWait
-                  if (trace) { log.trace(this + ": receive, noWait"); }
-                  
-                  m = getMessage(-1);                     
-                  
-                  if (m == null)
-                  {
-                     if (trace) { log.trace(this + ": no message available"); }
-                     return null;
-                  }
-               }
-               else
-               {
-                  if (trace) { log.trace(this + ": receive, timeout " + timeout + " ms, blocking poll on queue"); }
-                  
-                  m = getMessage(timeout);
-                                    
-                  if (m == null)
-                  {
-                     // timeout expired
-                     if (trace) { log.trace(this + ": " + timeout + " ms timeout expired"); }
-                     
-                     return null;
-                  }
-               }
-                              
-               if (trace) { log.trace(this + " received " + m + " after being blocked on buffer"); }
-                       
-               boolean ignore =
-                  checkExpiredOrReachedMaxdeliveries(m, sessionDelegate, maxDeliveries, shouldAck);
-               
-               if (!isConnectionConsumer && !ignore)
-               {
-                  DeliveryInfo info = new DeliveryInfo(m, consumerID, queueName, null, shouldAck);
-                                                    
-                  sessionDelegate.preDeliver(info);                  
-                  
-                  //If post deliver didn't succeed and acknowledgement mode is auto_ack
-                  //That means the ref wasn't acked since it couldn't be found.
-                  //In order to maintain at most once semantics we must therefore not return
-                  //the message
-                  
-                  ignore = !sessionDelegate.postDeliver();  
-                  
-                  if (trace)
-                  {
-                  	log.trace("Post deliver returned " + !ignore);
-                  }
-                  
-                  if (!ignore)
-                  {
-                     m.incDeliveryCount();                                
-                  }
-               }
-                                             
-               if (!ignore)
-               {
-                  if (trace) { log.trace(this + ": message " + m + " is not expired, pushing it to the caller"); }
-                  
-                  break;
-               }
-               
-               if (trace)
-               {
-                  log.trace("Discarding message " + m);
-               }
-               
-               // the message expired, so discard the message, adjust timeout and reenter the buffer
-               if (timeout != 0)
-               {
-                  timeout -= System.currentTimeMillis() - startTimestamp;
-                  if (timeout == 0)
-                  {
-                     // As 0 means waitForever, we make it noWait
-                     timeout = -1;
-                  }
-
-               }
-            }           
-         }
-         finally
-         {
-            receiverThread = null;            
-         }
-      } 
-      
-      if (trace) { log.trace(this + " receive() returning " + m); }
-      
-      return m;
-   } 
-         
-   public MessageListener getMessageListener()
-   {
-      return listener;      
-   }
-
-   public String toString()
-   {
-      return "ClientConsumer[" + consumerID + "]";
-   }
-   
-   public String getConsumerId()
-   {
-      return consumerID;
-   }
-
-   public void setConsumerId(String consumerId)
-   {
-       this.consumerID = consumerId;
-   }
-   
-   public void addToFrontOfBuffer(JBossMessage proxy) throws JMSException
-   {
-      synchronized (mainLock)
-      {
-         buffer.addFirst(proxy, proxy.getJMSPriority());
-         
-         consumeCount--;
-         
-         messageAdded();
-      }
-   }
-
-   public long getRedeliveryDelay()
-   {
-   	return redeliveryDelay;
-   }
-   
-   public void pause()
-   {
-      synchronized (mainLock)
-      {
-         paused = true;
-
-         sendChangeRateMessage(0f);         
-      }
-   }
-
-   public void resume()
-   {
-      synchronized (mainLock)
-      {
-         paused = false;
-
-         if (firstTime)
-         {
-            consumeCount = 0;
-
-            firstTime = false;
-         }
-         else
-         {
-            consumeCount = bufferSize / 3 - buffer.size();
-         }
-
-         sendChangeRateMessage(1f);
-      }
-   }
-
-   
-   // Package protected ----------------------------------------------------------------------------
-   
-   // Protected ------------------------------------------------------------------------------------
-            
-   // Private --------------------------------------------------------------------------------------
-
-   private void checkSendChangeRate()
-   {
-      consumeCount++;
-      
-      if (!paused && consumeCount == bufferSize)
-      {
-         consumeCount = 0;
-
-         sendChangeRateMessage(1.0f);
-      }
-   }
-
-   /*
-    * Wait for the last delivery to arrive
-    */
-   private void waitForLastDelivery(long id)
-   {
-      if (trace) { log.trace("Waiting for last delivery id " + id); }
-      
-      if (id == -1)
-      {
-      	//No need to wait - nothing to wait for      	
-      	return;
-      }
-      
-      synchronized (mainLock)
-      {          
-         waitingForLastDelivery = true;
-         try
-         {
-            long wait = WAIT_TIMEOUT;
-            while (lastDeliveryId != id && wait > 0)
-            {
-               long start = System.currentTimeMillis();  
-               try
-               {
-                  mainLock.wait(wait);
-               }
-               catch (InterruptedException e)
-               {               
-               }
-               wait -= (System.currentTimeMillis() - start);
-            }      
-            if (trace && lastDeliveryId == id)
-            {
-               log.trace("Got last delivery");
-            }
-             
-            if (lastDeliveryId != id)
-            {
-               log.warn("Timed out waiting for last delivery " + id + " got " + lastDeliveryId); 
-            }
-         }
-         finally
-         {
-            waitingForLastDelivery = false;
-         }
-      }
-   }
-   
-   private void sendChangeRateMessage(float newRate) 
-   {
-      try
-      {
-         // this invocation will be sent asynchronously to the server; it's DelegateSupport.invoke()
-         // job to detect it and turn it into a remoting one way invocation.
-         consumerDelegate.changeRate(newRate);
-      }
-      catch (JMSException e)
-      {
-         log.error("Failed to send changeRate message", e);
-      }
-   }
-   
-   private void waitForOnMessageToComplete()
-   {
-      // Wait for any onMessage() executions to complete
-
-      if (Thread.currentThread().equals(sessionExecutor.getThread()))
-      {
-         // the current thread already closing this ClientConsumer (this happens when the
-         // session is closed from within the MessageListener.onMessage(), for example), so no need
-         // to register another Closer (see http://jira.jboss.org/jira/browse/JBMESSAGING-542)
-         return;
-      }
-
-      Future result = new Future();
-      
-      try
-      {
-         sessionExecutor.execute(new Closer(result));
-
-         if (trace) { log.trace(this + " blocking wait for Closer execution"); }
-         result.getResult();
-         if (trace) { log.trace(this + " got Closer result"); }
-      }
-      catch (InterruptedException e)
-      {         
-      }
-   }
-
-   private void queueRunner(ListenerRunner runner)
-   {
-      try
-      {
-         this.sessionExecutor.execute(runner);
-      }
-      catch (InterruptedException e)
-      {         
-      }
-   }
-   
-   private void messageAdded()
-   {
-      boolean notified = false;
-      
-      if (trace) { log.trace("Receiver thread:" + receiverThread + " listener:" + listener + " listenerRunning:" + listenerRunning + 
-      		" sessionExecutor:" + sessionExecutor); }
-      
-      // If we have a thread waiting on receive() we notify it
-      if (receiverThread != null)
-      {
-         if (trace) { log.trace(this + " notifying receiver/waiter thread"); }   
-         
-         mainLock.notifyAll();
-         
-         notified = true;
-      }     
-      else if (listener != null)
-      { 
-         // We have a message listener
-         if (!listenerRunning)
-         {
-            listenerRunning = true;
-
-            if (trace) { log.trace(this + " scheduled a new ListenerRunner"); }
-            
-            this.queueRunner(new ListenerRunner());
-         }     
-         
-         //TODO - Execute onMessage on same thread for even better throughput 
-      }
-      
-      // Make sure we notify any thread waiting for last delivery
-      if (waitingForLastDelivery && !notified)
-      {
-      	if (trace) { log.trace("Notifying"); }
-      	
-         mainLock.notifyAll();
-      }
-   }
-   
-   private long waitOnLock(Object lock, long waitTime) throws InterruptedException
-   {
-      long start = System.currentTimeMillis();
-      
-      // Wait for last message to arrive
-      lock.wait(waitTime);
-     
-      long waited = System.currentTimeMillis() - start;
-      
-      if (waited < waitTime)
-      {
-         waitTime = waitTime - waited;
-         
-         return waitTime;
-      }
-      else
-      {
-         return 0;
-      }     
-   }
-        
-   private JBossMessage getMessage(long timeout)
-   {
-      if (timeout == -1)
-      {
-         // receiveNoWait so don't wait
-      }
-      else
-      {         
-         try
-         {         
-            if (timeout == 0)
-            {
-               // wait for ever potentially
-               while (!closed && buffer.isEmpty())
-               {
-                  if (trace) { log.trace(this + " waiting on main lock, no timeout"); }
-
-                  mainLock.wait();
-
-                  if (trace) { log.trace(this + " done waiting on main lock"); }
-               }
-            }
-            else
-            {
-               // wait with timeout
-               long toWait = timeout;
-             
-               while (!closed && buffer.isEmpty() && toWait > 0)
-               {
-                  if (trace) { log.trace(this + " waiting on main lock, timeout " + toWait + " ms"); }
-
-                  toWait = waitOnLock(mainLock, toWait);
-
-                  if (trace) { log.trace(this + " done waiting on lock, buffer is " + (buffer.isEmpty() ? "" : "NOT ") + "empty"); }
-               }
-            }
-         }
-         catch (InterruptedException e)
-         {
-            if (trace) { log.trace("InterruptedException, " + this + ".getMessage() returning null"); }
-            return null;
-         } 
-      }
-
-      JBossMessage m = null;
-             
-      if (!closed && !buffer.isEmpty())
-      {
-         m = (JBossMessage)buffer.removeFirst();
-         
-         checkSendChangeRate();
-      }
-
-      return m;
-   }
-   
-   // Inner classes --------------------------------------------------------------------------------
-         
-   /*
-    * This class is used to put on the listener executor to wait for onMessage
-    * invocations to complete when closing
-    */
-   private class Closer implements Runnable
-   {
-      Future result;
-      
-      Closer(Future result)
-      {
-         this.result = result;
-      }
-      
-      public void run()
-      {
-         if (trace) { log.trace("Closer starts running"); }
-
-         result.setResult(null);
-
-         if (trace) { log.trace("Closer finished run"); }
-      }
-   }
-   
-   /*
-    * This class handles the execution of onMessage methods
-    */
-   private class ListenerRunner implements Runnable
-   {
-      public void run()
-      {         
-         JBossMessage msg = null;
-         
-         MessageListener theListener = null;
-         
-         synchronized (mainLock)
-         {
-            if (listener == null || buffer.isEmpty())
-            {
-               listenerRunning = false;
-               
-               if (trace) { log.trace("no listener or buffer is empty, returning"); }
-               
-               return;
-            }
-            
-            theListener = listener;
-            
-            // remove a message from the buffer
-
-            msg = (JBossMessage)buffer.removeFirst();                
-            
-            checkSendChangeRate();
-         }
-         
-         /*
-          * Bug here is as follows:
-          * The next runner gets scheduled BEFORE the on message is executed
-          * so if the onmessage fails on acking it will be put on hold
-          * and failover will kick in, this will clear the executor
-          * so the next queud one disappears at everything grinds to a halt
-          * 
-          * Solution - don't use a session executor - have a sesion thread instead much nicer
-          */
-                                
-         if (msg != null)
-         {
-            try
-            {
-               callOnMessage(sessionDelegate, theListener, consumerID, queueName,
-                             false, msg, ackMode, maxDeliveries, null, shouldAck);
-               
-               if (trace) { log.trace("Called callonMessage"); }
-            }
-            catch (Throwable t)
-            {
-               log.error("Failed to deliver message", t);
-            } 
-         }
-         
-         synchronized (mainLock)
-         {
-         	if (!buffer.isEmpty())
-            {
-            	//Queue up the next runner to run
-            	
-            	if (trace) { log.trace("More messages in buffer so queueing next onMessage to run"); }
-            	
-            	queueRunner(this);
-            	
-            	if (trace) { log.trace("Queued next onMessage to run"); }
-            }
-            else
-            {
-            	if (trace) { log.trace("no more messages in buffer, marking listener as not running"); }
-            	
-            	listenerRunning  = false;
-            }   
-         }
-                  
-         if (trace) { log.trace("Exiting run()"); }
-      }
-   }   
-}
-
-
-

Copied: trunk/src/main/org/jboss/jms/client/impl/ClientConsumer.java (from rev 3604, trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java)
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientConsumer.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConsumer.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,933 @@
+/*
+  * 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.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jms.IllegalStateException;
+import javax.jms.JMSException;
+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.message.JBossMessage;
+import org.jboss.messaging.util.Logger;
+import org.jboss.messaging.core.Message;
+import org.jboss.messaging.core.PriorityLinkedList;
+import org.jboss.messaging.core.impl.PriorityLinkedListImpl;
+import org.jboss.messaging.util.Future;
+
+import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
+
+/**
+ * @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 $
+ */
+public class ClientConsumer
+{
+   // Constants ------------------------------------------------------------------------------------
+   
+   private static final Logger log;
+   
+   // Static ---------------------------------------------------------------------------------------
+   
+   private static boolean trace;      
+   
+   private static final int WAIT_TIMEOUT = 30000;
+   
+   
+   static
+   {
+      log = Logger.getLogger(ClientConsumer.class);
+      trace = log.isTraceEnabled();
+   }
+   
+   private static boolean checkExpiredOrReachedMaxdeliveries(JBossMessage jbm,
+                                                             ClientSession del,
+                                                             int maxDeliveries, boolean shouldCancel)
+   {
+      Message msg = jbm.getCoreMessage();
+      
+      boolean expired = msg.isExpired();
+      
+      boolean reachedMaxDeliveries = jbm.getDeliveryCount() == maxDeliveries;
+      
+      if (expired || reachedMaxDeliveries)
+      {
+         if (trace)
+         {
+            if (expired)
+            {
+               log.trace(msg + " has expired, cancelling to server");
+            }
+            else
+            {
+               log.trace(msg + " has reached maximum delivery number " + maxDeliveries +", cancelling to server");
+            }
+         }
+         
+         if (shouldCancel)
+         {	         
+	         final Cancel cancel = new CancelImpl(jbm.getDeliveryId(), jbm.getDeliveryCount(),
+	                                                 expired, reachedMaxDeliveries);	         
+	         try
+	         {
+	            del.cancelDelivery(cancel);
+	         }
+	         catch (JMSException e)
+	         {
+	            log.error("Failed to cancel delivery", e);
+	         }   
+         }
+               
+         return true;
+      }
+      else
+      {
+         return false;
+      }
+   }
+        
+   //This is static so it can be called by the asf layer too
+   public static void callOnMessage(ClientSession sess,
+                                    MessageListener listener,
+                                    String consumerID,
+                                    boolean isConnectionConsumer,
+                                    JBossMessage m,
+                                    int ackMode,
+                                    int maxDeliveries,
+                                    ClientSession connectionConsumerSession,
+                                    boolean shouldAck)
+      throws JMSException
+   {      
+      if (checkExpiredOrReachedMaxdeliveries(m, connectionConsumerSession!=null?connectionConsumerSession:sess, maxDeliveries, shouldAck))
+      {
+         //Message has been cancelled
+         return;
+      }
+      
+      DeliveryInfo deliveryInfo =
+         new DeliveryInfo(m, consumerID, connectionConsumerSession, shouldAck);
+            
+      m.incDeliveryCount();
+      
+      // If this is the callback-handler for a connection consumer we don't want to acknowledge or
+      // add anything to the tx for this session.
+      if (!isConnectionConsumer)
+      {
+         //We need to call preDeliver, deliver the message then call postDeliver - this is because
+         //it is legal to call session.recover(), or session.rollback() from within the onMessage()
+         //method in which case the last message needs to be delivered so it needs to know about it
+         sess.preDeliver(deliveryInfo);
+      } 
+      
+      try
+      {
+         if (trace) { log.trace("calling listener's onMessage(" + m + ")"); }
+                     
+         listener.onMessage(m);
+
+         if (trace) { log.trace("listener's onMessage() finished"); }
+      }
+      catch (RuntimeException e)
+      {
+         log.error("RuntimeException was thrown from onMessage, " + m.getJMSMessageID() + " will be redelivered", e);
+         
+         // See JMS 1.1 spec 4.5.2
+
+         if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE)
+         {              
+            sess.recover();
+         }
+      }   
+
+      // If this is the callback-handler for a connection consumer we don't want to acknowledge
+      // or add anything to the tx for this session
+      if (!isConnectionConsumer)
+      {
+      	if (trace) { log.trace("Calling postDeliver"); }
+      	
+         sess.postDeliver();
+         
+         if (trace) { log.trace("Called postDeliver"); }
+      }   
+   }
+   
+   // Attributes -----------------------------------------------------------------------------------
+      
+   /*
+    * The buffer is now a priority linked list
+    * This resolves problems whereby messages are delivered from the server side queue in
+    * correct priority order, but because the old consumer list was not a priority list
+    * then if messages were sitting waiting to be consumed on the client side, then higher
+    * priority messages might be behind lower priority messages and thus get consumed out of order
+    */
+   private PriorityLinkedList<JBossMessage> buffer;
+   private ClientSession sessionDelegate;
+   private Consumer consumerDelegate;
+   private String consumerID;
+   private boolean isConnectionConsumer;
+   private volatile Thread receiverThread;
+   private MessageListener listener;
+   private int ackMode;
+   private boolean closed;
+   private Object mainLock;
+   private QueuedExecutor sessionExecutor;
+   private boolean listenerRunning;
+   private int maxDeliveries;
+   private long lastDeliveryId = -1;
+   private boolean waitingForLastDelivery;
+   private boolean shouldAck;
+   private long redeliveryDelay;
+   private boolean paused;      
+   private int consumeCount;
+   private boolean firstTime = true;
+   private int bufferSize;
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   public ClientConsumer(boolean isCC, int ackMode,                                
+                         ClientSession sess, Consumer cons, String consumerID,
+                         String queueName,
+                         int bufferSize, QueuedExecutor sessionExecutor,
+                         int maxDeliveries, boolean shouldAck,
+                         long redeliveryDelay)
+   {
+      if (bufferSize < 1)
+      {
+         throw new IllegalArgumentException(this + " bufferSize must be > 0");
+      }
+              
+      buffer = new PriorityLinkedListImpl<JBossMessage>(10);
+      isConnectionConsumer = isCC;
+      this.ackMode = ackMode;
+      this.sessionDelegate = sess;
+      this.consumerDelegate = cons;
+      this.consumerID = consumerID;
+      mainLock = new Object();
+      this.sessionExecutor = sessionExecutor;
+      this.maxDeliveries = maxDeliveries;
+      this.shouldAck = shouldAck;
+      this.redeliveryDelay = redeliveryDelay;
+      this.bufferSize = bufferSize;
+   }
+        
+   // Public ---------------------------------------------------------------------------------------
+
+
+   public boolean isClosed()
+   {
+      return closed;
+   }
+
+   /**
+    * Handles a message sent from the server.
+    *
+    * @param message The message
+    */
+   public void handleMessage(final JBossMessage message) throws Exception
+   {
+      synchronized (mainLock)
+      {
+         if (closed)
+         {
+            // Sanity - this should never happen - we should always wait for all deliveries to arrive
+            // when closing
+            throw new IllegalStateException(this + " is closed, so ignoring message");
+         }
+
+         message.setSessionDelegate(sessionDelegate, isConnectionConsumer);
+
+         message.doBeforeReceive();
+
+         //Add it to the buffer
+         buffer.addLast(message, message.getJMSPriority());
+
+         lastDeliveryId = message.getDeliveryId();
+
+         if (trace) { log.trace(this + " added message(s) to the buffer are now " + buffer.size() + " messages"); }
+
+         messageAdded();
+      }
+   }
+
+   public void setMessageListener(MessageListener listener) throws JMSException
+   {     
+      synchronized (mainLock)
+      {
+         if (receiverThread != null)
+         {
+            // Should never happen
+            throw new IllegalStateException("Consumer is currently in receive(..). " +
+               "Cannot set MessageListener");
+         }
+         
+         this.listener = listener;
+                            
+         if (listener != null && !buffer.isEmpty())
+         {  
+            listenerRunning = true;
+            
+            this.queueRunner(new ListenerRunner());
+         }        
+      }   
+   }
+   
+   public void cancelBuffer() throws JMSException
+   {
+   	if (trace) { log.trace("Cancelling buffer: " + buffer.size()); }
+   	
+      synchronized (mainLock)
+      {      
+         // Now we cancel anything left in the buffer. The reason we do this now is that otherwise
+         // the deliveries wouldn't get cancelled until session close (since we don't cancel
+         // consumer's deliveries until then), which is too late - since we need to preserve the
+         // order of messages delivered in a session.
+         
+         if (shouldAck && !buffer.isEmpty())
+         {                        
+            // Now we cancel any deliveries that might be waiting in our buffer. This is because
+            // otherwise the messages wouldn't get cancelled until the corresponding session died.
+            // So if another consumer in another session tried to consume from the channel before
+            // that session died it wouldn't receive those messages.
+            // We can't just cancel all the messages in the SCE since some of those messages might
+            // have actually been delivered (unlike these) and we may want to acknowledge them
+            // later, after this consumer has been closed
+   
+            List cancels = new ArrayList();
+   
+            for(Iterator i = buffer.iterator(); i.hasNext();)
+            {
+               JBossMessage mp = (JBossMessage)i.next();
+               
+               CancelImpl cancel =
+                  new CancelImpl(mp.getDeliveryId(), mp.getDeliveryCount(), false, false);
+               
+               cancels.add(cancel);
+            }
+                  
+            if (trace) { log.trace("Calling cancelDeliveries"); }
+            sessionDelegate.cancelDeliveries(cancels);
+            if (trace) { log.trace("Done call"); }
+            
+            buffer.clear();
+         }    
+      }
+   }
+   
+   public void close(long lastDeliveryId) throws JMSException
+   {     
+   	log.trace(this + " close");
+         	
+   	//Wait for the last delivery to arrive
+      waitForLastDelivery(lastDeliveryId);
+      
+      //Important! We set the listener to null so the next ListenerRunner won't run
+      if (listener != null)
+      {
+      	setMessageListener(null);
+      }
+      
+      //Now we wait for any current listener runners to run.
+      waitForOnMessageToComplete();   
+      
+      synchronized (mainLock)
+      {         
+         if (closed)
+         {
+            return;
+         }
+         
+         closed = true;   
+         
+         if (receiverThread != null)
+         {            
+            // Wake up any receive() thread that might be waiting
+            mainLock.notify();
+         }   
+         
+         this.listener = null;
+      }
+                           
+      if (trace) { log.trace(this + " closed"); }
+   }
+     
+   /**
+    * Method used by the client thread to get a Message, if available.
+    *
+    * @param timeout - the timeout value in milliseconds. A zero timeount never expires, and the
+    *        call blocks indefinitely. A -1 timeout means receiveNoWait(): return the next message
+    *        or null if one is not immediately available. Returns null if the consumer is
+    *        concurrently closed.
+    */
+   public JBossMessage receive(long timeout) throws JMSException
+   {                
+      JBossMessage m = null;      
+      
+      synchronized (mainLock)
+      {        
+         if (trace) { log.trace(this + " receiving, timeout = " + timeout); }
+         
+         if (closed)
+         {
+            // If consumer is closed or closing calling receive returns null
+            if (trace) { log.trace(this + " closed, returning null"); }
+            return null;
+         }
+         
+         if (listener != null)
+         {
+            throw new JMSException("The consumer has a MessageListener set, " +
+               "cannot call receive(..)");
+         }
+                       
+         receiverThread = Thread.currentThread();
+               
+         long startTimestamp = System.currentTimeMillis();
+                  
+         try
+         {
+            while(true)
+            {                             
+               if (timeout == 0)
+               {
+                  if (trace) { log.trace(this + ": receive, no timeout"); }
+                  
+                  m = getMessage(0);                     
+                  
+                  if (m == null)
+                  {
+                     return null;
+                  }
+               }
+               else if (timeout == -1)
+               {
+                  //ReceiveNoWait
+                  if (trace) { log.trace(this + ": receive, noWait"); }
+                  
+                  m = getMessage(-1);                     
+                  
+                  if (m == null)
+                  {
+                     if (trace) { log.trace(this + ": no message available"); }
+                     return null;
+                  }
+               }
+               else
+               {
+                  if (trace) { log.trace(this + ": receive, timeout " + timeout + " ms, blocking poll on queue"); }
+                  
+                  m = getMessage(timeout);
+                                    
+                  if (m == null)
+                  {
+                     // timeout expired
+                     if (trace) { log.trace(this + ": " + timeout + " ms timeout expired"); }
+                     
+                     return null;
+                  }
+               }
+                              
+               if (trace) { log.trace(this + " received " + m + " after being blocked on buffer"); }
+                       
+               boolean ignore =
+                  checkExpiredOrReachedMaxdeliveries(m, sessionDelegate, maxDeliveries, shouldAck);
+               
+               if (!isConnectionConsumer && !ignore)
+               {
+                  DeliveryInfo info = new DeliveryInfo(m, consumerID, null, shouldAck);
+                                                    
+                  sessionDelegate.preDeliver(info);                  
+                  
+                  //If post deliver didn't succeed and acknowledgement mode is auto_ack
+                  //That means the ref wasn't acked since it couldn't be found.
+                  //In order to maintain at most once semantics we must therefore not return
+                  //the message
+                  
+                  ignore = !sessionDelegate.postDeliver();  
+                  
+                  if (trace)
+                  {
+                  	log.trace("Post deliver returned " + !ignore);
+                  }
+                  
+                  if (!ignore)
+                  {
+                     m.incDeliveryCount();                                
+                  }
+               }
+                                             
+               if (!ignore)
+               {
+                  if (trace) { log.trace(this + ": message " + m + " is not expired, pushing it to the caller"); }
+                  
+                  break;
+               }
+               
+               if (trace)
+               {
+                  log.trace("Discarding message " + m);
+               }
+               
+               // the message expired, so discard the message, adjust timeout and reenter the buffer
+               if (timeout != 0)
+               {
+                  timeout -= System.currentTimeMillis() - startTimestamp;
+                  if (timeout == 0)
+                  {
+                     // As 0 means waitForever, we make it noWait
+                     timeout = -1;
+                  }
+
+               }
+            }           
+         }
+         finally
+         {
+            receiverThread = null;            
+         }
+      } 
+      
+      if (trace) { log.trace(this + " receive() returning " + m); }
+      
+      return m;
+   } 
+         
+   public MessageListener getMessageListener()
+   {
+      return listener;      
+   }
+
+   public String toString()
+   {
+      return "ClientConsumer[" + consumerID + "]";
+   }
+   
+   public String getConsumerId()
+   {
+      return consumerID;
+   }
+
+   public void setConsumerId(String consumerId)
+   {
+       this.consumerID = consumerId;
+   }
+   
+   public void addToFrontOfBuffer(JBossMessage proxy) throws JMSException
+   {
+      synchronized (mainLock)
+      {
+         buffer.addFirst(proxy, proxy.getJMSPriority());
+         
+         consumeCount--;
+         
+         messageAdded();
+      }
+   }
+
+   public long getRedeliveryDelay()
+   {
+   	return redeliveryDelay;
+   }
+   
+   public void pause()
+   {
+      synchronized (mainLock)
+      {
+         paused = true;
+
+         sendChangeRateMessage(0f);         
+      }
+   }
+
+   public void resume()
+   {
+      synchronized (mainLock)
+      {
+         paused = false;
+
+         if (firstTime)
+         {
+            consumeCount = 0;
+
+            firstTime = false;
+         }
+         else
+         {
+            consumeCount = bufferSize / 3 - buffer.size();
+         }
+
+         sendChangeRateMessage(1f);
+      }
+   }
+
+   
+   // Package protected ----------------------------------------------------------------------------
+   
+   // Protected ------------------------------------------------------------------------------------
+            
+   // Private --------------------------------------------------------------------------------------
+
+   private void checkSendChangeRate()
+   {
+      consumeCount++;
+      
+      if (!paused && consumeCount == bufferSize)
+      {
+         consumeCount = 0;
+
+         sendChangeRateMessage(1.0f);
+      }
+   }
+
+   /*
+    * Wait for the last delivery to arrive
+    */
+   private void waitForLastDelivery(long id)
+   {
+      if (trace) { log.trace("Waiting for last delivery id " + id); }
+      
+      if (id == -1)
+      {
+      	//No need to wait - nothing to wait for      	
+      	return;
+      }
+      
+      synchronized (mainLock)
+      {          
+         waitingForLastDelivery = true;
+         try
+         {
+            long wait = WAIT_TIMEOUT;
+            while (lastDeliveryId != id && wait > 0)
+            {
+               long start = System.currentTimeMillis();  
+               try
+               {
+                  mainLock.wait(wait);
+               }
+               catch (InterruptedException e)
+               {               
+               }
+               wait -= (System.currentTimeMillis() - start);
+            }      
+            if (trace && lastDeliveryId == id)
+            {
+               log.trace("Got last delivery");
+            }
+             
+            if (lastDeliveryId != id)
+            {
+               log.warn("Timed out waiting for last delivery " + id + " got " + lastDeliveryId); 
+            }
+         }
+         finally
+         {
+            waitingForLastDelivery = false;
+         }
+      }
+   }
+   
+   private void sendChangeRateMessage(float newRate) 
+   {
+      try
+      {
+         // this invocation will be sent asynchronously to the server; it's DelegateSupport.invoke()
+         // job to detect it and turn it into a remoting one way invocation.
+         consumerDelegate.changeRate(newRate);
+      }
+      catch (JMSException e)
+      {
+         log.error("Failed to send changeRate message", e);
+      }
+   }
+   
+   private void waitForOnMessageToComplete()
+   {
+      // Wait for any onMessage() executions to complete
+
+      if (Thread.currentThread().equals(sessionExecutor.getThread()))
+      {
+         // the current thread already closing this ClientConsumer (this happens when the
+         // session is closed from within the MessageListener.onMessage(), for example), so no need
+         // to register another Closer (see http://jira.jboss.org/jira/browse/JBMESSAGING-542)
+         return;
+      }
+
+      Future result = new Future();
+      
+      try
+      {
+         sessionExecutor.execute(new Closer(result));
+
+         if (trace) { log.trace(this + " blocking wait for Closer execution"); }
+         result.getResult();
+         if (trace) { log.trace(this + " got Closer result"); }
+      }
+      catch (InterruptedException e)
+      {         
+      }
+   }
+
+   private void queueRunner(ListenerRunner runner)
+   {
+      try
+      {
+         this.sessionExecutor.execute(runner);
+      }
+      catch (InterruptedException e)
+      {         
+      }
+   }
+   
+   private void messageAdded()
+   {
+      boolean notified = false;
+      
+      if (trace) { log.trace("Receiver thread:" + receiverThread + " listener:" + listener + " listenerRunning:" + listenerRunning + 
+      		" sessionExecutor:" + sessionExecutor); }
+      
+      // If we have a thread waiting on receive() we notify it
+      if (receiverThread != null)
+      {
+         if (trace) { log.trace(this + " notifying receiver/waiter thread"); }   
+         
+         mainLock.notifyAll();
+         
+         notified = true;
+      }     
+      else if (listener != null)
+      { 
+         // We have a message listener
+         if (!listenerRunning)
+         {
+            listenerRunning = true;
+
+            if (trace) { log.trace(this + " scheduled a new ListenerRunner"); }
+            
+            this.queueRunner(new ListenerRunner());
+         }     
+         
+         //TODO - Execute onMessage on same thread for even better throughput 
+      }
+      
+      // Make sure we notify any thread waiting for last delivery
+      if (waitingForLastDelivery && !notified)
+      {
+      	if (trace) { log.trace("Notifying"); }
+      	
+         mainLock.notifyAll();
+      }
+   }
+   
+   private long waitOnLock(Object lock, long waitTime) throws InterruptedException
+   {
+      long start = System.currentTimeMillis();
+      
+      // Wait for last message to arrive
+      lock.wait(waitTime);
+     
+      long waited = System.currentTimeMillis() - start;
+      
+      if (waited < waitTime)
+      {
+         waitTime = waitTime - waited;
+         
+         return waitTime;
+      }
+      else
+      {
+         return 0;
+      }     
+   }
+        
+   private JBossMessage getMessage(long timeout)
+   {
+      if (timeout == -1)
+      {
+         // receiveNoWait so don't wait
+      }
+      else
+      {         
+         try
+         {         
+            if (timeout == 0)
+            {
+               // wait for ever potentially
+               while (!closed && buffer.isEmpty())
+               {
+                  if (trace) { log.trace(this + " waiting on main lock, no timeout"); }
+
+                  mainLock.wait();
+
+                  if (trace) { log.trace(this + " done waiting on main lock"); }
+               }
+            }
+            else
+            {
+               // wait with timeout
+               long toWait = timeout;
+             
+               while (!closed && buffer.isEmpty() && toWait > 0)
+               {
+                  if (trace) { log.trace(this + " waiting on main lock, timeout " + toWait + " ms"); }
+
+                  toWait = waitOnLock(mainLock, toWait);
+
+                  if (trace) { log.trace(this + " done waiting on lock, buffer is " + (buffer.isEmpty() ? "" : "NOT ") + "empty"); }
+               }
+            }
+         }
+         catch (InterruptedException e)
+         {
+            if (trace) { log.trace("InterruptedException, " + this + ".getMessage() returning null"); }
+            return null;
+         } 
+      }
+
+      JBossMessage m = null;
+             
+      if (!closed && !buffer.isEmpty())
+      {
+         m = (JBossMessage)buffer.removeFirst();
+         
+         checkSendChangeRate();
+      }
+
+      return m;
+   }
+   
+   // Inner classes --------------------------------------------------------------------------------
+         
+   /*
+    * This class is used to put on the listener executor to wait for onMessage
+    * invocations to complete when closing
+    */
+   private class Closer implements Runnable
+   {
+      Future result;
+      
+      Closer(Future result)
+      {
+         this.result = result;
+      }
+      
+      public void run()
+      {
+         if (trace) { log.trace("Closer starts running"); }
+
+         result.setResult(null);
+
+         if (trace) { log.trace("Closer finished run"); }
+      }
+   }
+   
+   /*
+    * This class handles the execution of onMessage methods
+    */
+   private class ListenerRunner implements Runnable
+   {
+      public void run()
+      {         
+         JBossMessage msg = null;
+         
+         MessageListener theListener = null;
+         
+         synchronized (mainLock)
+         {
+            if (listener == null || buffer.isEmpty())
+            {
+               listenerRunning = false;
+               
+               if (trace) { log.trace("no listener or buffer is empty, returning"); }
+               
+               return;
+            }
+            
+            theListener = listener;
+            
+            // remove a message from the buffer
+
+            msg = (JBossMessage)buffer.removeFirst();                
+            
+            checkSendChangeRate();
+         }
+         
+         /*
+          * Bug here is as follows:
+          * The next runner gets scheduled BEFORE the on message is executed
+          * so if the onmessage fails on acking it will be put on hold
+          * and failover will kick in, this will clear the executor
+          * so the next queud one disappears at everything grinds to a halt
+          * 
+          * Solution - don't use a session executor - have a sesion thread instead much nicer
+          */
+                                
+         if (msg != null)
+         {
+            try
+            {
+               callOnMessage(sessionDelegate, theListener, consumerID,
+                             false, msg, ackMode, maxDeliveries, null, shouldAck);
+               
+               if (trace) { log.trace("Called callonMessage"); }
+            }
+            catch (Throwable t)
+            {
+               log.error("Failed to deliver message", t);
+            } 
+         }
+         
+         synchronized (mainLock)
+         {
+         	if (!buffer.isEmpty())
+            {
+            	//Queue up the next runner to run
+            	
+            	if (trace) { log.trace("More messages in buffer so queueing next onMessage to run"); }
+            	
+            	queueRunner(this);
+            	
+            	if (trace) { log.trace("Queued next onMessage to run"); }
+            }
+            else
+            {
+            	if (trace) { log.trace("no more messages in buffer, marking listener as not running"); }
+            	
+            	listenerRunning  = false;
+            }   
+         }
+                  
+         if (trace) { log.trace("Exiting run()"); }
+      }
+   }   
+}
+
+
+

Added: trunk/src/main/org/jboss/jms/client/impl/ClientConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientConsumerImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConsumerImpl.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,348 @@
+/*
+  * 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.impl;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+
+import javax.jms.JMSException;
+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.remoting.CallbackManager;
+import org.jboss.jms.exception.MessagingShutdownException;
+import org.jboss.messaging.util.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.
+ *
+ * @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: 3603 $</tt>
+ *
+ * $Id: ClientConsumerImpl.java 3603 2008-01-21 18:49:20Z timfox $
+ */
+public class ClientConsumerImpl extends CommunicationSupport<ClientConsumerImpl> implements Consumer
+{
+   // Constants ------------------------------------------------------------------------------------
+
+	private static final long serialVersionUID = 3253922610778321868L;
+
+	private static final Logger log = Logger.getLogger(ClientConsumerImpl.class);
+
+   // 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 ClientConsumerImpl(String objectID, int bufferSize, int maxDeliveries, long redeliveryDelay)
+   {
+      super(objectID);
+      this.bufferSize = bufferSize;
+      this.maxDeliveries = maxDeliveries;
+      this.redeliveryDelay = redeliveryDelay;
+   }
+
+   public ClientConsumerImpl(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 ClientConsumerImpl()
+   {
+   }
+
+   // DelegateSupport overrides --------------------------------------------------------------------
+
+   @Override
+   protected byte getVersion()
+   {
+      return session.getConnection().getVersion();
+   }
+
+   protected Client getClient()
+   {
+      return this.session.getConnection().getClient();
+   }
+   
+   // Closeable implementation ---------------------------------------------------------------------
+
+   public void close() throws JMSException
+   {
+      sendBlocking(new CloseMessage());
+   }
+
+
+   public long closing(long sequence) throws JMSException
+   {
+      try
+      {
+         // We make sure closing is called on the ServerConsumerEndpoint.
+         // This returns us the last delivery id sent
+
+         long lastDeliveryId = invokeClosing(sequence);
+
+         // First we call close on the ClientConsumer which waits for onMessage invocations
+         // to complete and the last delivery to arrive
+         getClientConsumer().close(lastDeliveryId);
+
+         session.removeCallbackHandler(getClientConsumer());
+
+         CallbackManager cm = session.getConnection().getRemotingConnection().getCallbackManager();
+         cm.unregisterHandler(getConsumerID());
+
+         PacketDispatcher.client.unregister(getConsumerID());
+
+         //And then we cancel any messages still in the message callback handler buffer
+         getClientConsumer().cancelBuffer();
+
+         return lastDeliveryId;
+
+      }
+      catch (Exception proxiedException)
+      {
+         // 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 (!getClientConsumer().isClosed())
+            {
+               getClientConsumer().close(-1);
+            }
+         }
+         JMSException ex = new JMSException(proxiedException.toString());
+         ex.initCause(proxiedException);
+         throw ex;
+      }
+   }
+
+   private long invokeClosing(long sequence) throws JMSException
+   {
+      ClosingRequest request = new ClosingRequest(sequence);
+      ClosingResponse response = (ClosingResponse) sendBlocking(request);
+      return response.getID();
+   }
+
+   // ConsumerDelegate implementation --------------------------------------------------------------
+
+   public void changeRate(float newRate) throws JMSException
+   {
+      sendOneWay(new ChangeRateMessage(newRate));
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public MessageListener getMessageListener()
+   {
+      return getClientConsumer().getMessageListener();
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public Message receive(long timeout) throws JMSException
+   {
+      return getClientConsumer().receive(timeout);
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public void setMessageListener(MessageListener listener) throws JMSException
+   {
+      getClientConsumer().setMessageListener(listener);
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public boolean getNoLocal()
+   {
+      return this.noLocal;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public Destination getDestination()
+   {
+      return this.destination;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public String getMessageSelector()
+   {
+      return this.selector;
+   }
+
+   // Streamable implementation ----------------------------------------------------------
+
+   public void read(DataInputStream in) throws Exception
+   {
+      super.read(in);
+
+      bufferSize = in.readInt();
+
+      maxDeliveries = in.readInt();
+      
+      redeliveryDelay = in.readLong();
+   }
+
+   public void write(DataOutputStream out) throws Exception
+   {
+      super.write(out);
+
+      out.writeInt(bufferSize);
+
+      out.writeInt(maxDeliveries);
+      
+      out.writeLong(redeliveryDelay);
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public String toString()
+   {
+      return "ConsumerDelegate[" + System.identityHashCode(this) + ", ID=" + id + "]";
+   }
+
+   public int getBufferSize()
+   {
+      return bufferSize;
+   }
+
+   public int getMaxDeliveries()
+   {
+      return maxDeliveries;
+   }
+   
+   public long getRedeliveryDelay()
+   {
+   	return redeliveryDelay;
+   }
+   
+   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 ------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner Classes --------------------------------------------------------------------------------
+
+}

Copied: trunk/src/main/org/jboss/jms/client/impl/ClientConsumerPacketHandler.java (from rev 3602, trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerPacketHandler.java)
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientConsumerPacketHandler.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConsumerPacketHandler.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,70 @@
+package org.jboss.jms.client.impl;
+
+import org.jboss.jms.message.JBossMessage;
+import org.jboss.messaging.core.remoting.PacketHandler;
+import org.jboss.messaging.core.remoting.PacketSender;
+import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
+import org.jboss.messaging.core.remoting.wireformat.DeliverMessage;
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class ClientConsumerPacketHandler implements PacketHandler
+{
+   /**
+    * 
+    */
+   private final ClientConsumer messageHandler;
+   /**
+    * 
+    */
+   private final String consumerID;
+
+   /**
+    * @param messageHandler
+    * @param consumerID
+    */
+   public ClientConsumerPacketHandler(ClientConsumer messageHandler,
+         String consumerID)
+   {
+      this.messageHandler = messageHandler;
+      this.consumerID = consumerID;
+   }
+
+   public String getID()
+   {
+      return consumerID;
+   }
+
+   public void handle(AbstractPacket packet, PacketSender sender)
+   {
+      try
+      {
+         PacketType type = packet.getType();
+         if (type == PacketType.MSG_DELIVERMESSAGE)
+         {
+            DeliverMessage message = (DeliverMessage) packet;
+            
+            JBossMessage msg = JBossMessage.createMessage(message.getMessage(), message.getDeliveryID(), message.getDeliveryCount());
+            
+            msg.doBeforeReceive();
+            
+            messageHandler.handleMessage(msg);
+         }
+      } catch (Exception e)
+      {
+         // TODO Auto-generated catch block
+         e.printStackTrace();
+      }
+   }
+
+   @Override
+   public String toString()
+   {
+      return "ConsumerAspectPacketHandler[id=" + consumerID + "]";
+   }
+}
\ No newline at end of file

Added: trunk/src/main/org/jboss/jms/client/impl/ClientProducerImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientProducerImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientProducerImpl.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,395 @@
+/*
+  * 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.impl;
+
+import java.util.UUID;
+
+import javax.jms.BytesMessage;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageFormatException;
+import javax.jms.ObjectMessage;
+import javax.jms.StreamMessage;
+import javax.jms.TextMessage;
+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;
+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.remoting.Client;
+import org.jboss.messaging.util.Logger;
+import org.jboss.messaging.core.DestinationType;
+import org.jboss.messaging.core.impl.DestinationImpl;
+
+/**
+ * The client-side Producer delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ * @version <tt>$Revision: 3602 $</tt>
+ *
+ * $Id: ClientProducerImpl.java 3602 2008-01-21 17:48:32Z timfox $
+ */
+public class ClientProducerImpl extends CommunicationSupport<ClientProducerImpl> implements ClientProducer
+{
+   // Constants ------------------------------------------------------------------------------------
+
+   private static final long serialVersionUID = -6976930316308905681L;
+   private static final Logger log = Logger.getLogger(ClientProducerImpl.class);
+
+   // 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 ClientProducerImpl(ClientConnection connection,
+         ClientSession session, JBossDestination destination)
+   {
+      super();
+      this.connection = connection;
+      this.session = session;
+      this.destination = destination;
+   }
+
+   // ProducerDelegate implementation --------------------------------------------------------------
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public void close() throws JMSException
+   {
+      return;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public long closing(long sequence) throws JMSException
+   {
+      return -1;
+   }
+
+   public void setDestination(JBossDestination dest)
+   {
+      this.destination = dest;
+   }
+
+   public JBossDestination getDestination() throws JMSException
+   {
+      return this.destination;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public void send(JBossDestination destination, Message m, int deliveryMode,
+                    int priority, long timeToLive) throws JMSException
+   {
+      send(destination, m, deliveryMode, priority, timeToLive, false);
+   }
+
+
+   public void send(JBossDestination destination, Message m, int deliveryMode, int priority, long timeToLive, boolean keepID) throws JMSException
+   {
+
+      // configure the message for sending, using attributes stored as metadata
+
+      if (deliveryMode == -1)
+      {
+         // Use the delivery mode of the producer
+         deliveryMode = getDeliveryMode();
+         if (trace) { log.trace("Using producer's default delivery mode: " + deliveryMode); }
+      }
+      m.setJMSDeliveryMode(deliveryMode);
+
+      if (priority == -1)
+      {
+         // Use the priority of the producer
+         priority = getPriority();
+         if (trace) { log.trace("Using producer's default priority: " + priority); }
+      }
+      if (priority < 0 || priority > 9)
+      {
+         throw new MessageFormatException("Invalid message priority (" + priority + "). " +
+                                          "Valid priorities are 0-9");
+      }
+      m.setJMSPriority(priority);
+
+      if (this.isDisableMessageTimestamp())
+      {
+         m.setJMSTimestamp(0l);
+      }
+      else
+      {
+         m.setJMSTimestamp(System.currentTimeMillis());
+      }
+
+      if (timeToLive == Long.MIN_VALUE)
+      {
+         // Use time to live value from producer
+         timeToLive = getTimeToLive();
+         if (trace) { log.trace("Using producer's default timeToLive: " + timeToLive); }
+      }
+
+      if (timeToLive == 0)
+      {
+         // Zero implies never expires
+         m.setJMSExpiration(0);
+      }
+      else
+      {
+         m.setJMSExpiration(System.currentTimeMillis() + timeToLive);
+      }
+
+      if (destination == null)
+      {
+         // use destination from producer
+         destination = (JBossDestination)getDestination();
+
+         if (destination == null)
+         {
+            throw new UnsupportedOperationException("Destination not specified");
+         }
+
+         if (trace) { log.trace("Using producer's default destination: " + destination); }
+      }
+      else
+      {
+         // if a default destination was already specified then this must be same destination as
+         // that specified in the arguments
+
+         if (getDestination() != null &&
+             !getDestination().equals(destination))
+         {
+            throw new UnsupportedOperationException("Where a default destination is specified " +
+                                                    "for the sender and a destination is " +
+                                                    "specified in the arguments to the send, " +
+                                                    "these destinations must be equal");
+         }
+      }
+
+      JBossMessage jbm;
+
+      boolean foreign = false;
+
+      //First convert from foreign message if appropriate
+      if (!(m instanceof JBossMessage))
+      {
+         // it's a foreign message
+
+         // JMS 1.1 Sect. 3.11.4: A provider must be prepared to accept, from a client,
+         // a message whose implementation is not one of its own.
+
+         // create a matching JBossMessage Type from JMS Type
+         if (m instanceof BytesMessage)
+         {
+            jbm = new JBossBytesMessage((BytesMessage)m);
+         }
+         else if (m instanceof MapMessage)
+         {
+            jbm = new JBossMapMessage((MapMessage)m);
+         }
+         else if (m instanceof ObjectMessage)
+         {
+            jbm = new JBossObjectMessage((ObjectMessage)m);
+         }
+         else if (m instanceof StreamMessage)
+         {
+            jbm = new JBossStreamMessage((StreamMessage)m);
+         }
+         else if (m instanceof TextMessage)
+         {
+            jbm = new JBossTextMessage((TextMessage)m);
+         }
+         else
+         {
+            jbm = new JBossMessage(m);
+         }
+
+         //Set the destination on the original message
+         m.setJMSDestination(destination);
+
+         foreign = true;
+      }
+      else
+      {
+         jbm = (JBossMessage)m;
+      }
+
+      if (!keepID)
+      {
+         //Generate an id
+         
+         String id = UUID.randomUUID().toString();
+         
+         jbm.setJMSMessageID("ID:" + id);
+      }
+
+      if (foreign)
+      {
+         m.setJMSMessageID(jbm.getJMSMessageID());
+      }
+
+      jbm.setJMSDestination(destination);
+
+      try
+      {
+         jbm.doBeforeSend();
+      }
+      catch (Exception e)
+      {
+         JMSException exthrown = new JMSException (e.toString());
+         exthrown.initCause(e);
+         throw exthrown;
+      }
+
+      JBossDestination dest = (JBossDestination)destination;
+
+      //Set the destination on the core message - TODO temp for refactoring
+      org.jboss.messaging.core.Destination coreDest =
+         new DestinationImpl(dest.isQueue() ? DestinationType.QUEUE : DestinationType.TOPIC, dest.getName(), dest.isTemporary());
+      
+      //TODO - can optimise this copy to do copy lazily.
+      org.jboss.messaging.core.Message messageToSend = jbm.getCoreMessage().copy();
+
+      //FIXME - temp - for now we set destination as a header - should really be an attribute of the
+      //send packet - along with scheduleddelivery time
+
+      messageToSend.putHeader(org.jboss.messaging.core.Message.TEMP_DEST_HEADER_NAME, coreDest);
+
+      // we now invoke the send(Message) method on the session, which will eventually be fielded
+      // by connection endpoint
+      session.send(messageToSend);
+   }
+
+   public void setDeliveryMode(int deliveryMode) throws JMSException
+   {
+      this.deliveryMode = deliveryMode;
+   }
+
+   public int getDeliveryMode() throws JMSException
+   {
+      return this.deliveryMode;
+   }
+
+   
+
+   public boolean isDisableMessageID() throws JMSException
+   {
+      return this.disableMessageID;
+   }
+
+   public void setDisableMessageID(boolean value) throws JMSException
+   {
+      this.disableMessageID = value;   
+   }
+
+   public boolean isDisableMessageTimestamp() throws JMSException
+   {
+      return this.disableMessageTimestamp;
+   }
+
+   public void setDisableMessageTimestamp(boolean value) throws JMSException
+   {
+      this.disableMessageTimestamp = value;
+   }
+
+   public void setPriority(int priority) throws JMSException
+   {
+      this.priority = priority;
+   }
+
+   public int getPriority() throws JMSException
+   {
+      return this.priority;
+   }
+
+   public long getTimeToLive() throws JMSException
+   {
+        return this.timeToLive;
+   }
+
+
+   public void setTimeToLive(long timeToLive) throws JMSException
+   {
+      this.timeToLive = timeToLive;
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public String toString()
+   {
+      return "ProducerDelegate[" + System.identityHashCode(this) + ", ID=" + id + "]";
+   }
+
+   // Protected ------------------------------------------------------------------------------------
+   
+
+   @Override
+   protected Client getClient()
+   {
+      return connection.getClient();
+   }
+   // Package Private ------------------------------------------------------------------------------
+
+   @Override
+   protected byte getVersion()
+   {
+      return connection.getVersion();
+   }
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner Classes --------------------------------------------------------------------------------
+
+}

Added: trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,1408 @@
+/*
+  * 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.impl;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+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;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+import javax.jms.TransactionInProgressException;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.jms.client.Closeable;
+import org.jboss.jms.client.SelectorTranslator;
+import org.jboss.jms.client.api.ClientBrowser;
+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.client.api.Consumer;
+import org.jboss.jms.client.remoting.CallbackManager;
+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.jms.tx.LocalTx;
+import org.jboss.jms.tx.MessagingXAResource;
+import org.jboss.jms.tx.ResourceManager;
+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;
+import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryResponse;
+import org.jboss.messaging.core.remoting.wireformat.AddTemporaryDestinationMessage;
+import org.jboss.messaging.core.remoting.wireformat.CancelDeliveriesMessage;
+import org.jboss.messaging.core.remoting.wireformat.CancelDeliveryMessage;
+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.wireformat.CreateBrowserRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateBrowserResponse;
+import org.jboss.messaging.core.remoting.wireformat.CreateConsumerRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateConsumerResponse;
+import org.jboss.messaging.core.remoting.wireformat.CreateDestinationRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateDestinationResponse;
+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.Logger;
+import org.jboss.messaging.util.MessageQueueNameHelper;
+import org.jboss.messaging.util.ProxyFactory;
+
+import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
+
+/**
+ * The client-side Session delegate 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:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision: 3603 $</tt>
+ *
+ * $Id: ClientSessionImpl.java 3603 2008-01-21 18:49:20Z timfox $
+ */
+public class ClientSessionImpl extends CommunicationSupport<ClientSessionImpl> implements ClientSession
+{
+   // Constants ------------------------------------------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(ClientSessionImpl.class);
+
+   private boolean trace = log.isTraceEnabled();
+
+   private static final long serialVersionUID = -8096852898620279131L;
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   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 ClientSessionImpl(ClientConnection connection, String objectID, int dupsOKBatchSize)
+   {
+      super(objectID);
+      this.connection = connection;
+      this.dupsOKBatchSize = dupsOKBatchSize;
+   }
+   
+   public ClientSessionImpl(ClientConnectionImpl 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 ClientSessionImpl()
+   {
+   }
+
+   // DelegateSupport overrides --------------------------------------------------------------------
+
+   // Closeable implementation ---------------------------------------------------------------------
+
+   public void close() throws JMSException
+   {
+      sendBlocking(new CloseMessage());
+
+      Object xid = getCurrentTxId();
+
+      if (xid != null)
+      {
+         //Remove transaction from the resource manager
+         connection.getResourceManager().removeTx(xid);
+      }
+
+      // We must explicitly shutdown the executor
+
+      getExecutor().shutdownNow();
+
+   }
+
+   private long invokeClosing(long sequence) throws JMSException
+   {   	   
+      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
+   {
+      if (trace) { log.trace("handleClosing()"); }
+
+      closeChildren();
+      
+      //Sanity check
+      if (isXA() && !isXAAndConsideredNonTransacted())
+      {
+         if (trace) { log.trace("Session is XA"); }
+
+         ResourceManager rm = connection.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
+         // session to close. Closing the session causes any outstanding delivered but unacked
+         // messages to be cancelled to the server which means they would be available for other
+         // consumers to consume. If another consumer then consumes them, then recover() is called
+         // 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(this.getID()))
+         {
+            throw new javax.jms.IllegalStateException(
+               "Attempt to close an XASession when there are still uncommitted acknowledgements!");
+         }
+      }
+
+      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())
+      {
+         //Acknowledge or cancel any outstanding auto ack
+
+         DeliveryInfo remainingAutoAck = getAutoAckInfo();
+
+         if (remainingAutoAck != null)
+         {
+            if (trace) { log.trace(this + " handleClosing(). Found remaining auto ack. Will ack " + remainingAutoAck); }
+
+            try
+            {
+               ackDelivery(remainingAutoAck);
+
+               if (trace) { log.trace(this + " acked it"); }
+            }
+            finally
+            {
+               setAutoAckInfo(null);
+            }
+         }
+      }
+      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
+      {
+         //Ack any remaining deliveries
+
+         if (!getClientAckList().isEmpty())
+         {
+            try
+            {
+               acknowledgeDeliveries(getClientAckList());
+            }
+            finally
+            {
+               getClientAckList().clear();
+
+               setAutoAckInfo(null);
+            }
+         }
+      }
+      else if (ackMode == Session.CLIENT_ACKNOWLEDGE)
+      {
+         // Cancel any oustanding deliveries
+         // We cancel any client ack or transactional, we do this explicitly so we can pass the
+         // updated delivery count information from client to server. We could just do this on the
+         // server but we would lose delivery count info.
+
+         // CLIENT_ACKNOWLEDGE cannot be used with MDBs (i.e. no connection consumer)
+         // so is always safe to cancel on this session
+
+         internalCancelDeliveries(getClientAckList());
+
+         getClientAckList().clear();
+      }
+      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
+
+         List dels = connection.getResourceManager().getDeliveriesForSession(this.getID());
+
+         internalCancelDeliveries(dels);
+      }
+
+      return invokeClosing(sequence);
+
+   }
+
+   // 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());
+         AcknowledgeDeliveryResponse  response = (AcknowledgeDeliveryResponse) sendBlocking(request);
+         
+      return response.isAcknowledged();
+   }
+
+   public void acknowledgeDeliveries(List<Ack> acks) throws JMSException
+   {
+      sendBlocking(new AcknowledgeDeliveriesMessage(acks));
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public void acknowledgeAll() throws JMSException
+   {
+      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(getClientAckList());
+
+         getClientAckList().clear();
+      }
+   }
+
+   public void addTemporaryDestination(Destination destination) throws JMSException
+   {
+      sendBlocking(new AddTemporaryDestinationMessage(destination));
+   }
+
+   public void commit() throws JMSException
+   {
+      if (!isTransacted())
+      {
+         throw new IllegalStateException("Cannot commit a non-transacted session");
+      }
+
+      if (isXA())
+      {
+         throw new TransactionInProgressException("Cannot call commit on an XA session");
+      }
+
+      try
+      {
+         connection.getResourceManager().commitLocal((LocalTx)getCurrentTxId(), connection);
+      }
+      finally
+      {
+         //Start new local tx
+         setCurrentTxId( connection.getResourceManager().createLocalTx() );
+      }
+
+   }
+
+
+   public ClientBrowser createBrowserDelegate(Destination queue, String messageSelector)
+      throws JMSException
+   {
+      String coreSelector = SelectorTranslator.convertToJBMFilterString(messageSelector);
+      CreateBrowserRequest request = new CreateBrowserRequest(queue, coreSelector);
+      CreateBrowserResponse response = (CreateBrowserResponse) sendBlocking(request);
+      ClientBrowserImpl delegate = new ClientBrowserImpl(this, response.getBrowserID(), queue, messageSelector);
+      ClientBrowser proxy = (ClientBrowser)ProxyFactory.proxy(delegate, ClientBrowser.class);
+      children.add(proxy);
+      return proxy;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public JBossBytesMessage createBytesMessage() throws JMSException
+   {
+      JBossBytesMessage jbm = new JBossBytesMessage();
+      return jbm;
+   }
+
+
+   public Consumer createConsumerDelegate(Destination destination, String selector,
+                                                  boolean noLocal, String subscriptionName,
+                                                  boolean isCC) throws JMSException
+   {
+      String coreSelector = SelectorTranslator.convertToJBMFilterString(selector);
+      CreateConsumerRequest request =
+         new CreateConsumerRequest(destination, coreSelector, noLocal, subscriptionName, isCC);
+      
+      CreateConsumerResponse response = (CreateConsumerResponse) sendBlocking(request);
+
+      ClientConsumerImpl consumerDelegate = new ClientConsumerImpl(this, response.getConsumerID(), response.getBufferSize(), response.getMaxDeliveries(), response.getRedeliveryDelay(),
+            destination,
+            selector, noLocal, subscriptionName, response.getConsumerID(),isCC);      
+
+      Consumer proxy = (Consumer)ProxyFactory.proxy(consumerDelegate, Consumer.class);
+      
+      children.add(proxy);
+
+      //We need the queue name for recovering any deliveries after failover
+      String queueName = 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
+         // server side.
+         // 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(this.getID(),subscriptionName);
+      }
+      else if (destination.getType() == DestinationType.QUEUE)
+      {
+         queueName = destination.getName();
+      }
+
+      final ClientConsumer messageHandler =
+         new ClientConsumer(isCC, this.getAcknowledgeMode(),
+                            this, consumerDelegate, consumerDelegate.getID(), queueName,
+                            consumerDelegate.getBufferSize(), this.getExecutor(), consumerDelegate.getMaxDeliveries(), consumerDelegate.isShouldAck(),
+                            consumerDelegate.getRedeliveryDelay());
+
+      this.addCallbackHandler(messageHandler);
+
+      PacketDispatcher.client.register(new ClientConsumerPacketHandler(messageHandler, consumerDelegate.getID()));
+
+      CallbackManager cm = connection.getRemotingConnection().getCallbackManager();
+      cm.registerHandler(consumerDelegate.getID(), messageHandler);
+
+      consumerDelegate.setClientConsumer(messageHandler);
+
+      //Now we have finished creating the client consumer, we can tell the SCD
+      //we are ready
+      consumerDelegate.changeRate(1);
+      
+      return proxy;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public JBossMapMessage createMapMessage() throws JMSException
+   {
+      JBossMapMessage jbm = new JBossMapMessage();
+      return jbm;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public JBossMessage createMessage() throws JMSException
+   {
+      JBossMessage jbm = new JBossMessage();
+      return jbm;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public JBossObjectMessage createObjectMessage() throws JMSException
+   {
+      JBossObjectMessage jbm = new JBossObjectMessage();
+      return jbm;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public JBossObjectMessage createObjectMessage(Serializable object) throws JMSException
+   {
+      JBossObjectMessage jbm = new JBossObjectMessage();
+      jbm.setObject(object);
+      return jbm;
+   }
+
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public ClientProducer createProducerDelegate(JBossDestination destination) throws JMSException
+   {
+      // ProducerDelegates are not created on the server
+
+      ClientProducerImpl producerDelegate = new ClientProducerImpl(connection, this, destination );
+      ClientProducer proxy = (ClientProducer) ProxyFactory.proxy(producerDelegate, ClientProducer.class);
+      children.add(proxy);
+      return proxy;
+   }
+
+   public JBossQueue createQueue(String queueName) throws JMSException
+   {
+      CreateDestinationRequest request = new CreateDestinationRequest(queueName, true);      
+      CreateDestinationResponse response = (CreateDestinationResponse) sendBlocking(request);
+      return (JBossQueue) response.getDestination();
+   }
+   
+   public JBossStreamMessage createStreamMessage() throws JMSException
+   {
+      JBossStreamMessage jbm = new JBossStreamMessage();
+      return jbm;
+   }
+
+   public JBossTextMessage createTextMessage() throws JMSException
+   {
+      JBossTextMessage jbm = new JBossTextMessage();
+      return jbm;
+   }
+
+   public JBossTextMessage createTextMessage(String text) throws JMSException
+   {
+      JBossTextMessage jbm = new JBossTextMessage();
+      jbm.setText(text);
+      return jbm;
+   }
+
+   public JBossTopic createTopic(String topicName) throws JMSException
+   {
+      CreateDestinationRequest request = new CreateDestinationRequest(topicName, false);      
+      CreateDestinationResponse response = (CreateDestinationResponse) sendBlocking(request);
+      return (JBossTopic) response.getDestination();
+   }
+
+   public void deleteTemporaryDestination(Destination destination) throws JMSException
+   {
+      sendBlocking(new DeleteTemporaryDestinationMessage(destination));
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public boolean postDeliver() throws JMSException
+   {
+      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())
+      {
+         // 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 (!isRecoverCalled())
+         {
+            DeliveryInfo delivery = getAutoAckInfo();
+
+            if (delivery == null)
+            {
+               throw new IllegalStateException("Cannot find delivery to AUTO_ACKNOWLEDGE");
+            }
+
+            if (trace) { log.trace(this + " auto acknowledging delivery " + delivery); }
+
+            // We clear the state in a finally so then we don't get a knock on
+            // exception on the next ack since we haven't cleared the state. See
+            // http://jira.jboss.org/jira/browse/JBMESSAGING-852
+
+            //This is ok since the message is acked after delivery, then the client
+            //could get duplicates anyway
+
+            try
+            {
+               res = ackDelivery(delivery);
+            }
+            finally
+            {
+               setAutoAckInfo(null);
+            }
+         }
+         else
+         {
+            if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }
+
+            setRecoverCalled(false);
+         }
+      }
+      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
+      {
+         List acks = getClientAckList();
+
+         if (!isRecoverCalled())
+         {
+            if (acks.size() >= getDupsOKBatchSize())
+            {
+               // We clear the state in a finally
+               // http://jira.jboss.org/jira/browse/JBMESSAGING-852
+
+               try
+               {
+                  acknowledgeDeliveries(acks);
+               }
+               finally
+               {
+                  acks.clear();
+                  setAutoAckInfo(null);
+               }
+            }
+         }
+         else
+         {
+            if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }
+
+            setRecoverCalled(false);
+         }
+         setAutoAckInfo(null);
+      }
+
+      return Boolean.valueOf(res);
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public void preDeliver(DeliveryInfo info) throws JMSException
+   {
+      int ackMode = getAcknowledgeMode();
+
+      if (ackMode == Session.CLIENT_ACKNOWLEDGE)
+      {
+         // We collect acknowledgments in the list
+
+         if (trace) { log.trace(this + " added to CLIENT_ACKNOWLEDGE list delivery " + info); }
+
+         // Sanity check
+         if (info.getConnectionConsumerSession() != null)
+         {
+            throw new IllegalStateException(
+               "CLIENT_ACKNOWLEDGE cannot be used with a connection consumer");
+         }
+
+         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())
+      {
+         // We collect the single acknowledgement in the state.
+
+         if (trace) { log.trace(this + " added " + info + " to session state"); }
+
+         setAutoAckInfo(info);
+      }
+      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
+      {
+         if (trace) { log.trace(this + " added to DUPS_OK_ACKNOWLEDGE list delivery " + info); }
+
+         getClientAckList().add(info);
+
+         //Also set here - this would be used for recovery in a message listener
+         setAutoAckInfo(info);
+      }
+      else
+      {
+         Object txID = getCurrentTxId();
+
+         if (txID != null)
+         {
+            // the session is non-XA and transacted, or XA and enrolled in a global transaction. An
+            // XA session that has not been enrolled in a global transaction behaves as a
+            // transacted session.
+
+            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
+            // the connectionConsumer session as the session id, otherwise we use this sessions'
+            // session ID
+
+
+            ClientSession connectionConsumerDelegate =
+               info.getConnectionConsumerSession();
+
+            String sessionId = connectionConsumerDelegate != null ?
+               connectionConsumerDelegate.getID() : this.getID();
+
+            connection.getResourceManager().addAck(txID, sessionId, info);
+         }
+      }
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public void recover() throws JMSException
+   {
+      if (trace) { log.trace("recover called"); }
+
+      if (isTransacted() && !isXAAndConsideredNonTransacted())
+      {
+         throw new IllegalStateException("Cannot recover a transacted session");
+      }
+
+      if (trace) { log.trace("recovering the session"); }
+
+      int ackMode = getAcknowledgeMode();
+
+      if (ackMode == Session.CLIENT_ACKNOWLEDGE)
+      {
+         List dels = getClientAckList();
+
+         setClientAckList(new ArrayList());
+
+         redeliver(dels);
+
+         setRecoverCalled(true);
+      }
+      else if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
+      {
+         DeliveryInfo info = getAutoAckInfo();
+
+         //Don't recover if it's already to cancel
+
+         if (info != null)
+         {
+            List redels = new ArrayList();
+
+            redels.add(info);
+
+            redeliver(redels);
+
+            setAutoAckInfo(null);
+
+            setRecoverCalled(true);
+         }
+      }
+   }
+
+   /**
+    * Redelivery occurs in two situations:
+    *
+    * 1) When session.recover() is called (JMS1.1 4.4.11)
+    *
+    * "A session's recover method is used to stop a session and restart it with its first
+    * unacknowledged message. In effect, the session's series of delivered messages is reset to the
+    * point after its last acknowledged message."
+    *
+    * An important note here is that session recovery is LOCAL to the session. Session recovery DOES
+    * NOT result in delivered messages being cancelled back to the channel where they can be
+    * redelivered - since that may result in them being picked up by another session, which would
+    * break the semantics of recovery as described in the spec.
+    *
+    * 2) When session rollback occurs (JMS1.1 4.4.7). On rollback of a session the spec is clear
+    * that session recovery occurs:
+    *
+    * "If a transaction rollback is done, its produced messages are destroyed and its consumed
+    * messages are automatically recovered. For more information on session recovery, see Section
+    * 4.4.11 'Message Acknowledgment.'"
+    *
+    * So on rollback we do session recovery (local redelivery) in the same as if session.recover()
+    * was called.
+    *
+    * All cancellation at rollback is driven from the client side - we always attempt to redeliver
+    * messages to their original consumers if they are still open, or then cancel them to the server
+    * if they are not. Cancelling them to the server explicitly allows the delivery count to be updated.
+    *
+    *
+    */
+   public void redeliver(List toRedeliver) throws JMSException
+   {
+      // We put the messages back in the front of their appropriate consumer buffers
+
+      if (trace) { log.trace(this + " handleRedeliver() called: " + toRedeliver); }
+
+      // Need to be redelivered in reverse order.
+      for (int i = toRedeliver.size() - 1; i >= 0; i--)
+      {
+         DeliveryInfo info = (DeliveryInfo)toRedeliver.get(i);
+         JBossMessage msg = info.getMessage();
+
+         ClientConsumer handler = getCallbackHandler(info.getConsumerId());
+
+         if (handler == null)
+         {
+            // This is ok. The original consumer has closed, so we cancel the message
+
+            cancelDelivery(info);
+         }
+         else if (handler.getRedeliveryDelay() != 0)
+         {
+         	//We have a redelivery delay in action - all delayed redeliveries are handled on the server
+
+         	cancelDelivery(info);
+         }
+         else
+         {
+            if (trace) { log.trace("Adding proxy back to front of buffer"); }
+
+            handler.addToFrontOfBuffer(msg);
+         }
+      }
+
+   }
+   
+   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 (!isTransacted())
+      {
+         throw new IllegalStateException("Cannot rollback a non-transacted session");
+      }
+
+      if (isXA())
+      {
+         throw new TransactionInProgressException("Cannot call rollback on an XA session");
+      }
+
+      ResourceManager rm = connection.getResourceManager();
+      try
+      {
+         rm.rollbackLocal(getCurrentTxId());
+      }
+      finally
+      {
+         // startnew local tx
+         Object xid = rm.createLocalTx();
+         setCurrentTxId(xid);
+      }
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public void run() throws JMSException
+   {
+      if (trace) { log.trace("run()"); }
+
+      int ackMode = getAcknowledgeMode();
+
+      LinkedList msgs = getAsfMessages();
+
+      while (msgs.size() > 0)
+      {
+         AsfMessageHolder holder = (AsfMessageHolder)msgs.removeFirst();
+
+         if (trace) { log.trace("sending " + holder.msg + " to the message listener" ); }
+
+         ClientConsumer.callOnMessage(this, getDistinguishedListener(), holder.consumerID,
+                                      false,
+                                      holder.msg, ackMode, holder.maxDeliveries,
+                                      holder.connectionConsumerDelegate, holder.shouldAck);
+      }
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public void setMessageListener(MessageListener listener) throws JMSException
+   {
+      if (trace) { log.trace("setMessageListener()"); }
+
+      if (listener == null)
+      {
+         throw new IllegalStateException("Cannot set a null MessageListener on the session");
+      }
+
+      setDistinguishedListener(listener);
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public MessageListener getMessageListener() throws JMSException
+   {
+      if (trace) { log.trace("getMessageListener()"); }
+
+      return getDistinguishedListener();
+   }
+
+   
+
+   public void unsubscribe(String subscriptionName) throws JMSException
+   {
+      sendBlocking(new UnsubscribeMessage(subscriptionName));
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public XAResource getXAResource()
+   {
+      return xaResource;
+   }
+
+   /**
+    * This invocation should either be handled by the client-side interceptor chain or by the
+    * server-side endpoint.
+    */
+   public int getAcknowledgeMode()
+   {
+      return acknowledgeMode;
+   }
+
+   /**
+    * 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,
+                             ClientSession connectionConsumerDelegate, boolean shouldAck) throws JMSException
+   {
+      // Load the session with a message to be processed during a subsequent call to run()
+
+      if (m == null)
+      {
+         throw new IllegalStateException("Cannot add a null message to the session");
+      }
+
+      AsfMessageHolder holder = new AsfMessageHolder();
+      holder.msg = m;
+      holder.consumerID = theConsumerID;
+      holder.queueName = queueName;
+      holder.maxDeliveries = maxDeliveries;
+      holder.connectionConsumerDelegate = connectionConsumerDelegate;
+      holder.shouldAck = shouldAck;
+
+      getAsfMessages().add(holder);
+   }
+
+   public void send(Message m) throws JMSException
+   {
+      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 ((!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.
+
+         if (trace) { log.trace("sending message " + m + " transactionally, queueing on resource manager txID=" + txID + " sessionID= " + getID()); }
+
+         connection.getResourceManager().addMessage(txID, this.getID(), m);
+
+         // ... and we don't invoke any further interceptors in the stack
+         return;
+      }
+
+      if (trace) { log.trace("sending message NON-transactionally"); }
+
+      invokeSend(m);
+
+   }
+   
+   private void invokeSend(Message m) throws JMSException
+   {   	
+   	long seq;
+   	
+   	if (m.isDurable() || strictTck)
+   	{
+   		seq = -1;
+   	}
+   	else
+   	{
+   		seq = this.getNPSendSequence();
+   		
+   		this.incNpSendSequence();
+   	}
+   	
+   	SendMessage message = new SendMessage(m, seq);
+   	
+   	if (seq == -1)
+   	{
+   	   sendBlocking(message);
+   	}
+   	else
+   	{
+   	   sendOneWay(message);
+   	}
+   }
+
+   public void cancelDeliveries(List<Cancel> cancels) throws JMSException
+   {
+      sendBlocking(new CancelDeliveriesMessage(cancels));
+   }
+
+   public void cancelDelivery(Cancel cancel) throws JMSException
+   {
+      sendBlocking(new CancelDeliveryMessage(cancel));
+   }
+
+   // Streamable overrides -------------------------------------------------------------------------
+
+   public void read(DataInputStream in) throws Exception
+   {
+      super.read(in);
+
+      dupsOKBatchSize = in.readInt();
+   }
+
+   public void write(DataOutputStream out) throws Exception
+   {
+      super.write(out);
+
+      out.writeInt(dupsOKBatchSize);
+   }
+
+   // Public ---------------------------------------------------------------------------------------
+
+   public int getDupsOKBatchSize()
+   {
+      return dupsOKBatchSize;
+   }
+
+   public boolean isStrictTck()
+   {
+      return strictTck;
+   }
+
+   public String toString()
+   {
+      return "SessionDelegate[" + System.identityHashCode(this) + ", ID=" + id + "]";
+   }
+
+   // Protected ------------------------------------------------------------------------------------
+
+   @Override
+   protected Client getClient()
+   {
+      return connection.getClient();
+   }
+   
+   @Override
+   protected byte getVersion()
+   {
+      return connection.getVersion();
+   }
+
+   
+   
+   // Package Private ------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   /** http://jira.jboss.org/jira/browse/JBMESSAGING-946 - To accomodate TCK and the MQ behavior
+    *    we should behave as non transacted, AUTO_ACK when there is no transaction enlisted
+    *    However when the Session is being used by ASF we should consider the case where
+    *    we will convert LocalTX to GlobalTransactions.
+    *    This function helper will ensure the condition that needs to be tested on this aspect
+    *
+    *    There is a real conundrum here:
+    *
+    *    An XA Session needs to act as transacted when not enlisted for consuming messages for an MDB so when it does
+    *    get enlisted we can transfer the work inside the tx
+    *
+    *    But in needs to act as auto_acknowledge when not enlisted and not in an MDB (or bridge or stress test) to satisfy
+    *    integration tests and TCK!!! Hence getTreatAsNonTransactedWhenNotEnlisted()
+    *
+    * */
+   private boolean isXAAndConsideredNonTransacted()
+   {
+      return isXA() && (getCurrentTxId() instanceof LocalTx) && getTreatAsNonTransactedWhenNotEnlisted()
+             && getDistinguishedListener() == null;
+   }
+
+
+   private boolean ackDelivery(DeliveryInfo delivery) throws JMSException
+   {
+   	if (delivery.isShouldAck())
+   	{
+	      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
+
+	      ClientSession sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
+
+	      return sessionToUse.acknowledgeDelivery(delivery);
+   	}
+   	else
+   	{
+   		return true;
+   	}
+   }
+
+   private void cancelDelivery(DeliveryInfo delivery) throws JMSException
+   {
+   	if (delivery.isShouldAck())
+   	{
+   	   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
+
+   	   ClientSession sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
+
+	      sessionToUse.cancelDelivery(new CancelImpl(delivery.getDeliveryID(),
+	                                  delivery.getMessage().getDeliveryCount(), false, false));
+   	}
+   }
+
+   private void internalCancelDeliveries( List deliveryInfos) throws JMSException
+   {
+      List cancels = new ArrayList();
+
+      for (Iterator i = deliveryInfos.iterator(); i.hasNext(); )
+      {
+         DeliveryInfo ack = (DeliveryInfo)i.next();
+
+         if (ack.isShouldAck())
+         {
+	         CancelImpl cancel = new CancelImpl(ack.getMessage().getDeliveryId(),
+	                                                  ack.getMessage().getDeliveryCount(),
+	                                                  false, false);
+
+	         cancels.add(cancel);
+         }
+      }
+
+      if (!cancels.isEmpty())
+      {
+         this.cancelDeliveries(cancels);
+      }
+   }
+
+   private void acknowledgeDeliveries(ClientSession del, List deliveryInfos) throws JMSException
+   {
+      List acks = new ArrayList();
+
+      for (Iterator i = deliveryInfos.iterator(); i.hasNext(); )
+      {
+         DeliveryInfo ack = (DeliveryInfo)i.next();
+
+         if (ack.isShouldAck())
+         {
+	         acks.add(ack);
+         }
+      }
+
+      if (!acks.isEmpty())
+      {
+         del.acknowledgeDeliveries(acks);
+      }
+   }
+
+   // Inner Classes --------------------------------------------------------------------------------
+
+
+   private static class AsfMessageHolder
+   {
+      private JBossMessage msg;
+      private String consumerID;
+      private String queueName;
+      private int maxDeliveries;
+      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;
+   }
+   
+
+}

Deleted: trunk/src/main/org/jboss/jms/client/impl/ClosedInterceptor.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/ClosedInterceptor.java	2008-01-21 17:48:32 UTC (rev 3602)
+++ trunk/src/main/org/jboss/jms/client/impl/ClosedInterceptor.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,235 +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.container;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import javax.jms.IllegalStateException;
-
-import org.jboss.messaging.util.Logger;
-
-
-/**
- * An interceptor for checking closed state. It waits for other invocations to complete before
- * allowing the close. I.e. it performs the function of a "valve".
- *
- * This interceptor is PER_INSTANCE.
- *
- * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
- * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
- * @author <a href="mailto:ovidiu at feodorov.com>Ovidiu Feodorov</a>
- *
- * $Id$
- */
-public class ClosedInterceptor implements InvocationHandler
-{
-   // Constants -----------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(ClosedInterceptor.class);
-   private static boolean trace = log.isTraceEnabled();
-
-   private static final int NOT_CLOSED = 0;
-   private static final int IN_CLOSING = 1;
-   private static final int CLOSING = 2;
-   private static final int IN_CLOSE = 3; // performing the close
-   private static final int CLOSED = -1;
-
-   // Attributes ----------------------------------------------------
-
-
-   // The current state of the object guarded by this interceptor
-   private int state = NOT_CLOSED;
-
-   // The inuse count
-   private int inUseCount;
-
-
-   private Object target;
-
-   // Static --------------------------------------------------------
-
-   public static String stateToString(int state)
-   {
-      return state == NOT_CLOSED ? "NOT_CLOSED" :
-         state == IN_CLOSING ? "IN_CLOSING" :
-            state == CLOSING ? "CLOSING" :
-               state == IN_CLOSE ? "IN_CLOSE" :
-                  state == CLOSED ? "CLOSED" : "UNKNOWN";
-   }
-
-   // Constructors --------------------------------------------------
-
-   public ClosedInterceptor(Object target)
-   {
-      state = NOT_CLOSED;
-      inUseCount = 0;
-      this.target=target;
-   }
-
-   // Public --------------------------------------------------------
-
-
-   public Object getTarget()
-   {
-      return target;
-   }
-
-   public String toString()
-   {
-      return "ClosedInterceptor for (" + target + ")";
-   }
-
-   // Interceptor implementation -----------------------------------
-
-   public String getName()
-   {
-      return "ClosedInterceptor";
-   }
-
-   public Object invoke(Object o, Method method, Object[] args) throws Throwable
-   {
-      String methodName = method.getName();
-
-      boolean isClosing = methodName.equals("closing");
-      boolean isClose = methodName.equals("close");
-
-      synchronized(this)
-      {
-         // object "in use", increment inUseCount
-         if (state == IN_CLOSE || state == CLOSED)
-         {
-            if (isClosing || isClose)
-            {
-               return new Long(-1);
-            }
-            log.error(this + ": method " + methodName + "() did not go through, " +
-                             "the interceptor is " + stateToString(state));
-
-            throw new IllegalStateException("The object is closed");
-         }
-         ++inUseCount;
-      }
-
-      try
-      {
-         return method.invoke(target, args);
-      }
-      catch (InvocationTargetException exT)
-      {
-         Throwable t = exT.getCause();
-
-         if (isClosing || isClose)
-      	{
-	      	//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
-	      	//Close should ALWAYS (well apart from Errors) succeed irrespective of whether the actual connection to the server is alive.
-	      	return new Long(-1);
-      	}
-      	throw t;
-      }
-      finally
-      {
-         if (isClose)
-         {
-            closed();
-         }
-         else
-         {
-            done();
-         }
-      }
-   }
-
-   // Protected ------------------------------------------------------
-
-   /**
-    * Check the closing notification has not already been done
-    *
-    * @return true when already closing or closed
-    */
-   protected synchronized boolean checkClosingAlreadyDone() throws Throwable
-   {
-      if (state != NOT_CLOSED)
-      {
-         return true;
-      }
-      state = IN_CLOSING;
-      return false;
-   }
-
-   /**
-    * Closing the object
-    */
-   protected synchronized void closing() throws Throwable
-   {
-      state = CLOSING;
-   }
-
-   /**
-    * Check the close has not already been done and
-    * wait for all invocations to complete
-    *
-    * @return true when already closed
-    */
-   protected synchronized boolean checkCloseAlreadyDone() throws Throwable
-   {
-      if (state != CLOSING)
-      {
-         return true;
-      }
-      while (inUseCount > 0)
-      {
-         wait();
-      }
-      state = IN_CLOSE;
-      return false;
-   }
-
-   /**
-    * Closed the object
-    */
-   protected synchronized void closed() throws Throwable
-   {
-      state = CLOSED;
-      log.trace(this + " closed");
-   }
-
-   /**
-    * Mark the object as no longer inuse
-    */
-   protected synchronized void done() throws Throwable
-   {
-      if (--inUseCount == 0)
-      {
-         notifyAll();
-      }
-   }
-
-   // Package Private ------------------------------------------------
-
-   // Private --------------------------------------------------------
-
-   // Inner Classes --------------------------------------------------
-
-}
-

Copied: trunk/src/main/org/jboss/jms/client/impl/ClosedInterceptor.java (from rev 3604, trunk/src/main/org/jboss/jms/client/container/ClosedInterceptor.java)
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClosedInterceptor.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/ClosedInterceptor.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,235 @@
+/*
+  * 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.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import javax.jms.IllegalStateException;
+
+import org.jboss.messaging.util.Logger;
+
+
+/**
+ * An interceptor for checking closed state. It waits for other invocations to complete before
+ * allowing the close. I.e. it performs the function of a "valve".
+ *
+ * This interceptor is PER_INSTANCE.
+ *
+ * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
+ * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
+ * @author <a href="mailto:ovidiu at feodorov.com>Ovidiu Feodorov</a>
+ *
+ * $Id$
+ */
+public class ClosedInterceptor implements InvocationHandler
+{
+   // Constants -----------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(ClosedInterceptor.class);
+   private static boolean trace = log.isTraceEnabled();
+
+   private static final int NOT_CLOSED = 0;
+   private static final int IN_CLOSING = 1;
+   private static final int CLOSING = 2;
+   private static final int IN_CLOSE = 3; // performing the close
+   private static final int CLOSED = -1;
+
+   // Attributes ----------------------------------------------------
+
+
+   // The current state of the object guarded by this interceptor
+   private int state = NOT_CLOSED;
+
+   // The inuse count
+   private int inUseCount;
+
+
+   private Object target;
+
+   // Static --------------------------------------------------------
+
+   public static String stateToString(int state)
+   {
+      return state == NOT_CLOSED ? "NOT_CLOSED" :
+         state == IN_CLOSING ? "IN_CLOSING" :
+            state == CLOSING ? "CLOSING" :
+               state == IN_CLOSE ? "IN_CLOSE" :
+                  state == CLOSED ? "CLOSED" : "UNKNOWN";
+   }
+
+   // Constructors --------------------------------------------------
+
+   public ClosedInterceptor(Object target)
+   {
+      state = NOT_CLOSED;
+      inUseCount = 0;
+      this.target=target;
+   }
+
+   // Public --------------------------------------------------------
+
+
+   public Object getTarget()
+   {
+      return target;
+   }
+
+   public String toString()
+   {
+      return "ClosedInterceptor for (" + target + ")";
+   }
+
+   // Interceptor implementation -----------------------------------
+
+   public String getName()
+   {
+      return "ClosedInterceptor";
+   }
+
+   public Object invoke(Object o, Method method, Object[] args) throws Throwable
+   {
+      String methodName = method.getName();
+
+      boolean isClosing = methodName.equals("closing");
+      boolean isClose = methodName.equals("close");
+
+      synchronized(this)
+      {
+         // object "in use", increment inUseCount
+         if (state == IN_CLOSE || state == CLOSED)
+         {
+            if (isClosing || isClose)
+            {
+               return new Long(-1);
+            }
+            log.error(this + ": method " + methodName + "() did not go through, " +
+                             "the interceptor is " + stateToString(state));
+
+            throw new IllegalStateException("The object is closed");
+         }
+         ++inUseCount;
+      }
+
+      try
+      {
+         return method.invoke(target, args);
+      }
+      catch (InvocationTargetException exT)
+      {
+         Throwable t = exT.getCause();
+
+         if (isClosing || isClose)
+      	{
+	      	//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
+	      	//Close should ALWAYS (well apart from Errors) succeed irrespective of whether the actual connection to the server is alive.
+	      	return new Long(-1);
+      	}
+      	throw t;
+      }
+      finally
+      {
+         if (isClose)
+         {
+            closed();
+         }
+         else
+         {
+            done();
+         }
+      }
+   }
+
+   // Protected ------------------------------------------------------
+
+   /**
+    * Check the closing notification has not already been done
+    *
+    * @return true when already closing or closed
+    */
+   protected synchronized boolean checkClosingAlreadyDone() throws Throwable
+   {
+      if (state != NOT_CLOSED)
+      {
+         return true;
+      }
+      state = IN_CLOSING;
+      return false;
+   }
+
+   /**
+    * Closing the object
+    */
+   protected synchronized void closing() throws Throwable
+   {
+      state = CLOSING;
+   }
+
+   /**
+    * Check the close has not already been done and
+    * wait for all invocations to complete
+    *
+    * @return true when already closed
+    */
+   protected synchronized boolean checkCloseAlreadyDone() throws Throwable
+   {
+      if (state != CLOSING)
+      {
+         return true;
+      }
+      while (inUseCount > 0)
+      {
+         wait();
+      }
+      state = IN_CLOSE;
+      return false;
+   }
+
+   /**
+    * Closed the object
+    */
+   protected synchronized void closed() throws Throwable
+   {
+      state = CLOSED;
+      log.trace(this + " closed");
+   }
+
+   /**
+    * Mark the object as no longer inuse
+    */
+   protected synchronized void done() throws Throwable
+   {
+      if (--inUseCount == 0)
+      {
+         notifyAll();
+      }
+   }
+
+   // Package Private ------------------------------------------------
+
+   // Private --------------------------------------------------------
+
+   // Inner Classes --------------------------------------------------
+
+}
+

Copied: trunk/src/main/org/jboss/jms/client/impl/CommunicationSupport.java (from rev 3602, trunk/src/main/org/jboss/jms/client/delegate/CommunicationSupport.java)
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/CommunicationSupport.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/CommunicationSupport.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,197 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+package org.jboss.jms.client.impl;
+
+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.messaging.util.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;
+import org.jboss.messaging.util.Version;
+
+/**
+ * @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;
+   
+   
+   transient private boolean firstTime = true;
+   
+   
+   // getVersion cached (instead of calling it every time)
+   transient private byte cacheVersion;
+
+   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();
+   
+   protected byte getVersion()
+   {
+      return Version.instance().getProviderIncrementingVersion();
+   }
+   
+   public String getID()
+   {
+      return id;
+   }
+
+   public void setId(String id)
+   {
+      this.id = id;
+   }
+   
+   // Protected Methods-----------------------------------------------------------------------------
+   
+   protected void sendOneWay(AbstractPacket packet) throws JMSException
+   {
+      sendOneWay(getClient(), id, lookupVersion(), 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, lookupVersion(), 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);
+      }
+   }
+   
+   private byte lookupVersion()
+   {
+      if (firstTime)
+      {
+         firstTime=false;
+         cacheVersion = getVersion();
+      }
+      return cacheVersion;
+   }
+   
+   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);
+   }
+
+   
+
+}

Copied: trunk/src/main/org/jboss/jms/client/impl/CreateConnectionResult.java (from rev 3602, trunk/src/main/org/jboss/jms/delegate/CreateConnectionResult.java)
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/CreateConnectionResult.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/CreateConnectionResult.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,152 @@
+/*
+ * 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.impl;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+
+import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.messaging.util.ProxyFactory;
+import org.jboss.messaging.util.Streamable;
+
+/**
+ * 
+ * A CreateConnectionResult
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ *
+ */
+public class CreateConnectionResult implements Streamable
+{
+   // Constants -----------------------------------------------------
+
+   // Static --------------------------------------------------------
+   
+   private static final int NULL = 0;
+   
+   private static final int NOT_NULL = 1;
+
+   // Attributes ----------------------------------------------------
+
+   private ClientConnectionImpl delegate;
+
+   private int actualFailoverNodeID;
+
+   // TODO: Get rid of this
+   transient private ClientConnection proxiedDelegate;
+
+
+   // Constructors --------------------------------------------------
+   
+   public CreateConnectionResult()
+   {      
+   }
+
+   public CreateConnectionResult(ClientConnectionImpl delegate)
+   {
+      this(delegate, Integer.MIN_VALUE);
+   }
+
+   public CreateConnectionResult(int actualFailoverNodeID)
+   {
+      this(null, actualFailoverNodeID);
+   }
+
+   private CreateConnectionResult(ClientConnectionImpl delegate,
+                                  int actualFailoverNodeId)
+   {
+      this.delegate = delegate;
+      this.actualFailoverNodeID = actualFailoverNodeId;
+   }
+
+   // Public --------------------------------------------------------
+
+   public ClientConnection getInternalDelegate()
+   {
+      return delegate;
+   }
+
+   public ClientConnection getProxiedDelegate()
+   {
+      // TODO: Get rid of this Proxy
+      if (proxiedDelegate == null)
+      {
+         proxiedDelegate = (ClientConnection) ProxyFactory.proxy(delegate, ClientConnection.class);
+
+      }
+      return proxiedDelegate;
+   }
+
+   public int getActualFailoverNodeID()
+   {
+      return actualFailoverNodeID;
+   }
+
+   public String toString()
+   {
+      return "CreateConnectionResult[" + delegate + ", failover node " + actualFailoverNodeID + "]";
+   }
+   
+   // Streamable implementation ------------------------------------
+
+   public void read(DataInputStream in) throws Exception
+   {
+      actualFailoverNodeID = in.readInt();
+      
+      int b = in.readByte();
+      
+      if (b == NOT_NULL)
+      {
+         delegate = new ClientConnectionImpl();
+         
+         delegate.read(in);
+      }
+   }
+
+   public void write(DataOutputStream out) throws Exception
+   {
+      out.writeInt(actualFailoverNodeID);
+      
+      if (delegate == null)
+      {
+         out.writeByte(NULL);
+      }
+      else
+      {
+         out.writeByte(NOT_NULL);
+         
+         delegate.write(out);
+      }         
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Copied: trunk/src/main/org/jboss/jms/client/impl/DeliveryInfo.java (from rev 3603, trunk/src/main/org/jboss/jms/delegate/DeliveryInfo.java)
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/DeliveryInfo.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/DeliveryInfo.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,118 @@
+/*
+  * 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.impl;
+
+import org.jboss.jms.client.api.ClientSession;
+import org.jboss.jms.message.JBossMessage;
+
+/**
+ * Struct like class for holding information regarding a delivery 
+ * on the client side - this is never passed to the server
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com>Tim Fox </a>
+ * @author <a href="mailto:ovidiu at feodorov.com>Ovidiu Feodorov</a>
+ *
+ * $Id: AckInfo.java 1770 2006-12-12 10:49:42Z timfox $
+ */
+public class DeliveryInfo implements Ack
+{
+   // Constants -----------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+   
+   //This is needed when doing local redelivery of messages, since we need to know which
+   //consumer gets the message
+   private String consumerId;      
+
+   private JBossMessage msg;
+   
+   //For messages in non durable subscriptions - there is no need to ack on the server
+   private boolean shouldAck;
+   
+   //When using the evil abomination known as a ConnectionConsumer, the connection consumer
+   //will get from a session that it created, then pass them onto sessions got from the pool
+   //this means when the messages are acked/cancelled then this needs to be done against
+   //the connection consumer's session not the session from the pool, since that session won't know
+   //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 ClientSession connectionConsumerSession;
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+   
+   public DeliveryInfo(JBossMessage msg, String consumerId, 
+                       ClientSession connectionConsumerSession, boolean shouldAck)
+   {      
+      this.msg = msg;
+      
+      this.consumerId = consumerId;
+      
+      this.connectionConsumerSession = connectionConsumerSession;
+      
+      this.shouldAck = shouldAck;
+   }
+
+   // Public --------------------------------------------------------
+   
+   public String getConsumerId()
+   {
+      return consumerId;
+   }
+
+   public JBossMessage getMessage()
+   {
+      return msg;
+   }
+   
+   public ClientSession getConnectionConsumerSession()
+   {
+      return connectionConsumerSession;
+   }
+   
+   public boolean isShouldAck()
+   {
+   	return shouldAck;
+   }
+   
+   public String toString()
+   {
+      return "Delivery[" + getDeliveryID() + ", " + msg + "]";
+   }
+
+   // Ack Implementation  -------------------------------------------
+   
+   public long getDeliveryID()
+   {
+      return msg.getDeliveryId();
+   }
+
+   // Protected -----------------------------------------------------
+
+   // Package Private -----------------------------------------------
+
+   // Private -------------------------------------------------------
+   
+   // Inner Classes -------------------------------------------------
+   
+}

Deleted: trunk/src/main/org/jboss/jms/client/impl/JMSClientVMIdentifier.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/JMSClientVMIdentifier.java	2008-01-21 17:48:32 UTC (rev 3602)
+++ trunk/src/main/org/jboss/jms/client/impl/JMSClientVMIdentifier.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,38 +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.container;
-
-import java.util.UUID;
-
-/**
- * 
- * Unique id of a JMS client VM
- * 
- * @author <a href="tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class JMSClientVMIdentifier
-{
-   public static String instance = UUID.randomUUID().toString();
-}

Copied: trunk/src/main/org/jboss/jms/client/impl/JMSClientVMIdentifier.java (from rev 3604, trunk/src/main/org/jboss/jms/client/container/JMSClientVMIdentifier.java)
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/JMSClientVMIdentifier.java	                        (rev 0)
+++ trunk/src/main/org/jboss/jms/client/impl/JMSClientVMIdentifier.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -0,0 +1,38 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.jms.client.impl;
+
+import java.util.UUID;
+
+/**
+ * 
+ * Unique id of a JMS client VM
+ * 
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class JMSClientVMIdentifier
+{
+   public static String instance = UUID.randomUUID().toString();
+}

Modified: trunk/src/main/org/jboss/jms/client/plugin/LoadBalancingFactory.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/plugin/LoadBalancingFactory.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/plugin/LoadBalancingFactory.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -24,7 +24,7 @@
 
 import java.io.Serializable;
 
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
+import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
 
 /**
  * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
@@ -51,7 +51,7 @@
    /**
     * A LoadBalancingPolicy will work on top of ConnectionFactoryDelegate.
     */
-   public abstract LoadBalancingPolicy createLoadBalancingPolicy(ClientConnectionFactoryDelegate[] view);
+   public abstract LoadBalancingPolicy createLoadBalancingPolicy(ClientConnectionFactoryImpl[] view);
 
    public static LoadBalancingFactory getDefaultFactory()
    {

Modified: trunk/src/main/org/jboss/jms/client/plugin/LoadBalancingPolicy.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/plugin/LoadBalancingPolicy.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/plugin/LoadBalancingPolicy.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -8,7 +8,7 @@
 
 import java.io.Serializable;
 
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
+import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
 
 /**
  * The interface that must be implemented by any load balancing policy plugin.
@@ -21,14 +21,14 @@
 {
    static final long serialVersionUID = 328573973957394573L;
 
-   ClientConnectionFactoryDelegate getNext();
+   ClientConnectionFactoryImpl getNext();
    
    /**
     * This method should be called when updating the LoadBalancingFactory
     * @param delegates - a List<ConnectionFactoryDelegate> representing the lastest cluster view
     *        to chose delegates from
     */
-   void updateView(ClientConnectionFactoryDelegate[] delegates);
+   void updateView(ClientConnectionFactoryImpl[] delegates);
 
 
 }

Modified: trunk/src/main/org/jboss/jms/client/plugin/NoLoadBalancingLoadBalancingFactory.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/plugin/NoLoadBalancingLoadBalancingFactory.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/plugin/NoLoadBalancingLoadBalancingFactory.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -22,7 +22,7 @@
 
 package org.jboss.jms.client.plugin;
 
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
+import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
 
 /**
  * 
@@ -37,12 +37,12 @@
 	
 	private LoadBalancingPolicy policy;
 	
-	public NoLoadBalancingLoadBalancingFactory(ClientConnectionFactoryDelegate del)
+	public NoLoadBalancingLoadBalancingFactory(ClientConnectionFactoryImpl del)
 	{
 		policy = new NoLoadBalancingLoadBalancingPolicy(del);
 	}
 
-	public LoadBalancingPolicy createLoadBalancingPolicy(ClientConnectionFactoryDelegate[] view)
+	public LoadBalancingPolicy createLoadBalancingPolicy(ClientConnectionFactoryImpl[] view)
 	{
 		return policy;
 	}

Modified: trunk/src/main/org/jboss/jms/client/plugin/NoLoadBalancingLoadBalancingPolicy.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/plugin/NoLoadBalancingLoadBalancingPolicy.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/plugin/NoLoadBalancingLoadBalancingPolicy.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -21,7 +21,7 @@
    */
 package org.jboss.jms.client.plugin;
 
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
+import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
 
 /**
  * 
@@ -36,19 +36,19 @@
 {
 	private static final long serialVersionUID = -4683493821249921332L;
 	
-	private ClientConnectionFactoryDelegate del;
+	private ClientConnectionFactoryImpl del;
 	
-	public NoLoadBalancingLoadBalancingPolicy(ClientConnectionFactoryDelegate del)
+	public NoLoadBalancingLoadBalancingPolicy(ClientConnectionFactoryImpl del)
 	{
 		this.del = del;
 	}
 
-	public ClientConnectionFactoryDelegate getNext()
+	public ClientConnectionFactoryImpl getNext()
 	{
 		return del;
 	}
 
-	public void updateView(ClientConnectionFactoryDelegate[] delegates)
+	public void updateView(ClientConnectionFactoryImpl[] delegates)
 	{
 		// Do nothing
 	}

Modified: trunk/src/main/org/jboss/jms/client/plugin/RoundRobinLoadBalancingFactory.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/plugin/RoundRobinLoadBalancingFactory.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/plugin/RoundRobinLoadBalancingFactory.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -22,7 +22,7 @@
 
 package org.jboss.jms.client.plugin;
 
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
+import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
 
 /**
  * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
@@ -44,7 +44,7 @@
 
    // Public ---------------------------------------------------------------------------------------
 
-   public LoadBalancingPolicy createLoadBalancingPolicy(ClientConnectionFactoryDelegate[] view)
+   public LoadBalancingPolicy createLoadBalancingPolicy(ClientConnectionFactoryImpl[] view)
    {
       return new RoundRobinLoadBalancingPolicy(view);
    }

Modified: trunk/src/main/org/jboss/jms/client/plugin/RoundRobinLoadBalancingPolicy.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/plugin/RoundRobinLoadBalancingPolicy.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/plugin/RoundRobinLoadBalancingPolicy.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -8,7 +8,7 @@
 
 import java.util.Random;
 
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
+import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
 
 /**
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -31,11 +31,11 @@
    // The index of the next delegate to be used
    private int next;
 
-   private ClientConnectionFactoryDelegate[] delegates;
+   private ClientConnectionFactoryImpl[] delegates;
 
    // Constructors ---------------------------------------------------------------------------------
 
-   public RoundRobinLoadBalancingPolicy(ClientConnectionFactoryDelegate[] delegates)
+   public RoundRobinLoadBalancingPolicy(ClientConnectionFactoryImpl[] delegates)
    {
       next = -1;
       this.delegates = delegates;
@@ -43,7 +43,7 @@
 
    // LoadBalancingPolicy implementation -----------------------------------------------------------
 
-   public synchronized ClientConnectionFactoryDelegate getNext()
+   public synchronized ClientConnectionFactoryImpl getNext()
    {
       if (next >= delegates.length)
       {
@@ -58,7 +58,7 @@
       return delegates[next++];
    }
 
-   public synchronized void updateView(ClientConnectionFactoryDelegate[] delegates)
+   public synchronized void updateView(ClientConnectionFactoryImpl[] delegates)
    {
       next = -1;
       this.delegates = delegates;

Modified: trunk/src/main/org/jboss/jms/client/remoting/CallbackManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/remoting/CallbackManager.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/client/remoting/CallbackManager.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -23,7 +23,7 @@
 
 import java.util.Map;
 
-import org.jboss.jms.client.container.ClientConsumer;
+import org.jboss.jms.client.impl.ClientConsumer;
 import org.jboss.messaging.util.Logger;
 
 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;

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

Deleted: trunk/src/main/org/jboss/jms/delegate/Cancel.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/Cancel.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/delegate/Cancel.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,42 +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.delegate;
-
-/**
- * A Cancel
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public interface Cancel
-{
-   long getDeliveryId();
-   
-   int getDeliveryCount();
-   
-   boolean isExpired();
-   
-   boolean isReachedMaxDeliveryAttempts();
-}

Deleted: trunk/src/main/org/jboss/jms/delegate/CreateConnectionResult.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/CreateConnectionResult.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/delegate/CreateConnectionResult.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,153 +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.delegate;
-
-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;
-
-/**
- * 
- * A CreateConnectionResult
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public class CreateConnectionResult implements Streamable
-{
-   // Constants -----------------------------------------------------
-
-   // Static --------------------------------------------------------
-   
-   private static final int NULL = 0;
-   
-   private static final int NOT_NULL = 1;
-
-   // Attributes ----------------------------------------------------
-
-   private ClientConnectionDelegate delegate;
-
-   private int actualFailoverNodeID;
-
-   // TODO: Get rid of this
-   transient private ClientConnection proxiedDelegate;
-
-
-   // Constructors --------------------------------------------------
-   
-   public CreateConnectionResult()
-   {      
-   }
-
-   public CreateConnectionResult(ClientConnectionDelegate delegate)
-   {
-      this(delegate, Integer.MIN_VALUE);
-   }
-
-   public CreateConnectionResult(int actualFailoverNodeID)
-   {
-      this(null, actualFailoverNodeID);
-   }
-
-   private CreateConnectionResult(ClientConnectionDelegate delegate,
-                                  int actualFailoverNodeId)
-   {
-      this.delegate = delegate;
-      this.actualFailoverNodeID = actualFailoverNodeId;
-   }
-
-   // Public --------------------------------------------------------
-
-   public ClientConnection getInternalDelegate()
-   {
-      return delegate;
-   }
-
-   public ClientConnection getProxiedDelegate()
-   {
-      // TODO: Get rid of this Proxy
-      if (proxiedDelegate == null)
-      {
-         proxiedDelegate = (ClientConnection) ProxyFactory.proxy(delegate, ClientConnection.class);
-
-      }
-      return proxiedDelegate;
-   }
-
-   public int getActualFailoverNodeID()
-   {
-      return actualFailoverNodeID;
-   }
-
-   public String toString()
-   {
-      return "CreateConnectionResult[" + delegate + ", failover node " + actualFailoverNodeID + "]";
-   }
-   
-   // Streamable implementation ------------------------------------
-
-   public void read(DataInputStream in) throws Exception
-   {
-      actualFailoverNodeID = in.readInt();
-      
-      int b = in.readByte();
-      
-      if (b == NOT_NULL)
-      {
-         delegate = new ClientConnectionDelegate();
-         
-         delegate.read(in);
-      }
-   }
-
-   public void write(DataOutputStream out) throws Exception
-   {
-      out.writeInt(actualFailoverNodeID);
-      
-      if (delegate == null)
-      {
-         out.writeByte(NULL);
-      }
-      else
-      {
-         out.writeByte(NOT_NULL);
-         
-         delegate.write(out);
-      }         
-   }
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-
-}

Deleted: trunk/src/main/org/jboss/jms/delegate/DefaultAck.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/DefaultAck.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/delegate/DefaultAck.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,73 +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.delegate;
-
-/**
- * A DefaultAck
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public class DefaultAck implements Ack
-{
-
-   // Constants ------------------------------------------------------------------------------------
-
-   // Static ---------------------------------------------------------------------------------------
-
-   // Attributes -----------------------------------------------------------------------------------
-
-   private long deliveryID;
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   public DefaultAck(long deliveryId)
-   {
-      this.deliveryID = deliveryId;
-   }
-
-   // Ack implementation ---------------------------------------------------------------------------
-
-   public long getDeliveryID()
-   {
-      return deliveryID;
-   }
-
-   // Public ---------------------------------------------------------------------------------------
-
-   public String toString()
-   {
-      return "ACK[" + deliveryID + "]";
-   }
-
-   // Package protected ----------------------------------------------------------------------------
-
-   // Protected ------------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner classes --------------------------------------------------------------------------------
-
-}

Deleted: trunk/src/main/org/jboss/jms/delegate/DefaultCancel.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/DefaultCancel.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/delegate/DefaultCancel.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,115 +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.delegate;
-
-
-/**
- * 
- * A Cancel.
- * 
- * Used to send a cancel (NACK) to the server
- * 
- * When we cancel we send delivery count info, this means delivery count
- * can be updated on the server, and into storage if persistent, and the
- * message can be sent to DLQ if appropriate
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public class DefaultCancel implements Cancel
-{
-   // Constants -----------------------------------------------------
-   
-   // Attributes ----------------------------------------------------
-   
-   private long deliveryId;
-   
-   private int deliveryCount;    
-   
-   private boolean expired;
-   
-   private boolean reachedMaxDeliveryAttempts;
-
-   // Static --------------------------------------------------------
-   
-   // Constructors --------------------------------------------------
-   
-   public DefaultCancel()
-   {      
-   }
-   
-   public DefaultCancel(long deliveryId, int deliveryCount, boolean expired, boolean maxDeliveries)
-   {      
-      this.deliveryId = deliveryId;
-      
-      this.deliveryCount = deliveryCount;
-      
-      this.expired = expired;
-      
-      this.reachedMaxDeliveryAttempts = maxDeliveries;
-   }
-
-   // Public --------------------------------------------------------
-   
-   public long getDeliveryId()
-   {
-      return deliveryId;
-   }
-   
-   public int getDeliveryCount()
-   {
-      return deliveryCount;
-   }
-   
-   public boolean isExpired()
-   {
-      return expired;
-   }
-   
-   public boolean isReachedMaxDeliveryAttempts()
-   {
-      return reachedMaxDeliveryAttempts;
-   }
-
-   public String toString()
-   {
-      return "DefaultCancel(deliveryId=" + deliveryId +
-             ", deliveryCount=" + deliveryCount +
-             ", expired=" + expired +
-             ", reachedMaxDeliveryAttempts=" + reachedMaxDeliveryAttempts + ")";
-   }
-
-   // Class YYY overrides -------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Package Private -----------------------------------------------
-
-   // Private -------------------------------------------------------
-   
-   // Inner Classes -------------------------------------------------
-   
-}
-

Deleted: trunk/src/main/org/jboss/jms/delegate/DeliveryInfo.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/DeliveryInfo.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/delegate/DeliveryInfo.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -1,118 +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.delegate;
-
-import org.jboss.jms.client.api.ClientSession;
-import org.jboss.jms.message.JBossMessage;
-
-/**
- * Struct like class for holding information regarding a delivery 
- * on the client side - this is never passed to the server
- * 
- * @author <a href="mailto:tim.fox at jboss.com>Tim Fox </a>
- * @author <a href="mailto:ovidiu at feodorov.com>Ovidiu Feodorov</a>
- *
- * $Id: AckInfo.java 1770 2006-12-12 10:49:42Z timfox $
- */
-public class DeliveryInfo implements Ack
-{
-   // Constants -----------------------------------------------------
-   
-   // Attributes ----------------------------------------------------
-   
-   //This is needed when doing local redelivery of messages, since we need to know which
-   //consumer gets the message
-   private String consumerId;      
-
-   private JBossMessage msg;
-   
-   //For messages in non durable subscriptions - there is no need to ack on the server
-   private boolean shouldAck;
-   
-   //When using the evil abomination known as a ConnectionConsumer, the connection consumer
-   //will get from a session that it created, then pass them onto sessions got from the pool
-   //this means when the messages are acked/cancelled then this needs to be done against
-   //the connection consumer's session not the session from the pool, since that session won't know
-   //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 ClientSession connectionConsumerSession;
-   
-   // Static --------------------------------------------------------
-   
-   // Constructors --------------------------------------------------
-   
-   public DeliveryInfo(JBossMessage msg, String consumerId, 
-                       ClientSession connectionConsumerSession, boolean shouldAck)
-   {      
-      this.msg = msg;
-      
-      this.consumerId = consumerId;
-      
-      this.connectionConsumerSession = connectionConsumerSession;
-      
-      this.shouldAck = shouldAck;
-   }
-
-   // Public --------------------------------------------------------
-   
-   public String getConsumerId()
-   {
-      return consumerId;
-   }
-
-   public JBossMessage getMessage()
-   {
-      return msg;
-   }
-   
-   public ClientSession getConnectionConsumerSession()
-   {
-      return connectionConsumerSession;
-   }
-   
-   public boolean isShouldAck()
-   {
-   	return shouldAck;
-   }
-   
-   public String toString()
-   {
-      return "Delivery[" + getDeliveryID() + ", " + msg + "]";
-   }
-
-   // Ack Implementation  -------------------------------------------
-   
-   public long getDeliveryID()
-   {
-      return msg.getDeliveryId();
-   }
-
-   // Protected -----------------------------------------------------
-
-   // Package Private -----------------------------------------------
-
-   // Private -------------------------------------------------------
-   
-   // Inner Classes -------------------------------------------------
-   
-}

Modified: trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -31,7 +31,7 @@
 import javax.naming.NamingException;
 
 import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
+import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
 import org.jboss.jms.client.plugin.LoadBalancingFactory;
 import org.jboss.jms.server.ConnectionFactoryManager;
 import org.jboss.jms.server.endpoint.ServerConnectionFactoryEndpoint;
@@ -123,8 +123,8 @@
       //The server peer strict setting overrides the connection factory
       boolean useStrict = messagingServer.getConfiguration().isStrictTck() || strictTck;
 
-      ClientConnectionFactoryDelegate delegate =
-         new ClientConnectionFactoryDelegate(uniqueName, id, messagingServer.getConfiguration().getMessagingServerID(),
+      ClientConnectionFactoryImpl delegate =
+         new ClientConnectionFactoryImpl(uniqueName, id, messagingServer.getConfiguration().getMessagingServerID(),
                                              serverLocatorURI, version, clientPing, useStrict);
 
       log.debug(this + " created local delegate " + delegate);
@@ -195,7 +195,7 @@
    // Private --------------------------------------------------------------------------------------
 
    private void rebindConnectionFactory(Context ic, List<String> jndiBindings,
-                                        ClientConnectionFactoryDelegate delegate)
+                                        ClientConnectionFactoryImpl delegate)
       throws NamingException
    {
       JBossConnectionFactory cf = new JBossConnectionFactory(delegate);

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryEndpoint.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryEndpoint.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -23,7 +23,7 @@
 
 import javax.jms.JMSException;
 
-import org.jboss.jms.delegate.CreateConnectionResult;
+import org.jboss.jms.client.impl.CreateConnectionResult;
 
 /**
  * Represents the set of methods from the ConnectionFactoryDelegate that are handled on the server.

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryInternalEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryInternalEndpoint.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryInternalEndpoint.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -23,7 +23,7 @@
 
 import javax.jms.JMSException;
 
-import org.jboss.jms.delegate.CreateConnectionResult;
+import org.jboss.jms.client.impl.CreateConnectionResult;
 
 /**
  * The interface only exists so the connection factory requests can call through the AOP stack

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -47,7 +47,7 @@
 import javax.transaction.xa.Xid;
 
 import org.jboss.jms.client.api.ClientSession;
-import org.jboss.jms.client.delegate.ClientSessionDelegate;
+import org.jboss.jms.client.impl.ClientSessionImpl;
 import org.jboss.jms.exception.MessagingJMSException;
 import org.jboss.jms.server.ConnectionManager;
 import org.jboss.jms.server.SecurityStore;
@@ -246,7 +246,7 @@
          
          log.trace("created and registered " + ep);
 
-         org.jboss.jms.client.api.ClientSession d = new ClientSessionDelegate(null, sessionID, dupsOKBatchSize);
+         org.jboss.jms.client.api.ClientSession d = new ClientSessionImpl(null, sessionID, dupsOKBatchSize);
 
          log.trace("created " + d);
 
@@ -792,7 +792,7 @@
             if (type == REQ_CREATESESSION)
             {
                CreateSessionRequest request = (CreateSessionRequest) packet;
-               ClientSessionDelegate sessionDelegate = (ClientSessionDelegate) createSessionDelegate(
+               ClientSessionImpl sessionDelegate = (ClientSessionImpl) createSessionDelegate(
                      request.isTransacted(), request.getAcknowledgementMode(),
                      request.isXA());
 

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -29,9 +29,9 @@
 
 import javax.jms.JMSException;
 
-import org.jboss.jms.client.delegate.ClientConnectionDelegate;
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
-import org.jboss.jms.delegate.CreateConnectionResult;
+import org.jboss.jms.client.impl.ClientConnectionImpl;
+import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.jms.client.impl.CreateConnectionResult;
 import org.jboss.jms.exception.MessagingJMSException;
 import org.jboss.messaging.core.MessagingServer;
 import org.jboss.messaging.core.remoting.PacketHandler;
@@ -87,7 +87,7 @@
      
    /** Cluster Topology on ClusteredConnectionFactories
        Information to failover to other connections on clients **/
-   ClientConnectionFactoryDelegate[] delegates;
+   ClientConnectionFactoryImpl[] delegates;
 
    /** Cluster Topology on ClusteredConnectionFactories
        Information to failover to other connections on clients **/
@@ -148,7 +148,7 @@
       try
       {
          // Just a standard createConnection
-         ClientConnectionDelegate cd =
+         ClientConnectionImpl cd =
             createConnectionDelegateInternal(username, password, failedNodeID,
                                              remotingSessionID, clientVMID,
                                              versionToUse);
@@ -165,7 +165,7 @@
     * @param failedNodeID - zero or positive values mean connection creation attempt is result of
     *        failover. Negative values are ignored (mean regular connection creation attempt).
     */
-   private ClientConnectionDelegate
+   private ClientConnectionImpl
       createConnectionDelegateInternal(String username,
                                        String password,
                                        int failedNodeID,
@@ -214,7 +214,7 @@
 
       log.trace("created and registered " + endpoint);
 
-      return new ClientConnectionDelegate(connectionID, messagingServer.getConfiguration().getMessagingServerID());
+      return new ClientConnectionImpl(connectionID, messagingServer.getConfiguration().getMessagingServerID());
    }
       
    public void addSender(String VMID, String remotingSessionID,

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -52,12 +52,12 @@
 
 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;
-import org.jboss.jms.delegate.Cancel;
-import org.jboss.jms.delegate.DefaultAck;
-import org.jboss.jms.delegate.DeliveryInfo;
+import org.jboss.jms.client.impl.Ack;
+import org.jboss.jms.client.impl.Cancel;
+import org.jboss.jms.client.impl.ClientBrowserImpl;
+import org.jboss.jms.client.impl.ClientConsumerImpl;
+import org.jboss.jms.client.impl.AckImpl;
+import org.jboss.jms.client.impl.DeliveryInfo;
 import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.destination.JBossQueue;
 import org.jboss.jms.destination.JBossTopic;
@@ -1426,8 +1426,8 @@
 //      }
       connectionEndpoint.getMessagingServer().getMinaService().getDispatcher().register(ep.newHandler());
       
-      ClientConsumerDelegate stub =
-         new ClientConsumerDelegate(consumerID, prefetchSize, maxDeliveryAttemptsToUse, redeliveryDelayToUse);
+      ClientConsumerImpl stub =
+         new ClientConsumerImpl(consumerID, prefetchSize, maxDeliveryAttemptsToUse, redeliveryDelayToUse);
       
       synchronized (consumers)
       {
@@ -1485,7 +1485,7 @@
 
       connectionEndpoint.getMessagingServer().getMinaService().getDispatcher().register(ep.newHandler());
       
-      ClientBrowserDelegate stub = new ClientBrowserDelegate(browserID);
+      ClientBrowserImpl stub = new ClientBrowserImpl(browserID);
 
       log.trace(this + " created and registered " + ep);
 
@@ -1664,7 +1664,7 @@
             } else if (type == REQ_CREATECONSUMER)
             {
                CreateConsumerRequest request = (CreateConsumerRequest) packet;
-               ClientConsumerDelegate consumer = (ClientConsumerDelegate) createConsumerDelegate(
+               ClientConsumerImpl consumer = (ClientConsumerImpl) createConsumerDelegate(
                      request.getDestination(), request.getSelector(), request
                            .isNoLocal(), request.getSubscriptionName(), request
                            .isConnectionConsumer());
@@ -1688,14 +1688,14 @@
             } else if (type == REQ_CREATEBROWSER)
             {
                CreateBrowserRequest request = (CreateBrowserRequest) packet;
-               ClientBrowserDelegate browser = (ClientBrowserDelegate) createBrowserDelegate(
+               ClientBrowserImpl browser = (ClientBrowserImpl) createBrowserDelegate(
                      request.getDestination(), request.getSelector());
 
                response = new CreateBrowserResponse(browser.getID());
             } else if (type == REQ_ACKDELIVERY)
             {
                AcknowledgeDeliveryRequest request = (AcknowledgeDeliveryRequest) packet;
-               boolean acknowledged = acknowledgeDelivery(new DefaultAck(
+               boolean acknowledged = acknowledgeDelivery(new AckImpl(
                      request.getDeliveryID()));
 
                response = new AcknowledgeDeliveryResponse(acknowledged);

Modified: trunk/src/main/org/jboss/jms/server/endpoint/SessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/SessionEndpoint.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/server/endpoint/SessionEndpoint.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -29,8 +29,8 @@
 import org.jboss.jms.client.Closeable;
 import org.jboss.jms.client.api.ClientBrowser;
 import org.jboss.jms.client.api.Consumer;
-import org.jboss.jms.delegate.Ack;
-import org.jboss.jms.delegate.Cancel;
+import org.jboss.jms.client.impl.Ack;
+import org.jboss.jms.client.impl.Cancel;
 import org.jboss.jms.destination.JBossQueue;
 import org.jboss.jms.destination.JBossTopic;
 import org.jboss.messaging.core.Destination;

Modified: trunk/src/main/org/jboss/jms/tx/ClientTransaction.java
===================================================================
--- trunk/src/main/org/jboss/jms/tx/ClientTransaction.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/tx/ClientTransaction.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -30,9 +30,9 @@
 import java.util.List;
 import java.util.Map;
 
-import org.jboss.jms.delegate.Ack;
-import org.jboss.jms.delegate.DefaultAck;
-import org.jboss.jms.delegate.DeliveryInfo;
+import org.jboss.jms.client.impl.Ack;
+import org.jboss.jms.client.impl.AckImpl;
+import org.jboss.jms.client.impl.DeliveryInfo;
 import org.jboss.messaging.util.Logger;
 import org.jboss.messaging.core.Message;
 import org.jboss.messaging.core.impl.MessageImpl;
@@ -347,7 +347,7 @@
          
          while ((l = in.readLong()) != Long.MIN_VALUE)
          {
-         	sessionState.addAck(new DefaultAck(l));
+         	sessionState.addAck(new AckImpl(l));
          }
       }
    }

Modified: trunk/src/main/org/jboss/jms/tx/ResourceManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/tx/ResourceManager.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/jms/tx/ResourceManager.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -37,7 +37,7 @@
 
 import org.jboss.jms.client.api.ClientConnection;
 import org.jboss.jms.client.api.ClientSession;
-import org.jboss.jms.delegate.DeliveryInfo;
+import org.jboss.jms.client.impl.DeliveryInfo;
 import org.jboss.jms.exception.MessagingTransactionRolledBackException;
 import org.jboss.jms.exception.MessagingXAException;
 import org.jboss.jms.message.JBossMessage;

Modified: trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveriesRequestCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveriesRequestCodec.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveriesRequestCodec.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -11,8 +11,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.jboss.jms.delegate.Ack;
-import org.jboss.jms.delegate.DefaultAck;
+import org.jboss.jms.client.impl.Ack;
+import org.jboss.jms.client.impl.AckImpl;
 import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveriesMessage;
 
 /**
@@ -94,7 +94,7 @@
       List<Ack> acks = new ArrayList<Ack>(deliveryIDs.length);
       for (long deliveryID : deliveryIDs)
       {
-         acks.add(new DefaultAck(deliveryID));
+         acks.add(new AckImpl(deliveryID));
       }
       return acks;
    }

Modified: trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveriesMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveriesMessageCodec.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveriesMessageCodec.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -11,8 +11,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.jboss.jms.delegate.Cancel;
-import org.jboss.jms.delegate.DefaultCancel;
+import org.jboss.jms.client.impl.Cancel;
+import org.jboss.jms.client.impl.CancelImpl;
 import org.jboss.messaging.core.remoting.wireformat.CancelDeliveriesMessage;
 
 /**
@@ -80,7 +80,7 @@
          boolean expired = in.getBoolean();
          boolean reachedMaxDeliveryAttempts = in.getBoolean();
 
-         cancels.add(new DefaultCancel(deliveryID, deliveryCount, expired,
+         cancels.add(new CancelImpl(deliveryID, deliveryCount, expired,
                reachedMaxDeliveryAttempts));
       }
 

Modified: trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveryMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveryMessageCodec.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveryMessageCodec.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -8,8 +8,8 @@
 
 import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERY;
 
-import org.jboss.jms.delegate.Cancel;
-import org.jboss.jms.delegate.DefaultCancel;
+import org.jboss.jms.client.impl.Cancel;
+import org.jboss.jms.client.impl.CancelImpl;
 import org.jboss.messaging.core.remoting.wireformat.CancelDeliveryMessage;
 
 /**
@@ -68,7 +68,7 @@
       boolean expired = in.getBoolean();
       boolean reachedMaxDeliveryAttempts = in.getBoolean();
 
-      Cancel cancel = new DefaultCancel(deliveryID, deliveryCount, expired,
+      Cancel cancel = new CancelImpl(deliveryID, deliveryCount, expired,
             reachedMaxDeliveryAttempts);
       return new CancelDeliveryMessage(cancel);
    }

Modified: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveriesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveriesMessage.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveriesMessage.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -10,7 +10,7 @@
 
 import java.util.List;
 
-import org.jboss.jms.delegate.Ack;
+import org.jboss.jms.client.impl.Ack;
 
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>

Modified: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveriesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveriesMessage.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveriesMessage.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -10,7 +10,7 @@
 
 import java.util.List;
 
-import org.jboss.jms.delegate.Cancel;
+import org.jboss.jms.client.impl.Cancel;
 
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>

Modified: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveryMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveryMessage.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveryMessage.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -8,7 +8,7 @@
 
 import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERY;
 
-import org.jboss.jms.delegate.Cancel;
+import org.jboss.jms.client.impl.Cancel;
 
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>

Modified: trunk/src/main/org/jboss/messaging/util/ProxyFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/ProxyFactory.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/src/main/org/jboss/messaging/util/ProxyFactory.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -2,7 +2,7 @@
 
 import java.lang.reflect.Proxy;
 
-import org.jboss.jms.client.container.ClosedInterceptor;
+import org.jboss.jms.client.impl.ClosedInterceptor;
 
 public class ProxyFactory
 {

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -10,8 +10,8 @@
 
 import junit.framework.Assert;
 
-import org.jboss.jms.delegate.Ack;
-import org.jboss.jms.delegate.Cancel;
+import org.jboss.jms.client.impl.Ack;
+import org.jboss.jms.client.impl.Cancel;
 import org.jboss.messaging.core.tx.MessagingXid;
 
 /**

Modified: trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -83,10 +83,10 @@
 import junit.framework.TestCase;
 
 import org.apache.mina.common.IoBuffer;
-import org.jboss.jms.delegate.Ack;
-import org.jboss.jms.delegate.Cancel;
-import org.jboss.jms.delegate.DefaultAck;
-import org.jboss.jms.delegate.DefaultCancel;
+import org.jboss.jms.client.impl.Ack;
+import org.jboss.jms.client.impl.Cancel;
+import org.jboss.jms.client.impl.AckImpl;
+import org.jboss.jms.client.impl.CancelImpl;
 import org.jboss.jms.destination.JBossQueue;
 import org.jboss.jms.destination.JBossTopic;
 import org.jboss.jms.tx.ClientTransaction;
@@ -784,9 +784,9 @@
    public void testAcknowledgeDeliveriesRequest() throws Exception
    {
       List<Ack> acks = new ArrayList<Ack>();
-      acks.add(new DefaultAck(randomLong()));
-      acks.add(new DefaultAck(randomLong()));
-      acks.add(new DefaultAck(randomLong()));
+      acks.add(new AckImpl(randomLong()));
+      acks.add(new AckImpl(randomLong()));
+      acks.add(new AckImpl(randomLong()));
       AcknowledgeDeliveriesMessage request = new AcknowledgeDeliveriesMessage(
             acks);
       addVersion(request);
@@ -1009,7 +1009,7 @@
  
    public void testCancelDeliveryMessage() throws Exception
    {
-      Cancel cancel = new DefaultCancel(randomLong(), randomInt(), true, false);
+      Cancel cancel = new CancelImpl(randomLong(), randomInt(), true, false);
       CancelDeliveryMessage message = new CancelDeliveryMessage(cancel);
       addVersion(message);
       AbstractPacketCodec codec = new CancelDeliveryMessageCodec();
@@ -1036,8 +1036,8 @@
    public void testCancelDeliveriesMessage() throws Exception
    {
       List<Cancel> cancels = new ArrayList<Cancel>();
-      cancels.add(new DefaultCancel(randomLong(), 23, true, false));
-      cancels.add(new DefaultCancel(randomLong(), 33, false, true));
+      cancels.add(new CancelImpl(randomLong(), 23, true, false));
+      cancels.add(new CancelImpl(randomLong(), 33, false, true));
       CancelDeliveriesMessage message = new CancelDeliveriesMessage(cancels);
       addVersion(message);
       

Modified: trunk/tests/src/org/jboss/test/messaging/JBMBaseTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/JBMBaseTestCase.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/tests/src/org/jboss/test/messaging/JBMBaseTestCase.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -44,9 +44,9 @@
 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;
+import org.jboss.jms.client.impl.ClientConnectionImpl;
+import org.jboss.jms.client.impl.ClientConsumerImpl;
+import org.jboss.jms.client.impl.ClientSessionImpl;
 import org.jboss.messaging.util.Logger;
 import org.jboss.messaging.microcontainer.JBMBootstrapServer;
 import org.jboss.messaging.util.ProxyFactory;
@@ -167,19 +167,19 @@
       return msgIds;
    }
 
-   public ClientConsumerDelegate getDelegate(MessageConsumer cons)
+   public ClientConsumerImpl getDelegate(MessageConsumer cons)
    {
-      return (ClientConsumerDelegate)ProxyFactory.getDelegate(((JBossMessageConsumer)cons).getDelegate());
+      return (ClientConsumerImpl)ProxyFactory.getDelegate(((JBossMessageConsumer)cons).getDelegate());
    }
 
-   public ClientSessionDelegate getDelegate(Session sess)
+   public ClientSessionImpl getDelegate(Session sess)
    {
-      return (ClientSessionDelegate)ProxyFactory.getDelegate(((JBossSession)sess).getDelegate());
+      return (ClientSessionImpl)ProxyFactory.getDelegate(((JBossSession)sess).getDelegate());
    }
 
-   public ClientConnectionDelegate getDelegate(Connection conn)
+   public ClientConnectionImpl getDelegate(Connection conn)
    {
-      return (ClientConnectionDelegate)ProxyFactory.getDelegate(((JBossConnection)conn).getDelegate());
+      return (ClientConnectionImpl)ProxyFactory.getDelegate(((JBossConnection)conn).getDelegate());
    }
 
       protected List getReferenceIds(long channelId) throws Throwable

Modified: trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -33,7 +33,7 @@
 import javax.jms.TopicConnection;
 import javax.jms.TopicConnectionFactory;
 
-import org.jboss.jms.client.delegate.ClientConnectionDelegate;
+import org.jboss.jms.client.impl.ClientConnectionImpl;
 import org.jboss.jms.tx.ResourceManager;
 import org.jboss.jms.tx.ResourceManagerFactory;
 import org.jboss.messaging.util.Logger;
@@ -74,13 +74,13 @@
    {
       Connection conn1 = cf.createConnection();      
             
-      ClientConnectionDelegate del1 = getDelegate(conn1);
+      ClientConnectionImpl del1 = getDelegate(conn1);
       
       ResourceManager rm1 = del1.getResourceManager();
       
       Connection conn2 = cf.createConnection();      
       
-      ClientConnectionDelegate del2 = getDelegate(conn2);
+      ClientConnectionImpl del2 = getDelegate(conn2);
       
       ResourceManager rm2 = del2.getResourceManager();
 

Modified: trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -21,7 +21,7 @@
   */
 package org.jboss.test.messaging.jms;
 
-import org.jboss.jms.client.delegate.ClientSessionDelegate;
+import org.jboss.jms.client.impl.ClientSessionImpl;
 import org.jboss.jms.tx.ResourceManagerFactory;
 import org.jboss.test.messaging.JBMServerTestCase;
 
@@ -63,7 +63,7 @@
       cons.receive();
       sess.commit();
       
-      ClientSessionDelegate del = getDelegate(sess);
+      ClientSessionImpl del = getDelegate(sess);
       
       //SessionState state = (SessionState)del.getState();
       //ConnectionState cState = (ConnectionState)state.getParent();

Modified: trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -30,7 +30,7 @@
 import javax.management.ObjectName;
 
 import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.delegate.ClientConnectionDelegate;
+import org.jboss.jms.client.impl.ClientConnectionImpl;
 import org.jboss.jms.tx.ResourceManager;
 import org.jboss.jms.tx.ResourceManagerFactory;
 
@@ -66,7 +66,7 @@
 
          JBossConnection jbConn = (JBossConnection)conn;
 
-         ClientConnectionDelegate del = getDelegate(jbConn);
+         ClientConnectionImpl del = getDelegate(jbConn);
 
          ResourceManager rm = del.getResourceManager();
 
@@ -106,7 +106,7 @@
       {
          conn = cf.createConnection();
 
-         ClientConnectionDelegate del = getDelegate(conn);
+         ClientConnectionImpl del = getDelegate(conn);
 
          ResourceManager rm = del.getResourceManager();
 

Modified: trunk/tests/src/org/jboss/test/messaging/jms/XATest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XATest.java	2008-01-21 18:56:59 UTC (rev 3604)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XATest.java	2008-01-21 19:19:28 UTC (rev 3605)
@@ -47,7 +47,7 @@
 import org.jboss.jms.client.JBossConnection;
 import org.jboss.jms.client.JBossConnectionFactory;
 import org.jboss.jms.client.JBossSession;
-import org.jboss.jms.client.delegate.ClientConnectionDelegate;
+import org.jboss.jms.client.impl.ClientConnectionImpl;
 import org.jboss.jms.tx.LocalTx;
 import org.jboss.jms.tx.MessagingXAResource;
 import org.jboss.jms.tx.ResourceManager;
@@ -578,7 +578,7 @@
 
          JBossConnection jbConn = (JBossConnection)xaConn;
 
-         ClientConnectionDelegate del = getDelegate(jbConn);
+         ClientConnectionImpl del = getDelegate(jbConn);
 
          ResourceManager rm = del.getResourceManager();
 
@@ -638,7 +638,7 @@
 
          JBossConnection jbConn = (JBossConnection)xaConn;
 
-         ClientConnectionDelegate del = getDelegate(xaConn);
+         ClientConnectionImpl del = getDelegate(xaConn);
 
          ResourceManager rm = del.getResourceManager();
 




More information about the jboss-cvs-commits mailing list