[jboss-cvs] JBoss Messaging SVN: r1639 - in trunk: . docs/examples/queue docs/examples/secure-socket/etc src/etc src/etc/server/default/deploy src/etc/xmdesc src/main/org/jboss/jms/client src/main/org/jboss/jms/client/container src/main/org/jboss/jms/client/delegate src/main/org/jboss/jms/client/remoting src/main/org/jboss/jms/client/state src/main/org/jboss/jms/delegate src/main/org/jboss/jms/message src/main/org/jboss/jms/server src/main/org/jboss/jms/server/destination src/main/org/jboss/jms/server/endpoint src/main/org/jboss/jms/server/remoting src/main/org/jboss/jms/tx src/main/org/jboss/messaging/core src/main/org/jboss/messaging/core/message src/main/org/jboss/messaging/core/plugin src/main/org/jboss/messaging/core/plugin/contract src/main/org/jboss/messaging/core/tx tests tests/bin tests/src/org/jboss/test/messaging/core/plugin tests/src/org/jboss/test/messaging/core/plugin/base tests/src/org/jboss/test/messaging/jms tests/src/org/jboss/test/messaging/jms/message tests! /src/org/jboss/test/messaging/tools/jmx

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 27 05:29:30 EST 2006


Author: timfox
Date: 2006-11-27 05:28:46 -0500 (Mon, 27 Nov 2006)
New Revision: 1639

Added:
   trunk/src/main/org/jboss/jms/client/remoting/ClientSocketWrapper.java
   trunk/src/main/org/jboss/jms/server/remoting/ServerSocketWrapper.java
   trunk/tests/src/org/jboss/test/messaging/jms/DLQTest.java
Removed:
   trunk/src/main/org/jboss/jms/client/remoting/DummyCallbackHandler.java
   trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectInputStream.java
   trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectOutputStream.java
   trunk/src/main/org/jboss/jms/server/remoting/MessagingSerializationManager.java
Modified:
   trunk/
   trunk/build-messaging.xml
   trunk/build-thirdparty.xml
   trunk/docs/examples/queue/do-not-distribute.properties
   trunk/docs/examples/secure-socket/etc/messaging-secure-socket-service.xml
   trunk/src/etc/aop-messaging-client.xml
   trunk/src/etc/server/default/deploy/jms-ds.xml
   trunk/src/etc/server/default/deploy/messaging-service.xml
   trunk/src/etc/server/default/deploy/mssql-persistence-service.xml
   trunk/src/etc/server/default/deploy/mysql-persistence-service.xml
   trunk/src/etc/server/default/deploy/oracle-persistence-service.xml
   trunk/src/etc/server/default/deploy/postgresql-persistence-service.xml
   trunk/src/etc/server/default/deploy/remoting-service.xml
   trunk/src/etc/server/default/deploy/sybase-persistence-service.xml
   trunk/src/etc/xmdesc/ServerPeer-xmbean.xml
   trunk/src/etc/xmdesc/Topic-xmbean.xml
   trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java
   trunk/src/main/org/jboss/jms/client/JBossSession.java
   trunk/src/main/org/jboss/jms/client/container/AsfAspect.java
   trunk/src/main/org/jboss/jms/client/container/ConsumerAspect.java
   trunk/src/main/org/jboss/jms/client/container/SessionAspect.java
   trunk/src/main/org/jboss/jms/client/container/StateCreationAspect.java
   trunk/src/main/org/jboss/jms/client/container/TransactionAspect.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java
   trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java
   trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
   trunk/src/main/org/jboss/jms/client/remoting/MessageCallbackHandler.java
   trunk/src/main/org/jboss/jms/client/state/ConsumerState.java
   trunk/src/main/org/jboss/jms/delegate/SessionDelegate.java
   trunk/src/main/org/jboss/jms/message/JBossMessage.java
   trunk/src/main/org/jboss/jms/message/MessageProxy.java
   trunk/src/main/org/jboss/jms/server/ServerPeer.java
   trunk/src/main/org/jboss/jms/server/destination/DestinationServiceSupport.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
   trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
   trunk/src/main/org/jboss/jms/server/remoting/JMSWireFormat.java
   trunk/src/main/org/jboss/jms/server/remoting/MetaDataConstants.java
   trunk/src/main/org/jboss/jms/tx/AckInfo.java
   trunk/src/main/org/jboss/jms/tx/ResourceManager.java
   trunk/src/main/org/jboss/messaging/core/ChannelSupport.java
   trunk/src/main/org/jboss/messaging/core/Routable.java
   trunk/src/main/org/jboss/messaging/core/message/RoutableSupport.java
   trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java
   trunk/src/main/org/jboss/messaging/core/plugin/SimpleMessageReference.java
   trunk/src/main/org/jboss/messaging/core/plugin/contract/PersistenceManager.java
   trunk/src/main/org/jboss/messaging/core/tx/TransactionRepository.java
   trunk/tests/bin/runtest
   trunk/tests/build.xml
   trunk/tests/src/org/jboss/test/messaging/core/plugin/JDBCPersistenceManagerTest.java
   trunk/tests/src/org/jboss/test/messaging/core/plugin/base/MessageStoreTestBase.java
   trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/JMSTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.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/WireFormatTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java
   trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
Log:
Merge 1.0 branch (revisions 1535:1586) into TRUNK




Property changes on: trunk
___________________________________________________________________
Name: svn:ignore
   - output
thirdparty
messaging.iws


   + output
thirdparty
messaging.iws
jboss-head-partial-messaging-1-0.iml


Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/build-messaging.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -50,7 +50,7 @@
    <property name="messaging.version.revision" value="0"/>
    <property name="messaging.version.incrementing" value="8"/>
    <property name="messaging.version.tag" value="Beta1"/>
-   <property name="messaging.version.name" value=""/>
+   <property name="messaging.version.name" value="Berlin"/>
    <property name="messaging.version.cvstag" value="JBossMessaging_1_2_0_Beta1"/>
    <property name="module.name" value="messaging"/>
    <property name="module.Name" value="JBoss Messaging"/>

Modified: trunk/build-thirdparty.xml
===================================================================
--- trunk/build-thirdparty.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/build-thirdparty.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -93,7 +93,7 @@
       <componentref name="jboss/remoting" version="2.2.0.Alpha4"/>
 
       <!-- Need this otherwise project doesn't build in Eclipse -->
-      <componentref name="apache-logging" version="1.0.4.1jboss"/>
+      <componentref name="apache-logging" version="1.0.5.GA-jboss"/>
 
       <!--
            Dependencies required to test the project.

Modified: trunk/docs/examples/queue/do-not-distribute.properties
===================================================================
--- trunk/docs/examples/queue/do-not-distribute.properties	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/docs/examples/queue/do-not-distribute.properties	2006-11-27 10:28:46 UTC (rev 1639)
@@ -4,4 +4,4 @@
 #
 messaging.client.jar.path=../../../output/lib
 messaging.client.jar.name=jboss-messaging-client.jar
-jboss.configuration=current-version-server
+jboss.configuration=messaging

Modified: trunk/docs/examples/secure-socket/etc/messaging-secure-socket-service.xml
===================================================================
--- trunk/docs/examples/secure-socket/etc/messaging-secure-socket-service.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/docs/examples/secure-socket/etc/messaging-secure-socket-service.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -29,6 +29,8 @@
                <attribute name="serverBindPort">5457</attribute>
                <attribute name="leasePeriod">20000</attribute>
                <attribute name="serverSocketFactory">jboss.messaging:service=ServerSocketFactory,type=SSL</attribute>
+               <attribute name="clientSocketClass" isParam="true">org.jboss.jms.client.remoting.ClientSocketWrapper</attribute>
+               <attribute name="serverSocketClass">org.jboss.jms.server.remoting.ServerSocketWrapper</attribute>
             </invoker>
             <handlers>
                <handler subsystem="JMS">org.jboss.jms.server.remoting.JMSServerInvocationHandler</handler>

Modified: trunk/src/etc/aop-messaging-client.xml
===================================================================
--- trunk/src/etc/aop-messaging-client.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/aop-messaging-client.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -111,7 +111,7 @@
    <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientSessionDelegate->preDeliver(..))">
       <advice name="handlePreDeliver" aspect="org.jboss.jms.client.container.SessionAspect"/>
    </bind>
-   <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientSessionDelegate->postDeliver())">
+   <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientSessionDelegate->postDeliver(..))">
       <advice name="handlePostDeliver" aspect="org.jboss.jms.client.container.SessionAspect"/>
    </bind>
    <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientSessionDelegate->acknowledgeAll(..))">

Modified: trunk/src/etc/server/default/deploy/jms-ds.xml
===================================================================
--- trunk/src/etc/server/default/deploy/jms-ds.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/server/default/deploy/jms-ds.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -8,7 +8,7 @@
 
   <!-- The JMS provider loader -->
    <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
-          name="jboss.mq:service=JMSProviderLoader,name=JMSProvider">
+          name="jboss.messaging:service=JMSProviderLoader,name=JMSProvider">
       <attribute name="ProviderName">DefaultJMSProvider</attribute>
       <attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
       <attribute name="FactoryRef">java:/XAConnectionFactory</attribute>

Modified: trunk/src/etc/server/default/deploy/messaging-service.xml
===================================================================
--- trunk/src/etc/server/default/deploy/messaging-service.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/server/default/deploy/messaging-service.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -33,6 +33,8 @@
             <role name="guest" read="true" write="true" create="true"/>
         </security>
       </attribute>
+      <attribute name="MaxDeliveryAttempts">10</attribute>
+      <attribute name="DLQName">DLQ</attribute>
    </mbean>
 
 </server>
\ No newline at end of file

Modified: trunk/src/etc/server/default/deploy/mssql-persistence-service.xml
===================================================================
--- trunk/src/etc/server/default/deploy/mssql-persistence-service.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/server/default/deploy/mssql-persistence-service.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -38,6 +38,7 @@
 UPDATE_RELIABLE_REFS_NOT_LOADED=UPDATE JMS_MESSAGE_REFERENCE SET LOADED='N' WHERE CHANNELID=?
 SELECT_MIN_ORDERING=SELECT MIN(ORD) FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID=? AND STATE <> '+' AND LOADED = 'N'
 DELETE_UNRELIABLE_REFS=DELETE FROM JMS_MESSAGE_REFERENCE WHERE RELIABLE = 'N'
+UPDATE_DELIVERYCOUNT=UPDATE JMS_MESSAGE_REFERENCE SET DELIVERYCOUNT = ? WHERE CHANNELID = ? AND MESSAGEID = ?
 CREATE_MESSAGE=CREATE TABLE JMS_MESSAGE (MESSAGEID BIGINT, RELIABLE CHAR(1), EXPIRATION BIGINT, TIMESTAMP BIGINT, PRIORITY TINYINT, COREHEADERS IMAGE, PAYLOAD IMAGE, CHANNELCOUNT INTEGER, TYPE TINYINT, JMSTYPE VARCHAR(255), CORRELATIONID VARCHAR(255), CORRELATIONID_BYTES IMAGE, DESTINATION_ID BIGINT, REPLYTO_ID BIGINT, JMSPROPERTIES IMAGE, PRIMARY KEY (MESSAGEID))
 LOAD_MESSAGES=SELECT MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES FROM JMS_MESSAGE
 INSERT_MESSAGE=INSERT INTO JMS_MESSAGE (MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Modified: trunk/src/etc/server/default/deploy/mysql-persistence-service.xml
===================================================================
--- trunk/src/etc/server/default/deploy/mysql-persistence-service.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/server/default/deploy/mysql-persistence-service.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -67,10 +67,53 @@
       <attribute name="DataSource">java:/DefaultDS</attribute>
       <attribute name="CreateTablesOnStartup">true</attribute>
       <attribute name="SqlProperties"><![CDATA[
+<<<<<<< .working
 CREATE_POSTOFFICE_TABLE=CREATE TABLE JMS_POSTOFFICE (POSTOFFICE_NAME VARCHAR(255), NODE_ID INTEGER, QUEUE_NAME VARCHAR(1023), COND VARCHAR(1023), SELECTOR VARCHAR(1023), CHANNEL_ID BIGINT)
 INSERT_BINDING=INSERT INTO JMS_POSTOFFICE (POSTOFFICE_NAME, NODE_ID, QUEUE_NAME, COND, SELECTOR, CHANNEL_ID) VALUES (?, ?, ?, ?, ?, ?)
 DELETE_BINDING=DELETE FROM JMS_POSTOFFICE WHERE POSTOFFICE_NAME=? AND NODE_ID=? AND QUEUE_NAME=?
 LOAD_BINDINGS=SELECT NODE_ID, QUEUE_NAME, COND, SELECTOR, CHANNEL_ID FROM JMS_POSTOFFICE WHERE POSTOFFICE_NAME  = ?
+=======
+CREATE_MESSAGE_REF=CREATE TABLE JMS_MESSAGE_REFERENCE (CHANNELID BIGINT, MESSAGEID BIGINT, TRANSACTIONID BIGINT, STATE CHAR(1), ORD BIGINT, DELIVERYCOUNT INTEGER, RELIABLE CHAR(1), LOADED CHAR(1), PRIMARY KEY(CHANNELID, MESSAGEID)) 
+CREATE_IDX_MESSAGE_REF_TX=CREATE INDEX JMS_MESSAGE_REF_TX ON JMS_MESSAGE_REFERENCE (TRANSACTIONID)         
+CREATE_IDX_MESSAGE_REF_ORD=CREATE INDEX JMS_MESSAGE_REF_ORD ON JMS_MESSAGE_REFERENCE (ORD)
+CREATE_IDX_MESSAGE_REF_MESSAGEID=CREATE INDEX JMS_MESSAGE_REF_MESSAGEID ON JMS_MESSAGE_REFERENCE (MESSAGEID)
+CREATE_IDX_MESSAGE_REF_LOADED=CREATE INDEX JMS_MESSAGE_REF_LOADED ON JMS_MESSAGE_REFERENCE (LOADED)
+CREATE_IDX_MESSAGE_REF_RELIABLE=CREATE INDEX JMS_MESSAGE_REF_RELIABLE ON JMS_MESSAGE_REFERENCE (RELIABLE)
+INSERT_MESSAGE_REF=INSERT INTO JMS_MESSAGE_REFERENCE (CHANNELID, MESSAGEID, TRANSACTIONID, STATE, ORD, DELIVERYCOUNT, RELIABLE, LOADED) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
+DELETE_MESSAGE_REF=DELETE FROM JMS_MESSAGE_REFERENCE WHERE MESSAGEID=? AND CHANNELID=? AND STATE='C'
+UPDATE_MESSAGE_REF=UPDATE JMS_MESSAGE_REFERENCE SET TRANSACTIONID=?, STATE='-' WHERE MESSAGEID=? AND CHANNELID=? AND STATE='C'
+UPDATE_MESSAGE_REF_NOT_LOADED=UPDATE JMS_MESSAGE_REFERENCE SET LOADED='N' WHERE MESSAGEID=? AND CHANNELID=?
+COMMIT_MESSAGE_REF1=UPDATE JMS_MESSAGE_REFERENCE SET STATE='C', TRANSACTIONID = NULL WHERE TRANSACTIONID=? AND STATE='+'
+COMMIT_MESSAGE_REF2=DELETE FROM JMS_MESSAGE_REFERENCE WHERE TRANSACTIONID=? AND STATE='-'
+ROLLBACK_MESSAGE_REF1=DELETE FROM JMS_MESSAGE_REFERENCE WHERE TRANSACTIONID=? AND STATE='+'
+ROLLBACK_MESSAGE_REF2=UPDATE JMS_MESSAGE_REFERENCE SET STATE='C', TRANSACTIONID = NULL WHERE TRANSACTIONID=? AND STATE='-'
+LOAD_REF_INFO=SELECT MESSAGEID, ORD, DELIVERYCOUNT, RELIABLE FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID=? AND STATE <> '+' AND LOADED = 'N' AND ORD BETWEEN ? AND ? ORDER BY ORD
+SELECT_COUNT_REFS=SELECT COUNT(MESSAGEID) FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID=? AND STATE <> '+' AND LOADED='N'      
+UPDATE_RELIABLE_REFS=UPDATE JMS_MESSAGE_REFERENCE SET LOADED='Y' WHERE ORD BETWEEN ? AND ? AND CHANNELID=? AND RELIABLE='Y' AND STATE <> '+'      
+UPDATE_RELIABLE_REFS_NOT_LOADED=UPDATE JMS_MESSAGE_REFERENCE SET LOADED='N' WHERE CHANNELID=?  
+SELECT_MIN_ORDERING=SELECT MIN(ORD) FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID=? AND STATE <> '+' AND LOADED = 'N'          
+DELETE_UNRELIABLE_REFS=DELETE FROM JMS_MESSAGE_REFERENCE WHERE RELIABLE = 'N'
+UPDATE_DELIVERYCOUNT=UPDATE JMS_MESSAGE_REFERENCE SET DELIVERYCOUNT = ? WHERE CHANNELID = ? AND MESSAGEID = ?
+CREATE_MESSAGE=CREATE TABLE JMS_MESSAGE (MESSAGEID BIGINT, RELIABLE CHAR(1), EXPIRATION BIGINT, TIMESTAMP BIGINT, PRIORITY TINYINT, COREHEADERS MEDIUMBLOB, PAYLOAD LONGBLOB, CHANNELCOUNT INTEGER, TYPE TINYINT, JMSTYPE VARCHAR(255), CORRELATIONID VARCHAR(255), CORRELATIONID_BYTES VARBINARY(254), DESTINATION_ID BIGINT, REPLYTO_ID BIGINT, JMSPROPERTIES MEDIUMBLOB, PRIMARY KEY (MESSAGEID))
+LOAD_MESSAGES=SELECT MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES FROM JMS_MESSAGE
+INSERT_MESSAGE=INSERT INTO JMS_MESSAGE (MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+UPDATE_MESSAGE_CHANNELCOUNT=UPDATE JMS_MESSAGE SET CHANNELCOUNT=? WHERE MESSAGEID=?
+DELETE_MESSAGE=DELETE FROM JMS_MESSAGE WHERE MESSAGEID=?
+MESSAGEID_COLUMN=MESSAGEID    
+UPDATE_UNRELIABLE_CHANNELCOUNT=UPDATE JMS_MESSAGE M SET M.CHANNELCOUNT = M.CHANNELCOUNT - 1 WHERE M.MESSAGEID IN (SELECT MR.MESSAGEID FROM JMS_MESSAGE_REFERENCE MR WHERE MR.RELIABLE = 'N' AND MR.CHANNELID = ?)
+DELETE_UNREFFED_MESSAGES=DELETE FROM JMS_MESSAGE WHERE CHANNELCOUNT = 0    
+CREATE_TRANSACTION=CREATE TABLE JMS_TRANSACTION (TRANSACTIONID BIGINT, BRANCH_QUAL VARBINARY(254), FORMAT_ID INTEGER, GLOBAL_TXID VARBINARY(254), PRIMARY KEY (TRANSACTIONID))
+INSERT_TRANSACTION=INSERT INTO JMS_TRANSACTION (TRANSACTIONID, BRANCH_QUAL, FORMAT_ID, GLOBAL_TXID) VALUES(?, ?, ?, ?)
+DELETE_TRANSACTION=DELETE FROM JMS_TRANSACTION WHERE TRANSACTIONID = ?
+SELECT_PREPARED_TRANSACTIONS=SELECT TRANSACTIONID, BRANCH_QUAL, FORMAT_ID, GLOBAL_TXID FROM JMS_TRANSACTION         
+DELETE_ALL_TRANSACTIONS=DELETE FROM JMS_TRANSACTION
+CREATE_COUNTER=CREATE TABLE JMS_COUNTER (NAME VARCHAR(255), NEXT_ID BIGINT, PRIMARY KEY(NAME))
+UPDATE_COUNTER=UPDATE JMS_COUNTER SET NEXT_ID = ? WHERE NAME=?
+SELECT_COUNTER=SELECT NEXT_ID FROM JMS_COUNTER WHERE NAME=?
+INSERT_COUNTER=INSERT INTO JMS_COUNTER (NAME, NEXT_ID) VALUES (?, ?)
+DELETE_ALL_COUNTERS=DELETE FROM JMS_COUNTER
+SELECT_ALL_CHANNELS=SELECT DISTINCT(CHANNELID) FROM JMS_MESSAGE_REFERENCE
+>>>>>>> .merge-right.r1631
       ]]></attribute>
    </mbean>
 

Modified: trunk/src/etc/server/default/deploy/oracle-persistence-service.xml
===================================================================
--- trunk/src/etc/server/default/deploy/oracle-persistence-service.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/server/default/deploy/oracle-persistence-service.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -38,6 +38,7 @@
 UPDATE_RELIABLE_REFS_NOT_LOADED=UPDATE JMS_MESSAGE_REFERENCE SET LOADED='N' WHERE CHANNELID=?   
 SELECT_MIN_ORDERING=SELECT MIN(ORD) FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID=? AND STATE <> '+' AND LOADED = 'N'             
 DELETE_UNRELIABLE_REFS=DELETE FROM JMS_MESSAGE_REFERENCE WHERE RELIABLE = 'N'
+UPDATE_DELIVERYCOUNT=UPDATE JMS_MESSAGE_REFERENCE SET DELIVERYCOUNT = ? WHERE CHANNELID = ? AND MESSAGEID = ?
 CREATE_MESSAGE=CREATE TABLE JMS_MESSAGE (MESSAGEID INTEGER, RELIABLE CHAR(1), EXPIRATION INTEGER, TIMESTAMP INTEGER, PRIORITY INTEGER, COREHEADERS BLOB, PAYLOAD BLOB, CHANNELCOUNT INTEGER, TYPE INTEGER, JMSTYPE VARCHAR2(255), CORRELATIONID VARCHAR2(255), CORRELATIONID_BYTES RAW(254), DESTINATION_ID INTEGER, REPLYTO_ID INTEGER, JMSPROPERTIES BLOB, PRIMARY KEY (MESSAGEID))
 LOAD_MESSAGES=SELECT MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES FROM JMS_MESSAGE
 INSERT_MESSAGE=INSERT INTO JMS_MESSAGE (MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Modified: trunk/src/etc/server/default/deploy/postgresql-persistence-service.xml
===================================================================
--- trunk/src/etc/server/default/deploy/postgresql-persistence-service.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/server/default/deploy/postgresql-persistence-service.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -38,6 +38,7 @@
 UPDATE_RELIABLE_REFS_NOT_LOADED=UPDATE JMS_MESSAGE_REFERENCE SET LOADED='N' WHERE CHANNELID=?
 SELECT_MIN_ORDERING=SELECT MIN(ORD) FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID=? AND STATE <> '+' AND LOADED = 'N'
 DELETE_UNRELIABLE_REFS=DELETE FROM JMS_MESSAGE_REFERENCE WHERE RELIABLE = 'N'
+UPDATE_DELIVERYCOUNT=UPDATE JMS_MESSAGE_REFERENCE SET DELIVERYCOUNT = ? WHERE CHANNELID = ? AND MESSAGEID = ?
 CREATE_MESSAGE=CREATE TABLE JMS_MESSAGE (MESSAGEID BIGINT, RELIABLE CHAR(1), EXPIRATION BIGINT, TIMESTAMP BIGINT, PRIORITY int2, COREHEADERS BYTEA, PAYLOAD BYTEA, CHANNELCOUNT INTEGER, TYPE int2, JMSTYPE VARCHAR(255), CORRELATIONID VARCHAR(255), CORRELATIONID_BYTES BYTEA, DESTINATION_ID BIGINT, REPLYTO_ID BIGINT, JMSPROPERTIES BYTEA, PRIMARY KEY (MESSAGEID))
 LOAD_MESSAGES=SELECT MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES FROM JMS_MESSAGE
 INSERT_MESSAGE=INSERT INTO JMS_MESSAGE (MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Modified: trunk/src/etc/server/default/deploy/remoting-service.xml
===================================================================
--- trunk/src/etc/server/default/deploy/remoting-service.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/server/default/deploy/remoting-service.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -25,6 +25,8 @@
                <attribute name="serverBindPort">4457</attribute>
                <attribute name="leasePeriod">20000</attribute>
                <attribute name="callbackStore">org.jboss.remoting.callback.CallbackStore</attribute>
+               <attribute name="clientSocketClass" isParam="true">org.jboss.jms.client.remoting.ClientSocketWrapper</attribute>
+               <attribute name="serverSocketClass">org.jboss.jms.server.remoting.ServerSocketWrapper</attribute>
             </invoker>
             <handlers>
                <handler subsystem="JMS">org.jboss.jms.server.remoting.JMSServerInvocationHandler</handler>

Modified: trunk/src/etc/server/default/deploy/sybase-persistence-service.xml
===================================================================
--- trunk/src/etc/server/default/deploy/sybase-persistence-service.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/server/default/deploy/sybase-persistence-service.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -47,6 +47,7 @@
 UPDATE_RELIABLE_REFS_NOT_LOADED=UPDATE JMS_MESSAGE_REFERENCE SET LOADED='N' WHERE CHANNELID=?
 SELECT_MIN_ORDERING=SELECT MIN(ORD) FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID=? AND STATE <> '+' AND LOADED = 'N'
 DELETE_UNRELIABLE_REFS=DELETE FROM JMS_MESSAGE_REFERENCE WHERE RELIABLE = 'N'
+UPDATE_DELIVERYCOUNT=UPDATE JMS_MESSAGE_REFERENCE SET DELIVERYCOUNT = ? WHERE CHANNELID = ? AND MESSAGEID = ?
 CREATE_MESSAGE=CREATE TABLE JMS_MESSAGE (MESSAGEID INTEGER, RELIABLE CHAR(1) NULL, EXPIRATION INTEGER NULL, TIMESTAMP NUMERIC(20,0) NULL, PRIORITY INTEGER NULL, COREHEADERS IMAGE NULL, PAYLOAD IMAGE NULL, CHANNELCOUNT INTEGER NULL, TYPE INTEGER NULL, JMSTYPE VARCHAR(255) NULL, CORRELATIONID VARCHAR(255) NULL, CORRELATIONID_BYTES VARBINARY(254) NULL, DESTINATION_ID INTEGER NULL, REPLYTO_ID INTEGER NULL, JMSPROPERTIES IMAGE NULL, PRIMARY KEY (MESSAGEID))
 LOAD_MESSAGES=SELECT MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES FROM JMS_MESSAGE
 INSERT_MESSAGE=INSERT INTO JMS_MESSAGE (MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, COREHEADERS, PAYLOAD, CHANNELCOUNT, TYPE, JMSTYPE, CORRELATIONID, CORRELATIONID_BYTES, DESTINATION_ID, REPLYTO_ID, JMSPROPERTIES) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Modified: trunk/src/etc/xmdesc/ServerPeer-xmbean.xml
===================================================================
--- trunk/src/etc/xmdesc/ServerPeer-xmbean.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/xmdesc/ServerPeer-xmbean.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -151,6 +151,18 @@
       <name>QueuedExecutorPoolSize</name>
       <type>int</type>
    </attribute>
+   
+   <attribute access="read-write" getMethod="getMaxDeliveryAttempts" setMethod="setMaxDeliveryAttempts">
+      <description>The maximum delivery attempts for destinations</description>
+      <name>MaxDeliveryAttempts</name>
+      <type>int</type>
+   </attribute>  
+   
+   <attribute access="read-write" getMethod="getDLQName" setMethod="setDLQName">
+      <description>The JNDI name of the DLQ</description>
+      <name>DLQName</name>
+      <type>java.lang.String</type>
+   </attribute>     
 
    <!-- Managed operations -->
 

Modified: trunk/src/etc/xmdesc/Topic-xmbean.xml
===================================================================
--- trunk/src/etc/xmdesc/Topic-xmbean.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/etc/xmdesc/Topic-xmbean.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -87,7 +87,7 @@
       <name>DownCacheSize</name>
       <type>int</type>
    </attribute>
-   
+
    <attribute access="read-write" getMethod="isClustered" setMethod="setClustered">
       <description>Is this a clustered destination?</description>
       <name>Clustered</name>

Modified: trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -102,6 +102,8 @@
    
    protected Object closeLock = new Object();      
    
+   protected int maxDeliveries;
+   
    // Static --------------------------------------------------------
    
    // Constructors --------------------------------------------------
@@ -151,6 +153,8 @@
       ConsumerState state = (ConsumerState)((DelegateSupport)cons).getState();
 
       this.consumerID = state.getConsumerID();      
+      
+      this.maxDeliveries = state.getMaxDeliveries();
 
       id = threadId.increment();
       internalThread = new Thread(this, "Connection Consumer for dest " + destination + " id=" + id);
@@ -298,7 +302,7 @@
                for (int i = 0; i < mesList.size(); i++)
                {
                   MessageProxy m = (MessageProxy)mesList.get(i);
-                  session.addAsfMessage(m, consumerID, cons);
+                  session.addAsfMessage(m, consumerID, cons, maxDeliveries);
                   if (trace) { log.trace("added " + m + " to session"); }
                }
 

Modified: trunk/src/main/org/jboss/jms/client/JBossSession.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossSession.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/JBossSession.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -502,9 +502,9 @@
     * This method is used by the JBossConnectionConsumer to load up the session
     * with messages to be processed by the session's run() method
     */
-   void addAsfMessage(MessageProxy m, int consumerID, ConsumerDelegate cons)
+   void addAsfMessage(MessageProxy m, int consumerID, ConsumerDelegate cons, int maxDeliveries)
    {
-      delegate.addAsfMessage(m, consumerID, cons);
+      delegate.addAsfMessage(m, consumerID, cons, maxDeliveries);
    }
       
    // Protected -----------------------------------------------------

Modified: trunk/src/main/org/jboss/jms/client/container/AsfAspect.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/AsfAspect.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/container/AsfAspect.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -130,6 +130,7 @@
       MessageProxy m = (MessageProxy)mi.getArguments()[0];
       int theConsumerID = ((Integer)mi.getArguments()[1]).intValue();
       ConsumerDelegate cons = (ConsumerDelegate)mi.getArguments()[2];
+      int maxDeliveries = ((Integer)mi.getArguments()[3]).intValue();
       
       if (m == null)
       {
@@ -140,6 +141,7 @@
       holder.msg = m;
       holder.consumerID = theConsumerID;
       holder.consumerDelegate = cons;
+      holder.maxDeliveries = maxDeliveries;
       
       msgs.add(holder);
 
@@ -163,7 +165,7 @@
          if (trace) { log.trace("sending " + holder.msg + " to the message listener" ); }
          
          MessageCallbackHandler.callOnMessage(del, sessionListener, holder.consumerID, false,
-                                              holder.msg, ackMode);                          
+                                              holder.msg, ackMode, holder.maxDeliveries);                          
       }
       
       return null;
@@ -187,5 +189,6 @@
       MessageProxy msg;
       int consumerID;
       ConsumerDelegate consumerDelegate;
+      int maxDeliveries;
    }
 }

Modified: trunk/src/main/org/jboss/jms/client/container/ConsumerAspect.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/ConsumerAspect.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/container/ConsumerAspect.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -76,11 +76,12 @@
       int consumerID = consumerState.getConsumerID();
       int prefetchSize = consumerState.getPrefetchSize();
       QueuedExecutor sessionExecutor = sessionState.getExecutor();
+      int maxDeliveries = consumerState.getMaxDeliveries();
       
       MessageCallbackHandler messageHandler =
          new MessageCallbackHandler(isCC, sessionState.getAcknowledgeMode(),
                                     sessionDelegate, consumerDelegate, consumerID,
-                                    prefetchSize, sessionExecutor);
+                                    prefetchSize, sessionExecutor, maxDeliveries);
       
       sessionState.addCallbackHandler(messageHandler);
       

Modified: trunk/src/main/org/jboss/jms/client/container/SessionAspect.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/SessionAspect.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/container/SessionAspect.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -21,14 +21,13 @@
   */
 package org.jboss.jms.client.container;
 
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Iterator;
-import java.util.ArrayList;
 
 import javax.jms.IllegalStateException;
 import javax.jms.Session;
-import javax.jms.JMSException;
 
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
@@ -69,10 +68,45 @@
 
    public Object handleClosing(Invocation invocation) throws Throwable
    {
-      // Send to the server all acknowledgments accumulated in toAck. This is useful, for example,
-      // when a message listener close the session from its onMessage().
-      acknowledgeOnClosing(invocation);
+      MethodInvocation mi = (MethodInvocation)invocation;
+      SessionState state = getState(invocation);
+      SessionDelegate del = (SessionDelegate)mi.getTargetObject();
+      
+      int ackMode = state.getAcknowledgeMode();
 
+      // select eligible acknowledgments
+      List acks = new ArrayList();
+      List cancels = new ArrayList();
+      for(Iterator i = state.getToAck().iterator(); i.hasNext(); )
+      {
+         AckInfo ack = (AckInfo)i.next();
+         if (ackMode == Session.AUTO_ACKNOWLEDGE ||
+             ackMode == Session.DUPS_OK_ACKNOWLEDGE)
+         {
+            acks.add(ack);            
+         }
+         else
+         {
+            cancels.add(ack);
+         }
+         i.remove();
+      }
+      
+      // On closing we acknowlege any AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE, since the session
+      // might have closed before the onMessage had finished executing.
+      // 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.
+
+      if (!acks.isEmpty())
+      {
+         del.acknowledgeBatch(acks);
+      }
+      if (!cancels.isEmpty())
+      {
+         del.cancelDeliveries(cancels);
+      }
+
       return invocation.invokeNext();
    }
 
@@ -111,7 +145,7 @@
          Object[] args = mi.getArguments();
          MessageProxy mp = (MessageProxy)args[0];
          int consumerID = ((Integer)args[1]).intValue();
-         AckInfo info = new AckInfo(mp, consumerID, ackMode);
+         AckInfo info = new AckInfo(mp, consumerID);
          
          state.getToAck().add(info);
          
@@ -144,6 +178,13 @@
       
       int ackMode = state.getAcknowledgeMode();
       
+      boolean cancel = ((Boolean)mi.getArguments()[0]).booleanValue();
+      
+      if (cancel && ackMode != Session.AUTO_ACKNOWLEDGE && ackMode != Session.DUPS_OK_ACKNOWLEDGE)
+      {
+         throw new IllegalStateException("Ack mode must be AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE");
+      }
+      
       if (ackMode == Session.AUTO_ACKNOWLEDGE ||
           ackMode == Session.DUPS_OK_ACKNOWLEDGE ||
           ackMode != Session.CLIENT_ACKNOWLEDGE && state.getCurrentTxId() == null)
@@ -156,10 +197,26 @@
          if (!state.isRecoverCalled())
          {
             if (trace) { log.trace("acknowledging NON-transactionally"); }
-
+                        
             List acks = state.getToAck();
+            
+            // Sanity check
+            if (acks.size() != 1)
+            {
+               throw new IllegalStateException("Should only be one entry in list. " +
+                                               "There are " + acks.size());
+            }
+            
             AckInfo ack = (AckInfo)acks.get(0);
-            sd.acknowledge(ack);
+            
+            if (cancel)
+            {
+               sd.cancelDeliveries(acks);
+            }
+            else
+            {
+               sd.acknowledge(ack);
+            }
             state.getToAck().clear();
          }
          else
@@ -246,13 +303,8 @@
       for (int i = toRedeliver.size() - 1; i >= 0; i--)
       {
          AckInfo info = (AckInfo)toRedeliver.get(i);
-         MessageProxy proxy = info.getMessage();
-         proxy.setJMSRedelivered(true);
+         MessageProxy proxy = info.getMessage();        
          
-         //TODO delivery count although optional should be global so we need to send it back to the
-         //     server but this has performance hit so perhaps we just don't support it?
-         proxy.incDeliveryCount();
-         
          MessageCallbackHandler handler = state.getCallbackHandler(info.getConsumerID());
               
          if (handler == null)
@@ -307,35 +359,6 @@
       return (SessionState)((DelegateSupport)inv.getTargetObject()).getState();
    }
 
-   /**
-    * The method sends to server all eligible acknowlegments (those that are NOT CLIIENT_ACKNOWLEDGE
-    * for example)
-    */
-   private void acknowledgeOnClosing(Invocation invocation) throws JMSException
-   {
-      MethodInvocation mi = (MethodInvocation)invocation;
-      SessionState state = getState(invocation);
-      SessionDelegate del = (SessionDelegate)mi.getTargetObject();
-
-      // select eligible acknowledgments
-      List acks = new ArrayList();
-      for(Iterator i = state.getToAck().iterator(); i.hasNext(); )
-      {
-         AckInfo ack = (AckInfo)i.next();
-         if (ack.getAckMode() == Session.AUTO_ACKNOWLEDGE ||
-             ack.getAckMode() == Session.DUPS_OK_ACKNOWLEDGE)
-         {
-            acks.add(ack);
-            i.remove();
-         }
-      }
-
-      if (!acks.isEmpty())
-      {
-         del.acknowledgeBatch(acks);
-      }
-   }
-    
    // Inner Classes -------------------------------------------------
    
 }

Modified: trunk/src/main/org/jboss/jms/client/container/StateCreationAspect.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/StateCreationAspect.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/container/StateCreationAspect.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -140,9 +140,12 @@
       int prefetchSize =
          ((Integer)md.getMetaData(MetaDataConstants.JMS, MetaDataConstants.PREFETCH_SIZE)).intValue();
       
+      int maxDeliveries = 
+         ((Integer)md.getMetaData(MetaDataConstants.JMS, MetaDataConstants.MAX_DELIVERIES)).intValue();
+      
       ConsumerState consumerState =
          new ConsumerState(sessionState, consumerDelegate, dest, selector,
-                           noLocal, consumerID, connectionConsumer, prefetchSize);
+                           noLocal, consumerID, connectionConsumer, prefetchSize, maxDeliveries);
       
       delegate.setState(consumerState);
       return consumerDelegate;

Modified: trunk/src/main/org/jboss/jms/client/container/TransactionAspect.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/TransactionAspect.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/container/TransactionAspect.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -24,7 +24,6 @@
 import javax.jms.IllegalStateException;
 import javax.jms.Message;
 import javax.jms.TransactionInProgressException;
-import javax.jms.Session;
 
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
@@ -190,7 +189,7 @@
          MethodInvocation mi = (MethodInvocation)invocation;
          MessageProxy proxy = (MessageProxy)mi.getArguments()[0];
          int consumerID = ((Integer)mi.getArguments()[1]).intValue();
-         AckInfo info = new AckInfo(proxy, consumerID, Session.SESSION_TRANSACTED);
+         AckInfo info = new AckInfo(proxy, consumerID);
          ConnectionState connState = (ConnectionState)state.getParent();
 
          if (trace) { log.trace("sending acknowlegment transactionally, queueing on resource manager"); }

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -51,15 +51,17 @@
    // Attributes ----------------------------------------------------
    
    protected int bufferSize;
+   protected int maxDeliveries;
 
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
 
-   public ClientConsumerDelegate(int objectID, int bufferSize)
+   public ClientConsumerDelegate(int objectID, int bufferSize, int maxDeliveries)
    {
       super(objectID);
       this.bufferSize = bufferSize;
+      this.maxDeliveries = maxDeliveries;
    }
    
    public ClientConsumerDelegate()
@@ -177,6 +179,8 @@
                                 new Integer(id), PayloadKey.TRANSIENT);
       getMetaData().addMetaData(MetaDataConstants.JMS, MetaDataConstants.PREFETCH_SIZE,
                                 new Integer(bufferSize), PayloadKey.TRANSIENT);
+      getMetaData().addMetaData(MetaDataConstants.JMS, MetaDataConstants.MAX_DELIVERIES,
+                                new Integer(maxDeliveries), PayloadKey.TRANSIENT);
    }
 
    public String toString()

Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -303,7 +303,7 @@
     * This invocation should either be handled by the client-side interceptor chain or by the
     * server-side endpoint.
     */
-   public void postDeliver() throws JMSException
+   public void postDeliver(boolean cancel) throws JMSException
    {
       throw new IllegalStateException("This invocation should not be handled here!");
    }
@@ -403,7 +403,8 @@
     * This invocation should either be handled by the client-side interceptor chain or by the
     * server-side endpoint.
     */
-   public void addAsfMessage(MessageProxy m, int consumerID, ConsumerDelegate cons)
+   public void addAsfMessage(MessageProxy m, int consumerID,
+                             ConsumerDelegate cons, int maxDeliveries)
    {
       throw new IllegalStateException("This invocation should not be handled here!");
    }

Modified: trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/delegate/DelegateSupport.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -38,7 +38,7 @@
 
 /**
  * Base class for all client-side delegate classes.
- * 
+ *
  * Client-side delegate classes provide an empty implementation of the appropriate delegate
  * interface. The classes are advised using JBoss AOP to provide the client side advice stack.
  * The methods in the delegate class will never actually be invoked since they will either be
@@ -47,7 +47,7 @@
  * The delegates are created on the server and serialized back to the client. When they arrive on
  * the client, the init() method is called which causes the advices to be bound to the advised
  * class.
- * 
+ *
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  *
@@ -66,9 +66,9 @@
    // Attributes ----------------------------------------------------
 
    protected int id;
-   
+
    protected HierarchicalState state;
-   
+
    private boolean trace;
 
    // Static --------------------------------------------------------
@@ -77,12 +77,12 @@
 
    public DelegateSupport(int objectID)
    {
-      this.id = objectID;    
+      this.id = objectID;
       trace = log.isTraceEnabled();
    }
-   
+
    public DelegateSupport()
-   {      
+   {
    }
 
    // Interceptor implementation ------------------------------------
@@ -104,9 +104,9 @@
                                            Dispatcher.OID,
                                            new Integer(id),
                                            PayloadKey.AS_IS);
-      
+
       byte version = getState().getVersionToUse().getProviderIncrementingVersion();
-      
+
       MessagingMarshallable request = new MessagingMarshallable(version, invocation);
       MessagingMarshallable response = (MessagingMarshallable)getClient().invoke(request, null);
 
@@ -121,17 +121,17 @@
    {
       return state;
    }
-   
+
    public void setState(HierarchicalState state)
    {
       this.state = state;
    }
-   
+
    /**
     *  Add Invoking interceptor and prepare the stack for invocations.
     */
    public void init()
-   {          
+   {
       ((Advised)this)._getInstanceAdvisor().appendInterceptor(this);
 
       checkMarshallers();
@@ -150,7 +150,7 @@
    {
       return ((Advised)this)._getInstanceAdvisor().getMetaData();
    }
-   
+
    protected abstract Client getClient() throws Exception;
 
 
@@ -168,21 +168,7 @@
       {
          return;
       }
-      
-      //We explicitly associate the datatype "jms" with our custom SerializationManager
-      //This is vital for performance reasons.
-      try
-      {
-//         SerializationStreamFactory.setManagerClassName(
-//            "jms", "org.jboss.remoting.serialization.impl.jboss.JBossSerializationManager");
-         SerializationStreamFactory.setManagerClassName(
-                  "jms", "org.jboss.jms.server.remoting.MessagingSerializationManager");
-      }
-      catch (Exception e)
-      {
-         log.error("Failed to set SerializationManager, e");
-      }
-      
+
       checked = true;
    }
 

Copied: trunk/src/main/org/jboss/jms/client/remoting/ClientSocketWrapper.java (from rev 1631, branches/Branch_1_0/src/main/org/jboss/jms/client/remoting/ClientSocketWrapper.java)
===================================================================
--- branches/Branch_1_0/src/main/org/jboss/jms/client/remoting/ClientSocketWrapper.java	2006-11-23 06:51:36 UTC (rev 1631)
+++ trunk/src/main/org/jboss/jms/client/remoting/ClientSocketWrapper.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -0,0 +1,126 @@
+/*
+* 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.remoting;
+
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.util.Map;
+
+import org.jboss.jms.server.remoting.ServerSocketWrapper;
+import org.jboss.logging.Logger;
+import org.jboss.remoting.transport.socket.SocketWrapper;
+
+/**
+ * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
+ * @author <a href="mailto:tom.fox at jboss.com">Tim Fox</a>
+ *
+ * $Id$
+ */
+public class ClientSocketWrapper extends SocketWrapper
+{
+   // Constants -----------------------------------------------------
+   
+   final static private Logger log = Logger.getLogger(ClientSocketWrapper.class);
+
+
+   // Static --------------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private DataInputStream in;
+   private DataOutputStream out;
+
+   // Constructors --------------------------------------------------
+
+   public ClientSocketWrapper(Socket socket) throws IOException
+   {
+      super(socket);
+      createStreams(socket, null);
+   }
+
+   public ClientSocketWrapper(Socket socket, Map metadata, Integer timeout) throws Exception
+   {
+      super(socket, timeout);
+      createStreams(socket, metadata);
+   }
+
+   // Public --------------------------------------------------------
+
+   public OutputStream getOutputStream()
+   {
+      return out;
+   }
+
+   public InputStream getInputStream()
+   {
+      return in;
+   }
+
+   public void checkConnection() throws IOException
+   {
+      // Test to see if socket is alive by send ACK message
+      final byte ACK = 1;
+
+      out.writeByte(ACK);
+      out.flush();
+      in.readByte();
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   protected void createStreams(Socket socket, Map metadata) throws IOException
+   {
+      out = createOutputStream(socket);
+      in = createInputStream(socket);
+   }
+
+   protected DataInputStream createInputStream(Socket socket)
+         throws IOException
+   {
+      BufferedInputStream bin = new BufferedInputStream(socket.getInputStream());
+      
+      return new DataInputStream(bin);
+   }
+
+   protected DataOutputStream createOutputStream(Socket socket)
+         throws IOException
+   {
+      BufferedOutputStream bout = new BufferedOutputStream(socket.getOutputStream());
+      
+      return new DataOutputStream(bout);
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Deleted: trunk/src/main/org/jboss/jms/client/remoting/DummyCallbackHandler.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/remoting/DummyCallbackHandler.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/remoting/DummyCallbackHandler.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -1,48 +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.remoting;
-
-import org.jboss.remoting.callback.Callback;
-import org.jboss.remoting.callback.HandleCallbackException;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-
-/**
- * 
- * A DummyCallbackHandler.
- * 
- * This class is only used to trigger the addListener method on the JMSServerInvocationHandler
- * to be called, which allows the server to get hold of a reference to the callback client
- * so it can make callbacks
- * 
- * @author <a href="tim.fox at jboss.com">Tim Fox</a>
- * @version 1.1
- *
- * DummyCallbackHandler.java,v 1.1 2006/02/01 17:38:30 timfox Exp
- */
-public class DummyCallbackHandler implements InvokerCallbackHandler
-{
-
-   public void handleCallback(Callback cb) throws HandleCallbackException
-   {
-   }
-
-}

Modified: trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/remoting/JMSRemotingConnection.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -30,16 +30,14 @@
 import org.jboss.remoting.Client;
 import org.jboss.remoting.InvokerLocator;
 import org.jboss.remoting.callback.CallbackPoller;
+import org.jboss.remoting.transport.socket.MicroSocketClientInvoker;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
 
 
 /**
  * Encapsulates the state and behaviour from jboss remoting needed for a JMS connection.
  * 
- * Each JMS connection maintains a single Client instance for invoking on the server, and a
- * Connector instance that represents the callback server used to receive push callbacks from the
- * server.
- * Only Connector is maintained per protocol
- * 
+ * Each JMS connection maintains a single Client instance for invoking on the server
  * @author <a href="tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="ovidiu at jboss.org">Ovidiu Feodorov</a>
  * @version 1.1
@@ -107,8 +105,10 @@
          if (log.isTraceEnabled()) log.trace("doing push callbacks");
          HashMap metadata = new HashMap();
          metadata.put(InvokerLocator.DATATYPE, "jms");
-         metadata.put(InvokerLocator.SERIALIZATIONTYPE, "jms");
-
+         metadata.put(InvokerLocator.SERIALIZATIONTYPE, "jms"); //Not actually used at present - but it does no harm         
+         metadata.put(MicroSocketClientInvoker.CLIENT_SOCKET_CLASS_FLAG, "org.jboss.jms.client.remoting.ClientSocketWrapper");
+         metadata.put(SocketServerInvoker.SERVER_SOCKET_CLASS_FLAG, "org.jboss.jms.server.remoting.ServerSocketWrapper");
+         
          String bindAddress = System.getProperty("jboss.messaging.callback.bind.address");
          if (bindAddress != null)
          {

Modified: trunk/src/main/org/jboss/jms/client/remoting/MessageCallbackHandler.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/remoting/MessageCallbackHandler.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/remoting/MessageCallbackHandler.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -56,7 +56,7 @@
    
    // Static --------------------------------------------------------
    
-   private static boolean trace;
+   private static boolean trace;      
    
    static
    {
@@ -64,27 +64,29 @@
       trace = log.isTraceEnabled();
    }
      
-   // Hardcoded for now
-   private static final int MAX_REDELIVERIES = 10;
-      
    public static void callOnMessage(SessionDelegate sess,
                                     MessageListener listener,
                                     int consumerID,
                                     boolean isConnectionConsumer,
                                     MessageProxy m,
-                                    int ackMode)
+                                    int ackMode,
+                                    int maxDeliveries)
       throws JMSException
    {
       preDeliver(sess, consumerID, m, isConnectionConsumer);
                   
       int tries = 0;
       
+      boolean cancel = false;
+      
       while (true)
       {
          try
          {
             if (trace) { log.trace("calling listener's onMessage(" + m + ")"); }
-
+            
+            m.incDeliveryCount();
+            
             listener.onMessage(m);
 
             if (trace) { log.trace("listener's onMessage() finished"); }
@@ -101,24 +103,20 @@
    
             if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE)
             {
-               // We redeliver at certain number of times
-               if (tries < MAX_REDELIVERIES)
-               {
-                  m.setJMSRedelivered(true);
-                  
-                  // TODO delivery count although optional should be global so we need to send it
-                  // back to the server but this has performance hit so perhaps we just don't
-                  // support it?
-                  m.incDeliveryCount();
-                  
+               // We redeliver a certain number of times
+               if (tries < maxDeliveries)
+               {                            
                   tries++;
                }
                else
                {
                   log.error("Max redeliveries has occurred for message: " + m.getJMSMessageID());
                   
-                  //TODO - Send to DLQ
+                  // postdeliver will do a cancel rather than an ack which will cause the mesage
+                  // to end up in the DLQ
                   
+                  cancel = true;
+                  
                   break;
                }
             }
@@ -136,7 +134,7 @@
       if (!sess.isClosed())
       {
          // postDeliver only if the session is not closed
-         postDeliver(sess, isConnectionConsumer);
+         postDeliver(sess, isConnectionConsumer, cancel);
       }
    }
    
@@ -154,52 +152,41 @@
       }         
    }
    
-   protected static void postDeliver(SessionDelegate sess, boolean isConnectionConsumer)
-      throws JMSException
+   protected static void postDeliver(SessionDelegate sess, boolean isConnectionConsumer,
+                                     boolean cancel) throws JMSException
    {
       // 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)
       {
-         sess.postDeliver();
+         sess.postDeliver(cancel);
       }         
    }
    
    // Attributes ----------------------------------------------------
       
    private LinkedList buffer;
-   
    private SessionDelegate sessionDelegate;
-   
    private ConsumerDelegate consumerDelegate;
-   
    private int consumerID;
-   
    private boolean isConnectionConsumer;
-   
    private volatile Thread receiverThread;
-   
    private MessageListener listener;
-    
    private int ackMode;
-      
    private boolean closed;
-   
    private Object mainLock;
-   
    private boolean serverSending;
-   
    private int bufferSize;
-   
    private QueuedExecutor sessionExecutor;
-   
    private boolean listenerRunning;
+   private int maxDeliveries;
         
    // Constructors --------------------------------------------------
 
    public MessageCallbackHandler(boolean isCC, int ackMode,                                
                                  SessionDelegate sess, ConsumerDelegate cons, int consumerID,
-                                 int bufferSize, QueuedExecutor sessionExecutor)
+                                 int bufferSize, QueuedExecutor sessionExecutor,
+                                 int maxDeliveries)
    {
       if (bufferSize < 1)
       {
@@ -207,24 +194,16 @@
       }
               
       this.bufferSize = bufferSize;
-
       buffer = new LinkedList();
-
       isConnectionConsumer = isCC;
-      
       this.ackMode = ackMode;
-
       this.sessionDelegate = sess;
-
       this.consumerDelegate = cons;
-      
       this.consumerID = consumerID;
-      
       this.serverSending = true;
-      
-      mainLock = new Object();                  
-      
+      mainLock = new Object();
       this.sessionExecutor = sessionExecutor;
+      this.maxDeliveries = maxDeliveries;
    }
         
    // Public --------------------------------------------------------
@@ -464,7 +443,7 @@
                // message is acknowledged so it gets removed from the queue/subscription.
                preDeliver(sessionDelegate, consumerID, m, isConnectionConsumer);
                
-               postDeliver(sessionDelegate, isConnectionConsumer);
+               postDeliver(sessionDelegate, isConnectionConsumer, false);
                
                if (!m.getMessage().isExpired())
                {
@@ -499,6 +478,8 @@
          consumerDelegate.more();
       }
       
+      m.incDeliveryCount();
+      
       return m;
    }    
    
@@ -736,7 +717,7 @@
          {
             try
             {
-               callOnMessage(sessionDelegate, listener, consumerID, false, mp, ackMode);
+               callOnMessage(sessionDelegate, listener, consumerID, false, mp, ackMode, maxDeliveries);
             }
             catch (JMSException e)
             {

Modified: trunk/src/main/org/jboss/jms/client/state/ConsumerState.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/state/ConsumerState.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/client/state/ConsumerState.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -1,32 +1,32 @@
 /*
-  * 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.
-  */
+ * 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.state;
 
 import java.util.Collections;
 
 import javax.jms.Destination;
 
+import org.jboss.jms.client.delegate.DelegateSupport;
 import org.jboss.jms.client.remoting.MessageCallbackHandler;
-import org.jboss.jms.client.delegate.DelegateSupport;
 import org.jboss.jms.delegate.ConsumerDelegate;
 import org.jboss.jms.server.Version;
 
@@ -54,14 +54,16 @@
    private MessageCallbackHandler messageCallbackHandler;
    
    private int prefetchSize;
-
+   
    private SessionState parent;
-
+   
    private ConsumerDelegate delegate;
-
+   
+   private int maxDeliveries;
+   
    public ConsumerState(SessionState parent, ConsumerDelegate delegate, Destination dest,
-                        String selector, boolean noLocal, int consumerID, boolean isCC,
-                        int prefetchSize)
+            String selector, boolean noLocal, int consumerID, boolean isCC,
+            int prefetchSize, int maxDeliveries)
    {
       super(parent, (DelegateSupport)delegate);
       children = Collections.EMPTY_SET;
@@ -71,20 +73,21 @@
       this.consumerID = consumerID;
       this.isConnectionConsumer = isCC;
       this.prefetchSize = prefetchSize;
+      this.maxDeliveries = maxDeliveries;
    }
-
-
-    public DelegateSupport getDelegate()
-    {
-        return (DelegateSupport)delegate;
-    }
-
-    public void setDelegate(DelegateSupport delegate)
-    {
-        this.delegate = (ConsumerDelegate)delegate;
-    }
-
-
+   
+   
+   public DelegateSupport getDelegate()
+   {
+      return (DelegateSupport)delegate;
+   }
+   
+   public void setDelegate(DelegateSupport delegate)
+   {
+      this.delegate = (ConsumerDelegate)delegate;
+   }
+   
+   
    public Destination getDestination()
    {
       return destination;
@@ -129,13 +132,22 @@
    {
       return prefetchSize;
    }
-    public HierarchicalState getParent() {
-        return parent;
-    }
-
-    public void setParent(HierarchicalState parent) {
-        this.parent=(SessionState)parent;
-    }
+   
+   public HierarchicalState getParent()
+   {
+      return parent;
+   }
+   
+   public void setParent(HierarchicalState parent)
+   {
+      this.parent=(SessionState)parent;
+   }
+   
+   public int getMaxDeliveries()
+   {
+      return maxDeliveries;
+   }
+   
 }
 
 

Modified: trunk/src/main/org/jboss/jms/delegate/SessionDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/delegate/SessionDelegate.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/delegate/SessionDelegate.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -67,7 +67,7 @@
    
    void preDeliver(MessageProxy proxy, int consumerID) throws JMSException;
    
-   void postDeliver() throws JMSException;
+   void postDeliver(boolean cancel) throws JMSException;
    
    MessageListener getMessageListener() throws JMSException;
    
@@ -77,7 +77,7 @@
    
    XAResource getXAResource();
    
-   void addAsfMessage(MessageProxy m, int consumerID, ConsumerDelegate cons);
+   void addAsfMessage(MessageProxy m, int consumerID, ConsumerDelegate cons, int maxDeliveries);
    
    boolean getTransacted();
    
@@ -94,6 +94,4 @@
    ProducerDelegate createProducerDelegate(JBossDestination destination) throws JMSException;
    
    void acknowledgeAll() throws JMSException;
-
-
 }

Modified: trunk/src/main/org/jboss/jms/message/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMessage.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/message/JBossMessage.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -188,7 +188,7 @@
             sb.append(name).append(" - ").append(m.headers.get(name)).append('\n');
          }
       }
-      sb.append("              redelivered:   ").append(m.redelivered).append('\n');
+      sb.append("              redelivered:   ").append(m.deliveryCount >= 1).append('\n');
       sb.append("              priority:      ").append(m.priority).append('\n');
       sb.append("              deliveryCount: ").append(m.deliveryCount).append('\n');
 
@@ -336,7 +336,7 @@
          setJMSDestination(foreign.getJMSDestination());
       }
       setJMSDeliveryMode(foreign.getJMSDeliveryMode());
-      setJMSRedelivered(foreign.getJMSRedelivered());
+      setDeliveryCount(foreign.getJMSRedelivered() ? 1 : 0);
       setJMSExpiration(foreign.getJMSExpiration());
       setJMSPriority(foreign.getJMSPriority());
       setJMSType(foreign.getJMSType());
@@ -480,12 +480,19 @@
 
    public boolean getJMSRedelivered() throws JMSException
    {
-      return isRedelivered();
+      return deliveryCount >= 2;
    }
 
    public void setJMSRedelivered(boolean redelivered) throws JMSException
    {
-      setRedelivered(redelivered);
+      if (deliveryCount == 1)
+      {
+         deliveryCount++;
+      }
+      else
+      {
+         //do nothing
+      }
    }
 
    /**

Modified: trunk/src/main/org/jboss/jms/message/MessageProxy.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/MessageProxy.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/message/MessageProxy.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -80,7 +80,6 @@
    protected transient boolean bodyReadOnly;
 
    protected int deliveryCount;
-   protected transient boolean jmsRedelivered;
 
    // Constructors --------------------------------------------------
 
@@ -177,13 +176,24 @@
    public boolean getJMSRedelivered() throws JMSException
    {
       //Always handled in the delegate
-      return jmsRedelivered;
+      //This is because when sending a message to a topic (for instance)
+      //with multiple subscriptions all in the same VM, then we don't copy the original
+      //message for performance reasons, unless necessary, but each reference might have
+      //it's own value for delivery count
+      return deliveryCount >= 2;
    }
 
    public void setJMSRedelivered(boolean redelivered) throws JMSException
    {
       //Always handled in the delegate
-      jmsRedelivered = redelivered;
+      if (deliveryCount == 1)
+      {
+         deliveryCount++;
+      }
+      else
+      {
+         //do nothing
+      }
    }
 
    public String getJMSType() throws JMSException
@@ -407,8 +417,6 @@
       propertiesReadOnly = true;
 
       bodyReadOnly = true;
-
-      this.jmsRedelivered = deliveryCount > 1;
    }
 
    public JBossMessage getMessage()
@@ -423,7 +431,7 @@
    
    public void incDeliveryCount()
    {
-      this.deliveryCount++;
+      this.deliveryCount++;            
    }
 
    public String toString()

Modified: trunk/src/main/org/jboss/jms/server/ServerPeer.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/ServerPeer.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/server/ServerPeer.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -42,6 +42,7 @@
 import org.jboss.jms.server.security.SecurityMetadataStore;
 import org.jboss.jms.util.ExceptionUtil;
 import org.jboss.logging.Logger;
+import org.jboss.messaging.core.Queue;
 import org.jboss.messaging.core.memory.MemoryManager;
 import org.jboss.messaging.core.memory.SimpleMemoryManager;
 import org.jboss.messaging.core.plugin.IdManager;
@@ -49,13 +50,13 @@
 import org.jboss.messaging.core.plugin.contract.MessageStore;
 import org.jboss.messaging.core.plugin.contract.PersistenceManager;
 import org.jboss.messaging.core.plugin.contract.PostOffice;
+import org.jboss.messaging.core.plugin.postoffice.Binding;
 import org.jboss.messaging.core.plugin.postoffice.DefaultPostOffice;
 import org.jboss.messaging.core.tx.TransactionRepository;
 import org.jboss.messaging.util.Util;
 import org.jboss.mx.loading.UnifiedClassLoader3;
 import org.jboss.remoting.ServerInvocationHandler;
 import org.jboss.remoting.marshal.MarshalFactory;
-import org.jboss.remoting.serialization.SerializationStreamFactory;
 import org.jboss.system.ServiceCreator;
 import org.jboss.system.ServiceMBeanSupport;
 import org.w3c.dom.Element;
@@ -93,13 +94,17 @@
 
    private String defaultQueueJNDIContext;
    private String defaultTopicJNDIContext;
-   
+
    private int queuedExecutorPoolSize = 200;
 
    private boolean started;
 
    private int objectIDSequence = 1;
-   
+
+   private int maxDeliveryAttempts = 10;
+
+   private String dlqName;
+
    // wired components
 
    private DestinationJNDIMapper destinationJNDIMapper;
@@ -113,24 +118,24 @@
    private IdManager transactionIdManager;
    private MemoryManager memoryManager;
    private QueuedExecutorPool queuedExecutorPool;
-   private MessageStore messageStore;   
+   private MessageStore messageStore;
 
    // plugins
 
    protected ObjectName persistenceManagerObjectName;
    protected PersistenceManager persistenceManager;
-   
+
    protected ObjectName queuePostOfficeObjectName;
    protected DefaultPostOffice queuePostOffice;
-   
+
    protected ObjectName topicPostOfficeObjectName;
    protected DefaultPostOffice topicPostOffice;
-     
+
    protected ObjectName jmsUserManagerObjectName;
    protected JMSUserManager jmsUserManager;
-   
+
    //Other stuff
-   
+
    private JMSServerInvocationHandler handler;
 
    // We keep a map of consumers to prevent us to recurse through the attached session in order to
@@ -153,7 +158,7 @@
 
       // Some wired components need to be started here
       securityStore = new SecurityMetadataStore();
-      
+
       consumers = new ConcurrentReaderHashMap();
 
       version = Version.instance();
@@ -167,38 +172,40 @@
    {
       try
       {
+         log.debug("starting ServerPeer");
+
          if (started)
          {
             return;
          }
-         
+
          log.debug(this + " starting");
-         
+
          if (queuedExecutorPoolSize < 1)
          {
             throw new IllegalArgumentException("queuedExecutorPoolSize must be > 0");
          }
          queuedExecutorPool = new QueuedExecutorPool(queuedExecutorPoolSize);
-            
+
          loadClientAOPConfig();
-   
+
          loadServerAOPConfig();
-   
+
          MBeanServer mbeanServer = getServer();
-   
+
          // Acquire references to plugins. Each plug-in will be accessed directly via a reference
          // circumventing the MBeanServer. However, they are installed as services to take advantage
          // of their automatically-creating management interface.
-   
+
          persistenceManager = (PersistenceManager)mbeanServer.
             getAttribute(persistenceManagerObjectName, "Instance");
 
          jmsUserManager = (JMSUserManager)mbeanServer.
             getAttribute(jmsUserManagerObjectName, "Instance");
-         
+
          //We get references to some plugins lazily to avoid problems with circular
          //MBean dependencies
-            
+
          // Create the wired components
          messageIdManager = new IdManager("MESSAGE_ID", 4096, persistenceManager);
          channelIdManager = new IdManager("CHANNEL_ID", 10, persistenceManager);
@@ -208,36 +215,36 @@
          connectionManager = new SimpleConnectionManager();
          connectorManager = new SimpleConnectorManager();
          memoryManager = new SimpleMemoryManager();
-         messageStore = new SimpleMessageStore();         
+         messageStore = new SimpleMessageStore();
          txRepository = new TransactionRepository(persistenceManager, transactionIdManager);
- 
+
          // Start the wired components
-   
+
          messageIdManager.start();
          channelIdManager.start();
          transactionIdManager.start();
          destinationJNDIMapper.start();
          connFactoryJNDIMapper.start();
          connectionManager.start();
-         connectorManager.start();         
+         connectorManager.start();
          memoryManager.start();
          messageStore.start();
          securityStore.start();
          txRepository.start();
-         
+
          initializeRemoting(mbeanServer);
-   
+
          //createRecoverable();
-   
+
          started = true;
-   
+
          log.info("JBoss Messaging " + getVersion().getProviderVersion() + " server [" +
-            getServerPeerID()+ "] started");      
+            getServerPeerID()+ "] started");
       }
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " startService");
-      } 
+      }
    }
 
    public synchronized void stopService() throws Exception
@@ -248,15 +255,15 @@
          {
             return;
          }
-   
+
          log.debug(this + " stopping");
-   
+
          started = false;
-   
+
          //removeRecoverable();
-        
-         // Stop the wired components         
-         
+
+         // Stop the wired components
+
          messageIdManager.stop();
          messageIdManager = null;
          channelIdManager.stop();
@@ -269,7 +276,7 @@
          connFactoryJNDIMapper = null;
          connectionManager.stop();
          connectionManager = null;
-         connectorManager.start(); 
+         connectorManager.start();
          connectorManager = null;
          memoryManager.stop();
          memoryManager = null;
@@ -279,23 +286,43 @@
          securityStore = null;
          txRepository.stop();
          txRepository = null;
-   
+
          unloadServerAOPConfig();
-   
+
          // TODO unloadClientAOPConfig();
-         
+
          queuedExecutorPool.shutdown();
-                  
+
          log.info("JMS " + this + " stopped");
       }
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " stopService");
-      } 
+      }
    }
 
    // JMX Attributes ------------------------------------------------
 
+   public String getDLQName()
+   {
+      return dlqName;
+   }
+
+   public void setDLQName(String dlqName)
+   {
+      this.dlqName = dlqName;
+   }
+
+   public int getMaxDeliveryAttempts()
+   {
+      return maxDeliveryAttempts;
+   }
+
+   public void setMaxDeliveryAttempts(int attempts)
+   {
+      this.maxDeliveryAttempts = attempts;
+   }
+
    public ObjectName getPersistenceManager()
    {
       return persistenceManagerObjectName;
@@ -305,7 +332,7 @@
    {
       persistenceManagerObjectName = on;
    }
-   
+
    public ObjectName getQueuePostOffice()
    {
       return queuePostOfficeObjectName;
@@ -315,7 +342,7 @@
    {
       queuePostOfficeObjectName = on;
    }
-   
+
    public ObjectName getTopicPostOffice()
    {
       return topicPostOfficeObjectName;
@@ -325,7 +352,7 @@
    {
       topicPostOfficeObjectName = on;
    }
-   
+
    public ObjectName getJmsUserManager()
    {
       return jmsUserManagerObjectName;
@@ -335,7 +362,7 @@
    {
       jmsUserManagerObjectName = on;
    }
-   
+
    public Object getInstance()
    {
       return this;
@@ -395,12 +422,12 @@
    {
       try
       {
-         securityStore.setSecurityDomain(securityDomain);      
+         securityStore.setSecurityDomain(securityDomain);
       }
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " setSecurityDomain");
-      } 
+      }
    }
 
    public String getSecurityDomain()
@@ -422,7 +449,7 @@
    {
       return messageIdManager;
    }
-   
+
    public IdManager getChannelIdManager()
    {
       return channelIdManager;
@@ -432,17 +459,17 @@
    {
       return handler;
    }
-   
+
    public int getQueuedExecutorPoolSize()
    {
       return queuedExecutorPoolSize;
    }
-   
+
    public void setQueuedExecutorPoolSize(int poolSize)
    {
       this.queuedExecutorPoolSize = poolSize;
    }
-   
+
    // JMX Operations ------------------------------------------------
 
    public String createQueue(String name, String jndiName) throws Exception
@@ -454,7 +481,7 @@
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " createQueue");
-      } 
+      }
    }
 
    public String createQueue(String name, String jndiName, int fullSize, int pageSize, int downCacheSize) throws Exception
@@ -466,7 +493,7 @@
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " createQueue(2)");
-      } 
+      }
    }
 
    public boolean destroyQueue(String name) throws Exception
@@ -478,7 +505,7 @@
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " destroyQueue");
-      } 
+      }
    }
 
    public String createTopic(String name, String jndiName) throws Exception
@@ -490,7 +517,7 @@
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " createTopic");
-      } 
+      }
    }
 
    public String createTopic(String name, String jndiName, int fullSize, int pageSize, int downCacheSize) throws Exception
@@ -502,7 +529,7 @@
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " createTopic(2)");
-      } 
+      }
    }
 
    public boolean destroyTopic(String name) throws Exception
@@ -514,7 +541,7 @@
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " destroyTopic");
-      } 
+      }
    }
 
    public Set getDestinations() throws Exception
@@ -526,11 +553,33 @@
       catch (Throwable t)
       {
          throw ExceptionUtil.handleJMXInvocation(t, this + " getDestinations");
-      } 
+      }
    }
 
-   // Public --------------------------------------------------------     
+   // Public --------------------------------------------------------
 
+   public Queue getDLQ() throws Exception
+   {
+      if (dlqName == null)
+      {
+         //No DLQ name specified so there is no DLQ
+         return null;
+      }
+
+      PostOffice queuePostOffice = getQueuePostOfficeInstance();
+
+      Binding binding = queuePostOffice.getBindingForQueueName(dlqName);
+      
+      if (binding != null && binding.getQueue().isActive())
+      {
+         return binding.getQueue();
+      }
+      else
+      {
+         return null;
+      }   
+   }
+
    public TransactionRepository getTxRepository()
    {
       return txRepository;
@@ -550,7 +599,7 @@
    {
       return version;
    }
-   
+
    // access to hard-wired server extensions
 
    public SecurityManager getSecurityManager()
@@ -577,12 +626,12 @@
    {
       return connectorManager;
    }
-   
+
    public MessageStore getMessageStore()
    {
       return messageStore;
    }
-   
+
    public MemoryManager getMemoryManager()
    {
       return memoryManager;
@@ -594,23 +643,24 @@
    {
       return persistenceManager;
    }
-   
+
    public JMSUserManager getJmsUserManagerInstance()
    {
       return jmsUserManager;
    }
-   
+
    public PostOffice getQueuePostOfficeInstance() throws Exception
    {
       // We get the reference lazily to avoid problems with MBean circular dependencies
       if (queuePostOffice == null)
       {
+         //TODO - why is this DefaultPostOffice and not just PostOffice??
          queuePostOffice = (DefaultPostOffice)getServer().
             getAttribute(queuePostOfficeObjectName, "Instance");
       }
       return queuePostOffice;
    }
-      
+
    public PostOffice getTopicPostOfficeInstance() throws Exception
    {
       // We get the reference lazily to avoid problems with MBean circular dependencies
@@ -619,9 +669,9 @@
          topicPostOffice = (DefaultPostOffice)getServer().
             getAttribute(topicPostOfficeObjectName, "Instance");
       }
-      return topicPostOffice;        
+      return topicPostOffice;
    }
-      
+
    public synchronized int getNextObjectID()
    {
       return objectIDSequence++;
@@ -643,7 +693,7 @@
       log.debug(this + " removing consumer " + consumerID + " from the cache");
       return (ServerConsumerEndpoint)consumers.remove(consumerID);
    }
-   
+
    public QueuedExecutorPool getQueuedExecutorPool()
    {
       return queuedExecutorPool;
@@ -716,14 +766,6 @@
 
    private void initializeRemoting(MBeanServer mbeanServer) throws Exception
    {
-      // We explicitly associate the datatype "jms" with the java SerializationManager
-      // This is vital for performance reasons.
-//      SerializationStreamFactory.setManagerClassName(
-//         "jms", "org.jboss.remoting.serialization.impl.jboss.JBossSerializationManager");
-      SerializationStreamFactory.setManagerClassName(
-             "jms", "org.jboss.jms.server.remoting.MessagingSerializationManager");
-      
-
       JMSWireFormat wf = new JMSWireFormat();
 
       MarshalFactory.addMarshaller("jms", wf, wf);
@@ -855,7 +897,7 @@
 
       String destType = isQueue ? "Queue" : "Topic";
       String className = "org.jboss.jms.server.destination." + destType + "Service";
-      
+
       String ons ="jboss.messaging.destination:service="+ destType + ",name=" + name;
       ObjectName on = new ObjectName(ons);
 
@@ -870,7 +912,7 @@
          "    <attribute name=\"PageSize\">" + pageSize + "</attribute>" +
          "    <attribute name=\"DownCacheSize\">" + downCacheSize + "</attribute>" +
          "</mbean>";
-      
+
       return createDestinationInternal(destinationMBeanConfig, on, jndiName, true, fullSize,
                                        pageSize, downCacheSize);
    }

Modified: trunk/src/main/org/jboss/jms/server/destination/DestinationServiceSupport.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/destination/DestinationServiceSupport.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/server/destination/DestinationServiceSupport.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -118,7 +118,7 @@
             throw new IllegalStateException( "The " + (isQueue() ? "queue" : "topic") + " " +
                                              "name was not properly set in the service's" +
                                              "ObjectName");
-         }
+         }                  
          
          destination.setName(name);                   
       }
@@ -134,7 +134,7 @@
    }
    
    // JMX managed attributes ----------------------------------------
-
+   
    public String getJNDIName()
    {
       return destination.getJndiName();

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -45,6 +45,7 @@
 import org.jboss.messaging.core.Delivery;
 import org.jboss.messaging.core.DeliveryObserver;
 import org.jboss.messaging.core.MessageReference;
+import org.jboss.messaging.core.Queue;
 import org.jboss.messaging.core.Receiver;
 import org.jboss.messaging.core.Routable;
 import org.jboss.messaging.core.SimpleDelivery;
@@ -76,9 +77,8 @@
 
    private static final Logger log = Logger.getLogger(ServerConsumerEndpoint.class);
 
-   // Static --------------------------------------------------------
+   // Static --------------------------------------------------------  
 
-   private static final int MAX_DELIVERY_ATTEMPTS = 10;
    private static final int MESSAGES_IN_TRANSIT_WAIT_COUNT = 100;
 
    // Attributes ----------------------------------------------------
@@ -123,7 +123,9 @@
    private Object lock;
 
    private Map deliveries;
-
+   
+   private Queue dlq;
+   
    private Object messagesInTransitLock;
    private int messagesInTransitCount; // access only from a region guarded by messagesInTransitLock
    
@@ -132,8 +134,8 @@
    protected ServerConsumerEndpoint(int id, PagingFilteredQueue messageQueue, String queueName,
                                     ServerSessionEndpoint sessionEndpoint,
                                     String selector, boolean noLocal, JBossDestination dest,
-                                    int prefetchSize)
-                                    throws InvalidSelectorException
+                                    int prefetchSize, Queue dlq)
+      throws InvalidSelectorException
    {
       if (trace) { log.trace("constructing consumer endpoint " + id); }
 
@@ -142,6 +144,7 @@
       this.queueName = queueName;
       this.sessionEndpoint = sessionEndpoint;
       this.prefetchSize = prefetchSize;
+      this.dlq = dlq;
 
       // We always created with clientConsumerFull = true. This prevents the SCD sending messages to
       // the client before the client has fully finished creating the MessageCallbackHandler.
@@ -254,9 +257,7 @@
          {
             return delivery;
          }
-            
-         checkDeliveryCount(delivery);
-         
+                 
          if (delivery.isDone())
          {
             return delivery;
@@ -600,18 +601,56 @@
       messageQueue.deliver(false);
    }
    
-   protected void cancelDelivery(Long messageID) throws Throwable
+   protected void sendToDLQ(Long messageID, Transaction tx) throws Throwable
    {
       Delivery del = (Delivery)deliveries.remove(messageID);
+      
       if (del != null)
-      {     
-          del.cancel();
+      { 
+         log.warn(del.getReference() + " has exceed maximum delivery attempts and will be sent to the DLQ");
+         
+         if (dlq != null)
+         {         
+            //reset delivery count to zero
+            del.getReference().setDeliveryCount(0);
+            
+            dlq.handle(null, del.getReference(), tx);
+            
+            del.acknowledge(tx);           
+         }
+         else
+         {
+            log.warn("Cannot send to DLQ since DLQ has not been deployed! The message will be removed");
+            
+            del.acknowledge(tx);
+         }
       }
       else
       {
-          throw new IllegalStateException("Cannot find delivery to cancel:" + id);
+         throw new IllegalStateException("Cannot find delivery to send to DLQ:" + id);
       }
+      
    }
+   
+   protected void cancelDelivery(Long messageID, int deliveryCount) throws Throwable
+   {
+      Delivery del = (Delivery)deliveries.remove(messageID);
+      
+      if (del != null)
+      {                               
+         //Cancel back to the queue
+         
+         //Update the delivery count
+           
+         del.getReference().setDeliveryCount(deliveryCount);
+              
+         del.cancel();         
+      }
+      else
+      {
+         throw new IllegalStateException("Cannot find delivery to cancel:" + id);
+      }
+   }
                
    protected void start()
    {             
@@ -705,7 +744,7 @@
             {
                MessageProxy proxy = (MessageProxy)toDeliver.get(i);
                long id = proxy.getMessage().getMessageID();
-               cancelDelivery(new Long(id));
+               cancelDelivery(new Long(id), proxy.getMessage().getDeliveryCount());
             }
          }
                  
@@ -730,27 +769,7 @@
          if (trace) { log.trace(this + " removed from the queue"); }
       }
    }
-     
-   private void checkDeliveryCount(SimpleDelivery del)
-   {
-      // TODO - We need to put the message in a DLQ
-      // For now we just ack it otherwise the message will keep being retried and we'll never get
-      // anywhere
-      if (del.getReference().getDeliveryCount() > MAX_DELIVERY_ATTEMPTS)
-      {
-         log.warn(del.getReference() + " has exceed maximum delivery attempts and will be removed");
-         
-         try
-         {
-            del.acknowledge(null);
-         }
-         catch (Throwable t)
-         {
-            log.error("Failed to acknowledge delivery", t);
-         }
-      }                 
-   }
-   
+
    // Inner classes -------------------------------------------------   
    
    /*

Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -21,6 +21,8 @@
   */
 package org.jboss.jms.server.endpoint;
 
+
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -64,6 +66,7 @@
 import org.jboss.messaging.core.plugin.contract.PostOffice;
 import org.jboss.messaging.core.plugin.postoffice.Binding;
 import org.jboss.messaging.core.plugin.postoffice.cluster.LocalClusteredQueue;
+import org.jboss.messaging.core.tx.Transaction;
 import org.jboss.messaging.core.tx.TransactionRepository;
 import org.jboss.util.id.GUID;
 
@@ -101,6 +104,7 @@
 
    private PersistenceManager pm;
    private MessageStore ms;
+
    private DestinationManager dm;
    private IdManager idm;
    private QueuedExecutorPool pool;
@@ -108,8 +112,9 @@
    private PostOffice topicPostOffice;
    private PostOffice queuePostOffice;
    private int nodeId;
+   private int maxDeliveryAttempts;
+   private Queue dlq;
 
-
    // Constructors --------------------------------------------------
 
    protected ServerSessionEndpoint(int sessionID, ServerConnectionEndpoint connectionEndpoint)
@@ -133,6 +138,10 @@
 
       consumers = new HashMap();
 		browsers = new HashMap();
+      
+      dlq = sp.getDLQ();
+      tr = sp.getTxRepository();
+      maxDeliveryAttempts = sp.getMaxDeliveryAttempts();
    }
 
    // SessionDelegate implementation --------------------------------
@@ -385,11 +394,11 @@
 
          ServerConsumerEndpoint ep =
             new ServerConsumerEndpoint(consumerID, (PagingFilteredQueue)binding.getQueue(), binding.getQueue().getName(),
-                                       this, selectorString, noLocal, jmsDestination, prefetchSize);
+                                       this, selectorString, noLocal, jmsDestination, prefetchSize, dlq);
 
          JMSDispatcher.instance.registerTarget(new Integer(consumerID), new ConsumerAdvised(ep));
 
-         ClientConsumerDelegate stub = new ClientConsumerDelegate(consumerID, prefetchSize);
+         ClientConsumerDelegate stub = new ClientConsumerDelegate(consumerID, prefetchSize, maxDeliveryAttempts);
 
          putConsumerEndpoint(consumerID, ep); // caching consumer locally
 
@@ -585,7 +594,7 @@
          throw ExceptionUtil.handleJMSInvocation(t, this + " acknowledge");
       }
    }
-
+   
    public void cancelDeliveries(List ackInfos) throws JMSException
    {
       try
@@ -594,6 +603,8 @@
 
          Set consumers = new HashSet();
 
+         List forDLQ = null;
+         
          for (int i = ackInfos.size() - 1; i >= 0; i--)
          {
             AckInfo ack = (AckInfo)ackInfos.get(i);
@@ -607,10 +618,58 @@
                throw new IllegalArgumentException("Cannot find consumer id: " + ack.getConsumerID());
             }
 
-            consumer.cancelDelivery(new Long(ack.getMessageID()));
+            if (ack.getDeliveryCount() >= maxDeliveryAttempts)
+            {
+               if (forDLQ == null)
+               {
+                  forDLQ = new ArrayList();
+               }
+               
+               forDLQ.add(ack);
+            }
+            else
+            {            
+               consumer.cancelDelivery(new Long(ack.getMessageID()), ack.getDeliveryCount());
+            }
+            
             consumers.add(consumer);
          }
 
+         //Send stuff to DLQ
+         
+         if (forDLQ != null)
+         {
+            //We do this in a tx so we don't end up with the message in both the original queue
+            //and the dlq if it fails half way through
+            Transaction tx = tr.createTransaction();
+            
+            try
+            {               
+               for (int i = forDLQ.size() - 1; i >= 0; i--)
+               {
+                  AckInfo ack = (AckInfo)forDLQ.get(i);
+                  
+                  ServerConsumerEndpoint consumer =
+                     this.connectionEndpoint.getConsumerEndpoint(ack.getConsumerID());
+         
+                  if (consumer == null)
+                  {
+                     throw new IllegalArgumentException("Cannot find consumer id: " + ack.getConsumerID());
+                  }
+                  
+                  consumer.sendToDLQ(new Long(ack.getMessageID()), tx);                              
+               }
+               
+               tx.commit();
+            }
+            catch (Throwable t)
+            {
+               tx.rollback();
+               
+               throw t;
+            }
+         }
+         
          // need to prompt delivery for all consumers
 
          for(Iterator i = consumers.iterator(); i.hasNext(); )

Modified: trunk/src/main/org/jboss/jms/server/remoting/JMSWireFormat.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/remoting/JMSWireFormat.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/server/remoting/JMSWireFormat.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -130,22 +130,28 @@
 
    public void write(Object obj, OutputStream out) throws IOException
    {          
-      DataOutputStream dos = null;
+      DataOutputStream dos;
       
-      // This won't be necessary: see JBREM-597.
-      if (out instanceof MessagingObjectOutputStream)
+      if (out instanceof DataOutputStream)
       {
-         dos = (DataOutputStream)(((MessagingObjectOutputStream)out).getUnderlyingStream());
-      }
-      else if (out instanceof DataOutputStream)
-      {
          dos = (DataOutputStream)out;
       }
       else
       {
+         //Further sanity check
+         if (out instanceof ObjectOutputStream)
+         {
+            throw new IllegalArgumentException("Invalid stream - are you sure you have configured socket wrappers?");
+         }
+         
+         //This would be the case for the HTTP transport for example
+         //Wrap the stream
+         
+         //TODO Ideally remoting would let us wrap this before invoking the marshaller
+         //but this does not appear to be possible
          dos = new DataOutputStream(out);
       }
-      
+                  
       handleVersion(obj, dos);
 
       try
@@ -499,20 +505,26 @@
    // UnMarshaller implementation -----------------------------------
 
    public Object read(InputStream in, Map map) throws IOException, ClassNotFoundException
-   {      
-      DataInputStream dis = null;
+   {            
+      DataInputStream dis;
       
-      // This won't be necessary: see JBREM-597.
-      if (in instanceof MessagingObjectInputStream)
+      if (in instanceof DataInputStream)
       {
-         dis = (DataInputStream)(((MessagingObjectInputStream)in).getUnderlyingStream());
+         dis = (DataInputStream)in;         
       }
-      else if (in instanceof DataInputStream)
-      {
-         dis = (DataInputStream) in;
-      }
       else
-      {
+      {        
+         //Further sanity check
+         if (in instanceof ObjectInputStream)
+         {
+            throw new IllegalArgumentException("Invalid stream - are you sure you have configured socket wrappers?");
+         }
+         
+         //This would be the case for the HTTP transport for example
+         //Wrap the stream
+         
+         //TODO Ideally remoting would let us wrap this before invoking the marshaller
+         //but this does not appear to be possible
          dis = new DataInputStream(in);
       }
       

Deleted: trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectInputStream.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectInputStream.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectInputStream.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -1,201 +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.server.remoting;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InvalidObjectException;
-import java.io.NotActiveException;
-import java.io.ObjectInputStream;
-import java.io.ObjectInputValidation;
-
-/**
- * A MessagingObjectInputStream
- * 
- * See comment in MessagingSerializationManager
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class MessagingObjectInputStream extends ObjectInputStream
-{
-   private InputStream in;
-
-   public MessagingObjectInputStream(InputStream in) throws IOException, SecurityException
-   {
-      this.in = in;     
-   }
-   
-   public InputStream getUnderlyingStream()
-   {
-      return in;
-   }
-
-   public int available() throws IOException
-   {
-      return in.available();
-   }
-
-   public void close() throws IOException
-   {
-      in.close();
-   }
-
-   public boolean equals(Object obj)
-   {
-      return in.equals(obj);
-   }
-
-   public int hashCode()
-   {
-      return in.hashCode();
-   }
-
-   public void mark(int readlimit)
-   {
-      in.mark(readlimit);
-   }
-
-   public boolean markSupported()
-   {
-      return in.markSupported();
-   }
-
-   public int read() throws IOException
-   {
-      return in.read();
-   }
-
-   public int read(byte[] b, int off, int len) throws IOException
-   {
-      return in.read(b, off, len);
-   }
-
-   public int read(byte[] b) throws IOException
-   {
-      return in.read(b);
-   }
-
-   public void reset() throws IOException
-   {
-      in.reset();
-   }
-
-   public long skip(long n) throws IOException
-   {
-      return in.skip(n);
-   }
-
-   public String toString()
-   {
-      return in.toString();
-   }
-
-   public void defaultReadObject() throws IOException, ClassNotFoundException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public boolean readBoolean() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public byte readByte() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public char readChar() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public double readDouble() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public GetField readFields() throws IOException, ClassNotFoundException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public float readFloat() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void readFully(byte[] buf, int off, int len) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void readFully(byte[] buf) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public int readInt() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public long readLong() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public short readShort() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public Object readUnshared() throws IOException, ClassNotFoundException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public int readUnsignedByte() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public int readUnsignedShort() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public String readUTF() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void registerValidation(ObjectInputValidation obj, int prio) throws NotActiveException, InvalidObjectException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-}

Deleted: trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectOutputStream.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectOutputStream.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/server/remoting/MessagingObjectOutputStream.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -1,168 +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.server.remoting;
-
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-
-/**
- * A MessagingObjectOutputStream
- * 
- * See comment in MessagingSerializationManager
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class MessagingObjectOutputStream extends ObjectOutputStream
-{
-   private OutputStream out;
-   
-   public MessagingObjectOutputStream(OutputStream out) throws IOException
-   {
-      this.out = out;
-   }
-   
-   public OutputStream getUnderlyingStream()
-   {
-      return out;
-   }
-
-   public void close() throws IOException
-   {
-      out.close();
-   }
-
-   public boolean equals(Object obj)
-   {
-      return out.equals(obj);
-   }
-
-   public void flush() throws IOException
-   {
-      out.flush();
-   }
-
-   public void write(byte[] b, int off, int len) throws IOException
-   {
-      out.write(b, off, len);
-   }
-
-   public void write(byte[] b) throws IOException
-   {
-      out.write(b);
-   }
-
-   public void write(int b) throws IOException
-   {
-      out.write(b);
-   }
-
-   public void defaultWriteObject() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public PutField putFields() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void reset() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void useProtocolVersion(int version) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeBoolean(boolean val) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeByte(int val) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeBytes(String str) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeChar(int val) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeChars(String str) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeDouble(double val) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeFields() throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeFloat(float val) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeInt(int val) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeLong(long val) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeShort(int val) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeUnshared(Object obj) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void writeUTF(String str) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-}

Deleted: trunk/src/main/org/jboss/jms/server/remoting/MessagingSerializationManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/remoting/MessagingSerializationManager.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/server/remoting/MessagingSerializationManager.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -1,83 +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.server.remoting;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-
-import org.jboss.remoting.serialization.IMarshalledValue;
-import org.jboss.remoting.serialization.SerializationManager;
-
-/**
- * A MessagingSerializationManager
- * 
- * This class and the related ObjectInputStream and ObjectOutputStream classes
- * are a hack to work around a limitiation of JBoss remoting whereby it always assumes
- * the createInput and createOutput methods always return an ObjectInput/OutputStream
- * For the purposes of messaging we want the marshaller and the server and client invokers
- * to use the underlying stream instead, since we do not want all the extra crap that the object input/output
- * streams add to the stream (headers)
- * This should really be fixed properly in remoting
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class MessagingSerializationManager extends SerializationManager
-{
-   public IMarshalledValue createdMarshalledValue(Object arg0) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public ObjectInputStream createInput(InputStream in, ClassLoader cl) throws IOException
-   {
-      return new MessagingObjectInputStream(new DataInputStream(in));
-   }
-   
-   public ObjectOutputStream createOutput(OutputStream out) throws IOException
-   {
-      return new MessagingObjectOutputStream(new DataOutputStream(out));
-   }
-
-   public IMarshalledValue createMarshalledValueForClone(Object arg0) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-  
-   public Object receiveObject(InputStream arg0, ClassLoader arg1) throws IOException, ClassNotFoundException
-   {
-      throw new UnsupportedOperationException();
-   }
-
-   public void sendObject(ObjectOutputStream arg0, Object arg1) throws IOException
-   {
-      throw new UnsupportedOperationException();
-   }
-}

Modified: trunk/src/main/org/jboss/jms/server/remoting/MetaDataConstants.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/remoting/MetaDataConstants.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/server/remoting/MetaDataConstants.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -46,4 +46,6 @@
    public static final String VERSION_NUMBER = "VERSION_NUMBER";
    
    public static final String JMS_CLIENT_VM_ID = "JMS_CLIENT_VM_ID";
+   
+   public static final String MAX_DELIVERIES = "MAX_DELS";
 }

Copied: trunk/src/main/org/jboss/jms/server/remoting/ServerSocketWrapper.java (from rev 1631, branches/Branch_1_0/src/main/org/jboss/jms/server/remoting/ServerSocketWrapper.java)
===================================================================
--- branches/Branch_1_0/src/main/org/jboss/jms/server/remoting/ServerSocketWrapper.java	2006-11-23 06:51:36 UTC (rev 1631)
+++ trunk/src/main/org/jboss/jms/server/remoting/ServerSocketWrapper.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -0,0 +1,107 @@
+/*
+* 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.server.remoting;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.net.Socket;
+import java.util.Map;
+
+import org.jboss.jms.client.remoting.ClientSocketWrapper;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
+ * @author <a href="mailto:tom.fox at jboss.com">Tim Fox</a>
+ *
+ * $Id$
+ */
+public class ServerSocketWrapper extends ClientSocketWrapper
+{
+   // Constants -----------------------------------------------------
+
+   final static private Logger log = Logger.getLogger(ServerSocketWrapper.class);
+
+   // Static --------------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private boolean trace = log.isTraceEnabled();
+
+   // Constructors --------------------------------------------------
+
+   public ServerSocketWrapper(Socket socket) throws Exception
+   {
+      super(socket);
+   }
+
+   public ServerSocketWrapper(Socket socket, Map metadata, Integer timeout) throws Exception
+   {
+      super(socket, metadata, timeout);
+   }
+
+   // Public --------------------------------------------------------
+
+   public void checkConnection() throws IOException
+   {
+      // Perform acknowledgement to convince client that the socket is still active
+      byte ACK = 0;
+
+      try
+      {
+         ACK = ((DataInputStream)getInputStream()).readByte();
+      }
+      catch(EOFException eof)
+      {
+         if (trace)
+         {
+            log.trace("socket timeout is set to: " + getTimeout());
+            log.trace("EOFException waiting on ACK in readByte().");
+         }
+         throw eof;
+      }
+      catch(IOException e)
+      {
+         log.trace("IOException when reading in ACK", e);
+         throw e;
+      }
+
+      if (trace) { log.trace("acknowledge read byte " + Thread.currentThread()); }
+
+      DataOutputStream out = (DataOutputStream)getOutputStream();
+      out.writeByte(ACK);
+      out.flush();
+   }
+
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: trunk/src/main/org/jboss/jms/tx/AckInfo.java
===================================================================
--- trunk/src/main/org/jboss/jms/tx/AckInfo.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/tx/AckInfo.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -44,10 +44,8 @@
    
    protected long messageID;
    protected int consumerID;
+   protected int deliveryCount;
 
-   // One of Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, etc.
-   private int ackMode;
-   
    protected MessageProxy msg;
    
    // Static --------------------------------------------------------
@@ -60,28 +58,17 @@
 
    public AckInfo(MessageProxy proxy, int consumerID)
    {
-      this(proxy, consumerID, -1);
-   }
-
-   /**
-    * @param ackMode - one of Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, etc.
-    */
-   public AckInfo(MessageProxy proxy, int consumerID, int ackMode)
-   {
       this.msg = proxy;
       this.messageID = proxy.getMessage().getMessageID();
       this.consumerID = consumerID;
-      this.ackMode = ackMode;
    }
    
-   /**
-    * @param ackMode - one of Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE, etc.
-    */
-   public AckInfo(long messageID, int consumerID, int ackMode)
+   //Only used for testing
+   public AckInfo(long messageID, int consumerID, int deliveryCount)
    {
       this.messageID = messageID;
       this.consumerID = consumerID;
-      this.ackMode = ackMode;
+      this.deliveryCount = deliveryCount;
    }
 
    // Public --------------------------------------------------------
@@ -100,15 +87,17 @@
    {
       return msg;
    }
-
-   /**
-    *
-    * @return one of Session.AUTO_ACKNOWLEDGE, Session.CLIENT_ACKNOWLEDGE ..., or -1 if it has not
-    *         previously set
-    */
-   public int getAckMode()
+   
+   public int getDeliveryCount()
    {
-      return ackMode;
+      if (msg == null)
+      {
+         return deliveryCount;
+      }
+      else
+      {
+         return msg.getDeliveryCount();
+      }
    }
 
    public String toString()
@@ -122,12 +111,21 @@
    {
      out.writeLong(messageID);
      out.writeInt(consumerID);
+     if (msg != null)
+     {
+        out.writeInt(msg.getDeliveryCount());
+     }
+     else
+     {
+        out.writeInt(deliveryCount);
+     }
    }
 
    public void read(DataInputStream in) throws Exception
    {
       messageID = in.readLong();
       consumerID = in.readInt();
+      deliveryCount = in.readInt();
    }
    
    // Class YYY overrides -------------------------------------------

Modified: trunk/src/main/org/jboss/jms/tx/ResourceManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/tx/ResourceManager.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/jms/tx/ResourceManager.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -331,6 +331,11 @@
          sess.redeliver(acks);
       }  
    }
+   
+   public int size()
+   {
+      return transactions.size();
+   }
 
    // Protected ------------------------------------------------------
    

Modified: trunk/src/main/org/jboss/messaging/core/ChannelSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/ChannelSupport.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/messaging/core/ChannelSupport.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -555,8 +555,7 @@
                {
                   // Reference is not expired
 
-                  // Attempt to push the ref to a receiver, so increment the delivery count
-                  ref.incrementDeliveryCount();
+                  // Attempt to push the ref to a receiver
 
                   Delivery del = router.handle(this, ref, null);
 
@@ -564,23 +563,17 @@
                   
                   if (del == null)
                   {
-                     // No receiver, broken receiver or full receiver so we stop delivering; also
-                     // we need to decrement the delivery count, as no real delivery has been actually performed
-
+                     // No receiver, broken receiver or full receiver so we stop delivering
                      if (trace) { log.trace(this + ": no delivery returned for message" + ref + " so no receiver got the message. Delivery is now complete"); }
 
-                     ref.decrementDeliveryCount();
-                     
                      break;
                   }
                   else if (!del.isSelectorAccepted())
                   {
                      // No receiver accepted the message because no selectors matched, so we create
                      // an iterator (if we haven't already created it) to iterate through the refs
-                     // in the channel. No delivery was really performed, so we decrement the delivery count
-
-                     ref.decrementDeliveryCount();
-
+                     // in the channel. No delivery was really performed
+                     
                      if (iter == null)
                      {
                         iter = messageRefs.iterator();
@@ -788,8 +781,8 @@
       if (trace) { log.trace(this + " removed " + d + " from memory:" + removed); }
       
       return removed;
-   }     
-
+   }    
+   
    protected InMemoryCallback getCallback(Transaction tx, boolean synchronous)
    {
       InMemoryCallback callback = (InMemoryCallback) tx.getCallback(this);            
@@ -811,7 +804,9 @@
 
       return callback;
    }
+
    
+   
    protected boolean cancelInternal(Delivery del) throws Exception
    {
       if (trace) { log.trace(this + " cancelling " + del + " in memory"); }
@@ -829,9 +824,17 @@
       }
       else
       {
-         messageRefs.addFirst(del.getReference(), del.getReference().getPriority());
+         MessageReference ref = del.getReference();
          
-         if (trace) { log.trace(this + " added " + del.getReference() + " back into state"); }
+         messageRefs.addFirst(ref, ref.getPriority());
+         
+         //We may need to update the delivery count in the database
+         if (ref.isReliable())
+         {
+            pm.updateDeliveryCount(this.channelID, ref);
+         }
+         
+         if (trace) { log.trace(this + " added " + ref + " back into state"); }
       }
       
       return removed;

Modified: trunk/src/main/org/jboss/messaging/core/Routable.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/Routable.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/messaging/core/Routable.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -83,23 +83,12 @@
    void setPriority(byte priority);
 
    /**
-    * @return true if the delivery of this message had to be repeated at least once.
-    */
-   boolean isRedelivered();
-
-   void setRedelivered(boolean redelivered);
-   
-   /**
     * @return the number of times delivery has been attempted for this routable
     */
    int getDeliveryCount();
    
    void setDeliveryCount(int deliveryCount);
    
-   void incrementDeliveryCount();
-   
-   void decrementDeliveryCount();
-   
    /**
     * Binds a header. If the header map previously contained a mapping for this name, the old value
     * is replaced by the specified value.

Modified: trunk/src/main/org/jboss/messaging/core/message/RoutableSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/RoutableSupport.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/messaging/core/message/RoutableSupport.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -57,7 +57,6 @@
    protected long expiration;
    protected long timestamp;
    protected Map headers;
-   protected boolean redelivered;
    protected byte priority;
    protected int deliveryCount;   
 
@@ -111,7 +110,6 @@
       this.timestamp = timestamp;
       this.priority = priority;
       this.deliveryCount = deliveryCount;
-      this.redelivered = deliveryCount >= 2;
       if (headers == null)
       {
          this.headers = new HashMap();
@@ -129,7 +127,6 @@
       this.expiration = other.expiration;
       this.timestamp = other.timestamp;
       this.headers = new HashMap(other.headers);
-      this.redelivered = other.redelivered;
       this.deliveryCount = other.deliveryCount;
       this.priority = other.priority;  
    }
@@ -155,17 +152,7 @@
    {
       return timestamp;
    }
-
-   public boolean isRedelivered()
-   {
-      return redelivered;
-   }
-
-   public void setRedelivered(boolean redelivered)
-   {
-      this.redelivered = redelivered;      
-   }
-   
+ 
    public void setReliable(boolean reliable)
    {
       this.reliable = reliable;
@@ -189,10 +176,6 @@
    public void setDeliveryCount(int deliveryCount)
    {
       this.deliveryCount = deliveryCount;
-      if (deliveryCount > 0)
-      {
-         this.redelivered = true;
-      }
    }
 
    public Serializable putHeader(String name, Serializable value)
@@ -244,7 +227,7 @@
       out.writeLong(expiration);
       out.writeLong(timestamp);
       StreamUtils.writeMap(out, headers, true);
-      out.writeBoolean(redelivered);
+    //  out.writeBoolean(redelivered);
       out.writeByte(priority);
       out.writeInt(deliveryCount);
    }
@@ -264,7 +247,7 @@
       {
          headers = (HashMap)m;
       }
-      redelivered = in.readBoolean();
+     // redelivered = in.readBoolean();
       priority = in.readByte();
       deliveryCount = in.readInt();
    }

Modified: trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/messaging/core/plugin/JDBCPersistenceManager.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -82,7 +82,7 @@
    // Constants -----------------------------------------------------
    
    private static final Logger log = Logger.getLogger(JDBCPersistenceManager.class); 
-   
+
    // Static --------------------------------------------------------
    
    // Attributes ----------------------------------------------------
@@ -1402,6 +1402,57 @@
       }
    }
    
+   public void updateDeliveryCount(long channelID, MessageReference ref) throws Exception
+   {
+      TransactionWrapper wrap = new TransactionWrapper();
+      
+      PreparedStatement psReference = null;
+      
+      Connection conn = ds.getConnection();
+       
+      try
+      {                                    
+         psReference = conn.prepareStatement(getSQLStatement("UPDATE_DELIVERYCOUNT"));
+         
+         psReference.setInt(1, ref.getDeliveryCount());
+         
+         psReference.setLong(2, channelID);
+         
+         psReference.setLong(3, ref.getMessageID());
+         
+         int rows = psReference.executeUpdate();                         
+      }
+      catch (Exception e)
+      {
+         wrap.exceptionOccurred();
+         throw e;
+      }
+      finally
+      {
+         if (psReference != null)
+         {
+            try
+            {
+               psReference.close();
+            }
+            catch (Throwable t)
+            {
+            }
+         }         
+         if (conn != null)
+         {
+            try
+            {
+               conn.close();
+            }
+            catch (Throwable t)
+            {
+            }
+         }
+         wrap.end();                        
+      }  
+   }
+   
    public void removeReference(long channelID, MessageReference ref, Transaction tx) throws Exception
    {      
       if (tx != null)
@@ -1668,7 +1719,7 @@
    public String toString()
    {
       return "JDBCPersistenceManager[" + Integer.toHexString(hashCode()) + "]";
-   }
+   }   
    
    // Package protected ---------------------------------------------
    
@@ -3229,6 +3280,7 @@
       map.put("UPDATE_RELIABLE_REFS_NOT_PAGED", "UPDATE JMS_MESSAGE_REFERENCE SET PAGE_ORD = NULL WHERE PAGE_ORD BETWEEN ? AND ? AND CHANNELID=?");       
       map.put("SELECT_MIN_MAX_PAGE_ORD", "SELECT MIN(PAGE_ORD), MAX(PAGE_ORD) FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID = ?");
       map.put("SELECT_EXISTS_REF", "SELECT MESSAGEID FROM JMS_MESSAGE_REFERENCE WHERE CHANNELID = ? AND MESSAGEID = ?");
+      map.put("UPDATE_DELIVERYCOUNT", "UPDATE JMS_MESSAGE_REFERENCE SET DELIVERYCOUNT = ? WHERE CHANNELID = ? AND MESSAGEID = ?");
       //Message
       map.put("LOAD_MESSAGES",
               "SELECT MESSAGEID, RELIABLE, EXPIRATION, TIMESTAMP, " +

Modified: trunk/src/main/org/jboss/messaging/core/plugin/SimpleMessageReference.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/SimpleMessageReference.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/messaging/core/plugin/SimpleMessageReference.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -74,7 +74,7 @@
    {
       this(holder.getMessage().getMessageID(), holder.getMessage().isReliable(),
            holder.getMessage().getExpiration(), holder.getMessage().getTimestamp(),
-           holder.getMessage().getHeaders(), holder.getMessage().isRedelivered(),
+           holder.getMessage().getHeaders(), holder.getMessage().getDeliveryCount(),
            holder.getMessage().getPriority(), ms);
 
       this.holder = holder;
@@ -88,7 +88,7 @@
    public SimpleMessageReference(SimpleMessageReference other)
    {
       this(other.getMessageID(), other.isReliable(), other.getExpiration(),
-           other.getTimestamp(), other.getHeaders(), other.isRedelivered(),
+           other.getTimestamp(), other.getHeaders(), other.getDeliveryCount(),
            other.getPriority(), other.ms);
       
       this.headers = other.headers;
@@ -96,11 +96,11 @@
    }
    
    protected SimpleMessageReference(long messageID, boolean reliable, long expiration,
-                                    long timestamp, Map headers, boolean redelivered,
+                                    long timestamp, Map headers, int deliveryCount,
                                     byte priority, MessageStore ms)
    {
       super(messageID, reliable, expiration, timestamp, priority, 0, headers);
-      this.redelivered = redelivered;
+      this.deliveryCount = deliveryCount;
       this.ms = ms;
    }
 

Modified: trunk/src/main/org/jboss/messaging/core/plugin/contract/PersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/contract/PersistenceManager.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/messaging/core/plugin/contract/PersistenceManager.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -40,13 +40,16 @@
    void addReference(long channelID, MessageReference ref, Transaction tx) throws Exception;
 
    void removeReference(long channelID, MessageReference ref, Transaction tx) throws Exception;
-    
+   
+   void updateDeliveryCount(long channelID, MessageReference ref) throws Exception;
+   
+
    // XA Recovery functionality
    
    List retrievePreparedTransactions() throws Exception;
       
    // Paging functionality - TODO we should split this out into its own interface
-   
+
    void pageReferences(long channelID, List references, boolean paged) throws Exception;
    
    void removeDepagedReferences(long channelID, List refs) throws Exception;

Modified: trunk/src/main/org/jboss/messaging/core/tx/TransactionRepository.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/tx/TransactionRepository.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/src/main/org/jboss/messaging/core/tx/TransactionRepository.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -90,10 +90,13 @@
    public List getPreparedTransactions()
    {
       ArrayList prepared = new ArrayList();
+      
       Iterator iter = globalToLocalMap.values().iterator();
+      
       while (iter.hasNext())
       {
          Transaction tx = (Transaction)iter.next();
+         
          if (tx.xid != null && tx.getState() == Transaction.STATE_PREPARED)
          {
             prepared.add(tx.getXid());
@@ -118,7 +121,9 @@
          while (iter.hasNext())
          {
             Xid xid = (Xid)iter.next();
-            Transaction tx = createTransaction(xid);            
+            
+            Transaction tx = createTransaction(xid);   
+            
             tx.state = Transaction.STATE_PREPARED;
             
             //Load the references for this transaction
@@ -145,20 +150,17 @@
 	   final Xid id = transaction.getXid();
 	   final int state = transaction.getState();
 	   
-	   if (id==null)
+	   if (id == null)
 	   {
-		   Exception ex = new Exception();
-		   log.warn("DeleteTransaction was called for non XA transaction",ex);
-		   return;
+		   throw new IllegalArgumentException("DeleteTransaction was called for non XA transaction");
 	   }
 
-	   if (state!=Transaction.STATE_COMMITTED && state!=Transaction.STATE_ROLLEDBACK)
+	   if (state != Transaction.STATE_COMMITTED && state != Transaction.STATE_ROLLEDBACK)
 	   {
 		   throw new TransactionException("Transaction with xid " + id + " can't be removed as it's not yet commited or rolledback: (Current state is " + Transaction.stateToString(state));
 	   }
 	   
-	   globalToLocalMap.remove(id);
-	   
+	   globalToLocalMap.remove(id);	   
    }
    
    public Transaction createTransaction(Xid xid) throws Exception

Modified: trunk/tests/bin/runtest
===================================================================
--- trunk/tests/bin/runtest	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/bin/runtest	2006-11-27 10:28:46 UTC (rev 1639)
@@ -44,6 +44,8 @@
    TEST_REMOTING=$ENV_TEST_REMOTING
 fi
 
+TEST_REMOTING=http
+
 #
 # We should use the same test execution classpath as the ant <junit> task, so we run ant to get
 # it from there.

Modified: trunk/tests/build.xml
===================================================================
--- trunk/tests/build.xml	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/build.xml	2006-11-27 10:28:46 UTC (rev 1639)
@@ -342,7 +342,7 @@
       <antcall target="remote-tests"/>  <!-- default remoting configuration (socket) -->
       <antcall target="remote-tests">
          <param name="test.remoting" value="http"/>
-      </antcall>                                                                         
+      </antcall>
    </target>
 
    <target name="stress-tests" depends="tests-jar, prepare-testdirs, clear-test-logs">
@@ -872,7 +872,7 @@
       <!--
           CallbackFailureTest over "http" does not make sense
       -->
-                                                                                                 
+
    </target>
 
 

Modified: trunk/tests/src/org/jboss/test/messaging/core/plugin/JDBCPersistenceManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/JDBCPersistenceManagerTest.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/JDBCPersistenceManagerTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -884,7 +884,7 @@
       assertEquals(m1.isExpired(), m2.isExpired());
       assertEquals(m1.getTimestamp(), m2.getTimestamp());
       assertEquals(m1.getPriority(), m2.getPriority());
-      assertEquals(m1.isRedelivered(), m2.isRedelivered());
+      assertEquals(m1.getDeliveryCount(), m2.getDeliveryCount());
       Map m1Headers = m1.getHeaders();
       Map m2Headers = m2.getHeaders();
       checkMapsEquivalent(m1Headers, m2Headers);

Modified: trunk/tests/src/org/jboss/test/messaging/core/plugin/base/MessageStoreTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/base/MessageStoreTestBase.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/base/MessageStoreTestBase.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -72,7 +72,7 @@
       assertEquals(m.getExpiration(), ref.getExpiration());
       assertEquals(m.getTimestamp(), ref.getTimestamp());
       assertEquals(m.getPriority(), ref.getPriority());
-      assertFalse(ref.isRedelivered());
+      assertEquals(0, ref.getDeliveryCount());
 
       Map messageHeaders = m.getHeaders();
       Map refHeaders = ref.getHeaders();

Modified: trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -158,14 +158,20 @@
          pub.publish(m);
          sess.commit();
          
+         log.info("sent messages");
+         
          //receive but rollback
          TextMessage m2 = (TextMessage)sub.receive(3000);
+         
+         log.info("received");
             
          assertNotNull(m2);
          assertEquals("testing123", m2.getText());
          
          sess.rollback();
          
+         log.info("rolled back");
+         
          conn.close();
          conn = cf.createTopicConnection();
          conn.start();

Modified: trunk/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -266,6 +266,8 @@
                "<attribute name=\"timeout\">0</attribute>\n" +
                "<attribute name=\"serverBindAddress\">localhost</attribute>\n" +
                "<attribute name=\"leasePeriod\">20000</attribute>\n" +  
+               "<attribute name=\"clientSocketClass\" isParam=\"true\">org.jboss.jms.client.remoting.ClientSocketWrapper</attribute>\n" +
+               "<attribute name=\"serverSocketClass\">org.jboss.jms.server.remoting.ServerSocketWrapper</attribute>\n" +
             "</invoker>\n" +
             "<handlers>\n" +
                "<handler subsystem=\"JMS\">org.jboss.jms.server.remoting.JMSServerInvocationHandler</handler>\n" +

Copied: trunk/tests/src/org/jboss/test/messaging/jms/DLQTest.java (from rev 1631, branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/DLQTest.java)
===================================================================
--- branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/DLQTest.java	2006-11-23 06:51:36 UTC (rev 1631)
+++ trunk/tests/src/org/jboss/test/messaging/jms/DLQTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -0,0 +1,450 @@
+/*
+ * 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.test.messaging.jms;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.jms.destination.JBossQueue;
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+/**
+ * A DLQTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public class DLQTest extends MessagingTestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   protected InitialContext ic;
+   protected ConnectionFactory cf;
+   protected Queue queue;
+
+   // Constructors --------------------------------------------------
+
+   public DLQTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+
+   public void testDLQAlreadyDeployed() throws Exception
+   {
+      if (ServerManagement.isRemote())
+      {
+         //This test can only run in local mode
+         return;
+      }
+
+      ServerManagement.deployQueue("DLQ");
+
+      org.jboss.messaging.core.Queue dlq = ServerManagement.getServer().getServerPeer().getDLQ();
+
+      assertNotNull(dlq);
+
+      InitialContext ic = null;
+
+      try
+      {
+         ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+
+         JBossQueue q = (JBossQueue)ic.lookup("/queue/DLQ");
+
+         assertNotNull(q);
+
+         assertEquals("DLQ", q.getName());
+      }
+      finally
+      {
+         if (ic != null) ic.close();
+
+         log.info("undeploying dlq");
+         ServerManagement.undeployQueue("DLQ");
+         log.info("undeployed dlq");
+      }
+   }
+
+   public void testDLQNotAlreadyDeployed() throws Exception
+   {
+      if (ServerManagement.isRemote())
+      {
+         //This test can only run in local mode
+         return;
+      }
+
+      org.jboss.messaging.core.Queue dlq = ServerManagement.getServer().getServerPeer().getDLQ();
+
+      assertNull(dlq);
+
+      InitialContext ic = null;
+
+      try
+      {
+         ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+
+         try
+         {
+            ic.lookup("/queue/DLQ");
+
+            fail();
+         }
+         catch (NameNotFoundException e)
+         {
+            //Ok
+         }
+      }
+      finally
+      {
+         if (ic != null) ic.close();
+      }
+   }
+//
+//   public void testSendToDLQWithMessageListenerPersistent() throws Exception
+//   {
+//      sendToDLQWithMessageListener(true);
+//   }
+//
+//   public void testSendToDLQWithMessageListenerNonPersistent() throws Exception
+//   {
+//      sendToDLQWithMessageListener(false);
+//   }
+//
+//   public void testSendToDLQWithReceivePersistent() throws Exception
+//   {
+//      sendToDLQWithReceive(true);
+//   }
+//
+//   public void testSendToDLQWithReceiveNonPersistent() throws Exception
+//   {
+//      sendToDLQWithReceive(false);
+//   }
+//
+//   public void testSendToDLQWithReceivePartialPersistent() throws Exception
+//   {
+//      sendToDLQWithReceivePartial(true);
+//   }
+//
+//   public void testSendToDLQWithReceivePartialNonPersistent() throws Exception
+//   {
+//      sendToDLQWithReceivePartial(false);
+//   }
+//
+//   public void sendToDLQWithMessageListener(boolean persistent) throws Exception
+//   {
+//      Connection conn = null;
+//
+//      ServerManagement.deployQueue("DLQ");
+//
+//      Queue dlq = (Queue)ic.lookup("/queue/DLQ");
+//
+//      try
+//      {
+//         conn = cf.createConnection();
+//
+//         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//         MessageProducer prod = sess.createProducer(queue);
+//
+//         prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+//
+//         for (int i = 0; i < 10; i++)
+//         {
+//            TextMessage tm = sess.createTextMessage("Message:" + i);
+//
+//            prod.send(tm);
+//         }
+//
+//         MessageConsumer cons = sess.createConsumer(queue);
+//
+//         cons.setMessageListener(new FailingMessageListener());
+//
+//         conn.start();
+//
+//         Thread.sleep(4000);
+//
+//         cons.setMessageListener(null);
+//
+//         Message m = cons.receive(1000);
+//
+//         assertNull(m);
+//
+//         //Message should all be in the dlq - let's check
+//
+//         MessageConsumer cons2 = sess.createConsumer(dlq);
+//
+//         for (int i = 0; i < 10; i++)
+//         {
+//            TextMessage tm = (TextMessage)cons2.receive(1000);
+//
+//            assertNotNull(tm);
+//
+//            assertEquals("Message:" + i, tm.getText());
+//         }
+//
+//      }
+//      finally
+//      {
+//         ServerManagement.undeployQueue("DLQ");
+//
+//         if (conn != null) conn.close();
+//      }
+//   }
+//
+//   public void sendToDLQWithReceive(boolean persistent) throws Exception
+//   {
+//      Connection conn = null;
+//
+//      ServerManagement.deployQueue("DLQ");
+//
+//      Queue dlq = (Queue)ic.lookup("/queue/DLQ");
+//
+//      try
+//      {
+//         conn = cf.createConnection();
+//
+//         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//         MessageProducer prod = sess.createProducer(queue);
+//
+//         prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+//
+//         for (int i = 0; i < 10; i++)
+//         {
+//            TextMessage tm = sess.createTextMessage("Message:" + i);
+//
+//            prod.send(tm);
+//         }
+//
+//         Session sess2 = conn.createSession(true, Session.SESSION_TRANSACTED);
+//
+//         MessageConsumer cons = sess2.createConsumer(queue);
+//
+//         conn.start();
+//
+//         for (int i = 0; i < 10; i++)  // retries - default is 10
+//         {
+//            for (int j = 0; j < 10; j++)
+//            {
+//               TextMessage tm = (TextMessage)cons.receive(1000);
+//
+//               assertNotNull(tm);
+//
+//               assertEquals("Message:" + j, tm.getText());
+//            }
+//
+//            //rollback should cause redelivery
+//            sess2.rollback();
+//         }
+//
+//         cons.close();
+//
+//         MessageConsumer cons2 = sess2.createConsumer(queue);
+//
+//         Message m = cons2.receive(1000);
+//
+//         assertNull(m);
+//
+//         //Message should all be in the dlq - let's check
+//
+//         MessageConsumer cons3 = sess.createConsumer(dlq);
+//
+//         for (int i = 0; i < 10; i++)
+//         {
+//            TextMessage tm = (TextMessage)cons3.receive(1000);
+//
+//            assertNotNull(tm);
+//
+//            assertEquals("Message:" + i, tm.getText());
+//         }
+//
+//      }
+//      finally
+//      {
+//         ServerManagement.undeployQueue("DLQ");
+//
+//         if (conn != null) conn.close();
+//      }
+//   }
+//
+//   public void sendToDLQWithReceivePartial(boolean persistent) throws Exception
+//   {
+//      Connection conn = null;
+//
+//      ServerManagement.deployQueue("DLQ");
+//
+//      Queue dlq = (Queue)ic.lookup("/queue/DLQ");
+//
+//      try
+//      {
+//         conn = cf.createConnection();
+//
+//         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//         MessageProducer prod = sess.createProducer(queue);
+//
+//         prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
+//
+//         for (int i = 0; i < 10; i++)
+//         {
+//            TextMessage tm = sess.createTextMessage("Message:" + i);
+//
+//            prod.send(tm);
+//         }
+//
+//         Session sess2 = conn.createSession(true, Session.SESSION_TRANSACTED);
+//
+//         MessageConsumer cons = sess2.createConsumer(queue);
+//
+//         conn.start();
+//
+//         for (int i = 0; i < 5; i++)  // retries - default is 10
+//         {
+//            for (int j = 0; j < 10; j++)
+//            {
+//               TextMessage tm = (TextMessage)cons.receive(1000);
+//
+//               assertNotNull(tm);
+//
+//               assertEquals("Message:" + j, tm.getText());
+//            }
+//
+//            //rollback should cause redelivery
+//            sess2.rollback();
+//         }
+//
+//         //They should now be cancelled back to the server
+//         cons.close();
+//
+//         cons = sess2.createConsumer(queue);
+//
+//         for (int i = 0; i < 5; i++)  // retries - default is 10
+//         {
+//            for (int j = 0; j < 10; j++)
+//            {
+//               TextMessage tm = (TextMessage)cons.receive(1000);
+//
+//               assertNotNull(tm);
+//
+//               assertEquals("Message:" + j, tm.getText());
+//            }
+//
+//            //rollback should cause redelivery
+//            sess2.rollback();
+//         }
+//
+//         cons.close();
+//
+//         //Now they should be in DLQ
+//
+//         MessageConsumer cons2 = sess2.createConsumer(queue);
+//
+//         Message m = cons2.receive(1000);
+//
+//         assertNull(m);
+//
+//         //Message should all be in the dlq - let's check
+//
+//         MessageConsumer cons3 = sess.createConsumer(dlq);
+//
+//         for (int i = 0; i < 10; i++)
+//         {
+//            TextMessage tm = (TextMessage)cons3.receive(1000);
+//
+//            assertNotNull(tm);
+//
+//            assertEquals("Message:" + i, tm.getText());
+//         }
+//
+//      }
+//      finally
+//      {
+//         ServerManagement.undeployQueue("DLQ");
+//
+//         if (conn != null) conn.close();
+//      }
+//   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      ServerManagement.start("all");
+
+      ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+
+      cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+
+      ServerManagement.deployQueue("Queue");
+
+      queue = (Queue)ic.lookup("/queue/Queue");
+
+   }
+
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+
+      ServerManagement.undeployQueue("Queue");
+
+      if (ic != null) ic.close();
+   }
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+   
+   class FailingMessageListener implements MessageListener
+   {
+
+      public void onMessage(Message msg)
+      {
+         throw new RuntimeException("Your mum!");
+      }
+      
+   }
+
+}

Modified: trunk/tests/src/org/jboss/test/messaging/jms/JMSTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/JMSTest.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/jms/JMSTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -24,18 +24,19 @@
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.DeliveryMode;
+import javax.jms.Message;
 import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
 import javax.jms.Session;
 import javax.jms.TextMessage;
-import javax.jms.Message;
-import javax.jms.MessageListener;
+import javax.management.ObjectName;
 import javax.naming.InitialContext;
-import javax.management.ObjectName;
 
 import org.jboss.test.messaging.MessagingTestCase;
 import org.jboss.test.messaging.tools.ServerManagement;
+
 import EDU.oswego.cs.dl.util.concurrent.Slot;
 
 /**
@@ -86,7 +87,7 @@
 
       super.tearDown();
    }
-
+   
    public void test_NonPersistent_NonTransactional() throws Exception
    {
       ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");

Modified: trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -3026,14 +3026,12 @@
       //don't acknowledge it
       sess1.close();
 
-      log.debug("sess1 closed");
-
       Session sess2 = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
       MessageConsumer cons2 = sess2.createConsumer(queue);
       TextMessage tm3 = (TextMessage)cons2.receive(3000);
       assertNotNull(tm3);
       assertEquals("testRedeliveredDifferentSessions", tm3.getText());
-
+      
       assertTrue(tm3.getJMSRedelivered());
    }
 

Modified: trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -37,8 +37,8 @@
 import javax.jms.TopicSession;
 import javax.jms.XAConnection;
 import javax.jms.XASession;
+import javax.management.ObjectName;
 import javax.naming.InitialContext;
-import javax.management.ObjectName;
 
 import org.jboss.jms.client.JBossConnectionFactory;
 import org.jboss.jms.client.JBossSession;
@@ -143,6 +143,7 @@
       
       conn.close();
       
+      assertEquals(0, cState.getResourceManager().size());
    }
 
    public void testCreateProducer() throws Exception
@@ -535,7 +536,7 @@
       conn.start();
       TextMessage rm = (TextMessage)s.createConsumer(queue).receive(1000);
 
-      assertEquals("bex", m.getText());
+      assertEquals("bex", rm.getText());
 
       conn.close();
    }

Modified: trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -28,8 +28,8 @@
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TextMessage;
-import javax.naming.InitialContext;
 import javax.management.ObjectName;
+import javax.naming.InitialContext;
 
 import org.jboss.jms.client.JBossConnectionFactory;
 import org.jboss.test.messaging.MessagingTestCase;
@@ -589,11 +589,10 @@
          tm = (TextMessage)cons.receive();
 
          assertEquals("a message", tm.getText());
-         
-         log.info("del count2:" + tm.getIntProperty("JMSXDeliveryCount"));
+ 
+         assertEquals(2, tm.getIntProperty("JMSXDeliveryCount"));
 
          assertTrue(tm.getJMSRedelivered());
-         assertEquals(2, tm.getIntProperty("JMSXDeliveryCount"));
       }
       finally
       {

Modified: trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -26,7 +26,8 @@
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.EOFException;
-import java.io.ObjectInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.Serializable;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -45,8 +46,6 @@
 import org.jboss.jms.server.endpoint.ClientDelivery;
 import org.jboss.jms.server.remoting.JMSWireFormat;
 import org.jboss.jms.server.remoting.MessagingMarshallable;
-import org.jboss.jms.server.remoting.MessagingObjectInputStream;
-import org.jboss.jms.server.remoting.MessagingObjectOutputStream;
 import org.jboss.jms.tx.AckInfo;
 import org.jboss.jms.tx.TransactionRequest;
 import org.jboss.jms.tx.TxState;
@@ -266,7 +265,8 @@
          
          long messageID = 123456;
          int consumerID = 65432;
-         AckInfo ack = new AckInfo(messageID, consumerID, -1);
+         int deliveryCount = 765;
+         AckInfo ack = new AckInfo(messageID, consumerID, deliveryCount);
          
          Object[] args = new Object[] { ack };
          
@@ -278,7 +278,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
                   
          wf.write(ir, oos);
          
@@ -311,6 +311,7 @@
          
          assertEquals(ack.getMessageID(), ack2.getMessageID());
          assertEquals(ack.getConsumerID(), ack2.getConsumerID());
+         assertEquals(ack.getDeliveryCount(), ack2.getDeliveryCount());
          
          //Now eos
          try
@@ -325,7 +326,7 @@
          
          bis.reset();
          
-         ObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
          
          InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
          
@@ -356,9 +357,9 @@
          
          mi.getMetaData().addMetaData(Dispatcher.DISPATCHER, Dispatcher.OID, new Integer(objectId));   
          
-         AckInfo ackA = new AckInfo(1524, 71627, -1);
-         AckInfo ackB = new AckInfo(987987, 45354, -1);
-         AckInfo ackC = new AckInfo(32423, 4533, -1);
+         AckInfo ackA = new AckInfo(1524, 71627, 32);
+         AckInfo ackB = new AckInfo(987987, 45354, 21);
+         AckInfo ackC = new AckInfo(32423, 4533, 6);
          
          List acks = new ArrayList();
          acks.add(ackA);
@@ -375,7 +376,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
       
          wf.write(ir, oos);
          
@@ -411,6 +412,7 @@
          
          assertEquals(ackA.getMessageID(), ack.getMessageID());
          assertEquals(ackA.getConsumerID(), ack.getConsumerID());
+         assertEquals(ackA.getDeliveryCount(), ack.getDeliveryCount());
          
          ack = new AckInfo();
          
@@ -418,6 +420,7 @@
          
          assertEquals(ackB.getMessageID(), ack.getMessageID());
          assertEquals(ackB.getConsumerID(), ack.getConsumerID());
+         assertEquals(ackB.getDeliveryCount(), ack.getDeliveryCount());
          
          ack = new AckInfo();
          
@@ -425,6 +428,7 @@
          
          assertEquals(ackC.getMessageID(), ack.getMessageID());
          assertEquals(ackC.getConsumerID(), ack.getConsumerID());
+         assertEquals(ackC.getDeliveryCount(), ack.getDeliveryCount());
          
          
          //Now eos
@@ -440,7 +444,7 @@
          
          bis.reset();
          
-         ObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
          
          InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
          
@@ -498,7 +502,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
          
          wf.write(ir, oos);
          
@@ -517,7 +521,7 @@
          
          bis.reset();
          
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
                                  
          InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
          
@@ -559,7 +563,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
          
          wf.write(ir, oos);
          
@@ -576,7 +580,7 @@
          
          bis.reset();
          
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
             
          InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
          
@@ -603,7 +607,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
          
          wf.write(ir, oos);
          
@@ -620,7 +624,7 @@
          
          bis.reset();
          
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
                   
          InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
          
@@ -658,7 +662,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
                   
          wf.write(ir, oos);
          
@@ -709,8 +713,9 @@
          MessageTest.ensureEquivalent(m, m2);
          
          bis.reset();
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
          
+         InputStream ois = new DataInputStream(bis);
+         
          InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
          
          mm = (MessagingMarshallable)ir2.getParameter();
@@ -734,7 +739,7 @@
          JBossMessage m = new JBossMessage(123);
          MessageTest.configureMessage(m);
          
-         AckInfo info = new AckInfo(123, 456, -1);
+         AckInfo info = new AckInfo(123, 456, 66);
          
          TxState state = new TxState();
          state.getMessages().add(m);
@@ -758,7 +763,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
                   
          wf.write(ir, oos);
         
@@ -812,10 +817,11 @@
          
          assertEquals(info.getConsumerID(), info2.getConsumerID());
          assertEquals(info.getMessageID(), info2.getMessageID());
+         assertEquals(info.getDeliveryCount(), info2.getDeliveryCount());
          
          bis.reset();
          
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
          
          InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
          
@@ -853,8 +859,8 @@
          
          List ids = new ArrayList();
          
-         AckInfo ack1 = new AckInfo(1254, 78123, -1);
-         AckInfo ack2 = new AckInfo(786, 8979, -1);
+         AckInfo ack1 = new AckInfo(1254, 78123, 22);
+         AckInfo ack2 = new AckInfo(786, 8979, 461);
          ids.add(ack1);
          ids.add(ack2);
          
@@ -870,7 +876,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
                   
          wf.write(ir, oos);
         
@@ -915,9 +921,14 @@
          
          assertEquals(ack1.getMessageID(), rack1.getMessageID());
          
+         assertEquals(ack1.getDeliveryCount(), rack1.getDeliveryCount());
+         
          assertEquals(ack2.getConsumerID(), rack2.getConsumerID());
          
          assertEquals(ack2.getMessageID(), rack2.getMessageID());
+         
+         assertEquals(ack2.getDeliveryCount(), rack2.getDeliveryCount());
+         
           
          //should be eos
                 
@@ -934,7 +945,7 @@
          
          bis.reset();
          
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
          
          InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
          
@@ -970,7 +981,7 @@
          InvocationResponse resp = new InvocationResponse(null, mm, false, null);
 
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
          
          wf.write(resp, oos);
          oos.flush();
@@ -1000,7 +1011,7 @@
          
          bis.reset();
 
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
 
          InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
          
@@ -1030,7 +1041,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
                   
          wf.write(ir, oos);
          
@@ -1068,7 +1079,7 @@
          }
          
          bis.reset();
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
          
          InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
          
@@ -1113,7 +1124,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
          
          MessagingMarshallable mm = new MessagingMarshallable((byte)77, dr);
          
@@ -1201,7 +1212,7 @@
          
          bis.reset();
          
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
          
          InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
          
@@ -1252,7 +1263,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
          
          wf.write(ir, oos);
          
@@ -1289,7 +1300,7 @@
          
          bis.reset();
          
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
          
          InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
          
@@ -1313,7 +1324,7 @@
          
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          
-         MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
+         OutputStream oos = new DataOutputStream(bos);
          
          wf.write(ir, oos);
          
@@ -1350,7 +1361,7 @@
          
          bis.reset();
          
-         MessagingObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
+         InputStream ois = new DataInputStream(bis);
          
          InvocationResponse ir2 = (InvocationResponse)wf.read(ois, null);
          

Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -93,7 +93,7 @@
       super.tearDown();
    }
 
-   public void testSimpleJMSXDeliverCount() throws Exception
+   public void testSimpleJMSXDeliveryCount() throws Exception
    {
       Connection conn = cf.createConnection();
       Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java	2006-11-25 19:52:47 UTC (rev 1638)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java	2006-11-27 10:28:46 UTC (rev 1639)
@@ -189,7 +189,7 @@
 
    private List toUnbindAtExit;
    private String ipAddressOrHostName;
-   
+
    // There may be many service containers on the same machine, so we need to distinguish them
    // so we don't start up multiple servers with services running on the same port
    private int serverIndex;
@@ -256,7 +256,7 @@
    {
       this(servicesToStart, null);
    }
-   
+
    public ServiceContainer(String sevicesToStart, int serverIndex) throws Exception
    {
       this(sevicesToStart, null, serverIndex);
@@ -277,7 +277,7 @@
       toUnbindAtExit = new ArrayList();
       this.serverIndex = 0;
    }
-   
+
    public ServiceContainer(String sevicesToStart, TransactionManager tm, int serverIndex) throws Exception
    {
       this.tm = tm;
@@ -366,12 +366,12 @@
                                    DEFAULTDS_MANAGED_CONNECTION_POOL_OBJECT_NAME);
             startWrapperDataSourceService();
          }
-         
+
          if (remoting)
          {
             startRemoting();
          }
-         
+
          if (security)
          {
             startSecurityManager();
@@ -397,7 +397,7 @@
          String transport = config.getRemotingTransport();
          log.info("remoting = \"" +
             (remoting ? transport : "disabled") + "\", " +
-            "serialization = \"" + config.getSerializationType() + "\", " + 
+            "serialization = \"" + config.getSerializationType() + "\", " +
             "database = \"" + getDatabaseType() + "\"");
          log.debug(this + " started");
       }
@@ -492,37 +492,37 @@
    {
       return mbeanServer.invoke(on, "getInstance", new Object[0], new String[0]);
    }
-   
+
    public Properties getPersistenceManagerSQLProperties() throws Exception
    {
       String databaseType = getDatabaseType();
-      
+
       String persistenceConfigFile =
          "server/default/deploy/" + databaseType + "-persistence-service.xml";
-      
+
       log.info("********* Using config file: " + persistenceConfigFile);
-      
+
       URL persistenceConfigFileURL = getClass().getClassLoader().getResource(persistenceConfigFile);
       if (persistenceConfigFileURL == null)
       {
          throw new Exception("Cannot find " + persistenceConfigFile + " in the classpath");
       }
-      
+
       ServiceDeploymentDescriptor pdd = new ServiceDeploymentDescriptor(persistenceConfigFileURL);
-      
+
       MBeanConfigurationElement persistenceManagerConfig =
          (MBeanConfigurationElement)pdd.query("service", "PersistenceManager").iterator().next();
-      
+
       String props = persistenceManagerConfig.getAttributeValue("SqlProperties");
-      
+
       if (props != null)
-      {         
+      {
          ByteArrayInputStream is = new ByteArrayInputStream(props.getBytes());
-         
+
          Properties sqlProperties = new Properties();
-         
-         sqlProperties.load(is);      
-         
+
+         sqlProperties.load(is);
+
          return sqlProperties;
       }
       else
@@ -530,37 +530,37 @@
          return null;
       }
    }
-   
+
    public Properties getPostOfficeSQLProperties() throws Exception
    {
       String databaseType = getDatabaseType();
-      
+
       String persistenceConfigFile =
          "server/default/deploy/" + databaseType + "-persistence-service.xml";
-      
+
       log.info("********* Using config file: " + persistenceConfigFile);
-      
+
       URL persistenceConfigFileURL = getClass().getClassLoader().getResource(persistenceConfigFile);
       if (persistenceConfigFileURL == null)
       {
          throw new Exception("Cannot find " + persistenceConfigFile + " in the classpath");
       }
-      
+
       ServiceDeploymentDescriptor pdd = new ServiceDeploymentDescriptor(persistenceConfigFileURL);
-      
+
       MBeanConfigurationElement postOfficeConfig =
          (MBeanConfigurationElement)pdd.query("service", "QueuePostOffice").iterator().next();
-      
+
       String props = postOfficeConfig.getAttributeValue("SqlProperties");
-      
+
       if (props != null)
-      {         
+      {
          ByteArrayInputStream is = new ByteArrayInputStream(props.getBytes());
-         
+
          Properties sqlProperties = new Properties();
-         
-         sqlProperties.load(is);      
-         
+
+         sqlProperties.load(is);
+
          return sqlProperties;
       }
       else
@@ -568,11 +568,11 @@
          return null;
       }
    }
-   
+
    public Properties getClusteredPostOfficeSQLProperties() throws Exception
    {
       String databaseType = getDatabaseType();
-      
+
       String persistenceConfigFile;
       if (databaseType.equals("hsqldb"))
       {
@@ -584,30 +584,30 @@
          persistenceConfigFile =
             "server/default/deploy/clustered-" + databaseType + "-persistence-service.xml";
       }
-      
+
       log.info("********* Using config file: " + persistenceConfigFile);
-      
+
       URL persistenceConfigFileURL = getClass().getClassLoader().getResource(persistenceConfigFile);
       if (persistenceConfigFileURL == null)
       {
          throw new Exception("Cannot find " + persistenceConfigFile + " in the classpath");
       }
-      
+
       ServiceDeploymentDescriptor pdd = new ServiceDeploymentDescriptor(persistenceConfigFileURL);
-      
+
       MBeanConfigurationElement postOfficeConfig =
          (MBeanConfigurationElement)pdd.query("service", "QueuePostOffice").iterator().next();
-      
+
       String props = postOfficeConfig.getAttributeValue("SqlProperties");
-      
+
       if (props != null)
-      {         
+      {
          ByteArrayInputStream is = new ByteArrayInputStream(props.getBytes());
-         
+
          Properties sqlProperties = new Properties();
-         
-         sqlProperties.load(is);      
-         
+
+         sqlProperties.load(is);
+
          return sqlProperties;
       }
       else
@@ -627,7 +627,7 @@
       }
       return mbeanServer.queryNames(pattern, null);
    }
-  
+
    /**
     * Creates and registers a service based on the MBean service descriptor element. Supports
     * XMBeans. The implementing class and the ObjectName are inferred from the mbean element. If
@@ -780,7 +780,7 @@
    // Protected -----------------------------------------------------
 
    // Private -------------------------------------------------------
-   
+
    /**
     * Note that this method makes no assumption on whether the service was created or started, nor
     * does it attempt to create/start the service.
@@ -791,7 +791,7 @@
    {
       mbeanServer.registerMBean(service, on);
       log.debug(service + " registered as " + on);
-   }  
+   }
 
    private void readConfigurationFile() throws Exception
    {
@@ -1118,24 +1118,28 @@
 
    private void startRemoting() throws Exception
    {
-      SerializationStreamFactory.setManagerClassName(
-               "jms", "org.jboss.jms.server.remoting.MessagingSerializationManager");
-              
       RemotingJMXWrapper mbean;
 
       // TODO - use remoting-service.xml parameters, not these ...
 
-      //String serializationType = config.getSerializationType();
-      String serializationType = "jms";
+      String serializationType = config.getSerializationType();
+      
+      //TODO - Actually serializationType is irrelevant since we pass a
+      //DataOutput/InputStream into the marshaller and don't use serialization apart
+      //from one specific case with a JMS ObjectMessage in which case Java serialization
+      //is always currently used - (we could make this configurable)
+                  
       String transport = config.getRemotingTransport();
-      
+
       String params = "/?marshaller=org.jboss.jms.server.remoting.JMSWireFormat&" +
                       "unmarshaller=org.jboss.jms.server.remoting.JMSWireFormat&" +
                       "serializationtype=" + serializationType + "&" +
                       "dataType=jms&" +
                       "socket.check_connection=false&" +
                       "clientLeasePeriod=20000&" +
-                      "callbackStore=org.jboss.remoting.callback.BlockingCallbackStore";
+                      "callbackStore=org.jboss.remoting.callback.BlockingCallbackStore&" +
+                      "clientSocketClass=org.jboss.jms.client.remoting.ClientSocketWrapper&" +
+                      "serverSocketClass=org.jboss.jms.server.remoting.ServerSocketWrapper";
 
       // specific parameters per transport
 
@@ -1145,7 +1149,7 @@
       }
       else
       {
-         params += "timeout=0&";
+         params += "&timeout=0";
       }
 
 //      int freePort = PortUtil.findFreePort(ipAddressOrHostName);
@@ -1209,7 +1213,7 @@
       try
       {
          log.info("************************** Deleting all data from database");
-         
+
          InitialContext ctx = new InitialContext();
 
          TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
@@ -1282,7 +1286,7 @@
       }
       catch (SQLException e)
       {
-         //Ignore - tables might not exist      
+         //Ignore - tables might not exist
       }
    }
 




More information about the jboss-cvs-commits mailing list