[jboss-cvs] JBoss Messaging SVN: r3631 - in trunk: docs/examples/embedded/src/org/jboss/example/embedded and 25 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Jan 26 09:56:43 EST 2008
Author: timfox
Date: 2008-01-26 09:56:42 -0500 (Sat, 26 Jan 2008)
New Revision: 3631
Added:
trunk/src/main/org/jboss/messaging/core/remoting/codec/ConsumerChangeRateMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionSendMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ConsumerChangeRateMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionSendMessage.java
Removed:
trunk/src/main/org/jboss/jms/client/Closeable.java
trunk/src/main/org/jboss/jms/client/MessageHandler.java
trunk/src/main/org/jboss/jms/client/impl/Ack.java
trunk/src/main/org/jboss/jms/client/impl/AckImpl.java
trunk/src/main/org/jboss/jms/client/impl/Cancel.java
trunk/src/main/org/jboss/jms/client/impl/CancelImpl.java
trunk/src/main/org/jboss/jms/client/impl/DeliveryInfo.java
trunk/src/main/org/jboss/jms/server/endpoint/BrowserEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/ConnectionEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/ConsumerEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/SessionEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/SessionInternalEndpoint.java
trunk/src/main/org/jboss/jms/tx/
trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveriesRequestCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveryRequestCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveryResponseCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveriesMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveryMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/ChangeRateMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/ClosingRequestCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/ClosingResponseCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/GetPreparedTransactionsResponseCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/SendMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/SendTransactionMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/UpdateCallbackMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveriesMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveryRequest.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveryResponse.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveriesMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveryMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ChangeRateMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingRequest.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingResponse.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/GetPreparedTransactionsRequest.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/GetPreparedTransactionsResponse.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SendMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SendTransactionMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/UpdateCallbackMessage.java
Modified:
trunk/.classpath
trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java
trunk/src/main/org/jboss/jms/client/JBossConnection.java
trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java
trunk/src/main/org/jboss/jms/client/JBossConnectionFactory.java
trunk/src/main/org/jboss/jms/client/JBossConnectionMetaData.java
trunk/src/main/org/jboss/jms/client/JBossMessageConsumer.java
trunk/src/main/org/jboss/jms/client/JBossMessageProducer.java
trunk/src/main/org/jboss/jms/client/JBossQueueBrowser.java
trunk/src/main/org/jboss/jms/client/JBossSession.java
trunk/src/main/org/jboss/jms/client/api/ClientBrowser.java
trunk/src/main/org/jboss/jms/client/api/ClientConnection.java
trunk/src/main/org/jboss/jms/client/api/ClientConsumer.java
trunk/src/main/org/jboss/jms/client/api/ClientProducer.java
trunk/src/main/org/jboss/jms/client/api/ClientSession.java
trunk/src/main/org/jboss/jms/client/impl/ClientBrowserImpl.java
trunk/src/main/org/jboss/jms/client/impl/ClientConnectionFactoryImpl.java
trunk/src/main/org/jboss/jms/client/impl/ClientConnectionImpl.java
trunk/src/main/org/jboss/jms/client/impl/ClientConsumerImpl.java
trunk/src/main/org/jboss/jms/client/impl/ClientConsumerPacketHandler.java
trunk/src/main/org/jboss/jms/client/impl/ClientProducerImpl.java
trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java
trunk/src/main/org/jboss/jms/jndi/JNDIObjectDeployer.java
trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java
trunk/src/main/org/jboss/jms/message/JBossMapMessage.java
trunk/src/main/org/jboss/jms/message/JBossMessage.java
trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java
trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java
trunk/src/main/org/jboss/jms/message/JBossTextMessage.java
trunk/src/main/org/jboss/jms/server/ConnectionManager.java
trunk/src/main/org/jboss/jms/server/bridge/Bridge.java
trunk/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java
trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryAdvisedPacketHandler.java
trunk/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.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/messaging/core/Message.java
trunk/src/main/org/jboss/messaging/core/Queue.java
trunk/src/main/org/jboss/messaging/core/Transaction.java
trunk/src/main/org/jboss/messaging/core/impl/MessageImpl.java
trunk/src/main/org/jboss/messaging/core/impl/MessageReferenceImpl.java
trunk/src/main/org/jboss/messaging/core/impl/QueueImpl.java
trunk/src/main/org/jboss/messaging/core/impl/TransactionImpl.java
trunk/src/main/org/jboss/messaging/core/remoting/codec/DeliverMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/DeliverMessage.java
trunk/src/main/org/jboss/messaging/core/remoting/wireformat/PacketType.java
trunk/tests/build.xml
trunk/tests/etc/log4j.xml
trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java
trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java
trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java
trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java
trunk/tests/src/org/jboss/test/messaging/JBMServerTestCase.java
trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java
trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java
trunk/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.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/XARecoveryTest.java
trunk/tests/src/org/jboss/test/messaging/jms/XAResourceRecoveryTest.java
trunk/tests/src/org/jboss/test/messaging/jms/XATest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSExpirationHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTestBase.java
trunk/tests/src/org/jboss/test/messaging/jms/stress/StressTestBase.java
trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java
trunk/tests/src/org/jboss/test/messaging/tools/container/RMITestServer.java
trunk/tests/src/org/jboss/test/messaging/tools/container/Server.java
Log:
Transactions refactoring and client refactoring continued
Modified: trunk/.classpath
===================================================================
--- trunk/.classpath 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/.classpath 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="docs/examples/queue-failover/src"/>
+ <classpathentry kind="src" path="docs/examples/embedded/src"/>
<classpathentry kind="src" path="output/gen-parsers"/>
<classpathentry kind="src" path="docs/examples/bridge/src"/>
<classpathentry kind="src" path="docs/examples/stateless-clustered/src"/>
Modified: trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java
===================================================================
--- trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/docs/examples/embedded/src/org/jboss/example/embedded/EmbeddedExample.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,7 +21,11 @@
*/
package org.jboss.example.embedded;
+import javax.jms.Session;
+
+import org.jboss.example.embedded.MessagingServerFactory;
import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.jms.client.api.ClientConnectionFactory;
import org.jboss.jms.client.api.ClientConsumer;
import org.jboss.jms.client.api.ClientSession;
import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
@@ -32,8 +36,6 @@
import org.jboss.messaging.core.impl.DestinationImpl;
import org.jboss.messaging.core.impl.MessageImpl;
-import javax.jms.Session;
-
/**
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
*/
@@ -44,7 +46,7 @@
MessagingServer messagingServer = MessagingServerFactory.createMessagingServer();
messagingServer.start();
messagingServer.createQueue("Queue1");
- ClientConnectionFactoryImpl cf = new ClientConnectionFactoryImpl("tcp://localhost:5400?timeout=5");
+ ClientConnectionFactory cf = new ClientConnectionFactoryImpl("tcp://localhost:5400?timeout=5");
ClientConnection clientConnection = cf.createConnection(null, null);
ClientSession clientSession = clientConnection.createClientSession(false, Session.AUTO_ACKNOWLEDGE, false);
@@ -54,7 +56,7 @@
message.setPayload("hello".getBytes());
clientSession.send(message);
- ClientConsumer clientConsumer = clientSession.createClientConsumer(destination, null, false, "me", false);
+ ClientConsumer clientConsumer = clientSession.createClientConsumer(destination, null, false, null);
clientConnection.start();
JBossMessage m = (JBossMessage) clientConsumer.receive(0);
System.out.println("m = " + new String(m.getCoreMessage().getPayload()));
Deleted: trunk/src/main/org/jboss/jms/client/Closeable.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/Closeable.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/Closeable.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,50 +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;
-
-import javax.jms.JMSException;
-
-/**
- *
- * Implemented by JMS classes that can be closed
- *
- * @author <a href="mailto:adrian at jboss.org>Adrian Brock</a>
- * @author <a href="mailto:ovidiu at feodorov.com>Ovidiu Feodorov</a>
- *
- * @version $Revision$
- */
-public interface Closeable
-{
- /**
- * Close the instance
- *
- * @throws JMSException
- */
- void close() throws JMSException;
-
- /**
- * Tell the instance to prepare to close
- *
- * @throws JMSException
- */
- long closing(long sequence) throws JMSException;
-}
Modified: trunk/src/main/org/jboss/jms/client/JBossConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnection.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/JBossConnection.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,8 +21,6 @@
*/
package org.jboss.jms.client;
-import java.io.Serializable;
-
import javax.jms.Connection;
import javax.jms.ConnectionConsumer;
import javax.jms.ConnectionMetaData;
@@ -45,6 +43,7 @@
import javax.jms.XATopicSession;
import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.jms.client.api.ClientSession;
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -55,12 +54,11 @@
*/
public class JBossConnection implements
Connection, QueueConnection, TopicConnection,
- XAConnection, XAQueueConnection, XATopicConnection, Serializable
+ XAConnection, XAQueueConnection, XATopicConnection
{
// Constants ------------------------------------------------------------------------------------
- private static final long serialVersionUID = -3715868654823177898L;
-
+
static final int TYPE_GENERIC_CONNECTION = 0;
static final int TYPE_QUEUE_CONNECTION = 1;
static final int TYPE_TOPIC_CONNECTION = 2;
@@ -124,7 +122,7 @@
public void close() throws JMSException
{
- connection.closing(-1);
+ connection.closing();
connection.close();
}
@@ -252,9 +250,9 @@
acknowledgeMode = Session.SESSION_TRANSACTED;
}
- org.jboss.jms.client.api.ClientSession session =
- connection.createClientSession(transacted, acknowledgeMode, isXA);
- return new JBossSession(session, type);
+ ClientSession session = connection.createClientSession(transacted, acknowledgeMode, isXA);
+
+ return new JBossSession(transacted, acknowledgeMode, session, type);
}
// Private --------------------------------------------------------------------------------------
Modified: trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/JBossConnectionConsumer.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -115,11 +115,11 @@
// not call pre or postDeliver so messages won't be acked, or stored in session/tx.
sess = conn.createClientSession(false, Session.CLIENT_ACKNOWLEDGE, false);
- cons = sess.createClientConsumer(dest.toCoreDestination(), messageSelector, false, subName, true);
+ cons = sess.createClientConsumer(dest.toCoreDestination(), messageSelector, false, subName);
this.consumerID = cons.getID();
- this.maxDeliveries = cons.getMaxDeliveries();
+ //this.maxDeliveries = cons.getMaxDeliveries();
if (subName != null)
{
@@ -175,136 +175,138 @@
public void run()
{
- if (trace) { log.trace("running connection consumer"); }
- try
- {
- List mesList = new ArrayList();
-
- while (true)
- {
- if (closed)
- {
- if (trace) { log.trace("Connection consumer is closed, breaking"); }
- break;
- }
-
- if (mesList.isEmpty())
- {
- // Remove up to maxMessages messages from the consumer
- for (int i = 0; i < maxMessages; i++)
- {
- // receiveNoWait
-
- if (trace) { log.trace(this + " attempting to get message with receiveNoWait"); }
-
- Message m = null;
-
- try
- {
- m = cons.receive(-1);
- }
- catch (JMSException e)
- {
- //If the consumer is closed, we will get a JMSException so we ignore
- if (!closed)
- {
- throw e;
- }
- }
-
- if (m == null)
- {
- if (trace) { log.trace("receiveNoWait did not retrieve any message"); }
- break;
- }
-
- if (trace) { log.trace("receiveNoWait got message " + m + " adding to queue"); }
- mesList.add(m);
- }
-
- if (mesList.isEmpty())
- {
- // We didn't get any messages doing receiveNoWait, so let's wait. This returns if
- // a message is received or by the consumer closing.
-
- if (trace) { log.trace(this + " attempting to get message with blocking receive (no timeout)"); }
-
- Message m = null;
-
- try
- {
- m = cons.receive(0);
- }
- catch (JMSException e)
- {
- //If the consumer is closed, we will get a JMSException so we ignore
- if (!closed)
- {
- throw e;
- }
- }
-
- if (m != null)
- {
- if (trace) { log.trace("receive (no timeout) got message " + m + " adding to queue"); }
- mesList.add(m);
- }
- else
- {
- // The consumer must have closed
- if (trace) { log.trace("blocking receive returned null, consumer must have closed"); }
- break;
- }
- }
- }
-
- if (!mesList.isEmpty())
- {
- if (trace) { log.trace("there are " + mesList.size() + " messages to send to session"); }
-
- ServerSession serverSession = serverSessionPool.getServerSession();
- JBossSession session = (JBossSession)serverSession.getSession();
-
- MessageListener listener = session.getMessageListener();
-
- if (listener == null)
- {
- // Sanity check
- if (trace) { log.trace(this + ": session " + session + " did not have a set MessageListener"); }
- }
-
- for (int i = 0; i < mesList.size(); i++)
- {
- JBossMessage m = (JBossMessage)mesList.get(i);
- session.addAsfMessage(m, consumerID, queueName, maxDeliveries, sess);
- if (trace) { log.trace("added " + m + " to session"); }
- }
-
- if (trace) { log.trace(this + " starting serverSession " + serverSession); }
-
- serverSession.start();
-
- if (trace) { log.trace(this + "'s serverSession processed messages"); }
-
- mesList.clear();
- }
- }
- if (trace) { log.trace("ConnectionConsumer run() exiting"); }
- }
- catch (Throwable t)
- {
- log.debug("Connection consumer closing due to error in listening thread " + this, t);
-
- try
- {
- //Closing
- doClose();
- }
- catch (JMSException e)
- {
- log.error("Failed to close connection consumer", e);
- }
- }
+ //TODO - need to work out how to get ASF to work with core
+
+// if (trace) { log.trace("running connection consumer"); }
+// try
+// {
+// List mesList = new ArrayList();
+//
+// while (true)
+// {
+// if (closed)
+// {
+// if (trace) { log.trace("Connection consumer is closed, breaking"); }
+// break;
+// }
+//
+// if (mesList.isEmpty())
+// {
+// // Remove up to maxMessages messages from the consumer
+// for (int i = 0; i < maxMessages; i++)
+// {
+// // receiveNoWait
+//
+// if (trace) { log.trace(this + " attempting to get message with receiveNoWait"); }
+//
+// Message m = null;
+//
+// try
+// {
+// m = cons.receive(-1);
+// }
+// catch (JMSException e)
+// {
+// //If the consumer is closed, we will get a JMSException so we ignore
+// if (!closed)
+// {
+// throw e;
+// }
+// }
+//
+// if (m == null)
+// {
+// if (trace) { log.trace("receiveNoWait did not retrieve any message"); }
+// break;
+// }
+//
+// if (trace) { log.trace("receiveNoWait got message " + m + " adding to queue"); }
+// mesList.add(m);
+// }
+//
+// if (mesList.isEmpty())
+// {
+// // We didn't get any messages doing receiveNoWait, so let's wait. This returns if
+// // a message is received or by the consumer closing.
+//
+// if (trace) { log.trace(this + " attempting to get message with blocking receive (no timeout)"); }
+//
+// Message m = null;
+//
+// try
+// {
+// m = cons.receive(0);
+// }
+// catch (JMSException e)
+// {
+// //If the consumer is closed, we will get a JMSException so we ignore
+// if (!closed)
+// {
+// throw e;
+// }
+// }
+//
+// if (m != null)
+// {
+// if (trace) { log.trace("receive (no timeout) got message " + m + " adding to queue"); }
+// mesList.add(m);
+// }
+// else
+// {
+// // The consumer must have closed
+// if (trace) { log.trace("blocking receive returned null, consumer must have closed"); }
+// break;
+// }
+// }
+// }
+//
+// if (!mesList.isEmpty())
+// {
+// if (trace) { log.trace("there are " + mesList.size() + " messages to send to session"); }
+//
+// ServerSession serverSession = serverSessionPool.getServerSession();
+// JBossSession session = (JBossSession)serverSession.getSession();
+//
+// MessageListener listener = session.getMessageListener();
+//
+// if (listener == null)
+// {
+// // Sanity check
+// if (trace) { log.trace(this + ": session " + session + " did not have a set MessageListener"); }
+// }
+//
+// for (int i = 0; i < mesList.size(); i++)
+// {
+// JBossMessage m = (JBossMessage)mesList.get(i);
+// session.addAsfMessage(m, consumerID, queueName, maxDeliveries, sess);
+// if (trace) { log.trace("added " + m + " to session"); }
+// }
+//
+// if (trace) { log.trace(this + " starting serverSession " + serverSession); }
+//
+// serverSession.start();
+//
+// if (trace) { log.trace(this + "'s serverSession processed messages"); }
+//
+// mesList.clear();
+// }
+// }
+// if (trace) { log.trace("ConnectionConsumer run() exiting"); }
+// }
+// catch (Throwable t)
+// {
+// log.debug("Connection consumer closing due to error in listening thread " + this, t);
+//
+// try
+// {
+// //Closing
+// doClose();
+// }
+// catch (JMSException e)
+// {
+// log.error("Failed to close connection consumer", e);
+// }
+// }
}
protected synchronized void doClose() throws JMSException
@@ -316,22 +318,9 @@
closed = true;
- //Calling session.closing() will cause the consumer to close which
- //will make any receive() calls return null
- //and not return until the consumer close protocol is complete
-
- try
- {
- sess.closing(-1);
- sess.close();
- }
- catch (Throwable t)
- {
- //Closing may fail if doClose() was called after a previous Throwable was caught hence
- //only want to log in trace mode
- log.trace("Failed to close session", t);
- }
-
+ sess.closing();
+ sess.close();
+
if (trace) { log.trace(this + "Closed message handler"); }
}
Modified: trunk/src/main/org/jboss/jms/client/JBossConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnectionFactory.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/JBossConnectionFactory.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -40,7 +40,7 @@
import javax.naming.Reference;
import org.jboss.jms.client.api.ClientConnection;
-import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.jms.client.api.ClientConnectionFactory;
import org.jboss.jms.referenceable.SerializableObjectRefAddr;
import org.jboss.messaging.util.Logger;
@@ -66,11 +66,11 @@
// Attributes -----------------------------------------------------------------------------------
- protected ClientConnectionFactoryImpl delegate;
+ protected ClientConnectionFactory delegate;
// Constructors ---------------------------------------------------------------------------------
- public JBossConnectionFactory(ClientConnectionFactoryImpl delegate)
+ public JBossConnectionFactory(ClientConnectionFactory delegate)
{
this.delegate = delegate;
}
@@ -174,7 +174,7 @@
return "JBossConnectionFactory->" + delegate;
}
- public ClientConnectionFactoryImpl getDelegate()
+ public ClientConnectionFactory getDelegate()
{
return delegate;
}
Modified: trunk/src/main/org/jboss/jms/client/JBossConnectionMetaData.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnectionMetaData.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/JBossConnectionMetaData.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,7 +21,6 @@
*/
package org.jboss.jms.client;
-import java.io.Serializable;
import java.util.Enumeration;
import java.util.Vector;
@@ -38,13 +37,11 @@
*
* $Id$
*/
-public class JBossConnectionMetaData implements Serializable, ConnectionMetaData
+public class JBossConnectionMetaData implements ConnectionMetaData
{
// Constants -----------------------------------------------------
- private static final long serialVersionUID = 327633302671160939L;
-
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
Modified: trunk/src/main/org/jboss/jms/client/JBossMessageConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossMessageConsumer.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/JBossMessageConsumer.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,8 +21,7 @@
*/
package org.jboss.jms.client;
-import java.io.Serializable;
-
+import javax.jms.IllegalStateException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
@@ -33,7 +32,11 @@
import javax.jms.TopicSubscriber;
import org.jboss.jms.client.api.ClientConsumer;
+import org.jboss.jms.client.api.ClientSession;
+import org.jboss.jms.client.api.MessageHandler;
import org.jboss.jms.destination.JBossDestination;
+import org.jboss.jms.message.JBossMessage;
+import org.jboss.messaging.util.Logger;
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -41,23 +44,35 @@
*
* $Id$
*/
-public class JBossMessageConsumer implements MessageConsumer, QueueReceiver, TopicSubscriber, Serializable
+public class JBossMessageConsumer implements MessageConsumer, QueueReceiver, TopicSubscriber
{
// Constants -----------------------------------------------------
- private static final long serialVersionUID = -8776908463975467851L;
-
+ private static final Logger log = Logger.getLogger(JBossMessageConsumer.class);
+
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
- protected ClientConsumer consumer;
+ private ClientConsumer consumer;
+
+ private MessageListener listener;
+
+ private MessageHandler coreListener;
+
+ private JBossSession session;
+
+ private int ackMode;
// Constructors --------------------------------------------------
- public JBossMessageConsumer(ClientConsumer consumer)
+ public JBossMessageConsumer(JBossSession session, ClientConsumer consumer) throws JMSException
{
+ this.session = session;
+
this.consumer = consumer;
+
+ this.ackMode = session.getAcknowledgeMode();
}
// MessageConsumer implementation --------------------------------
@@ -69,32 +84,38 @@
public MessageListener getMessageListener() throws JMSException
{
- return consumer.getMessageListener();
+ checkClosed();
+
+ return listener;
}
public void setMessageListener(MessageListener listener) throws JMSException
{
- consumer.setMessageListener(listener);
+ this.listener = listener;
+
+ coreListener = new JMSMessageListenerWrapper(session, listener, ackMode);
+
+ consumer.setMessageHandler(coreListener);
}
public Message receive() throws JMSException
{
- return consumer.receive(0);
+ return getMessage(0);
}
public Message receive(long timeout) throws JMSException
{
- return consumer.receive(timeout);
+ return getMessage(timeout);
}
public Message receiveNoWait() throws JMSException
{
- return consumer.receive(-1);
+ return getMessage(-1);
}
-
+
public void close() throws JMSException
{
- consumer.closing(-1);
+ consumer.closing();
consumer.close();
}
@@ -135,6 +156,42 @@
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
+
+ private void checkClosed() throws JMSException
+ {
+ if (session.getCoreSession().isClosed())
+ {
+ throw new IllegalStateException("Consumer is closed");
+ }
+ }
+
+ private JBossMessage getMessage(long timeout) throws JMSException
+ {
+ org.jboss.messaging.core.Message message = consumer.receive(timeout);
+
+ JBossMessage jbm = null;
+
+ if (message != null)
+ {
+ //At this point JMS considers the message delivered
+ session.getCoreSession().delivered();
+
+ jbm = JBossMessage.createMessage(message, session.getCoreSession());
+
+ try
+ {
+ jbm.doBeforeReceive();
+ }
+ catch (Exception e)
+ {
+ log.error("Failed to prepare message", e);
+
+ return null;
+ }
+ }
+
+ return jbm;
+ }
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/jms/client/JBossMessageProducer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossMessageProducer.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/JBossMessageProducer.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,8 +21,6 @@
*/
package org.jboss.jms.client;
-import java.io.Serializable;
-
import javax.jms.Destination;
import javax.jms.InvalidDestinationException;
import javax.jms.JMSException;
@@ -43,12 +41,10 @@
*
* $Id$
*/
-public class JBossMessageProducer implements MessageProducer, QueueSender, TopicPublisher, Serializable
+public class JBossMessageProducer implements MessageProducer, QueueSender, TopicPublisher
{
// Constants -----------------------------------------------------
- private static final long serialVersionUID = 1080736785725023015L;
-
// Static --------------------------------------------------------
private static final Logger log = Logger.getLogger(JBossMessageProducer.class);
@@ -125,7 +121,7 @@
public void close() throws JMSException
{
- producer.closing(-1);
+ producer.closing();
producer.close();
}
Modified: trunk/src/main/org/jboss/jms/client/JBossQueueBrowser.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossQueueBrowser.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/JBossQueueBrowser.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -38,15 +38,12 @@
*
* $Id$
*/
-public class JBossQueueBrowser implements QueueBrowser, Serializable
+public class JBossQueueBrowser implements QueueBrowser
{
// Constants ------------------------------------------------------------------------------------
private static final Logger log = Logger.getLogger(JBossQueueBrowser.class);
-
- private static final long serialVersionUID = 4245650830082712281L;
-
// Static ---------------------------------------------------------------------------------------
// Attributes -----------------------------------------------------------------------------------
@@ -68,7 +65,7 @@
public void close() throws JMSException
{
- delegate.closing(-1);
+ delegate.closing();
delegate.close();
}
@@ -129,7 +126,7 @@
{
Message message = delegate.nextMessage();
- JBossMessage jbm = JBossMessage.createMessage(message, 0, 0);
+ JBossMessage jbm = JBossMessage.createMessage(message, null);
jbm.doBeforeReceive();
Modified: trunk/src/main/org/jboss/jms/client/JBossSession.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossSession.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/JBossSession.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -62,7 +62,12 @@
import org.jboss.jms.destination.JBossTemporaryQueue;
import org.jboss.jms.destination.JBossTemporaryTopic;
import org.jboss.jms.destination.JBossTopic;
+import org.jboss.jms.message.JBossBytesMessage;
+import org.jboss.jms.message.JBossMapMessage;
import org.jboss.jms.message.JBossMessage;
+import org.jboss.jms.message.JBossObjectMessage;
+import org.jboss.jms.message.JBossStreamMessage;
+import org.jboss.jms.message.JBossTextMessage;
import org.jboss.messaging.util.Logger;
/**
@@ -75,12 +80,10 @@
*/
public class JBossSession implements
Session, XASession, QueueSession, XAQueueSession,
- TopicSession, XATopicSession, Serializable
+ TopicSession, XATopicSession
{
// Constants -----------------------------------------------------
- private static final long serialVersionUID = 2235942510476264909L;
-
static final int TYPE_GENERIC_SESSION = 0;
static final int TYPE_QUEUE_SESSION = 1;
@@ -101,137 +104,184 @@
private MessageListener distinguishedListener;
+ private int ackMode;
+
+ private boolean transacted;
+
+ private boolean recoverCalled;
+
// Constructors --------------------------------------------------
- public JBossSession(ClientSession sessionDelegate, int sessionType)
- {
- this.session = sessionDelegate;
+ public JBossSession(boolean transacted, int ackMode, ClientSession session, int sessionType)
+ {
+ this.ackMode = ackMode;
+ this.session = session;
+
this.sessionType = sessionType;
+
+ this.transacted = transacted;
}
// Session implementation ----------------------------------------
public BytesMessage createBytesMessage() throws JMSException
{
- return session.createBytesMessage();
+ checkClosed();
+
+ return new JBossBytesMessage();
}
public MapMessage createMapMessage() throws JMSException
{
- return session.createMapMessage();
+ checkClosed();
+
+ return new JBossMapMessage();
}
public Message createMessage() throws JMSException
{
- return session.createMessage();
+ checkClosed();
+
+ return new JBossMessage();
}
public ObjectMessage createObjectMessage() throws JMSException
{
- return session.createObjectMessage();
+ checkClosed();
+
+ return new JBossObjectMessage();
}
public ObjectMessage createObjectMessage(Serializable object) throws JMSException
{
- return session.createObjectMessage(object);
+ checkClosed();
+
+ JBossObjectMessage jbm = new JBossObjectMessage();
+
+ jbm.setObject(object);
+
+ return jbm;
}
public StreamMessage createStreamMessage() throws JMSException
{
- return session.createStreamMessage();
+ checkClosed();
+
+ return new JBossStreamMessage();
}
public TextMessage createTextMessage() throws JMSException
{
- return session.createTextMessage();
+ checkClosed();
+
+ return new JBossTextMessage();
}
public TextMessage createTextMessage(String text) throws JMSException
{
- return session.createTextMessage(text);
+ checkClosed();
+
+ JBossTextMessage jbm = new JBossTextMessage();
+
+ jbm.setText(text);
+
+ return jbm;
}
public boolean getTransacted() throws JMSException
{
- return session.isTransacted();
+ checkClosed();
+
+ return transacted;
}
public int getAcknowledgeMode() throws JMSException
{
- return session.getAcknowledgeMode();
+ checkClosed();
+
+ return ackMode;
}
public void commit() throws JMSException
{
+ if (!transacted)
+ {
+ throw new IllegalStateException("Cannot commit a non-transacted session");
+ }
session.commit();
}
public void rollback() throws JMSException
{
+ if (!transacted)
+ {
+ throw new IllegalStateException("Cannot rollback a non-transacted session");
+ }
+
session.rollback();
}
public void close() throws JMSException
{
- session.closing(-1);
+ session.closing();
session.close();
}
public void recover() throws JMSException
{
- session.recover();
+ if (transacted)
+ {
+ throw new IllegalStateException("Cannot recover a transacted session");
+ }
+
+ session.rollback();
+
+ recoverCalled = true;
}
public MessageListener getMessageListener() throws JMSException
{
- if (session.isClosed())
- {
- throw new IllegalStateException("Session is closed");
- }
+ checkClosed();
+
return distinguishedListener;
}
public void setMessageListener(MessageListener listener) throws JMSException
{
- if (session.isClosed())
- {
- throw new IllegalStateException("Session is closed");
- }
+ checkClosed();
+
this.distinguishedListener = listener;
-
- //When we have a distinguised listener our behaviour is to fall back to local transacted
- //when the session is not enlisted.
- this.session.setTreatAsNonTransactedWhenNotEnlisted(false);
}
-
+
/**
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
public void run()
{
- try
- {
- if (asfMessages != null)
- {
- int ackMode = getAcknowledgeMode();
+// try
+// {
+// if (asfMessages != null)
+// {
+// while (asfMessages.size() > 0)
+// {
+// AsfMessageHolder holder = (AsfMessageHolder)asfMessages.removeFirst();
+//
+// session.preDeliver(holder.getMsg().getDeliveryId());
+//
+// session.postDeliver();
+//
+// distinguishedListener.onMessage(holder.getMsg());
+// }
+// }
+// }
+// catch (Exception e)
+// {
+// log.error("Failed to process ASF messages", e);
+// }
- while (asfMessages.size() > 0)
- {
- AsfMessageHolder holder = (AsfMessageHolder)asfMessages.removeFirst();
-
- MessageHandler.callOnMessage(session, distinguishedListener, holder.getConsumerID(),
- false,
- holder.getMsg(), ackMode, holder.getMaxDeliveries(),
- holder.getConnectionConsumerSession());
- }
- }
- }
- catch (Exception e)
- {
- log.error("Failed to process ASF messages", e);
- }
+ //Need to work out how to get ASF to work with core
}
public MessageProducer createProducer(Destination d) throws JMSException
@@ -267,12 +317,28 @@
{
throw new InvalidDestinationException("Not a JBossDestination:" + d);
}
+
+ ClientConsumer cd = session.
+ createClientConsumer(((JBossDestination)d).toCoreDestination(), messageSelector, noLocal, null);
- org.jboss.jms.client.api.ClientConsumer cd = session.
- createClientConsumer(((JBossDestination)d).toCoreDestination(), messageSelector, noLocal, null, false);
-
- return new JBossMessageConsumer(cd);
+ return new JBossMessageConsumer(this, cd);
}
+
+ private boolean isDeliveredBeforeOnMessage()
+ {
+ boolean deliveredBeforeOnMessage;
+
+ if (transacted || ackMode == Session.CLIENT_ACKNOWLEDGE)
+ {
+ deliveredBeforeOnMessage = true;
+ }
+ else
+ {
+ deliveredBeforeOnMessage = false;
+ }
+
+ return deliveredBeforeOnMessage;
+ }
public Queue createQueue(String queueName) throws JMSException
{
@@ -311,9 +377,9 @@
}
ClientConsumer cd =
- session.createClientConsumer(((JBossTopic)topic).toCoreDestination(), null, false, name, false);
+ session.createClientConsumer(((JBossTopic)topic).toCoreDestination(), null, false, name);
- return new JBossMessageConsumer(cd);
+ return new JBossMessageConsumer(this, cd);
}
public TopicSubscriber createDurableSubscriber(Topic topic,
@@ -341,9 +407,9 @@
}
ClientConsumer cd = session.
- createClientConsumer(((JBossTopic)topic).toCoreDestination(), messageSelector, noLocal, name, false);
+ createClientConsumer(((JBossTopic)topic).toCoreDestination(), messageSelector, noLocal, name);
- return new JBossMessageConsumer(cd);
+ return new JBossMessageConsumer(this, cd);
}
public QueueBrowser createBrowser(Queue queue) throws JMSException
@@ -485,10 +551,20 @@
return "JBossSession->" + session;
}
- public org.jboss.jms.client.api.ClientSession getDelegate()
+ public ClientSession getCoreSession()
{
return session;
+ }
+
+ public boolean isRecoverCalled()
+ {
+ return recoverCalled;
}
+
+ public void setRecoverCalled(boolean recoverCalled)
+ {
+ this.recoverCalled = recoverCalled;
+ }
// Package protected ---------------------------------------------
@@ -515,7 +591,16 @@
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
+
+ private void checkClosed() throws JMSException
+ {
+ if (session.isClosed())
+ {
+ throw new IllegalStateException("Session is closed");
+ }
+ }
+
// Inner classes -------------------------------------------------
}
Deleted: trunk/src/main/org/jboss/jms/client/MessageHandler.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/MessageHandler.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/MessageHandler.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,158 +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;
-
-import javax.jms.JMSException;
-import javax.jms.MessageListener;
-import javax.jms.Session;
-
-import org.jboss.jms.client.api.ClientSession;
-import org.jboss.jms.client.impl.Cancel;
-import org.jboss.jms.client.impl.CancelImpl;
-import org.jboss.jms.client.impl.DeliveryInfo;
-import org.jboss.jms.message.JBossMessage;
-import org.jboss.messaging.core.Message;
-import org.jboss.messaging.util.Logger;
-
-/**
- *
- * A MessageHandler
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class MessageHandler
-{
- private static final Logger log = Logger.getLogger(MessageHandler.class);
-
- private static final boolean trace = log.isTraceEnabled();
-
- // This is static so it can be called by the asf layer too
- public static void callOnMessage(ClientSession sess,
- MessageListener listener,
- String consumerID,
- boolean isConnectionConsumer,
- JBossMessage m,
- int ackMode,
- int maxDeliveries,
- ClientSession connectionConsumerSession)
- throws JMSException
- {
- if (checkExpiredOrReachedMaxdeliveries(m, connectionConsumerSession!=null?connectionConsumerSession:sess, maxDeliveries))
- {
- // Message has been cancelled
- return;
- }
-
- DeliveryInfo deliveryInfo =
- new DeliveryInfo(m, consumerID, connectionConsumerSession);
-
- m.incDeliveryCount();
-
- // If this is the callback-handler for a connection consumer we don't want to acknowledge or
- // add anything to the tx for this session.
- if (!isConnectionConsumer)
- {
- // We need to call preDeliver, deliver the message then call postDeliver - this is because
- // it is legal to call session.recover(), or session.rollback() from within the onMessage()
- // method in which case the last message needs to be delivered so it needs to know about it
- sess.preDeliver(deliveryInfo);
- }
-
- try
- {
- if (trace) { log.trace("calling listener's onMessage(" + m + ")"); }
-
- listener.onMessage(m);
-
- if (trace) { log.trace("listener's onMessage() finished"); }
- }
- catch (RuntimeException e)
- {
- log.error("RuntimeException was thrown from onMessage, " + m.getJMSMessageID() + " will be redelivered", e);
-
- // See JMS 1.1 spec 4.5.2
-
- if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE)
- {
- sess.recover();
- }
- }
-
- // If this is the callback-handler for a connection consumer we don't want to acknowledge
- //or add anything to the tx for this session
- if (!isConnectionConsumer)
- {
- if (trace) { log.trace("Calling postDeliver"); }
-
- sess.postDeliver();
-
- if (trace) { log.trace("Called postDeliver"); }
- }
- }
-
-
- public static boolean checkExpiredOrReachedMaxdeliveries(JBossMessage jbm,
- ClientSession del,
- int maxDeliveries)
- {
- Message msg = jbm.getCoreMessage();
-
- boolean expired = msg.isExpired();
-
- boolean reachedMaxDeliveries = jbm.getDeliveryCount() == maxDeliveries;
-
- if (expired || reachedMaxDeliveries)
- {
- if (trace)
- {
- if (expired)
- {
- log.trace(msg + " has expired, cancelling to server");
- }
- else
- {
- log.trace(msg + " has reached maximum delivery number " + maxDeliveries +", cancelling to server");
- }
- }
-
- final Cancel cancel = new CancelImpl(jbm.getDeliveryId(), jbm.getDeliveryCount(),
- expired, reachedMaxDeliveries);
- try
- {
- del.cancelDelivery(cancel);
- }
- catch (JMSException e)
- {
- log.error("Failed to cancel delivery", e);
- }
-
- return true;
- }
- else
- {
- return false;
- }
- }
-
-
-}
Modified: trunk/src/main/org/jboss/jms/client/api/ClientBrowser.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientBrowser.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/api/ClientBrowser.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -9,7 +9,6 @@
import javax.jms.JMSException;
-import org.jboss.jms.client.Closeable;
import org.jboss.messaging.core.Message;
/**
@@ -17,7 +16,7 @@
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
*/
-public interface ClientBrowser extends Closeable
+public interface ClientBrowser
{
void reset() throws JMSException;
@@ -26,4 +25,8 @@
boolean hasNextMessage() throws JMSException;
Message[] nextMessageBlock(int maxMessages) throws JMSException;
+
+ void closing() throws JMSException;
+
+ void close() throws JMSException;
}
Modified: trunk/src/main/org/jboss/jms/client/api/ClientConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientConnection.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/api/ClientConnection.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -13,26 +13,21 @@
import javax.jms.JMSException;
import javax.jms.ServerSessionPool;
-import org.jboss.jms.client.Closeable;
import org.jboss.jms.client.JBossConnectionConsumer;
import org.jboss.jms.client.remoting.MessagingRemotingConnection;
-import org.jboss.jms.tx.ResourceManager;
-import org.jboss.jms.tx.TransactionRequest;
-import org.jboss.messaging.core.tx.MessagingXid;
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
*/
-public interface ClientConnection extends Closeable
+public interface ClientConnection
{
ClientSession createClientSession(boolean transacted,
int acknowledgmentMode, boolean isXA) throws JMSException;
String getClientID() throws JMSException;
- //Only used for testing
int getServerID();
void setClientID(String id) throws JMSException;
@@ -41,11 +36,6 @@
void stop() throws JMSException;
- void sendTransaction(TransactionRequest request)
- throws JMSException;
-
- MessagingXid[] getPreparedTransactions() throws JMSException;
-
ExceptionListener getExceptionListener() throws JMSException;
void setExceptionListener(ExceptionListener listener) throws JMSException;
@@ -60,8 +50,9 @@
MessagingRemotingConnection getRemotingConnection();
- ResourceManager getResourceManager();
-
- /** This is a method used by children Session during close operations */
void removeChild(String id) throws JMSException;
+
+ void closing() throws JMSException;
+
+ void close() throws JMSException;
}
Modified: trunk/src/main/org/jboss/jms/client/api/ClientConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientConsumer.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/api/ClientConsumer.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -8,27 +8,25 @@
package org.jboss.jms.client.api;
import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import org.jboss.jms.client.Closeable;
-import org.jboss.jms.message.JBossMessage;
import org.jboss.messaging.core.Destination;
+import org.jboss.messaging.core.Message;
+import org.jboss.messaging.core.remoting.wireformat.DeliverMessage;
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
*/
-public interface ClientConsumer extends Closeable
+public interface ClientConsumer
{
String getID();
void changeRate(float newRate) throws JMSException;
- MessageListener getMessageListener() throws JMSException;
+ MessageHandler getMessageHandler() throws JMSException;
- void setMessageListener(MessageListener listener) throws JMSException;
+ void setMessageHandler(MessageHandler handler) throws JMSException;
Destination getDestination() throws JMSException;
@@ -38,11 +36,11 @@
Message receive(long timeout) throws JMSException;
- int getMaxDeliveries();
+ void handleMessage(DeliverMessage message) throws Exception;
- void handleMessage(JBossMessage message) throws Exception;
+ void closing() throws JMSException;
- void addToFrontOfBuffer(JBossMessage message) throws JMSException;
+ void close() throws JMSException;
- long getRedeliveryDelay();
+ void recover(long lastDeliveryID) throws JMSException;
}
Modified: trunk/src/main/org/jboss/jms/client/api/ClientProducer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientProducer.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/api/ClientProducer.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -10,7 +10,6 @@
import javax.jms.JMSException;
import javax.jms.Message;
-import org.jboss.jms.client.Closeable;
import org.jboss.jms.destination.JBossDestination;
/**
@@ -18,7 +17,7 @@
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
*/
-public interface ClientProducer extends Closeable
+public interface ClientProducer
{
String getID();
@@ -49,5 +48,9 @@
int deliveryMode,
int priority,
long timeToLive) throws JMSException;
+
+ void closing() throws JMSException;
+
+ void close() throws JMSException;
}
Modified: trunk/src/main/org/jboss/jms/client/api/ClientSession.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/api/ClientSession.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/api/ClientSession.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -7,25 +7,12 @@
package org.jboss.jms.client.api;
-import java.io.Serializable;
-import java.util.List;
-
import javax.jms.JMSException;
import javax.transaction.xa.XAResource;
-import org.jboss.jms.client.Closeable;
-import org.jboss.jms.client.impl.Ack;
-import org.jboss.jms.client.impl.Cancel;
-import org.jboss.jms.client.impl.DeliveryInfo;
import org.jboss.jms.destination.JBossDestination;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
-import org.jboss.jms.message.JBossBytesMessage;
-import org.jboss.jms.message.JBossMapMessage;
-import org.jboss.jms.message.JBossMessage;
-import org.jboss.jms.message.JBossObjectMessage;
-import org.jboss.jms.message.JBossStreamMessage;
-import org.jboss.jms.message.JBossTextMessage;
import org.jboss.messaging.core.Destination;
import org.jboss.messaging.core.Message;
@@ -34,17 +21,15 @@
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
*/
-public interface ClientSession extends Closeable
+public interface ClientSession
{
ClientConnection getConnection();
String getID();
ClientConsumer createClientConsumer(Destination destination, String selector,
- boolean noLocal, String subscriptionName,
- boolean isCC) throws JMSException;
+ boolean noLocal, String subscriptionName) throws JMSException;
-
ClientBrowser createClientBrowser(Destination queue, String messageSelector) throws JMSException;
ClientProducer createClientProducer(JBossDestination destination) throws JMSException;
@@ -53,14 +38,8 @@
JBossTopic createTopic(String topicName) throws JMSException;
- void acknowledgeDeliveries(List<Ack> acks) throws JMSException;
-
- boolean acknowledgeDelivery(Ack ack) throws JMSException;
-
- void cancelDeliveries(List<Cancel> cancels) throws JMSException;
-
- void cancelDelivery(Cancel cancel) throws JMSException;
-
+ void delivered() throws JMSException;
+
void addTemporaryDestination(Destination destination) throws JMSException;
void deleteTemporaryDestination(Destination destination) throws JMSException;
@@ -69,56 +48,27 @@
void send(Message message) throws JMSException;
- int getDupsOKBatchSize() throws JMSException;
-
- public boolean isStrictTck() throws JMSException;
-
- JBossMessage createMessage() throws JMSException;
-
- JBossBytesMessage createBytesMessage() throws JMSException;
-
- JBossMapMessage createMapMessage() throws JMSException;
-
- JBossObjectMessage createObjectMessage() throws JMSException;
-
- JBossObjectMessage createObjectMessage(Serializable object) throws JMSException;
-
- JBossStreamMessage createStreamMessage() throws JMSException;
-
- JBossTextMessage createTextMessage() throws JMSException;
-
- JBossTextMessage createTextMessage(String text) throws JMSException;
-
- void preDeliver(DeliveryInfo deliveryInfo) throws JMSException;
-
- boolean postDeliver() throws JMSException;
-
XAResource getXAResource();
- boolean isTransacted() throws JMSException;
-
- int getAcknowledgeMode() throws JMSException;
-
void commit() throws JMSException;
void rollback() throws JMSException;
- void recover() throws JMSException;
-
- void redeliver(List deliveryInfos) throws JMSException;
-
- void acknowledgeAll() throws JMSException;
-
boolean isXA() throws JMSException;
- void setTreatAsNonTransactedWhenNotEnlisted(boolean treatAsNonTransactedWhenNotEnlisted);
-
- Object getCurrentTxId();
-
- void setCurrentTxId(Object currentTxId);
+ void removeConsumer(ClientConsumer consumer) throws JMSException;
- /** This is a method used by children (Producer, Consumer and Browser) during close operations */
- void removeChild(String id) throws JMSException;
+ void removeProducer(ClientProducer producer);
+ void removeBrowser(ClientBrowser browser);
+
boolean isClosed();
+
+ void closing() throws JMSException;
+
+ void close() throws JMSException;
+
+ //TOD hide these private api
+ void delivered(long deliveryID, boolean expired);
+
}
Deleted: trunk/src/main/org/jboss/jms/client/impl/Ack.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/Ack.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/Ack.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,36 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jms.client.impl;
-
-/**
- * A Ack
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public interface Ack
-{
- long getDeliveryID();
-}
Deleted: trunk/src/main/org/jboss/jms/client/impl/AckImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/AckImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/AckImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,73 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jms.client.impl;
-
-/**
- * A AckImpl
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 2684 $</tt>
- *
- * $Id: AckImpl.java 2684 2007-05-15 07:31:30Z timfox $
- *
- */
-public class AckImpl implements Ack
-{
-
- // Constants ------------------------------------------------------------------------------------
-
- // Static ---------------------------------------------------------------------------------------
-
- // Attributes -----------------------------------------------------------------------------------
-
- private long deliveryID;
-
- // Constructors ---------------------------------------------------------------------------------
-
- public AckImpl(long deliveryId)
- {
- this.deliveryID = deliveryId;
- }
-
- // Ack implementation ---------------------------------------------------------------------------
-
- public long getDeliveryID()
- {
- return deliveryID;
- }
-
- // Public ---------------------------------------------------------------------------------------
-
- public String toString()
- {
- return "ACK[" + deliveryID + "]";
- }
-
- // Package protected ----------------------------------------------------------------------------
-
- // Protected ------------------------------------------------------------------------------------
-
- // Private --------------------------------------------------------------------------------------
-
- // Inner classes --------------------------------------------------------------------------------
-
-}
Deleted: trunk/src/main/org/jboss/jms/client/impl/Cancel.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/Cancel.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/Cancel.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jms.client.impl;
-
-/**
- * A Cancel
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public interface Cancel
-{
- long getDeliveryId();
-
- int getDeliveryCount();
-
- boolean isExpired();
-
- boolean isReachedMaxDeliveryAttempts();
-}
Deleted: trunk/src/main/org/jboss/jms/client/impl/CancelImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/CancelImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/CancelImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,115 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jms.client.impl;
-
-
-/**
- *
- * A Cancel.
- *
- * Used to send a cancel (NACK) to the server
- *
- * When we cancel we send delivery count info, this means delivery count
- * can be updated on the server, and into storage if persistent, and the
- * message can be sent to DLQ if appropriate
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 3047 $</tt>
- *
- * $Id: CancelImpl.java 3047 2007-08-23 19:02:05Z clebert.suconic at jboss.com $
- *
- */
-public class CancelImpl implements Cancel
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private long deliveryId;
-
- private int deliveryCount;
-
- private boolean expired;
-
- private boolean reachedMaxDeliveryAttempts;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public CancelImpl()
- {
- }
-
- public CancelImpl(long deliveryId, int deliveryCount, boolean expired, boolean maxDeliveries)
- {
- this.deliveryId = deliveryId;
-
- this.deliveryCount = deliveryCount;
-
- this.expired = expired;
-
- this.reachedMaxDeliveryAttempts = maxDeliveries;
- }
-
- // Public --------------------------------------------------------
-
- public long getDeliveryId()
- {
- return deliveryId;
- }
-
- public int getDeliveryCount()
- {
- return deliveryCount;
- }
-
- public boolean isExpired()
- {
- return expired;
- }
-
- public boolean isReachedMaxDeliveryAttempts()
- {
- return reachedMaxDeliveryAttempts;
- }
-
- public String toString()
- {
- return "CancelImpl(deliveryId=" + deliveryId +
- ", deliveryCount=" + deliveryCount +
- ", expired=" + expired +
- ", reachedMaxDeliveryAttempts=" + reachedMaxDeliveryAttempts + ")";
- }
-
- // Class YYY overrides -------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Package Private -----------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner Classes -------------------------------------------------
-
-}
-
Modified: trunk/src/main/org/jboss/jms/client/impl/ClientBrowserImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientBrowserImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientBrowserImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -35,8 +35,7 @@
import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageResponse;
import org.jboss.messaging.core.remoting.wireformat.BrowserResetMessage;
import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
+import org.jboss.messaging.core.remoting.wireformat.ClosingMessage;
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -89,22 +88,20 @@
}
finally
{
- session.removeChild(id);
+ session.removeBrowser(this);
closed = true;
}
}
- public synchronized long closing(long sequence) throws JMSException
+ public synchronized void closing() throws JMSException
{
if (closed)
{
- return -1;
+ return;
}
- ClosingResponse response = (ClosingResponse) remotingConnection.sendBlocking(id, new ClosingRequest(sequence));
-
- return response.getID();
+ remotingConnection.sendBlocking(id, new ClosingMessage());
}
public void reset() throws JMSException
Modified: trunk/src/main/org/jboss/jms/client/impl/ClientConnectionFactoryImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientConnectionFactoryImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConnectionFactoryImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,23 +21,25 @@
*/
package org.jboss.jms.client.impl;
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+
import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.jms.client.api.ClientConnectionFactory;
import org.jboss.jms.client.plugin.LoadBalancingFactory;
import org.jboss.jms.client.remoting.ConsolidatedRemotingConnectionListener;
import org.jboss.jms.client.remoting.MessagingRemotingConnection;
import org.jboss.jms.exception.MessagingJMSException;
-import org.jboss.jms.tx.ResourceManager;
-import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.messaging.core.remoting.wireformat.CreateConnectionRequest;
import org.jboss.messaging.core.remoting.wireformat.CreateConnectionResponse;
import org.jboss.messaging.util.Logger;
import org.jboss.messaging.util.Version;
-import javax.jms.JMSException;
-import java.io.Serializable;
-
/**
- * The client-side ConnectionFactory delegate class.
+ * Core connection factory.
+ *
+ * Can be instantiate programmatically and used to make connections.
*
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -49,7 +51,7 @@
*
* $Id: ClientConnectionFactoryImpl.java 3602 2008-01-21 17:48:32Z timfox $
*/
-public class ClientConnectionFactoryImpl implements Serializable
+public class ClientConnectionFactoryImpl implements ClientConnectionFactory, Serializable
{
// Constants ------------------------------------------------------------------------------------
public static final String id = "CONNECTION_FACTORY_ID";
@@ -66,14 +68,10 @@
private int serverID;
- private boolean clientPing;
-
private String clientID;
private int prefetchSize = 150;
- private boolean slowConsumers;
-
private boolean supportsFailover;
private boolean supportsLoadBalancing;
@@ -85,36 +83,16 @@
private boolean strictTck;
// Static ---------------------------------------------------------------------------------------
-
- private static Version getVersionToUse(Version connectionVersion)
- {
- Version clientVersion = Version.instance();
-
- Version versionToUse;
-
- if (connectionVersion != null && connectionVersion.getProviderIncrementingVersion() <=
- clientVersion.getProviderIncrementingVersion())
- {
- versionToUse = connectionVersion;
- }
- else
- {
- versionToUse = clientVersion;
- }
-
- return versionToUse;
- }
-
+
// Constructors ---------------------------------------------------------------------------------
- public ClientConnectionFactoryImpl( int serverID,
- String serverLocatorURI, Version serverVersion, boolean clientPing, boolean strictTck,
+ public ClientConnectionFactoryImpl(int serverID,
+ String serverLocatorURI, Version serverVersion, boolean strictTck,
int prefetchSize, int dupsOKBatchSize, String clientID)
{
this.serverID = serverID;
this.serverLocatorURI = serverLocatorURI;
this.serverVersion = serverVersion;
- this.clientPing = clientPing;
this.strictTck = strictTck;
this.prefetchSize = prefetchSize;
this.dupsOKBatchSize = dupsOKBatchSize;
@@ -130,6 +108,11 @@
{
}
+ public ClientConnection createConnection() throws JMSException
+ {
+ return createConnection(null, null);
+ }
+
public ClientConnection createConnection(String username, String password) throws JMSException
{
Version version = getVersionToUse(serverVersion);
@@ -152,10 +135,8 @@
CreateConnectionResponse response =
(CreateConnectionResponse)remotingConnection.sendBlocking(id, request);
- ResourceManager resourceManager = ResourceManagerFactory.instance.checkOutResourceManager(this.serverID);
-
ClientConnectionImpl connection =
- new ClientConnectionImpl(response.getConnectionID(), serverID, strictTck, version, resourceManager, remotingConnection);
+ new ClientConnectionImpl(response.getConnectionID(), serverID, strictTck, version, remotingConnection);
//FIXME - get rid of this stupid ConsolidatedThingamajug bollocks
@@ -186,8 +167,8 @@
}
}
- // Public ---------------------------------------------------------------------------------------
-
+ // ClientConnectionFactory implementation ---------------------------------------------
+
public String getServerLocatorURI()
{
return serverLocatorURI;
@@ -198,28 +179,38 @@
return serverID;
}
- public boolean getClientPing()
- {
- return clientPing;
- }
-
public Version getServerVersion()
{
return serverVersion;
}
- public boolean getStrictTck()
- {
- return strictTck;
- }
-
-
+ // Public ---------------------------------------------------------------------------------------
+
// Protected ------------------------------------------------------------------------------------
// Package Private ------------------------------------------------------------------------------
// Private --------------------------------------------------------------------------------------
+ private Version getVersionToUse(Version connectionVersion)
+ {
+ Version clientVersion = Version.instance();
+
+ Version versionToUse;
+
+ if (connectionVersion != null && connectionVersion.getProviderIncrementingVersion() <=
+ clientVersion.getProviderIncrementingVersion())
+ {
+ versionToUse = connectionVersion;
+ }
+ else
+ {
+ versionToUse = clientVersion;
+ }
+
+ return versionToUse;
+ }
+
// Inner Classes --------------------------------------------------------------------------------
}
Modified: trunk/src/main/org/jboss/jms/client/impl/ClientConnectionImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientConnectionImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConnectionImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -32,6 +32,7 @@
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
import javax.jms.ServerSessionPool;
+import javax.jms.Session;
import org.jboss.jms.client.JBossConnectionConsumer;
import org.jboss.jms.client.JBossConnectionMetaData;
@@ -40,23 +41,15 @@
import org.jboss.jms.client.remoting.ConsolidatedRemotingConnectionListener;
import org.jboss.jms.client.remoting.MessagingRemotingConnection;
import org.jboss.jms.destination.JBossDestination;
-import org.jboss.jms.tx.ResourceManager;
-import org.jboss.jms.tx.ResourceManagerFactory;
-import org.jboss.jms.tx.TransactionRequest;
import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
+import org.jboss.messaging.core.remoting.wireformat.ClosingMessage;
import org.jboss.messaging.core.remoting.wireformat.CreateSessionRequest;
import org.jboss.messaging.core.remoting.wireformat.CreateSessionResponse;
import org.jboss.messaging.core.remoting.wireformat.GetClientIDRequest;
import org.jboss.messaging.core.remoting.wireformat.GetClientIDResponse;
-import org.jboss.messaging.core.remoting.wireformat.GetPreparedTransactionsRequest;
-import org.jboss.messaging.core.remoting.wireformat.GetPreparedTransactionsResponse;
-import org.jboss.messaging.core.remoting.wireformat.SendTransactionMessage;
import org.jboss.messaging.core.remoting.wireformat.SetClientIDMessage;
import org.jboss.messaging.core.remoting.wireformat.StartConnectionMessage;
import org.jboss.messaging.core.remoting.wireformat.StopConnectionMessage;
-import org.jboss.messaging.core.tx.MessagingXid;
import org.jboss.messaging.util.Logger;
import org.jboss.messaging.util.Version;
@@ -100,15 +93,13 @@
private String clientID;
- private ResourceManager resourceManager;
-
private volatile boolean closed;
// Static ---------------------------------------------------------------------------------------
// Constructors ---------------------------------------------------------------------------------
- public ClientConnectionImpl(String id, int serverID, boolean strictTck, Version version, ResourceManager rm,
+ public ClientConnectionImpl(String id, int serverID, boolean strictTck, Version version,
MessagingRemotingConnection connection)
{
this.id = id;
@@ -119,8 +110,6 @@
this.versionToUse = version;
- this.resourceManager = rm;
-
this.remotingConnection = connection;
}
@@ -151,25 +140,20 @@
// Finished with the connection - we need to shutdown callback server
remotingConnection.stop();
- // And to resource manager
- ResourceManagerFactory.instance.checkInResourceManager(serverID);
-
closed = true;
}
}
- public synchronized long closing(long sequence) throws JMSException
+ public synchronized void closing() throws JMSException
{
if (closed)
{
- return -1;
+ return;
}
closeChildren();
- ClosingResponse response = (ClosingResponse)remotingConnection.sendBlocking(id, new ClosingRequest(sequence));
-
- return response.getID();
+ remotingConnection.sendBlocking(id, new ClosingMessage());
}
// ClientConnection implementation ------------------------------------------------------------
@@ -194,20 +178,35 @@
public ClientSession createClientSession(boolean transacted,
- int acknowledgmentMode,
- boolean isXA) throws JMSException
+ int acknowledgementMode,
+ boolean isXA) throws JMSException
{
checkClosed();
justCreated = false;
- CreateSessionRequest request = new CreateSessionRequest(transacted, acknowledgmentMode, isXA);
+ CreateSessionRequest request = new CreateSessionRequest(transacted, acknowledgementMode, isXA);
CreateSessionResponse response = (CreateSessionResponse)remotingConnection.sendBlocking(id, request);
- ClientSession session = new ClientSessionImpl(this, response.getSessionID(), response.getDupsOKBatchSize(), isStrictTck(),
- transacted, acknowledgmentMode, isXA);
+ int ackBatchSize;
+ if (transacted || acknowledgementMode == Session.CLIENT_ACKNOWLEDGE)
+ {
+ ackBatchSize = -1; //Infinite
+ }
+ else if (acknowledgementMode == Session.DUPS_OK_ACKNOWLEDGE)
+ {
+ ackBatchSize = response.getDupsOKBatchSize();
+ }
+ else
+ {
+ //Auto ack
+ ackBatchSize = 1;
+ }
+
+ ClientSession session = new ClientSessionImpl(this, response.getSessionID(), ackBatchSize, isXA);
+
children.put(response.getSessionID(), session);
return session;
@@ -262,13 +261,6 @@
return remotingConnection.getConnectionListener().getJMSExceptionListener();
}
- public void sendTransaction(TransactionRequest tr) throws JMSException
- {
- checkClosed();
-
- remotingConnection.sendBlocking(id, new SendTransactionMessage(tr));
- }
-
public void setClientID(String clientID) throws JMSException
{
checkClosed();
@@ -321,21 +313,6 @@
remotingConnection.sendBlocking(id, new StopConnectionMessage());
}
- public MessagingXid[] getPreparedTransactions() throws JMSException
- {
- checkClosed();
-
- GetPreparedTransactionsResponse response =
- (GetPreparedTransactionsResponse)remotingConnection.sendBlocking(id, new GetPreparedTransactionsRequest());
-
- return response.getXids();
- }
-
- public ResourceManager getResourceManager()
- {
- return resourceManager;
- }
-
public MessagingRemotingConnection getRemotingConnection()
{
return remotingConnection;
@@ -377,7 +354,7 @@
for (ClientSession session: childrenClone)
{
- session.closing(-1);
+ session.closing();
session.close();
}
}
Modified: trunk/src/main/org/jboss/jms/client/impl/ClientConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientConsumerImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConsumerImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,27 +21,22 @@
*/
package org.jboss.jms.client.impl;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
-import javax.jms.MessageListener;
-import org.jboss.jms.client.MessageHandler;
import org.jboss.jms.client.api.ClientConsumer;
import org.jboss.jms.client.api.ClientSession;
+import org.jboss.jms.client.api.MessageHandler;
import org.jboss.jms.client.remoting.MessagingRemotingConnection;
-import org.jboss.jms.message.JBossMessage;
import org.jboss.messaging.core.Destination;
+import org.jboss.messaging.core.Message;
import org.jboss.messaging.core.PriorityLinkedList;
import org.jboss.messaging.core.impl.PriorityLinkedListImpl;
import org.jboss.messaging.core.remoting.PacketDispatcher;
-import org.jboss.messaging.core.remoting.wireformat.ChangeRateMessage;
import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
+import org.jboss.messaging.core.remoting.wireformat.ClosingMessage;
+import org.jboss.messaging.core.remoting.wireformat.ConsumerChangeRateMessage;
+import org.jboss.messaging.core.remoting.wireformat.DeliverMessage;
import org.jboss.messaging.util.Future;
import org.jboss.messaging.util.Logger;
@@ -67,32 +62,25 @@
private static final boolean trace = log.isTraceEnabled();
- private static final int WAIT_TIMEOUT = 30000;
-
// Attributes -----------------------------------------------------------------------------------
private String id;
private ClientSession session;
private int bufferSize;
- private int maxDeliveries;
- private long redeliveryDelay;
private Destination destination;
private String selector;
private boolean noLocal;
- private boolean isConnectionConsumer;
- private PriorityLinkedList<JBossMessage> buffer = new PriorityLinkedListImpl<JBossMessage>(10);
+ private PriorityLinkedList<DeliverMessage> buffer = new PriorityLinkedListImpl<DeliverMessage>(10);
private volatile Thread receiverThread;
- private MessageListener listener;
+ private MessageHandler handler;
private volatile boolean closed;
private boolean closing;
private Object mainLock = new Object();
private QueuedExecutor sessionExecutor;
private boolean listenerRunning;
- private long lastDeliveryId = -1;
- private boolean waitingForLastDelivery;
private int consumeCount;
private MessagingRemotingConnection remotingConnection;
-
+
//FIXME - revisit closed and closing flags
// Static ---------------------------------------------------------------------------------------
@@ -100,24 +88,19 @@
// Constructors ---------------------------------------------------------------------------------
public ClientConsumerImpl(ClientSession session, String id, int bufferSize,
- int maxDeliveries, long redeliveryDelay,
Destination dest,
String selector, boolean noLocal,
- boolean isCC, QueuedExecutor sessionExecutor,
+ QueuedExecutor sessionExecutor,
MessagingRemotingConnection remotingConnection)
{
this.id = id;
this.session = session;
this.bufferSize = bufferSize;
- this.maxDeliveries = maxDeliveries;
- this.redeliveryDelay = redeliveryDelay;
this.destination = dest;
this.selector = selector;
this.noLocal = noLocal;
- this.isConnectionConsumer = isCC;
this.sessionExecutor = sessionExecutor;
- this.remotingConnection = remotingConnection;
-
+ this.remotingConnection = remotingConnection;
}
// Closeable implementation ---------------------------------------------------------------------
@@ -135,37 +118,59 @@
}
finally
{
- session.removeChild(id);
+ session.removeConsumer(this);
closed = true;
}
}
- public synchronized long closing(long sequence) throws JMSException
+ public synchronized void closing() throws JMSException
{
if (closed)
{
- return -1;
+ return;
}
+
+ try
+ {
+ remotingConnection.sendBlocking(id, new ClosingMessage());
+
+ //Important! We set the handler to null so the next ListenerRunner won't run
+ if (handler != null)
+ {
+ setMessageHandler(null);
+ }
+
+ //Now we wait for any current handler runners to run.
+ waitForOnMessageToComplete();
+
+ synchronized (mainLock)
+ {
+ if (closing)
+ {
+ return;
+ }
+
+ closing = true;
+
+ if (receiverThread != null)
+ {
+ // Wake up any receive() thread that might be waiting
+ mainLock.notify();
+ }
+
+ this.handler = null;
+ }
+
+ if (trace) { log.trace(this + " closed"); }
+ }
+ finally
+ {
+ session.removeConsumer(this);
+ }
- // We make sure closing is called on the ServerConsumerEndpoint.
- // This returns us the last delivery id sent
-
- ClosingRequest request = new ClosingRequest(sequence);
- ClosingResponse response = (ClosingResponse)remotingConnection.sendBlocking(id, request);
- long lastDeliveryId = response.getID();
-
- // First we call close on the ClientConsumer which waits for onMessage invocations
- // to complete and the last delivery to arrive
- close(lastDeliveryId);
-
PacketDispatcher.client.unregister(id);
-
- //And then we cancel any messages still in the message callback handler buffer
- cancelBuffer();
-
- return lastDeliveryId;
}
@@ -180,17 +185,17 @@
{
checkClosed();
- remotingConnection.sendOneWay(id, new ChangeRateMessage(newRate));
+ remotingConnection.sendOneWay(id, new ConsumerChangeRateMessage(newRate));
}
- public MessageListener getMessageListener() throws JMSException
+ public MessageHandler getMessageHandler() throws JMSException
{
checkClosed();
- return this.listener;
+ return handler;
}
- public void setMessageListener(MessageListener listener) throws JMSException
+ public void setMessageHandler(MessageHandler handler) throws JMSException
{
checkClosed();
@@ -203,9 +208,9 @@
"Cannot set MessageListener");
}
- this.listener = listener;
+ this.handler = handler;
- if (listener != null && !buffer.isEmpty())
+ if (handler != null && !buffer.isEmpty())
{
listenerRunning = true;
@@ -235,16 +240,6 @@
return this.selector;
}
- public int getMaxDeliveries()
- {
- return maxDeliveries;
- }
-
- public long getRedeliveryDelay()
- {
- return redeliveryDelay;
- }
-
/**
* Method used by the client thread to synchronously get a Message, if available.
*
@@ -253,11 +248,11 @@
* or null if one is not immediately available. Returns null if the consumer is
* concurrently closed.
*/
- public JBossMessage receive(long timeout) throws JMSException
+ public Message receive(long timeout) throws JMSException
{
checkClosed();
- JBossMessage m = null;
+ DeliverMessage m = null;
synchronized (mainLock)
{
@@ -270,7 +265,7 @@
return null;
}
- if (listener != null)
+ if (handler != null)
{
throw new JMSException("The consumer has a MessageListener set, " +
"cannot call receive(..)");
@@ -325,46 +320,17 @@
if (trace) { log.trace(this + " received " + m + " after being blocked on buffer"); }
- boolean ignore =
- MessageHandler.checkExpiredOrReachedMaxdeliveries(m, session, maxDeliveries);
+ boolean expired = m.getMessage().isExpired();
- if (!isConnectionConsumer && !ignore)
+ session.delivered(m.getDeliveryID(), expired);
+
+ if (!expired)
{
- DeliveryInfo info = new DeliveryInfo(m, id, null);
-
- session.preDeliver(info);
-
- //If post deliver didn't succeed and acknowledgement mode is auto_ack
- //That means the ref wasn't acked since it couldn't be found.
- //In order to maintain at most once semantics we must therefore not return
- //the message
-
- ignore = !session.postDeliver();
-
- if (trace)
- {
- log.trace("Post deliver returned " + !ignore);
- }
-
- if (!ignore)
- {
- m.incDeliveryCount();
- }
- }
-
- if (!ignore)
- {
- if (trace) { log.trace(this + ": message " + m + " is not expired, pushing it to the caller"); }
-
break;
}
+
+ if (trace) { log.trace("Message has expired " + m); }
- if (trace)
- {
- log.trace("Discarding message " + m);
- }
-
- // the message expired, so discard the message, adjust timeout and reenter the buffer
if (timeout != 0)
{
timeout -= System.currentTimeMillis() - startTimestamp;
@@ -382,27 +348,25 @@
receiverThread = null;
}
}
-
- if (trace) { log.trace(this + " receive() returning " + m); }
-
- return m;
+
+ return m.getMessage();
}
- public void addToFrontOfBuffer(JBossMessage proxy) throws JMSException
- {
- checkClosed();
-
- synchronized (mainLock)
- {
- buffer.addFirst(proxy, proxy.getJMSPriority());
-
- consumeCount--;
-
- messageAdded();
- }
- }
+// public void addToFrontOfBuffer(JBossMessage proxy) throws JMSException
+// {
+// checkClosed();
+//
+// synchronized (mainLock)
+// {
+// buffer.addFirst(proxy, proxy.getJMSPriority());
+//
+// consumeCount--;
+//
+// messageAdded();
+// }
+// }
- public void handleMessage(final JBossMessage message) throws Exception
+ public void handleMessage(final DeliverMessage message) throws Exception
{
synchronized (mainLock)
{
@@ -412,22 +376,48 @@
// when closing
throw new IllegalStateException(this + " is closed, so ignoring message");
}
+
+ if (ignoreDeliveryMark >= 0)
+ {
+ long delID = message.getDeliveryID();
+
+ if (delID > ignoreDeliveryMark)
+ {
+ //Ignore - the session is recovering and these are inflight messages
+ return;
+ }
+ else
+ {
+ //We have hit the begining of the recovered messages - we can stop ignoring
+ ignoreDeliveryMark = -1;
+ }
+ }
+
+ //Add it to the buffer
+ Message coreMessage = message.getMessage();
+
+ coreMessage.setDeliveryCount(message.getDeliveryCount());
+
+ buffer.addLast(message, coreMessage.getPriority());
- message.setSession(session, isConnectionConsumer);
-
- message.doBeforeReceive();
-
- //Add it to the buffer
- buffer.addLast(message, message.getJMSPriority());
-
- lastDeliveryId = message.getDeliveryId();
-
if (trace) { log.trace(this + " added message(s) to the buffer are now " + buffer.size() + " messages"); }
messageAdded();
}
}
+ private long ignoreDeliveryMark = -1;
+
+ public void recover(long lastDeliveryID)
+ {
+ synchronized (mainLock)
+ {
+ ignoreDeliveryMark = lastDeliveryID;
+
+ buffer.clear();
+ }
+ }
+
// Public ---------------------------------------------------------------------------------------
// Package protected ----------------------------------------------------------------------------
@@ -436,92 +426,6 @@
// Private --------------------------------------------------------------------------------------
- private void close(long lastDeliveryId) throws JMSException
- {
- try
- {
- log.trace(this + " close");
-
- //Wait for the last delivery to arrive
- waitForLastDelivery(lastDeliveryId);
-
- //Important! We set the listener to null so the next ListenerRunner won't run
- if (listener != null)
- {
- setMessageListener(null);
- }
-
- //Now we wait for any current listener runners to run.
- waitForOnMessageToComplete();
-
- synchronized (mainLock)
- {
- if (closing)
- {
- return;
- }
-
- closing = true;
-
- if (receiverThread != null)
- {
- // Wake up any receive() thread that might be waiting
- mainLock.notify();
- }
-
- this.listener = null;
- }
-
- if (trace) { log.trace(this + " closed"); }
- }
- finally
- {
- session.removeChild(id);
- }
- }
-
- private void cancelBuffer() throws JMSException
- {
- if (trace) { log.trace("Cancelling buffer: " + buffer.size()); }
-
- synchronized (mainLock)
- {
- // Now we cancel anything left in the buffer. The reason we do this now is that otherwise
- // the deliveries wouldn't get cancelled until session close (since we don't cancel
- // consumer's deliveries until then), which is too late - since we need to preserve the
- // order of messages delivered in a session.
-
- if (!buffer.isEmpty())
- {
- // Now we cancel any deliveries that might be waiting in our buffer. This is because
- // otherwise the messages wouldn't get cancelled until the corresponding session died.
- // So if another consumer in another session tried to consume from the channel before
- // that session died it wouldn't receive those messages.
- // We can't just cancel all the messages in the SCE since some of those messages might
- // have actually been delivered (unlike these) and we may want to acknowledge them
- // later, after this consumer has been closed
-
- List cancels = new ArrayList();
-
- for(Iterator i = buffer.iterator(); i.hasNext();)
- {
- JBossMessage mp = (JBossMessage)i.next();
-
- CancelImpl cancel =
- new CancelImpl(mp.getDeliveryId(), mp.getDeliveryCount(), false, false);
-
- cancels.add(cancel);
- }
-
- if (trace) { log.trace("Calling cancelDeliveries"); }
- session.cancelDeliveries(cancels);
- if (trace) { log.trace("Done call"); }
-
- buffer.clear();
- }
- }
- }
-
private void checkSendChangeRate()
{
consumeCount++;
@@ -533,55 +437,7 @@
sendChangeRateMessage(1.0f);
}
}
-
- /*
- * Wait for the last delivery to arrive
- */
- private void waitForLastDelivery(long id)
- {
- if (trace) { log.trace("Waiting for last delivery id " + id); }
-
- if (id == -1)
- {
- //No need to wait - nothing to wait for
- return;
- }
-
- synchronized (mainLock)
- {
- waitingForLastDelivery = true;
- try
- {
- long wait = WAIT_TIMEOUT;
- while (lastDeliveryId != id && wait > 0)
- {
- long start = System.currentTimeMillis();
- try
- {
- mainLock.wait(wait);
- }
- catch (InterruptedException e)
- {
- }
- wait -= (System.currentTimeMillis() - start);
- }
- if (trace && lastDeliveryId == id)
- {
- log.trace("Got last delivery");
- }
-
- if (lastDeliveryId != id)
- {
- log.warn("Timed out waiting for last delivery " + id + " got " + lastDeliveryId);
- }
- }
- finally
- {
- waitingForLastDelivery = false;
- }
- }
- }
-
+
private void sendChangeRateMessage(float newRate)
{
try
@@ -636,7 +492,7 @@
{
boolean notified = false;
- if (trace) { log.trace("Receiver thread:" + receiverThread + " listener:" + listener + " listenerRunning:" + listenerRunning +
+ if (trace) { log.trace("Receiver thread:" + receiverThread + " handler:" + handler + " listenerRunning:" + listenerRunning +
" sessionExecutor:" + sessionExecutor); }
// If we have a thread waiting on receive() we notify it
@@ -648,9 +504,9 @@
notified = true;
}
- else if (listener != null)
+ else if (handler != null)
{
- // We have a message listener
+ // We have a message handler
if (!listenerRunning)
{
listenerRunning = true;
@@ -664,7 +520,7 @@
}
// Make sure we notify any thread waiting for last delivery
- if (waitingForLastDelivery && !notified)
+ if (!notified)
{
if (trace) { log.trace("Notifying"); }
@@ -693,7 +549,7 @@
}
}
- private JBossMessage getMessage(long timeout)
+ private DeliverMessage getMessage(long timeout)
{
if (timeout == -1)
{
@@ -737,11 +593,11 @@
}
}
- JBossMessage m = null;
+ DeliverMessage m = null;
if (!closing && !buffer.isEmpty())
{
- m = (JBossMessage)buffer.removeFirst();
+ m = buffer.removeFirst();
checkSendChangeRate();
}
@@ -760,7 +616,7 @@
// Inner classes --------------------------------------------------------------------------------
/*
- * This class is used to put on the listener executor to wait for onMessage
+ * This class is used to put on the handler executor to wait for onMessage
* invocations to complete when closing
*/
private class Closer implements Runnable
@@ -789,26 +645,26 @@
{
public void run()
{
- JBossMessage msg = null;
+ DeliverMessage msg = null;
- MessageListener theListener = null;
+ MessageHandler theListener = null;
synchronized (mainLock)
{
- if (listener == null || buffer.isEmpty())
+ if (handler == null || buffer.isEmpty())
{
listenerRunning = false;
- if (trace) { log.trace("no listener or buffer is empty, returning"); }
+ if (trace) { log.trace("no handler or buffer is empty, returning"); }
return;
}
- theListener = listener;
+ theListener = handler;
// remove a message from the buffer
- msg = (JBossMessage)buffer.removeFirst();
+ msg = buffer.removeFirst();
checkSendChangeRate();
}
@@ -820,22 +676,19 @@
* and failover will kick in, this will clear the executor
* so the next queud one disappears at everything grinds to a halt
*
- * Solution - don't use a session executor - have a sesion thread instead much nicer
+ * Solution - don't use a session executor - have a session thread instead much nicer
*/
if (msg != null)
- {
- try
+ {
+ boolean expired = msg.getMessage().isExpired();
+
+ session.delivered(msg.getDeliveryID(), expired);
+
+ if (!expired)
{
- MessageHandler.callOnMessage(session, theListener, id,
- false, msg, session.getAcknowledgeMode(), maxDeliveries, null);
-
- if (trace) { log.trace("Called callonMessage"); }
+ theListener.onMessage(msg.getMessage());
}
- catch (Throwable t)
- {
- log.error("Failed to deliver message", t);
- }
}
synchronized (mainLock)
@@ -852,7 +705,7 @@
}
else
{
- if (trace) { log.trace("no more messages in buffer, marking listener as not running"); }
+ if (trace) { log.trace("no more messages in buffer, marking handler as not running"); }
listenerRunning = false;
}
Modified: trunk/src/main/org/jboss/jms/client/impl/ClientConsumerPacketHandler.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientConsumerPacketHandler.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientConsumerPacketHandler.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -28,6 +28,7 @@
String consumerID)
{
this.clientConsumer = clientConsumer;
+
this.consumerID = consumerID;
}
@@ -45,13 +46,10 @@
{
DeliverMessage message = (DeliverMessage) packet;
- JBossMessage msg = JBossMessage.createMessage(message.getMessage(), message.getDeliveryID(), message.getDeliveryCount());
-
- msg.doBeforeReceive();
-
- clientConsumer.handleMessage(msg);
+ clientConsumer.handleMessage(message);
}
- } catch (Exception e)
+ }
+ catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
Modified: trunk/src/main/org/jboss/jms/client/impl/ClientProducerImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientProducerImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientProducerImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -110,14 +110,13 @@
{
return;
}
- session.removeChild(id);
+ session.removeProducer(this);
closed = true;
}
- public synchronized long closing(long sequence) throws JMSException
- {
- return -1;
+ public synchronized void closing() throws JMSException
+ {
}
public JBossDestination getDestination() throws JMSException
Modified: trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/ClientSessionImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,22 +21,16 @@
*/
package org.jboss.jms.client.impl;
-import java.io.Serializable;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
-import javax.jms.Session;
import javax.jms.TransactionInProgressException;
import javax.transaction.xa.XAResource;
-import org.jboss.jms.client.Closeable;
import org.jboss.jms.client.SelectorTranslator;
import org.jboss.jms.client.api.ClientBrowser;
import org.jboss.jms.client.api.ClientConnection;
@@ -47,28 +41,12 @@
import org.jboss.jms.destination.JBossDestination;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
-import org.jboss.jms.message.JBossBytesMessage;
-import org.jboss.jms.message.JBossMapMessage;
-import org.jboss.jms.message.JBossMessage;
-import org.jboss.jms.message.JBossObjectMessage;
-import org.jboss.jms.message.JBossStreamMessage;
-import org.jboss.jms.message.JBossTextMessage;
-import org.jboss.jms.tx.LocalTx;
-import org.jboss.jms.tx.MessagingXAResource;
-import org.jboss.jms.tx.ResourceManager;
import org.jboss.messaging.core.Destination;
-import org.jboss.messaging.core.DestinationType;
import org.jboss.messaging.core.Message;
import org.jboss.messaging.core.remoting.PacketDispatcher;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveriesMessage;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryRequest;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryResponse;
import org.jboss.messaging.core.remoting.wireformat.AddTemporaryDestinationMessage;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveriesMessage;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveryMessage;
import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
+import org.jboss.messaging.core.remoting.wireformat.ClosingMessage;
import org.jboss.messaging.core.remoting.wireformat.CreateBrowserRequest;
import org.jboss.messaging.core.remoting.wireformat.CreateBrowserResponse;
import org.jboss.messaging.core.remoting.wireformat.CreateConsumerRequest;
@@ -76,7 +54,11 @@
import org.jboss.messaging.core.remoting.wireformat.CreateDestinationRequest;
import org.jboss.messaging.core.remoting.wireformat.CreateDestinationResponse;
import org.jboss.messaging.core.remoting.wireformat.DeleteTemporaryDestinationMessage;
-import org.jboss.messaging.core.remoting.wireformat.SendMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionAcknowledgeMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionCancelMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionCommitMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionRollbackMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionSendMessage;
import org.jboss.messaging.core.remoting.wireformat.UnsubscribeMessage;
import org.jboss.messaging.util.ClearableQueuedExecutor;
import org.jboss.messaging.util.Logger;
@@ -105,73 +87,56 @@
private String id;
- private int dupsOKBatchSize;
+ private boolean xa;
+
+ private int lazyAckBatchSize;
- private boolean strictTck;
+ private XAResource xaResource;
+
+ private volatile boolean closed;
+
+ private boolean acked = true;
- private ClientConnection connection;
+ private boolean broken;
- private Map<String, Closeable> children = new ConcurrentHashMap<String, Closeable>();
+ private long toAckCount;
- private int acknowledgeMode;
+ private long lastID = -1;
- private boolean transacted;
+ private long deliverID;
- private boolean xa;
+ private boolean deliveryExpired;
- private MessagingXAResource xaResource;
-
- private Object currentTxId;
-
// Executor used for executing onMessage methods
private ClearableQueuedExecutor executor;
- private boolean recoverCalled;
+ private MessagingRemotingConnection remotingConnection;
+
+ private ClientConnection connection;
- private List<Ack> clientAckList = new ArrayList<Ack>();
-
- private DeliveryInfo autoAckInfo;
-
- //This is somewhat strange - but some of the MQ and TCK tests expect an XA session to behavior as AUTO_ACKNOWLEDGE when not enlisted in
- //a transaction
- //This is the opposite behavior as what is required when the XA session handles MDB delivery or when using the message bridge.
- //In that case we want it to act as transacted, so when the session is subsequently enlisted the work can be converted into the
- //XA transaction
- private boolean treatAsNonTransactedWhenNotEnlisted = true;
+ private Set<ClientBrowser> browsers = new HashSet<ClientBrowser>();
- private long npSendSequence;
+ private Set<ClientProducer> producers = new HashSet<ClientProducer>();
- private MessagingRemotingConnection remotingConnection;
+ private Map<String, ClientConsumer> consumers = new HashMap<String, ClientConsumer>();
- private volatile boolean closed;
-
+
// Constructors ---------------------------------------------------------------------------------
- public ClientSessionImpl(ClientConnection connection, String id, int dupsOKBatchSize, boolean strictTCK,
- boolean transacted, int acknowledgmentMode, boolean xa)
+ public ClientSessionImpl(ClientConnection connection, String id,
+ int lazyAckBatchSize, boolean xa)
{
this.id = id;
+
this.connection = connection;
+
this.remotingConnection = connection.getRemotingConnection();
- this.dupsOKBatchSize = dupsOKBatchSize;
- this.strictTck = strictTCK;
- this.transacted = transacted;
- this.xa = xa;
- this.acknowledgeMode = acknowledgmentMode;
+ this.xa = xa;
+
executor = new ClearableQueuedExecutor(new LinkedQueue());
- if (xa)
- {
- // Create an XA resource
- xaResource = new MessagingXAResource(connection.getResourceManager(), this);
- }
-
- if (transacted)
- {
- // Create a local tx
- currentTxId = connection.getResourceManager().createLocalTx();
- }
+ this.lazyAckBatchSize = lazyAckBatchSize;
}
// ClientSession implementation ----------------------------------------------------
@@ -192,16 +157,6 @@
{
remotingConnection.sendBlocking(id, new CloseMessage());
- Object xid = getCurrentTxId();
-
- if (xid != null)
- {
- //Remove transaction from the resource manager
- connection.getResourceManager().removeTx(xid);
- }
-
- // We must explicitly shutdown the executor
-
executor.shutdownNow();
}
finally
@@ -212,113 +167,22 @@
}
}
- public long closing(long sequence) throws JMSException
+ public void closing() throws JMSException
{
if (closed)
{
- return -1;
+ return;
}
- if (trace) { log.trace("handleClosing()"); }
-
closeChildren();
- //Sanity check
- if (isXA() && !isXAAndConsideredNonTransacted())
- {
- if (trace) { log.trace("Session is XA"); }
-
- ResourceManager rm = connection.getResourceManager();
-
- // An XASession should never be closed if there is prepared ack work that has not yet been
- // committed or rolled back. Imagine if messages had been consumed in the session, and
- // prepared but not committed. Then the connection was explicitly closed causing the
- // session to close. Closing the session causes any outstanding delivered but unacked
- // messages to be cancelled to the server which means they would be available for other
- // consumers to consume. If another consumer then consumes them, then recover() is called
- // and the original transaction is committed, then this means the same message has been
- // delivered twice which breaks the once and only once delivery guarantee.
-
- if (rm.checkForAcksInSession(this.getID()))
- {
- throw new javax.jms.IllegalStateException(
- "Attempt to close an XASession when there are still uncommitted acknowledgements!");
- }
- }
-
- int ackMode = getAcknowledgeMode();
-
- //We need to either ack (for auto_ack) or cancel (for client_ack)
- //any deliveries - this is because the message listener might have closed
- //before on message had finished executing
-
- if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
- {
- //Acknowledge or cancel any outstanding auto ack
-
- if (autoAckInfo != null)
- {
- if (trace) { log.trace(this + " handleClosing(). Found remaining auto ack. Will ack " + autoAckInfo); }
-
- try
- {
- ackDelivery(autoAckInfo);
-
- if (trace) { log.trace(this + " acked it"); }
- }
- finally
- {
- autoAckInfo = null;
- }
- }
- }
- else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
- {
- //Ack any remaining deliveries
-
- if (!clientAckList.isEmpty())
- {
- try
- {
- acknowledgeDeliveries(clientAckList);
- }
- finally
- {
- clientAckList.clear();
-
- autoAckInfo = null;
- }
- }
- }
- else if (ackMode == Session.CLIENT_ACKNOWLEDGE)
- {
- // Cancel any oustanding deliveries
- // We cancel any client ack or transactional, we do this explicitly so we can pass the
- // updated delivery count information from client to server. We could just do this on the
- // server but we would lose delivery count info.
-
- // CLIENT_ACKNOWLEDGE cannot be used with MDBs (i.e. no connection consumer)
- // so is always safe to cancel on this session
-
- internalCancelDeliveries(clientAckList);
-
- clientAckList.clear();
- }
- else if (isTransacted() && !isXA())
- {
- //We need to explicitly cancel any deliveries back to the server
- //from the resource manager, otherwise delivery count won't be updated
-
- List dels = connection.getResourceManager().getDeliveriesForSession(this.getID());
-
- internalCancelDeliveries(dels);
- }
-
- ClosingRequest request = new ClosingRequest(npSendSequence);
+ //Make sure any remaining acks make it to the server
- ClosingResponse response = (ClosingResponse)remotingConnection.sendBlocking(id, request);
+ acknowledgeInternal(false);
+
+ ClosingMessage request = new ClosingMessage();
- return response.getID();
+ remotingConnection.sendBlocking(id, request);
}
public ClientConnection getConnection()
@@ -326,70 +190,51 @@
return connection;
}
- public boolean acknowledgeDelivery(Ack ack) throws JMSException
+ public void addTemporaryDestination(Destination destination) throws JMSException
{
checkClosed();
- AcknowledgeDeliveryRequest request = new AcknowledgeDeliveryRequest(ack.getDeliveryID());
-
- AcknowledgeDeliveryResponse response =
- (AcknowledgeDeliveryResponse)remotingConnection.sendBlocking(id, request);
-
- return response.isAcknowledged();
+ remotingConnection.sendBlocking(id, new AddTemporaryDestinationMessage(destination));
}
- public void acknowledgeDeliveries(List<Ack> acks) throws JMSException
+ public void commit() throws JMSException
{
checkClosed();
-
- remotingConnection.sendBlocking(id, new AcknowledgeDeliveriesMessage(acks));
- }
-
- public void acknowledgeAll() throws JMSException
- {
- checkClosed();
-
- if (!clientAckList.isEmpty())
+
+ if (isXA())
{
- //CLIENT_ACKNOWLEDGE can't be used with a MDB so it is safe to always acknowledge all
- //on this session (rather than the connection consumer session)
- acknowledgeDeliveries(clientAckList);
-
- clientAckList.clear();
+ throw new TransactionInProgressException("Cannot call commit on an XA session");
}
- }
- public void addTemporaryDestination(Destination destination) throws JMSException
- {
- checkClosed();
+ //Before committing we must make sure the acks make it to the server
+ //instead of this we could possibly add the lastDeliveryID in the SessionCommitMessage
+ acknowledgeInternal(false);
- remotingConnection.sendBlocking(id, new AddTemporaryDestinationMessage(destination));
+ remotingConnection.sendBlocking(id, new SessionCommitMessage());
}
-
- public void commit() throws JMSException
+
+ public void rollback() throws JMSException
{
checkClosed();
-
- if (!isTransacted())
- {
- throw new IllegalStateException("Cannot commit a non-transacted session");
- }
-
+
if (isXA())
{
- throw new TransactionInProgressException("Cannot call commit on an XA session");
+ throw new TransactionInProgressException("Cannot call rollback on an XA session");
}
-
- try
+
+ //First we tell each consumer to clear it's buffers and ignore any deliveries with
+ //delivery id > last delivery id
+
+ for (ClientConsumer consumer: consumers.values())
{
- connection.getResourceManager().commitLocal((LocalTx)getCurrentTxId(), connection);
+ consumer.recover(lastID + 1);
}
- finally
- {
- //Start new local tx
- setCurrentTxId( connection.getResourceManager().createLocalTx() );
- }
+
+ //Before rolling back we must make sure the acks make it to the server
+ //instead of this we could possibly add the lastDeliveryID in the SessionRollbackMessage
+ acknowledgeInternal(false);
+ remotingConnection.sendBlocking(id, new SessionRollbackMessage());
}
public ClientBrowser createClientBrowser(Destination queue, String messageSelector)
@@ -405,32 +250,30 @@
ClientBrowser browser = new ClientBrowserImpl(remotingConnection, this, response.getBrowserID());
- children.put(response.getBrowserID(), browser);
+ browsers.add(browser);
return browser;
}
public ClientConsumer createClientConsumer(Destination destination, String selector,
- boolean noLocal, String subscriptionName,
- boolean isCC) throws JMSException
+ boolean noLocal, String subscriptionName) throws JMSException
{
checkClosed();
String coreSelector = SelectorTranslator.convertToJBMFilterString(selector);
CreateConsumerRequest request =
- new CreateConsumerRequest(destination, coreSelector, noLocal, subscriptionName, isCC);
+ new CreateConsumerRequest(destination, coreSelector, noLocal, subscriptionName, false);
CreateConsumerResponse response = (CreateConsumerResponse)remotingConnection.sendBlocking(id, request);
ClientConsumer consumer =
- new ClientConsumerImpl(this, response.getConsumerID(), response.getBufferSize(),
- response.getMaxDeliveries(), response.getRedeliveryDelay(),
- destination,
- selector, noLocal,
- isCC, executor, remotingConnection);
+ new ClientConsumerImpl(this, response.getConsumerID(), response.getBufferSize(),
+ destination,
+ selector, noLocal,
+ executor, remotingConnection);
- children.put(response.getConsumerID(), consumer);
+ consumers.put(response.getConsumerID(), consumer);
PacketDispatcher.client.register(new ClientConsumerPacketHandler(consumer, response.getConsumerID()));
@@ -441,60 +284,13 @@
return consumer;
}
- public JBossBytesMessage createBytesMessage() throws JMSException
- {
- checkClosed();
-
- JBossBytesMessage jbm = new JBossBytesMessage();
-
- return jbm;
- }
-
- public JBossMapMessage createMapMessage() throws JMSException
- {
- checkClosed();
-
- JBossMapMessage jbm = new JBossMapMessage();
-
- return jbm;
- }
-
- public JBossMessage createMessage() throws JMSException
- {
- checkClosed();
-
- JBossMessage jbm = new JBossMessage();
-
- return jbm;
- }
-
- public JBossObjectMessage createObjectMessage() throws JMSException
- {
- checkClosed();
-
- JBossObjectMessage jbm = new JBossObjectMessage();
-
- return jbm;
- }
-
- public JBossObjectMessage createObjectMessage(Serializable object) throws JMSException
- {
- checkClosed();
-
- JBossObjectMessage jbm = new JBossObjectMessage();
-
- jbm.setObject(object);
-
- return jbm;
- }
-
public ClientProducer createClientProducer(JBossDestination destination) throws JMSException
{
checkClosed();
ClientProducer producer = new ClientProducerImpl(this, destination);
- children.put(producer.getID(), producer);
+ producers.add(producer);
return producer;
}
@@ -510,35 +306,6 @@
return (JBossQueue) response.getDestination();
}
- public JBossStreamMessage createStreamMessage() throws JMSException
- {
- checkClosed();
-
- JBossStreamMessage jbm = new JBossStreamMessage();
-
- return jbm;
- }
-
- public JBossTextMessage createTextMessage() throws JMSException
- {
- checkClosed();
-
- JBossTextMessage jbm = new JBossTextMessage();
-
- return jbm;
- }
-
- public JBossTextMessage createTextMessage(String text) throws JMSException
- {
- checkClosed();
-
- JBossTextMessage jbm = new JBossTextMessage();
-
- jbm.setText(text);
-
- return jbm;
- }
-
public JBossTopic createTopic(String topicName) throws JMSException
{
checkClosed();
@@ -556,263 +323,86 @@
remotingConnection.sendBlocking(id, new DeleteTemporaryDestinationMessage(destination));
}
-
- public boolean postDeliver() throws JMSException
+
+ //Internal method to be called from consumerImpl - should not expose this publicly
+ public void delivered(long deliverID, boolean expired)
{
- checkClosed();
+ this.deliverID = deliverID;
- int ackMode = getAcknowledgeMode();
-
- boolean res = true;
-
- // if XA and there is no transaction enlisted on XA we will act as AutoAcknowledge
- // However if it's a MDB (if there is a DistinguishedListener) we should behaved as transacted
- if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
+ this.deliveryExpired = expired;
+ }
+
+ //Called after a message has been delivered
+ public void delivered() throws JMSException
+ {
+ if (lastID + 1 != deliverID)
{
- // It is possible that session.recover() is called inside a message listener onMessage
- // method - i.e. between the invocations of preDeliver and postDeliver. In this case we
- // don't want to acknowledge the last delivered messages - since it will be redelivered.
- if (!recoverCalled)
- {
- if (autoAckInfo == null)
- {
- throw new IllegalStateException("Cannot find delivery to AUTO_ACKNOWLEDGE");
- }
-
- if (trace) { log.trace(this + " auto acknowledging delivery " + autoAckInfo); }
-
- // We clear the state in a finally so then we don't get a knock on
- // exception on the next ack since we haven't cleared the state. See
- // http://jira.jboss.org/jira/browse/JBMESSAGING-852
-
- //This is ok since the message is acked after delivery, then the client
- //could get duplicates anyway
-
- try
- {
- res = ackDelivery(autoAckInfo);
- }
- finally
- {
- autoAckInfo = null;
- }
- }
- else
- {
- if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }
-
- recoverCalled = false;
- }
+ broken = true;
}
- else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
+
+ lastID = deliverID;
+
+ toAckCount++;
+
+ acked = false;
+
+ if (deliveryExpired)
{
- if (!recoverCalled)
- {
- if (clientAckList.size() >= getDupsOKBatchSize())
- {
- // We clear the state in a finally
- // http://jira.jboss.org/jira/browse/JBMESSAGING-852
-
- try
- {
- acknowledgeDeliveries(clientAckList);
- }
- finally
- {
- clientAckList.clear();
-
- autoAckInfo = null;
- }
- }
- }
- else
- {
- if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }
-
- recoverCalled = false;
- }
+ remotingConnection.sendOneWay(id, new SessionCancelMessage(lastID, true));
- autoAckInfo = null;
+ toAckCount = 0;
}
-
- return Boolean.valueOf(res);
- }
-
- public void preDeliver(DeliveryInfo info) throws JMSException
- {
- checkClosed();
-
- int ackMode = getAcknowledgeMode();
-
- if (ackMode == Session.CLIENT_ACKNOWLEDGE)
+ else if (broken)
{
- // We collect acknowledgments in the list
-
- if (trace) { log.trace(this + " added to CLIENT_ACKNOWLEDGE list delivery " + info); }
-
- // Sanity check
- if (info.getConnectionConsumerSession() != null)
- {
- throw new IllegalStateException(
- "CLIENT_ACKNOWLEDGE cannot be used with a connection consumer");
- }
-
- clientAckList.add(info);
+ //Must always ack now
+ acknowledgeInternal(false);
+
+ toAckCount = 0;
}
- // if XA and there is no transaction enlisted on XA we will act as AutoAcknowledge
- // However if it's a MDB (if there is a DistinguishedListener) we should behaved as transacted
- else if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
- {
- // We collect the single acknowledgement in the state.
-
- if (trace) { log.trace(this + " added " + info + " to session state"); }
-
- autoAckInfo = info;
- }
- else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
- {
- if (trace) { log.trace(this + " added to DUPS_OK_ACKNOWLEDGE list delivery " + info); }
-
- clientAckList.add(info);
-
- //Also set here - this would be used for recovery in a message listener
- autoAckInfo = info;
- }
else
{
- Object txID = getCurrentTxId();
-
- if (txID != null)
+ if (toAckCount == lazyAckBatchSize)
{
- // the session is non-XA and transacted, or XA and enrolled in a global transaction. An
- // XA session that has not been enrolled in a global transaction behaves as a
- // transacted session.
-
- if (trace) { log.trace("sending acknowlegment transactionally, queueing on resource manager"); }
-
- // If the ack is for a delivery that came through via a connection consumer then we use
- // the connectionConsumer session as the session id, otherwise we use this sessions'
- // session ID
-
-
- ClientSession connectionConsumerSession =
- info.getConnectionConsumerSession();
-
- String sessionId = connectionConsumerSession != null ?
- connectionConsumerSession.getID() : this.getID();
-
- connection.getResourceManager().addAck(txID, sessionId, info);
- }
- }
+ acknowledgeInternal(false);
+
+ toAckCount = 0;
+ }
+ }
}
-
- public void recover() throws JMSException
+
+ private void acknowledgeInternal(boolean block) throws JMSException
{
- checkClosed();
-
- if (isTransacted() && !isXAAndConsideredNonTransacted())
+ if (acked)
{
- throw new IllegalStateException("Cannot recover a transacted session");
+ return;
}
-
- if (trace) { log.trace("recovering the session"); }
-
- int ackMode = getAcknowledgeMode();
-
- if (ackMode == Session.CLIENT_ACKNOWLEDGE)
+
+ if (broken)
{
- List<Ack> dels = clientAckList;
-
- clientAckList = new ArrayList<Ack>();
-
- redeliver(dels);
-
- recoverCalled = true;
- }
- else if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE || isXAAndConsideredNonTransacted())
- {
- //Don't recover if it's already to cancel
-
- if (autoAckInfo != null)
+ if (block)
{
- List<Ack> redels = new ArrayList<Ack>();
-
- redels.add(autoAckInfo);
-
- redeliver(redels);
-
- autoAckInfo = null;
-
- recoverCalled = true;
+ remotingConnection.sendBlocking(id, new SessionAcknowledgeMessage(lastID, false));
}
+ else
+ {
+ remotingConnection.sendOneWay(id, new SessionAcknowledgeMessage(lastID, false));
+ }
}
- }
-
- public void redeliver(List toRedeliver) throws JMSException
- {
- checkClosed();
-
- // We put the messages back in the front of their appropriate consumer buffers
-
- if (trace) { log.trace(this + " handleRedeliver() called: " + toRedeliver); }
-
- // Need to be redelivered in reverse order.
- for (int i = toRedeliver.size() - 1; i >= 0; i--)
+ else
{
- DeliveryInfo info = (DeliveryInfo)toRedeliver.get(i);
- JBossMessage msg = info.getMessage();
-
- ClientConsumer handler = (ClientConsumer)children.get(info.getConsumerId());
-
- if (handler == null)
+ if (block)
{
- // This is ok. The original consumer has closed, so we cancel the message
-
- cancelDelivery(info);
+ remotingConnection.sendBlocking(id, new SessionAcknowledgeMessage(lastID, true));
}
- else if (handler.getRedeliveryDelay() != 0)
- {
- //We have a redelivery delay in action - all delayed redeliveries are handled on the server
-
- cancelDelivery(info);
- }
else
{
- if (trace) { log.trace("Adding proxy back to front of buffer"); }
-
- handler.addToFrontOfBuffer(msg);
+ remotingConnection.sendOneWay(id, new SessionAcknowledgeMessage(lastID, true));
}
}
-
- }
-
- public void rollback() throws JMSException
- {
- checkClosed();
- if (!isTransacted())
- {
- throw new IllegalStateException("Cannot rollback a non-transacted session");
- }
-
- if (isXA())
- {
- throw new TransactionInProgressException("Cannot call rollback on an XA session");
- }
-
- ResourceManager rm = connection.getResourceManager();
- try
- {
- rm.rollbackLocal(getCurrentTxId());
- }
- finally
- {
- // startnew local tx
- Object xid = rm.createLocalTx();
- setCurrentTxId(xid);
- }
+ acked = true;
}
-
+
public void unsubscribe(String subscriptionName) throws JMSException
{
checkClosed();
@@ -825,78 +415,45 @@
return xaResource;
}
- public int getAcknowledgeMode() throws JMSException
- {
- checkClosed();
-
- return acknowledgeMode;
- }
-
public void send(Message m) throws JMSException
{
checkClosed();
- Object txID = getCurrentTxId();
-
- // If there is no GlobalTransaction we run it as local transacted
- // as discussed at http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577
- // http://jira.jboss.org/jira/browse/JBMESSAGING-946
- // and
- // http://jira.jboss.org/jira/browse/JBMESSAGING-410
- if ((!isXA() && isTransacted()) || (isXA() && !(txID instanceof LocalTx)))
+ SessionSendMessage message = new SessionSendMessage(m);
+
+ if (m.isDurable())
{
- // the session is non-XA and transacted, or XA and enrolled in a global transaction, so
- // we add the message to a transaction instead of sending it now. An XA session that has
- // not been enrolled in a global transaction behaves as a non-transacted session.
-
- if (trace) { log.trace("sending message " + m + " transactionally, queueing on resource manager txID=" + txID + " sessionID= " + getID()); }
-
- connection.getResourceManager().addMessage(txID, this.getID(), m);
-
- // ... and we don't invoke any further interceptors in the stack
- return;
+ remotingConnection.sendBlocking(id, message);
}
-
- if (trace) { log.trace("sending message NON-transactionally"); }
-
- invokeSend(m);
+ else
+ {
+ remotingConnection.sendOneWay(id, message);
+ }
}
- public void removeChild(String key) throws JMSException
+ public void removeConsumer(ClientConsumer consumer) throws JMSException
{
- checkClosed();
+ consumers.remove(consumer.getID());
+
+ //1. flush any unacked message to the server
- children.remove(key);
- }
-
- public void cancelDeliveries(List<Cancel> cancels) throws JMSException
- {
- checkClosed();
+ acknowledgeInternal(false);
- remotingConnection.sendBlocking(id, new CancelDeliveriesMessage(cancels));
+ //2. cancel all deliveries on server but not in tx
+
+ remotingConnection.sendBlocking(id, new SessionCancelMessage(-1, false));
}
-
- public void cancelDelivery(Cancel cancel) throws JMSException
+
+ public void removeProducer(ClientProducer producer)
{
- checkClosed();
-
- remotingConnection.sendBlocking(id, new CancelDeliveryMessage(cancel));
+ producers.remove(producer);
}
- public int getDupsOKBatchSize() throws JMSException
+ public void removeBrowser(ClientBrowser browser)
{
- checkClosed();
-
- return dupsOKBatchSize;
+ browsers.remove(browser);
}
-
- public boolean isStrictTck() throws JMSException
- {
- checkClosed();
-
- return strictTck;
- }
-
+
public boolean isXA() throws JMSException
{
checkClosed();
@@ -904,29 +461,13 @@
return xa;
}
- public Object getCurrentTxId()
- {
- return currentTxId;
- }
+// public boolean isTransacted() throws JMSException
+// {
+// checkClosed();
+//
+// return transacted;
+// }
- public void setCurrentTxId(Object currentTxId)
- {
- this.currentTxId = currentTxId;
- }
-
- public void setTreatAsNonTransactedWhenNotEnlisted(
- boolean treatAsNonTransactedWhenNotEnlisted)
- {
- this.treatAsNonTransactedWhenNotEnlisted = treatAsNonTransactedWhenNotEnlisted;
- }
-
- public boolean isTransacted() throws JMSException
- {
- checkClosed();
-
- return transacted;
- }
-
public boolean isClosed()
{
return closed;
@@ -947,119 +488,38 @@
throw new IllegalStateException("Session is closed");
}
}
-
- private void invokeSend(Message m) throws JMSException
- {
- long seq;
+
+ private void closeChildren() throws JMSException
+ {
+
+ Set<ClientConsumer> consumersClone = new HashSet<ClientConsumer>(consumers.values());
- if (m.isDurable() || strictTck)
+ for (ClientConsumer consumer: consumersClone)
{
- seq = -1;
+ consumer.closing();
+
+ consumer.close();
}
- else
+
+ Set<ClientProducer> producersClone = new HashSet<ClientProducer>(producers);
+
+ for (ClientProducer producer: producersClone)
{
- seq = npSendSequence++;
+ producer.closing();
+
+ producer.close();
}
- SendMessage message = new SendMessage(m, seq);
+ Set<ClientBrowser> browsersClone = new HashSet<ClientBrowser>(browsers);
- if (seq == -1)
+ for (ClientBrowser browser: browsersClone)
{
- remotingConnection.sendBlocking(id, message);
+ browser.closing();
+
+ browser.close();
}
- else
- {
- remotingConnection.sendOneWay(id, message);
- }
}
- private void closeChildren() throws JMSException
- {
- Set<Closeable> chilrenValues = new HashSet<Closeable>(children.values());
- for (Closeable child: chilrenValues)
- {
- child.closing(-1);
- child.close();
- }
- }
-
- /** http://jira.jboss.org/jira/browse/JBMESSAGING-946 -
- * To accomodate TCK and the MQ behavior
- * we should behave as non transacted, AUTO_ACK when there is no transaction enlisted
- * However when the Session is being used by ASF we should consider the case where
- * we will convert LocalTX to GlobalTransactions.
- * This function helper will ensure the condition that needs to be tested on this aspect
- *
- * There is a real conundrum here:
- *
- * An XA Session needs to act as transacted when not enlisted for consuming messages for an MDB so when it does
- * get enlisted we can transfer the work inside the tx
- *
- * But in needs to act as auto_acknowledge when not enlisted and not in an MDB (or bridge or stress test) to satisfy
- * integration tests and TCK!!! Hence getTreatAsNonTransactedWhenNotEnlisted()
- *
- * */
- private boolean isXAAndConsideredNonTransacted() throws JMSException
- {
- return isXA() && (getCurrentTxId() instanceof LocalTx)
- && treatAsNonTransactedWhenNotEnlisted;
- }
-
-
- private boolean ackDelivery(DeliveryInfo delivery) throws JMSException
- {
- ClientSession connectionConsumerSession = delivery.getConnectionConsumerSession();
-
- //If the delivery was obtained via a connection consumer we need to ack via that
- //otherwise we just use this session
-
- ClientSession sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
-
- return sessionToUse.acknowledgeDelivery(delivery);
- }
-
- private void cancelDelivery(DeliveryInfo delivery) throws JMSException
- {
- ClientSession connectionConsumerSession = delivery.getConnectionConsumerSession();
-
- //If the delivery was obtained via a connection consumer we need to cancel via that
- //otherwise we just use this session
-
- ClientSession sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : this;
-
- sessionToUse.cancelDelivery(new CancelImpl(delivery.getDeliveryID(),
- delivery.getMessage().getDeliveryCount(), false, false));
- }
-
- private void internalCancelDeliveries( List deliveryInfos) throws JMSException
- {
- List cancels = new ArrayList();
-
- for (Iterator i = deliveryInfos.iterator(); i.hasNext(); )
- {
- DeliveryInfo ack = (DeliveryInfo)i.next();
-
- CancelImpl cancel = new CancelImpl(ack.getMessage().getDeliveryId(),
- ack.getMessage().getDeliveryCount(),
- false, false);
-
- cancels.add(cancel);
- }
-
- if (!cancels.isEmpty())
- {
- this.cancelDeliveries(cancels);
- }
- }
-
- private void acknowledgeDeliveries(ClientSession del, List deliveryInfos) throws JMSException
- {
- if (!deliveryInfos.isEmpty())
- {
- del.acknowledgeDeliveries(deliveryInfos);
- }
- }
-
// Inner Classes --------------------------------------------------------------------------------
}
Deleted: trunk/src/main/org/jboss/jms/client/impl/DeliveryInfo.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/impl/DeliveryInfo.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/client/impl/DeliveryInfo.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,108 +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.impl;
-
-import org.jboss.jms.client.api.ClientSession;
-import org.jboss.jms.message.JBossMessage;
-
-/**
- * Struct like class for holding information regarding a delivery
- * on the client side - this is never passed to the server
- *
- * @author <a href="mailto:tim.fox at jboss.com>Tim Fox </a>
- * @author <a href="mailto:ovidiu at feodorov.com>Ovidiu Feodorov</a>
- *
- * $Id: AckInfo.java 1770 2006-12-12 10:49:42Z timfox $
- */
-public class DeliveryInfo implements Ack
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- //This is needed when doing local redelivery of messages, since we need to know which
- //consumer gets the message
- private String consumerId;
-
- private JBossMessage msg;
-
- //When using the evil abomination known as a ConnectionConsumer, the connection consumer
- //will get from a session that it created, then pass them onto sessions got from the pool
- //this means when the messages are acked/cancelled then this needs to be done against
- //the connection consumer's session not the session from the pool, since that session won't know
- //about the deliveries on the server side
- //Therefore if this delivery was done using a connection consumer then this attribute is set
- //to the connection consumer's session, otherwise it will be null
- private ClientSession connectionConsumerSession;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public DeliveryInfo(JBossMessage msg, String consumerId,
- ClientSession connectionConsumerSession)
- {
- this.msg = msg;
-
- this.consumerId = consumerId;
-
- this.connectionConsumerSession = connectionConsumerSession;
- }
-
- // Public --------------------------------------------------------
-
- public String getConsumerId()
- {
- return consumerId;
- }
-
- public JBossMessage getMessage()
- {
- return msg;
- }
-
- public ClientSession getConnectionConsumerSession()
- {
- return connectionConsumerSession;
- }
-
- public String toString()
- {
- return "Delivery[" + getDeliveryID() + ", " + msg + "]";
- }
-
- // Ack Implementation -------------------------------------------
-
- public long getDeliveryID()
- {
- return msg.getDeliveryId();
- }
-
- // Protected -----------------------------------------------------
-
- // Package Private -----------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner Classes -------------------------------------------------
-
-}
Modified: trunk/src/main/org/jboss/jms/jndi/JNDIObjectDeployer.java
===================================================================
--- trunk/src/main/org/jboss/jms/jndi/JNDIObjectDeployer.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/jndi/JNDIObjectDeployer.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -227,7 +227,7 @@
ClientConnectionFactoryImpl delegate =
new ClientConnectionFactoryImpl(messagingServer.getConfiguration().getMessagingServerID(),
- serverLocator.getURI(), version, false, useStrict, prefetchSize, dupsOKBatchSize, clientID);
+ serverLocator.getURI(), version, useStrict, prefetchSize, dupsOKBatchSize, clientID);
log.debug(this + " created local delegate " + delegate);
Modified: trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -33,6 +33,7 @@
import javax.jms.MessageEOFException;
import javax.jms.MessageFormatException;
+import org.jboss.jms.client.api.ClientSession;
import org.jboss.jms.exception.MessagingJMSException;
/**
@@ -76,10 +77,9 @@
super(JBossBytesMessage.TYPE);
}
- public JBossBytesMessage(org.jboss.messaging.core.Message message,
- long deliveryID, int deliveryCount)
+ public JBossBytesMessage(org.jboss.messaging.core.Message message, ClientSession session)
{
- super(message, deliveryID, deliveryCount);
+ super(message, session);
}
public JBossBytesMessage(BytesMessage foreign) throws JMSException
Modified: trunk/src/main/org/jboss/jms/message/JBossMapMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMapMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/message/JBossMapMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -33,6 +33,7 @@
import javax.jms.MapMessage;
import javax.jms.MessageFormatException;
+import org.jboss.jms.client.api.ClientSession;
import org.jboss.messaging.util.StreamUtils;
/**
@@ -69,9 +70,9 @@
super(JBossMapMessage.TYPE);
}
- public JBossMapMessage(org.jboss.messaging.core.Message message, long deliveryID, int deliveryCount)
+ public JBossMapMessage(org.jboss.messaging.core.Message message, ClientSession session)
{
- super(message, deliveryID, deliveryCount);
+ super(message, session);
}
/**
Modified: trunk/src/main/org/jboss/jms/message/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/message/JBossMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -119,28 +119,39 @@
private static final Logger log = Logger.getLogger(JBossMessage.class);
- public static JBossMessage createMessage(org.jboss.messaging.core.Message message,
- long deliveryID, int deliveryCount)
+ public static JBossMessage createMessage(org.jboss.messaging.core.Message message, ClientSession session)
{
int type = message.getType();
+ JBossMessage msg;
+
switch(type)
{
case JBossMessage.TYPE:
- return new JBossMessage(message, deliveryID, deliveryCount);
+ msg = new JBossMessage(message, session);
+ break;
case JBossBytesMessage.TYPE:
- return new JBossBytesMessage(message, deliveryID, deliveryCount);
+ msg = new JBossBytesMessage(message, session);
+ break;
case JBossMapMessage.TYPE:
- return new JBossMapMessage(message, deliveryID, deliveryCount);
+ msg = new JBossMapMessage(message, session);
+ break;
case JBossObjectMessage.TYPE:
- return new JBossObjectMessage(message, deliveryID, deliveryCount);
+ msg = new JBossObjectMessage(message, session);
+ break;
case JBossStreamMessage.TYPE:
- return new JBossStreamMessage(message, deliveryID, deliveryCount);
+ msg = new JBossStreamMessage(message, session);
+ break;
case JBossTextMessage.TYPE:
- return new JBossTextMessage(message, deliveryID, deliveryCount);
+ msg = new JBossTextMessage(message, session);
+ break;
default:
throw new IllegalArgumentException("Invalid message type " + type);
}
+
+ message.putHeader("JMSXDeliveryCount", message.getDeliveryCount());
+
+ return msg;
}
// Attributes ----------------------------------------------------
@@ -150,15 +161,6 @@
private ClientSession session;
- //From a connection consumer?
- private boolean cc;
-
- //The delivery count
- private int deliveryCount;
-
- //The delivery id
- private long deliveryID;
-
//Read-only?
protected boolean readOnly;
@@ -177,15 +179,13 @@
/**
* Constructor for when receiving a message from the server
*/
- public JBossMessage(org.jboss.messaging.core.Message message, long deliveryID, int deliveryCount)
+ public JBossMessage(org.jboss.messaging.core.Message message, ClientSession session)
{
this.message = message;
- this.deliveryID = deliveryID;
-
- this.deliveryCount = deliveryCount;
-
this.readOnly = true;
+
+ this.session = session;
}
/*
@@ -347,25 +347,25 @@
}
else
{
- throw new MessagingJMSException("Delivery mode must be either DeliveryMode.PERSISTENT "
+ throw new MessagingJMSException("DeliveryImpl mode must be either DeliveryMode.PERSISTENT "
+ "or DeliveryMode.NON_PERSISTENT");
}
}
public boolean getJMSRedelivered() throws JMSException
{
- return deliveryCount >= 2;
+ return message.getDeliveryCount() > 1;
}
public void setJMSRedelivered(boolean redelivered) throws JMSException
- {
- if (deliveryCount == 1)
+ {
+ if (message.getDeliveryCount() > 1)
{
- deliveryCount++;
+ //do nothing
}
else
{
- //do nothing
+ message.setDeliveryCount(2);
}
}
@@ -492,12 +492,7 @@
}
public int getIntProperty(String name) throws JMSException
- {
- if ("JMSXDeliveryCount".equals(name))
- {
- return deliveryCount;
- }
-
+ {
Object value = message.getHeader(name);
if (value == null)
@@ -529,11 +524,6 @@
public long getLongProperty(String name) throws JMSException
{
- if ("JMSXDeliveryCount".equals(name))
- {
- return deliveryCount;
- }
-
Object value = message.getHeader(name);
if (value == null)
@@ -599,11 +589,6 @@
public String getStringProperty(String name) throws JMSException
{
- if ("JMSXDeliveryCount".equals(name))
- {
- return Integer.toString(deliveryCount);
- }
-
Object value = message.getHeader(name);
if (value == null)
return null;
@@ -758,11 +743,7 @@
public void acknowledge() throws JMSException
{
- if (!cc)
- {
- //Only acknowledge for client ack if is not in connection consumer
- session.acknowledgeAll();
- }
+ session.commit();
}
// Public --------------------------------------------------------
@@ -815,33 +796,11 @@
return JBossMessage.TYPE;
}
- public void setSession(ClientSession sd, boolean isConnectionConsumer)
- {
- this.session = sd;
-
- this.cc = isConnectionConsumer;
- }
-
public ClientSession getSession()
{
return session;
}
- public int getDeliveryCount()
- {
- return deliveryCount;
- }
-
- public void incDeliveryCount()
- {
- this.deliveryCount++;
- }
-
- public long getDeliveryId()
- {
- return deliveryID;
- }
-
public void copyMessage()
{
message = message.copy();
Modified: trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -29,6 +29,7 @@
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
+import org.jboss.jms.client.api.ClientSession;
import org.jboss.messaging.util.StreamUtils;
/**
@@ -63,9 +64,9 @@
super(JBossObjectMessage.TYPE);
}
- public JBossObjectMessage(org.jboss.messaging.core.Message message, long deliveryID, int deliveryCount)
+ public JBossObjectMessage(org.jboss.messaging.core.Message message, ClientSession session)
{
- super(message, deliveryID, deliveryCount);
+ super(message, session);
}
/**
Modified: trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -31,6 +31,7 @@
import javax.jms.MessageFormatException;
import javax.jms.StreamMessage;
+import org.jboss.jms.client.api.ClientSession;
import org.jboss.messaging.util.StreamUtils;
/**
@@ -73,9 +74,9 @@
super(JBossStreamMessage.TYPE);
}
- public JBossStreamMessage(org.jboss.messaging.core.Message message, long deliveryID, int deliveryCount)
+ public JBossStreamMessage(org.jboss.messaging.core.Message message, ClientSession session)
{
- super(message, deliveryID, deliveryCount);
+ super(message, session);
}
public JBossStreamMessage(StreamMessage foreign) throws JMSException
Modified: trunk/src/main/org/jboss/jms/message/JBossTextMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossTextMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/message/JBossTextMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -28,6 +28,7 @@
import javax.jms.JMSException;
import javax.jms.TextMessage;
+import org.jboss.jms.client.api.ClientSession;
import org.jboss.messaging.util.Logger;
import org.jboss.messaging.util.SafeUTF;
@@ -68,9 +69,9 @@
super(JBossTextMessage.TYPE);
}
- public JBossTextMessage(org.jboss.messaging.core.Message message, long deliveryID, int deliveryCount)
+ public JBossTextMessage(org.jboss.messaging.core.Message message, ClientSession session)
{
- super(message, deliveryID, deliveryCount);
+ super(message, session);
}
/**
Modified: trunk/src/main/org/jboss/jms/server/ConnectionManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/ConnectionManager.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/ConnectionManager.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -23,7 +23,7 @@
import java.util.List;
-import org.jboss.jms.server.endpoint.ConnectionEndpoint;
+import org.jboss.jms.server.endpoint.ServerConnectionEndpoint;
import org.jboss.messaging.core.MessagingComponent;
import org.jboss.messaging.core.remoting.PacketSender;
@@ -42,12 +42,12 @@
{
void registerConnection(String jmsClientVMId,
String remotingClientSessionID,
- ConnectionEndpoint endpoint);
+ ServerConnectionEndpoint endpoint);
/**
* @return null if there is no such connection.
*/
- ConnectionEndpoint unregisterConnection(String jmsClientVMID, String remotingClientSessionID);
+ ServerConnectionEndpoint unregisterConnection(String jmsClientVMID, String remotingClientSessionID);
boolean containsRemotingSession(String remotingClientSessionID);
Modified: trunk/src/main/org/jboss/jms/server/bridge/Bridge.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/bridge/Bridge.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/bridge/Bridge.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -990,9 +990,9 @@
{
JBossSession jsession = (JBossSession)sourceSession;
- org.jboss.jms.client.api.ClientSession session = jsession.getDelegate();
+ org.jboss.jms.client.api.ClientSession session = jsession.getCoreSession();
- session.setTreatAsNonTransactedWhenNotEnlisted(false);
+ //session.setTreatAsNonTransactedWhenNotEnlisted(false);
}
if (subName == null)
Modified: trunk/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -34,7 +34,7 @@
import javax.jms.JMSException;
import org.jboss.jms.server.ConnectionManager;
-import org.jboss.jms.server.endpoint.ConnectionEndpoint;
+import org.jboss.jms.server.endpoint.ServerConnectionEndpoint;
import org.jboss.messaging.core.remoting.PacketSender;
import org.jboss.messaging.util.ConcurrentHashSet;
import org.jboss.messaging.util.Logger;
@@ -59,13 +59,13 @@
// Attributes -----------------------------------------------------------------------------------
- private Map</** VMID */String, Map</** RemoteSessionID */String, ConnectionEndpoint>> jmsClients;
+ private Map</** VMID */String, Map</** RemoteSessionID */String, ServerConnectionEndpoint>> jmsClients;
// Map<remotingClientSessionID<String> - jmsClientVMID<String>
private Map<String, String> remotingSessions;
- // Set<ConnectionEndpoint>
- private Set<ConnectionEndpoint> activeConnectionEndpoints;
+ // Set<ServerConnectionEndpoint>
+ private Set<ServerConnectionEndpoint> activeServerConnectionEndpoints;
private Map</** CFUniqueName*/ String, ConnectionFactoryCallbackInformation> cfCallbackInfo;
@@ -73,9 +73,9 @@
public SimpleConnectionManager()
{
- jmsClients = new HashMap<String, Map<String, ConnectionEndpoint>>();
+ jmsClients = new HashMap<String, Map<String, ServerConnectionEndpoint>>();
remotingSessions = new HashMap<String, String>();
- activeConnectionEndpoints = new HashSet<ConnectionEndpoint>();
+ activeServerConnectionEndpoints = new HashSet<ServerConnectionEndpoint>();
cfCallbackInfo = new ConcurrentHashMap<String, ConnectionFactoryCallbackInformation>();
}
@@ -85,13 +85,13 @@
public synchronized void registerConnection(String jmsClientVMID,
String remotingClientSessionID,
- ConnectionEndpoint endpoint)
+ ServerConnectionEndpoint endpoint)
{
- Map<String, ConnectionEndpoint> endpoints = jmsClients.get(jmsClientVMID);
+ Map<String, ServerConnectionEndpoint> endpoints = jmsClients.get(jmsClientVMID);
if (endpoints == null)
{
- endpoints = new HashMap<String, ConnectionEndpoint>();
+ endpoints = new HashMap<String, ServerConnectionEndpoint>();
jmsClients.put(jmsClientVMID, endpoints);
}
@@ -100,25 +100,25 @@
remotingSessions.put(remotingClientSessionID, jmsClientVMID);
- activeConnectionEndpoints.add(endpoint);
+ activeServerConnectionEndpoints.add(endpoint);
log.debug("registered connection " + endpoint + " as " +
Util.guidToString(remotingClientSessionID));
}
- public synchronized ConnectionEndpoint unregisterConnection(String jmsClientVMId,
+ public synchronized ServerConnectionEndpoint unregisterConnection(String jmsClientVMId,
String remotingClientSessionID)
{
- Map<String, ConnectionEndpoint> endpoints = jmsClients.get(jmsClientVMId);
+ Map<String, ServerConnectionEndpoint> endpoints = jmsClients.get(jmsClientVMId);
if (endpoints != null)
{
- ConnectionEndpoint e = endpoints.remove(remotingClientSessionID);
+ ServerConnectionEndpoint e = endpoints.remove(remotingClientSessionID);
if (e != null)
{
endpoints.remove(e);
- activeConnectionEndpoints.remove(e);
+ activeServerConnectionEndpoints.remove(e);
}
log.debug("unregistered connection " + e + " with remoting session ID " +
@@ -139,8 +139,8 @@
public synchronized List getActiveConnections()
{
// I will make a copy to avoid ConcurrentModification
- List<ConnectionEndpoint> list = new ArrayList<ConnectionEndpoint>();
- list.addAll(activeConnectionEndpoints);
+ List<ServerConnectionEndpoint> list = new ArrayList<ServerConnectionEndpoint>();
+ list.addAll(activeServerConnectionEndpoints);
return list;
}
@@ -248,15 +248,15 @@
// Remoting only provides one pinger per invoker, not per connection therefore when the pinger
// dies we must close ALL connections corresponding to that jms client ID.
- Map<String, ConnectionEndpoint> endpoints = jmsClients.get(jmsClientID);
+ Map<String, ServerConnectionEndpoint> endpoints = jmsClients.get(jmsClientID);
if (endpoints != null)
{
- List<ConnectionEndpoint> sces = new ArrayList<ConnectionEndpoint>();
+ List<ServerConnectionEndpoint> sces = new ArrayList<ServerConnectionEndpoint>();
- for (Map.Entry<String, ConnectionEndpoint> entry: endpoints.entrySet())
+ for (Map.Entry<String, ServerConnectionEndpoint> entry: endpoints.entrySet())
{
- ConnectionEndpoint sce = entry.getValue();
+ ServerConnectionEndpoint sce = entry.getValue();
sces.add(sce);
}
@@ -264,12 +264,12 @@
// to remove the data from the jmsClients and sessions maps.
// Note we do this outside the loop to prevent ConcurrentModificationException
- for(ConnectionEndpoint sce: sces )
+ for(ServerConnectionEndpoint sce: sces )
{
try
{
log.debug("clPearing up state for connection " + sce);
- sce.closing(-1);
+ sce.closing();
sce.close();
log.debug("cleared up state for connection " + sce);
}
@@ -367,7 +367,7 @@
String sessionID = (String)entry2.getKey();
- ConnectionEndpoint endpoint = (ConnectionEndpoint)entry2.getValue();
+ ServerConnectionEndpoint endpoint = (ServerConnectionEndpoint)entry2.getValue();
log.debug(" " + sessionID + "------>" + System.identityHashCode(endpoint));
}
Deleted: trunk/src/main/org/jboss/jms/server/endpoint/BrowserEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/BrowserEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/BrowserEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,53 +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.endpoint;
-
-import javax.jms.JMSException;
-
-import org.jboss.jms.client.Closeable;
-import org.jboss.messaging.core.Message;
-
-/**
- * Represents the set of methods from the BrowserDelegate that are handled on the server. The rest
- * of the methods are handled in the advice stack.
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public interface BrowserEndpoint extends Closeable
-{
- /**
- * Reset the internal state of the browser endpoint so the following
- * nextMessage()/hasNextMessage()/nextMessageBlock() invocations would reflect the state of the
- * queue at the moment of the reset.
- */
- void reset() throws JMSException;
-
- Message nextMessage() throws JMSException;
-
- boolean hasNextMessage() throws JMSException;
-
- Message[] nextMessageBlock(int maxMessages) throws JMSException;
-}
Deleted: trunk/src/main/org/jboss/jms/server/endpoint/ConnectionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ConnectionEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ConnectionEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,57 +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.endpoint;
-
-import javax.jms.JMSException;
-
-import org.jboss.jms.client.Closeable;
-import org.jboss.jms.tx.TransactionRequest;
-import org.jboss.messaging.core.remoting.wireformat.CreateSessionResponse;
-import org.jboss.messaging.core.tx.MessagingXid;
-
-
-/**
- * Represents the set of methods from the ConnectionDelegate that are handled on the server. The
- * rest of the methods are handled in the advice stack.
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public interface ConnectionEndpoint extends Closeable
-{
- CreateSessionResponse createSession(boolean transacted,
- int acknowledgmentMode,
- boolean isXA) throws JMSException;
-
- String getClientID() throws JMSException;
-
- void setClientID(String id) throws JMSException;
-
- void start() throws JMSException;
-
- void stop() throws JMSException;
-
- void sendTransaction(TransactionRequest request) throws JMSException;
-}
-
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryAdvisedPacketHandler.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryAdvisedPacketHandler.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryAdvisedPacketHandler.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,19 +21,23 @@
*/
package org.jboss.jms.server.endpoint;
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATECONNECTION;
+
+import javax.jms.JMSException;
+
import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
import org.jboss.jms.exception.MessagingJMSException;
import org.jboss.logging.Logger;
import org.jboss.messaging.core.MessagingServer;
import org.jboss.messaging.core.remoting.PacketHandler;
import org.jboss.messaging.core.remoting.PacketSender;
-import org.jboss.messaging.core.remoting.wireformat.*;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_UPDATECALLBACK;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATECONNECTION;
+import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
+import org.jboss.messaging.core.remoting.wireformat.CreateConnectionRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateConnectionResponse;
+import org.jboss.messaging.core.remoting.wireformat.JMSExceptionMessage;
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
import org.jboss.messaging.util.ExceptionUtil;
-import javax.jms.JMSException;
-
/**
* A packet handler for creating connections. All ConnectionFactories will use the same instance of this
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -79,17 +83,8 @@
request.getClientVMID(), request.getPrefetchSize(), request.getDupsOKBatchSize(),
request.getClientID(), request.getVersion());
}
- else if (type == MSG_UPDATECALLBACK)
+ else
{
- UpdateCallbackMessage message = (UpdateCallbackMessage) packet;
- if (message.isAdd())
- {
- addSender(message.getClientVMID(), message.getRemotingSessionID(), sender);
- } else {
- removeSender(message.getClientVMID(), message.getRemotingSessionID(), sender);
- }
- } else
- {
response = new JMSExceptionMessage(new MessagingJMSException(
"Unsupported packet for browser: " + packet));
}
Deleted: trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ConnectionFactoryEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,46 +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.endpoint;
-
-import javax.jms.JMSException;
-
-import org.jboss.messaging.core.remoting.wireformat.CreateConnectionResponse;
-
-/**
- * Represents the set of methods from the ConnectionFactoryDelegate that are handled on the server.
- * The rest of the methods are handled in the advice stack.
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public interface ConnectionFactoryEndpoint
-{
- CreateConnectionResponse createConnectionDelegate(String username,
- String password,
- String remotingSessionID,
- String clientVMID,
- byte versionToUse) throws JMSException;
-}
-
Deleted: trunk/src/main/org/jboss/jms/server/endpoint/ConsumerEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ConsumerEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ConsumerEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,45 +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.endpoint;
-
-import javax.jms.JMSException;
-
-import org.jboss.jms.client.Closeable;
-
-/**
- * Represents the set of methods from the ConsumerDelegate that are handled on the server.
- * The rest of the methods are handled in the advice stack.
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- *
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public interface ConsumerEndpoint extends Closeable
-{
- /**
- * Sent to the server to specify a new maximum rate at which to send messages at
- */
- void changeRate(float newRate) throws JMSException;
-}
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -25,7 +25,6 @@
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CLOSE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_BROWSER_HASNEXTMESSAGE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_BROWSER_NEXTMESSAGE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CLOSING;
import java.util.ArrayList;
import java.util.Iterator;
@@ -46,8 +45,7 @@
import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
import org.jboss.messaging.core.remoting.wireformat.BrowserHasNextMessageResponse;
import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageResponse;
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
+import org.jboss.messaging.core.remoting.wireformat.ClosingMessage;
import org.jboss.messaging.core.remoting.wireformat.JMSExceptionMessage;
import org.jboss.messaging.core.remoting.wireformat.NullPacket;
import org.jboss.messaging.core.remoting.wireformat.PacketType;
@@ -63,7 +61,7 @@
*
* $Id$
*/
-public class ServerBrowserEndpoint implements BrowserEndpoint
+public class ServerBrowserEndpoint
{
// Constants ------------------------------------------------------------------------------------
@@ -232,10 +230,8 @@
}
}
- public long closing(long sequence) throws JMSException
+ public void closing() throws JMSException
{
- // Do nothing
- return -1;
}
// Public ---------------------------------------------------------------------------------------
@@ -312,12 +308,12 @@
reset();
response = new NullPacket();
- } else if (type == REQ_CLOSING)
+ } else if (type == PacketType.MSG_CLOSING)
{
- ClosingRequest request = (ClosingRequest) packet;
- long id = closing(request.getSequence());
+ ClosingMessage request = (ClosingMessage) packet;
+ closing();
- response = new ClosingResponse(id);
+ response = new NullPacket();
} else if (type == MSG_CLOSE)
{
close();
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,33 +21,56 @@
*/
package org.jboss.jms.server.endpoint;
+
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CLOSE;
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SETCLIENTID;
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_STARTCONNECTION;
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_STOPCONNECTION;
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATESESSION;
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_GETCLIENTID;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.jms.IllegalStateException;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.transaction.xa.Xid;
+
import org.jboss.jms.exception.MessagingJMSException;
import org.jboss.jms.server.ConnectionManager;
import org.jboss.jms.server.SecurityStore;
import org.jboss.jms.server.TransactionRepository;
import org.jboss.jms.server.container.SecurityAspect;
-import org.jboss.jms.server.security.CheckType;
-import org.jboss.jms.tx.ClientTransaction;
-import org.jboss.jms.tx.ClientTransaction.SessionTxState;
-import org.jboss.jms.tx.TransactionRequest;
-import org.jboss.messaging.core.*;
+import org.jboss.messaging.core.Binding;
+import org.jboss.messaging.core.Condition;
+import org.jboss.messaging.core.Destination;
+import org.jboss.messaging.core.DestinationType;
+import org.jboss.messaging.core.MessagingServer;
+import org.jboss.messaging.core.PostOffice;
import org.jboss.messaging.core.impl.ConditionImpl;
-import org.jboss.messaging.core.impl.TransactionImpl;
import org.jboss.messaging.core.remoting.PacketHandler;
import org.jboss.messaging.core.remoting.PacketSender;
-import org.jboss.messaging.core.remoting.wireformat.*;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.*;
+import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
+import org.jboss.messaging.core.remoting.wireformat.CreateSessionRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateSessionResponse;
+import org.jboss.messaging.core.remoting.wireformat.GetClientIDResponse;
+import org.jboss.messaging.core.remoting.wireformat.JMSExceptionMessage;
+import org.jboss.messaging.core.remoting.wireformat.NullPacket;
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SetClientIDMessage;
import org.jboss.messaging.core.tx.MessagingXid;
import org.jboss.messaging.util.ExceptionUtil;
import org.jboss.messaging.util.Logger;
import org.jboss.messaging.util.Util;
-import javax.jms.IllegalStateException;
-import javax.jms.InvalidDestinationException;
-import javax.jms.JMSException;
-import javax.transaction.xa.Xid;
-import java.util.*;
-
/**
* Concrete implementation of ConnectionEndpoint.
*
@@ -58,7 +81,7 @@
*
* $Id$
*/
-public class ServerConnectionEndpoint implements ConnectionEndpoint
+public class ServerConnectionEndpoint
{
// Constants ------------------------------------------------------------------------------------
@@ -152,14 +175,15 @@
// ConnectionDelegate implementation ------------------------------------------------------------
public CreateSessionResponse createSession(boolean transacted,
- int acknowledgmentMode,
- boolean xa)
+ int acknowledgementMode,
+ boolean xa,
+ PacketSender sender)
throws JMSException
{
try
{
log.trace(this + " creating " + (transacted ? "transacted" : "non transacted") +
- " session, " + Util.acknowledgmentMode(acknowledgmentMode) + ", " +
+ " session, " + Util.acknowledgmentMode(acknowledgementMode) + ", " +
(xa ? "XA": "non XA"));
if (closed)
@@ -169,11 +193,40 @@
String sessionID = UUID.randomUUID().toString();
- // create the corresponding server-side session endpoint and register it with this
- // connection endpoint instance
-
+ //TODO do this checks on the client side
+ boolean autoCommitSends;
+
+ boolean autoCommitAcks;
+
+ if (!transacted)
+ {
+ if (acknowledgementMode == Session.AUTO_ACKNOWLEDGE || acknowledgementMode == Session.DUPS_OK_ACKNOWLEDGE)
+ {
+ autoCommitSends = true;
+
+ autoCommitAcks = true;
+ }
+ else if (acknowledgementMode == Session.CLIENT_ACKNOWLEDGE)
+ {
+ autoCommitSends = true;
+
+ autoCommitAcks = false;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Invalid ack mode " + acknowledgementMode);
+ }
+ }
+ else
+ {
+ autoCommitSends = false;
+
+ autoCommitAcks = false;
+ }
+
//Note we only replicate transacted and client acknowledge sessions.
- ServerSessionEndpoint ep = new ServerSessionEndpoint(sessionID, this, transacted, xa);
+ ServerSessionEndpoint ep =
+ new ServerSessionEndpoint(sessionID, this, autoCommitSends, autoCommitAcks, xa, sender);
synchronized (sessions)
{
@@ -191,7 +244,7 @@
throw ExceptionUtil.handleJMSInvocation(t, this + " createSessionDelegate");
}
}
-
+
public String getClientID() throws JMSException
{
try
@@ -346,114 +399,10 @@
}
}
- public long closing(long sequence) throws JMSException
+ public void closing() throws JMSException
{
- log.trace(this + " closing (noop)");
-
- return -1;
}
- private void checkSecurityOnSendTransaction(TransactionRequest t) throws JMSException
- {
- ClientTransaction txState = t.getState();
-
- //FIXME - can't we optimise this??
- if (txState != null)
- {
- // distinct list of destinations...
- HashSet<org.jboss.messaging.core.Destination> destinations = new HashSet<org.jboss.messaging.core.Destination>();
-
- for (Iterator i = txState.getSessionStates().iterator(); i.hasNext(); )
- {
- ClientTransaction.SessionTxState sessionState = (ClientTransaction.SessionTxState)i.next();
- for (Iterator j = sessionState.getMsgs().iterator(); j.hasNext(); )
- {
- Message message = (Message)j.next();
-
- org.jboss.messaging.core.Destination dest =
- (org.jboss.messaging.core.Destination)message.getHeader(org.jboss.messaging.core.Message.TEMP_DEST_HEADER_NAME);
-
-
- destinations.add(dest);
- }
- }
- for (Iterator iterDestinations = destinations.iterator();iterDestinations.hasNext();)
- {
- org.jboss.messaging.core.Destination destination = (org.jboss.messaging.core.Destination) iterDestinations.next();
- security.check(destination, CheckType.WRITE, this);
- }
-
- }
-
- }
-
- public void sendTransaction(TransactionRequest request) throws JMSException
- {
-
- checkSecurityOnSendTransaction(request);
- try
- {
- if (closed)
- {
- throw new IllegalStateException("Connection is closed");
- }
-
- if (request.getRequestType() == TransactionRequest.ONE_PHASE_COMMIT_REQUEST)
- {
- if (trace) { log.trace(this + " received ONE_PHASE_COMMIT request"); }
-
- Transaction tx = new TransactionImpl();
-
- processTransaction(request.getState(), tx);
-
- tx.commit(messagingServer.getPersistenceManager());
- }
- else if (request.getRequestType() == TransactionRequest.TWO_PHASE_PREPARE_REQUEST)
- {
- if (trace) { log.trace(this + " received TWO_PHASE_COMMIT prepare request"); }
-
- Transaction tx = new TransactionImpl(request.getXid());
-
- tr.addTransaction(request.getXid(), tx);
-
- processTransaction(request.getState(), tx);
-
- tx.prepare(messagingServer.getPersistenceManager());
- }
- else if (request.getRequestType() == TransactionRequest.TWO_PHASE_COMMIT_REQUEST)
- {
- if (trace) { log.trace(this + " received TWO_PHASE_COMMIT commit request"); }
-
- Transaction tx = tr.getTransaction(request.getXid());
-
- if (trace) { log.trace("Committing " + tx); }
-
- tx.commit(messagingServer.getPersistenceManager());
- }
- else if (request.getRequestType() == TransactionRequest.TWO_PHASE_ROLLBACK_REQUEST)
- {
- if (trace) { log.trace(this + " received TWO_PHASE_COMMIT rollback request"); }
-
- // for 2pc rollback - we just don't cancel any messages back to the channel; this is
- // driven from the client side.
-
- Transaction tx = tr.getTransaction(request.getXid());
-
- if (trace) { log.trace(this + " rolling back " + tx); }
-
- tx.rollback(messagingServer.getPersistenceManager());
-
- tr.removeTransaction(request.getXid());
- }
-
- if (trace) { log.trace(this + " processed transaction successfully"); }
- }
- catch (Throwable t)
- {
- throw ExceptionUtil.handleJMSInvocation(t, this + " sendTransaction");
- }
- }
-
/**
* Get array of XA transactions in prepared state-
* This would be used by the transaction manager in recovery or by a tool to apply
@@ -578,36 +527,7 @@
return remotingClientSessionID;
}
- void sendMessage(Message msg) throws Exception
- {
- if (trace) { log.trace(this + " sending message " + msg); }
-
- Destination dest = (Destination)msg.getHeader(org.jboss.messaging.core.Message.TEMP_DEST_HEADER_NAME);
-
- //Assign the message an internal id - this is used to key it in the store and also used to
- //handle delivery
-
- msg.setMessageID(messagingServer.getPersistenceManager().generateMessageID());
-
- // This allows the no-local consumers to filter out the messages that come from the same
- // connection.
-
- msg.setConnectionID(id);
-
- Condition condition = new ConditionImpl(dest.getType(), dest.getName());
-
- postOffice.route(condition, msg);
-
- //FIXME - this check belongs on the client side!!
-
- if (dest.getType() == DestinationType.QUEUE && msg.getReferences().isEmpty())
- {
- throw new InvalidDestinationException("Failed to route to queue " + dest.getName());
- }
-
- if (trace) { log.trace("sent " + msg); }
- }
-
+
// Protected ------------------------------------------------------------------------------------
// Private --------------------------------------------------------------------------------------
@@ -631,41 +551,6 @@
started = s;
}
- private void processTransaction(ClientTransaction txState, Transaction tx) throws Exception
- {
- if (trace) { log.trace(this + " processing transaction " + tx); }
-
- for (SessionTxState sessionState: txState.getSessionStates())
- {
- List<Message> messages = sessionState.getMsgs();
-
- for (Message message: messages)
- {
- sendMessage(message);
-
- if (message.getNumDurableReferences() != 0)
- {
- tx.setContainsPersistent(true);
- }
- }
-
- tx.addAllSends(messages);
-
- ServerSessionEndpoint session = messagingServer.getSession(sessionState.getSessionId());
-
- if (session == null)
- {
- throw new IllegalStateException("Cannot find session with id " +
- sessionState.getSessionId());
- }
-
- tx.addAllAcks(session.acknowledgeTransactionally(sessionState.getAcks(), tx));
- }
-
- if (trace) { log.trace(this + " processed transaction " + tx); }
- }
-
-
// Inner classes --------------------------------------------------------------------------------
private class ConnectionPacketHandler implements PacketHandler
@@ -691,7 +576,7 @@
CreateSessionRequest request = (CreateSessionRequest) packet;
response = createSession(
request.isTransacted(), request.getAcknowledgementMode(),
- request.isXA());
+ request.isXA(), sender);
} else if (type == MSG_STARTCONNECTION)
{
start();
@@ -700,30 +585,19 @@
stop();
response = new NullPacket();
- } else if (type == REQ_CLOSING)
- {
- ClosingRequest request = (ClosingRequest) packet;
- long id = closing(request.getSequence());
+ } else if (type == PacketType.MSG_CLOSING)
+ {
+ closing();
- response = new ClosingResponse(id);
+ response = new NullPacket();
} else if (type == MSG_CLOSE)
{
close();
response = new NullPacket();
- } else if (type == MSG_SENDTRANSACTION)
+ }
+ else if (type == REQ_GETCLIENTID)
{
- SendTransactionMessage message = (SendTransactionMessage) packet;
- sendTransaction(message.getTransactionRequest());
-
- response = new NullPacket();
- } else if (type == REQ_GETPREPAREDTRANSACTIONS)
- {
- MessagingXid[] xids = getPreparedTransactions();
-
- response = new GetPreparedTransactionsResponse(xids);
- } else if (type == REQ_GETCLIENTID)
- {
response = new GetClientIDResponse(getClientID());
} else if (type == MSG_SETCLIENTID)
{
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -23,7 +23,6 @@
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CHANGERATE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CLOSE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CLOSING;
import javax.jms.JMSException;
@@ -44,9 +43,7 @@
import org.jboss.messaging.core.remoting.PacketHandler;
import org.jboss.messaging.core.remoting.PacketSender;
import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
-import org.jboss.messaging.core.remoting.wireformat.ChangeRateMessage;
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
+import org.jboss.messaging.core.remoting.wireformat.ConsumerChangeRateMessage;
import org.jboss.messaging.core.remoting.wireformat.DeliverMessage;
import org.jboss.messaging.core.remoting.wireformat.JMSExceptionMessage;
import org.jboss.messaging.core.remoting.wireformat.NullPacket;
@@ -67,7 +64,7 @@
*
* @version <tt>$Revision$</tt> $Id$
*/
-public class ServerConsumerEndpoint implements Consumer, ConsumerEndpoint
+public class ServerConsumerEndpoint implements Consumer
{
// Constants ------------------------------------------------------------------------------------
@@ -109,15 +106,12 @@
// Must be volatile
private volatile boolean clientAccepting;
- private long lastDeliveryID = -1;
-
private int prefetchSize;
private volatile int sendCount;
private boolean firstTime = true;
-
-
+
//FIXME temp
public Queue getMessageQueue()
{
@@ -270,7 +264,7 @@
try
{
- sessionEndpoint.handleDelivery(ref, this);
+ sessionEndpoint.handleDelivery(ref, this, replier);
}
catch (Exception e)
{
@@ -308,15 +302,13 @@
// Closeable implementation ---------------------------------------------------------------------
- public long closing(long sequence) throws JMSException
+ public void closing() throws JMSException
{
try
{
if (trace) { log.trace(this + " closing");}
stop();
-
- return lastDeliveryID;
}
catch (Throwable t)
{
@@ -405,11 +397,6 @@
return this.id;
}
- void setLastDeliveryID(long id)
- {
- this.lastDeliveryID = id;
- }
-
void setStarted(boolean started)
{
//No need to lock since caller already has the lock
@@ -523,35 +510,7 @@
return;
}
- started = false;
-
- // Any message deliveries already transit to the consumer, will just be ignored by the
- // ClientConsumer since it will be closed.
- //
- // To clarify, the close protocol (from connection) is as follows:
- //
- // 1) ClientConsumer::close() - any messages in buffer are cancelled to the server
- // session, and any subsequent receive messages will be ignored.
- //
- // 2) ServerConsumerEndpoint::closing() causes stop() this flushes any deliveries yet to
- // deliver to the client callback handler.
- //
- // 3) ClientConsumer waits for all deliveries to arrive at client side
- //
- // 4) ServerConsumerEndpoint:close() - endpoint is deregistered.
- //
- // 5) Session.close() - acks or cancels any remaining deliveries in the SessionState as
- // appropriate.
- //
- // 6) ServerSessionEndpoint::close() - cancels any remaining deliveries and deregisters
- // session.
- //
- // 7) Client side session executor is shutdown.
- //
- // 8) ServerConnectionEndpoint::close() - connection is deregistered.
- //
- // 9) Remoting connection listener is removed and remoting connection stopped.
-
+ started = false;
}
}
@@ -566,23 +525,25 @@
private PacketSender replier;
+ //FIXME - this is a hack - we shouldn't have to wait for a change rate message before we can send
+ //a message to the client
private void setReplier(PacketSender replier)
{
this.replier = replier;
}
+//
+// public void deliver(DeliverMessage message)
+// {
+// if (replier != null)
+// {
+// message.setTargetID(id);
+// replier.send(message);
+// } else
+// {
+// log.error("No replier to deliver message to consumer");
+// }
+// }
- public void deliver(DeliverMessage message)
- {
- if (replier != null)
- {
- message.setTargetID(id);
- replier.send(message);
- } else
- {
- log.error("No replier to deliver message to consumer");
- }
- }
-
// Inner classes --------------------------------------------------------------------------------
private class ServerConsumerEndpointPacketHandler implements PacketHandler {
@@ -603,14 +564,13 @@
{
setReplier(sender);
- ChangeRateMessage message = (ChangeRateMessage) packet;
+ ConsumerChangeRateMessage message = (ConsumerChangeRateMessage) packet;
changeRate(message.getRate());
- } else if (type == REQ_CLOSING)
+ } else if (type == PacketType.MSG_CLOSING)
{
- ClosingRequest request = (ClosingRequest) packet;
- long id = closing(request.getSequence());
+ closing();
- response = new ClosingResponse(id);
+ response = new NullPacket();
} else if (type == MSG_CLOSE)
{
close();
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,26 +21,18 @@
*/
package org.jboss.jms.server.endpoint;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_ACKDELIVERIES;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_ADDTEMPORARYDESTINATION;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERIES;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERY;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CLOSE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_DELETETEMPORARYDESTINATION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SENDMESSAGE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_UNSUBSCRIBE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_ACKDELIVERY;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CLOSING;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATEBROWSER;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATECONSUMER;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATEDESTINATION;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -50,10 +42,6 @@
import javax.jms.InvalidSelectorException;
import javax.jms.JMSException;
-import org.jboss.jms.client.impl.Ack;
-import org.jboss.jms.client.impl.AckImpl;
-import org.jboss.jms.client.impl.Cancel;
-import org.jboss.jms.client.impl.DeliveryInfo;
import org.jboss.jms.destination.JBossDestination;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
@@ -62,6 +50,7 @@
import org.jboss.jms.server.security.CheckType;
import org.jboss.messaging.core.Binding;
import org.jboss.messaging.core.Condition;
+import org.jboss.messaging.core.Delivery;
import org.jboss.messaging.core.Destination;
import org.jboss.messaging.core.DestinationType;
import org.jboss.messaging.core.Filter;
@@ -71,21 +60,14 @@
import org.jboss.messaging.core.PostOffice;
import org.jboss.messaging.core.Queue;
import org.jboss.messaging.core.Transaction;
-import org.jboss.messaging.core.TransactionSynchronization;
import org.jboss.messaging.core.impl.ConditionImpl;
+import org.jboss.messaging.core.impl.DeliveryImpl;
import org.jboss.messaging.core.impl.TransactionImpl;
import org.jboss.messaging.core.impl.filter.FilterImpl;
import org.jboss.messaging.core.remoting.PacketHandler;
import org.jboss.messaging.core.remoting.PacketSender;
import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveriesMessage;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryRequest;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryResponse;
import org.jboss.messaging.core.remoting.wireformat.AddTemporaryDestinationMessage;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveriesMessage;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveryMessage;
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
import org.jboss.messaging.core.remoting.wireformat.CreateBrowserRequest;
import org.jboss.messaging.core.remoting.wireformat.CreateBrowserResponse;
import org.jboss.messaging.core.remoting.wireformat.CreateConsumerRequest;
@@ -93,20 +75,19 @@
import org.jboss.messaging.core.remoting.wireformat.CreateDestinationRequest;
import org.jboss.messaging.core.remoting.wireformat.CreateDestinationResponse;
import org.jboss.messaging.core.remoting.wireformat.DeleteTemporaryDestinationMessage;
-import org.jboss.messaging.core.remoting.wireformat.DeliverMessage;
import org.jboss.messaging.core.remoting.wireformat.JMSExceptionMessage;
import org.jboss.messaging.core.remoting.wireformat.NullPacket;
import org.jboss.messaging.core.remoting.wireformat.PacketType;
-import org.jboss.messaging.core.remoting.wireformat.SendMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionAcknowledgeMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionCancelMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionSendMessage;
import org.jboss.messaging.core.remoting.wireformat.UnsubscribeMessage;
import org.jboss.messaging.util.ExceptionUtil;
import org.jboss.messaging.util.Logger;
import org.jboss.messaging.util.MessageQueueNameHelper;
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
-import EDU.oswego.cs.dl.util.concurrent.SynchronizedLong;
/**
* Session implementation
@@ -122,7 +103,7 @@
*
* $Id$
*/
-public class ServerSessionEndpoint implements SessionEndpoint
+public class ServerSessionEndpoint
{
// Constants ------------------------------------------------------------------------------------
@@ -132,8 +113,6 @@
static final String TEMP_QUEUE_MESSAGECOUNTER_PREFIX = "TempQueue.";
- private static final long CLOSE_WAIT_TIMEOUT = 5 * 1000;
-
// Static ---------------------------------------------------------------------------------------
// Attributes -----------------------------------------------------------------------------------
@@ -159,26 +138,34 @@
private Queue defaultDLQ;
private Queue defaultExpiryQueue;
- // Map <deliveryID, Delivery>
- private Map deliveries;
+ private volatile LinkedList<Delivery> deliveries = new LinkedList<Delivery>();
- private SynchronizedLong deliveryIdSequence;
+ //private SynchronizedLong deliveryIdSequence;
+
+ private long deliveryIDSequence = 0;
//Temporary until we have our own NIO transport
QueuedExecutor executor = new QueuedExecutor(new LinkedQueue());
- private Object waitLock = new Object();
-
private Transaction tx;
- private boolean transacted;
+ //private boolean transacted;
private boolean xa;
+
+ private PacketSender sender;
+
+ //private boolean transactionalSends;
+
+ private boolean autoCommitSends;
+
+ private boolean autoCommitAcks;
// Constructors ---------------------------------------------------------------------------------
ServerSessionEndpoint(String sessionID, ServerConnectionEndpoint connectionEndpoint,
- boolean transacted, boolean xa) throws Exception
+ boolean autoCommitSends, boolean autoCommitAcks, boolean xa,
+ PacketSender sender) throws Exception
{
this.id = sessionID;
@@ -196,41 +183,198 @@
defaultRedeliveryDelay = sp.getConfiguration().getDefaultRedeliveryDelay();
- deliveries = new ConcurrentHashMap();
-
- deliveryIdSequence = new SynchronizedLong(0);
+ //this.transacted = transacted;
- this.transacted = transacted;
-
this.xa = xa;
- if (transacted && !xa)
+ tx = new TransactionImpl();
+
+
+ this.sender = sender;
+
+ //this.transactionalSends = transactionalSends;
+
+ this.autoCommitSends = autoCommitSends;
+
+ this.autoCommitAcks = autoCommitAcks;
+ }
+
+
+ // Public ---------------------------------------------------------------------------------------
+
+ public ServerConnectionEndpoint getConnectionEndpoint()
+ {
+ return connectionEndpoint;
+ }
+
+ public String toString()
+ {
+ return "SessionEndpoint[" + id + "]";
+ }
+
+ // Package protected ----------------------------------------------------------------------------
+
+ void expireDelivery(MessageReference ref, Queue expiryQueue) throws Exception
+ {
+ if (trace) { log.trace(this + " detected expired message " + ref); }
+
+// if (expiryQueue != null)
+// {
+// if (trace) { log.trace(this + " sending expired message to expiry queue " + expiryQueue); }
+//
+// Message copy = makeCopyForDLQOrExpiry(true, ref);
+//
+// moveInTransaction(copy, ref, expiryQueue, true);
+// }
+// else
+// {
+// log.warn("No expiry queue has been configured so removing expired " + ref);
+//
+// //TODO - tidy up these references - ugly
+// ref.acknowledge(this.getConnectionEndpoint().getMessagingServer().getPersistenceManager());
+// }
+
+ //TODO
+ }
+
+ void removeBrowser(String browserId) throws Exception
+ {
+ synchronized (browsers)
{
- tx = new TransactionImpl();
+ if (browsers.remove(browserId) == null)
+ {
+ throw new IllegalStateException("Cannot find browser with id " + browserId + " to remove");
+ }
}
}
- // SessionDelegate implementation ---------------------------------------------------------------
+ void removeConsumer(String consumerId) throws Exception
+ {
+ synchronized (consumers)
+ {
+ if (consumers.remove(consumerId) == null)
+ {
+ throw new IllegalStateException("Cannot find consumer with id " + consumerId + " to remove");
+ }
+ }
+ }
+ void localClose() throws Exception
+ {
+ if (closed)
+ {
+ throw new IllegalStateException("Session is already closed");
+ }
- private void checkSecurityCreateConsumerDelegate(Destination dest, String subscriptionName ) throws JMSException
+ if (trace) log.trace(this + " close()");
+
+ //We clone to avoid deadlock http://jira.jboss.org/jira/browse/JBMESSAGING-836
+ Map consumersClone;
+ synchronized (consumers)
+ {
+ consumersClone = new HashMap(consumers);
+ }
+
+ for( Iterator i = consumersClone.values().iterator(); i.hasNext(); )
+ {
+ ((ServerConsumerEndpoint)i.next()).localClose();
+ }
+
+ consumers.clear();
+
+
+ //We clone to avoid deadlock http://jira.jboss.org/jira/browse/JBMESSAGING-836
+ Map browsersClone;
+ synchronized (browsers)
+ {
+ browsersClone = new HashMap(browsers);
+ }
+
+ for( Iterator i = browsersClone.values().iterator(); i.hasNext(); )
+ {
+ ((ServerBrowserEndpoint)i.next()).localClose();
+ }
+
+ browsers.clear();
+
+ rollback();
+
+ //Close down the executor
+
+ //Note we need to wait for ALL tasks to complete NOT just one otherwise we can end up with the following situation
+ //prompter is queued and starts to execute
+ //prompter almost finishes executing then a message is cancelled due to this session closing
+ //this causes another prompter to be queued
+ //shutdownAfterProcessingCurrentTask is then called
+ //this means the second prompter never runs and the cancelled message doesn't get redelivered
+ executor.shutdownAfterProcessingCurrentlyQueuedTasks();
+
+ deliveries.clear();
+
+ sp.removeSession(id);
+
+ closed = true;
+ }
+
+ synchronized void handleDelivery(MessageReference ref, ServerConsumerEndpoint consumer,
+ PacketSender sender) throws Exception
+ {
+ //FIXME - we shouldn't have to pass in the packet Sender - this should be creatable
+ //without the consumer having to call change rate first
+ Delivery delivery = new DeliveryImpl(ref, consumer.getID(), deliveryIDSequence++, sender);
+
+ deliveries.add(delivery);
+
+ delivery.deliver();
+ }
+
+ /**
+ * Starts this session's Consumers
+ */
+ void setStarted(boolean s) throws Exception
{
- security.check(dest, CheckType.READ, this.getConnectionEndpoint());
+ //We clone to prevent deadlock http://jira.jboss.org/jira/browse/JBMESSAGING-836
+ Map consumersClone;
+ synchronized(consumers)
+ {
+ consumersClone = new HashMap(consumers);
+ }
- // if creating a durable subscription then need create permission
+ for(Iterator i = consumersClone.values().iterator(); i.hasNext(); )
+ {
+ ServerConsumerEndpoint sce = (ServerConsumerEndpoint)i.next();
+ if (s)
+ {
+ sce.start();
+ }
+ else
+ {
+ sce.stop();
+ }
+ }
+ }
- if (subscriptionName != null)
+ void promptDelivery(final Queue queue)
+ {
+ if (trace) { log.trace("Prompting delivery on " + queue); }
+
+ try
{
- // durable
- security.check(dest, CheckType.CREATE, this.getConnectionEndpoint());
+ //TODO - do we really need to prompt on a different thread?
+ this.executor.execute(new Runnable() { public void run() { queue.deliver();} } );
+
}
+ catch (Throwable t)
+ {
+ log.error("Failed to prompt delivery", t);
+ }
}
- public CreateConsumerResponse createConsumerDelegate(Destination destination,
- String filterString,
- boolean noLocal,
- String subscriptionName,
- boolean isCC) throws JMSException
+ private CreateConsumerResponse createServerConsumer(Destination destination,
+ String filterString,
+ boolean noLocal,
+ String subscriptionName,
+ boolean isCC) throws JMSException
{
checkSecurityCreateConsumerDelegate(destination, subscriptionName);
@@ -245,8 +389,8 @@
}
}
- public CreateBrowserResponse createBrowserDelegate(Destination destination,
- String filterString)
+ private CreateBrowserResponse createServerBrowser(Destination destination,
+ String filterString)
throws JMSException
{
security.check(destination, CheckType.READ, this.getConnectionEndpoint());
@@ -261,7 +405,7 @@
}
}
- public JBossQueue createQueue(String name) throws JMSException
+ private JBossQueue createQueue(String name) throws JMSException
{
try
{
@@ -287,7 +431,7 @@
}
}
- public JBossTopic createTopic(String name) throws JMSException
+ private JBossTopic createTopic(String name) throws JMSException
{
try
{
@@ -312,8 +456,12 @@
throw ExceptionUtil.handleJMSInvocation(t, this + " createTopic");
}
}
+
+ private void closing() throws JMSException
+ {
+ }
- public void close() throws JMSException
+ private void close() throws JMSException
{
try
{
@@ -329,157 +477,54 @@
}
}
- public long closing(long sequence) throws JMSException
+ private void send(Message msg) throws JMSException
{
- if (trace) log.trace(this + " closing");
-
- // Wait for last np message to arrive
-
- if (sequence != 0)
- {
- synchronized (waitLock)
- {
- long wait = CLOSE_WAIT_TIMEOUT;
-
- while (sequence != expectedSequence && wait > 0)
- {
- long start = System.currentTimeMillis();
- try
- {
- waitLock.wait();
- }
- catch (InterruptedException e)
- {
- }
- wait -= (System.currentTimeMillis() - start);
- }
-
- if (wait <= 0)
- {
- log.warn("Timed out waiting for last message");
- }
- }
- }
-
- return -1;
- }
-
- private volatile long expectedSequence = 0;
-
- public void send(Message message) throws JMSException
- {
- throw new IllegalStateException("Should not be handled on the server");
- }
-
- public void send(Message message, long thisSequence) throws JMSException
- {
try
{
- if (thisSequence != -1)
- {
- synchronized (waitLock)
- {
- connectionEndpoint.sendMessage(message);
+ Destination dest = (Destination)msg.getHeader(org.jboss.messaging.core.Message.TEMP_DEST_HEADER_NAME);
- expectedSequence++;
+ //Assign the message an internal id - this is used to key it in the store and also used to
+ //handle delivery
+
+ msg.setMessageID(sp.getPersistenceManager().generateMessageID());
+
+ // This allows the no-local consumers to filter out the messages that come from the same
+ // connection.
- waitLock.notify();
- }
- }
- else
- {
- connectionEndpoint.sendMessage(message);
- }
+ msg.setConnectionID(connectionEndpoint.getConnectionID());
- if (message.isDurable())
- {
- sp.getPersistenceManager().addMessage(message);
- }
-
- message.send();
- }
- catch (Throwable t)
- {
- throw ExceptionUtil.handleJMSInvocation(t, this + " send");
- }
- }
-
- public boolean acknowledgeDelivery(Ack ack) throws JMSException
- {
- try
- {
- return acknowledgeDeliveryInternal(ack);
- }
- catch (Throwable t)
- {
- JMSException e = ExceptionUtil.handleJMSInvocation(t, this + " acknowledgeDelivery");
-
- throw e;
- }
- }
-
- public void acknowledgeDeliveries(List acks) throws JMSException
- {
- if (trace) {log.trace(this + " acknowledges deliveries " + acks); }
-
- try
- {
- Iterator iter = acks.iterator();
-
- while (iter.hasNext())
+ Condition condition = new ConditionImpl(dest.getType(), dest.getName());
+
+ postOffice.route(condition, msg);
+
+ //FIXME - this check belongs on the client side!!
+
+ if (dest.getType() == DestinationType.QUEUE && msg.getReferences().isEmpty())
{
- Ack ack = (Ack)iter.next();
-
- acknowledgeDeliveryInternal(ack);
+ throw new InvalidDestinationException("Failed to route to queue " + dest.getName());
}
- }
- catch (Throwable t)
- {
- throw ExceptionUtil.handleJMSInvocation(t, this + " acknowledgeDeliveries");
- }
- }
-
- public void cancelDelivery(Cancel cancel) throws JMSException
- {
- try
- {
- if (trace) {log.trace(this + " cancelDelivery " + cancel); }
-
- cancelDeliveryInternal(cancel);
- }
- catch (Throwable t)
- {
- throw ExceptionUtil.handleJMSInvocation(t, this + " acknowledgeDeliveries");
- }
- }
-
- public void cancelDeliveries(List cancels) throws JMSException
- {
- if (trace) {log.trace(this + " cancels deliveries " + cancels); }
-
- try
- {
- // deliveries must be cancelled in reverse order
-
- for (int i = cancels.size() - 1; i >= 0; i--)
+
+ if (autoCommitSends)
{
- Cancel cancel = (Cancel)cancels.get(i);
+ if (msg.getNumDurableReferences() != 0)
+ {
+ sp.getPersistenceManager().addMessage(msg);
+ }
- if (trace) { log.trace(this + " cancelling delivery " + cancel.getDeliveryId()); }
-
- cancelDeliveryInternal(cancel);
+ msg.send();
}
-
- if (trace) { log.trace("Cancelled deliveries"); }
-
+ else
+ {
+ tx.addMessage(msg);
+ }
}
catch (Throwable t)
{
- throw ExceptionUtil.handleJMSInvocation(t, this + " cancelDeliveries");
+ throw ExceptionUtil.handleJMSInvocation(t, this + " send");
}
}
- public void addTemporaryDestination(Destination dest) throws JMSException
+ private void addTemporaryDestination(Destination dest) throws JMSException
{
try
{
@@ -515,7 +560,7 @@
}
}
- public void deleteTemporaryDestination(Destination dest) throws JMSException
+ private void deleteTemporaryDestination(Destination dest) throws JMSException
{
try
{
@@ -579,7 +624,7 @@
}
}
- public void unsubscribe(String subscriptionName) throws JMSException
+ private void unsubscribe(String subscriptionName) throws JMSException
{
log.trace(this + " unsubscribing " + subscriptionName);
@@ -670,385 +715,252 @@
throw ExceptionUtil.handleJMSInvocation(t, this + " unsubscribe");
}
}
-
- public int getDupsOKBatchSize()
+
+
+ private synchronized void acknowledge(long deliveryID, boolean allUpTo) throws JMSException
{
- throw new RuntimeException("information only available on client side");
- }
-
- public boolean isStrictTck()
- {
- throw new RuntimeException("information only available on client side");
- }
-
- // Public ---------------------------------------------------------------------------------------
-
- public ServerConnectionEndpoint getConnectionEndpoint()
- {
- return connectionEndpoint;
- }
-
- public String toString()
- {
- return "SessionEndpoint[" + id + "]";
- }
-
- // Package protected ----------------------------------------------------------------------------
-
- void expireDelivery(MessageReference ref, Queue expiryQueue) throws Exception
- {
- if (trace) { log.trace(this + " detected expired message " + ref); }
-
- if (expiryQueue != null)
+ //Note that we do not consider it an error if the deliveries cannot be found to be acked.
+ //This can legitimately occur if a connection/session/consumer is closed from inside a MessageHandlers
+ //onMessage method. In this situation the close will cancel any unacked deliveries, but the subsequent
+ //call to delivered() will try and ack again and not find the last delivery on the server.
+ try
{
- if (trace) { log.trace(this + " sending expired message to expiry queue " + expiryQueue); }
-
- Message copy = makeCopyForDLQOrExpiry(true, ref);
-
- moveInTransaction(copy, ref, expiryQueue, true);
- }
- else
- {
- log.warn("No expiry queue has been configured so removing expired " + ref);
-
- //TODO - tidy up these references - ugly
- ref.acknowledge(this.getConnectionEndpoint().getMessagingServer().getPersistenceManager());
- }
- }
-
- void removeBrowser(String browserId) throws Exception
- {
- synchronized (browsers)
- {
- if (browsers.remove(browserId) == null)
+ if (allUpTo)
{
- throw new IllegalStateException("Cannot find browser with id " + browserId + " to remove");
+ //Ack all deliveries up to and including the specified id
+
+ for (Iterator<Delivery> iter = deliveries.iterator(); iter.hasNext();)
+ {
+ Delivery rec = iter.next();
+
+ if (rec.getDeliveryID() <= deliveryID)
+ {
+ iter.remove();
+
+ MessageReference ref = rec.getReference();
+
+ if (rec.getDeliveryID() > deliveryID)
+ {
+ //This catches the case where the delivery has been cancelled since it's expired
+ //And we don't want to end up acking all deliveries!
+ break;
+ }
+
+ if (autoCommitAcks)
+ {
+ ref.acknowledge(sp.getPersistenceManager());
+ }
+ else
+ {
+ tx.addAcknowledgement(ref);
+ }
+
+ if (rec.getDeliveryID() == deliveryID)
+ {
+ break;
+ }
+ }
+ else
+ {
+ //Sanity check
+ throw new IllegalStateException("Failed to ack contiguently");
+ }
+ }
}
- }
- }
-
- void removeConsumer(String consumerId) throws Exception
- {
- synchronized (consumers)
- {
- if (consumers.remove(consumerId) == null)
+ else
{
- throw new IllegalStateException("Cannot find consumer with id " + consumerId + " to remove");
+ //Ack a specific delivery
+
+ for (Iterator<Delivery> iter = deliveries.iterator(); iter.hasNext();)
+ {
+ Delivery rec = iter.next();
+
+ if (rec.getDeliveryID() == deliveryID)
+ {
+ iter.remove();
+
+ MessageReference ref = rec.getReference();
+
+ if (autoCommitAcks)
+ {
+ ref.acknowledge(sp.getPersistenceManager());
+ }
+ else
+ {
+ tx.addAcknowledgement(ref);
+ }
+
+ break;
+ }
+ }
}
}
- }
-
- void localClose() throws Exception
- {
- if (closed)
+ catch (Throwable t)
{
- throw new IllegalStateException("Session is already closed");
+ throw ExceptionUtil.handleJMSInvocation(t, this + " acknowledge");
}
-
- if (trace) log.trace(this + " close()");
-
- //We clone to avoid deadlock http://jira.jboss.org/jira/browse/JBMESSAGING-836
- Map consumersClone;
- synchronized (consumers)
- {
- consumersClone = new HashMap(consumers);
- }
-
- for( Iterator i = consumersClone.values().iterator(); i.hasNext(); )
- {
- ((ServerConsumerEndpoint)i.next()).localClose();
- }
-
- consumers.clear();
-
-
- //We clone to avoid deadlock http://jira.jboss.org/jira/browse/JBMESSAGING-836
- Map browsersClone;
- synchronized (browsers)
- {
- browsersClone = new HashMap(browsers);
- }
-
- for( Iterator i = browsersClone.values().iterator(); i.hasNext(); )
- {
- ((ServerBrowserEndpoint)i.next()).localClose();
- }
-
- browsers.clear();
-
-
- //Now cancel any remaining deliveries in reverse delivery order
- //Note we don't maintain order using a LinkedHashMap since then we lose
- //concurrency since we would have to lock it exclusively
-
- List entries = new ArrayList(deliveries.entrySet());
-
- //Sort them in reverse delivery id order
- Collections.sort(entries,
- new Comparator()
- {
- public int compare(Object obj1, Object obj2)
- {
- Map.Entry entry1 = (Map.Entry)obj1;
- Map.Entry entry2 = (Map.Entry)obj2;
- Long id1 = (Long)entry1.getKey();
- Long id2 = (Long)entry2.getKey();
- return id2.compareTo(id1);
- }
- });
-
- Iterator iter = entries.iterator();
-
- if (trace) { log.trace(this + " cancelling " + entries.size() + " deliveries"); }
-
- while (iter.hasNext())
- {
- Map.Entry entry = (Map.Entry)iter.next();
-
- if (trace) { log.trace(this + " cancelling delivery with delivery id: " + entry.getKey()); }
-
- DeliveryRecord rec = (DeliveryRecord)entry.getValue();
-
- rec.ref.cancel(this.sp.getPersistenceManager());
- }
-
- //Close down the executor
-
- //Note we need to wait for ALL tasks to complete NOT just one otherwise we can end up with the following situation
- //prompter is queued and starts to execute
- //prompter almost finishes executing then a message is cancelled due to this session closing
- //this causes another prompter to be queued
- //shutdownAfterProcessingCurrentTask is then called
- //this means the second prompter never runs and the cancelled message doesn't get redelivered
- executor.shutdownAfterProcessingCurrentlyQueuedTasks();
-
- deliveries.clear();
-
- sp.removeSession(id);
-
- closed = true;
}
-
- void cancelDelivery(long deliveryId) throws Exception
- {
- DeliveryRecord rec = (DeliveryRecord)deliveries.remove(new Long(deliveryId));
-
- if (rec == null)
- {
- throw new IllegalStateException("Cannot find delivery to cancel " + deliveryId);
+
+ private void rollback() throws JMSException
+ {
+ try
+ {
+ //Synchronize to prevent any new deliveries arriving during this recovery
+ synchronized (this)
+ {
+ //Add any unacked deliveries into the tx
+ //Doing this ensures all references are rolled back in the correct order
+ //in a single contiguous block
+
+ for (Delivery del: deliveries)
+ {
+ tx.addAcknowledgement(del.getReference());
+ }
+
+ deliveries.clear();
+
+ deliveryIDSequence -= tx.getAcknowledgementsCount();
+ }
+
+ tx.rollback(sp.getPersistenceManager());
}
-
- rec.ref.cancel(this.sp.getPersistenceManager());
- }
-
- //TODO NOTE! This needs to be synchronized to prevent deliveries coming back
- //out of order! There maybe some better way of doing this
- synchronized void handleDelivery(MessageReference ref, ServerConsumerEndpoint consumer) throws Exception
- {
- long deliveryId = -1;
-
- DeliveryRecord rec = null;
-
- deliveryId = deliveryIdSequence.increment();
-
- if (trace) { log.trace("Delivery id is now " + deliveryId); }
-
- // Add a delivery
-
- rec = new DeliveryRecord(ref, consumer, deliveryId);
-
- deliveries.put(new Long(deliveryId), rec);
-
- if (trace) { log.trace(this + " added delivery " + deliveryId + ": " + ref); }
-
- performDelivery(ref, deliveryId, consumer);
- }
-
- void performDelivery(MessageReference ref, long deliveryID, ServerConsumerEndpoint consumer)
- {
- if (consumer == null)
- {
- if (trace) { log.trace(this + " consumer is null, cannot perform delivery"); }
-
- return;
- }
-
- if (trace) { log.trace(this + " performing delivery for " + ref); }
-
- // We send the message to the client on the current thread. The message is written onto the
- // transport and then the thread returns immediately without waiting for a response.
-
- DeliverMessage m = new DeliverMessage(ref.getMessage(), consumer.getID(), deliveryID, ref.getDeliveryCount());
- m.setVersion(getConnectionEndpoint().getUsingVersion());
- consumer.deliver(m);
-
- //TODO - what if we get an exception from MINA?
- //Surely we need to do exception logic too???
-
-// }
-// catch (Throwable t)
-// {
-// // it's an oneway callback, so exception could only have happened on the server, while
-// // trying to send the callback. This is a good reason to smack the whole connection.
-// // I trust remoting to have already done its own cleanup via a CallbackErrorHandler,
-// // I need to do my own cleanup at ConnectionManager level.
-//
-// log.trace(this + " failed to handle callback", t);
-//
-// //We stop the consumer - some time later the lease will expire and the connection will be closed
-// //which will remove the consumer
-//
-// consumer.setStarted(false);
-//
-// consumer.setDead();
-//
-// //** IMPORTANT NOTE! We must return the delivery NOT null. **
-// //This is because if we return NULL then message will remain in the queue, but later
-// //the connection checker will cleanup and close this consumer which will cancel all the deliveries in it
-// //including this one, so the message will go back on the queue twice!
-// }
- }
-
- List<MessageReference> acknowledgeTransactionally(List<Ack> acks, Transaction tx) throws Exception
- {
- if (trace) { log.trace(this + " acknowledging transactionally " + acks.size() + " messages for " + tx); }
-
- List<MessageReference> refs = new ArrayList<MessageReference>();
-
- for(Ack ack: acks)
+ catch (Throwable t)
{
- long id = ack.getDeliveryID();
-
- DeliveryRecord rec = (DeliveryRecord)deliveries.get(id);
-
- DeliveryCallback cb = new DeliveryCallback(id);
-
- tx.addSynchronization(cb);
-
- refs.add(rec.ref);
-
- if (rec.ref.getMessage().isDurable() && rec.getConsumer().getMessageQueue().isDurable())
- {
- tx.setContainsPersistent(true);
- }
+ throw ExceptionUtil.handleJMSInvocation(t, this + " commit");
}
-
- return refs;
}
-
- /**
- * Starts this session's Consumers
- */
- void setStarted(boolean s) throws Exception
+
+ private void cancel(long deliveryID, boolean expired) throws JMSException
{
- //We clone to prevent deadlock http://jira.jboss.org/jira/browse/JBMESSAGING-836
- Map consumersClone;
- synchronized(consumers)
+ try
{
- consumersClone = new HashMap(consumers);
- }
-
- for(Iterator i = consumersClone.values().iterator(); i.hasNext(); )
- {
- ServerConsumerEndpoint sce = (ServerConsumerEndpoint)i.next();
- if (s)
+ if (deliveryID == -1)
{
- sce.start();
+ //Cancel all
+
+ Transaction cancelTx;
+
+ synchronized (this)
+ {
+ cancelTx = new TransactionImpl();
+
+ for (Delivery del: deliveries)
+ {
+ cancelTx.addAcknowledgement(del.getReference());
+ }
+
+ deliveries.clear();
+ }
+
+ cancelTx.rollback(sp.getPersistenceManager());
}
else
{
- sce.stop();
+ for (Iterator<Delivery> iter = deliveries.iterator(); iter.hasNext();)
+ {
+ Delivery delivery = iter.next();
+
+ if (delivery.getDeliveryID() == deliveryID)
+ {
+ //TODO - send to expiry queue
+ delivery.getReference().acknowledge(sp.getPersistenceManager());
+ }
+
+ iter.remove();
+
+ break;
+ }
}
}
+ catch (Throwable t)
+ {
+ throw ExceptionUtil.handleJMSInvocation(t, this + " commit");
+ }
}
-
- void promptDelivery(final Queue queue)
+
+ private void commit() throws JMSException
{
- if (trace) { log.trace("Prompting delivery on " + queue); }
-
try
{
- //TODO - do we really need to prompt on a different thread?
- this.executor.execute(new Runnable() { public void run() { queue.deliver();} } );
-
+ tx.commit(sp.getPersistenceManager());
}
catch (Throwable t)
{
- log.error("Failed to prompt delivery", t);
+ throw ExceptionUtil.handleJMSInvocation(t, this + " commit");
}
}
-
+
// Protected ------------------------------------------------------------------------------------
// Private --------------------------------------------------------------------------------------
- private void cancelDeliveryInternal(Cancel cancel) throws Exception
- {
- DeliveryRecord rec = (DeliveryRecord)deliveries.remove(cancel.getDeliveryId());
+// private void cancelDeliveryInternal(Cancel cancel) throws Exception
+// {
+// DeliveryRecord rec = (DeliveryRecord)deliveries.remove(cancel.getDeliveryId());
+//
+// if (rec == null)
+// {
+// //The delivery might not be found, if the session is not replicated (i.e. auto_ack or dups_ok)
+// //and has failed over since recoverDeliveries won't have been called
+// if (trace)
+// {
+// log.trace("Cannot find delivery to cancel, session probably failed over and is not replicated");
+// }
+// return;
+// }
+//
+// MessageReference ref = rec.ref;
+//
+// //Note we check the flag *and* evaluate again, this is because the server and client clocks may
+// //be out of synch and don't want to send back to the client a message it thought it has sent to
+// //the expiry queue
+// boolean expired = cancel.isExpired() || ref.getMessage().isExpired();
+//
+// //Note we check the flag *and* evaluate again, this is because the server value of maxDeliveries
+// //might get changed after the client has sent the cancel - and we don't want to end up cancelling
+// //back to the original queue
+// boolean reachedMaxDeliveryAttempts =
+// cancel.isReachedMaxDeliveryAttempts() || cancel.getDeliveryCount() >= rec.maxDeliveryAttempts;
+//
+// if (!expired && !reachedMaxDeliveryAttempts)
+// {
+// //Normal cancel back to the queue
+//
+// ref.setDeliveryCount(cancel.getDeliveryCount());
+//
+// //Do we need to set a redelivery delay?
+//
+// if (rec.redeliveryDelay != 0)
+// {
+// ref.setScheduledDeliveryTime(System.currentTimeMillis() + rec.redeliveryDelay);
+// }
+//
+// if (trace) { log.trace("Cancelling delivery " + cancel.getDeliveryId()); }
+//
+// ref.cancel(sp.getPersistenceManager());
+//
+// }
+// else
+// {
+// if (expired)
+// {
+// //Sent to expiry queue
+//
+// Message copy = makeCopyForDLQOrExpiry(true, ref);
+//
+// moveInTransaction(copy, ref, rec.expiryQueue, false);
+// }
+// else
+// {
+// //Send to DLQ
+//
+// Message copy = makeCopyForDLQOrExpiry(false, ref);
+//
+// moveInTransaction(copy, ref, rec.dlq, true);
+// }
+// }
+// }
- if (rec == null)
- {
- //The delivery might not be found, if the session is not replicated (i.e. auto_ack or dups_ok)
- //and has failed over since recoverDeliveries won't have been called
- if (trace)
- {
- log.trace("Cannot find delivery to cancel, session probably failed over and is not replicated");
- }
- return;
- }
-
- MessageReference ref = rec.ref;
-
- //Note we check the flag *and* evaluate again, this is because the server and client clocks may
- //be out of synch and don't want to send back to the client a message it thought it has sent to
- //the expiry queue
- boolean expired = cancel.isExpired() || ref.getMessage().isExpired();
-
- //Note we check the flag *and* evaluate again, this is because the server value of maxDeliveries
- //might get changed after the client has sent the cancel - and we don't want to end up cancelling
- //back to the original queue
- boolean reachedMaxDeliveryAttempts =
- cancel.isReachedMaxDeliveryAttempts() || cancel.getDeliveryCount() >= rec.maxDeliveryAttempts;
-
- if (!expired && !reachedMaxDeliveryAttempts)
- {
- //Normal cancel back to the queue
-
- ref.setDeliveryCount(cancel.getDeliveryCount());
-
- //Do we need to set a redelivery delay?
-
- if (rec.redeliveryDelay != 0)
- {
- ref.setScheduledDeliveryTime(System.currentTimeMillis() + rec.redeliveryDelay);
- }
-
- if (trace) { log.trace("Cancelling delivery " + cancel.getDeliveryId()); }
-
- ref.cancel(sp.getPersistenceManager());
-
- }
- else
- {
- if (expired)
- {
- //Sent to expiry queue
-
- Message copy = makeCopyForDLQOrExpiry(true, ref);
-
- moveInTransaction(copy, ref, rec.expiryQueue, false);
- }
- else
- {
- //Send to DLQ
-
- Message copy = makeCopyForDLQOrExpiry(false, ref);
-
- moveInTransaction(copy, ref, rec.dlq, true);
- }
- }
- }
-
private Message makeCopyForDLQOrExpiry(boolean expiry, MessageReference ref) throws Exception
{
//We copy the message and send that to the dlq/expiry queue - this is because
@@ -1091,64 +1003,46 @@
return copy;
}
- private void moveInTransaction(Message msg, MessageReference ref, Queue queue, boolean dlq) throws Exception
- {
- List<Message> msgs = new ArrayList<Message>();
-
- msgs.add(msg);
-
- List<MessageReference> refs = new ArrayList<MessageReference>();
-
- refs.add(ref);
-
- Transaction tx = new TransactionImpl(msgs, refs, msg.isDurable());
-
- //FIXME - clear up these ugly refs to the pm
- tx.commit(getConnectionEndpoint().getMessagingServer().getPersistenceManager());
-
-// MessageReference ref = msg.createReference();
+// private void moveInTransaction(Message msg, MessageReference ref, Queue queue, boolean dlq) throws Exception
+// {
+// List<Message> msgs = new ArrayList<Message>();
//
-// try
-// {
-// if (queue != null)
-// {
-// queue.handle(null, ref, tx);
-// del.acknowledge(tx);
-// }
-// else
-// {
-// log.warn("No " + (dlq ? "DLQ" : "expiry queue") + " has been specified so the message will be removed");
+// msgs.add(msg);
//
-// del.acknowledge(tx);
-// }
+// List<MessageReference> refs = new ArrayList<MessageReference>();
//
-// tx.commit();
-// }
-// catch (Throwable t)
-// {
-// tx.rollback();
-// throw t;
-// }
- }
+// refs.add(ref);
+//
+// Transaction tx = new TransactionImpl(msgs, refs, msg.isDurable());
+//
+// //FIXME - clear up these ugly refs to the pm
+// tx.commit(getConnectionEndpoint().getMessagingServer().getPersistenceManager());
+//
+//// MessageReference ref = msg.createReference();
+////
+//// try
+//// {
+//// if (queue != null)
+//// {
+//// queue.handle(null, ref, tx);
+//// del.acknowledge(tx);
+//// }
+//// else
+//// {
+//// log.warn("No " + (dlq ? "DLQ" : "expiry queue") + " has been specified so the message will be removed");
+////
+//// del.acknowledge(tx);
+//// }
+////
+//// tx.commit();
+//// }
+//// catch (Throwable t)
+//// {
+//// tx.rollback();
+//// throw t;
+//// }
+// }
- private boolean acknowledgeDeliveryInternal(Ack ack) throws Exception
- {
- if (trace) { log.trace(this + " acknowledging delivery " + ack); }
-
- DeliveryRecord rec = (DeliveryRecord)deliveries.remove(ack.getDeliveryID());
-
- if (rec != null)
- {
- rec.ref.acknowledge(this.sp.getPersistenceManager());
-
- if (trace) { log.trace(this + " acknowledged delivery " + ack); }
-
- return true;
- }
-
- return false;
- }
-
private CreateConsumerResponse createConsumerDelegateInternal(Destination destination,
String filterString,
boolean noLocal,
@@ -1440,131 +1334,146 @@
return new CreateBrowserResponse(browserID);
}
-
- // Inner classes --------------------------------------------------------------------------------
-
- /*
- * Holds a record of a delivery - we need to store the consumer id as well
- * hence this class
- * We can't rely on the cancel being driven from the ClientConsumer since
- * the deliveries may have got lost in transit (ignored) since the consumer might have closed
- * when they were in transit.
- * In such a case we might otherwise end up with the consumer closing but not all it's deliveries being
- * cancelled, which would mean they wouldn't be cancelled until the session is closed which is too late
- *
- * We need to store various pieces of information, such as consumer id, dlq, expiry queue
- * since we need this at cancel time, but by then the actual consumer might have closed
- */
- private static class DeliveryRecord
+
+ private void checkSecurityCreateConsumerDelegate(Destination dest, String subscriptionName ) throws JMSException
{
- // We need to cache the attributes here since the consumer may get gc'd BEFORE the delivery is acked
+ security.check(dest, CheckType.READ, this.getConnectionEndpoint());
- MessageReference ref;
+ // if creating a durable subscription then need create permission
- Queue dlq;
-
- Queue expiryQueue;
-
- long redeliveryDelay;
-
- int maxDeliveryAttempts;
-
- WeakReference consumerRef;
-
- String queueName;
-
- long deliveryID;
-
- ServerConsumerEndpoint getConsumer()
+ if (subscriptionName != null)
{
- if (consumerRef != null)
- {
- return (ServerConsumerEndpoint)consumerRef.get();
- }
- else
- {
- return null;
- }
+ // durable
+ security.check(dest, CheckType.CREATE, this.getConnectionEndpoint());
}
-
- private DeliveryRecord(MessageReference ref, Queue dlq, Queue expiryQueue, long redeliveryDelay, int maxDeliveryAttempts,
- String queueName, long deliveryID)
- {
- this.ref = ref;
-
- this.dlq = dlq;
-
- this.expiryQueue = expiryQueue;
-
- this.redeliveryDelay = redeliveryDelay;
-
- this.maxDeliveryAttempts = maxDeliveryAttempts;
-
- this.queueName = queueName;
-
- this.deliveryID = deliveryID;
- }
-
- DeliveryRecord(MessageReference ref, ServerConsumerEndpoint consumer, long deliveryID)
- {
- this (ref, consumer.getDLQ(), consumer.getExpiryQueue(), consumer.getRedliveryDelay(), consumer.getMaxDeliveryAttempts(),
- consumer.getQueueName(), deliveryID);
-
- // We need to cache the attributes here since the consumer may get gc'd BEFORE the delivery is acked
-
-
- //We hold a WeakReference to the consumer - this is only needed when replicating - where we store the delivery then wait
- //for the response to come back from the replicant before actually performing delivery
- //We need a weak ref since when the consumer closes deliveries may still and remain and we don't want that to prevent
- //the consumer being gc'd
-
- //FIXME - do we still need this??
- this.consumerRef = new WeakReference(consumer);
- }
-
- public String toString()
- {
- return "DeliveryRecord " + System.identityHashCode(this) + " ref: " + ref + " queueName: " + queueName;
- }
}
- /**
- *
- * The purpose of this class is to remove deliveries from the delivery list on commit
- * Each transaction has once instance of this per SCE
- *
- */
- private class DeliveryCallback implements TransactionSynchronization
- {
- private long deliveryId;
- DeliveryCallback(long deliveryId)
- {
- this.deliveryId = deliveryId;
- }
+ // Inner classes --------------------------------------------------------------------------------
- public void afterCommit() throws Exception
- {
- deliveries.remove(deliveryId);
- }
+// /*
+// * Holds a record of a delivery - we need to store the consumer id as well
+// * hence this class
+// * We can't rely on the cancel being driven from the ClientConsumer since
+// * the deliveries may have got lost in transit (ignored) since the consumer might have closed
+// * when they were in transit.
+// * In such a case we might otherwise end up with the consumer closing but not all it's deliveries being
+// * cancelled, which would mean they wouldn't be cancelled until the session is closed which is too late
+// *
+// * We need to store various pieces of information, such as consumer id, dlq, expiry queue
+// * since we need this at cancel time, but by then the actual consumer might have closed
+// */
+// private static class DeliveryRecord
+// {
+// // We need to cache the attributes here since the consumer may get gc'd BEFORE the delivery is acked
+//
+// MessageReference ref;
+//
+// Queue dlq;
+//
+// Queue expiryQueue;
+//
+// long redeliveryDelay;
+//
+// int maxDeliveryAttempts;
+//
+// WeakReference consumerRef;
+//
+// String queueName;
+//
+// long deliveryID;
+//
+// ServerConsumerEndpoint getConsumer()
+// {
+// if (consumerRef != null)
+// {
+// return (ServerConsumerEndpoint)consumerRef.get();
+// }
+// else
+// {
+// return null;
+// }
+// }
+//
+// private DeliveryRecord(MessageReference ref, Queue dlq, Queue expiryQueue, long redeliveryDelay, int maxDeliveryAttempts,
+// String queueName, long deliveryID)
+// {
+// this.ref = ref;
+//
+// this.dlq = dlq;
+//
+// this.expiryQueue = expiryQueue;
+//
+// this.redeliveryDelay = redeliveryDelay;
+//
+// this.maxDeliveryAttempts = maxDeliveryAttempts;
+//
+// this.queueName = queueName;
+//
+// this.deliveryID = deliveryID;
+// }
+//
+// DeliveryRecord(MessageReference ref, ServerConsumerEndpoint consumer, long deliveryID)
+// {
+// this (ref, consumer.getDLQ(), consumer.getExpiryQueue(), consumer.getRedliveryDelay(), consumer.getMaxDeliveryAttempts(),
+// consumer.getQueueName(), deliveryID);
+//
+// // We need to cache the attributes here since the consumer may get gc'd BEFORE the delivery is acked
+//
+//
+// //We hold a WeakReference to the consumer - this is only needed when replicating - where we store the delivery then wait
+// //for the response to come back from the replicant before actually performing delivery
+// //We need a weak ref since when the consumer closes deliveries may still and remain and we don't want that to prevent
+// //the consumer being gc'd
+//
+// //FIXME - do we still need this??
+// this.consumerRef = new WeakReference(consumer);
+// }
+//
+// public String toString()
+// {
+// return "DeliveryRecord " + System.identityHashCode(this) + " ref: " + ref + " queueName: " + queueName;
+// }
+// }
- public void afterRollback() throws Exception
- {
- //One phase rollbacks never hit the server - they are dealt with locally only
- //so this would only ever be executed for a two phase rollback.
-
- //We don't do anything since cancellation is driven from the client.
- }
-
- public void beforeCommit() throws Exception
- {
- }
-
- public void beforeRollback() throws Exception
- {
- }
- }
-
+// /**
+// *
+// * The purpose of this class is to remove deliveries from the delivery list on commit
+// * Each transaction has once instance of this per SCE
+// *
+// */
+// private class DeliveryCallback implements TransactionSynchronization
+// {
+// private long deliveryId;
+//
+// DeliveryCallback(long deliveryId)
+// {
+// this.deliveryId = deliveryId;
+// }
+//
+// public void afterCommit() throws Exception
+// {
+// //deliveries.remove(deliveryId);
+// }
+//
+// public void afterRollback() throws Exception
+// {
+// //One phase rollbacks never hit the server - they are dealt with locally only
+// //so this would only ever be executed for a two phase rollback.
+//
+// //We don't do anything since cancellation is driven from the client.
+// }
+//
+// public void beforeCommit() throws Exception
+// {
+// }
+//
+// public void beforeRollback() throws Exception
+// {
+// }
+// }
+//
+
public PacketHandler newHandler()
{
return new SessionAdvisedPacketHandler();
@@ -1574,9 +1483,7 @@
// INNER CLASSES
private class SessionAdvisedPacketHandler implements PacketHandler
- {
-
-
+ {
public SessionAdvisedPacketHandler()
{
}
@@ -1595,13 +1502,11 @@
PacketType type = packet.getType();
if (type == MSG_SENDMESSAGE)
{
- SendMessage message = (SendMessage) packet;
+ SessionSendMessage message = (SessionSendMessage) packet;
+
+ send(message.getMessage());
- long sequence = message.getSequence();
- send(message.getMessage(), sequence);
-
- // a response is required only if seq == -1 -> reliable message or strict TCK
- if (sequence == -1)
+ if (message.getMessage().isDurable())
{
response = new NullPacket();
}
@@ -1609,7 +1514,7 @@
} else if (type == REQ_CREATECONSUMER)
{
CreateConsumerRequest request = (CreateConsumerRequest) packet;
- response = createConsumerDelegate(
+ response = createServerConsumer(
request.getDestination(), request.getSelector(), request
.isNoLocal(), request.getSubscriptionName(), request
.isConnectionConsumer());
@@ -1629,39 +1534,14 @@
} else if (type == REQ_CREATEBROWSER)
{
CreateBrowserRequest request = (CreateBrowserRequest) packet;
- response = createBrowserDelegate(
+ response = createServerBrowser(
request.getDestination(), request.getSelector());
- } else if (type == REQ_ACKDELIVERY)
+ }
+ else if (type == PacketType.MSG_CLOSING)
{
- AcknowledgeDeliveryRequest request = (AcknowledgeDeliveryRequest) packet;
- boolean acknowledged = acknowledgeDelivery(new AckImpl(
- request.getDeliveryID()));
+ closing();
- response = new AcknowledgeDeliveryResponse(acknowledged);
- } else if (type == MSG_ACKDELIVERIES)
- {
- AcknowledgeDeliveriesMessage message = (AcknowledgeDeliveriesMessage) packet;
- acknowledgeDeliveries(message.getAcks());
-
response = new NullPacket();
- } else if (type == MSG_CANCELDELIVERY)
- {
- CancelDeliveryMessage message = (CancelDeliveryMessage) packet;
- cancelDelivery(message.getCancel());
-
- response = new NullPacket();
- } else if (type == MSG_CANCELDELIVERIES)
- {
- CancelDeliveriesMessage message = (CancelDeliveriesMessage) packet;
- cancelDeliveries(message.getCancels());
-
- response = new NullPacket();
- } else if (type == REQ_CLOSING)
- {
- ClosingRequest request = (ClosingRequest) packet;
- long id = closing(request.getSequence());
-
- response = new ClosingResponse(id);
} else if (type == MSG_CLOSE)
{
close();
@@ -1685,8 +1565,28 @@
deleteTemporaryDestination(message.getDestination());
response = new NullPacket();
- } else
+ }
+ else if (type == PacketType.MSG_ACKNOWLEDGE)
{
+ SessionAcknowledgeMessage message = (SessionAcknowledgeMessage)packet;
+ acknowledge(message.getDeliveryID(), message.isAllUpTo());
+ response = new NullPacket();
+ }
+ else if (type == PacketType.MSG_COMMIT)
+ {
+ commit();
+ }
+ else if (type == PacketType.MSG_ROLLBACK)
+ {
+ rollback();
+ }
+ else if (type == PacketType.MSG_CANCEL)
+ {
+ SessionCancelMessage message = (SessionCancelMessage)packet;
+ cancel(message.getDeliveryID(), message.isExpired());
+ }
+ else
+ {
response = new JMSExceptionMessage(new MessagingJMSException(
"Unsupported packet for browser: " + packet));
}
Deleted: trunk/src/main/org/jboss/jms/server/endpoint/SessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/SessionEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/SessionEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,147 +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.endpoint;
-
-
-import java.util.List;
-
-import javax.jms.JMSException;
-import javax.transaction.xa.Xid;
-
-import org.jboss.jms.client.Closeable;
-import org.jboss.jms.client.impl.Ack;
-import org.jboss.jms.client.impl.Cancel;
-import org.jboss.jms.destination.JBossQueue;
-import org.jboss.jms.destination.JBossTopic;
-import org.jboss.messaging.core.Destination;
-import org.jboss.messaging.core.Message;
-import org.jboss.messaging.core.remoting.wireformat.CreateBrowserResponse;
-import org.jboss.messaging.core.remoting.wireformat.CreateConsumerResponse;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- *
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public interface SessionEndpoint extends Closeable
-{
- CreateConsumerResponse createConsumerDelegate(Destination destination, String selector,
- boolean noLocal, String subscriptionName,
- boolean connectionConsumer) throws JMSException;
-
- CreateBrowserResponse createBrowserDelegate(Destination queue, String messageSelector) throws JMSException;
-
- /**
- * Creates a queue identity given a Queue name. Does NOT create the physical queue. The physical
- * creation of queues is an administrative task and is not to be initiated by the JMS API, with
- * the exception of temporary queues.
- */
- JBossQueue createQueue(String queueName) throws JMSException;
-
- /**
- * Creates a topic identity given a Queue name. Does NOT create the physical topic. The physical
- * creation of topics is an administrative task and is not to be initiated by the JMS API, with
- * the exception of temporary topics.
- */
- JBossTopic createTopic(String topicName) throws JMSException;
-
- /**
- * Acknowledge a list of deliveries
- * @throws JMSException
- */
- void acknowledgeDeliveries(List<Ack> acks) throws JMSException;
-
- /**
- * Acknowledge a delivery
- * @throws JMSException
- */
- boolean acknowledgeDelivery(Ack ack) throws JMSException;
-
- /**
- * Cancel a list of deliveries.
- */
- void cancelDeliveries(List<Cancel> cancels) throws JMSException;
-
- /**
- * Cancel a delivery
- * @param cancel
- * @throws JMSException
- */
- void cancelDelivery(Cancel cancel) throws JMSException;
-
- /**
- * Add a temporary destination.
- */
- void addTemporaryDestination(Destination destination) throws JMSException;
-
- /**
- * Delete a temporary destination
- */
- void deleteTemporaryDestination(Destination destination) throws JMSException;
-
- /**
- * Unsubscribe the client from the durable subscription
- * specified by subscriptionName
- *
- * @param subscriptionName the Name of the durable subscription to unsubscribe from
- * @throws JMSException if the unsubscribe fails
- */
- void unsubscribe(String subscriptionName) throws JMSException;
-
- /**
- * Send a message
- * @param message The message to send
- * @throws JMSException
- */
- void send(Message message) throws JMSException;
-
- int getDupsOKBatchSize();
-
- public boolean isStrictTck();
-
-// public void XAStart(Xid xid) throws JMSException;
-//
-// public void XAEnd(Xid xid) throws JMSException;
-//
-// public void XASuspend(Xid xid) throws JMSException;
-//
-// public void XAJoin(Xid xid) throws JMSException;
-//
-// public void XAResume(Xid xid) throws JMSException;
-//
-// public void XAPrepare(Xid xid) throws JMSException;
-//
-// public void XACommit(Xid xid, boolean onePhase) throws JMSException;
-//
-// public void XARollback(Xid xid) throws JMSException;
-//
-// public List<Xid> XARecover() throws JMSException;
-//
-// public void XASetTxTimeout(int seconds) throws JMSException;
-//
-// public int XAGetTimeout() throws JMSException;
-}
-
Deleted: trunk/src/main/org/jboss/jms/server/endpoint/SessionInternalEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/SessionInternalEndpoint.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/jms/server/endpoint/SessionInternalEndpoint.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,39 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jms.server.endpoint;
-
-import javax.jms.JMSException;
-
-import org.jboss.messaging.core.Message;
-
-/**
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: $</tt>5 Oct 2007
- *
- * $Id: $
- *
- */
-public interface SessionInternalEndpoint extends SessionEndpoint
-{
- void send(Message msg, boolean checkForDuplicates, long seq) throws JMSException;
-}
Modified: trunk/src/main/org/jboss/messaging/core/Message.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/Message.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/Message.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -28,6 +28,7 @@
/**
* A message is a routable instance that has a payload.
+ *
* The payload is opaque to the messaging system.
*
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -41,27 +42,6 @@
//FIXME - temp
public static final String TEMP_DEST_HEADER_NAME = "JMSDestination";
-
- /**
- * This header is set on a message when a message is sucked from one node of the cluster to another
- * and order preservation is true.
- * The header is checked when sucking messages and if order preservation is true then the message is not accepted.
- * This is a basic way of ensuring message order is preserved.
- */
- public static final String CLUSTER_SUCKED = "SUCKED";
-
- /**
- * This header is set on a message when it is sucked from one node to another.
- * If the header exists on the destination node, and the message is persistent, the message
- * will be moved from one channel to the other by doing a simple database update
- */
- public static final String SOURCE_CHANNEL_ID = "SCID";
-
- /**
- * The scheduled delivery time for the message
- */
- public static final String SCHEDULED_DELIVERY_TIME = "SCHED";
-
/**
* @return The unique id of the message
*/
@@ -193,6 +173,18 @@
int getType();
/**
+ *
+ * @return The delivery count of the message - only available on the client side
+ */
+ int getDeliveryCount();
+
+ /**
+ * Set the delivery count of the message
+ * @param count
+ */
+ void setDeliveryCount(int count);
+
+ /**
* Get the connection id
* @return
*/
Modified: trunk/src/main/org/jboss/messaging/core/Queue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/Queue.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/Queue.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,6 +21,7 @@
*/
package org.jboss.messaging.core;
+import java.util.LinkedList;
import java.util.List;
@@ -39,6 +40,13 @@
HandleStatus addFirst(MessageReference ref);
+ /**
+ * This method is used to add a List of MessageReferences atomically at the head of the list.
+ * Useful when cancelling messages and guaranteeing ordering
+ * @param list
+ */
+ void addListFirst(LinkedList<MessageReference> list);
+
void deliver();
void addConsumer(Consumer consumer);
Modified: trunk/src/main/org/jboss/messaging/core/Transaction.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/Transaction.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/Transaction.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,8 +21,8 @@
*/
package org.jboss.messaging.core;
-import java.util.List;
+
/**
*
* A JBoss Messaging internal transaction
@@ -40,11 +40,9 @@
void rollback(PersistenceManager persistenceManager) throws Exception;
- //FIXME temp
+ void addMessage(Message message);
- void addAllSends(List<Message> msgs);
+ void addAcknowledgement(MessageReference acknowledgement);
- void addAllAcks(List<MessageReference> refs);
-
- void setContainsPersistent(boolean b);
+ int getAcknowledgementsCount();
}
Modified: trunk/src/main/org/jboss/messaging/core/impl/MessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/MessageImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/impl/MessageImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -86,6 +86,8 @@
private volatile int numDurableReferences;
+ private int deliveryCount;
+
/*
* We use a semaphore of size 1, i.e. a mutex to synchronize access to the refs rather than
* use the synchronized keyword since java.util.Semaphore uses compareAndSet to maintain the semaphore
@@ -94,7 +96,7 @@
private Semaphore refsLock = new Semaphore(1);
- //FIXME - does scheduledDeliveryTime belong on message? surely on SendMessage
+ //FIXME - does scheduledDeliveryTime belong on message? surely on SessionSendMessage
// private long scheduledDeliveryTime;
// Constructors --------------------------------------------------
@@ -285,6 +287,16 @@
{
this.connectionID = connectionID;
}
+
+ public void setDeliveryCount(int deliveryCount)
+ {
+ this.deliveryCount = deliveryCount;
+ }
+
+ public int getDeliveryCount()
+ {
+ return this.deliveryCount;
+ }
public boolean isExpired()
{
Modified: trunk/src/main/org/jboss/messaging/core/impl/MessageReferenceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/MessageReferenceImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/impl/MessageReferenceImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -127,15 +127,15 @@
}
public void cancel(PersistenceManager persistenceManager) throws Exception
- {
+ {
+ deliveryCount++;
+
if (message.isDurable() && queue.isDurable())
{
persistenceManager.updateDeliveryCount(queue, this);
}
queue.referenceAcknowledged();
-
- queue.addFirst(this);
}
// Public --------------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/impl/QueueImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/QueueImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/impl/QueueImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
@@ -160,6 +161,20 @@
{
return add(ref, true);
}
+
+ public synchronized void addListFirst(LinkedList<MessageReference> list)
+ {
+ ListIterator<MessageReference> iter = list.listIterator(list.size());
+
+ while (iter.hasPrevious())
+ {
+ MessageReference ref = iter.previous();
+
+ messageReferences.addFirst(ref, ref.getMessage().getPriority());
+ }
+
+ deliver();
+ }
/*
* Attempt to deliver all the messages in the queue
@@ -315,6 +330,7 @@
public synchronized int getMessageCount()
{
+ // log.info("mr: " + messageReferences.size() + " sc: " + getScheduledCount() + " dc: " + getDeliveringCount());
return messageReferences.size() + getScheduledCount() + getDeliveringCount();
}
@@ -327,7 +343,7 @@
{
return deliveringCount.get();
}
-
+
public void referenceAcknowledged()
{
deliveringCount.decrementAndGet();
Modified: trunk/src/main/org/jboss/messaging/core/impl/TransactionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/TransactionImpl.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/impl/TransactionImpl.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -22,13 +22,17 @@
package org.jboss.messaging.core.impl;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import javax.transaction.xa.Xid;
import org.jboss.messaging.core.Message;
import org.jboss.messaging.core.MessageReference;
import org.jboss.messaging.core.PersistenceManager;
+import org.jboss.messaging.core.Queue;
import org.jboss.messaging.core.Transaction;
import org.jboss.messaging.core.TransactionSynchronization;
import org.jboss.messaging.util.Logger;
@@ -44,9 +48,9 @@
{
private static final Logger log = Logger.getLogger(TransactionImpl.class);
- private List<Message> messagesToAdd;
+ private List<Message> messagesToAdd = new ArrayList<Message>();
- private List<MessageReference> refsToRemove;
+ private List<MessageReference> acknowledgements = new ArrayList<MessageReference>();
private List<TransactionSynchronization> synchronizations = new ArrayList<TransactionSynchronization>();
@@ -56,61 +60,38 @@
private boolean prepared;
- //FIXME - temp
public TransactionImpl()
- {
- messagesToAdd = new ArrayList<Message>();
-
- refsToRemove = new ArrayList<MessageReference>();
+ {
}
public TransactionImpl(Xid xid)
{
- this();
-
this.xid = xid;
}
- public void setContainsPersistent(boolean persistent)
- {
- this.containsPersistent = persistent;
- }
+ // Transaction implementation -----------------------------------------------------------
- public TransactionImpl(List<Message> messagesToAdd, List<MessageReference> refsToRemove,
- boolean containsPersistent)
+ public void addMessage(Message message)
{
- this.messagesToAdd = messagesToAdd;
+ messagesToAdd.add(message);
- this.refsToRemove = refsToRemove;
-
- this.containsPersistent = containsPersistent;
+ if (message.getNumDurableReferences() != 0)
+ {
+ containsPersistent = true;
+ }
}
- public TransactionImpl(Xid xid, List<Message> messagesToAdd, List<MessageReference> refsToRemove,
- boolean containsPersistent)
+ public void addAcknowledgement(MessageReference acknowledgement)
{
- this(messagesToAdd, refsToRemove, containsPersistent);
-
- this.xid = xid;
+ acknowledgements.add(acknowledgement);
+
+ if (acknowledgement.getMessage().isDurable() && acknowledgement.getQueue().isDurable())
+ {
+ containsPersistent = true;
+ }
}
- // Transaction implementation -----------------------------------------------------------
- //FIXME temp
-
-
- public void addAllSends(List<Message> msgs)
- {
- messagesToAdd.addAll(msgs);
- }
-
- public void addAllAcks(List<MessageReference> refs)
- {
- refsToRemove.addAll(refs);
- }
-
- //End FIXME
-
public void addSynchronization(TransactionSynchronization sync)
{
synchronizations.add(sync);
@@ -124,7 +105,7 @@
}
else if (containsPersistent)
{
- persistenceManager.prepareTransaction(xid, messagesToAdd, refsToRemove);
+ persistenceManager.prepareTransaction(xid, messagesToAdd, acknowledgements);
prepared = true;
}
@@ -133,14 +114,14 @@
public void commit(PersistenceManager persistenceManager) throws Exception
{
callSynchronizations(SyncType.BEFORE_COMMIT);
-
+
if (containsPersistent)
{
if (xid == null)
{
//1PC commit
- persistenceManager.commitTransaction(messagesToAdd, refsToRemove);
+ persistenceManager.commitTransaction(messagesToAdd, acknowledgements);
}
else
{
@@ -155,52 +136,40 @@
}
}
- //Now add to queue(s)
-
for (Message msg: messagesToAdd)
{
- for (MessageReference ref: msg.getReferences())
- {
- ref.getQueue().addLast(ref);
- }
+ msg.send();
}
- //And acknowledge
-
- //TODO find better transactional abstraction so don't have to manually do this
-
- for (MessageReference ref: refsToRemove)
+ for (MessageReference reference: acknowledgements)
{
- ref.getQueue().referenceAcknowledged();
+ reference.getQueue().referenceAcknowledged();
}
callSynchronizations(SyncType.AFTER_COMMIT);
+
+ clear();
}
public void rollback(PersistenceManager persistenceManager) throws Exception
{
callSynchronizations(SyncType.BEFORE_ROLLBACK);
-
- if (xid == null)
+
+ if (xid != null && containsPersistent)
{
- //1PC rollback - nothing to do
+ persistenceManager.unprepareTransaction(xid, messagesToAdd, acknowledgements);
}
- else
- {
- persistenceManager.unprepareTransaction(xid, messagesToAdd, refsToRemove);
-
- //Now we need to add the refs back on the tx
-
- for (MessageReference ref: refsToRemove)
- {
- if (ref.getMessage().isDurable() && ref.getQueue().isDurable())
- {
- ref.getMessage().addBackDurableReference(ref);
- }
- }
- }
- callSynchronizations(SyncType.AFTER_ROLLBACK);
+ cancelDeliveries(persistenceManager);
+
+ callSynchronizations(SyncType.AFTER_ROLLBACK);
+
+ clear();
+ }
+
+ public int getAcknowledgementsCount()
+ {
+ return acknowledgements.size();
}
// Private -------------------------------------------------------------------
@@ -227,7 +196,55 @@
}
}
}
+
+ private void clear()
+ {
+ messagesToAdd.clear();
+
+ acknowledgements.clear();
+
+ synchronizations.clear();
+
+ containsPersistent = false;
+ }
+ private void cancelDeliveries(PersistenceManager persistenceManager) throws Exception
+ {
+ Map<Queue, LinkedList<MessageReference>> queueMap = new HashMap<Queue, LinkedList<MessageReference>>();
+
+ //Need to sort into lists - one for each queue involved.
+ //Then cancelling back atomicly for each queue adding list on front to guarantee ordering is preserved
+
+ for (MessageReference ref: acknowledgements)
+ {
+ Queue queue = ref.getQueue();
+
+ LinkedList<MessageReference> list = queueMap.get(queue);
+
+ if (list == null)
+ {
+ list = new LinkedList<MessageReference>();
+
+ queueMap.put(queue, list);
+ }
+
+ list.add(ref);
+ }
+
+ for (Map.Entry<Queue, LinkedList<MessageReference>> entry: queueMap.entrySet())
+ {
+ LinkedList<MessageReference> refs = entry.getValue();
+
+ for (MessageReference ref: refs)
+ {
+ //Need to update delivery counts
+ ref.cancel(persistenceManager);
+ }
+
+ entry.getKey().addListFirst(refs);
+ }
+ }
+
// Inner Enums -------------------------------------------------------------------------------
private enum SyncType
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveriesRequestCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveriesRequestCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveriesRequestCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,102 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_ACKDELIVERIES;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.jms.client.impl.Ack;
-import org.jboss.jms.client.impl.AckImpl;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveriesMessage;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class AcknowledgeDeliveriesRequestCodec extends
- AbstractPacketCodec<AcknowledgeDeliveriesMessage>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- public static long[] convert(List<Ack> acks)
- {
- long[] deliveryIDs = new long[acks.size()];
- for (int i = 0; i < acks.size(); i++)
- {
- deliveryIDs[i] = acks.get(i).getDeliveryID();
- }
- return deliveryIDs;
- }
-
- // Constructors --------------------------------------------------
-
- public AcknowledgeDeliveriesRequestCodec()
- {
- super(MSG_ACKDELIVERIES);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(AcknowledgeDeliveriesMessage request,
- RemotingBuffer out) throws Exception
- {
-
- long[] deliveryIDs = convert(request.getAcks());
-
- int bodyLength = LONG_LENGTH * deliveryIDs.length;
- out.putInt(bodyLength);
- for (long id : deliveryIDs)
- {
- out.putLong(id);
- }
- }
-
- @Override
- protected AcknowledgeDeliveriesMessage decodeBody(RemotingBuffer in) throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- int numOfDeliveryIds = bodyLength / LONG_LENGTH;
- long[] deliveryIDs = new long[numOfDeliveryIds];
- for (int i = 0; i < numOfDeliveryIds; i++)
- {
- deliveryIDs[i] = in.getLong();
- }
- List<Ack> acks = convert(deliveryIDs);
-
- return new AcknowledgeDeliveriesMessage(acks);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- private List<Ack> convert(long[] deliveryIDs)
- {
- List<Ack> acks = new ArrayList<Ack>(deliveryIDs.length);
- for (long deliveryID : deliveryIDs)
- {
- acks.add(new AckImpl(deliveryID));
- }
- return acks;
- }
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveryRequestCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveryRequestCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveryRequestCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_ACKDELIVERY;
-
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryRequest;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class AcknowledgeDeliveryRequestCodec extends
- AbstractPacketCodec<AcknowledgeDeliveryRequest>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public AcknowledgeDeliveryRequestCodec()
- {
- super(REQ_ACKDELIVERY);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(AcknowledgeDeliveryRequest request,
- RemotingBuffer out) throws Exception
- {
- long deliveryID = request.getDeliveryID();
-
- out.putInt(LONG_LENGTH);
- out.putLong(deliveryID);
- }
-
- @Override
- protected AcknowledgeDeliveryRequest decodeBody(RemotingBuffer in) throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- long deliveryID = in.getLong();
-
- return new AcknowledgeDeliveryRequest(deliveryID);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveryResponseCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveryResponseCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/AcknowledgeDeliveryResponseCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,65 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_ACKDELIVERY;
-
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryResponse;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class AcknowledgeDeliveryResponseCodec extends
- AbstractPacketCodec<AcknowledgeDeliveryResponse>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public AcknowledgeDeliveryResponseCodec()
- {
- super(RESP_ACKDELIVERY);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(AcknowledgeDeliveryResponse response,
- RemotingBuffer out) throws Exception
- {
- out.putInt(1); //body length
- out.putBoolean(response.isAcknowledged());
- }
-
- @Override
- protected AcknowledgeDeliveryResponse decodeBody(RemotingBuffer in) throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- boolean acknowledged = in.getBoolean();
-
- return new AcknowledgeDeliveryResponse(acknowledged);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveriesMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveriesMessageCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveriesMessageCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,97 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERIES;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.jms.client.impl.Cancel;
-import org.jboss.jms.client.impl.CancelImpl;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveriesMessage;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$F</tt>
- */
-public class CancelDeliveriesMessageCodec extends
- AbstractPacketCodec<CancelDeliveriesMessage>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public CancelDeliveriesMessageCodec()
- {
- super(MSG_CANCELDELIVERIES);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(CancelDeliveriesMessage message,
- RemotingBuffer out) throws Exception
- {
- List<Cancel> cancels = message.getCancels();
-
- int numOfCancels = cancels.size();
- int cancelLength = LONG_LENGTH + INT_LENGTH + 1 + 1; // 2 booleans
- int bodyLength = INT_LENGTH + cancelLength * numOfCancels;
-
- out.putInt(bodyLength);
- out.putInt(numOfCancels);
- for (Cancel cancel : cancels)
- {
- out.putLong(cancel.getDeliveryId());
- out.putInt(cancel.getDeliveryCount());
- out.putBoolean(cancel.isExpired());
- out.putBoolean(cancel.isReachedMaxDeliveryAttempts());
- }
- }
-
- @Override
- protected CancelDeliveriesMessage decodeBody(RemotingBuffer in)
- throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- int numOfCancels = in.getInt();
- List<Cancel> cancels = new ArrayList<Cancel>(numOfCancels);
- for (int i = 0; i < numOfCancels; i++)
- {
- long deliveryID = in.getLong();
- int deliveryCount = in.getInt();
- boolean expired = in.getBoolean();
- boolean reachedMaxDeliveryAttempts = in.getBoolean();
-
- cancels.add(new CancelImpl(deliveryID, deliveryCount, expired,
- reachedMaxDeliveryAttempts));
- }
-
- return new CancelDeliveriesMessage(cancels);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveryMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveryMessageCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/CancelDeliveryMessageCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERY;
-
-import org.jboss.jms.client.impl.Cancel;
-import org.jboss.jms.client.impl.CancelImpl;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveryMessage;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class CancelDeliveryMessageCodec extends
- AbstractPacketCodec<CancelDeliveryMessage>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public CancelDeliveryMessageCodec()
- {
- super(MSG_CANCELDELIVERY);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(CancelDeliveryMessage message, RemotingBuffer out) throws Exception
- {
- long deliveryID = message.getCancel().getDeliveryId();
- int deliveryCount = message.getCancel().getDeliveryCount();
- boolean expired = message.getCancel().isExpired();
- boolean reachedMaxDeliveryAttempts = message.getCancel()
- .isReachedMaxDeliveryAttempts();
-
- int bodyLength = LONG_LENGTH + INT_LENGTH + 2;
-
- out.putInt(bodyLength);
- out.putLong(deliveryID);
- out.putInt(deliveryCount);
- out.putBoolean(expired);
- out.putBoolean(reachedMaxDeliveryAttempts);
- }
-
- @Override
- protected CancelDeliveryMessage decodeBody(RemotingBuffer in)
- throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- long deliveryID = in.getLong();
- int deliveryCount = in.getInt();
- boolean expired = in.getBoolean();
- boolean reachedMaxDeliveryAttempts = in.getBoolean();
-
- Cancel cancel = new CancelImpl(deliveryID, deliveryCount, expired,
- reachedMaxDeliveryAttempts);
- return new CancelDeliveryMessage(cancel);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/ChangeRateMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/ChangeRateMessageCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/ChangeRateMessageCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,65 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CHANGERATE;
-
-import org.jboss.messaging.core.remoting.wireformat.ChangeRateMessage;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class ChangeRateMessageCodec extends
- AbstractPacketCodec<ChangeRateMessage>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public ChangeRateMessageCodec()
- {
- super(MSG_CHANGERATE);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(ChangeRateMessage message, RemotingBuffer out) throws Exception
- {
- out.putInt(FLOAT_LENGTH);
- out.putFloat(message.getRate());
- }
-
- @Override
- protected ChangeRateMessage decodeBody(RemotingBuffer in)
- throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- float rate = in.getFloat();
-
- return new ChangeRateMessage(rate);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private ----------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/ClosingRequestCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/ClosingRequestCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/ClosingRequestCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CLOSING;
-
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class ClosingRequestCodec extends AbstractPacketCodec<ClosingRequest>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public ClosingRequestCodec()
- {
- super(REQ_CLOSING);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(ClosingRequest request, RemotingBuffer out) throws Exception
- {
- out.putInt(LONG_LENGTH);
- out.putLong(request.getSequence());
- }
-
- @Override
- protected ClosingRequest decodeBody(RemotingBuffer in)
- throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- long sequence = in.getLong();
-
- return new ClosingRequest(sequence);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/ClosingResponseCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/ClosingResponseCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/ClosingResponseCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_CLOSING;
-
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class ClosingResponseCodec extends AbstractPacketCodec<ClosingResponse>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public ClosingResponseCodec()
- {
- super(RESP_CLOSING);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(ClosingResponse response, RemotingBuffer out) throws Exception
- {
- out.putInt(LONG_LENGTH);
- out.putLong(response.getID());
- }
-
- @Override
- protected ClosingResponse decodeBody(RemotingBuffer in)
- throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- long id = in.getLong();
-
- return new ClosingResponse(id);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/src/main/org/jboss/messaging/core/remoting/codec/ConsumerChangeRateMessageCodec.java (from rev 3616, trunk/src/main/org/jboss/messaging/core/remoting/codec/ChangeRateMessageCodec.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/ConsumerChangeRateMessageCodec.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/ConsumerChangeRateMessageCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CHANGERATE;
+
+import org.jboss.messaging.core.remoting.wireformat.ConsumerChangeRateMessage;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
+ */
+public class ConsumerChangeRateMessageCodec extends
+ AbstractPacketCodec<ConsumerChangeRateMessage>
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public ConsumerChangeRateMessageCodec()
+ {
+ super(MSG_CHANGERATE);
+ }
+
+ // Public --------------------------------------------------------
+
+ // AbstractPacketCodec overrides ---------------------------------
+
+ @Override
+ protected void encodeBody(ConsumerChangeRateMessage message, RemotingBuffer out) throws Exception
+ {
+ out.putInt(FLOAT_LENGTH);
+ out.putFloat(message.getRate());
+ }
+
+ @Override
+ protected ConsumerChangeRateMessage decodeBody(RemotingBuffer in)
+ throws Exception
+ {
+ int bodyLength = in.getInt();
+ if (in.remaining() < bodyLength)
+ {
+ return null;
+ }
+
+ float rate = in.getFloat();
+
+ return new ConsumerChangeRateMessage(rate);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private ----------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/codec/DeliverMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/DeliverMessageCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/DeliverMessageCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -37,17 +37,15 @@
protected void encodeBody(DeliverMessage message, RemotingBuffer out) throws Exception
{
byte[] encodedMsg = encodeMessage(message.getMessage());
- String consumerID = message.getConsumerID();
long deliveryID = message.getDeliveryID();
int deliveryCount = message.getDeliveryCount();
- int bodyLength = INT_LENGTH + encodedMsg.length + sizeof(consumerID)
+ int bodyLength = INT_LENGTH + encodedMsg.length
+ LONG_LENGTH + INT_LENGTH;
out.putInt(bodyLength);
out.putInt(encodedMsg.length);
out.put(encodedMsg);
- out.putNullableString(consumerID);
out.putLong(deliveryID);
out.putInt(deliveryCount);
}
@@ -66,11 +64,10 @@
byte[] encodedMsg = new byte[msgLength];
in.get(encodedMsg);
Message msg = decodeMessage(encodedMsg);
- String consumerID = in.getNullableString();
long deliveryID = in.getLong();
int deliveryCount = in.getInt();
- return new DeliverMessage(msg, consumerID, deliveryID, deliveryCount);
+ return new DeliverMessage(msg, deliveryID, deliveryCount);
}
// Package protected ---------------------------------------------
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/GetPreparedTransactionsResponseCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/GetPreparedTransactionsResponseCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/GetPreparedTransactionsResponseCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,110 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_GETPREPAREDTRANSACTIONS;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-
-import org.jboss.messaging.core.remoting.wireformat.GetPreparedTransactionsResponse;
-import org.jboss.messaging.core.tx.MessagingXid;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class GetPreparedTransactionsResponseCodec extends
- AbstractPacketCodec<GetPreparedTransactionsResponse>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- public static byte[] encode(MessagingXid[] xids) throws Exception
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream dos = new DataOutputStream(baos);
- for (int i = 0; i < xids.length; i++)
- {
- MessagingXid xid = xids[i];
- xid.write(dos);
- }
- return baos.toByteArray();
- }
-
- // Constructors --------------------------------------------------
-
- public GetPreparedTransactionsResponseCodec()
- {
- super(RESP_GETPREPAREDTRANSACTIONS);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(GetPreparedTransactionsResponse response,
- RemotingBuffer out) throws Exception
- {
-
- MessagingXid[] xids = response.getXids();
-
- byte[] encodedXids = encode(xids);
-
- int bodyLength = INT_LENGTH + INT_LENGTH + encodedXids.length;
-
- out.putInt(bodyLength);
- out.putInt(xids.length);
- out.putInt(encodedXids.length);
- out.put(encodedXids);
- }
-
- @Override
- protected GetPreparedTransactionsResponse decodeBody(RemotingBuffer in) throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- int numOfXids = in.getInt();
- int encodedXidsLength = in.getInt();
- byte[] b = new byte[encodedXidsLength];
- in.get(b);
- MessagingXid[] xids = decode(numOfXids, b);
-
- return new GetPreparedTransactionsResponse(xids);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- private MessagingXid[] decode(int numOfXids, byte[] encodedXids) throws Exception
- {
- MessagingXid[] xids = new MessagingXid[numOfXids];
- ByteArrayInputStream bais = new ByteArrayInputStream(encodedXids);
- DataInputStream dis = new DataInputStream(bais);
- for (int i = 0; i < xids.length; i++)
- {
- MessagingXid xid = new MessagingXid();
- xid.read(dis);
- xids[i] = xid;
- }
- return xids;
- }
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/SendMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SendMessageCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SendMessageCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,76 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SENDMESSAGE;
-
-import org.jboss.messaging.core.Message;
-import org.jboss.messaging.core.remoting.wireformat.SendMessage;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class SendMessageCodec extends AbstractPacketCodec<SendMessage>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public SendMessageCodec()
- {
- super(MSG_SENDMESSAGE);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(SendMessage message, RemotingBuffer out) throws Exception
- {
- byte[] encodedMsg = encodeMessage(message.getMessage());
- long sequence = message.getSequence();
-
- int bodyLength = INT_LENGTH + encodedMsg.length + LONG_LENGTH;
-
- out.putInt(bodyLength);
- out.putInt(encodedMsg.length);
- out.put(encodedMsg);
- out.putLong(sequence);
- }
-
- @Override
- protected SendMessage decodeBody(RemotingBuffer in)
- throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- int msgLength = in.getInt();
- byte[] encodedMsg = new byte[msgLength];
- in.get(encodedMsg);
- Message msg = decodeMessage(encodedMsg);
- long sequence = in.getLong();
-
- return new SendMessage(msg, sequence);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private ----------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/SendTransactionMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SendTransactionMessageCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SendTransactionMessageCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,94 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SENDTRANSACTION;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-
-import org.jboss.jms.tx.TransactionRequest;
-import org.jboss.messaging.core.remoting.wireformat.SendTransactionMessage;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class SendTransactionMessageCodec extends AbstractPacketCodec<SendTransactionMessage>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- public static byte[] encodeTransactionRequest(TransactionRequest tr) throws Exception
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- tr.write(new DataOutputStream(baos));
- baos.flush();
- return baos.toByteArray();
- }
-
- // Constructors --------------------------------------------------
-
- public SendTransactionMessageCodec()
- {
- super(MSG_SENDTRANSACTION);
- }
-
- // Public --------------------------------------------------------
-
- // AbstractPacketCodec overrides ---------------------------------
-
- @Override
- protected void encodeBody(SendTransactionMessage request, RemotingBuffer out) throws Exception
- {
- byte[] encodedTxReq = encodeTransactionRequest(request.getTransactionRequest());
-
- int bodyLength = INT_LENGTH + encodedTxReq.length;
-
- out.putInt(bodyLength);
- out.putInt(encodedTxReq.length);
- out.put(encodedTxReq);
- }
-
- @Override
- protected SendTransactionMessage decodeBody(RemotingBuffer in)
- throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
-
- int txReqLength = in.getInt();
- byte[] encodedTxReq = new byte[txReqLength];
- in.get(encodedTxReq);
- TransactionRequest tr = decodeTransactionRequest(encodedTxReq);
-
- return new SendTransactionMessage(tr);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private ----------------------------------------------------
-
- private static TransactionRequest decodeTransactionRequest(byte[] b) throws Exception
- {
- TransactionRequest tr = new TransactionRequest();
- ByteArrayInputStream bais = new ByteArrayInputStream(b);
- tr.read(new DataInputStream(bais));
- return tr;
- }
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionSendMessageCodec.java (from rev 3616, trunk/src/main/org/jboss/messaging/core/remoting/codec/SendMessageCodec.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionSendMessageCodec.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/SessionSendMessageCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.codec;
+
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SENDMESSAGE;
+
+import org.jboss.messaging.core.Message;
+import org.jboss.messaging.core.remoting.wireformat.SessionSendMessage;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
+ */
+public class SessionSendMessageCodec extends AbstractPacketCodec<SessionSendMessage>
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public SessionSendMessageCodec()
+ {
+ super(MSG_SENDMESSAGE);
+ }
+
+ // Public --------------------------------------------------------
+
+ // AbstractPacketCodec overrides ---------------------------------
+
+ @Override
+ protected void encodeBody(SessionSendMessage message, RemotingBuffer out) throws Exception
+ {
+ byte[] encodedMsg = encodeMessage(message.getMessage());
+
+ int bodyLength = INT_LENGTH + encodedMsg.length;
+
+ out.putInt(bodyLength);
+ out.putInt(encodedMsg.length);
+ out.put(encodedMsg);
+ }
+
+ @Override
+ protected SessionSendMessage decodeBody(RemotingBuffer in)
+ throws Exception
+ {
+ int bodyLength = in.getInt();
+ if (in.remaining() < bodyLength)
+ {
+ return null;
+ }
+
+ int msgLength = in.getInt();
+ byte[] encodedMsg = new byte[msgLength];
+ in.get(encodedMsg);
+ Message msg = decodeMessage(encodedMsg);
+
+ return new SessionSendMessage(msg);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private ----------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/codec/UpdateCallbackMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/codec/UpdateCallbackMessageCodec.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/codec/UpdateCallbackMessageCodec.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,74 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.codec;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_UPDATECALLBACK;
-
-import org.jboss.messaging.core.remoting.wireformat.UpdateCallbackMessage;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- */
-public class UpdateCallbackMessageCodec extends
- AbstractPacketCodec<UpdateCallbackMessage>
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public UpdateCallbackMessageCodec()
- {
- super(MSG_UPDATECALLBACK);
- }
-
- // AbstractPackedCodec overrides----------------------------------
-
- @Override
- protected void encodeBody(UpdateCallbackMessage message, RemotingBuffer out) throws Exception
- {
- String remotingSessionID = message.getRemotingSessionID();
- String clientVMID = message.getClientVMID();
- boolean add = message.isAdd();
-
- int bodyLength = sizeof(remotingSessionID) + sizeof(clientVMID) + 1;
-
- out.putInt(bodyLength);
- out.putNullableString(remotingSessionID);
- out.putNullableString(clientVMID);
- out.putBoolean(add);
- }
-
- @Override
- protected UpdateCallbackMessage decodeBody(RemotingBuffer in)
- throws Exception
- {
- int bodyLength = in.getInt();
- if (in.remaining() < bodyLength)
- {
- return null;
- }
- String remotingSessionID = in.getNullableString();
- String clientVMID = in.getNullableString();
- boolean add = in.getBoolean();
-
- return new UpdateCallbackMessage(remotingSessionID, clientVMID, add);
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/PacketCodecFactory.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -10,22 +10,15 @@
import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory;
import org.jboss.messaging.core.remoting.codec.AbstractPacketCodec;
-import org.jboss.messaging.core.remoting.codec.AcknowledgeDeliveriesRequestCodec;
-import org.jboss.messaging.core.remoting.codec.AcknowledgeDeliveryRequestCodec;
-import org.jboss.messaging.core.remoting.codec.AcknowledgeDeliveryResponseCodec;
import org.jboss.messaging.core.remoting.codec.AddTemporaryDestinationMessageCodec;
import org.jboss.messaging.core.remoting.codec.BrowserHasNextMessageResponseCodec;
import org.jboss.messaging.core.remoting.codec.BrowserNextMessageBlockRequestCodec;
import org.jboss.messaging.core.remoting.codec.BrowserNextMessageBlockResponseCodec;
import org.jboss.messaging.core.remoting.codec.BrowserNextMessageResponseCodec;
import org.jboss.messaging.core.remoting.codec.BytesPacketCodec;
-import org.jboss.messaging.core.remoting.codec.CancelDeliveriesMessageCodec;
-import org.jboss.messaging.core.remoting.codec.CancelDeliveryMessageCodec;
-import org.jboss.messaging.core.remoting.codec.ChangeRateMessageCodec;
-import org.jboss.messaging.core.remoting.codec.ClosingRequestCodec;
-import org.jboss.messaging.core.remoting.codec.ClosingResponseCodec;
import org.jboss.messaging.core.remoting.codec.ConnectionFactoryCreateConnectionRequestCodec;
import org.jboss.messaging.core.remoting.codec.ConnectionFactoryCreateConnectionResponseCodec;
+import org.jboss.messaging.core.remoting.codec.ConsumerChangeRateMessageCodec;
import org.jboss.messaging.core.remoting.codec.CreateBrowserRequestCodec;
import org.jboss.messaging.core.remoting.codec.CreateBrowserResponseCodec;
import org.jboss.messaging.core.remoting.codec.CreateConsumerRequestCodec;
@@ -37,19 +30,15 @@
import org.jboss.messaging.core.remoting.codec.DeleteTemporaryDestinationMessageCodec;
import org.jboss.messaging.core.remoting.codec.DeliverMessageCodec;
import org.jboss.messaging.core.remoting.codec.GetClientIDResponseCodec;
-import org.jboss.messaging.core.remoting.codec.GetPreparedTransactionsResponseCodec;
import org.jboss.messaging.core.remoting.codec.JMSExceptionMessageCodec;
import org.jboss.messaging.core.remoting.codec.RemotingBuffer;
-import org.jboss.messaging.core.remoting.codec.SendMessageCodec;
-import org.jboss.messaging.core.remoting.codec.SendTransactionMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionAcknowledgeMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionCancelMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SessionSendMessageCodec;
import org.jboss.messaging.core.remoting.codec.SetClientIDMessageCodec;
import org.jboss.messaging.core.remoting.codec.TextPacketCodec;
import org.jboss.messaging.core.remoting.codec.UnsubscribeMessageCodec;
-import org.jboss.messaging.core.remoting.codec.UpdateCallbackMessageCodec;
import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveriesMessage;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryRequest;
-import org.jboss.messaging.core.remoting.wireformat.AcknowledgeDeliveryResponse;
import org.jboss.messaging.core.remoting.wireformat.AddTemporaryDestinationMessage;
import org.jboss.messaging.core.remoting.wireformat.BrowserHasNextMessageRequest;
import org.jboss.messaging.core.remoting.wireformat.BrowserHasNextMessageResponse;
@@ -59,12 +48,9 @@
import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageResponse;
import org.jboss.messaging.core.remoting.wireformat.BrowserResetMessage;
import org.jboss.messaging.core.remoting.wireformat.BytesPacket;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveriesMessage;
-import org.jboss.messaging.core.remoting.wireformat.CancelDeliveryMessage;
-import org.jboss.messaging.core.remoting.wireformat.ChangeRateMessage;
import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
-import org.jboss.messaging.core.remoting.wireformat.ClosingRequest;
-import org.jboss.messaging.core.remoting.wireformat.ClosingResponse;
+import org.jboss.messaging.core.remoting.wireformat.ClosingMessage;
+import org.jboss.messaging.core.remoting.wireformat.ConsumerChangeRateMessage;
import org.jboss.messaging.core.remoting.wireformat.CreateBrowserRequest;
import org.jboss.messaging.core.remoting.wireformat.CreateBrowserResponse;
import org.jboss.messaging.core.remoting.wireformat.CreateConnectionRequest;
@@ -79,19 +65,20 @@
import org.jboss.messaging.core.remoting.wireformat.DeliverMessage;
import org.jboss.messaging.core.remoting.wireformat.GetClientIDRequest;
import org.jboss.messaging.core.remoting.wireformat.GetClientIDResponse;
-import org.jboss.messaging.core.remoting.wireformat.GetPreparedTransactionsRequest;
-import org.jboss.messaging.core.remoting.wireformat.GetPreparedTransactionsResponse;
import org.jboss.messaging.core.remoting.wireformat.JMSExceptionMessage;
import org.jboss.messaging.core.remoting.wireformat.NullPacket;
import org.jboss.messaging.core.remoting.wireformat.PacketType;
-import org.jboss.messaging.core.remoting.wireformat.SendMessage;
-import org.jboss.messaging.core.remoting.wireformat.SendTransactionMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionAcknowledgeMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionCancelMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionCommitMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionRecoverMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionRollbackMessage;
+import org.jboss.messaging.core.remoting.wireformat.SessionSendMessage;
import org.jboss.messaging.core.remoting.wireformat.SetClientIDMessage;
import org.jboss.messaging.core.remoting.wireformat.StartConnectionMessage;
import org.jboss.messaging.core.remoting.wireformat.StopConnectionMessage;
import org.jboss.messaging.core.remoting.wireformat.TextPacket;
import org.jboss.messaging.core.remoting.wireformat.UnsubscribeMessage;
-import org.jboss.messaging.core.remoting.wireformat.UpdateCallbackMessage;
import org.jboss.messaging.util.Logger;
/**
@@ -126,8 +113,6 @@
addCodec(CreateConnectionResponse.class,
ConnectionFactoryCreateConnectionResponseCodec.class);
- addCodec(UpdateCallbackMessage.class, UpdateCallbackMessageCodec.class);
-
addCodec(CreateSessionRequest.class, CreateSessionRequestCodec.class);
addCodec(CreateSessionResponse.class, CreateSessionResponseCodec.class);
@@ -139,7 +124,7 @@
addCodec(SetClientIDMessage.class, SetClientIDMessageCodec.class);
- addCodec(SendMessage.class, SendMessageCodec.class);
+ addCodec(SessionSendMessage.class, SessionSendMessageCodec.class);
addCodec(CreateConsumerRequest.class, CreateConsumerRequestCodec.class);
@@ -161,38 +146,27 @@
addCodecForEmptyPacket(PacketType.MSG_STOPCONNECTION,
StopConnectionMessage.class);
- addCodec(ChangeRateMessage.class, ChangeRateMessageCodec.class);
+ addCodec(ConsumerChangeRateMessage.class, ConsumerChangeRateMessageCodec.class);
addCodec(DeliverMessage.class, DeliverMessageCodec.class);
- addCodec(AcknowledgeDeliveryRequest.class,
- AcknowledgeDeliveryRequestCodec.class);
+ addCodec(SessionAcknowledgeMessage.class,
+ SessionAcknowledgeMessageCodec.class);
+
+ addCodec(SessionCancelMessage.class,
+ SessionCancelMessageCodec.class);
+
+ addCodecForEmptyPacket(PacketType.MSG_COMMIT, SessionCommitMessage.class);
+
+ addCodecForEmptyPacket(PacketType.MSG_COMMIT, SessionRollbackMessage.class);
- addCodec(AcknowledgeDeliveryResponse.class,
- AcknowledgeDeliveryResponseCodec.class);
-
- addCodec(AcknowledgeDeliveriesMessage.class,
- AcknowledgeDeliveriesRequestCodec.class);
-
- addCodec(CancelDeliveryMessage.class, CancelDeliveryMessageCodec.class);
-
- addCodec(CancelDeliveriesMessage.class,
- CancelDeliveriesMessageCodec.class);
-
- addCodec(ClosingRequest.class, ClosingRequestCodec.class);
-
- addCodec(ClosingResponse.class, ClosingResponseCodec.class);
-
addCodecForEmptyPacket(PacketType.MSG_CLOSE, CloseMessage.class);
-
- addCodec(SendTransactionMessage.class, SendTransactionMessageCodec.class);
-
- addCodecForEmptyPacket(PacketType.REQ_GETPREPAREDTRANSACTIONS,
- GetPreparedTransactionsRequest.class);
-
- addCodec(GetPreparedTransactionsResponse.class,
- GetPreparedTransactionsResponseCodec.class);
-
+
+ addCodecForEmptyPacket(PacketType.MSG_CLOSING, ClosingMessage.class);
+
+ addCodecForEmptyPacket(PacketType.MSG_RECOVER, SessionRecoverMessage.class);
+
+
addCodecForEmptyPacket(PacketType.MSG_BROWSER_RESET,
BrowserResetMessage.class);
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveriesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveriesMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveriesMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_ACKDELIVERIES;
-
-import java.util.List;
-
-import org.jboss.jms.client.impl.Ack;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- *
- * @version <tt>$Revision$</tt>
- */
-public class AcknowledgeDeliveriesMessage extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final List<Ack> acks;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public AcknowledgeDeliveriesMessage(List<Ack> acks)
- {
- super(MSG_ACKDELIVERIES);
-
- assert acks != null;
- assert acks.size() != 0;
-
- this.acks = acks;
- }
-
-
- // Public --------------------------------------------------------
-
- public List<Ack> getAcks()
- {
- return acks;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", acks=" + acks + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveryRequest.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveryRequest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveryRequest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,56 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_ACKDELIVERY;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- *
- * @version <tt>$Revision$</tt>
- */
-public class AcknowledgeDeliveryRequest extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final long deliveryID;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public AcknowledgeDeliveryRequest(long deliveryID)
- {
- super(REQ_ACKDELIVERY);
-
- this.deliveryID = deliveryID;
- }
-
- // Public --------------------------------------------------------
-
- public long getDeliveryID()
- {
- return deliveryID;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", deliveryID=" + deliveryID + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveryResponse.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveryResponse.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/AcknowledgeDeliveryResponse.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,55 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_ACKDELIVERY;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- *
- * @version <tt>$Revision$</tt>
- */
-public class AcknowledgeDeliveryResponse extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final boolean acknowledged;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public AcknowledgeDeliveryResponse(boolean acknowledged)
- {
- super(RESP_ACKDELIVERY);
-
- this.acknowledged = acknowledged;
- }
-
- // Public --------------------------------------------------------
-
- public boolean isAcknowledged()
- {
- return acknowledged;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", acknowledged=" + acknowledged + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveriesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveriesMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveriesMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERIES;
-
-import java.util.List;
-
-import org.jboss.jms.client.impl.Cancel;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class CancelDeliveriesMessage extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final List<Cancel> cancels;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public CancelDeliveriesMessage(List<Cancel> cancels)
- {
- super(MSG_CANCELDELIVERIES);
-
- assert cancels != null;
- assert cancels.size() > 0;
-
- this.cancels = cancels;
- }
-
- // Public --------------------------------------------------------
-
- public List<Cancel> getCancels()
- {
- return cancels;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", cancels=" + cancels + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveryMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveryMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/CancelDeliveryMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,61 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERY;
-
-import org.jboss.jms.client.impl.Cancel;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class CancelDeliveryMessage extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final Cancel cancel;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public CancelDeliveryMessage(Cancel cancel)
- {
- super(MSG_CANCELDELIVERY);
-
- assert cancel != null;
-
- this.cancel = cancel;
- }
-
- // Public --------------------------------------------------------
-
- public Cancel getCancel()
- {
- return cancel;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", cancel=" + cancel + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ChangeRateMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ChangeRateMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ChangeRateMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,55 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CHANGERATE;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- *
- * @version <tt>$Revision$</tt>
- */
-public class ChangeRateMessage extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final float rate;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public ChangeRateMessage(float rate)
- {
- super(MSG_CHANGERATE);
-
- this.rate = rate;
- }
-
- // Public --------------------------------------------------------
-
- public float getRate()
- {
- return rate;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", rate=" + rate + "]";
- }
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingMessage.java (from rev 3616, trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingRequest.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingMessage.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
+ *
+ * @version <tt>$Revision$</tt>
+ */
+public class ClosingMessage extends AbstractPacket
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public ClosingMessage()
+ {
+ super(PacketType.MSG_CLOSING);
+ }
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingRequest.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingRequest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingRequest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,56 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CLOSING;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- *
- * @version <tt>$Revision$</tt>
- */
-public class ClosingRequest extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final long sequence;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public ClosingRequest(long sequence)
- {
- super(REQ_CLOSING);
-
- this.sequence = sequence;
- }
-
- // Public --------------------------------------------------------
-
- public long getSequence()
- {
- return sequence;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", sequence=" + sequence + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingResponse.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingResponse.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ClosingResponse.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_CLOSING;
-
-
-/**
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- *
- * @version <tt>$Revision$</tt>
- */
-public class ClosingResponse extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final long id;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public ClosingResponse(long id)
- {
- super(RESP_CLOSING);
-
- this.id = id;
- }
-
- // Public --------------------------------------------------------
-
- public long getID()
- {
- return id;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", id=" + id + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ConsumerChangeRateMessage.java (from rev 3616, trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ChangeRateMessage.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ConsumerChangeRateMessage.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/ConsumerChangeRateMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CHANGERATE;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
+ *
+ * @version <tt>$Revision$</tt>
+ */
+public class ConsumerChangeRateMessage extends AbstractPacket
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private final float rate;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public ConsumerChangeRateMessage(float rate)
+ {
+ super(MSG_CHANGERATE);
+
+ this.rate = rate;
+ }
+
+ // Public --------------------------------------------------------
+
+ public float getRate()
+ {
+ return rate;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getParentString() + ", rate=" + rate + "]";
+ }
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/DeliverMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/DeliverMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/DeliverMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -6,7 +6,6 @@
*/
package org.jboss.messaging.core.remoting.wireformat;
-import static org.jboss.messaging.core.remoting.Assert.assertValidID;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_DELIVERMESSAGE;
import org.jboss.messaging.core.Message;
@@ -24,10 +23,10 @@
// Attributes ----------------------------------------------------
+ //FIXME - we do not need all these fields
+
private final Message message;
- private final String consumerID;
-
private final long deliveryID;
private final int deliveryCount;
@@ -36,19 +35,16 @@
// Constructors --------------------------------------------------
- public DeliverMessage(Message message, String consumerID, long deliveryID,
- int deliveryCount)
+ public DeliverMessage(Message message, long deliveryID,
+ int deliveryCount)
{
super(MSG_DELIVERMESSAGE);
assert message != null;
- assertValidID(consumerID);
this.message = message;
- this.consumerID = consumerID;
this.deliveryID = deliveryID;
this.deliveryCount = deliveryCount;
-
}
// Public --------------------------------------------------------
@@ -58,11 +54,6 @@
return message;
}
- public String getConsumerID()
- {
- return consumerID;
- }
-
public long getDeliveryID()
{
return deliveryID;
@@ -78,7 +69,6 @@
{
StringBuffer buf = new StringBuffer(getParentString());
buf.append(", message=" + message);
- buf.append(", consumerID=" + consumerID);
buf.append(", deliveryID=" + deliveryID);
buf.append(", deliveryCount=" + deliveryCount);
buf.append("]");
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/GetPreparedTransactionsRequest.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/GetPreparedTransactionsRequest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/GetPreparedTransactionsRequest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_GETPREPAREDTRANSACTIONS;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class GetPreparedTransactionsRequest extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public GetPreparedTransactionsRequest()
- {
- super(REQ_GETPREPAREDTRANSACTIONS);
- }
-
- // Public --------------------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/GetPreparedTransactionsResponse.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/GetPreparedTransactionsResponse.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/GetPreparedTransactionsResponse.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_GETPREPAREDTRANSACTIONS;
-
-import java.util.Arrays;
-
-import org.jboss.messaging.core.tx.MessagingXid;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class GetPreparedTransactionsResponse extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final MessagingXid[] xids;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public GetPreparedTransactionsResponse(MessagingXid[] xids)
- {
- super(RESP_GETPREPAREDTRANSACTIONS);
-
- assert xids != null;
-
- this.xids = xids;
- }
-
- // Public --------------------------------------------------------
-
- public MessagingXid[] getXids()
- {
- return xids;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", xids=" + Arrays.asList(xids) + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/PacketType.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/PacketType.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/PacketType.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,21 +21,15 @@
// Connection factory
REQ_CREATECONNECTION ((byte)10),
RESP_CREATECONNECTION ((byte)11),
- RESP_GETTOPOLOGY ((byte)15),
- MSG_UPDATECALLBACK ((byte)16),
// Connection
- REQ_CREATESESSION ((byte)22),
- RESP_CREATESESSION ((byte)23),
- MSG_STARTCONNECTION ((byte)24),
- MSG_STOPCONNECTION ((byte)25),
- MSG_SENDTRANSACTION ((byte)26),
- RESP_SENDTRANSACTION ((byte)27),
- REQ_GETPREPAREDTRANSACTIONS ((byte)28),
- RESP_GETPREPAREDTRANSACTIONS ((byte)29),
- REQ_GETCLIENTID ((byte)30),
- RESP_GETCLIENTID ((byte)31),
- MSG_SETCLIENTID ((byte)32),
+ REQ_CREATESESSION ((byte)20),
+ RESP_CREATESESSION ((byte)21),
+ MSG_STARTCONNECTION ((byte)22),
+ MSG_STOPCONNECTION ((byte)23),
+ REQ_GETCLIENTID ((byte)24),
+ RESP_GETCLIENTID ((byte)25),
+ MSG_SETCLIENTID ((byte)26),
// Session
REQ_CREATECONSUMER ((byte)40),
@@ -47,15 +41,25 @@
REQ_CREATEBROWSER ((byte)46),
RESP_CREATEBROWSER ((byte)47),
MSG_SENDMESSAGE ((byte)48),
- MSG_DELIVERMESSAGE ((byte)49),
- REQ_ACKDELIVERY ((byte)50),
- RESP_ACKDELIVERY ((byte)51),
- MSG_ACKDELIVERIES ((byte)52),
- RESP_ACKDELIVERIES ((byte)53),
- MSG_CANCELDELIVERY ((byte)55),
- MSG_CANCELDELIVERIES ((byte)56),
- MSG_UNSUBSCRIBE ((byte)57),
+ MSG_DELIVERMESSAGE ((byte)49),
+ MSG_UNSUBSCRIBE ((byte)50),
+ MSG_ACKNOWLEDGE ((byte)51),
+ MSG_RECOVER ((byte)52),
+ MSG_COMMIT ((byte)53),
+ MSG_ROLLBACK ((byte)54),
+ MSG_CANCEL ((byte)55),
+ MSG_XA_START ((byte)56),
+ MSG_XA_END ((byte)57),
+ MSG_XA_COMMIT ((byte)58),
+ MSG_XA_PREPARE ((byte)59),
+ MSG_XA_ROLLBACK ((byte)60),
+ MSG_XA_JOIN ((byte)61),
+ MSG_XA_RESUME ((byte)62),
+ MSG_XA_FORGET ((byte)63),
+ REQ_XA_INDOUBT_XIDS ((byte)64),
+ RESP_XA_INDOUBT_XIDS ((byte)65),
+
// ClientConsumer
MSG_CHANGERATE ((byte)70),
@@ -69,9 +73,8 @@
RESP_BROWSER_NEXTMESSAGE ((byte)86),
// Misc
- REQ_CLOSING ((byte)90),
- RESP_CLOSING ((byte)91),
- MSG_CLOSE ((byte)92);
+ MSG_CLOSING ((byte)90),
+ MSG_CLOSE ((byte)91);
private final byte type;
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SendMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SendMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SendMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,69 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SENDMESSAGE;
-
-import org.jboss.messaging.core.Message;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- */
-public class SendMessage extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final Message message;
- private final long sequence;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public SendMessage(Message message, long sequence)
- {
- super(MSG_SENDMESSAGE);
-
- assert message != null;
-
- this.message = message;
- this.sequence = sequence;
- }
-
- // Public --------------------------------------------------------
-
- public Message getMessage()
- {
- return message;
- }
-
- public long getSequence()
- {
- return sequence;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", message=" + message
- + ", sequence="
- + sequence + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SendTransactionMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SendTransactionMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SendTransactionMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,59 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import org.jboss.jms.tx.TransactionRequest;
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- */
-public class SendTransactionMessage extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final TransactionRequest transactionRequest;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public SendTransactionMessage(TransactionRequest transactionRequest)
- {
- super(PacketType.MSG_SENDTRANSACTION);
-
- assert transactionRequest != null;
-
- this.transactionRequest = transactionRequest;
- }
-
- // Public --------------------------------------------------------
-
- public TransactionRequest getTransactionRequest()
- {
- return transactionRequest;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", transactionRequest=" + transactionRequest
- + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Copied: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionSendMessage.java (from rev 3616, trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SendMessage.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionSendMessage.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/SessionSendMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.wireformat;
+
+import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SENDMESSAGE;
+
+import org.jboss.messaging.core.Message;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ */
+public class SessionSendMessage extends AbstractPacket
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private final Message message;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public SessionSendMessage(Message message)
+ {
+ super(MSG_SENDMESSAGE);
+
+ assert message != null;
+
+ this.message = message;
+ }
+
+ // Public --------------------------------------------------------
+
+ public Message getMessage()
+ {
+ return message;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getParentString() + ", message=" + message
+ + "]";
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/wireformat/UpdateCallbackMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/wireformat/UpdateCallbackMessage.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/src/main/org/jboss/messaging/core/remoting/wireformat/UpdateCallbackMessage.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,81 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.wireformat;
-
-import static org.jboss.messaging.core.remoting.Assert.assertValidID;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_UPDATECALLBACK;
-
-/**
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- */
-public class UpdateCallbackMessage extends AbstractPacket
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private final String remotingSessionID;
-
- private final String clientVMID;
-
- private final boolean add;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public UpdateCallbackMessage(String remotingSessionID, String clientVMID,
- boolean add)
- {
- super(MSG_UPDATECALLBACK);
-
- assertValidID(remotingSessionID);
- assertValidID(clientVMID);
-
- this.remotingSessionID = remotingSessionID;
- this.clientVMID = clientVMID;
- this.add = add;
- }
-
- // Public --------------------------------------------------------
-
- public String getRemotingSessionID()
- {
- return remotingSessionID;
- }
-
- public String getClientVMID()
- {
- return clientVMID;
- }
-
- /**
- * @return the add
- */
- public boolean isAdd()
- {
- return add;
- }
-
- @Override
- public String toString()
- {
- return getParentString() + ", remotingSessionID=" + remotingSessionID
- + ", clientVMID=" + clientVMID + ", add=" + add + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Modified: trunk/tests/build.xml
===================================================================
--- trunk/tests/build.xml 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/build.xml 2008-01-26 14:56:42 UTC (rev 3631)
@@ -504,6 +504,9 @@
<!-- We exclude the recovery tests for now, until we get recovery up and running again -->
<exclude name="**/jms/XARecoveryTest.class"/>
<exclude name="**/jms/XAResourceRecoveryTest.class"/>
+ <exclude name="**/jms/XATest.class"/>
+ <exclude name="**/jms/ClientExitTest.class"/>
+ <exclude name="**/jms/ConnectionConsumerTest.class"/>
<include name="**/messaging/util/**/${test-mask}.class"/>
<exclude name="**/jms/MemLeakTest.class"/>
Modified: trunk/tests/etc/log4j.xml
===================================================================
--- trunk/tests/etc/log4j.xml 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/etc/log4j.xml 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
-<!-- $Id: log4j.xml 1019 2006-07-17 17:15:04Z timfox $ -->
+<!-- $Id: log4j.xml 1184 2006-08-03 18:52:12Z ovidiu.feodorov at jboss.com $ -->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
@@ -14,9 +14,8 @@
"crash-server", etc.
-->
<param name="File" value="${module.output}/logs/messaging-${test.logfile.suffix}.log"/>
-
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
- <param name="Threshold" value="INFO"/>
+ <param name="Threshold" value="TRACE#org.jboss.logging.XLevel"/>
<!-- since majority of the tests are ran in fork mode by ant, the log file is overwritten
for each test. We need to append if we want to preserve a full testsuite run log.
@@ -32,24 +31,54 @@
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
- <param name="Threshold" value="TRACE"/>
+ <param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%t %d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
+ <category name="com.arjuna">
+ <priority value="TRACE" class="org.jboss.logging.XLevel"/>
+ </category>
+
<category name="org.apache">
<priority value="INFO"/>
</category>
<category name="org.jgroups">
- <priority value="TRACE"/>
+ <priority value="WARN"/>
</category>
<category name="org.jboss">
<priority value="INFO"/>
</category>
+ <category name="org.jboss.messaging">
+ <priority value="TRACE" class="org.jboss.logging.XLevel"/>
+ </category>
+
+ <category name="org.jboss.jms">
+ <priority value="TRACE" class="org.jboss.logging.XLevel"/>
+ </category>
+
+ <category name="org.jboss.test">
+ <priority value="TRACE" class="org.jboss.logging.XLevel"/>
+ </category>
+
+ <!-- Ignoring trace from these: -->
+
+ <category name="org.jboss.jms.server.remoting.JMSServerInvocationHandler">
+ <priority value="DEBUG"/>
+ </category>
+
+ <category name="org.jboss.test.messaging.tools.container.MockJBossSecurityManager">
+ <priority value="DEBUG"/>
+ </category>
+
+ <category name="org.jboss.jms.wireformat.JMSWireFormat">
+ <priority value="DEBUG"/>
+ </category>
+
<root>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
Modified: trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -317,7 +317,7 @@
if (message.getNumDurableReferences() != 0)
{
//Need to route in a transaction
- Transaction tx = new TransactionImpl(msgs, null, true);
+ Transaction tx = new TransactionImpl();
}
Modified: trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/messaging/core/impl/test/unit/TransactionTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -20,6 +20,8 @@
*
* A TransactionTest
*
+ * TODO test with persistent and non persistent
+ *
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
*
*/
@@ -40,8 +42,11 @@
MessageReference ref2 = this.generateReference(queue, 2);
refsToRemove.add(ref2);
- Transaction tx = new TransactionImpl(msgsToAdd, refsToRemove, true);
+ Transaction tx = new TransactionImpl();
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
+
PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
pm.commitTransaction(msgsToAdd, refsToRemove);
@@ -69,17 +74,21 @@
MessageReference ref2 = this.generateReference(queue, 2);
refsToRemove.add(ref2);
- Transaction tx = new TransactionImpl(msgsToAdd, refsToRemove, true);
+ Transaction tx = new TransactionImpl();
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
+ pm.updateDeliveryCount(queue, ref2);
+
EasyMock.replay(pm);
tx.rollback(pm);
EasyMock.verify(pm);
- assertTrue(queue.list(null).isEmpty());
+ assertEquals(ref2, queue.list(null).get(0));
}
public void test1PCPrepare() throws Exception
@@ -96,7 +105,9 @@
MessageReference ref2 = this.generateReference(queue, 2);
refsToRemove.add(ref2);
- Transaction tx = new TransactionImpl(msgsToAdd, refsToRemove, true);
+ Transaction tx = new TransactionImpl();
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
@@ -129,7 +140,9 @@
Xid xid = generateXid();
- Transaction tx = new TransactionImpl(xid, msgsToAdd, refsToRemove, true);
+ Transaction tx = new TransactionImpl(xid);
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
@@ -165,11 +178,13 @@
MessageReference ref2 = this.generateReference(queue, 2);
refsToRemove.add(ref2);
-
+
Xid xid = generateXid();
-
- Transaction tx = new TransactionImpl(xid, msgsToAdd, refsToRemove, true);
+ Transaction tx = new TransactionImpl(xid);
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
+
PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
try
@@ -200,7 +215,9 @@
Xid xid = generateXid();
- Transaction tx = new TransactionImpl(xid, msgsToAdd, refsToRemove, true);
+ Transaction tx = new TransactionImpl(xid);
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
PersistenceManager pm = EasyMock.createStrictMock(PersistenceManager.class);
@@ -216,6 +233,8 @@
pm.unprepareTransaction(xid, msgsToAdd, refsToRemove);
+ pm.updateDeliveryCount(queue, ref2);
+
EasyMock.replay(pm);
tx.rollback(pm);
@@ -237,7 +256,9 @@
MessageReference ref2 = this.generateReference(queue, 2);
refsToRemove.add(ref2);
- Transaction tx = new TransactionImpl(msgsToAdd, refsToRemove, true);
+ Transaction tx = new TransactionImpl();
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
TransactionSynchronization sync = EasyMock.createStrictMock(TransactionSynchronization.class);
@@ -256,7 +277,9 @@
EasyMock.reset(sync);
- tx = new TransactionImpl(msgsToAdd, refsToRemove, true);
+ tx = new TransactionImpl();
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
tx.addSynchronization(sync);
@@ -286,7 +309,9 @@
Xid xid = generateXid();
- Transaction tx = new TransactionImpl(xid, msgsToAdd, refsToRemove, true);
+ Transaction tx = new TransactionImpl(xid);
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
TransactionSynchronization sync = EasyMock.createStrictMock(TransactionSynchronization.class);
@@ -308,7 +333,9 @@
xid = generateXid();
- tx = new TransactionImpl(xid, msgsToAdd, refsToRemove, true);
+ tx = new TransactionImpl(xid);
+ tx.addMessage(ref1.getMessage());
+ tx.addAcknowledgement(ref2);
tx.addSynchronization(sync);
@@ -322,5 +349,7 @@
EasyMock.verify(sync);
}
-
+
+ // Inner classes -----------------------------------------------------------------------
+
}
Modified: trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/CodecAssert.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -6,12 +6,8 @@
*/
package org.jboss.messaging.core.remoting.wireformat.test.unit;
-import java.util.List;
-
import junit.framework.Assert;
-import org.jboss.jms.client.impl.Ack;
-import org.jboss.jms.client.impl.Cancel;
import org.jboss.messaging.core.tx.MessagingXid;
/**
@@ -28,33 +24,6 @@
// Static --------------------------------------------------------
- static void assertEqualsAcks(List<Ack> expected, List<Ack> actual)
- {
- assertEquals(expected.size(), actual.size());
- for (int i = 0; i < expected.size(); i++)
- {
- assertEquals(expected.get(i).getDeliveryID(), actual.get(i)
- .getDeliveryID());
- }
- }
-
- static void assertEqualsCancels(List<Cancel> expected, List<Cancel> actual)
- {
- assertEquals(expected.size(), actual.size());
- for (int i = 0; i < expected.size(); i++)
- {
- Cancel expectedCancel = expected.get(i);
- Cancel actualCancel = actual.get(i);
- assertEquals(expectedCancel.getDeliveryId(), actualCancel
- .getDeliveryId());
- assertEquals(expectedCancel.getDeliveryCount(), actualCancel
- .getDeliveryCount());
- assertEquals(expectedCancel.isExpired(), actualCancel.isExpired());
- assertEquals(expectedCancel.isReachedMaxDeliveryAttempts(),
- actualCancel.isReachedMaxDeliveryAttempts());
- }
- }
-
static void assertSameXids(MessagingXid[] expected, MessagingXid[] actual)
{
assertEquals(expected.length, actual.length);
Modified: trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/messaging/core/remoting/wireformat/test/unit/PacketTypeTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -12,94 +12,129 @@
import static org.jboss.messaging.core.remoting.codec.AbstractPacketCodec.TRUE;
import static org.jboss.messaging.core.remoting.codec.AbstractPacketCodec.encodeMessage;
import static org.jboss.messaging.core.remoting.codec.AbstractPacketCodec.sizeof;
-import static org.jboss.messaging.core.remoting.codec.SendTransactionMessageCodec.encodeTransactionRequest;
import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.NOT_NULL_STRING;
import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.NULL_BYTE;
import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.NULL_STRING;
import static org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.UTF_8_ENCODER;
import static org.jboss.messaging.core.remoting.wireformat.AbstractPacket.NO_ID_SET;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_ACKDELIVERIES;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_ADDTEMPORARYDESTINATION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_BROWSER_RESET;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERIES;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CANCELDELIVERY;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CHANGERATE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CLOSE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_DELETETEMPORARYDESTINATION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_DELIVERMESSAGE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_JMSEXCEPTION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SENDMESSAGE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SENDTRANSACTION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_SETCLIENTID;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_STARTCONNECTION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_STOPCONNECTION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_UNSUBSCRIBE;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_UPDATECALLBACK;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.NULL;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_ACKDELIVERY;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_BROWSER_HASNEXTMESSAGE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_BROWSER_NEXTMESSAGE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_BROWSER_NEXTMESSAGEBLOCK;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CLOSING;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATEBROWSER;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATECONNECTION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATECONSUMER;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATEDESTINATION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CREATESESSION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_GETCLIENTID;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_GETPREPAREDTRANSACTIONS;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_ACKDELIVERY;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_BROWSER_HASNEXTMESSAGE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_BROWSER_NEXTMESSAGE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_BROWSER_NEXTMESSAGEBLOCK;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_CLOSING;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_CREATEBROWSER;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_CREATECONNECTION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_CREATECONSUMER;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_CREATEDESTINATION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_CREATESESSION;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_GETCLIENTID;
-import static org.jboss.messaging.core.remoting.wireformat.PacketType.RESP_GETPREPAREDTRANSACTIONS;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.TEXT;
-import static org.jboss.messaging.core.remoting.wireformat.test.unit.CodecAssert.assertEqualsAcks;
import static org.jboss.messaging.core.remoting.wireformat.test.unit.CodecAssert.assertEqualsByteArrays;
-import static org.jboss.messaging.core.remoting.wireformat.test.unit.CodecAssert.assertEqualsCancels;
-import static org.jboss.messaging.core.remoting.wireformat.test.unit.CodecAssert.assertSameXids;
import static org.jboss.messaging.test.unit.RandomUtil.randomByte;
-import static org.jboss.messaging.test.unit.RandomUtil.randomBytes;
-import static org.jboss.messaging.test.unit.RandomUtil.randomInt;
import static org.jboss.messaging.test.unit.RandomUtil.randomLong;
import static org.jboss.messaging.test.unit.RandomUtil.randomString;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+
+import javax.jms.InvalidDestinationException;
+import javax.jms.JMSException;
+
import junit.framework.TestCase;
+
import org.apache.mina.common.IoBuffer;
-import org.jboss.jms.client.impl.Ack;
-import org.jboss.jms.client.impl.AckImpl;
-import org.jboss.jms.client.impl.Cancel;
-import org.jboss.jms.client.impl.CancelImpl;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
-import org.jboss.jms.tx.ClientTransaction;
-import org.jboss.jms.tx.TransactionRequest;
import org.jboss.messaging.core.Destination;
import org.jboss.messaging.core.DestinationType;
import org.jboss.messaging.core.Message;
import org.jboss.messaging.core.impl.DestinationImpl;
import org.jboss.messaging.core.impl.MessageImpl;
-import org.jboss.messaging.core.remoting.codec.*;
-import org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.*;
+import org.jboss.messaging.core.remoting.codec.AbstractPacketCodec;
+import org.jboss.messaging.core.remoting.codec.AddTemporaryDestinationMessageCodec;
+import org.jboss.messaging.core.remoting.codec.BrowserHasNextMessageResponseCodec;
+import org.jboss.messaging.core.remoting.codec.BrowserNextMessageBlockRequestCodec;
+import org.jboss.messaging.core.remoting.codec.BrowserNextMessageBlockResponseCodec;
+import org.jboss.messaging.core.remoting.codec.BrowserNextMessageResponseCodec;
+import org.jboss.messaging.core.remoting.codec.ConnectionFactoryCreateConnectionRequestCodec;
+import org.jboss.messaging.core.remoting.codec.ConnectionFactoryCreateConnectionResponseCodec;
+import org.jboss.messaging.core.remoting.codec.ConsumerChangeRateMessageCodec;
+import org.jboss.messaging.core.remoting.codec.CreateBrowserRequestCodec;
+import org.jboss.messaging.core.remoting.codec.CreateBrowserResponseCodec;
+import org.jboss.messaging.core.remoting.codec.CreateConsumerRequestCodec;
+import org.jboss.messaging.core.remoting.codec.CreateConsumerResponseCodec;
+import org.jboss.messaging.core.remoting.codec.CreateDestinationRequestCodec;
+import org.jboss.messaging.core.remoting.codec.CreateDestinationResponseCodec;
+import org.jboss.messaging.core.remoting.codec.CreateSessionRequestCodec;
+import org.jboss.messaging.core.remoting.codec.CreateSessionResponseCodec;
+import org.jboss.messaging.core.remoting.codec.DeleteTemporaryDestinationMessageCodec;
+import org.jboss.messaging.core.remoting.codec.DeliverMessageCodec;
+import org.jboss.messaging.core.remoting.codec.GetClientIDResponseCodec;
+import org.jboss.messaging.core.remoting.codec.JMSExceptionMessageCodec;
+import org.jboss.messaging.core.remoting.codec.RemotingBuffer;
+import org.jboss.messaging.core.remoting.codec.SessionSendMessageCodec;
+import org.jboss.messaging.core.remoting.codec.SetClientIDMessageCodec;
+import org.jboss.messaging.core.remoting.codec.TextPacketCodec;
+import org.jboss.messaging.core.remoting.codec.UnsubscribeMessageCodec;
import org.jboss.messaging.core.remoting.impl.mina.PacketCodecFactory;
-import org.jboss.messaging.core.remoting.wireformat.*;
-import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.messaging.core.remoting.impl.mina.MinaPacketCodec.BufferWrapper;
+import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
+import org.jboss.messaging.core.remoting.wireformat.AddTemporaryDestinationMessage;
+import org.jboss.messaging.core.remoting.wireformat.BrowserHasNextMessageRequest;
+import org.jboss.messaging.core.remoting.wireformat.BrowserHasNextMessageResponse;
+import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageBlockRequest;
+import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageBlockResponse;
+import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageRequest;
+import org.jboss.messaging.core.remoting.wireformat.BrowserNextMessageResponse;
+import org.jboss.messaging.core.remoting.wireformat.BrowserResetMessage;
+import org.jboss.messaging.core.remoting.wireformat.CloseMessage;
+import org.jboss.messaging.core.remoting.wireformat.ClosingMessage;
+import org.jboss.messaging.core.remoting.wireformat.ConsumerChangeRateMessage;
+import org.jboss.messaging.core.remoting.wireformat.CreateBrowserRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateBrowserResponse;
+import org.jboss.messaging.core.remoting.wireformat.CreateConnectionRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateConnectionResponse;
+import org.jboss.messaging.core.remoting.wireformat.CreateConsumerRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateConsumerResponse;
+import org.jboss.messaging.core.remoting.wireformat.CreateDestinationRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateDestinationResponse;
+import org.jboss.messaging.core.remoting.wireformat.CreateSessionRequest;
+import org.jboss.messaging.core.remoting.wireformat.CreateSessionResponse;
+import org.jboss.messaging.core.remoting.wireformat.DeleteTemporaryDestinationMessage;
+import org.jboss.messaging.core.remoting.wireformat.DeliverMessage;
+import org.jboss.messaging.core.remoting.wireformat.GetClientIDRequest;
+import org.jboss.messaging.core.remoting.wireformat.GetClientIDResponse;
+import org.jboss.messaging.core.remoting.wireformat.JMSExceptionMessage;
+import org.jboss.messaging.core.remoting.wireformat.NullPacket;
+import org.jboss.messaging.core.remoting.wireformat.PacketType;
+import org.jboss.messaging.core.remoting.wireformat.SessionSendMessage;
+import org.jboss.messaging.core.remoting.wireformat.SetClientIDMessage;
+import org.jboss.messaging.core.remoting.wireformat.StartConnectionMessage;
+import org.jboss.messaging.core.remoting.wireformat.StopConnectionMessage;
+import org.jboss.messaging.core.remoting.wireformat.TextPacket;
+import org.jboss.messaging.core.remoting.wireformat.UnsubscribeMessage;
-import javax.jms.InvalidDestinationException;
-import javax.jms.JMSException;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
*
@@ -156,18 +191,6 @@
buffer.putLong(l);
}
}
- else if (arg instanceof Cancel[])
- {
- Cancel[] cancels = (Cancel[])arg;
- for (Cancel cancel : cancels)
- {
- buffer.putLong(cancel.getDeliveryId());
- buffer.putInt(cancel.getDeliveryCount());
- buffer.put(cancel.isExpired() ? TRUE : FALSE);
- buffer.put(cancel.isReachedMaxDeliveryAttempts() ? TRUE : FALSE);
- }
- }
-
else
{
fail("no encoding defined for " + arg);
@@ -386,33 +409,7 @@
assertEquals(response.getConnectionID(), decodedResponse
.getConnectionID());
}
-
-
- public void testUpdateCallbackMessage() throws Exception
- {
- UpdateCallbackMessage message = new UpdateCallbackMessage(randomString(),
- randomString(), true);
- addVersion(message);
-
- AbstractPacketCodec codec = new UpdateCallbackMessageCodec();
- SimpleRemotingBuffer buffer = encode(message, codec);
- checkHeader(buffer, message);
- checkBody(buffer, message.getRemotingSessionID(), message.getClientVMID(), message.isAdd());
- buffer.rewind();
-
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof UpdateCallbackMessage);
-
- UpdateCallbackMessage decodedMessage = (UpdateCallbackMessage) decodedPacket;
- assertEquals(MSG_UPDATECALLBACK, decodedMessage.getType());
- assertEquals(message.getRemotingSessionID(), decodedMessage
- .getRemotingSessionID());
- assertEquals(message.getClientVMID(), decodedMessage.getClientVMID());
- assertEquals(message.isAdd(), decodedMessage.isAdd());
- }
-
public void testCreateSessionRequest() throws Exception
{
CreateSessionRequest request = new CreateSessionRequest(true, 0, false);
@@ -459,22 +456,20 @@
public void testSendMessage() throws Exception
{
- SendMessage packet = new SendMessage(new MessageImpl(),
- randomLong());
+ SessionSendMessage packet = new SessionSendMessage(new MessageImpl());
addVersion(packet);
- AbstractPacketCodec codec = new SendMessageCodec();
+ AbstractPacketCodec codec = new SessionSendMessageCodec();
SimpleRemotingBuffer buffer = encode(packet, codec);
checkHeader(buffer, packet);
- checkBody(buffer, encodeMessage(packet.getMessage()), packet.getSequence());
+ checkBody(buffer, encodeMessage(packet.getMessage()));
buffer.rewind();
AbstractPacket p = codec.decode(buffer);
- assertTrue(p instanceof SendMessage);
- SendMessage decodedPacket = (SendMessage) p;
+ assertTrue(p instanceof SessionSendMessage);
+ SessionSendMessage decodedPacket = (SessionSendMessage) p;
assertEquals(MSG_SENDMESSAGE, decodedPacket.getType());
- assertEquals(packet.getSequence(), decodedPacket.getSequence());
assertEquals(packet.getMessage().getMessageID(), decodedPacket
.getMessage().getMessageID());
}
@@ -638,9 +633,9 @@
public void testChangeRateMessage() throws Exception
{
- ChangeRateMessage message = new ChangeRateMessage(0.63f);
+ ConsumerChangeRateMessage message = new ConsumerChangeRateMessage(0.63f);
addVersion(message);
- AbstractPacketCodec codec = new ChangeRateMessageCodec();
+ AbstractPacketCodec codec = new ConsumerChangeRateMessageCodec();
SimpleRemotingBuffer buffer = encode(message, codec);
checkHeader(buffer, message);
checkBody(buffer, message.getRate());
@@ -648,8 +643,8 @@
AbstractPacket decodedPacket = codec.decode(buffer);
- assertTrue(decodedPacket instanceof ChangeRateMessage);
- ChangeRateMessage decodedMessage = (ChangeRateMessage) decodedPacket;
+ assertTrue(decodedPacket instanceof ConsumerChangeRateMessage);
+ ConsumerChangeRateMessage decodedMessage = (ConsumerChangeRateMessage) decodedPacket;
assertEquals(MSG_CHANGERATE, decodedMessage.getType());
assertEquals(message.getRate(), decodedMessage.getRate());
}
@@ -657,14 +652,13 @@
public void testDeliverMessage() throws Exception
{
Message msg = new MessageImpl();
- DeliverMessage message = new DeliverMessage(msg, randomString(),
- randomLong(), 23);
+ DeliverMessage message = new DeliverMessage(msg, randomLong(), 23);
addVersion(message);
AbstractPacketCodec codec = new DeliverMessageCodec();
SimpleRemotingBuffer buffer = encode(message, codec);
checkHeader(buffer, message);
- checkBody(buffer, encodeMessage(msg), message.getConsumerID(),
+ checkBody(buffer, encodeMessage(msg),
message.getDeliveryID(), message.getDeliveryCount());
buffer.rewind();
@@ -675,115 +669,32 @@
assertEquals(MSG_DELIVERMESSAGE, decodedMessage.getType());
assertEquals(message.getMessage().getMessageID(), decodedMessage
.getMessage().getMessageID());
- assertEquals(message.getConsumerID(), decodedMessage.getConsumerID());
assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
assertEquals(message.getDeliveryCount(), decodedMessage
.getDeliveryCount());
}
- public void testAcknowledgeDeliveryRequest() throws Exception
- {
- AcknowledgeDeliveryRequest request = new AcknowledgeDeliveryRequest(
- randomLong());
- addVersion(request);
-
- AbstractPacketCodec codec = new AcknowledgeDeliveryRequestCodec();
- SimpleRemotingBuffer buffer = encode(request, codec);
- checkHeader(buffer, request);
- checkBody(buffer, request.getDeliveryID());
- buffer.rewind();
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof AcknowledgeDeliveryRequest);
- AcknowledgeDeliveryRequest decodedRequest = (AcknowledgeDeliveryRequest) decodedPacket;
- assertEquals(REQ_ACKDELIVERY, decodedRequest.getType());
- assertEquals(request.getDeliveryID(), decodedRequest.getDeliveryID());
- }
-
- public void testAcknowledgeDeliveriesRequest() throws Exception
+ public void testClosingMessage() throws Exception
{
- List<Ack> acks = new ArrayList<Ack>();
- acks.add(new AckImpl(randomLong()));
- acks.add(new AckImpl(randomLong()));
- acks.add(new AckImpl(randomLong()));
- AcknowledgeDeliveriesMessage request = new AcknowledgeDeliveriesMessage(
- acks);
+ ClosingMessage request = new ClosingMessage();
addVersion(request);
- AcknowledgeDeliveriesRequestCodec codec = new AcknowledgeDeliveriesRequestCodec();
+ AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
+ PacketType.MSG_CLOSING, ClosingMessage.class);
SimpleRemotingBuffer buffer = encode(request, codec);
checkHeader(buffer, request);
- checkBody(buffer, AcknowledgeDeliveriesRequestCodec.convert(acks));
+ checkBodyIsEmpty(buffer);
buffer.rewind();
AbstractPacket decodedPacket = codec.decode(buffer);
- assertTrue(decodedPacket instanceof AcknowledgeDeliveriesMessage);
- AcknowledgeDeliveriesMessage decodedRequest = (AcknowledgeDeliveriesMessage) decodedPacket;
- assertEquals(MSG_ACKDELIVERIES, decodedRequest.getType());
- assertEqualsAcks(request.getAcks(), decodedRequest.getAcks());
+ assertTrue(decodedPacket instanceof ClosingMessage);
+ ClosingMessage decodedRequest = (ClosingMessage) decodedPacket;
+ assertEquals(PacketType.MSG_CLOSING, decodedRequest.getType());
}
- public void testAcknowledgeDeliveryResponse() throws Exception
- {
- AcknowledgeDeliveryResponse response = new AcknowledgeDeliveryResponse(
- true);
- addVersion(response);
-
- AbstractPacketCodec codec = new AcknowledgeDeliveryResponseCodec();
- SimpleRemotingBuffer buffer = encode(response, codec);
- checkHeader(buffer, response);
- checkBody(buffer, response.isAcknowledged());
- buffer.rewind();
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof AcknowledgeDeliveryResponse);
- AcknowledgeDeliveryResponse decodedResponse = (AcknowledgeDeliveryResponse) decodedPacket;
- assertEquals(RESP_ACKDELIVERY, decodedResponse.getType());
- assertEquals(response.isAcknowledged(), decodedResponse.isAcknowledged());
-
- }
-
- public void testClosingRequest() throws Exception
- {
- ClosingRequest request = new ClosingRequest(randomLong());
- addVersion(request);
-
- AbstractPacketCodec codec = new ClosingRequestCodec();
- SimpleRemotingBuffer buffer = encode(request, codec);
- checkHeader(buffer, request);
- checkBody(buffer, request.getSequence());
- buffer.rewind();
-
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof ClosingRequest);
- ClosingRequest decodedRequest = (ClosingRequest) decodedPacket;
- assertEquals(REQ_CLOSING, decodedRequest.getType());
- assertEquals(request.getSequence(), decodedRequest.getSequence());
- }
-
- public void testClosingResponse() throws Exception
- {
- ClosingResponse response = new ClosingResponse(randomLong());
- addVersion(response);
-
- AbstractPacketCodec codec = new ClosingResponseCodec();
- SimpleRemotingBuffer buffer = encode(response, codec);
- checkHeader(buffer, response);
- checkBody(buffer, response.getID());
- buffer.rewind();
-
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof ClosingResponse);
- ClosingResponse decodedRequest = (ClosingResponse) decodedPacket;
- assertEquals(RESP_CLOSING, decodedRequest.getType());
- assertEquals(response.getID(), decodedRequest.getID());
- }
-
public void testCloseMessage() throws Exception
{
CloseMessage message = new CloseMessage();
@@ -803,74 +714,7 @@
assertEquals(MSG_CLOSE, decodedMessage.getType());
}
- public void testSendTransactionMessage() throws Exception
- {
- ClientTransaction tx = new ClientTransaction();
- MessagingXid xid = new MessagingXid(randomBytes(), randomInt(), randomBytes());
- TransactionRequest tr = new TransactionRequest(
- TransactionRequest.ONE_PHASE_COMMIT_REQUEST, xid, tx);
- SendTransactionMessage message = new SendTransactionMessage(tr);
- addVersion(message);
-
- AbstractPacketCodec codec = new SendTransactionMessageCodec();
- SimpleRemotingBuffer buffer = encode(message, codec);
- checkHeader(buffer, message);
- checkBody(buffer, encodeTransactionRequest(tr));
- buffer.rewind();
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof SendTransactionMessage);
- SendTransactionMessage decodedMessage = (SendTransactionMessage) decodedPacket;
- assertEquals(MSG_SENDTRANSACTION, decodedMessage.getType());
- TransactionRequest expectedTxReq = message.getTransactionRequest();
- TransactionRequest actualTxReq = decodedMessage.getTransactionRequest();
- assertEquals(expectedTxReq.getRequestType(), actualTxReq.getRequestType());
- assertEquals(expectedTxReq.getXid(), actualTxReq.getXid());
- }
-
- public void testGetPreparedTransactionsRequest() throws Exception
- {
- GetPreparedTransactionsRequest request = new GetPreparedTransactionsRequest();
- addVersion(request);
-
- AbstractPacketCodec codec = PacketCodecFactory.createCodecForEmptyPacket(
- REQ_GETPREPAREDTRANSACTIONS, GetPreparedTransactionsRequest.class);
- SimpleRemotingBuffer buffer = encode(request, codec);
- checkHeader(buffer, request);
- checkBodyIsEmpty(buffer);
- buffer.rewind();
-
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof GetPreparedTransactionsRequest);
- assertEquals(REQ_GETPREPAREDTRANSACTIONS, decodedPacket.getType());
- }
-
- public void testGetPreparedTransactionsResponse() throws Exception
- {
- MessagingXid[] xids = new MessagingXid[] {
- new MessagingXid(randomBytes(), 23, randomBytes()),
- new MessagingXid(randomBytes(), 33, randomBytes()),
- new MessagingXid(randomBytes(), 91, randomBytes()) };
- GetPreparedTransactionsResponse response = new GetPreparedTransactionsResponse(
- xids);
- addVersion(response);
-
- AbstractPacketCodec codec = new GetPreparedTransactionsResponseCodec();
- SimpleRemotingBuffer buffer = encode(response, codec);
- checkHeader(buffer, response);
- checkBody(buffer, xids.length, GetPreparedTransactionsResponseCodec.encode(xids));
- buffer.rewind();
-
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof GetPreparedTransactionsResponse);
- GetPreparedTransactionsResponse decodedResponse = (GetPreparedTransactionsResponse) decodedPacket;
- assertEquals(RESP_GETPREPAREDTRANSACTIONS, decodedResponse.getType());
- assertSameXids(response.getXids(), decodedResponse.getXids());
- }
-
public void testGetClientIDRequest() throws Exception
{
GetClientIDRequest request = new GetClientIDRequest();
@@ -927,54 +771,6 @@
assertEquals(message.getClientID(), decodedMessage.getClientID());
}
- public void testCancelDeliveryMessage() throws Exception
- {
- Cancel cancel = new CancelImpl(randomLong(), randomInt(), true, false);
- CancelDeliveryMessage message = new CancelDeliveryMessage(cancel);
- addVersion(message);
- AbstractPacketCodec codec = new CancelDeliveryMessageCodec();
- SimpleRemotingBuffer buffer = encode(message, codec);
- checkHeader(buffer, message);
- checkBody(buffer, cancel.getDeliveryId(), cancel.getDeliveryCount(), cancel.isExpired(),
- cancel.isReachedMaxDeliveryAttempts());
- buffer.rewind();
-
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof CancelDeliveryMessage);
- CancelDeliveryMessage decodedMessage = (CancelDeliveryMessage) decodedPacket;
- assertEquals(MSG_CANCELDELIVERY, decodedMessage.getType());
- Cancel expected = message.getCancel();
- Cancel actual = decodedMessage.getCancel();
- assertEquals(expected.getDeliveryId(), actual.getDeliveryId());
- assertEquals(expected.getDeliveryCount(), actual.getDeliveryCount());
- assertEquals(expected.isExpired(), actual.isExpired());
- assertEquals(expected.isReachedMaxDeliveryAttempts(), actual
- .isReachedMaxDeliveryAttempts());
- }
-
- public void testCancelDeliveriesMessage() throws Exception
- {
- List<Cancel> cancels = new ArrayList<Cancel>();
- cancels.add(new CancelImpl(randomLong(), 23, true, false));
- cancels.add(new CancelImpl(randomLong(), 33, false, true));
- CancelDeliveriesMessage message = new CancelDeliveriesMessage(cancels);
- addVersion(message);
-
- AbstractPacketCodec codec = new CancelDeliveriesMessageCodec();
- SimpleRemotingBuffer buffer = encode(message, codec);
- checkHeader(buffer, message);
- checkBody(buffer, cancels.size(), cancels.toArray(new Cancel[cancels.size()]));
- buffer.rewind();
-
- AbstractPacket decodedPacket = codec.decode(buffer);
-
- assertTrue(decodedPacket instanceof CancelDeliveriesMessage);
- CancelDeliveriesMessage decodedMessage = (CancelDeliveriesMessage) decodedPacket;
- assertEquals(MSG_CANCELDELIVERIES, decodedMessage.getType());
- assertEqualsCancels(message.getCancels(), decodedMessage.getCancels());
- }
-
public void testCreateBrowserRequest() throws Exception
{
Destination destination = new DestinationImpl(DestinationType.QUEUE, "testCreateBrowserRequest", false);
Modified: trunk/tests/src/org/jboss/test/messaging/JBMServerTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/JBMServerTestCase.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/JBMServerTestCase.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,9 +21,23 @@
*/
package org.jboss.test.messaging;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+
+import javax.jms.Queue;
+import javax.jms.Topic;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+
import org.jboss.jms.client.JBossConnectionFactory;
import org.jboss.jms.server.security.Role;
-import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.messaging.core.MessagingServer;
import org.jboss.messaging.core.MessagingServerManagement;
import org.jboss.messaging.microcontainer.JBMBootstrapServer;
@@ -32,20 +46,6 @@
import org.jboss.test.messaging.tools.container.Server;
import org.jboss.tm.TransactionManagerLocator;
-import javax.jms.Queue;
-import javax.jms.Topic;
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-
/**
* @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
@@ -182,13 +182,7 @@
checkNoSubscriptions(topic1);
checkNoSubscriptions(topic2);
checkNoSubscriptions(topic3);
- //some clean up between tests
- for (int i = 0; i < getServerCount(); i++)
- {
- servers.get(i).clear();
- }
- ResourceManagerFactory.instance.clear();
-
+
if (isRemote())
{
// log the test start in the remote log, this will make hunting through logs so much easier
@@ -197,14 +191,6 @@
}
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
- //this will make sure there arent any connection hanging around
- assertEquals(0, servers.get(0).getResourceManagerFactorySize());
- }
-
protected boolean isRemote()
{
return ServerManagement.isRemote();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/AcknowledgementTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -267,16 +267,18 @@
assertRemainingMessages(NUM_MESSAGES);
- log.trace("Session rollback called");
+ log.info("Session rollback called");
int i = 0;
for(; i < NUM_MESSAGES; i++)
{
consumer.receive();
- log.trace("Received message " + i);
+ log.info("Received message " + i);
}
assertRemainingMessages(NUM_MESSAGES);
+
+ log.info("Got here");
// if I don't receive enough messages, the test will timeout
@@ -338,10 +340,11 @@
assertRemainingMessages(NUM_MESSAGES);
- log.trace("Received " + count + " messages");
+ log.info("Received " + count + " messages");
assertEquals(count, NUM_MESSAGES);
+ log.info("calling recover");
consumerSess.recover();
assertRemainingMessages(NUM_MESSAGES);
@@ -353,15 +356,20 @@
int i = 0;
for(; i < NUM_MESSAGES; i++)
{
- m = consumer.receive();
+ m = consumer.receive(1000);
log.trace("Received message " + i);
+
+ if (m == null)
+ {
+ break;
+ }
}
assertRemainingMessages(NUM_MESSAGES);
// if I don't receive enough messages, the test will timeout
- log.trace("Received " + i + " messages after recover");
+ log.info("Received " + i + " messages after recover");
m.acknowledge();
@@ -597,7 +605,12 @@
conn.close();
}
+ log.info("Removing all messages from queue " + queue1.getQueueName());
removeAllMessages(queue1.getQueueName(), true, 0);
+
+ log.info("Done remove");
+
+ assertRemainingMessages(0);
}
}
@@ -613,6 +626,7 @@
try
{
+ assertRemainingMessages(0);
conn = cf.createConnection();
@@ -634,7 +648,7 @@
assertRemainingMessages(NUM_MESSAGES);
- log.trace("Sent messages");
+ log.info("Sent messages");
int count = 0;
@@ -644,6 +658,8 @@
assertRemainingMessages(NUM_MESSAGES - i);
m = consumer.receive(200);
+
+ log.info("got message " + m);
assertRemainingMessages(NUM_MESSAGES - (i + 1));
@@ -679,30 +695,7 @@
}
- public void testDupsOKBatchDefault() throws Exception
- {
- //test default
- Connection conn = null;
- try
- {
- conn = cf.createConnection();
-
- JBossSession sess = (JBossSession)conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
-
- ClientSession del = sess.getDelegate();
-
- assertEquals(1000, del.getDupsOKBatchSize());
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
public void testDupsOKAcknowledgeQueue() throws Exception
{
final int BATCH_SIZE = 10;
@@ -830,84 +823,10 @@
}
undeployConnectionFactory("mycf");
- }
-
-
+ }
}
-
-
- /*
- * Send some messages, consume them and verify the messages are not sent upon recovery
- *
- */
- public void testLazyAcknowledge() throws Exception
- {
- Connection conn = null;
-
- try
- {
-
- conn = cf.createConnection();
-
- Session producerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
- MessageProducer producer = producerSess.createProducer(queue1);
-
- Session consumerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
- MessageConsumer consumer = consumerSess.createConsumer(queue1);
- conn.start();
-
- final int NUM_MESSAGES = 20;
-
- //Send some messages
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- Message m = producerSess.createMessage();
- producer.send(m);
- }
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Sent messages");
-
- int count = 0;
-
- Message m = null;
- for (int i = 0; i < NUM_MESSAGES; i++)
- {
- m = consumer.receive(200);
- if (m == null) break;
- count++;
- }
-
- assertNotNull(m);
-
- assertRemainingMessages(NUM_MESSAGES);
-
- log.trace("Received " + count + " messages");
-
- assertEquals(count, NUM_MESSAGES);
-
- consumerSess.recover();
-
- log.trace("Session recover called");
-
- m = consumer.receive(200);
-
- log.trace("Message is:" + m);
-
- assertNull(m);
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
-
- }
-
+
public void testMessageListenerAutoAck() throws Exception
{
Connection conn = null;
@@ -918,7 +837,7 @@
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessSend.createProducer(queue1);
- log.trace("Sending messages");
+ log.info("Sending messages");
TextMessage tm1 = sessSend.createTextMessage("a");
TextMessage tm2 = sessSend.createTextMessage("b");
@@ -927,7 +846,7 @@
prod.send(tm2);
prod.send(tm3);
- log.trace("Sent messages");
+ log.info("Sent messages");
sessSend.close();
@@ -937,19 +856,19 @@
Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- log.trace("Creating consumer");
+ log.info("Creating consumer");
MessageConsumer cons = sessReceive.createConsumer(queue1);
- log.trace("Created consumer");
+ log.info("Created consumer");
MessageListenerAutoAck listener = new MessageListenerAutoAck(sessReceive);
- log.trace("Setting message listener");
+ log.info("Setting message listener");
cons.setMessageListener(listener);
- log.trace("Set message listener");
+ log.info("Set message listener");
listener.waitForMessages();
@@ -1004,33 +923,42 @@
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(queue1);
+
+ log.info("here1");
TextMessage messageReceived = (TextMessage)consumer.receive(1000);
+
+ log.info("here2");
assertNotNull(messageReceived);
assertEquals("one", messageReceived.getText());
+
+ log.info("here3");
session.recover();
messageReceived = (TextMessage)consumer.receive(1000);
+
+ log.info("here4");
+
+ assertNotNull(messageReceived);
assertEquals("two", messageReceived.getText());
+ log.info("closing consumer");
+
consumer.close();
+
+ log.info("consumer closed");
- // I can't call xasession.close for this test as JCA layer would cache the session
- // So.. keep this close commented!
- //xasession.close();
-
assertRemainingMessages(0);
-
}
finally
{
if (conn != null)
{
- conn.close();
+ conn.close();
}
}
}
@@ -1044,6 +972,8 @@
try
{
+ this.assertRemainingMessages(0);
+
conn = cf.createConnection();
Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessSend.createProducer(queue1);
@@ -1083,14 +1013,20 @@
listener.waitForMessages();
- assertRemainingMessages(3);
+ assertFalse(listener.failed);
- conn.close();
+ assertRemainingMessages(1);
- Thread.sleep(500);
+ log.info("Closing session");
+ sessReceive.close();
+ log.info("Closed session");
assertRemainingMessages(0);
- assertFalse(listener.failed);
+
+ conn.close();
+
+ assertRemainingMessages(0);
+
}
finally
{
@@ -1098,6 +1034,7 @@
{
conn.close();
}
+
}
}
@@ -1240,7 +1177,7 @@
TextMessage tm = (TextMessage)m;
- //log.info("Got message: " + tm.getText());
+ log.info("Got message: " + tm.getText());
// Receive first three messages then recover() session
// Only last message should be redelivered
@@ -1273,7 +1210,9 @@
failed = true;
latch.release();
}
+ log.info("Recovering session");
sess.recover();
+ log.info("Session recovered");
}
if (count == 4)
{
@@ -1313,6 +1252,8 @@
count++;
TextMessage tm = (TextMessage)m;
+
+ log.info("Got message " + tm.getText());
// Receive first three messages then recover() session
// Only last message should be redelivered
@@ -1323,6 +1264,7 @@
if (!"a".equals(tm.getText()))
{
failed = true;
+ log.info("Failed1");
latch.release();
}
}
@@ -1333,6 +1275,7 @@
if (!"b".equals(tm.getText()))
{
failed = true;
+ log.info("Failed2");
latch.release();
}
}
@@ -1343,27 +1286,30 @@
if (!"c".equals(tm.getText()))
{
failed = true;
+ log.info("Failed3");
latch.release();
}
sess.recover();
}
if (count == 4)
{
- assertRemainingMessages(3);
+ assertRemainingMessages(1);
if (!"c".equals(tm.getText()))
{
failed = true;
+ log.info("Failed4");
latch.release();
- }
+ }
latch.release();
- }
-
+ }
+
}
catch (Exception e)
{
failed = true;
latch.release();
+ e.printStackTrace();
}
}
@@ -1427,6 +1373,7 @@
failed = true;
latch.release();
}
+ log.info("acknowledging manually");
tm.acknowledge();
assertRemainingMessages(2);
sess.recover();
@@ -1493,6 +1440,8 @@
count++;
TextMessage tm = (TextMessage)m;
+
+ log.info("Got message " + tm.getText());
if (count == 1)
{
@@ -1520,7 +1469,7 @@
failed = true;
latch.release();
}
- log.trace("Rollback");
+ log.info("Rollback");
sess.rollback();
}
if (count == 4)
@@ -1540,7 +1489,7 @@
failed = true;
latch.release();
}
- log.trace("commit");
+ log.info("commit");
sess.commit();
assertRemainingMessages(1);
}
@@ -1552,7 +1501,7 @@
failed = true;
latch.release();
}
- log.trace("recover");
+ log.info("rollback2");
sess.rollback();
}
if (count == 7)
@@ -1563,7 +1512,7 @@
failed = true;
latch.release();
}
- log.trace("Commit");
+ log.info("Commit2");
sess.commit();
assertRemainingMessages(0);
latch.release();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ConnectionTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -33,7 +33,6 @@
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
-import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.messaging.util.Logger;
@@ -69,51 +68,6 @@
// Public --------------------------------------------------------
- public void testResourceManagerFactory()
- {
- ResourceManagerFactory.instance.checkOutResourceManager(1);
-
- ResourceManagerFactory.instance.checkOutResourceManager(2);
-
- ResourceManagerFactory.instance.checkOutResourceManager(3);
-
- ResourceManagerFactory.instance.checkOutResourceManager(4);
-
- assertEquals(4, ResourceManagerFactory.instance.size());
-
- ResourceManagerFactory.instance.checkOutResourceManager(4);
-
- assertEquals(4, ResourceManagerFactory.instance.size());
-
- ResourceManagerFactory.instance.checkOutResourceManager(4);
-
- assertEquals(4, ResourceManagerFactory.instance.size());
-
- ResourceManagerFactory.instance.checkInResourceManager(4);
-
- assertEquals(4, ResourceManagerFactory.instance.size());
-
- ResourceManagerFactory.instance.checkInResourceManager(4);
-
- assertEquals(4, ResourceManagerFactory.instance.size());
-
- ResourceManagerFactory.instance.checkInResourceManager(4);
-
- assertEquals(3, ResourceManagerFactory.instance.size());
-
- ResourceManagerFactory.instance.checkInResourceManager(3);
-
- assertEquals(2, ResourceManagerFactory.instance.size());
-
- ResourceManagerFactory.instance.checkInResourceManager(2);
-
- assertEquals(1, ResourceManagerFactory.instance.size());
-
- ResourceManagerFactory.instance.checkInResourceManager(1);
-
- assertEquals(0, ResourceManagerFactory.instance.size());
-
- }
public void testManyConnections() throws Exception
{
Modified: trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -258,7 +258,11 @@
// this should cancel message and cause delivery to other consumer
+ log.info("closing session");
+
sessConsume1.close();
+
+ log.info("closed session");
TextMessage tm3 = (TextMessage)cons2.receive(1000);
@@ -780,9 +784,15 @@
assertEquals("One", m.getText());
+ log.info("Closing consumer");
queueConsumer.close();
+ log.info("Closed consumer");
+ log.info("Committing session");
consumerSession.commit();
+ log.info("Committed session");
+
+
// I expect that "Two" is still in the queue
@@ -1400,7 +1410,7 @@
MessageConsumer cons2 = sess2.createConsumer(topic1);
MessageConsumer cons3 = sess3.createConsumer(topic1);
- final int NUM_MESSAGES = 100;
+ final int NUM_MESSAGES = 10;
class Receiver implements Runnable
{
@@ -1423,7 +1433,7 @@
failed = true;
break;
}
- log.trace("received message");
+ log.info("received message");
if (!m.getText().equals("testing"))
{
failed = true;
@@ -1468,9 +1478,9 @@
log.trace("Sent message to topic");
}
- t1.join();
- t2.join();
- t3.join();
+ t1.join(15000);
+ t2.join(15000);
+ t3.join(15000);
sess1.close();
sess2.close();
Modified: trunk/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MiscellaneousTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -99,7 +99,7 @@
/**
* Test case for http://jira.jboss.org/jira/browse/JBMESSAGING-542
*/
- public void testClosingConsumerFromMessageListener() throws Exception
+ public void testClosingConsumerFromMessageListenerAutoAck() throws Exception
{
Connection c = null;
@@ -147,10 +147,10 @@
assertTrue(result.isSuccess());
assertNull(result.getFailure());
- // make sure the acknowledgment made it back to the queue
+ // it's auto _ack so message *should not* be acked (auto ack acks after successfully completion of onMessage
Thread.sleep(1000);
- assertRemainingMessages(0);
+ assertRemainingMessages(1);
conn.close();
@@ -159,7 +159,7 @@
/**
* Test case for http://jira.jboss.org/jira/browse/JBMESSAGING-542
*/
- public void testClosingSessionFromMessageListener() throws Exception
+ public void testClosingSessionFromMessageListenerAutoAck() throws Exception
{
Connection c = null;
@@ -207,17 +207,15 @@
assertTrue(result.isSuccess());
assertNull(result.getFailure());
- // make sure the acknowledgment made it back to the queue
-
Thread.sleep(1000);
- assertRemainingMessages(0);
+ assertRemainingMessages(1);
conn.close();
}
/**
* Test case for http://jira.jboss.org/jira/browse/JBMESSAGING-542
*/
- public void testClosingConnectionFromMessageListener() throws Exception
+ public void testClosingConnectionFromMessageListenerAutoAck() throws Exception
{
Connection c = null;
@@ -266,15 +264,192 @@
assertTrue(result.isSuccess());
assertNull(result.getFailure());
- // make sure the acknowledgment made it back to the queue
+ Thread.sleep(1000);
+ assertRemainingMessages(1);
+
+ conn.close();
+
+ }
+
+
+
+ /**
+ * Test case for http://jira.jboss.org/jira/browse/JBMESSAGING-542
+ */
+ public void testClosingConsumerFromMessageListenerTransacted() throws Exception
+ {
+ Connection c = null;
+
+ try
+ {
+ c = cf.createConnection();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(queue1);
+ Message m = s.createMessage();
+ prod.send(m);
+ }
+ finally
+ {
+ if (c != null)
+ {
+ c.close();
+ }
+ }
+
+ log.info("sent message");
+
+ final Result result = new Result();
+ Connection conn = cf.createConnection();
+ Session s = conn.createSession(true, Session.SESSION_TRANSACTED);
+ final MessageConsumer cons = s.createConsumer(queue1);
+ cons.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message m)
+ {
+ // close the connection on the same thread that processed the message
+ try
+ {
+ log.info("Closing consumer");
+ cons.close();
+ log.info("closed consumer");
+ result.setSuccess();
+ }
+ catch(Exception e)
+ {
+ result.setFailure(e);
+ }
+ }
+ });
+ conn.start();
+
+ result.waitForResult();
+
+ assertTrue(result.isSuccess());
+ assertNull(result.getFailure());
+
Thread.sleep(1000);
- assertRemainingMessages(0);
+ assertRemainingMessages(1);
conn.close();
+
+ }
+
+ /**
+ * Test case for http://jira.jboss.org/jira/browse/JBMESSAGING-542
+ */
+ public void testClosingSessionFromMessageListenerTransacted() throws Exception
+ {
+ Connection c = null;
+ try
+ {
+ c = cf.createConnection();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(queue1);
+ Message m = s.createMessage();
+ prod.send(m);
+ }
+ finally
+ {
+ if (c != null)
+ {
+ c.close();
+ }
+ }
+
+ final Result result = new Result();
+ Connection conn = cf.createConnection();
+ final Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer cons = session.createConsumer(queue1);
+ cons.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message m)
+ {
+ // close the connection on the same thread that processed the message
+ try
+ {
+ session.close();
+ result.setSuccess();
+ }
+ catch(Exception e)
+ {
+ result.setFailure(e);
+ }
+ }
+ });
+
+ conn.start();
+
+ result.waitForResult();
+
+ assertTrue(result.isSuccess());
+ assertNull(result.getFailure());
+
+ Thread.sleep(1000);
+ assertRemainingMessages(1);
+ conn.close();
}
+
+ /**
+ * Test case for http://jira.jboss.org/jira/browse/JBMESSAGING-542
+ */
+ public void testClosingConnectionFromMessageListenerTransacted() throws Exception
+ {
+ Connection c = null;
+
+ try
+ {
+ c = cf.createConnection();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = s.createProducer(queue1);
+ Message m = s.createMessage();
+ prod.send(m);
+ }
+ finally
+ {
+ if (c != null)
+ {
+ c.close();
+ }
+ }
+ final Result result = new Result();
+ final Connection conn = cf.createConnection();
+ Session s = conn.createSession(true, Session.SESSION_TRANSACTED);
+ MessageConsumer cons = s.createConsumer(queue1);
+ cons.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message m)
+ {
+ // close the connection on the same thread that processed the message
+ try
+ {
+ conn.close();
+ result.setSuccess();
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ result.setFailure(e);
+ }
+ }
+ });
+
+ conn.start();
+
+ result.waitForResult();
+
+ assertTrue(result.isSuccess());
+ assertNull(result.getFailure());
+
+ Thread.sleep(1000);
+ assertRemainingMessages(1);
+
+ conn.close();
+
+ }
+
// Test case for http://jira.jboss.com/jira/browse/JBMESSAGING-788
public void testGetDeliveriesForSession() throws Exception
{
Modified: trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -38,9 +38,6 @@
import javax.jms.XAConnection;
import javax.jms.XASession;
-import org.jboss.jms.client.JBossSession;
-import org.jboss.jms.client.api.ClientSession;
-import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.test.messaging.JBMServerTestCase;
/**
@@ -67,39 +64,39 @@
// Public --------------------------------------------------------
- public void testNoTransactionAfterClose() throws Exception
- {
- Connection conn = getConnectionFactory().createConnection();
- conn.start();
- Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
- MessageProducer prod = sess.createProducer(queue1);
- prod.send(sess.createMessage());
- sess.commit();
- MessageConsumer cons = sess.createConsumer(queue1);
- cons.receive();
- sess.commit();
-
- ClientSession del = ((JBossSession)sess).getDelegate();
-
- //SessionState state = (SessionState)del.getState();
- //ConnectionState cState = (ConnectionState)state.getParent();
-
- Object xid = del.getCurrentTxId();
- assertNotNull(xid);
- assertNotNull(del.getConnection().getResourceManager().getTx(xid));
-
- //Now close the session
- sess.close();
-
- //Session should be removed from resource manager
- xid = del.getCurrentTxId();
- assertNotNull(xid);
- assertNull(del.getConnection().getResourceManager().getTx(xid));
-
- conn.close();
-
- assertEquals(0, del.getConnection().getResourceManager().size());
- }
+// public void testNoTransactionAfterClose() throws Exception
+// {
+// Connection conn = getConnectionFactory().createConnection();
+// conn.start();
+// Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+// MessageProducer prod = sess.createProducer(queue1);
+// prod.send(sess.createMessage());
+// sess.commit();
+// MessageConsumer cons = sess.createConsumer(queue1);
+// cons.receive();
+// sess.commit();
+//
+// ClientSession del = ((JBossSession)sess).getDelegate();
+//
+// //SessionState state = (SessionState)del.getState();
+// //ConnectionState cState = (ConnectionState)state.getParent();
+//
+// Object xid = del.getCurrentTxId();
+// assertNotNull(xid);
+// assertNotNull(del.getConnection().getResourceManager().getTx(xid));
+//
+// //Now close the session
+// sess.close();
+//
+// //Session should be removed from resource manager
+// xid = del.getCurrentTxId();
+// assertNotNull(xid);
+// assertNull(del.getConnection().getResourceManager().getTx(xid));
+//
+// conn.close();
+//
+// assertEquals(0, del.getConnection().getResourceManager().size());
+// }
public void testCreateProducer() throws Exception
{
@@ -497,13 +494,7 @@
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
-
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ResourceManagerFactory.instance.clear();
- }
+
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/TransactedSessionTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -29,8 +29,6 @@
import javax.jms.TextMessage;
import javax.management.ObjectName;
-import org.jboss.jms.tx.ResourceManagerFactory;
-
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
*
@@ -513,18 +511,22 @@
assertFalse(tm.getJMSRedelivered());
assertEquals(1, tm.getIntProperty("JMSXDeliveryCount"));
+ log.info("rolling back");
sess.rollback();
+
+ log.info("closing");
sess.close();
+ log.info("Closed");
Session sess2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
cons = sess2.createConsumer(queue1);
- tm = (TextMessage)cons.receive();
+ tm = (TextMessage)cons.receive(1000);
assertEquals("a message", tm.getText());
- assertEquals(2, tm.getIntProperty("JMSXDeliveryCount"));
+ assertEquals(3, tm.getIntProperty("JMSXDeliveryCount"));
assertTrue(tm.getJMSRedelivered());
}
@@ -761,10 +763,14 @@
assertEquals(NUM_MESSAGES, count);
conn.stop();
+ log.info("closing consumer");
consumer.close();
-
+ log.info("closed consumer");
+
+ log.info("closing connection");
conn.close();
-
+ log.info("closed connection");
+
conn = cf.createConnection();
consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
@@ -772,12 +778,17 @@
conn.start();
count = 0;
+
+ log.info("Receiving...");
+
while (true)
{
Message m = consumer.receive(500);
if (m == null) break;
count++;
}
+
+ log.info("Done receive");
assertEquals(NUM_MESSAGES, count);
}
@@ -812,7 +823,7 @@
Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = producerSess.createProducer(queue1);
- Session consumerSess = conn.createSession(true, Session.CLIENT_ACKNOWLEDGE);
+ Session consumerSess = conn.createSession(true, Session.SESSION_TRANSACTED);
MessageConsumer consumer = consumerSess.createConsumer(queue1);
conn.start();
@@ -835,7 +846,9 @@
assertEquals(NUM_MESSAGES, count);
+ log.info("Comitting sesion");
consumerSess.commit();
+ log.info("Committed session");
conn.stop();
consumer.close();
@@ -1084,14 +1097,6 @@
// Protected -----------------------------------------------------
- protected void setUp() throws Exception
- {
- super.setUp();
-
- ResourceManagerFactory.instance.clear();
- }
-
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XARecoveryTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -33,7 +33,6 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.messaging.core.tx.MessagingXid;
import com.arjuna.ats.arjuna.common.Uid;
@@ -67,22 +66,6 @@
// TestCase overrides -------------------------------------------
-
- protected void setUp() throws Exception
- {
- // if this is not set testMockCoordinatorRecoveryWithJBossTSXids will create an invalid ObjectStore
- //ServiceContainer.setupObjectStoreDir();
- super.setUp();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
-
- ResourceManagerFactory.instance.clear();
- }
-
-
// Public --------------------------------------------------------
/*
Modified: trunk/tests/src/org/jboss/test/messaging/jms/XAResourceRecoveryTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XAResourceRecoveryTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XAResourceRecoveryTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -27,7 +27,6 @@
import javax.transaction.TransactionManager;
import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.test.messaging.JBMServerTestCase;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.test.messaging.tools.container.ServiceContainer;
@@ -72,11 +71,6 @@
{
super.setUp();
- // Now start another remote server
- //ServerManagement.start(1, "all", false);
-
- ResourceManagerFactory.instance.clear();
-
// We need a local transaction and recovery manager
// We must start this after the remote servers have been created or it
// won't
@@ -157,12 +151,6 @@
tm.resume(suspendedTx);
}
- // We explicitly clear the resource manager factory since the recovery
- // manager will keep a connection open, and
- // otherewise it will fail
-
- ResourceManagerFactory.instance.clear();
-
super.tearDown();
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/XATest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/XATest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/XATest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -1,3373 +1,3266 @@
-/*
- * 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 com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
-import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.jms.client.JBossSession;
-import org.jboss.jms.client.api.ClientConnection;
-import org.jboss.jms.client.api.ClientSession;
-import org.jboss.jms.tx.LocalTx;
-import org.jboss.jms.tx.MessagingXAResource;
-import org.jboss.jms.tx.ResourceManager;
-import org.jboss.jms.tx.ResourceManagerFactory;
-import org.jboss.messaging.core.tx.MessagingXid;
-import org.jboss.messaging.util.Logger;
-import org.jboss.test.messaging.JBMServerTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.tm.TxUtils;
-
-import javax.jms.*;
-import javax.naming.InitialContext;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.xa.XAException;
-import javax.transaction.xa.XAResource;
-import javax.transaction.xa.Xid;
-import java.util.ArrayList;
-
-/**
- *
- * A XATestBase
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class XATest extends JBMServerTestCase
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- protected TransactionManager tm;
-
- protected Transaction suspendedTx;
-
- protected JBossConnectionFactory cf;
-
- // Constructors --------------------------------------------------
-
- public XATest(String name)
- {
- super(name);
- }
-
-
- // TestCase overrides -------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
- cf = getConnectionFactory();
- ResourceManagerFactory.instance.clear();
-
- //Also need a local tx mgr if test is running remote
- if (ServerManagement.isRemote())
- {
- tm = new TransactionManagerImple();
- }
- else
- {
- InitialContext localIc = getInitialContext();
-
- tm = getTransactionManager();
- }
-
-
- assertTrue(tm instanceof TransactionManagerImple);
-
- if (!ServerManagement.isRemote())
- {
- suspendedTx = tm.suspend();
- }
- }
-
- public void tearDown() throws Exception
- {
- if (TxUtils.isUncommitted(tm))
- {
- //roll it back
- try
- {
- tm.rollback();
- }
- catch (Throwable ignore)
- {
- //The connection will probably be closed so this may well throw an exception
- }
- }
- if (tm.getTransaction() != null)
- {
- Transaction tx = tm.suspend();
- if (tx != null)
- log.warn("Transaction still associated with thread " + tx + " at status " + TxUtils.getStatusAsString(tx.getStatus()));
- }
-
- if (suspendedTx != null)
- {
- tm.resume(suspendedTx);
- }
-
- super.tearDown();
- }
-
- // Public --------------------------------------------------------
-
- /* If there is no global tx present the send must behave as non transacted.
- * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
- * http://jira.jboss.com/jira/browse/JBMESSAGING-410
- * http://jira.jboss.com/jira/browse/JBMESSAGING-721
- * http://jira.jboss.org/jira/browse/JBMESSAGING-946
- */
- public void testSendNoGlobalTransaction() throws Exception
- {
- Transaction suspended = null;
-
- try
- {
- // make sure there's no active JTA transaction
-
- suspended = tm.suspend();
-
- // send a message to the queue using an XASession that's not enlisted in a global tx
-
- XAConnectionFactory xcf = (XAConnectionFactory)cf;
-
- XAConnection xconn = xcf.createXAConnection();
-
- XASession xs = xconn.createXASession();
-
- MessageProducer p = xs.createProducer(queue1);
- Message m = xs.createTextMessage("one");
-
- p.send(m);
-
- xconn.close();
-
- // receive the message
- Connection conn = cf.createConnection();
- conn.start();
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer c = s.createConsumer(queue1);
- TextMessage rm = (TextMessage)c.receive(1000);
-
- assertEquals("one", rm.getText());
-
- conn.close();
- }
- finally
- {
- if (suspended != null)
- {
- tm.resume(suspended);
- }
- }
- }
-
-
- /*
- * If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
- * falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
- *
- * There is one exception to this:
- *
- * For transactional delivery of messages in an MDB using the old container invoker (non JCA 1.5 inflow) the message
- * is received from the JMS provider *before* the MDB container has a chance to enlist the session in a transaction.
- * (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration" of Mark Little's book Java Transaction
- * processing for a discussion of how different app servers deal with this)
- * This is not a problem specific to JBoss and was solved with JCA 1.5 message inflow.
- * Consequently, if we detect the session has a distinguised session listener (which it will if using ASF) then the behaviour
- * is to fall back to being a local transacted session. Later on, when the session is enlisted the work done in the local tx
- * is converted to the global tx brach.
- *
- * We are testing the exceptional case here without a global tx here
- *
- * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
- * http://jira.jboss.com/jira/browse/JBMESSAGING-410
- * http://jira.jboss.com/jira/browse/JBMESSAGING-721
- * http://jira.jboss.org/jira/browse/JBMESSAGING-946
- *
- */
- public void testConsumeWithConnectionConsumerNoGlobalTransaction() throws Exception
- {
- // send a message to the queue
-
- Connection conn = cf.createConnection();
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue1);
- p.setDeliveryMode(DeliveryMode.PERSISTENT);
- Message m = s.createTextMessage("one");
- p.send(m);
- conn.close();
-
- // make sure there's no active JTA transaction
-
- Transaction suspended = tm.suspend();
-
- XAConnection xaconn = null;
- try
- {
- Integer count = getMessageCountForQueue("Queue1");
- assertEquals(1, count.intValue());
-
- // using XA with a ConnectionConsumer (testing the transaction behavior under MDBs)
-
- XAConnectionFactory xacf = (XAConnectionFactory)cf;
- xaconn = xacf.createXAConnection();
- xaconn.start();
- XASession xasession = xaconn.createXASession();
- DummyListener listener = new DummyListener();
- xasession.setMessageListener(listener);
-
- ServerSessionPool pool = new MockServerSessionPool(xasession);
-
- xaconn.createConnectionConsumer(queue1, null, pool, 1);
-
- Thread.sleep(1000);
- assertEquals(1, listener.messages.size());
-
- // Message should still be on server
- count = getMessageCountForQueue("Queue1");
- assertEquals(1, count.intValue());
-
- XAResource resource = xasession.getXAResource();
-
- // Starts a new transaction
- tm.begin();
-
- Transaction trans = tm.getTransaction();
-
- ClientSession clientSession = ((JBossSession)xasession).getDelegate();
-
- // Validates TX convertion
- assertTrue(clientSession.getCurrentTxId() instanceof LocalTx);
-
- // Enlist the transaction... as supposed to be happening on JBossAS with the
- // default listener (enlist happening after message is received)
- trans.enlistResource(resource);
-
- // Validates TX convertion
- assertFalse(clientSession.getCurrentTxId() instanceof LocalTx);
-
- trans.delistResource(resource, XAResource.TMSUCCESS);
-
- trans.commit();
-
- // After commit the message should be consumed
- count = getMessageCountForQueue("Queue1");
- assertEquals(0, count.intValue());
- }
- finally
- {
- if (xaconn != null)
- {
- xaconn.close();
- }
- if (suspended != null)
- {
- tm.resume(suspended);
- }
- }
- }
-
-
- /*
- * If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
- * falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
- *
- * There is one exception to this:
- *
- * For transactional delivery of messages in an MDB using the old container invoker (non JCA 1.5 inflow) the message
- * is received from the JMS provider *before* the MDB container has a chance to enlist the session in a transaction.
- * (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration" of Mark Little's book Java Transaction
- * processing for a discussion of how different app servers deal with this)
- * This is not a problem specific to JBoss and was solved with JCA 1.5 message inflow.
- * Consequently, if we detect the session has a distinguised session listener (which it will if using ASF) then the behaviour
- * is to fall back to being a local transacted session. Later on, when the session is enlisted the work done in the local tx
- * is converted to the global tx brach.
- *
- * We are testing the standard case without a global tx here
- *
- * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
- * http://jira.jboss.com/jira/browse/JBMESSAGING-410
- * http://jira.jboss.com/jira/browse/JBMESSAGING-721
- * http://jira.jboss.org/jira/browse/JBMESSAGING-946
- *
- */
- public void testConsumeWithoutConnectionConsumerNoGlobalTransaction() throws Exception
- {
- // send a message to the queue
-
- Connection conn = cf.createConnection();
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue1);
- p.setDeliveryMode(DeliveryMode.PERSISTENT);
- Message m = s.createTextMessage("one");
- p.send(m);
- conn.close();
-
- // make sure there's no active JTA transaction
-
- Transaction suspended = tm.suspend();
-
- try
- {
- Integer count = getMessageCountForQueue("Queue1");
- assertEquals(1, count.intValue());
-
- XAConnectionFactory xcf = (XAConnectionFactory)cf;
- XAConnection xconn = xcf.createXAConnection();
- xconn.start();
-
- // no active JTA transaction here
-
- XASession xs = xconn.createXASession();
-
- MessageConsumer c = xs.createConsumer(queue1);
-
- // the message should be store unacked in the local session
- TextMessage rm = (TextMessage)c.receive(1000);
-
- assertEquals("one", rm.getText());
-
- // messages should be acked
- count = getMessageCountForQueue("Queue1");
- assertEquals(0, count.intValue());
-
- xconn.close();
- }
- finally
- {
-
- if (suspended != null)
- {
- tm.resume(suspended);
- }
- }
- }
-
-
- /*
- * If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
- * falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
- *
- * There is one exception to this:
- *
- * For transactional delivery of messages in an MDB using the old container invoker (non JCA 1.5 inflow) the message
- * is received from the JMS provider *before* the MDB container has a chance to enlist the session in a transaction.
- * (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration" of Mark Little's book Java Transaction
- * processing for a discussion of how different app servers deal with this)
- * This is not a problem specific to JBoss and was solved with JCA 1.5 message inflow.
- * Consequently, if we detect the session has a distinguised session listener (which it will if using ASF) then the behaviour
- * is to fall back to being a local transacted session. Later on, when the session is enlisted the work done in the local tx
- * is converted to the global tx brach.
- *
- * We are testing the case with a global tx here
- *
- * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
- * http://jira.jboss.com/jira/browse/JBMESSAGING-410
- * http://jira.jboss.com/jira/browse/JBMESSAGING-721
- * http://jira.jboss.org/jira/browse/JBMESSAGING-946
- *
- */
- public void testConsumeGlobalTransaction() throws Exception
- {
- XAConnection xaconn = null;
-
- try
- {
- // send a message to the queue
-
- Connection conn = cf.createConnection();
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue1);
- p.setDeliveryMode(DeliveryMode.PERSISTENT);
- Message m = s.createTextMessage("one");
- p.send(m);
- conn.close();
-
- Integer count = getMessageCountForQueue("Queue1");
- assertEquals(1, count.intValue());
-
- tm.begin();
-
- Transaction trans = tm.getTransaction();
-
- XAConnectionFactory xacf = (XAConnectionFactory)cf;
-
- xaconn = xacf.createXAConnection();
-
- xaconn.start();
-
- XASession xasession = xaconn.createXASession();
-
- XAResource resouce = xasession.getXAResource();
-
- trans.enlistResource(resouce);
-
- MessageConsumer consumer = xasession.createConsumer(queue1);
-
- TextMessage messageReceived = (TextMessage)consumer.receive(1000);
-
- assertNotNull(messageReceived);
-
- assertEquals("one", messageReceived.getText());
-
- assertNull(consumer.receive(1000));
-
- count = getMessageCountForQueue("Queue1");
-
- assertEquals(1, count.intValue());
-
- trans.delistResource(resouce, XAResource.TMSUCCESS);
-
- tm.rollback();
-
- tm.begin();
- trans = tm.getTransaction();
- trans.enlistResource(resouce);
-
- messageReceived = (TextMessage)consumer.receive(1000);
-
- assertNotNull(messageReceived);
-
- assertEquals("one", messageReceived.getText());
-
- count = getMessageCountForQueue("Queue1");
- assertEquals(1, count.intValue());
-
- trans.commit();
-
- count = getMessageCountForQueue("Queue1");
- assertEquals(0, count.intValue());
-
- }
- finally
- {
- if (xaconn != null)
- {
- xaconn.close();
- }
- }
- }
-
- /*
- * This test will:
- * - Send two messages over a producer
- * - Receive one message over a consumer created used a XASession
- * - Call Recover
- * - Receive the second message
- * - The queue should be empty after that
- * Verifies if messages are sent ok and ack properly when recovery is called
- * NOTE: To accomodate TCK tests where Session/Consumers are being used without transaction enlisting
- * we are processing those cases as nonTransactional/AutoACK, however if the session is being used
- * to process MDBs we will consider the LocalTransaction convertion and process those as the comment above
- * This was done as per: http://jira.jboss.org/jira/browse/JBMESSAGING-946
- *
- */
- public void testRecoverOnXA() throws Exception
- {
- XAConnection xaconn = null;
-
- try
- {
- // send a message to the queue
-
- Connection conn = cf.createConnection();
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer p = s.createProducer(queue1);
- p.setDeliveryMode(DeliveryMode.PERSISTENT);
- Message m = s.createTextMessage("one");
- p.send(m);
- m = s.createTextMessage("two");
- p.send(m);
- conn.close();
-
- Integer count = getMessageCountForQueue("Queue1");
- assertEquals(2, count.intValue());
-
- XAConnectionFactory xacf = (XAConnectionFactory)cf;
-
- xaconn = xacf.createXAConnection();
-
- xaconn.start();
-
- XASession xasession = xaconn.createXASession();
-
- MessageConsumer consumer = xasession.createConsumer(queue1);
-
- TextMessage messageReceived = (TextMessage)consumer.receive(1000);
-
- assertNotNull(messageReceived);
-
- assertEquals("one", messageReceived.getText());
-
- xasession.recover();
-
- messageReceived = (TextMessage)consumer.receive(1000);
-
- assertEquals("two", messageReceived.getText());
-
- consumer.close();
-
- // I can't call xasession.close for this test as JCA layer would cache the session
- // So.. keep this close commented!
- //xasession.close();
-
- count = getMessageCountForQueue("Queue1");
- assertEquals(0, count.intValue());
- }
- finally
- {
- if (xaconn != null)
- {
- xaconn.close();
- }
- }
- }
-
- //See http://jira.jboss.com/jira/browse/JBMESSAGING-638
- public void testResourceManagerMemoryLeakOnCommit() throws Exception
- {
- XAConnection xaConn = null;
-
- try
- {
- xaConn = cf.createXAConnection();
-
- JBossConnection jbConn = (JBossConnection)xaConn;
-
- ClientConnection del = ((JBossConnection)jbConn).getDelegate();
-
- ResourceManager rm = del.getResourceManager();
-
- XASession xaSession = xaConn.createXASession();
-
- xaConn.start();
-
- XAResource res = xaSession.getXAResource();
-
- XAResource dummy = new DummyXAResource();
-
- for (int i = 0; i < 100; i++)
- {
- tm.begin();
-
- Transaction tx = tm.getTransaction();
-
- tx.enlistResource(res);
-
- tx.enlistResource(dummy);
-
- assertEquals(1, rm.size());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- tx.delistResource(dummy, XAResource.TMSUCCESS);
-
- tm.commit();
- }
-
- assertEquals(1, rm.size());
-
- xaConn.close();
-
- xaConn = null;
-
- assertEquals(0, rm.size());
-
- }
- finally
- {
- if (xaConn != null)
- {
- xaConn.close();
- }
- }
- }
-
- //See http://jira.jboss.com/jira/browse/JBMESSAGING-638
- public void testResourceManagerMemoryLeakOnRollback() throws Exception
- {
- XAConnection xaConn = null;
-
- try
- {
- xaConn = cf.createXAConnection();
-
- JBossConnection jbConn = (JBossConnection)xaConn;
-
- ClientConnection del = ((JBossConnection)xaConn).getDelegate();
-
- ResourceManager rm = del.getResourceManager();
-
- XASession xaSession = xaConn.createXASession();
-
- xaConn.start();
-
- XAResource res = xaSession.getXAResource();
-
- XAResource dummy = new DummyXAResource();
-
- for (int i = 0; i < 100; i++)
- {
- tm.begin();
-
- Transaction tx = tm.getTransaction();
-
- tx.enlistResource(res);
-
- tx.enlistResource(dummy);
-
- assertEquals(1, rm.size());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- tx.delistResource(dummy, XAResource.TMSUCCESS);
-
- tm.rollback();
- }
-
- assertEquals(1, rm.size());
-
- xaConn.close();
-
- xaConn = null;
-
- assertEquals(0, rm.size());
-
- }
- finally
- {
- if (xaConn != null)
- {
- xaConn.close();
- }
- }
- }
-
- // http://jira.jboss.com/jira/browse/JBMESSAGING-721
- public void testConvertFromLocalTx() throws Exception
- {
- Connection conn = null;
-
- XAConnection xaConn = null;
-
- try
- {
-
- //First send some messages to a queue
-
- Integer count = getMessageCountForQueue("Queue1");
- assertEquals(0, count.intValue());
-
- conn = cf.createConnection();
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSend.createProducer(queue1);
-
- TextMessage tm1 = sessSend.createTextMessage("message1");
-
- TextMessage tm2 = sessSend.createTextMessage("message2");
-
- prod.send(tm1);
-
- prod.send(tm2);
-
- count = getMessageCountForQueue("Queue1");
- assertEquals(2, count.intValue());
-
- xaConn = cf.createXAConnection();
-
- XASession xaSession = xaConn.createXASession();
-
- xaConn.start();
-
- DummyListener listener = new DummyListener();
-
- //We set the distinguised listener so it will convert
- xaSession.setMessageListener(listener);
-
- ServerSessionPool pool = new MockServerSessionPool(xaSession);
-
- xaConn.createConnectionConsumer(queue1, null, pool, 1);
-
- Thread.sleep(1000);
-
- assertEquals(2, listener.messages.size());
-
- assertEquals("message1", ((TextMessage)(listener.messages.get(0))).getText());
- assertEquals("message2", ((TextMessage)(listener.messages.get(1))).getText());
-
- count = getMessageCountForQueue("Queue1");
- assertEquals(2, count.intValue());
-
- listener.messages.clear();
-
- //Now we enlist the session in an xa transaction
-
- XAResource res = xaSession.getXAResource();
-
- tm.begin();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
-
- //This should cause the work done previously to be converted into work done in the xa transaction
- //this is what an MDB does
- //There is a difficulty in transactional delivery with an MDB.
- //The message is received from the destination and then sent to the mdb container so
- //it can call onMessage.
- //For transactional delivery the receipt of the message should be in a transaction but by the time
- //the mdb container is invoked the message has already been received it is too late - the message
- //has already been received and passed on (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration"
- //of Mark Little's book Java Transaction processing
- //for a discussion of how different app serves deal with this)
- //The way jboss messaging (and jboss mq) deals with this is to convert any work done
- //prior to when the xasession is enlisted in the tx, into work done in the xa tx
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- //Now rollback the tx - this should cause redelivery of the two messages
- tm.rollback();
-
- count = getMessageCountForQueue("Queue1");
- assertEquals(2, count.intValue());
-
- Thread.sleep(1000);
-
- assertEquals(2, listener.messages.size());
-
- listener.messages.clear();
-
- tm.begin();
-
- tx = tm.getTransaction();
- tx.enlistResource(res);
-
- tm.commit();
-
- Thread.sleep(1000);
-
- assertEquals(0, listener.messages.size());
-
- count = getMessageCountForQueue("Queue1");
- assertEquals(0, count.intValue());
-
- assertNull(tm.getTransaction());
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
-
- if (xaConn != null)
- {
- xaConn.close();
- }
-
- /* if (suspended != null)
- {
- tm.resume(suspended);
- }*/
- }
- }
-
- //http://jira.jboss.com/jira/browse/JBMESSAGING-721
- // Note: The behavior of this test was changed after http://jira.jboss.com/jira/browse/JBMESSAGING-946
- // When you have a XASession without a transaction enlisted we will behave the same way as non transactedSession, AutoAck
- public void testTransactionIdSetAfterCommit() throws Exception
- {
- Connection conn = null;
-
- XAConnection xaConn = null;
-
- try
- {
- //First send some messages to a queue
-
- conn = cf.createConnection();
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSend.createProducer(queue1);
-
- TextMessage tm1 = sessSend.createTextMessage("message1");
-
- TextMessage tm2 = sessSend.createTextMessage("message2");
-
- prod.send(tm1);
-
- prod.send(tm2);
-
-
- xaConn = cf.createXAConnection();
-
- XASession xaSession = xaConn.createXASession();
-
- xaConn.start();
-
- MessageConsumer cons = xaSession.createConsumer(queue1);
-
- //Now we enlist the session in an xa transaction
-
- XAResource res = xaSession.getXAResource();
-
- tm.begin();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- //Then we do a commit
- tm.commit();
-
- // I have changed where this begin was originally set
- // as when you don't have a resource enlisted, XASessions will act as
- // non transacted + AutoAck
-
- //And enlist again - this should convert the work done in the local tx
- //into the global branch
-
- tx = tm.getTransaction();
-
- tm.begin();
-
- tx = tm.getTransaction();
- tx.enlistResource(res);
-
- //Then we receive the messages outside the tx
-
- TextMessage rm1 = (TextMessage)cons.receive(1000);
-
- assertNotNull(rm1);
-
- assertEquals("message1", rm1.getText());
-
- TextMessage rm2 = (TextMessage)cons.receive(1000);
-
- assertNotNull(rm2);
-
- assertEquals("message2", rm2.getText());
-
- Message rm3 = cons.receive(1000);
-
- assertNull(rm3);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- //Now rollback the tx - this should cause redelivery of the two messages
- tx.rollback();
-
- rm1 = (TextMessage)cons.receive(1000);
-
- assertNotNull(rm1);
-
- assertEquals("message1", rm1.getText());
-
- rm2 = (TextMessage)cons.receive(1000);
-
- assertNotNull(rm2);
-
- assertEquals("message2", rm2.getText());
-
- rm3 = cons.receive(1000);
-
- assertNull(rm3);
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
-
- if (xaConn != null)
- {
- xaConn.close();
- }
- }
-
- }
-
- //http://jira.jboss.com/jira/browse/JBMESSAGING-721
- public void testTransactionIdSetAfterRollback() throws Exception
- {
- Connection conn = null;
-
- XAConnection xaConn = null;
-
- try
- {
- //First send some messages to a queue
-
- conn = cf.createConnection();
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageProducer prod = sessSend.createProducer(queue1);
-
- TextMessage tm1 = sessSend.createTextMessage("message1");
-
- TextMessage tm2 = sessSend.createTextMessage("message2");
-
- prod.send(tm1);
-
- prod.send(tm2);
-
- xaConn = cf.createXAConnection();
-
- XASession xaSession = xaConn.createXASession();
-
- xaConn.start();
-
- MessageConsumer cons = xaSession.createConsumer(queue1);
-
- //Now we enlist the session in an xa transaction
-
- XAResource res = xaSession.getXAResource();
-
- tm.begin();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- //Then we do a rollback
- tm.rollback();
-
- tm.begin();
-
- //And enlist again - the work should then be converted into the global tx branch
-
- // I have changed where this begin was originally set
- // as when you don't have a resource enlisted, XASessions will act as
- // non transacted + AutoAck
-
- tx = tm.getTransaction();
-
- tx.enlistResource(res);
-
- //Then we receive the messages outside the global tx
-
- TextMessage rm1 = (TextMessage)cons.receive(1000);
-
- assertNotNull(rm1);
-
- assertEquals("message1", rm1.getText());
-
- TextMessage rm2 = (TextMessage)cons.receive(1000);
-
- assertNotNull(rm2);
-
- assertEquals("message2", rm2.getText());
-
- Message rm3 = cons.receive(1000);
-
- assertNull(rm3);
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- //Now rollback the tx - this should cause redelivery of the two messages
- tx.rollback();
-
- rm1 = (TextMessage)cons.receive(1000);
-
- assertNotNull(rm1);
-
- assertEquals("message1", rm1.getText());
-
- rm2 = (TextMessage)cons.receive(1000);
-
- assertNotNull(rm2);
-
- assertEquals("message2", rm2.getText());
-
- rm3 = cons.receive(1000);
-
- assertNull(rm3);
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
-
- if (xaConn != null)
- {
- xaConn.close();
- }
- }
- }
-
- // See http://jira.jboss.org/jira/browse/JBMESSAGING-825
- // Need to test that ids with trailing zeros are dealt with properly - sybase has the habit
- // of truncating trailing zeros in varbinary columns
- public void testXidsWithTrailingZeros() throws Exception
- {
- if (!ServerManagement.isRemote())
- {
- return;
- }
-
- XAConnection conn1 = null;
-
- try
- {
- conn1 = cf.createXAConnection();
-
- XASession sess1 = conn1.createXASession();
-
- XAResource res1 = sess1.getXAResource();
-
- byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
-
- byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
-
- Xid trailing = new MessagingXid(branchQualifier, 12435, globalTxId);
-
- res1.start(trailing, XAResource.TMNOFLAGS);
-
- MessageProducer prod1 = sess1.createProducer(queue1);
-
- TextMessage tm1 = sess1.createTextMessage("testing1");
-
- prod1.send(tm1);
-
- res1.end(trailing, XAResource.TMSUCCESS);
-
- res1.prepare(trailing);
-
- //Now "crash" the server
-
- stopServerPeer();
-
- startServerPeer();
-
- deployAndLookupAdministeredObjects();
-
- conn1.close();
-
- conn1 = cf.createXAConnection();
-
- XAResource res = conn1.createXASession().getXAResource();
-
- Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
- assertEquals(1, xids.length);
-
- Xid[] xids2 = res.recover(XAResource.TMENDRSCAN);
- assertEquals(0, xids2.length);
-
- Xid trailing2 = xids[0];
-
- assertTrue(trailing.getFormatId() == trailing2.getFormatId());
-
- assertEqualByteArrays(trailing.getGlobalTransactionId(), trailing2.getGlobalTransactionId());
-
- assertEqualByteArrays(trailing.getBranchQualifier(), trailing2.getBranchQualifier());
-
- res.commit(trailing, false);
- }
- finally
- {
- removeAllMessages(queue1.getQueueName(), true, 0);
-
- if (conn1 != null)
- {
- try
- {
- conn1.close();
- }
- catch (Exception e)
- {
- //Ignore
- }
- }
- }
- }
-
- public void test2PCSendCommit1PCOptimization() throws Exception
- {
- //Since both resources have same RM, TM will probably use 1PC optimization
-
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- conn = cf.createXAConnection();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- XAResource res = sess.getXAResource();
-
- XAResource res2 = new DummyXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- MessageProducer prod = sess.createProducer(queue1);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- Message m = sess.createTextMessage("XATest1");
- prod.send(queue1, m);
- m = sess.createTextMessage("XATest2");
- prod.send(queue1, m);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.commit();
-
- conn2 = cf.createConnection();
- conn2.start();
- Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue1);
- TextMessage m2 = (TextMessage)cons.receive(1000);
- assertNotNull(m2);
- assertEquals("XATest1", m2.getText());
- m2 = (TextMessage)cons.receive(1000);
- assertNotNull(m2);
- assertEquals("XATest2", m2.getText());
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
-
-
- public void test2PCSendCommit() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- conn = cf.createXAConnection();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
-
- MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
- XAResource res2 = new DummyXAResource();
-
- //To prevent 1PC optimization being used
- res.setPreventJoining(true);
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- MessageProducer prod = sess.createProducer(queue1);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- Message m = sess.createTextMessage("XATest1");
- prod.send(queue1, m);
- m = sess.createTextMessage("XATest2");
- prod.send(queue1, m);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- log.info("Committing***");
- tm.commit();
- log.info("Committed****");
-
- conn2 = cf.createConnection();
- conn2.start();
- Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue1);
- TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m2);
- assertEquals("XATest1", m2.getText());
- m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m2);
- assertEquals("XATest2", m2.getText());
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
-
- public void test2PCSendRollback1PCOptimization() throws Exception
- {
- //Since both resources have some RM, TM will probably use 1PC optimization
-
- XAConnection conn = null;
- Connection conn2 = null;
- try
- {
- conn = cf.createXAConnection();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- XAResource res = sess.getXAResource();
-
- XAResource res2 = new DummyXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- MessageProducer prod = sess.createProducer(queue1);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- Message m = sess.createTextMessage("XATest1");
- prod.send(queue1, m);
- m = sess.createTextMessage("XATest2");
- prod.send(queue1, m);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.rollback();
-
- conn2 = cf.createConnection();
- conn2.start();
- Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue1);
- Message m2 = cons.receive(MIN_TIMEOUT);
- assertNull(m2);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
-
- public void test2PCSendFailOnPrepare() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
- try
- {
- conn = cf.createXAConnection();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
-
- //prevent 1Pc optimisation
- res.setPreventJoining(true);
-
- XAResource res2 = new DummyXAResource(true);
- XAResource res3 = new DummyXAResource();
- XAResource res4 = new DummyXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
- tx.enlistResource(res3);
- tx.enlistResource(res4);
-
- MessageProducer prod = sess.createProducer(queue1);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- Message m = sess.createTextMessage("XATest1");
- prod.send(queue1, m);
- m = sess.createTextMessage("XATest2");
- prod.send(queue1, m);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
- tx.delistResource(res3, XAResource.TMSUCCESS);
- tx.delistResource(res4, XAResource.TMSUCCESS);
-
- try
- {
- tm.commit();
-
- fail("should not get here");
- }
- catch (Exception e)
- {
- //We should expect this
- }
-
- conn2 = cf.createConnection();
- conn2.start();
- Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue1);
- Message m2 = cons.receive(MIN_TIMEOUT);
- assertNull(m2);
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
- public void test2PCSendRollback() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
- try
- {
- conn = cf.createXAConnection();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
-
- //prevent 1Pc optimisation
- res.setPreventJoining(true);
-
- XAResource res2 = new DummyXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- MessageProducer prod = sess.createProducer(queue1);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- Message m = sess.createTextMessage("XATest1");
- prod.send(queue1, m);
- m = sess.createTextMessage("XATest2");
- prod.send(queue1, m);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.rollback();
-
- conn2 = cf.createConnection();
- conn2.start();
- Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue1);
- Message m2 = cons.receive(MIN_TIMEOUT);
- assertNull(m2);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
- public void test2PCReceiveCommit1PCOptimization() throws Exception
- {
- //Since both resources have some RM, TM will probably use 1PC optimization
-
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- conn2 = cf.createConnection();
- conn2.start();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("XATest1");
- prod.send(m);
- m = sessProducer.createTextMessage("XATest2");
- prod.send(m);
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- XAResource res = sess.getXAResource();
-
- XAResource res2 = new DummyXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- MessageConsumer cons = sess.createConsumer(queue1);
-
-
- TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m2);
- assertEquals("XATest1", m2.getText());
-
- m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m2);
- assertEquals("XATest2", m2.getText());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.commit();
-
- //New tx
- tm.begin();
- tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- Message m3 = cons.receive(MIN_TIMEOUT);
-
- assertNull(m3);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.commit();
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
- public void test2PCReceiveCommit() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- conn2 = cf.createConnection();
- conn2.start();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("XATest1");
- prod.send(m);
- m = sessProducer.createTextMessage("XATest2");
- prod.send(m);
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
- res.setPreventJoining(true);
-
- XAResource res2 = new DummyXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- MessageConsumer cons = sess.createConsumer(queue1);
-
-
- TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m2);
- assertEquals("XATest1", m2.getText());
-
- m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m2);
- assertEquals("XATest2", m2.getText());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.commit();
-
- //New tx
- tm.begin();
- tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- Message m3 = cons.receive(MIN_TIMEOUT);
-
- assertNull(m3);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.commit();
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
- public void test2PCReceiveRollback1PCOptimization() throws Exception
- {
- //Since both resources have some RM, TM will probably use 1PC optimization
-
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("XATest1");
- prod.send(m);
-
- m = sessProducer.createTextMessage("XATest2");
- prod.send(m);
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- XAResource res = sess.getXAResource();
-
- XAResource res2 = new DummyXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- MessageConsumer cons = sess.createConsumer(queue1);
-
-
- TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m2);
- assertEquals("XATest1", m2.getText());
- m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m2);
- assertEquals("XATest2", m2.getText());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.rollback();
-
- //Message should be redelivered
-
- //New tx
- tm.begin();
- tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m3);
- assertEquals("XATest1", m3.getText());
- m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m3);
- assertEquals("XATest2", m3.getText());
-
- assertTrue(m3.getJMSRedelivered());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.commit();
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
- public void test2PCReceiveRollback() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("XATest1");
- prod.send(m);
-
- m = sessProducer.createTextMessage("XATest2");
- prod.send(m);
-
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
- res.setPreventJoining(true);
-
- XAResource res2 = new DummyXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- MessageConsumer cons = sess.createConsumer(queue1);
-
-
- TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m2);
- assertEquals("XATest1", m2.getText());
- m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m2);
- assertEquals("XATest2", m2.getText());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.rollback();
-
- //Message should be redelivered
-
- //New tx
- tm.begin();
- tx = tm.getTransaction();
- tx.enlistResource(res);
- tx.enlistResource(res2);
-
- TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m3);
- assertEquals("XATest1", m3.getText());
- m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m3);
- assertEquals("XATest2", m3.getText());
-
- assertTrue(m3.getJMSRedelivered());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.commit();
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
-
- public void test1PCSendCommit() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- conn = cf.createXAConnection();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- XAResource res = sess.getXAResource();
-
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
-
-
- MessageProducer prod = sess.createProducer(queue1);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- Message m = sess.createTextMessage("XATest1");
- prod.send(queue1, m);
- m = sess.createTextMessage("XATest2");
- prod.send(queue1, m);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- tm.commit();
-
- conn2 = cf.createConnection();
- conn2.start();
- Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue1);
- TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m2);
- assertEquals("XATest1", m2.getText());
- m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(m2);
- assertEquals("XATest2", m2.getText());
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
-
- public void test1PCSendRollback() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
- try
- {
- conn = cf.createXAConnection();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- XAResource res = sess.getXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
-
- MessageProducer prod = sess.createProducer(queue1);
- prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- Message m = sess.createTextMessage("XATest1");
- prod.send(queue1, m);
- m = sess.createTextMessage("XATest2");
- prod.send(queue1, m);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- tm.rollback();
-
- conn2 = cf.createConnection();
- conn2.start();
- Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sessReceiver.createConsumer(queue1);
- Message m2 = cons.receive(MIN_TIMEOUT);
- assertNull(m2);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
- public void test1PCReceiveCommit() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- conn2 = cf.createConnection();
- conn2.start();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("XATest1");
- prod.send(m);
- m = sessProducer.createTextMessage("XATest2");
- prod.send(m);
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- XAResource res = sess.getXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
-
- MessageConsumer cons = sess.createConsumer(queue1);
-
-
- TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m2);
- assertEquals("XATest1", m2.getText());
- m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m2);
- assertEquals("XATest2", m2.getText());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- tm.commit();
-
- //New tx
- tm.begin();
- tx = tm.getTransaction();
- tx.enlistResource(res);
-
- Message m3 = cons.receive(MIN_TIMEOUT);
-
- assertNull(m3);
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- tm.commit();
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
- public void test1PCReceiveRollback() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("XATest1");
- prod.send(m);
- m = sessProducer.createTextMessage("XATest2");
- prod.send(m);
-
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- XASession sess = conn.createXASession();
- XAResource res = sess.getXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res);
-
- MessageConsumer cons = sess.createConsumer(queue1);
-
-
- TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m2);
- assertEquals("XATest1", m2.getText());
-
- m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m2);
- assertEquals("XATest2", m2.getText());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- tm.rollback();
-
- //Message should be redelivered
-
- //New tx
- tm.begin();
- tx = tm.getTransaction();
- tx.enlistResource(res);
-
- TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m3);
- assertEquals("XATest1", m3.getText());
-
- m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(m3);
- assertEquals("XATest2", m3.getText());
-
- assertTrue(m3.getJMSRedelivered());
-
- tx.delistResource(res, XAResource.TMSUCCESS);
-
- tm.commit();
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
- public void testMultipleSessionsOneTxCommitAcknowledge1PCOptimization() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- //Since both resources have some RM, TM will probably use 1PC optimization
-
- try
- {
- //First send 2 messages
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("jellyfish1");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish2");
- prod.send(m);
-
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- //Create 2 sessions and enlist them
- XASession sess1 = conn.createXASession();
- XAResource res1 = sess1.getXAResource();
- XASession sess2 = conn.createXASession();
- XAResource res2 = sess2.getXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res1);
- tx.enlistResource(res2);
-
- //Receive the messages, one on each consumer
- MessageConsumer cons1 = sess1.createConsumer(queue1);
- TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish1", r1.getText());
-
- cons1.close();
-
- MessageConsumer cons2 = sess2.createConsumer(queue1);
- TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-
- assertNotNull(r2);
- assertEquals("jellyfish2", r2.getText());
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- //commit
- tm.commit();
-
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue1);
- conn2.start();
-
- TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
- assertNull(r3);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
- public void testMultipleSessionsOneTxCommitAcknowledge() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- //First send 2 messages
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("jellyfish1");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish2");
- prod.send(m);
-
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- //Create 2 sessions and enlist them
- XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
- XASession sess2 = conn.createXASession();
- MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
- res1.setPreventJoining(true);
- res2.setPreventJoining(true);
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res1);
- tx.enlistResource(res2);
-
- //Receive the messages, one on each consumer
- MessageConsumer cons1 = sess1.createConsumer(queue1);
- TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish1", r1.getText());
-
- cons1.close();
-
- MessageConsumer cons2 = sess2.createConsumer(queue1);
- TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-
- assertNotNull(r2);
- assertEquals("jellyfish2", r2.getText());
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- //commit
- tm.commit();
-
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue1);
- conn2.start();
-
- TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
- assertNull(r3);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
-
- public void testMultipleSessionsOneTxRollbackAcknowledge1PCOptimization() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- //Since both resources have some RM, TM will probably use 1PC optimization
-
- try
- {
- //First send 2 messages
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("jellyfish1");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish2");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish3");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish4");
- prod.send(m);
-
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- //Create 2 sessions and enlist them
- XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
- XASession sess2 = conn.createXASession();
- MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res1);
- tx.enlistResource(res2);
-
- //Receive the messages, two on each consumer
- MessageConsumer cons1 = sess1.createConsumer(queue1);
- TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish1", r1.getText());
-
- r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish2", r1.getText());
-
- cons1.close();
-
- MessageConsumer cons2 = sess2.createConsumer(queue1);
- TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-
- assertNotNull(r2);
- assertEquals("jellyfish3", r2.getText());
-
- r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-
- assertNotNull(r2);
- assertEquals("jellyfish4", r2.getText());
-
- cons2.close();
-
- //rollback
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.rollback();
-
- //Rollback causes cancel which is asynch
- Thread.sleep(1000);
-
- //We cannot assume anything about the order in which the transaction manager rollsback
- //the sessions - this is implementation dependent
-
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue1);
- conn2.start();
-
- TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r);
-
- boolean session1First = false;
-
- if (r.getText().equals("jellyfish1"))
- {
- session1First = true;
- }
- else if (r.getText().equals("jellyfish3"))
- {
- session1First = false;
- }
- else
- {
- fail("Unexpected message");
- }
-
- if (session1First)
- {
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish2", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish3", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish4", r.getText());
-
-
- }
- else
- {
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish4", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish1", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish2", r.getText());
- }
-
- r = (TextMessage)cons.receive(MIN_TIMEOUT);
-
- assertNull(r);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
- public void testMultipleSessionsOneTxRollbackAcknowledge() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- //First send 2 messages
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("jellyfish1");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish2");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish3");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish4");
- prod.send(m);
-
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- //Create 2 sessions and enlist them
- XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
- XASession sess2 = conn.createXASession();
- MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
- res1.setPreventJoining(true);
- res2.setPreventJoining(true);
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res1);
- tx.enlistResource(res2);
-
- //Receive the messages, two on each consumer
- MessageConsumer cons1 = sess1.createConsumer(queue1);
- TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish1", r1.getText());
-
- r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish2", r1.getText());
-
- cons1.close();
-
- //Cancel is asynch
- Thread.sleep(500);
-
- MessageConsumer cons2 = sess2.createConsumer(queue1);
- TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-
- assertNotNull(r2);
- assertEquals("jellyfish3", r2.getText());
-
- r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
-
- assertNotNull(r2);
- assertEquals("jellyfish4", r2.getText());
-
- //rollback
-
- cons2.close();
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- tm.rollback();
-
- // Rollback causes cancel which is asynch
- Thread.sleep(1000);
-
- //We cannot assume anything about the order in which the transaction manager rollsback
- //the sessions - this is implementation dependent
-
-
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue1);
- conn2.start();
-
- TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r);
-
- boolean session1First = false;
-
- if (r.getText().equals("jellyfish1"))
- {
- session1First = true;
- }
- else if (r.getText().equals("jellyfish3"))
- {
- session1First = false;
- }
- else
- {
- fail("Unexpected message");
- }
-
- if (session1First)
- {
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish2", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish3", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish4", r.getText());
-
-
- }
- else
- {
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish4", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish1", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish2", r.getText());
- }
-
- r = (TextMessage)cons.receive(MIN_TIMEOUT);
-
- assertNull(r);
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
- public void testMultipleSessionsOneTxRollbackAcknowledgeForceFailureInCommit() throws Exception
- {
- XAConnection conn = null;
- Connection conn2 = null;
-
- try
- {
- //First send 4 messages
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
-
- Message m = sessProducer.createTextMessage("jellyfish1");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish2");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish3");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish4");
- prod.send(m);
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
- DummyXAResource res2 = new DummyXAResource(true);
- res1.setPreventJoining(true);
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res1);
- tx.enlistResource(res2);
-
- MessageConsumer cons1 = sess1.createConsumer(queue1);
- TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish1", r1.getText());
-
- r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish2", r1.getText());
-
- r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish3", r1.getText());
-
- r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
-
- assertNotNull(r1);
- assertEquals("jellyfish4", r1.getText());
-
- r1 = (TextMessage)cons1.receive(1000);
-
- assertNull(r1);
-
- cons1.close();
-
-
- //try and commit - and we're going to make the dummyxaresource throw an exception on commit,
- //which should cause rollback to be called on the other resource
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- //rollback will cause an attemp to deliver messages locally to the original consumers.
- //the original consumer has closed, so it will cancelled to the server
- //the server cancel is asynch, so we need to sleep for a bit to make sure it completes
- log.trace("Forcing failure");
- try
- {
- tm.commit();
- fail("should not get here");
- }
- catch (Exception e)
- {
- //We should expect this
- }
-
- Thread.sleep(1000);
-
-
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue1);
- conn2.start();
-
- TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish1", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish2", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish3", r.getText());
-
- r = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r);
-
- assertEquals("jellyfish4", r.getText());
-
- r = (TextMessage)cons.receive(MIN_TIMEOUT);
-
- assertNull(r);
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
-
- }
-
- public void testMultipleSessionsOneTxCommitSend1PCOptimization() throws Exception
- {
- //Since both resources have some RM, TM will probably use 1PC optimization
-
- XAConnection conn = null;
-
- Connection conn2 = null;
-
- try
- {
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- //Create 2 sessions and enlist them
- XASession sess1 = conn.createXASession();
- XAResource res1 = sess1.getXAResource();
- XASession sess2 = conn.createXASession();
- XAResource res2 = sess2.getXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res1);
- tx.enlistResource(res2);
-
- // Send 2 messages - one from each session
-
- MessageProducer prod1 = sess1.createProducer(queue1);
- MessageProducer prod2 = sess2.createProducer(queue1);
-
- prod1.send(sess1.createTextMessage("echidna1"));
- prod2.send(sess2.createTextMessage("echidna2"));
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- //commit
- tm.commit();
-
- //Messages should be in queue
-
- conn2 = cf.createConnection();
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue1);
- conn2.start();
-
- TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r1);
- assertEquals("echidna1", r1.getText());
-
- TextMessage r2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r2);
- assertEquals("echidna2", r2.getText());
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
- public void testMultipleSessionsOneTxCommitSend() throws Exception
- {
- //Since both resources have some RM, TM will probably use 1PC optimization
-
- XAConnection conn = null;
-
- Connection conn2 = null;
-
- try
- {
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- //Create 2 sessions and enlist them
- XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
- XASession sess2 = conn.createXASession();
- MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
- res1.setPreventJoining(true);
- res2.setPreventJoining(true);
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res1);
- tx.enlistResource(res2);
-
- // Send 2 messages - one from each session
-
- MessageProducer prod1 = sess1.createProducer(queue1);
- MessageProducer prod2 = sess2.createProducer(queue1);
-
- prod1.send(sess1.createTextMessage("echidna1"));
- prod2.send(sess2.createTextMessage("echidna2"));
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- //commit
- tm.commit();
-
- //Messages should be in queue
-
- conn2 = cf.createConnection();
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue1);
- conn2.start();
-
- TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r1);
- assertEquals("echidna1", r1.getText());
-
- TextMessage r2 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r2);
- assertEquals("echidna2", r2.getText());
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
-
- }
-
- }
-
-
- public void testMultipleSessionsOneTxRollbackSend1PCOptimization() throws Exception
- {
- //Since both resources have some RM, TM will probably use 1PC optimization
-
- XAConnection conn = null;
-
- Connection conn2 = null;
-
- try
- {
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- //Create 2 sessions and enlist them
- XASession sess1 = conn.createXASession();
- XAResource res1 = sess1.getXAResource();
- XASession sess2 = conn.createXASession();
- XAResource res2 = sess2.getXAResource();
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res1);
- tx.enlistResource(res2);
-
- // Send 2 messages - one from each session
-
- MessageProducer prod1 = sess1.createProducer(queue1);
- MessageProducer prod2 = sess2.createProducer(queue1);
-
- prod1.send(sess1.createTextMessage("echidna1"));
- prod2.send(sess2.createTextMessage("echidna2"));
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- //rollback
- tm.rollback();
-
- //Messages should not be in queue
-
- conn2 = cf.createConnection();
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue1);
- conn2.start();
-
- TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
- assertNull(r1);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
- public void testMultipleSessionsOneTxRollbackSend() throws Exception
- {
- XAConnection conn = null;
-
- Connection conn2 = null;
-
- try
- {
-
- conn = cf.createXAConnection();
- conn.start();
-
- tm.begin();
-
- //Create 2 sessions and enlist them
- XASession sess1 = conn.createXASession();
- MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
- XASession sess2 = conn.createXASession();
- MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
- res1.setPreventJoining(true);
- res2.setPreventJoining(true);
-
- Transaction tx = tm.getTransaction();
- tx.enlistResource(res1);
- tx.enlistResource(res2);
-
- // Send 2 messages - one from each session
-
- MessageProducer prod1 = sess1.createProducer(queue1);
- MessageProducer prod2 = sess2.createProducer(queue1);
-
- prod1.send(sess1.createTextMessage("echidna1"));
- prod2.send(sess2.createTextMessage("echidna2"));
-
- tx.delistResource(res1, XAResource.TMSUCCESS);
- tx.delistResource(res2, XAResource.TMSUCCESS);
-
- //rollback
- tm.rollback();
-
- //Messages should not be in queue
-
- conn2 = cf.createConnection();
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageConsumer cons = sess.createConsumer(queue1);
- conn2.start();
-
- TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
- assertNull(r1);
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
-
- public void testOneSessionTwoTransactionsCommitAcknowledge() throws Exception
- {
- XAConnection conn = null;
-
- Connection conn2 = null;
-
- try
- {
- //First send 2 messages
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("jellyfish1");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish2");
- prod.send(m);
-
- conn = cf.createXAConnection();
-
- //Create a session
- XASession sess1 = conn.createXASession();
- XAResource res1 = sess1.getXAResource();
-
- conn.start();
- MessageConsumer cons1 = sess1.createConsumer(queue1);
-
- tm.begin();
-
- Transaction tx1 = tm.getTransaction();
- tx1.enlistResource(res1);
-
- //Receive one message in one tx
-
- TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
- assertNotNull(r1);
- assertEquals("jellyfish1", r1.getText());
-
- //suspend the tx
- Transaction suspended = tm.suspend();
-
- tm.begin();
-
- Transaction tx2 = tm.getTransaction();
- tx2.enlistResource(res1);
-
- //Receive 2nd message in a different tx
- TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
- assertNotNull(r2);
- assertEquals("jellyfish2", r2.getText());
-
- tx2.delistResource(res1, XAResource.TMSUCCESS);
-
- //commit this transaction
- tm.commit();
-
- //verify that no messages are available
- conn2.close();
- conn2 = cf.createConnection();
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn2.start();
- MessageConsumer cons = sess.createConsumer(queue1);
- TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
- assertNull(r3);
-
- //now resume the first tx and then commit it
- tm.resume(suspended);
-
- tx1.delistResource(res1, XAResource.TMSUCCESS);
-
- tm.commit();
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
- }
- }
-
-
- public void testOneSessionTwoTransactionsRollbackAcknowledge() throws Exception
- {
- XAConnection conn = null;
-
- Connection conn2 = null;
-
- try
- {
- //First send 2 messages
- conn2 = cf.createConnection();
- Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessProducer.createProducer(queue1);
- Message m = sessProducer.createTextMessage("jellyfish1");
- prod.send(m);
- m = sessProducer.createTextMessage("jellyfish2");
- prod.send(m);
-
- conn = cf.createXAConnection();
-
- //Create a session
- XASession sess1 = conn.createXASession();
- XAResource res1 = sess1.getXAResource();
-
- conn.start();
- MessageConsumer cons1 = sess1.createConsumer(queue1);
-
- tm.begin();
-
- Transaction tx1 = tm.getTransaction();
- tx1.enlistResource(res1);
-
- //Receive one message in one tx
-
- TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
- assertNotNull(r1);
- assertEquals("jellyfish1", r1.getText());
-
- //suspend the tx
- Transaction suspended = tm.suspend();
-
- tm.begin();
-
- Transaction tx2 = tm.getTransaction();
- tx2.enlistResource(res1);
-
- //Receive 2nd message in a different tx
- TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
- assertNotNull(r2);
- assertEquals("jellyfish2", r2.getText());
-
- cons1.close();
-
- tx1.delistResource(res1, XAResource.TMSUCCESS);
-
- //rollback this transaction
- tm.rollback();
-
- //verify that second message is available
- conn2.close();
- conn2 = cf.createConnection();
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn2.start();
- MessageConsumer cons = sess.createConsumer(queue1);
-
- TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
-
- assertNotNull(r3);
- assertEquals("jellyfish2", r3.getText());
- r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
- assertNull(r3);
-
-
- //rollback the other tx
- tm.resume(suspended);
- tm.rollback();
-
- //Verify the first message is now available
- r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r3);
- assertEquals("jellyfish1", r3.getText());
- r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
- assertNull(r3);
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
-
- }
-
- }
-
-
- public void testOneSessionTwoTransactionsCommitSend() throws Exception
- {
- XAConnection conn = null;
-
- Connection conn2 = null;
-
- try
- {
- conn = cf.createXAConnection();
-
- //Create a session
- XASession sess1 = conn.createXASession();
- XAResource res1 = sess1.getXAResource();
-
- MessageProducer prod1 = sess1.createProducer(queue1);
-
- tm.begin();
-
- Transaction tx1 = tm.getTransaction();
- tx1.enlistResource(res1);
-
- //Send a message
- prod1.send(sess1.createTextMessage("kangaroo1"));
-
- //suspend the tx
- Transaction suspended = tm.suspend();
-
- tm.begin();
-
- //Send another message in another tx using the same session
- Transaction tx2 = tm.getTransaction();
- tx2.enlistResource(res1);
-
- //Send a message
- prod1.send(sess1.createTextMessage("kangaroo2"));
-
- tx2.delistResource(res1, XAResource.TMSUCCESS);
-
- //commit this transaction
- tm.commit();
-
- //verify only kangaroo2 message is sent
- conn2 = cf.createConnection();
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn2.start();
- MessageConsumer cons = sess.createConsumer(queue1);
- TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r1);
- assertEquals("kangaroo2", r1.getText());
- TextMessage r2 = (TextMessage)cons.receive(MIN_TIMEOUT);
- assertNull(r2);
-
- //now resume the first tx and then commit it
- tm.resume(suspended);
-
- tx1.delistResource(res1, XAResource.TMSUCCESS);
-
- tm.commit();
-
- //verify that the first text message is received
- TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r3);
- assertEquals("kangaroo1", r3.getText());
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
-
- }
-
- }
-
-
- public void testOneSessionTwoTransactionsRollbackSend() throws Exception
- {
- XAConnection conn = null;
-
- Connection conn2 = null;
-
- try
- {
-
- conn = cf.createXAConnection();
-
- //Create a session
- XASession sess1 = conn.createXASession();
- XAResource res1 = sess1.getXAResource();
-
- MessageProducer prod1 = sess1.createProducer(queue1);
-
- tm.begin();
-
- Transaction tx1 = tm.getTransaction();
- tx1.enlistResource(res1);
-
- //Send a message
- prod1.send(sess1.createTextMessage("kangaroo1"));
-
- //suspend the tx
- Transaction suspended = tm.suspend();
-
- tm.begin();
-
- //Send another message in another tx using the same session
- Transaction tx2 = tm.getTransaction();
- tx2.enlistResource(res1);
-
- //Send a message
- prod1.send(sess1.createTextMessage("kangaroo2"));
-
- tx2.delistResource(res1, XAResource.TMSUCCESS);
-
- //rollback this transaction
- tm.rollback();
-
- //verify no messages are sent
- conn2 = cf.createConnection();
- Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn2.start();
- MessageConsumer cons = sess.createConsumer(queue1);
- TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
-
- assertNull(r1);
-
-
- //now resume the first tx and then commit it
- tm.resume(suspended);
-
- tx1.delistResource(res1, XAResource.TMSUCCESS);
-
- tm.commit();
-
- //verify that the first text message is received
- TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
- assertNotNull(r3);
- assertEquals("kangaroo1", r3.getText());
-
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- if (conn2 != null)
- {
- conn2.close();
- }
-
- }
-
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- private void assertEqualByteArrays(byte[] b1, byte[] b2)
- {
- log.info("b1 length: " + b1.length + " b2 length " + b2.length);
-
- if (b1.length != b2.length)
- {
- fail("Lengths not the same");
- }
-
- for (int i = 0; i < b1.length; i++)
- {
- if (b1[i] != b2[i])
- {
- fail("Not same at index " + i);
- }
- }
- }
-
- // Inner classes -------------------------------------------------
-
-
- static class DummyListener implements MessageListener
- {
-
- protected Logger log = Logger.getLogger(getClass());
-
- public ArrayList messages = new ArrayList();
-
- public void onMessage(Message message)
- {
- log.info("Message received on DummyListener " + message);
- messages.add(message);
- }
- }
-
- static class MockServerSessionPool implements ServerSessionPool
- {
- private ServerSession serverSession;
-
- MockServerSessionPool(Session sess)
- {
- serverSession = new MockServerSession(sess);
- }
-
- public ServerSession getServerSession() throws JMSException
- {
- return serverSession;
- }
- }
-
- static class MockServerSession implements ServerSession
- {
- Session session;
-
- MockServerSession(Session sess)
- {
- this.session = sess;
- }
-
-
- public Session getSession() throws JMSException
- {
- return session;
- }
-
- public void start() throws JMSException
- {
- session.run();
- }
-
- }
-
-
-
- static class DummyXAResource implements XAResource
- {
- boolean failOnPrepare;
-
- DummyXAResource()
- {
- }
-
- DummyXAResource(boolean failOnPrepare)
- {
- this.failOnPrepare = failOnPrepare;
- }
-
- public void commit(Xid arg0, boolean arg1) throws XAException
- {
- }
-
- public void end(Xid arg0, int arg1) throws XAException
- {
- }
-
- public void forget(Xid arg0) throws XAException
- {
- }
-
- public int getTransactionTimeout() throws XAException
- {
- return 0;
- }
-
- public boolean isSameRM(XAResource arg0) throws XAException
- {
- return false;
- }
-
- public int prepare(Xid arg0) throws XAException
- {
- if (failOnPrepare)
- {
- throw new XAException(XAException.XAER_RMFAIL);
- }
- return XAResource.XA_OK;
- }
-
- public Xid[] recover(int arg0) throws XAException
- {
- return null;
- }
-
- public void rollback(Xid arg0) throws XAException
- {
- }
-
- public boolean setTransactionTimeout(int arg0) throws XAException
- {
- return false;
- }
-
- public void start(Xid arg0, int arg1) throws XAException
- {
-
- }
-
- }
-
-}
+/*
+ * 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 java.util.ArrayList;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ServerSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.XAConnection;
+import javax.jms.XAConnectionFactory;
+import javax.jms.XASession;
+import javax.naming.InitialContext;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.jboss.jms.client.JBossConnection;
+import org.jboss.jms.client.JBossConnectionFactory;
+import org.jboss.jms.client.JBossSession;
+import org.jboss.jms.client.api.ClientConnection;
+import org.jboss.jms.client.api.ClientSession;
+import org.jboss.messaging.core.tx.MessagingXid;
+import org.jboss.messaging.util.Logger;
+import org.jboss.test.messaging.JBMServerTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.container.ServiceContainer;
+import org.jboss.tm.TransactionManagerLocator;
+import org.jboss.tm.TxUtils;
+
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
+import com.sun.naming.internal.ResourceManager;
+
+/**
+ *
+ * A XATestBase
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public class XATest extends JBMServerTestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ protected TransactionManager tm;
+
+ protected Transaction suspendedTx;
+
+ protected JBossConnectionFactory cf;
+
+ // Constructors --------------------------------------------------
+
+ public XATest(String name)
+ {
+ super(name);
+ }
+
+
+ // TestCase overrides -------------------------------------------
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ cf = getConnectionFactory();
+
+ //Also need a local tx mgr if test is running remote
+ if (ServerManagement.isRemote())
+ {
+ tm = new TransactionManagerImple();
+ }
+ else
+ {
+ InitialContext localIc = getInitialContext();
+
+ tm = (TransactionManager)localIc.lookup(ServiceContainer.TRANSACTION_MANAGER_JNDI_NAME);
+ }
+
+
+ assertTrue(tm instanceof TransactionManagerImple);
+
+ if (!ServerManagement.isRemote())
+ {
+ suspendedTx = tm.suspend();
+ }
+ }
+
+ public void tearDown() throws Exception
+ {
+ if (TxUtils.isUncommitted(tm))
+ {
+ //roll it back
+ try
+ {
+ tm.rollback();
+ }
+ catch (Throwable ignore)
+ {
+ //The connection will probably be closed so this may well throw an exception
+ }
+ }
+ if (tm.getTransaction() != null)
+ {
+ Transaction tx = tm.suspend();
+ if (tx != null)
+ log.warn("Transaction still associated with thread " + tx + " at status " + TxUtils.getStatusAsString(tx.getStatus()));
+ }
+
+ if (suspendedTx != null)
+ {
+ tm.resume(suspendedTx);
+ }
+
+ super.tearDown();
+ }
+
+ // Public --------------------------------------------------------
+//
+// /* If there is no global tx present the send must behave as non transacted.
+// * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
+// * http://jira.jboss.com/jira/browse/JBMESSAGING-410
+// * http://jira.jboss.com/jira/browse/JBMESSAGING-721
+// * http://jira.jboss.org/jira/browse/JBMESSAGING-946
+// */
+// public void testSendNoGlobalTransaction() throws Exception
+// {
+// Transaction suspended = null;
+//
+// try
+// {
+// // make sure there's no active JTA transaction
+//
+// suspended = tm.suspend();
+//
+// // send a message to the queue using an XASession that's not enlisted in a global tx
+//
+// XAConnectionFactory xcf = (XAConnectionFactory)cf;
+//
+// XAConnection xconn = xcf.createXAConnection();
+//
+// XASession xs = xconn.createXASession();
+//
+// MessageProducer p = xs.createProducer(queue1);
+// Message m = xs.createTextMessage("one");
+//
+// p.send(m);
+//
+// xconn.close();
+//
+// // receive the message
+// Connection conn = cf.createConnection();
+// conn.start();
+// Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer c = s.createConsumer(queue1);
+// TextMessage rm = (TextMessage)c.receive(1000);
+//
+// assertEquals("one", rm.getText());
+//
+// conn.close();
+// }
+// finally
+// {
+// if (suspended != null)
+// {
+// TransactionManagerLocator.getInstance().locate().resume(suspended);
+// }
+// }
+// }
+//
+//
+// /*
+// * If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
+// * falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
+// *
+// * There is one exception to this:
+// *
+// * For transactional delivery of messages in an MDB using the old container invoker (non JCA 1.5 inflow) the message
+// * is received from the JMS provider *before* the MDB container has a chance to enlist the session in a transaction.
+// * (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration" of Mark Little's book Java Transaction
+// * processing for a discussion of how different app servers deal with this)
+// * This is not a problem specific to JBoss and was solved with JCA 1.5 message inflow.
+// * Consequently, if we detect the session has a distinguised session listener (which it will if using ASF) then the behaviour
+// * is to fall back to being a local transacted session. Later on, when the session is enlisted the work done in the local tx
+// * is converted to the global tx brach.
+// *
+// * We are testing the exceptional case here without a global tx here
+// *
+// * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
+// * http://jira.jboss.com/jira/browse/JBMESSAGING-410
+// * http://jira.jboss.com/jira/browse/JBMESSAGING-721
+// * http://jira.jboss.org/jira/browse/JBMESSAGING-946
+// *
+// */
+// public void testConsumeWithConnectionConsumerNoGlobalTransaction() throws Exception
+// {
+// // send a message to the queue
+//
+// Connection conn = cf.createConnection();
+// Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer p = s.createProducer(queue1);
+// p.setDeliveryMode(DeliveryMode.PERSISTENT);
+// Message m = s.createTextMessage("one");
+// p.send(m);
+// conn.close();
+//
+// // make sure there's no active JTA transaction
+//
+// Transaction suspended = tm.suspend();
+//
+// XAConnection xaconn = null;
+// try
+// {
+// Integer count = getMessageCountForQueue("Queue1");
+// assertEquals(1, count.intValue());
+//
+// // using XA with a ConnectionConsumer (testing the transaction behavior under MDBs)
+//
+// XAConnectionFactory xacf = (XAConnectionFactory)cf;
+// xaconn = xacf.createXAConnection();
+// xaconn.start();
+// XASession xasession = xaconn.createXASession();
+// DummyListener listener = new DummyListener();
+// xasession.setMessageListener(listener);
+//
+// ServerSessionPool pool = new MockServerSessionPool(xasession);
+//
+// xaconn.createConnectionConsumer(queue1, null, pool, 1);
+//
+// Thread.sleep(1000);
+// assertEquals(1, listener.messages.size());
+//
+// // Message should still be on server
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(1, count.intValue());
+//
+// XAResource resource = xasession.getXAResource();
+//
+// // Starts a new transaction
+// tm.begin();
+//
+// Transaction trans = tm.getTransaction();
+//
+// ClientSession clientSession = ((JBossSession)xasession).getDelegate();
+//
+// // Validates TX convertion
+// assertTrue(clientSession.getCurrentTxId() instanceof LocalTx);
+//
+// // Enlist the transaction... as supposed to be happening on JBossAS with the
+// // default listener (enlist happening after message is received)
+// trans.enlistResource(resource);
+//
+// // Validates TX convertion
+// assertFalse(clientSession.getCurrentTxId() instanceof LocalTx);
+//
+// trans.delistResource(resource, XAResource.TMSUCCESS);
+//
+// trans.commit();
+//
+// // After commit the message should be consumed
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(0, count.intValue());
+// }
+// finally
+// {
+// if (xaconn != null)
+// {
+// xaconn.close();
+// }
+// if (suspended != null)
+// {
+// TransactionManagerLocator.getInstance().locate().resume(suspended);
+// }
+// }
+// }
+//
+//
+// /*
+// * If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
+// * falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
+// *
+// * There is one exception to this:
+// *
+// * For transactional delivery of messages in an MDB using the old container invoker (non JCA 1.5 inflow) the message
+// * is received from the JMS provider *before* the MDB container has a chance to enlist the session in a transaction.
+// * (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration" of Mark Little's book Java Transaction
+// * processing for a discussion of how different app servers deal with this)
+// * This is not a problem specific to JBoss and was solved with JCA 1.5 message inflow.
+// * Consequently, if we detect the session has a distinguised session listener (which it will if using ASF) then the behaviour
+// * is to fall back to being a local transacted session. Later on, when the session is enlisted the work done in the local tx
+// * is converted to the global tx brach.
+// *
+// * We are testing the standard case without a global tx here
+// *
+// * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
+// * http://jira.jboss.com/jira/browse/JBMESSAGING-410
+// * http://jira.jboss.com/jira/browse/JBMESSAGING-721
+// * http://jira.jboss.org/jira/browse/JBMESSAGING-946
+// *
+// */
+// public void testConsumeWithoutConnectionConsumerNoGlobalTransaction() throws Exception
+// {
+// // send a message to the queue
+//
+// Connection conn = cf.createConnection();
+// Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer p = s.createProducer(queue1);
+// p.setDeliveryMode(DeliveryMode.PERSISTENT);
+// Message m = s.createTextMessage("one");
+// p.send(m);
+// conn.close();
+//
+// // make sure there's no active JTA transaction
+//
+// Transaction suspended = tm.suspend();
+//
+// try
+// {
+// Integer count = getMessageCountForQueue("Queue1");
+// assertEquals(1, count.intValue());
+//
+// XAConnectionFactory xcf = (XAConnectionFactory)cf;
+// XAConnection xconn = xcf.createXAConnection();
+// xconn.start();
+//
+// // no active JTA transaction here
+//
+// XASession xs = xconn.createXASession();
+//
+// MessageConsumer c = xs.createConsumer(queue1);
+//
+// // the message should be store unacked in the local session
+// TextMessage rm = (TextMessage)c.receive(1000);
+//
+// assertEquals("one", rm.getText());
+//
+// // messages should be acked
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(0, count.intValue());
+//
+// xconn.close();
+// }
+// finally
+// {
+//
+// if (suspended != null)
+// {
+// TransactionManagerLocator.getInstance().locate().resume(suspended);
+// }
+// }
+// }
+//
+//
+// /*
+// * If messages are consumed using an XASession that is not enlisted in a transaction then the behaviour of the session
+// * falls back to being AUTO_ACK - i.e. the messages will get acked immediately.
+// *
+// * There is one exception to this:
+// *
+// * For transactional delivery of messages in an MDB using the old container invoker (non JCA 1.5 inflow) the message
+// * is received from the JMS provider *before* the MDB container has a chance to enlist the session in a transaction.
+// * (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration" of Mark Little's book Java Transaction
+// * processing for a discussion of how different app servers deal with this)
+// * This is not a problem specific to JBoss and was solved with JCA 1.5 message inflow.
+// * Consequently, if we detect the session has a distinguised session listener (which it will if using ASF) then the behaviour
+// * is to fall back to being a local transacted session. Later on, when the session is enlisted the work done in the local tx
+// * is converted to the global tx brach.
+// *
+// * We are testing the case with a global tx here
+// *
+// * See http://www.jboss.com/index.html?module=bb&op=viewtopic&t=98577&postdays=0&postorder=asc&start=0
+// * http://jira.jboss.com/jira/browse/JBMESSAGING-410
+// * http://jira.jboss.com/jira/browse/JBMESSAGING-721
+// * http://jira.jboss.org/jira/browse/JBMESSAGING-946
+// *
+// */
+// public void testConsumeGlobalTransaction() throws Exception
+// {
+// XAConnection xaconn = null;
+//
+// try
+// {
+// // send a message to the queue
+//
+// Connection conn = cf.createConnection();
+// Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer p = s.createProducer(queue1);
+// p.setDeliveryMode(DeliveryMode.PERSISTENT);
+// Message m = s.createTextMessage("one");
+// p.send(m);
+// conn.close();
+//
+// Integer count = getMessageCountForQueue("Queue1");
+// assertEquals(1, count.intValue());
+//
+// tm.begin();
+//
+// Transaction trans = tm.getTransaction();
+//
+// XAConnectionFactory xacf = (XAConnectionFactory)cf;
+//
+// xaconn = xacf.createXAConnection();
+//
+// xaconn.start();
+//
+// XASession xasession = xaconn.createXASession();
+//
+// XAResource resouce = xasession.getXAResource();
+//
+// trans.enlistResource(resouce);
+//
+// MessageConsumer consumer = xasession.createConsumer(queue1);
+//
+// TextMessage messageReceived = (TextMessage)consumer.receive(1000);
+//
+// assertNotNull(messageReceived);
+//
+// assertEquals("one", messageReceived.getText());
+//
+// assertNull(consumer.receive(1000));
+//
+// count = getMessageCountForQueue("Queue1");
+//
+// assertEquals(1, count.intValue());
+//
+// trans.delistResource(resouce, XAResource.TMSUCCESS);
+//
+// tm.rollback();
+//
+// tm.begin();
+// trans = tm.getTransaction();
+// trans.enlistResource(resouce);
+//
+// messageReceived = (TextMessage)consumer.receive(1000);
+//
+// assertNotNull(messageReceived);
+//
+// assertEquals("one", messageReceived.getText());
+//
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(1, count.intValue());
+//
+// trans.commit();
+//
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(0, count.intValue());
+//
+// }
+// finally
+// {
+// if (xaconn != null)
+// {
+// xaconn.close();
+// }
+// }
+// }
+//
+// /*
+// * This test will:
+// * - Send two messages over a producer
+// * - Receive one message over a consumer created used a XASession
+// * - Call Recover
+// * - Receive the second message
+// * - The queue should be empty after that
+// * Verifies if messages are sent ok and ack properly when recovery is called
+// * NOTE: To accomodate TCK tests where Session/Consumers are being used without transaction enlisting
+// * we are processing those cases as nonTransactional/AutoACK, however if the session is being used
+// * to process MDBs we will consider the LocalTransaction convertion and process those as the comment above
+// * This was done as per: http://jira.jboss.org/jira/browse/JBMESSAGING-946
+// *
+// */
+// public void testRecoverOnXA() throws Exception
+// {
+// XAConnection xaconn = null;
+//
+// try
+// {
+// // send a message to the queue
+//
+// Connection conn = cf.createConnection();
+// Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer p = s.createProducer(queue1);
+// p.setDeliveryMode(DeliveryMode.PERSISTENT);
+// Message m = s.createTextMessage("one");
+// p.send(m);
+// m = s.createTextMessage("two");
+// p.send(m);
+// conn.close();
+//
+// Integer count = getMessageCountForQueue("Queue1");
+// assertEquals(2, count.intValue());
+//
+// XAConnectionFactory xacf = (XAConnectionFactory)cf;
+//
+// xaconn = xacf.createXAConnection();
+//
+// xaconn.start();
+//
+// XASession xasession = xaconn.createXASession();
+//
+// MessageConsumer consumer = xasession.createConsumer(queue1);
+//
+// TextMessage messageReceived = (TextMessage)consumer.receive(1000);
+//
+// assertNotNull(messageReceived);
+//
+// assertEquals("one", messageReceived.getText());
+//
+// xasession.recover();
+//
+// messageReceived = (TextMessage)consumer.receive(1000);
+//
+// assertEquals("two", messageReceived.getText());
+//
+// consumer.close();
+//
+// // I can't call xasession.close for this test as JCA layer would cache the session
+// // So.. keep this close commented!
+// //xasession.close();
+//
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(0, count.intValue());
+// }
+// finally
+// {
+// if (xaconn != null)
+// {
+// xaconn.close();
+// }
+// }
+// }
+//
+// // http://jira.jboss.com/jira/browse/JBMESSAGING-721
+// public void testConvertFromLocalTx() throws Exception
+// {
+// Connection conn = null;
+//
+// XAConnection xaConn = null;
+//
+// try
+// {
+//
+// //First send some messages to a queue
+//
+// Integer count = getMessageCountForQueue("Queue1");
+// assertEquals(0, count.intValue());
+//
+// conn = cf.createConnection();
+//
+// Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+// MessageProducer prod = sessSend.createProducer(queue1);
+//
+// TextMessage tm1 = sessSend.createTextMessage("message1");
+//
+// TextMessage tm2 = sessSend.createTextMessage("message2");
+//
+// prod.send(tm1);
+//
+// prod.send(tm2);
+//
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(2, count.intValue());
+//
+// xaConn = cf.createXAConnection();
+//
+// XASession xaSession = xaConn.createXASession();
+//
+// xaConn.start();
+//
+// DummyListener listener = new DummyListener();
+//
+// //We set the distinguised listener so it will convert
+// xaSession.setMessageListener(listener);
+//
+// ServerSessionPool pool = new MockServerSessionPool(xaSession);
+//
+// xaConn.createConnectionConsumer(queue1, null, pool, 1);
+//
+// Thread.sleep(1000);
+//
+// assertEquals(2, listener.messages.size());
+//
+// assertEquals("message1", ((TextMessage)(listener.messages.get(0))).getText());
+// assertEquals("message2", ((TextMessage)(listener.messages.get(1))).getText());
+//
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(2, count.intValue());
+//
+// listener.messages.clear();
+//
+// //Now we enlist the session in an xa transaction
+//
+// XAResource res = xaSession.getXAResource();
+//
+// tm.begin();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+// //This should cause the work done previously to be converted into work done in the xa transaction
+// //this is what an MDB does
+// //There is a difficulty in transactional delivery with an MDB.
+// //The message is received from the destination and then sent to the mdb container so
+// //it can call onMessage.
+// //For transactional delivery the receipt of the message should be in a transaction but by the time
+// //the mdb container is invoked the message has already been received it is too late - the message
+// //has already been received and passed on (see page 199 (chapter 5 JMS and Transactions, section "Application Server Integration"
+// //of Mark Little's book Java Transaction processing
+// //for a discussion of how different app serves deal with this)
+// //The way jboss messaging (and jboss mq) deals with this is to convert any work done
+// //prior to when the xasession is enlisted in the tx, into work done in the xa tx
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// //Now rollback the tx - this should cause redelivery of the two messages
+// tm.rollback();
+//
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(2, count.intValue());
+//
+// Thread.sleep(1000);
+//
+// assertEquals(2, listener.messages.size());
+//
+// listener.messages.clear();
+//
+// tm.begin();
+//
+// tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+// tm.commit();
+//
+// Thread.sleep(1000);
+//
+// assertEquals(0, listener.messages.size());
+//
+// count = getMessageCountForQueue("Queue1");
+// assertEquals(0, count.intValue());
+//
+// assertNull(tm.getTransaction());
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+//
+// if (xaConn != null)
+// {
+// xaConn.close();
+// }
+//
+// /* if (suspended != null)
+// {
+// tm.resume(suspended);
+// }*/
+// }
+// }
+//
+// //http://jira.jboss.com/jira/browse/JBMESSAGING-721
+// // Note: The behavior of this test was changed after http://jira.jboss.com/jira/browse/JBMESSAGING-946
+// // When you have a XASession without a transaction enlisted we will behave the same way as non transactedSession, AutoAck
+// public void testTransactionIdSetAfterCommit() throws Exception
+// {
+// Connection conn = null;
+//
+// XAConnection xaConn = null;
+//
+// try
+// {
+// //First send some messages to a queue
+//
+// conn = cf.createConnection();
+//
+// Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+// MessageProducer prod = sessSend.createProducer(queue1);
+//
+// TextMessage tm1 = sessSend.createTextMessage("message1");
+//
+// TextMessage tm2 = sessSend.createTextMessage("message2");
+//
+// prod.send(tm1);
+//
+// prod.send(tm2);
+//
+//
+// xaConn = cf.createXAConnection();
+//
+// XASession xaSession = xaConn.createXASession();
+//
+// xaConn.start();
+//
+// MessageConsumer cons = xaSession.createConsumer(queue1);
+//
+// //Now we enlist the session in an xa transaction
+//
+// XAResource res = xaSession.getXAResource();
+//
+// tm.begin();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// //Then we do a commit
+// tm.commit();
+//
+// // I have changed where this begin was originally set
+// // as when you don't have a resource enlisted, XASessions will act as
+// // non transacted + AutoAck
+//
+// //And enlist again - this should convert the work done in the local tx
+// //into the global branch
+//
+// tx = tm.getTransaction();
+//
+// tm.begin();
+//
+// tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+// //Then we receive the messages outside the tx
+//
+// TextMessage rm1 = (TextMessage)cons.receive(1000);
+//
+// assertNotNull(rm1);
+//
+// assertEquals("message1", rm1.getText());
+//
+// TextMessage rm2 = (TextMessage)cons.receive(1000);
+//
+// assertNotNull(rm2);
+//
+// assertEquals("message2", rm2.getText());
+//
+// Message rm3 = cons.receive(1000);
+//
+// assertNull(rm3);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// //Now rollback the tx - this should cause redelivery of the two messages
+// tx.rollback();
+//
+// rm1 = (TextMessage)cons.receive(1000);
+//
+// assertNotNull(rm1);
+//
+// assertEquals("message1", rm1.getText());
+//
+// rm2 = (TextMessage)cons.receive(1000);
+//
+// assertNotNull(rm2);
+//
+// assertEquals("message2", rm2.getText());
+//
+// rm3 = cons.receive(1000);
+//
+// assertNull(rm3);
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+//
+// if (xaConn != null)
+// {
+// xaConn.close();
+// }
+// }
+//
+// }
+//
+// //http://jira.jboss.com/jira/browse/JBMESSAGING-721
+// public void testTransactionIdSetAfterRollback() throws Exception
+// {
+// Connection conn = null;
+//
+// XAConnection xaConn = null;
+//
+// try
+// {
+// //First send some messages to a queue
+//
+// conn = cf.createConnection();
+//
+// Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+// MessageProducer prod = sessSend.createProducer(queue1);
+//
+// TextMessage tm1 = sessSend.createTextMessage("message1");
+//
+// TextMessage tm2 = sessSend.createTextMessage("message2");
+//
+// prod.send(tm1);
+//
+// prod.send(tm2);
+//
+// xaConn = cf.createXAConnection();
+//
+// XASession xaSession = xaConn.createXASession();
+//
+// xaConn.start();
+//
+// MessageConsumer cons = xaSession.createConsumer(queue1);
+//
+// //Now we enlist the session in an xa transaction
+//
+// XAResource res = xaSession.getXAResource();
+//
+// tm.begin();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// //Then we do a rollback
+// tm.rollback();
+//
+// tm.begin();
+//
+// //And enlist again - the work should then be converted into the global tx branch
+//
+// // I have changed where this begin was originally set
+// // as when you don't have a resource enlisted, XASessions will act as
+// // non transacted + AutoAck
+//
+// tx = tm.getTransaction();
+//
+// tx.enlistResource(res);
+//
+// //Then we receive the messages outside the global tx
+//
+// TextMessage rm1 = (TextMessage)cons.receive(1000);
+//
+// assertNotNull(rm1);
+//
+// assertEquals("message1", rm1.getText());
+//
+// TextMessage rm2 = (TextMessage)cons.receive(1000);
+//
+// assertNotNull(rm2);
+//
+// assertEquals("message2", rm2.getText());
+//
+// Message rm3 = cons.receive(1000);
+//
+// assertNull(rm3);
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// //Now rollback the tx - this should cause redelivery of the two messages
+// tx.rollback();
+//
+// rm1 = (TextMessage)cons.receive(1000);
+//
+// assertNotNull(rm1);
+//
+// assertEquals("message1", rm1.getText());
+//
+// rm2 = (TextMessage)cons.receive(1000);
+//
+// assertNotNull(rm2);
+//
+// assertEquals("message2", rm2.getText());
+//
+// rm3 = cons.receive(1000);
+//
+// assertNull(rm3);
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+//
+// if (xaConn != null)
+// {
+// xaConn.close();
+// }
+// }
+// }
+//
+// // See http://jira.jboss.org/jira/browse/JBMESSAGING-825
+// // Need to test that ids with trailing zeros are dealt with properly - sybase has the habit
+// // of truncating trailing zeros in varbinary columns
+// public void testXidsWithTrailingZeros() throws Exception
+// {
+// if (!ServerManagement.isRemote())
+// {
+// return;
+// }
+//
+// XAConnection conn1 = null;
+//
+// try
+// {
+// conn1 = cf.createXAConnection();
+//
+// XASession sess1 = conn1.createXASession();
+//
+// XAResource res1 = sess1.getXAResource();
+//
+// byte[] branchQualifier = new byte[] { 1, 2, 3, 4, 5, 6, 0, 0, 0, 0 };
+//
+// byte[] globalTxId = new byte[] { 6, 5, 4, 3, 2, 1, 0, 0, 0, 0 };
+//
+// Xid trailing = new MessagingXid(branchQualifier, 12435, globalTxId);
+//
+// res1.start(trailing, XAResource.TMNOFLAGS);
+//
+// MessageProducer prod1 = sess1.createProducer(queue1);
+//
+// TextMessage tm1 = sess1.createTextMessage("testing1");
+//
+// prod1.send(tm1);
+//
+// res1.end(trailing, XAResource.TMSUCCESS);
+//
+// res1.prepare(trailing);
+//
+// //Now "crash" the server
+//
+// stopServerPeer();
+//
+// startServerPeer();
+//
+// deployAndLookupAdministeredObjects();
+//
+// conn1.close();
+//
+// conn1 = cf.createXAConnection();
+//
+// XAResource res = conn1.createXASession().getXAResource();
+//
+// Xid[] xids = res.recover(XAResource.TMSTARTRSCAN);
+// assertEquals(1, xids.length);
+//
+// Xid[] xids2 = res.recover(XAResource.TMENDRSCAN);
+// assertEquals(0, xids2.length);
+//
+// Xid trailing2 = xids[0];
+//
+// assertTrue(trailing.getFormatId() == trailing2.getFormatId());
+//
+// assertEqualByteArrays(trailing.getGlobalTransactionId(), trailing2.getGlobalTransactionId());
+//
+// assertEqualByteArrays(trailing.getBranchQualifier(), trailing2.getBranchQualifier());
+//
+// res.commit(trailing, false);
+// }
+// finally
+// {
+// removeAllMessages(queue1.getQueueName(), true, 0);
+//
+// if (conn1 != null)
+// {
+// try
+// {
+// conn1.close();
+// }
+// catch (Exception e)
+// {
+// //Ignore
+// }
+// }
+// }
+// }
+//
+// public void test2PCSendCommit1PCOptimization() throws Exception
+// {
+// //Since both resources have same RM, TM will probably use 1PC optimization
+//
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// conn = cf.createXAConnection();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// XAResource res = sess.getXAResource();
+//
+// XAResource res2 = new DummyXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// MessageProducer prod = sess.createProducer(queue1);
+// prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+// Message m = sess.createTextMessage("XATest1");
+// prod.send(queue1, m);
+// m = sess.createTextMessage("XATest2");
+// prod.send(queue1, m);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sessReceiver.createConsumer(queue1);
+// TextMessage m2 = (TextMessage)cons.receive(1000);
+// assertNotNull(m2);
+// assertEquals("XATest1", m2.getText());
+// m2 = (TextMessage)cons.receive(1000);
+// assertNotNull(m2);
+// assertEquals("XATest2", m2.getText());
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+//
+//
+// public void test2PCSendCommit() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// conn = cf.createXAConnection();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+//
+// MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
+// XAResource res2 = new DummyXAResource();
+//
+// //To prevent 1PC optimization being used
+// res.setPreventJoining(true);
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// MessageProducer prod = sess.createProducer(queue1);
+// prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+// Message m = sess.createTextMessage("XATest1");
+// prod.send(queue1, m);
+// m = sess.createTextMessage("XATest2");
+// prod.send(queue1, m);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// log.info("Committing***");
+// tm.commit();
+// log.info("Committed****");
+//
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sessReceiver.createConsumer(queue1);
+// TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m2);
+// assertEquals("XATest1", m2.getText());
+// m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m2);
+// assertEquals("XATest2", m2.getText());
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+//
+// public void test2PCSendRollback1PCOptimization() throws Exception
+// {
+// //Since both resources have some RM, TM will probably use 1PC optimization
+//
+// XAConnection conn = null;
+// Connection conn2 = null;
+// try
+// {
+// conn = cf.createXAConnection();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// XAResource res = sess.getXAResource();
+//
+// XAResource res2 = new DummyXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// MessageProducer prod = sess.createProducer(queue1);
+// prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+// Message m = sess.createTextMessage("XATest1");
+// prod.send(queue1, m);
+// m = sess.createTextMessage("XATest2");
+// prod.send(queue1, m);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.rollback();
+//
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sessReceiver.createConsumer(queue1);
+// Message m2 = cons.receive(MIN_TIMEOUT);
+// assertNull(m2);
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+//
+// public void test2PCSendFailOnPrepare() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+// try
+// {
+// conn = cf.createXAConnection();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
+//
+// //prevent 1Pc optimisation
+// res.setPreventJoining(true);
+//
+// XAResource res2 = new DummyXAResource(true);
+// XAResource res3 = new DummyXAResource();
+// XAResource res4 = new DummyXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+// tx.enlistResource(res3);
+// tx.enlistResource(res4);
+//
+// MessageProducer prod = sess.createProducer(queue1);
+// prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+// Message m = sess.createTextMessage("XATest1");
+// prod.send(queue1, m);
+// m = sess.createTextMessage("XATest2");
+// prod.send(queue1, m);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+// tx.delistResource(res3, XAResource.TMSUCCESS);
+// tx.delistResource(res4, XAResource.TMSUCCESS);
+//
+// try
+// {
+// tm.commit();
+//
+// fail("should not get here");
+// }
+// catch (Exception e)
+// {
+// //We should expect this
+// }
+//
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sessReceiver.createConsumer(queue1);
+// Message m2 = cons.receive(MIN_TIMEOUT);
+// assertNull(m2);
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+// public void test2PCSendRollback() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+// try
+// {
+// conn = cf.createXAConnection();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
+//
+// //prevent 1Pc optimisation
+// res.setPreventJoining(true);
+//
+// XAResource res2 = new DummyXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// MessageProducer prod = sess.createProducer(queue1);
+// prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+// Message m = sess.createTextMessage("XATest1");
+// prod.send(queue1, m);
+// m = sess.createTextMessage("XATest2");
+// prod.send(queue1, m);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.rollback();
+//
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sessReceiver.createConsumer(queue1);
+// Message m2 = cons.receive(MIN_TIMEOUT);
+// assertNull(m2);
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+// public void test2PCReceiveCommit1PCOptimization() throws Exception
+// {
+// //Since both resources have some RM, TM will probably use 1PC optimization
+//
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("XATest1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("XATest2");
+// prod.send(m);
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// XAResource res = sess.getXAResource();
+//
+// XAResource res2 = new DummyXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// MessageConsumer cons = sess.createConsumer(queue1);
+//
+//
+// TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m2);
+// assertEquals("XATest1", m2.getText());
+//
+// m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m2);
+// assertEquals("XATest2", m2.getText());
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// //New tx
+// tm.begin();
+// tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// Message m3 = cons.receive(MIN_TIMEOUT);
+//
+// assertNull(m3);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.commit();
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+// public void test2PCReceiveCommit() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("XATest1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("XATest2");
+// prod.send(m);
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
+// res.setPreventJoining(true);
+//
+// XAResource res2 = new DummyXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// MessageConsumer cons = sess.createConsumer(queue1);
+//
+//
+// TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m2);
+// assertEquals("XATest1", m2.getText());
+//
+// m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m2);
+// assertEquals("XATest2", m2.getText());
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// //New tx
+// tm.begin();
+// tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// Message m3 = cons.receive(MIN_TIMEOUT);
+//
+// assertNull(m3);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.commit();
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+// public void test2PCReceiveRollback1PCOptimization() throws Exception
+// {
+// //Since both resources have some RM, TM will probably use 1PC optimization
+//
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("XATest1");
+// prod.send(m);
+//
+// m = sessProducer.createTextMessage("XATest2");
+// prod.send(m);
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// XAResource res = sess.getXAResource();
+//
+// XAResource res2 = new DummyXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// MessageConsumer cons = sess.createConsumer(queue1);
+//
+//
+// TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m2);
+// assertEquals("XATest1", m2.getText());
+// m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m2);
+// assertEquals("XATest2", m2.getText());
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.rollback();
+//
+// //Message should be redelivered
+//
+// //New tx
+// tm.begin();
+// tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m3);
+// assertEquals("XATest1", m3.getText());
+// m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m3);
+// assertEquals("XATest2", m3.getText());
+//
+// assertTrue(m3.getJMSRedelivered());
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.commit();
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+// public void test2PCReceiveRollback() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("XATest1");
+// prod.send(m);
+//
+// m = sessProducer.createTextMessage("XATest2");
+// prod.send(m);
+//
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// MessagingXAResource res = (MessagingXAResource)sess.getXAResource();
+// res.setPreventJoining(true);
+//
+// XAResource res2 = new DummyXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// MessageConsumer cons = sess.createConsumer(queue1);
+//
+//
+// TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m2);
+// assertEquals("XATest1", m2.getText());
+// m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m2);
+// assertEquals("XATest2", m2.getText());
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.rollback();
+//
+// //Message should be redelivered
+//
+// //New tx
+// tm.begin();
+// tx = tm.getTransaction();
+// tx.enlistResource(res);
+// tx.enlistResource(res2);
+//
+// TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m3);
+// assertEquals("XATest1", m3.getText());
+// m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m3);
+// assertEquals("XATest2", m3.getText());
+//
+// assertTrue(m3.getJMSRedelivered());
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+//
+// public void test1PCSendCommit() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// conn = cf.createXAConnection();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// XAResource res = sess.getXAResource();
+//
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+//
+// MessageProducer prod = sess.createProducer(queue1);
+// prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+// Message m = sess.createTextMessage("XATest1");
+// prod.send(queue1, m);
+// m = sess.createTextMessage("XATest2");
+// prod.send(queue1, m);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sessReceiver.createConsumer(queue1);
+// TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m2);
+// assertEquals("XATest1", m2.getText());
+// m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(m2);
+// assertEquals("XATest2", m2.getText());
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+//
+// public void test1PCSendRollback() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+// try
+// {
+// conn = cf.createXAConnection();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// XAResource res = sess.getXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+// MessageProducer prod = sess.createProducer(queue1);
+// prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+// Message m = sess.createTextMessage("XATest1");
+// prod.send(queue1, m);
+// m = sess.createTextMessage("XATest2");
+// prod.send(queue1, m);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// tm.rollback();
+//
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessReceiver = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sessReceiver.createConsumer(queue1);
+// Message m2 = cons.receive(MIN_TIMEOUT);
+// assertNull(m2);
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+// public void test1PCReceiveCommit() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// conn2 = cf.createConnection();
+// conn2.start();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("XATest1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("XATest2");
+// prod.send(m);
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// XAResource res = sess.getXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+// MessageConsumer cons = sess.createConsumer(queue1);
+//
+//
+// TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m2);
+// assertEquals("XATest1", m2.getText());
+// m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m2);
+// assertEquals("XATest2", m2.getText());
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// //New tx
+// tm.begin();
+// tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+// Message m3 = cons.receive(MIN_TIMEOUT);
+//
+// assertNull(m3);
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// tm.commit();
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+// public void test1PCReceiveRollback() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("XATest1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("XATest2");
+// prod.send(m);
+//
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// XASession sess = conn.createXASession();
+// XAResource res = sess.getXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+// MessageConsumer cons = sess.createConsumer(queue1);
+//
+//
+// TextMessage m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m2);
+// assertEquals("XATest1", m2.getText());
+//
+// m2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m2);
+// assertEquals("XATest2", m2.getText());
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// tm.rollback();
+//
+// //Message should be redelivered
+//
+// //New tx
+// tm.begin();
+// tx = tm.getTransaction();
+// tx.enlistResource(res);
+//
+// TextMessage m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m3);
+// assertEquals("XATest1", m3.getText());
+//
+// m3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(m3);
+// assertEquals("XATest2", m3.getText());
+//
+// assertTrue(m3.getJMSRedelivered());
+//
+// tx.delistResource(res, XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+// public void testMultipleSessionsOneTxCommitAcknowledge1PCOptimization() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// //Since both resources have some RM, TM will probably use 1PC optimization
+//
+// try
+// {
+// //First send 2 messages
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("jellyfish1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish2");
+// prod.send(m);
+//
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// //Create 2 sessions and enlist them
+// XASession sess1 = conn.createXASession();
+// XAResource res1 = sess1.getXAResource();
+// XASession sess2 = conn.createXASession();
+// XAResource res2 = sess2.getXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res1);
+// tx.enlistResource(res2);
+//
+// //Receive the messages, one on each consumer
+// MessageConsumer cons1 = sess1.createConsumer(queue1);
+// TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish1", r1.getText());
+//
+// cons1.close();
+//
+// MessageConsumer cons2 = sess2.createConsumer(queue1);
+// TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r2);
+// assertEquals("jellyfish2", r2.getText());
+//
+// tx.delistResource(res1, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// //commit
+// tm.commit();
+//
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sess.createConsumer(queue1);
+// conn2.start();
+//
+// TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+// assertNull(r3);
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+// public void testMultipleSessionsOneTxCommitAcknowledge() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// //First send 2 messages
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("jellyfish1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish2");
+// prod.send(m);
+//
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// //Create 2 sessions and enlist them
+// XASession sess1 = conn.createXASession();
+// MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
+// XASession sess2 = conn.createXASession();
+// MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
+// res1.setPreventJoining(true);
+// res2.setPreventJoining(true);
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res1);
+// tx.enlistResource(res2);
+//
+// //Receive the messages, one on each consumer
+// MessageConsumer cons1 = sess1.createConsumer(queue1);
+// TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish1", r1.getText());
+//
+// cons1.close();
+//
+// MessageConsumer cons2 = sess2.createConsumer(queue1);
+// TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r2);
+// assertEquals("jellyfish2", r2.getText());
+//
+// tx.delistResource(res1, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// //commit
+// tm.commit();
+//
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sess.createConsumer(queue1);
+// conn2.start();
+//
+// TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+// assertNull(r3);
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+//
+// public void testMultipleSessionsOneTxRollbackAcknowledge1PCOptimization() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// //Since both resources have some RM, TM will probably use 1PC optimization
+//
+// try
+// {
+// //First send 2 messages
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("jellyfish1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish2");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish3");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish4");
+// prod.send(m);
+//
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// //Create 2 sessions and enlist them
+// XASession sess1 = conn.createXASession();
+// MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
+// XASession sess2 = conn.createXASession();
+// MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res1);
+// tx.enlistResource(res2);
+//
+// //Receive the messages, two on each consumer
+// MessageConsumer cons1 = sess1.createConsumer(queue1);
+// TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish1", r1.getText());
+//
+// r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish2", r1.getText());
+//
+// cons1.close();
+//
+// MessageConsumer cons2 = sess2.createConsumer(queue1);
+// TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r2);
+// assertEquals("jellyfish3", r2.getText());
+//
+// r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r2);
+// assertEquals("jellyfish4", r2.getText());
+//
+// cons2.close();
+//
+// //rollback
+//
+// tx.delistResource(res1, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.rollback();
+//
+// //Rollback causes cancel which is asynch
+// Thread.sleep(1000);
+//
+// //We cannot assume anything about the order in which the transaction manager rollsback
+// //the sessions - this is implementation dependent
+//
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sess.createConsumer(queue1);
+// conn2.start();
+//
+// TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r);
+//
+// boolean session1First = false;
+//
+// if (r.getText().equals("jellyfish1"))
+// {
+// session1First = true;
+// }
+// else if (r.getText().equals("jellyfish3"))
+// {
+// session1First = false;
+// }
+// else
+// {
+// fail("Unexpected message");
+// }
+//
+// if (session1First)
+// {
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish2", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish3", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish4", r.getText());
+//
+//
+// }
+// else
+// {
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish4", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish1", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish2", r.getText());
+// }
+//
+// r = (TextMessage)cons.receive(MIN_TIMEOUT);
+//
+// assertNull(r);
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+// public void testMultipleSessionsOneTxRollbackAcknowledge() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// //First send 2 messages
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("jellyfish1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish2");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish3");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish4");
+// prod.send(m);
+//
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// //Create 2 sessions and enlist them
+// XASession sess1 = conn.createXASession();
+// MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
+// XASession sess2 = conn.createXASession();
+// MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
+// res1.setPreventJoining(true);
+// res2.setPreventJoining(true);
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res1);
+// tx.enlistResource(res2);
+//
+// //Receive the messages, two on each consumer
+// MessageConsumer cons1 = sess1.createConsumer(queue1);
+// TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish1", r1.getText());
+//
+// r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish2", r1.getText());
+//
+// cons1.close();
+//
+// //Cancel is asynch
+// Thread.sleep(500);
+//
+// MessageConsumer cons2 = sess2.createConsumer(queue1);
+// TextMessage r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r2);
+// assertEquals("jellyfish3", r2.getText());
+//
+// r2 = (TextMessage)cons2.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r2);
+// assertEquals("jellyfish4", r2.getText());
+//
+// //rollback
+//
+// cons2.close();
+//
+// tx.delistResource(res1, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// tm.rollback();
+//
+// // Rollback causes cancel which is asynch
+// Thread.sleep(1000);
+//
+// //We cannot assume anything about the order in which the transaction manager rollsback
+// //the sessions - this is implementation dependent
+//
+//
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sess.createConsumer(queue1);
+// conn2.start();
+//
+// TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r);
+//
+// boolean session1First = false;
+//
+// if (r.getText().equals("jellyfish1"))
+// {
+// session1First = true;
+// }
+// else if (r.getText().equals("jellyfish3"))
+// {
+// session1First = false;
+// }
+// else
+// {
+// fail("Unexpected message");
+// }
+//
+// if (session1First)
+// {
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish2", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish3", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish4", r.getText());
+//
+//
+// }
+// else
+// {
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish4", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish1", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish2", r.getText());
+// }
+//
+// r = (TextMessage)cons.receive(MIN_TIMEOUT);
+//
+// assertNull(r);
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+// public void testMultipleSessionsOneTxRollbackAcknowledgeForceFailureInCommit() throws Exception
+// {
+// XAConnection conn = null;
+// Connection conn2 = null;
+//
+// try
+// {
+// //First send 4 messages
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+//
+// Message m = sessProducer.createTextMessage("jellyfish1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish2");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish3");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish4");
+// prod.send(m);
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// XASession sess1 = conn.createXASession();
+// MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
+// DummyXAResource res2 = new DummyXAResource(true);
+// res1.setPreventJoining(true);
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res1);
+// tx.enlistResource(res2);
+//
+// MessageConsumer cons1 = sess1.createConsumer(queue1);
+// TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish1", r1.getText());
+//
+// r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish2", r1.getText());
+//
+// r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish3", r1.getText());
+//
+// r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r1);
+// assertEquals("jellyfish4", r1.getText());
+//
+// r1 = (TextMessage)cons1.receive(1000);
+//
+// assertNull(r1);
+//
+// cons1.close();
+//
+//
+// //try and commit - and we're going to make the dummyxaresource throw an exception on commit,
+// //which should cause rollback to be called on the other resource
+//
+// tx.delistResource(res1, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// //rollback will cause an attemp to deliver messages locally to the original consumers.
+// //the original consumer has closed, so it will cancelled to the server
+// //the server cancel is asynch, so we need to sleep for a bit to make sure it completes
+// log.trace("Forcing failure");
+// try
+// {
+// tm.commit();
+// fail("should not get here");
+// }
+// catch (Exception e)
+// {
+// //We should expect this
+// }
+//
+// Thread.sleep(1000);
+//
+//
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sess.createConsumer(queue1);
+// conn2.start();
+//
+// TextMessage r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish1", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish2", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish3", r.getText());
+//
+// r = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r);
+//
+// assertEquals("jellyfish4", r.getText());
+//
+// r = (TextMessage)cons.receive(MIN_TIMEOUT);
+//
+// assertNull(r);
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+//
+// }
+//
+// public void testMultipleSessionsOneTxCommitSend1PCOptimization() throws Exception
+// {
+// //Since both resources have some RM, TM will probably use 1PC optimization
+//
+// XAConnection conn = null;
+//
+// Connection conn2 = null;
+//
+// try
+// {
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// //Create 2 sessions and enlist them
+// XASession sess1 = conn.createXASession();
+// XAResource res1 = sess1.getXAResource();
+// XASession sess2 = conn.createXASession();
+// XAResource res2 = sess2.getXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res1);
+// tx.enlistResource(res2);
+//
+// // Send 2 messages - one from each session
+//
+// MessageProducer prod1 = sess1.createProducer(queue1);
+// MessageProducer prod2 = sess2.createProducer(queue1);
+//
+// prod1.send(sess1.createTextMessage("echidna1"));
+// prod2.send(sess2.createTextMessage("echidna2"));
+//
+// tx.delistResource(res1, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// //commit
+// tm.commit();
+//
+// //Messages should be in queue
+//
+// conn2 = cf.createConnection();
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sess.createConsumer(queue1);
+// conn2.start();
+//
+// TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r1);
+// assertEquals("echidna1", r1.getText());
+//
+// TextMessage r2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r2);
+// assertEquals("echidna2", r2.getText());
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+// public void testMultipleSessionsOneTxCommitSend() throws Exception
+// {
+// //Since both resources have some RM, TM will probably use 1PC optimization
+//
+// XAConnection conn = null;
+//
+// Connection conn2 = null;
+//
+// try
+// {
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// //Create 2 sessions and enlist them
+// XASession sess1 = conn.createXASession();
+// MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
+// XASession sess2 = conn.createXASession();
+// MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
+// res1.setPreventJoining(true);
+// res2.setPreventJoining(true);
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res1);
+// tx.enlistResource(res2);
+//
+// // Send 2 messages - one from each session
+//
+// MessageProducer prod1 = sess1.createProducer(queue1);
+// MessageProducer prod2 = sess2.createProducer(queue1);
+//
+// prod1.send(sess1.createTextMessage("echidna1"));
+// prod2.send(sess2.createTextMessage("echidna2"));
+//
+// tx.delistResource(res1, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// //commit
+// tm.commit();
+//
+// //Messages should be in queue
+//
+// conn2 = cf.createConnection();
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sess.createConsumer(queue1);
+// conn2.start();
+//
+// TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r1);
+// assertEquals("echidna1", r1.getText());
+//
+// TextMessage r2 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r2);
+// assertEquals("echidna2", r2.getText());
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+//
+// }
+//
+// }
+//
+//
+// public void testMultipleSessionsOneTxRollbackSend1PCOptimization() throws Exception
+// {
+// //Since both resources have some RM, TM will probably use 1PC optimization
+//
+// XAConnection conn = null;
+//
+// Connection conn2 = null;
+//
+// try
+// {
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// //Create 2 sessions and enlist them
+// XASession sess1 = conn.createXASession();
+// XAResource res1 = sess1.getXAResource();
+// XASession sess2 = conn.createXASession();
+// XAResource res2 = sess2.getXAResource();
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res1);
+// tx.enlistResource(res2);
+//
+// // Send 2 messages - one from each session
+//
+// MessageProducer prod1 = sess1.createProducer(queue1);
+// MessageProducer prod2 = sess2.createProducer(queue1);
+//
+// prod1.send(sess1.createTextMessage("echidna1"));
+// prod2.send(sess2.createTextMessage("echidna2"));
+//
+// tx.delistResource(res1, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// //rollback
+// tm.rollback();
+//
+// //Messages should not be in queue
+//
+// conn2 = cf.createConnection();
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sess.createConsumer(queue1);
+// conn2.start();
+//
+// TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
+// assertNull(r1);
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+// public void testMultipleSessionsOneTxRollbackSend() throws Exception
+// {
+// XAConnection conn = null;
+//
+// Connection conn2 = null;
+//
+// try
+// {
+//
+// conn = cf.createXAConnection();
+// conn.start();
+//
+// tm.begin();
+//
+// //Create 2 sessions and enlist them
+// XASession sess1 = conn.createXASession();
+// MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
+// XASession sess2 = conn.createXASession();
+// MessagingXAResource res2 = (MessagingXAResource)sess2.getXAResource();
+// res1.setPreventJoining(true);
+// res2.setPreventJoining(true);
+//
+// Transaction tx = tm.getTransaction();
+// tx.enlistResource(res1);
+// tx.enlistResource(res2);
+//
+// // Send 2 messages - one from each session
+//
+// MessageProducer prod1 = sess1.createProducer(queue1);
+// MessageProducer prod2 = sess2.createProducer(queue1);
+//
+// prod1.send(sess1.createTextMessage("echidna1"));
+// prod2.send(sess2.createTextMessage("echidna2"));
+//
+// tx.delistResource(res1, XAResource.TMSUCCESS);
+// tx.delistResource(res2, XAResource.TMSUCCESS);
+//
+// //rollback
+// tm.rollback();
+//
+// //Messages should not be in queue
+//
+// conn2 = cf.createConnection();
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageConsumer cons = sess.createConsumer(queue1);
+// conn2.start();
+//
+// TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
+// assertNull(r1);
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+//
+// public void testOneSessionTwoTransactionsCommitAcknowledge() throws Exception
+// {
+// XAConnection conn = null;
+//
+// Connection conn2 = null;
+//
+// try
+// {
+// //First send 2 messages
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("jellyfish1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish2");
+// prod.send(m);
+//
+// conn = cf.createXAConnection();
+//
+// //Create a session
+// XASession sess1 = conn.createXASession();
+// XAResource res1 = sess1.getXAResource();
+//
+// conn.start();
+// MessageConsumer cons1 = sess1.createConsumer(queue1);
+//
+// tm.begin();
+//
+// Transaction tx1 = tm.getTransaction();
+// tx1.enlistResource(res1);
+//
+// //Receive one message in one tx
+//
+// TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+// assertNotNull(r1);
+// assertEquals("jellyfish1", r1.getText());
+//
+// //suspend the tx
+// Transaction suspended = tm.suspend();
+//
+// tm.begin();
+//
+// Transaction tx2 = tm.getTransaction();
+// tx2.enlistResource(res1);
+//
+// //Receive 2nd message in a different tx
+// TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+// assertNotNull(r2);
+// assertEquals("jellyfish2", r2.getText());
+//
+// tx2.delistResource(res1, XAResource.TMSUCCESS);
+//
+// //commit this transaction
+// tm.commit();
+//
+// //verify that no messages are available
+// conn2.close();
+// conn2 = cf.createConnection();
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// conn2.start();
+// MessageConsumer cons = sess.createConsumer(queue1);
+// TextMessage r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+// assertNull(r3);
+//
+// //now resume the first tx and then commit it
+// tm.resume(suspended);
+//
+// tx1.delistResource(res1, XAResource.TMSUCCESS);
+//
+// tm.commit();
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+// }
+// }
+//
+//
+// public void testOneSessionTwoTransactionsRollbackAcknowledge() throws Exception
+// {
+// XAConnection conn = null;
+//
+// Connection conn2 = null;
+//
+// try
+// {
+// //First send 2 messages
+// conn2 = cf.createConnection();
+// Session sessProducer = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessProducer.createProducer(queue1);
+// Message m = sessProducer.createTextMessage("jellyfish1");
+// prod.send(m);
+// m = sessProducer.createTextMessage("jellyfish2");
+// prod.send(m);
+//
+// conn = cf.createXAConnection();
+//
+// //Create a session
+// XASession sess1 = conn.createXASession();
+// XAResource res1 = sess1.getXAResource();
+//
+// conn.start();
+// MessageConsumer cons1 = sess1.createConsumer(queue1);
+//
+// tm.begin();
+//
+// Transaction tx1 = tm.getTransaction();
+// tx1.enlistResource(res1);
+//
+// //Receive one message in one tx
+//
+// TextMessage r1 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+// assertNotNull(r1);
+// assertEquals("jellyfish1", r1.getText());
+//
+// //suspend the tx
+// Transaction suspended = tm.suspend();
+//
+// tm.begin();
+//
+// Transaction tx2 = tm.getTransaction();
+// tx2.enlistResource(res1);
+//
+// //Receive 2nd message in a different tx
+// TextMessage r2 = (TextMessage)cons1.receive(MAX_TIMEOUT);
+// assertNotNull(r2);
+// assertEquals("jellyfish2", r2.getText());
+//
+// cons1.close();
+//
+// tx1.delistResource(res1, XAResource.TMSUCCESS);
+//
+// //rollback this transaction
+// tm.rollback();
+//
+// //verify that second message is available
+// conn2.close();
+// conn2 = cf.createConnection();
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// conn2.start();
+// MessageConsumer cons = sess.createConsumer(queue1);
+//
+// TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+//
+// assertNotNull(r3);
+// assertEquals("jellyfish2", r3.getText());
+// r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+// assertNull(r3);
+//
+//
+// //rollback the other tx
+// tm.resume(suspended);
+// tm.rollback();
+//
+// //Verify the first message is now available
+// r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r3);
+// assertEquals("jellyfish1", r3.getText());
+// r3 = (TextMessage)cons.receive(MIN_TIMEOUT);
+// assertNull(r3);
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+//
+// }
+//
+// }
+//
+//
+// public void testOneSessionTwoTransactionsCommitSend() throws Exception
+// {
+// XAConnection conn = null;
+//
+// Connection conn2 = null;
+//
+// try
+// {
+// conn = cf.createXAConnection();
+//
+// //Create a session
+// XASession sess1 = conn.createXASession();
+// XAResource res1 = sess1.getXAResource();
+//
+// MessageProducer prod1 = sess1.createProducer(queue1);
+//
+// tm.begin();
+//
+// Transaction tx1 = tm.getTransaction();
+// tx1.enlistResource(res1);
+//
+// //Send a message
+// prod1.send(sess1.createTextMessage("kangaroo1"));
+//
+// //suspend the tx
+// Transaction suspended = tm.suspend();
+//
+// tm.begin();
+//
+// //Send another message in another tx using the same session
+// Transaction tx2 = tm.getTransaction();
+// tx2.enlistResource(res1);
+//
+// //Send a message
+// prod1.send(sess1.createTextMessage("kangaroo2"));
+//
+// tx2.delistResource(res1, XAResource.TMSUCCESS);
+//
+// //commit this transaction
+// tm.commit();
+//
+// //verify only kangaroo2 message is sent
+// conn2 = cf.createConnection();
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// conn2.start();
+// MessageConsumer cons = sess.createConsumer(queue1);
+// TextMessage r1 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r1);
+// assertEquals("kangaroo2", r1.getText());
+// TextMessage r2 = (TextMessage)cons.receive(MIN_TIMEOUT);
+// assertNull(r2);
+//
+// //now resume the first tx and then commit it
+// tm.resume(suspended);
+//
+// tx1.delistResource(res1, XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// //verify that the first text message is received
+// TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r3);
+// assertEquals("kangaroo1", r3.getText());
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+//
+// }
+//
+// }
+//
+//
+// public void testOneSessionTwoTransactionsRollbackSend() throws Exception
+// {
+// XAConnection conn = null;
+//
+// Connection conn2 = null;
+//
+// try
+// {
+//
+// conn = cf.createXAConnection();
+//
+// //Create a session
+// XASession sess1 = conn.createXASession();
+// XAResource res1 = sess1.getXAResource();
+//
+// MessageProducer prod1 = sess1.createProducer(queue1);
+//
+// tm.begin();
+//
+// Transaction tx1 = tm.getTransaction();
+// tx1.enlistResource(res1);
+//
+// //Send a message
+// prod1.send(sess1.createTextMessage("kangaroo1"));
+//
+// //suspend the tx
+// Transaction suspended = tm.suspend();
+//
+// tm.begin();
+//
+// //Send another message in another tx using the same session
+// Transaction tx2 = tm.getTransaction();
+// tx2.enlistResource(res1);
+//
+// //Send a message
+// prod1.send(sess1.createTextMessage("kangaroo2"));
+//
+// tx2.delistResource(res1, XAResource.TMSUCCESS);
+//
+// //rollback this transaction
+// tm.rollback();
+//
+// //verify no messages are sent
+// conn2 = cf.createConnection();
+// Session sess = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// conn2.start();
+// MessageConsumer cons = sess.createConsumer(queue1);
+// TextMessage r1 = (TextMessage)cons.receive(MIN_TIMEOUT);
+//
+// assertNull(r1);
+//
+//
+// //now resume the first tx and then commit it
+// tm.resume(suspended);
+//
+// tx1.delistResource(res1, XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// //verify that the first text message is received
+// TextMessage r3 = (TextMessage)cons.receive(MAX_TIMEOUT);
+// assertNotNull(r3);
+// assertEquals("kangaroo1", r3.getText());
+//
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// if (conn2 != null)
+// {
+// conn2.close();
+// }
+//
+// }
+//
+// }
+//
+// // Package protected ---------------------------------------------
+//
+// // Protected -----------------------------------------------------
+//
+// // Private -------------------------------------------------------
+//
+// private void assertEqualByteArrays(byte[] b1, byte[] b2)
+// {
+// log.info("b1 length: " + b1.length + " b2 length " + b2.length);
+//
+// if (b1.length != b2.length)
+// {
+// fail("Lengths not the same");
+// }
+//
+// for (int i = 0; i < b1.length; i++)
+// {
+// if (b1[i] != b2[i])
+// {
+// fail("Not same at index " + i);
+// }
+// }
+// }
+//
+// // Inner classes -------------------------------------------------
+//
+//
+// static class DummyListener implements MessageListener
+// {
+//
+// protected Logger log = Logger.getLogger(getClass());
+//
+// public ArrayList messages = new ArrayList();
+//
+// public void onMessage(Message message)
+// {
+// log.info("Message received on DummyListener " + message);
+// messages.add(message);
+// }
+// }
+//
+// static class MockServerSessionPool implements ServerSessionPool
+// {
+// private ServerSession serverSession;
+//
+// MockServerSessionPool(Session sess)
+// {
+// serverSession = new MockServerSession(sess);
+// }
+//
+// public ServerSession getServerSession() throws JMSException
+// {
+// return serverSession;
+// }
+// }
+//
+// static class MockServerSession implements ServerSession
+// {
+// Session session;
+//
+// MockServerSession(Session sess)
+// {
+// this.session = sess;
+// }
+//
+//
+// public Session getSession() throws JMSException
+// {
+// return session;
+// }
+//
+// public void start() throws JMSException
+// {
+// session.run();
+// }
+//
+// }
+//
+//
+//
+// static class DummyXAResource implements XAResource
+// {
+// boolean failOnPrepare;
+//
+// DummyXAResource()
+// {
+// }
+//
+// DummyXAResource(boolean failOnPrepare)
+// {
+// this.failOnPrepare = failOnPrepare;
+// }
+//
+// public void commit(Xid arg0, boolean arg1) throws XAException
+// {
+// }
+//
+// public void end(Xid arg0, int arg1) throws XAException
+// {
+// }
+//
+// public void forget(Xid arg0) throws XAException
+// {
+// }
+//
+// public int getTransactionTimeout() throws XAException
+// {
+// return 0;
+// }
+//
+// public boolean isSameRM(XAResource arg0) throws XAException
+// {
+// return false;
+// }
+//
+// public int prepare(Xid arg0) throws XAException
+// {
+// if (failOnPrepare)
+// {
+// throw new XAException(XAException.XAER_RMFAIL);
+// }
+// return XAResource.XA_OK;
+// }
+//
+// public Xid[] recover(int arg0) throws XAException
+// {
+// return null;
+// }
+//
+// public void rollback(Xid arg0) throws XAException
+// {
+// }
+//
+// public boolean setTransactionTimeout(int arg0) throws XAException
+// {
+// return false;
+// }
+//
+// public void start(Xid arg0, int arg1) throws XAException
+// {
+//
+// }
+//
+// }
+
+}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSExpirationHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSExpirationHeaderTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSExpirationHeaderTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -83,7 +83,7 @@
Message m = queueProducerSession.createMessage();
queueProducer.send(m, DeliveryMode.NON_PERSISTENT, 4, 5000);
- //Delivery is asynch - need to give enough time to get to the consumer
+ //DeliveryImpl is asynch - need to give enough time to get to the consumer
Thread.sleep(2000);
Message result = queueConsumer.receive(10);
@@ -95,7 +95,7 @@
Message m = queueProducerSession.createMessage();
queueProducer.send(m, DeliveryMode.NON_PERSISTENT, 4, 1000);
- // Delivery is asynch - need to give enough time to get to the consumer
+ // DeliveryImpl is asynch - need to give enough time to get to the consumer
Thread.sleep(2000);
assertNull(queueConsumer.receive(100));
@@ -106,7 +106,7 @@
Message m = queueProducerSession.createMessage();
queueProducer.send(m, DeliveryMode.NON_PERSISTENT, 4, 1000);
- // Delivery is asynch - need to give enough time to get to the consumer
+ // DeliveryImpl is asynch - need to give enough time to get to the consumer
Thread.sleep(2000);
assertNull(queueConsumer.receiveNoWait());
@@ -117,7 +117,7 @@
Message m = queueProducerSession.createMessage();
queueProducer.send(m, DeliveryMode.NON_PERSISTENT, 4, 1000);
- // Delivery is asynch - need to give enough time to get to the consumer
+ // DeliveryImpl is asynch - need to give enough time to get to the consumer
Thread.sleep(2000);
// start the receiver thread
@@ -312,7 +312,7 @@
queueProducer.send(m, DeliveryMode.NON_PERSISTENT, 4, 1000);
- //Delivery is asynch - need to give enough time to get to the consumer
+ //DeliveryImpl is asynch - need to give enough time to get to the consumer
Thread.sleep(2000);
assertNull(queueConsumer.receive(100));
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/JMSXDeliveryCountTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -641,7 +641,7 @@
if (tm.getIntProperty("JMSXDeliveryCount") != (j + 1))
{
- log.error("Delivery count not expected value:" + (j + 1) +
+ log.error("DeliveryImpl count not expected value:" + (j + 1) +
" actual:" + tm.getIntProperty("JMSXDeliveryCount"));;
failed = true;
}
@@ -661,11 +661,6 @@
}
}
- //TODO Check that delivery count is persisted properly, local to the channel
- //Currently we are not persisting delivery count on the channel, only on the message
- //So this won't work
-
-
// Package protected ----------------------------------------------------------------------------
// Protected ------------------------------------------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -299,7 +299,7 @@
propNames.add(propName);
}
- assertEquals(8, propNames.size());
+ assertEquals(9, propNames.size());
assertTrue(propNames.contains("myBool"));
assertTrue(propNames.contains("myByte"));
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTestBase.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTestBase.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -142,13 +142,23 @@
assertEquals(m1.getJMSPriority(), m2.getJMSPriority());
int m1PropertyCount = 0, m2PropertyCount = 0;
- for(Enumeration p = m1.getPropertyNames(); p.hasMoreElements(); m1PropertyCount++)
+ for(Enumeration p = m1.getPropertyNames(); p.hasMoreElements(); )
{
- p.nextElement();
+ String name = (String)p.nextElement();
+
+ if (!name.startsWith("JMSX"))
+ {
+ m1PropertyCount++;
+ }
}
- for(Enumeration p = m2.getPropertyNames(); p.hasMoreElements(); m2PropertyCount++)
+ for(Enumeration p = m2.getPropertyNames(); p.hasMoreElements();)
{
- p.nextElement();
+ String name = (String)p.nextElement();
+
+ if (!name.startsWith("JMSX"))
+ {
+ m2PropertyCount++;
+ }
}
assertEquals(m1PropertyCount, m2PropertyCount);
@@ -158,6 +168,12 @@
boolean found = false;
String name = (String)props.nextElement();
+
+ if (name.startsWith("JMSX"))
+ {
+ //ignore
+ continue;
+ }
boolean booleanProperty = false;
try
Modified: trunk/tests/src/org/jboss/test/messaging/jms/stress/StressTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/stress/StressTestBase.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/jms/stress/StressTestBase.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -149,6 +149,6 @@
protected void tweakXASession(XASession sess)
{
- ((JBossSession)sess).getDelegate().setTreatAsNonTransactedWhenNotEnlisted(false);
+
}
}
Modified: trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -21,14 +21,39 @@
*/
package org.jboss.test.messaging.tools.container;
+import java.io.File;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+
+import javax.jms.InvalidDestinationException;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
+
import org.jboss.jms.client.JBossConnectionFactory;
+import org.jboss.jms.client.api.ClientConnectionFactory;
import org.jboss.jms.client.impl.ClientConnectionFactoryImpl;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
import org.jboss.jms.server.security.Role;
-import org.jboss.jms.tx.ResourceManagerFactory;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.*;
+import org.jboss.messaging.core.Binding;
+import org.jboss.messaging.core.Condition;
+import org.jboss.messaging.core.DestinationType;
+import org.jboss.messaging.core.MessagingServer;
+import org.jboss.messaging.core.MessagingServerManagement;
import org.jboss.messaging.core.impl.ConditionImpl;
import org.jboss.messaging.core.remoting.ServerLocator;
import org.jboss.messaging.microcontainer.JBMBootstrapServer;
@@ -39,21 +64,6 @@
import org.jboss.test.messaging.tools.jboss.MBeanConfigurationElement;
import org.jboss.tm.TransactionManagerLocator;
-import javax.jms.InvalidDestinationException;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-import javax.transaction.UserTransaction;
-import java.io.File;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.*;
-
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -651,9 +661,9 @@
//The server peer strict setting overrides the connection factory
boolean useStrict = getMessagingServer().getConfiguration().isStrictTck() || strictTck;
- ClientConnectionFactoryImpl delegate =
+ ClientConnectionFactory delegate =
new ClientConnectionFactoryImpl( getMessagingServer().getConfiguration().getMessagingServerID(),
- serverLocator.getURI(), version, false, useStrict, prefetchSize, dupsOkBatchSize, clientId);
+ serverLocator.getURI(), version, useStrict, prefetchSize, dupsOkBatchSize, clientId);
log.debug(this + " created local delegate " + delegate);
@@ -863,17 +873,6 @@
}
- public void clear() throws Exception
- {
- ResourceManagerFactory.instance.clear();
- }
-
-
- public int getResourceManagerFactorySize()
- {
- return ResourceManagerFactory.instance.size();
- }
-
// Inner classes --------------------------------------------------------------------------------
}
Modified: trunk/tests/src/org/jboss/test/messaging/tools/container/RMITestServer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/container/RMITestServer.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/tools/container/RMITestServer.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -596,18 +596,6 @@
server.setDefaultRedeliveryDelay(delay);
}
-
- public void clear() throws Exception
- {
- server.clear();
- }
-
-
- public int getResourceManagerFactorySize()
- {
- return server.getResourceManagerFactorySize();
- }
-
public InitialContext getInitialContext() throws Exception
{
Hashtable env = new Hashtable();
Modified: trunk/tests/src/org/jboss/test/messaging/tools/container/Server.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/container/Server.java 2008-01-25 13:59:59 UTC (rev 3630)
+++ trunk/tests/src/org/jboss/test/messaging/tools/container/Server.java 2008-01-26 14:56:42 UTC (rev 3631)
@@ -301,8 +301,4 @@
void setRedeliveryDelayOnDestination(String dest, boolean queue, long delay) throws Exception;
void setDefaultRedeliveryDelay(long delay) throws Exception;
-
- void clear() throws Exception;
-
- int getResourceManagerFactorySize() throws Exception;
}
More information about the jboss-cvs-commits
mailing list