[jboss-cvs] JBoss Messaging SVN: r3412 - in branches/Branch_New_Persistence: src/main/org/jboss/jms/client and 34 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 5 14:41:48 EST 2007
Author: timfox
Date: 2007-12-05 14:41:47 -0500 (Wed, 05 Dec 2007)
New Revision: 3412
Added:
branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/
branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/
branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Message.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/MessageReference.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/MessagingComponent.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedListImpl.java
Removed:
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/BytesMessageProxy.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/MapMessageProxy.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/MessageProxy.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/ObjectMessageProxy.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/StreamMessageProxy.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/TextMessageProxy.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Filter.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Message.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessageReference.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessagingComponent.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/ChannelSupport.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/PagingChannelSupport.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/CoreMessage.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/MessageFactory.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/MessageSupport.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/SimpleMessageReference.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/jmx/JDBCPersistenceManagerService.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/BasicPriorityLinkedList.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/BrokenReceiver.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/JDBCPersistenceManagerTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/MessagingQueueTestBase.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/NonRecoverableMessagingQueueTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/RecoverableMessagingQueueTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/RoundRobinDistributorTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleChannel.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleDeliveryObserver.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleFilter.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleFilterFactory.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/message/
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/paging/
Modified:
branches/Branch_New_Persistence/.classpath
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/JBossConnectionConsumer.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/JBossSession.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/BrowserAspect.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/ClientConsumer.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/ProducerAspect.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/SessionAspect.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/remoting/CallbackManager.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/client/state/SessionState.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/BrowserEndpoint.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/DeliveryInfo.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/SessionDelegate.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/SessionEndpoint.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossBytesMessage.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMapMessage.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMessage.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossObjectMessage.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossStreamMessage.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossTextMessage.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectionFactoryManager.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectionManager.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectorManager.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/DestinationManager.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/bridge/Bridge.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/bridge/BridgeService.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/DestinationServiceSupport.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedDestination.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedQueue.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedTopic.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/SessionInternalEndpoint.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/advised/BrowserAdvised.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/advised/SessionAdvised.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/messagecounter/MessageCounterManager.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManagerService.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/plugin/contract/JMSUserManager.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/Selector.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ClientTransaction.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ResourceManager.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageBlockResponse.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageResponse.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/ClientDelivery.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/SessionSendRequest.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Channel.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Delivery.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/FilterFactory.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MemoryManager.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessageStore.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/PersistenceManager.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/PostOffice.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Queue.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Receiver.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/ClusterRoundRobinDistributor.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/FirstReceiverDistributor.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/IDManager.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/JDBCSupport.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/MessagingQueue.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/RoundRobinDistributor.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/SimpleDelivery.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/clusterconnection/MessageSucker.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/SimpleMessageStore.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageHolder.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageRequest.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/RequestTarget.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/jmx/MessagingPostOfficeService.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedList.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/postoffice/ClusteredPostOfficeTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/BytesMessagePersistenceManagerTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/MapMessagePersistenceManagerTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/MessagePersistenceManagerTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/ObjectMessagePersistenceManagerTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/StreamMessagePersistenceManagerTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/TextMessagePersistenceManagerTest.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/util/CoreMessageFactory.java
branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/util/prioritylinkedlist/PriorityLinkedListTest.java
Log:
First stab of new persistence and core refactoring
Modified: branches/Branch_New_Persistence/.classpath
===================================================================
--- branches/Branch_New_Persistence/.classpath 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/.classpath 2007-12-05 19:41:47 UTC (rev 3412)
@@ -60,5 +60,6 @@
<classpathentry kind="lib" path="thirdparty/jbossas/core-libs/lib/jboss-local-jdbc.jar"/>
<classpathentry kind="lib" path="thirdparty/jbossas/core-libs/lib/jboss-xml-binding.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="/home/tim/work/je-3.2.44/lib/je-3.2.44.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/JBossConnectionConsumer.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/JBossConnectionConsumer.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/JBossConnectionConsumer.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -34,12 +34,11 @@
import org.jboss.jms.client.delegate.DelegateSupport;
import org.jboss.jms.client.state.ConsumerState;
-import org.jboss.jms.client.state.SessionState;
import org.jboss.jms.delegate.ConnectionDelegate;
import org.jboss.jms.delegate.ConsumerDelegate;
import org.jboss.jms.delegate.SessionDelegate;
import org.jboss.jms.destination.JBossDestination;
-import org.jboss.jms.message.MessageProxy;
+import org.jboss.jms.message.JBossMessage;
import org.jboss.logging.Logger;
import org.jboss.messaging.util.MessageQueueNameHelper;
@@ -287,7 +286,7 @@
for (int i = 0; i < mesList.size(); i++)
{
- MessageProxy m = (MessageProxy)mesList.get(i);
+ JBossMessage m = (JBossMessage)mesList.get(i);
session.addAsfMessage(m, consumerID, queueName, maxDeliveries, sess, shouldAck);
if (trace) { log.trace("added " + m + " to session"); }
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/JBossSession.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/JBossSession.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/JBossSession.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -64,7 +64,7 @@
import org.jboss.jms.destination.JBossTemporaryQueue;
import org.jboss.jms.destination.JBossTemporaryTopic;
import org.jboss.jms.destination.JBossTopic;
-import org.jboss.jms.message.MessageProxy;
+import org.jboss.jms.message.JBossMessage;
import org.jboss.logging.Logger;
/**
@@ -462,7 +462,7 @@
* This method is used by the JBossConnectionConsumer to load up the session
* with messages to be processed by the session's run() method
*/
- void addAsfMessage(MessageProxy m, String consumerID, String queueName, int maxDeliveries,
+ void addAsfMessage(JBossMessage m, String consumerID, String queueName, int maxDeliveries,
SessionDelegate connectionConsumerSession, boolean shouldAck)
{
delegate.addAsfMessage(m, consumerID, queueName, maxDeliveries, connectionConsumerSession, shouldAck);
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/BrowserAspect.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/BrowserAspect.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/BrowserAspect.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -22,8 +22,9 @@
package org.jboss.jms.client.container;
import javax.jms.JMSException;
-import javax.jms.Message;
+import org.jboss.messaging.newcore.intf.Message;
+
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.jms.delegate.BrowserDelegate;
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/ClientConsumer.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/ClientConsumer.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/ClientConsumer.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -35,11 +35,11 @@
import org.jboss.jms.delegate.DefaultCancel;
import org.jboss.jms.delegate.DeliveryInfo;
import org.jboss.jms.delegate.SessionDelegate;
-import org.jboss.jms.message.MessageProxy;
+import org.jboss.jms.message.JBossMessage;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Message;
+import org.jboss.messaging.newcore.intf.Message;
import org.jboss.messaging.util.Future;
-import org.jboss.messaging.util.prioritylinkedlist.BasicPriorityLinkedList;
+import org.jboss.messaging.util.prioritylinkedlist.PriorityLinkedListImpl;
import org.jboss.messaging.util.prioritylinkedlist.PriorityLinkedList;
import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
@@ -70,33 +70,31 @@
trace = log.isTraceEnabled();
}
- private static boolean checkExpiredOrReachedMaxdeliveries(MessageProxy proxy,
+ private static boolean checkExpiredOrReachedMaxdeliveries(JBossMessage msg,
SessionDelegate del,
int maxDeliveries, boolean shouldCancel)
{
- Message msg = proxy.getMessage();
+ boolean expired = msg.getCoreMessage().isExpired();
- boolean expired = msg.isExpired();
+ boolean reachedMaxDeliveries = msg.getDeliveryCount() == maxDeliveries;
- boolean reachedMaxDeliveries = proxy.getDeliveryCount() == maxDeliveries;
-
if (expired || reachedMaxDeliveries)
{
if (trace)
{
if (expired)
{
- log.trace(proxy.getMessage() + " has expired, cancelling to server");
+ log.trace(msg + " has expired, cancelling to server");
}
else
{
- log.trace(proxy.getMessage() + " has reached maximum delivery number " + maxDeliveries +", cancelling to server");
+ log.trace(msg + " has reached maximum delivery number " + maxDeliveries +", cancelling to server");
}
}
if (shouldCancel)
{
- final Cancel cancel = new DefaultCancel(proxy.getDeliveryId(), proxy.getDeliveryCount(),
+ final Cancel cancel = new DefaultCancel(msg.getDeliveryId(), msg.getDeliveryCount(),
expired, reachedMaxDeliveries);
try
{
@@ -122,7 +120,7 @@
String consumerID,
String queueName,
boolean isConnectionConsumer,
- MessageProxy m,
+ JBossMessage m,
int ackMode,
int maxDeliveries,
SessionDelegate connectionConsumerSession,
@@ -160,9 +158,7 @@
}
catch (RuntimeException e)
{
- long id = m.getMessage().getMessageID();
-
- log.error("RuntimeException was thrown from onMessage, " + id + " will be redelivered", e);
+ log.error("RuntimeException was thrown from onMessage, " + m.getJMSMessageID() + " will be redelivered", e);
// See JMS 1.1 spec 4.5.2
@@ -233,7 +229,7 @@
this.maxBufferSize = bufferSize;
this.minBufferSize = bufferSize / 2;
- buffer = new BasicPriorityLinkedList(10);
+ buffer = new PriorityLinkedListImpl(10);
isConnectionConsumer = isCC;
this.ackMode = ackMode;
this.sessionDelegate = sess;
@@ -261,7 +257,7 @@
*
* @param message The message
*/
- public void handleMessage(final Object message) throws Exception
+ public void handleMessage(final JBossMessage message) throws Exception
{
//TODO - we temporarily need to execute on a different thread to avoid a deadlock situation in
// failover where a message is sent then the valve is locked, and the message send cause
@@ -318,10 +314,10 @@
for(Iterator i = buffer.iterator(); i.hasNext();)
{
- MessageProxy mp = (MessageProxy)i.next();
+ JBossMessage message = (JBossMessage)i.next();
DefaultCancel cancel =
- new DefaultCancel(mp.getDeliveryId(), mp.getDeliveryCount(), false, false);
+ new DefaultCancel(message.getDeliveryId(), message.getDeliveryCount(), false, false);
cancels.add(cancel);
}
@@ -380,9 +376,9 @@
* or null if one is not immediately available. Returns null if the consumer is
* concurrently closed.
*/
- public MessageProxy receive(long timeout) throws JMSException
+ public JBossMessage receive(long timeout) throws JMSException
{
- MessageProxy m = null;
+ JBossMessage m = null;
synchronized (mainLock)
{
@@ -540,11 +536,11 @@
this.consumerID = consumerId;
}
- public void addToFrontOfBuffer(MessageProxy proxy) throws Exception
+ public void addToFrontOfBuffer(JBossMessage message) throws Exception
{
synchronized (mainLock)
{
- buffer.addFirst(proxy, proxy.getJMSPriority());
+ buffer.addFirst(message, message.getJMSPriority());
messageAdded();
}
@@ -777,7 +773,7 @@
}
}
- private MessageProxy getMessage(long timeout)
+ private JBossMessage getMessage(long timeout)
{
if (timeout == -1)
{
@@ -821,11 +817,11 @@
}
}
- MessageProxy m = null;
+ JBossMessage m = null;
if (!closed && !buffer.isEmpty())
{
- m = (MessageProxy)buffer.removeFirst();
+ m = (JBossMessage)buffer.removeFirst();
}
return m;
@@ -860,9 +856,9 @@
{
private int token;
- private Object message;
+ private JBossMessage message;
- HandleMessageRunnable(int token, Object message)
+ HandleMessageRunnable(int token, JBossMessage message)
{
this.token = token;
@@ -873,10 +869,8 @@
{
try
{
- MessageProxy proxy = (MessageProxy) message;
+ if (trace) { log.trace(this + " receiving message " + message + " from the remoting layer"); }
- if (trace) { log.trace(this + " receiving message " + proxy + " from the remoting layer"); }
-
synchronized (mainLock)
{
if (closed)
@@ -893,14 +887,14 @@
return;
}
- proxy.setSessionDelegate(sessionDelegate, isConnectionConsumer);
+ message.setSessionDelegate(sessionDelegate, isConnectionConsumer);
- proxy.getMessage().doBeforeReceive();
+ message.doBeforeReceive();
//Add it to the buffer
- buffer.addLast(proxy, proxy.getJMSPriority());
+ buffer.addLast(message, message.getJMSPriority());
- lastDeliveryId = proxy.getDeliveryId();
+ lastDeliveryId = message.getDeliveryId();
if (trace) { log.trace(this + " added message(s) to the buffer are now " + buffer.size() + " messages"); }
@@ -926,7 +920,7 @@
{
public void run()
{
- MessageProxy mp = null;
+ JBossMessage message = null;
MessageListener theListener = null;
@@ -945,7 +939,7 @@
// remove a message from the buffer
- mp = (MessageProxy)buffer.removeFirst();
+ message = (JBossMessage)buffer.removeFirst();
}
/*
@@ -958,12 +952,12 @@
* Solution - don't use a session executor - have a sesion thread instead much nicer
*/
- if (mp != null)
+ if (message != null)
{
try
{
callOnMessage(sessionDelegate, theListener, consumerID, queueName,
- false, mp, ackMode, maxDeliveries, null, shouldAck);
+ false, message, ackMode, maxDeliveries, null, shouldAck);
if (trace) { log.trace("Called callonMessage"); }
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/ProducerAspect.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/ProducerAspect.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/ProducerAspect.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -38,13 +38,13 @@
import org.jboss.jms.client.state.SessionState;
import org.jboss.jms.delegate.ConnectionDelegate;
import org.jboss.jms.delegate.SessionDelegate;
+import org.jboss.jms.destination.JBossDestination;
import org.jboss.jms.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.message.MessageProxy;
import org.jboss.logging.Logger;
/**
@@ -88,7 +88,7 @@
int priority = ((Integer)args[3]).intValue();
long timeToLive = ((Long)args[4]).longValue();
- boolean keepID = args.length>5? ((Boolean)args[5]).booleanValue() : false;
+ boolean keepID = args.length > 5 ? ((Boolean)args[5]).booleanValue() : false;
// configure the message for sending, using attributes stored as metadata
@@ -173,14 +173,15 @@
// Generate the message id
ConnectionState connectionState = (ConnectionState)sessionState.getParent();
- long id = -1;
+ //long id = -1;
- JBossMessage messageToSend;
+ JBossMessage jbm;
+
boolean foreign = false;
- if (!(m instanceof MessageProxy))
+ if (!(m instanceof JBossMessage))
{
- // it's a foreign message
+ // it's a foreign message - convert to a JBossMessage
foreign = true;
@@ -190,82 +191,76 @@
// create a matching JBossMessage Type from JMS Type
if(m instanceof BytesMessage)
{
- messageToSend = new JBossBytesMessage((BytesMessage)m,0);
+ jbm = new JBossBytesMessage((BytesMessage)m);
}
else if(m instanceof MapMessage)
{
- messageToSend = new JBossMapMessage((MapMessage)m,0);
+ jbm = new JBossMapMessage((MapMessage)m);
}
else if(m instanceof ObjectMessage)
{
- messageToSend = new JBossObjectMessage((ObjectMessage)m,0);
+ jbm = new JBossObjectMessage((ObjectMessage)m);
}
else if(m instanceof StreamMessage)
{
- messageToSend = new JBossStreamMessage((StreamMessage)m,0);
+ jbm = new JBossStreamMessage((StreamMessage)m);
}
else if(m instanceof TextMessage)
{
- messageToSend = new JBossTextMessage((TextMessage)m,0);
+ jbm = new JBossTextMessage((TextMessage)m);
}
else
{
- messageToSend = new JBossMessage(m, 0);
+ jbm = new JBossMessage(m);
}
-
- messageToSend.setJMSMessageID(null);
-
- //We must set the destination *after* converting from foreign message
- messageToSend.setJMSDestination(destination);
- if(connectionState.getRemotingConnection().isStrictTck())
- {
- m.setJMSDestination(destination);
- }
}
else
{
- // get the actual message
- MessageProxy proxy = (MessageProxy)m;
-
- m.setJMSDestination(destination);
-
- if (keepID)
- {
- id = proxy.getMessage().getMessageID();
- }
-
- //The following line executed on the proxy should cause a copy to occur
- //if it is necessary
- proxy.setJMSMessageID(null);
-
- //Get the underlying message
- messageToSend = proxy.getMessage();
-
- proxy.beforeSend();
+ jbm = (JBossMessage)m;
}
- // Set the new id
-
+ //We must set the destination *after* converting from foreign message
+ jbm.setJMSDestination(destination);
+
if (!keepID)
{
- id = connectionState.getIdGenerator().getId((ConnectionDelegate)connectionState.getDelegate());
+ // Generate a new id
+
+ long id = connectionState.getIdGenerator().getId((ConnectionDelegate)connectionState.getDelegate());
+
+ jbm.getCoreMessage().setMessageID(id);
}
- messageToSend.setMessageId(id);
-
- // This only really used for BytesMessages and StreamMessages to reset their state
- messageToSend.doBeforeSend();
-
// now that we know the messageID, set it also on the foreign message, if is the case
if (foreign)
{
- m.setJMSMessageID(messageToSend.getJMSMessageID());
+ m.setJMSMessageID(jbm.getJMSMessageID());
}
-
- // we now invoke the send(Message) method on the session, which will eventually be fielded
- // by connection endpoint
- ((SessionDelegate)sessionState.getDelegate()).send(messageToSend, false);
+ //FIXME - temp kludge - will be removed when refactoring is complete
+ StringBuffer buff = new StringBuffer();
+
+ JBossDestination jbdest = (JBossDestination)destination;
+
+ if (jbdest.isQueue())
+ {
+ buff.append('Q');
+ }
+ else if (jbdest.isDirect())
+ {
+ buff.append('D');
+ }
+ else if (jbdest.isTopic())
+ {
+ buff.append('T');
+ }
+ buff.append(jbdest.getName());
+
+ jbm.getCoreMessage().setDestination(buff.toString());
+
+ // send the message
+ ((SessionDelegate)sessionState.getDelegate()).send(jbm.getCoreMessage(), false);
+
return null;
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/SessionAspect.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/SessionAspect.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/container/SessionAspect.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -46,18 +46,12 @@
import org.jboss.jms.delegate.DeliveryInfo;
import org.jboss.jms.delegate.SessionDelegate;
import org.jboss.jms.destination.JBossDestination;
-import org.jboss.jms.message.BytesMessageProxy;
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.message.MapMessageProxy;
-import org.jboss.jms.message.MessageProxy;
-import org.jboss.jms.message.ObjectMessageProxy;
-import org.jboss.jms.message.StreamMessageProxy;
-import org.jboss.jms.message.TextMessageProxy;
import org.jboss.jms.tx.LocalTx;
import org.jboss.jms.tx.ResourceManager;
import org.jboss.logging.Logger;
@@ -508,7 +502,7 @@
for (int i = toRedeliver.size() - 1; i >= 0; i--)
{
DeliveryInfo info = (DeliveryInfo)toRedeliver.get(i);
- MessageProxy proxy = info.getMessageProxy();
+ JBossMessage message = info.getMessage();
ClientConsumer handler = state.getCallbackHandler(info.getConsumerId());
@@ -528,7 +522,7 @@
{
if (trace) { log.trace("Adding proxy back to front of buffer"); }
- handler.addToFrontOfBuffer(proxy);
+ handler.addToFrontOfBuffer(message);
}
}
@@ -649,28 +643,22 @@
public Object handleCreateMessage(Invocation invocation) throws Throwable
{
- JBossMessage jbm = new JBossMessage(0);
-
- return new MessageProxy(jbm);
+ return new JBossMessage();
}
public Object handleCreateBytesMessage(Invocation invocation) throws Throwable
{
- JBossBytesMessage jbm = new JBossBytesMessage(0);
-
- return new BytesMessageProxy(jbm);
+ return new JBossBytesMessage();
}
public Object handleCreateMapMessage(Invocation invocation) throws Throwable
{
- JBossMapMessage jbm = new JBossMapMessage(0);
-
- return new MapMessageProxy(jbm);
+ return new JBossMapMessage();
}
public Object handleCreateObjectMessage(Invocation invocation) throws Throwable
{
- JBossObjectMessage jbm = new JBossObjectMessage(0);
+ JBossObjectMessage jbm = new JBossObjectMessage();
MethodInvocation mi = (MethodInvocation)invocation;
@@ -679,19 +667,17 @@
jbm.setObject((Serializable)mi.getArguments()[0]);
}
- return new ObjectMessageProxy(jbm);
+ return jbm;
}
public Object handleCreateStreamMessage(Invocation invocation) throws Throwable
{
- JBossStreamMessage jbm = new JBossStreamMessage(0);
-
- return new StreamMessageProxy(jbm);
+ return new JBossStreamMessage();
}
public Object handleCreateTextMessage(Invocation invocation) throws Throwable
{
- JBossTextMessage jbm = new JBossTextMessage(0);
+ JBossTextMessage jbm = new JBossTextMessage();
MethodInvocation mi = (MethodInvocation)invocation;
@@ -700,7 +686,7 @@
jbm.setText((String)mi.getArguments()[0]);
}
- return new TextMessageProxy(jbm);
+ return jbm;
}
public Object handleSetMessageListener(Invocation invocation) throws Throwable
@@ -753,7 +739,7 @@
// Load the session with a message to be processed during a subsequent call to run()
- MessageProxy m = (MessageProxy)mi.getArguments()[0];
+ JBossMessage m = (JBossMessage)mi.getArguments()[0];
String theConsumerID = (String)mi.getArguments()[1];
String queueName = (String)mi.getArguments()[2];
int maxDeliveries = ((Integer)mi.getArguments()[3]).intValue();
@@ -861,7 +847,7 @@
SessionDelegate sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : sess;
sessionToUse.cancelDelivery(new DefaultCancel(delivery.getDeliveryID(),
- delivery.getMessageProxy().getDeliveryCount(), false, false));
+ delivery.getMessage().getDeliveryCount(), false, false));
}
}
@@ -875,8 +861,8 @@
if (ack.isShouldAck())
{
- DefaultCancel cancel = new DefaultCancel(ack.getMessageProxy().getDeliveryId(),
- ack.getMessageProxy().getDeliveryCount(),
+ DefaultCancel cancel = new DefaultCancel(ack.getMessage().getDeliveryId(),
+ ack.getMessage().getDeliveryCount(),
false, false);
cancels.add(cancel);
@@ -934,7 +920,7 @@
private static class AsfMessageHolder
{
- private MessageProxy msg;
+ private JBossMessage msg;
private String consumerID;
private String queueName;
private int maxDeliveries;
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -29,7 +29,6 @@
import org.jboss.jms.client.state.ConnectionState;
import org.jboss.jms.client.state.HierarchicalState;
import org.jboss.jms.delegate.BrowserDelegate;
-import org.jboss.jms.message.JBossMessage;
import org.jboss.jms.wireformat.BrowserHasNextMessageRequest;
import org.jboss.jms.wireformat.BrowserNextMessageBlockRequest;
import org.jboss.jms.wireformat.BrowserNextMessageRequest;
@@ -37,6 +36,7 @@
import org.jboss.jms.wireformat.CloseRequest;
import org.jboss.jms.wireformat.ClosingRequest;
import org.jboss.jms.wireformat.RequestSupport;
+import org.jboss.messaging.newcore.intf.Message;
/**
* The client-side Browser delegate class.
@@ -127,18 +127,18 @@
return ((Boolean)doInvoke(client, req)).booleanValue();
}
- public JBossMessage nextMessage() throws JMSException
+ public Message nextMessage() throws JMSException
{
RequestSupport req = new BrowserNextMessageRequest(id, version);
- return (JBossMessage)doInvoke(client, req);
+ return (Message)doInvoke(client, req);
}
- public JBossMessage[] nextMessageBlock(int maxMessages) throws JMSException
+ public Message[] nextMessageBlock(int maxMessages) throws JMSException
{
RequestSupport req = new BrowserNextMessageBlockRequest(id, version, maxMessages);
- return (JBossMessage[])doInvoke(client, req);
+ return (Message[])doInvoke(client, req);
}
// Streamable implementation ----------------------------------------------------------
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -44,13 +44,12 @@
import org.jboss.jms.destination.JBossDestination;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
-import org.jboss.jms.message.BytesMessageProxy;
+import org.jboss.jms.message.JBossBytesMessage;
+import org.jboss.jms.message.JBossMapMessage;
import org.jboss.jms.message.JBossMessage;
-import org.jboss.jms.message.MapMessageProxy;
-import org.jboss.jms.message.MessageProxy;
-import org.jboss.jms.message.ObjectMessageProxy;
-import org.jboss.jms.message.StreamMessageProxy;
-import org.jboss.jms.message.TextMessageProxy;
+import org.jboss.jms.message.JBossObjectMessage;
+import org.jboss.jms.message.JBossStreamMessage;
+import org.jboss.jms.message.JBossTextMessage;
import org.jboss.jms.wireformat.CloseRequest;
import org.jboss.jms.wireformat.ClosingRequest;
import org.jboss.jms.wireformat.RequestSupport;
@@ -69,6 +68,8 @@
import org.jboss.jms.wireformat.SessionUnsubscribeRequest;
import org.jboss.logging.Logger;
+import org.jboss.messaging.newcore.intf.Message;
+
/**
* The client-side Session delegate class.
*
@@ -224,7 +225,7 @@
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
- public BytesMessageProxy createBytesMessage() throws JMSException
+ public JBossBytesMessage createBytesMessage() throws JMSException
{
throw new IllegalStateException("This invocation should not be handled here!");
}
@@ -245,7 +246,7 @@
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
- public MapMessageProxy createMapMessage() throws JMSException
+ public JBossMapMessage createMapMessage() throws JMSException
{
throw new IllegalStateException("This invocation should not be handled here!");
}
@@ -254,7 +255,7 @@
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
- public MessageProxy createMessage() throws JMSException
+ public JBossMessage createMessage() throws JMSException
{
throw new IllegalStateException("This invocation should not be handled here!");
}
@@ -263,7 +264,7 @@
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
- public ObjectMessageProxy createObjectMessage() throws JMSException
+ public JBossObjectMessage createObjectMessage() throws JMSException
{
throw new IllegalStateException("This invocation should not be handled here!");
}
@@ -272,7 +273,7 @@
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
- public ObjectMessageProxy createObjectMessage(Serializable object) throws JMSException
+ public JBossObjectMessage createObjectMessage(Serializable object) throws JMSException
{
throw new IllegalStateException("This invocation should not be handled here!");
}
@@ -297,7 +298,7 @@
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
- public StreamMessageProxy createStreamMessage() throws JMSException
+ public JBossStreamMessage createStreamMessage() throws JMSException
{
throw new IllegalStateException("This invocation should not be handled here!");
}
@@ -306,7 +307,7 @@
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
- public TextMessageProxy createTextMessage() throws JMSException
+ public JBossTextMessage createTextMessage() throws JMSException
{
throw new IllegalStateException("This invocation should not be handled here!");
}
@@ -315,7 +316,7 @@
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
- public TextMessageProxy createTextMessage(String text) throws JMSException
+ public JBossTextMessage createTextMessage(String text) throws JMSException
{
throw new IllegalStateException("This invocation should not be handled here!");
}
@@ -444,13 +445,13 @@
* This invocation should either be handled by the client-side interceptor chain or by the
* server-side endpoint.
*/
- public void addAsfMessage(MessageProxy m, String consumerID, String queueName, int maxDeliveries,
+ public void addAsfMessage(JBossMessage m, String consumerID, String queueName, int maxDeliveries,
SessionDelegate connectionConsumerSession, boolean shouldAck)
{
throw new IllegalStateException("This invocation should not be handled here!");
}
- public void send(JBossMessage m, boolean checkForDuplicates) throws JMSException
+ public void send(Message m, boolean checkForDuplicates) throws JMSException
{
long seq;
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/remoting/CallbackManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/remoting/CallbackManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/remoting/CallbackManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,13 +24,11 @@
import java.util.Map;
import org.jboss.jms.client.container.ClientConsumer;
-import org.jboss.jms.client.delegate.ClientConnectionDelegate;
import org.jboss.jms.message.JBossMessage;
-import org.jboss.jms.message.MessageProxy;
import org.jboss.jms.wireformat.ClientDelivery;
import org.jboss.jms.wireformat.ConnectionFactoryUpdate;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Message;
+import org.jboss.messaging.newcore.intf.Message;
import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.HandleCallbackException;
import org.jboss.remoting.callback.InvokerCallbackHandler;
@@ -86,8 +84,8 @@
Message msg = dr.getMessage();
- MessageProxy proxy = JBossMessage.
- createThinDelegate(dr.getDeliveryId(), (JBossMessage)msg, dr.getDeliveryCount());
+ //Wrap in a JMS message
+ JBossMessage jbm = JBossMessage.createMessage(msg, dr.getDeliveryId(), dr.getDeliveryCount());
ClientConsumer handler =
(ClientConsumer)callbackHandlers.get(dr.getConsumerId());
@@ -102,7 +100,7 @@
try
{
- handler.handleMessage(proxy);
+ handler.handleMessage(jbm);
}
catch (Exception e)
{
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/client/state/SessionState.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/client/state/SessionState.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/client/state/SessionState.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -295,7 +295,7 @@
for(Iterator i = getClientAckList().iterator(); i.hasNext(); )
{
DeliveryInfo info = (DeliveryInfo)i.next();
- if (!info.getMessageProxy().getMessage().isReliable())
+ if (!info.getMessage().getCoreMessage().isReliable())
{
i.remove();
log.trace("removed non persistent delivery " + info);
@@ -309,7 +309,7 @@
DeliveryInfo autoAck = getAutoAckInfo();
if (autoAck != null)
{
- if (!autoAck.getMessageProxy().getMessage().isReliable())
+ if (!autoAck.getMessage().getCoreMessage().isReliable())
{
// unreliable, discard
setAutoAckInfo(null);
@@ -340,8 +340,8 @@
{
DeliveryInfo del = (DeliveryInfo)i.next();
DeliveryRecovery recInfo =
- new DeliveryRecovery(del.getMessageProxy().getDeliveryId(),
- del.getMessageProxy().getMessage().getMessageID(),
+ new DeliveryRecovery(del.getMessage().getDeliveryId(),
+ del.getMessage().getCoreMessage().getMessageID(),
del.getQueueName());
recoveryInfos.add(recInfo);
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/BrowserEndpoint.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/BrowserEndpoint.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/BrowserEndpoint.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,7 +24,7 @@
import javax.jms.JMSException;
import org.jboss.jms.client.Closeable;
-import org.jboss.jms.message.JBossMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
* Represents the set of methods from the BrowserDelegate that are handled on the server. The rest
@@ -45,9 +45,9 @@
*/
void reset() throws JMSException;
- JBossMessage nextMessage() throws JMSException;
+ Message nextMessage() throws JMSException;
boolean hasNextMessage() throws JMSException;
- JBossMessage[] nextMessageBlock(int maxMessages) throws JMSException;
+ Message[] nextMessageBlock(int maxMessages) throws JMSException;
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/DeliveryInfo.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/DeliveryInfo.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/DeliveryInfo.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,7 +21,7 @@
*/
package org.jboss.jms.delegate;
-import org.jboss.jms.message.MessageProxy;
+import org.jboss.jms.message.JBossMessage;
/**
* Struct like class for holding information regarding a delivery
@@ -44,7 +44,7 @@
//consumer gets the message
private String consumerId;
- private MessageProxy msg;
+ private JBossMessage msg;
//For messages in non durable subscriptions - there is no need to ack on the server
private boolean shouldAck;
@@ -62,7 +62,7 @@
// Constructors --------------------------------------------------
- public DeliveryInfo(MessageProxy msg, String consumerId, String queueName,
+ public DeliveryInfo(JBossMessage msg, String consumerId, String queueName,
SessionDelegate connectionConsumerSession, boolean shouldAck)
{
this.msg = msg;
@@ -88,7 +88,7 @@
return consumerId;
}
- public MessageProxy getMessageProxy()
+ public JBossMessage getMessage()
{
return msg;
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/SessionDelegate.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/SessionDelegate.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/SessionDelegate.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -29,12 +29,12 @@
import javax.transaction.xa.XAResource;
import org.jboss.jms.destination.JBossDestination;
-import org.jboss.jms.message.BytesMessageProxy;
-import org.jboss.jms.message.MapMessageProxy;
-import org.jboss.jms.message.MessageProxy;
-import org.jboss.jms.message.ObjectMessageProxy;
-import org.jboss.jms.message.StreamMessageProxy;
-import org.jboss.jms.message.TextMessageProxy;
+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;
/**
* Represents the minimal set of operations to provide session functionality.
@@ -48,21 +48,21 @@
*/
public interface SessionDelegate extends SessionEndpoint
{
- MessageProxy createMessage() throws JMSException;
+ JBossMessage createMessage() throws JMSException;
- BytesMessageProxy createBytesMessage() throws JMSException;
+ JBossBytesMessage createBytesMessage() throws JMSException;
- MapMessageProxy createMapMessage() throws JMSException;
+ JBossMapMessage createMapMessage() throws JMSException;
- ObjectMessageProxy createObjectMessage() throws JMSException;
+ JBossObjectMessage createObjectMessage() throws JMSException;
- ObjectMessageProxy createObjectMessage(Serializable object) throws JMSException;
+ JBossObjectMessage createObjectMessage(Serializable object) throws JMSException;
- StreamMessageProxy createStreamMessage() throws JMSException;
+ JBossStreamMessage createStreamMessage() throws JMSException;
- TextMessageProxy createTextMessage() throws JMSException;
+ JBossTextMessage createTextMessage() throws JMSException;
- TextMessageProxy createTextMessage(String text) throws JMSException;
+ JBossTextMessage createTextMessage(String text) throws JMSException;
void preDeliver(DeliveryInfo deliveryInfo) throws JMSException;
@@ -76,7 +76,7 @@
XAResource getXAResource();
- void addAsfMessage(MessageProxy m, String consumerID, String queueName,
+ void addAsfMessage(JBossMessage m, String consumerID, String queueName,
int maxDeliveries, SessionDelegate connectionConsumerDelegate,
boolean shouldAck);
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/SessionEndpoint.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/SessionEndpoint.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/delegate/SessionEndpoint.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,7 +21,6 @@
*/
package org.jboss.jms.delegate;
-
import java.util.List;
import javax.jms.JMSException;
@@ -30,7 +29,7 @@
import org.jboss.jms.destination.JBossDestination;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
-import org.jboss.jms.message.JBossMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -111,7 +110,7 @@
* @param message The message to send
* @throws JMSException
*/
- void send(JBossMessage message, boolean checkForDuplicates) throws JMSException;
+ void send(Message message, boolean checkForDuplicates) throws JMSException;
/**
* Send delivery info to the server so the delivery lists can be repopulated. Used only in
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/BytesMessageProxy.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/BytesMessageProxy.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/BytesMessageProxy.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,302 +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.message;
-
-import javax.jms.BytesMessage;
-import javax.jms.JMSException;
-import javax.jms.MessageNotReadableException;
-import javax.jms.MessageNotWriteableException;
-
-/**
- *
- * Thin proxy for a JBossBytesMessage
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * BytesMessageProxy.java,v 1.1 2006/03/08 08:00:34 timfox Exp
- */
-public class BytesMessageProxy extends MessageProxy implements BytesMessage
-{
- private static final long serialVersionUID = -9121097962625801946L;
-
- public BytesMessageProxy(long deliveryId, JBossBytesMessage message, int deliveryCount)
- {
- super(deliveryId, message, deliveryCount);
- }
-
- public BytesMessageProxy(JBossBytesMessage message)
- {
- super(message);
- }
-
- public long getBodyLength() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).getBodyLength();
- }
-
- public boolean readBoolean() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readBoolean();
- }
-
- public byte readByte() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readByte();
- }
-
- public int readUnsignedByte() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readUnsignedByte();
- }
-
- public short readShort() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readShort();
- }
-
- public int readUnsignedShort() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readUnsignedShort();
- }
-
- public char readChar() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readChar();
- }
-
- public int readInt() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readInt();
- }
-
- public long readLong() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readLong();
- }
-
- public float readFloat() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readFloat();
- }
-
- public double readDouble() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readDouble();
- }
-
- public String readUTF() throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readUTF();
- }
-
- public int readBytes(byte[] value) throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readBytes(value);
- }
-
- public int readBytes(byte[] value, int length) throws JMSException
- {
- if (!bodyReadOnly)
- {
- throw new MessageNotReadableException("The message body is writeonly");
- }
- return ((BytesMessage)message).readBytes(value, length);
- }
-
- public void writeBoolean(boolean value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeBoolean(value);
- }
-
- public void writeByte(byte value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeByte(value);
- }
-
- public void writeShort(short value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeShort(value);
- }
-
- public void writeChar(char value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeChar(value);
- }
-
- public void writeInt(int value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeInt(value);
- }
-
- public void writeLong(long value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeLong(value);
- }
-
- public void writeFloat(float value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeFloat(value);
- }
-
- public void writeDouble(double value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeDouble(value);
- }
-
- public void writeUTF(String value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeUTF(value);
- }
-
- public void writeBytes(byte[] value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeBytes(value);
- }
-
- public void writeBytes(byte[] value, int offset, int length) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeBytes(value, offset, length);
- }
-
- public void writeObject(Object value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("the message body is read-only");
- }
- bodyChange();
- ((BytesMessage)message).writeObject(value);
- }
-
- public void reset() throws JMSException
- {
- ((BytesMessage)message).reset();
- bodyReadOnly = true;
- }
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossBytesMessage.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossBytesMessage.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossBytesMessage.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -27,15 +27,14 @@
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
-import java.util.Map;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.MessageEOFException;
import javax.jms.MessageFormatException;
+import javax.jms.MessageNotWriteableException;
import org.jboss.jms.exception.MessagingJMSException;
-import org.jboss.logging.Logger;
/**
* This class implements javax.jms.BytesMessage.
@@ -53,70 +52,34 @@
{
// Static -------------------------------------------------------
- private static final long serialVersionUID = 5914561890366707664L;
-
- private static final Logger log = Logger.getLogger(JBossBytesMessage.class);
-
public static final byte TYPE = 4;
// Attributes ----------------------------------------------------
- private boolean trace = log.isTraceEnabled();
-
- private transient ByteArrayOutputStream baos;
- private transient DataOutputStream dos;
+ private ByteArrayOutputStream baos;
+ private DataOutputStream dos;
- private transient ByteArrayInputStream bais;
- private transient DataInputStream dis;
+ private ByteArrayInputStream bais;
+ private DataInputStream dis;
// Constructor ---------------------------------------------------
- /**
- * Only deserialization should use this constructor directly
- */
- public JBossBytesMessage()
- {
- }
-
/*
* This constructor is used to construct messages prior to sending
*/
- public JBossBytesMessage(long messageID)
+ public JBossBytesMessage()
{
- super(messageID);
}
-
- /*
- * This constructor is used to construct messages when retrieved from persistence storage
- */
- public JBossBytesMessage(long messageID,
- boolean reliable,
- long expiration,
- long timestamp,
- byte priority,
- Map coreHeaders,
- byte[] payloadAsByteArray)
+
+ public JBossBytesMessage(org.jboss.messaging.newcore.intf.Message message, long deliveryID, int deliveryCount)
{
- super(messageID, reliable, expiration, timestamp, priority, coreHeaders, payloadAsByteArray);
+ super(message, deliveryID, deliveryCount);
}
- /**
- *
- * Make a shallow copy of another JBossBytesMessage
- *
- * @param other
- */
- public JBossBytesMessage(JBossBytesMessage other)
+ public JBossBytesMessage(BytesMessage foreign) throws JMSException
{
- super(other);
+ super(foreign);
- if (trace) { log.trace("Creating new JBossBytesMessage from other JBossBytesMessage"); }
- }
-
- public JBossBytesMessage(BytesMessage foreign, long id) throws JMSException
- {
- super(foreign, id);
-
foreign.reset();
baos = new ByteArrayOutputStream();
@@ -131,13 +94,6 @@
}
}
- // Streamable override ---------------------------------------
-
- public void read(DataInputStream in) throws Exception
- {
- super.read(in);
- }
-
// BytesMessage implementation -----------------------------------
public boolean readBoolean() throws JMSException
@@ -560,9 +516,7 @@
{
dos.flush();
- payload = baos.toByteArray();
-
- payloadAsByteArray = (byte[])payload;
+ message.setPayload(baos.toByteArray());
baos.close();
}
@@ -579,18 +533,6 @@
}
}
- // MessageSupport overrides --------------------------------------
-
- public Object getPayload()
- {
- return payload;
- }
-
- public byte[] getPayloadAsByteArray()
- {
- return payloadAsByteArray;
- }
-
// JBossMessage overrides ----------------------------------------
public void doBeforeSend() throws JMSException
@@ -628,8 +570,7 @@
baos = new ByteArrayOutputStream();
dos = new DataOutputStream(baos);
- payload = null;
- payloadAsByteArray = null;
+ message.setPayload(null);
bais = null;
dis = null;
}
@@ -637,7 +578,17 @@
public long getBodyLength() throws JMSException
{
checkRead();
- return payloadAsByteArray.length;
+
+ byte[] payload = (byte[])message.getPayload();
+
+ if (payload != null)
+ {
+ return payload.length;
+ }
+ else
+ {
+ return 0;
+ }
}
// Public --------------------------------------------------------
@@ -647,29 +598,29 @@
return JBossBytesMessage.TYPE;
}
- public JBossMessage doCopy() throws JMSException
- {
- reset();
-
- return new JBossBytesMessage(this);
- }
-
- public void copyPayload(Object payload) throws JMSException
- {
- byte[] otherBytes = (byte[])payload;
- if (otherBytes == null)
- {
- payload = null;
- }
- else
- {
- payload = new byte[otherBytes.length];
-
- System.arraycopy(otherBytes, 0, payload, 0, otherBytes.length);
-
- payloadAsByteArray = (byte[])payload;
- }
- }
+// public JBossMessage doCopy() throws JMSException
+// {
+// reset();
+//
+// return new JBossBytesMessage(this);
+// }
+//
+// public void copyPayload(Object payload) throws JMSException
+// {
+// byte[] otherBytes = (byte[])payload;
+// if (otherBytes == null)
+// {
+// payload = null;
+// }
+// else
+// {
+// payload = new byte[otherBytes.length];
+//
+// System.arraycopy(otherBytes, 0, payload, 0, otherBytes.length);
+//
+// payloadAsByteArray = (byte[])payload;
+// }
+// }
// Package protected ---------------------------------------------
@@ -677,25 +628,5 @@
// Private -------------------------------------------------------
- void checkRead()
- {
- // We have just received/reset() the message, and the client is trying to
- // read it
- if (bais == null)
- {
- bais = new ByteArrayInputStream(payloadAsByteArray);
- dis = new DataInputStream(bais);
- }
- }
-
- void checkWrite()
- {
- if (baos == null)
- {
- baos = new ByteArrayOutputStream();
- dos = new DataOutputStream(baos);
- }
- }
-
// Inner classes -------------------------------------------------
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMapMessage.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMapMessage.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMapMessage.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,15 +24,14 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageFormatException;
+import javax.jms.MessageNotWriteableException;
-import org.jboss.logging.Logger;
-import org.jboss.util.Primitives;
-
/**
* This class implements javax.jms.MapMessage
*
@@ -49,56 +48,37 @@
{
// Constants -----------------------------------------------------
- private static final long serialVersionUID = 7939593521831220924L;
-
public static final byte TYPE = 5;
// Attributes ----------------------------------------------------
+
+ private Map<String, Object> map = new HashMap<String, Object>();
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
- /**
- * Only deserialization should use this constructor directory
- */
- public JBossMapMessage()
- {
- }
-
/*
* This constructor is used to construct messages prior to sending
*/
- public JBossMapMessage(long messageID)
+ public JBossMapMessage()
{
- super(messageID);
- payload = new HashMap();
}
-
- /*
- * This constructor is used to construct messages when retrieved from persistence storage
- */
- public JBossMapMessage(long messageID, boolean reliable, long expiration, long timestamp,
- byte priority, Map coreHeaders, byte[] payloadAsByteArray)
+
+ public JBossMapMessage(org.jboss.messaging.newcore.intf.Message message, long deliveryID, int deliveryCount)
{
- super(messageID, reliable, expiration, timestamp, priority, coreHeaders, payloadAsByteArray);
+ super(message, deliveryID, deliveryCount);
}
- public JBossMapMessage(JBossMapMessage other)
- {
- super(other);
- }
-
/**
*
- * Make a shallow copy of another JBossMapMessage
+ * Constructor for a foreign MapMessage
* @param foreign
* @throws JMSException
*/
- public JBossMapMessage(MapMessage foreign, long id) throws JMSException
+ public JBossMapMessage(MapMessage foreign) throws JMSException
{
- super(foreign, id);
- payload = new HashMap();
+ super(foreign);
Enumeration names = foreign.getMapNames();
while (names.hasMoreElements())
{
@@ -115,71 +95,71 @@
return JBossMapMessage.TYPE;
}
- public void copyPayload(Object otherPayload) throws JMSException
- {
- payload = new HashMap((Map)otherPayload);
- }
+// public void copyPayload(Object otherPayload) throws JMSException
+// {
+// payload = new HashMap((Map)otherPayload);
+// }
// MapMessage implementation -------------------------------------
public void setBoolean(String name, boolean value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, Primitives.valueOf(value));
+ map.put(name, Boolean.valueOf(value));
}
public void setByte(String name, byte value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, new Byte(value));
+ map.put(name, Byte.valueOf(value));
}
public void setShort(String name, short value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, new Short(value));
+ map.put(name, Short.valueOf(value));
}
public void setChar(String name, char value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, new Character(value));
+ map.put(name, Character.valueOf(value));
}
public void setInt(String name, int value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, new Integer(value));
+ map.put(name, Integer.valueOf(value));
}
public void setLong(String name, long value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, new Long(value));
+ map.put(name, Long.valueOf(value));
}
public void setFloat(String name, float value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, new Float(value));
+ map.put(name, Float.valueOf(value));
}
public void setDouble(String name, double value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, new Double(value));
+ map.put(name, Double.valueOf(value));
}
public void setString(String name, String value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
}
public void setBytes(String name, byte[] value) throws JMSException
{
checkName(name);
- ((Map)getPayload()).put(name, value.clone());
+ map.put(name, value.clone());
}
public void setBytes(String name, byte[] value, int offset, int length) throws JMSException
@@ -187,50 +167,44 @@
checkName(name);
if (offset + length > value.length)
{
- throw new JMSException("Array is too small");
+ throw new JMSException("Invalid offset/length");
}
- byte[] temp = new byte[length];
- for (int i = 0; i < length; i++)
- {
- temp[i] = value[i + offset];
- }
- ((Map)getPayload()).put(name, temp);
+ byte[] newBytes = new byte[length];
+ System.arraycopy(value, offset, newBytes, 0, length);
+ map.put(name, newBytes);
}
public void setObject(String name, Object value) throws JMSException
{
checkName(name);
if (value instanceof Boolean)
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
else if (value instanceof Byte)
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
else if (value instanceof Short)
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
else if (value instanceof Character)
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
else if (value instanceof Integer)
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
else if (value instanceof Long)
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
else if (value instanceof Float)
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
else if (value instanceof Double)
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
else if (value instanceof String)
- ((Map)getPayload()).put(name, value);
+ map.put(name, value);
else if (value instanceof byte[])
- ((Map)getPayload()).put(name, ((byte[]) value).clone());
+ map.put(name, ((byte[]) value).clone());
else
throw new MessageFormatException("Invalid object type.");
-
}
public boolean getBoolean(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
return Boolean.valueOf(null).booleanValue();
@@ -244,10 +218,8 @@
public byte getByte(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
return Byte.parseByte(null);
@@ -261,10 +233,8 @@
public short getShort(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
return Short.parseShort(null);
@@ -280,10 +250,8 @@
public char getChar(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
throw new NullPointerException("Invalid conversion");
@@ -295,10 +263,8 @@
public int getInt(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
return Integer.parseInt(null);
@@ -316,10 +282,8 @@
public long getLong(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
return Long.parseLong(null);
@@ -339,10 +303,8 @@
public float getFloat(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
return Float.parseFloat(null);
@@ -356,10 +318,8 @@
public double getDouble(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
return Double.parseDouble(null);
@@ -375,10 +335,8 @@
public String getString(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
return null;
@@ -426,10 +384,8 @@
public byte[] getBytes(String name) throws JMSException
{
- Object value;
+ Object value = map.get(name);
- value = ((Map)getPayload()).get(name);
-
if (value == null)
return null;
if (value instanceof byte[])
@@ -440,19 +396,17 @@
public Object getObject(String name) throws JMSException
{
-
- return ((Map)getPayload()).get(name);
-
+ return map.get(name);
}
public Enumeration getMapNames() throws JMSException
{
- return Collections.enumeration(new HashMap(((Map)getPayload())).keySet());
+ return Collections.enumeration(new HashSet<String>(map.keySet()));
}
public boolean itemExists(String name) throws JMSException
{
- return ((Map)getPayload()).containsKey(name);
+ return map.containsKey(name);
}
// JBossMessage overrides ----------------------------------------
@@ -460,28 +414,31 @@
public void clearBody() throws JMSException
{
super.clearBody();
- payload = new HashMap();
- payloadAsByteArray = null;
+
+ map.clear();
}
- public JBossMessage doCopy()
- {
- return new JBossMapMessage(this);
- }
-
+// public JBossMessage doCopy()
+// {
+// return new JBossMapMessage(this);
+// }
+//
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
+
/**
* Check the name
*
* @param name the name
*/
- private void checkName(String name)
+ private void checkName(String name) throws JMSException
{
+ checkWrite();
+
if (name == null)
{
throw new IllegalArgumentException("Name must not be null.");
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMessage.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMessage.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMessage.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,31 +21,22 @@
*/
package org.jboss.jms.message;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.Serializable;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.Map;
-import javax.jms.BytesMessage;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
-import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageFormatException;
-import javax.jms.ObjectMessage;
-import javax.jms.StreamMessage;
-import javax.jms.TextMessage;
+import javax.jms.MessageNotReadableException;
+import javax.jms.MessageNotWriteableException;
-import org.jboss.jms.destination.JBossDestination;
+import org.jboss.jms.delegate.SessionDelegate;
import org.jboss.jms.exception.MessagingJMSException;
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.impl.message.MessageSupport;
+import org.jboss.messaging.core.impl.message.CoreMessage;
import org.jboss.util.Primitives;
import org.jboss.util.Strings;
@@ -53,12 +44,8 @@
*
* Implementation of a JMS Message
*
- * Note that the only reason this class is Serializable is so that messages
- * can be returned from JMX operations.
+ * JMS Messages only live on the client side - the server only deals with MessageImpl instances
*
- * Java serialization is not used to serialize messages between client and server
- * in normal JMS operations
- *
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @author <a href="mailto:bershath at yahoo.com">Tyronne Wickramarathne</a>
@@ -71,13 +58,10 @@
*
* $Id$
*/
-public class JBossMessage extends MessageSupport implements javax.jms.Message, Serializable
+public class JBossMessage implements javax.jms.Message
{
// Constants -----------------------------------------------------
- private static final long serialVersionUID = 2833181306818971346L;
- public static final byte TYPE = 1;
-
private static final char PROPERTY_PREFIX_CHAR = 'P';
private static final String PROPERTY_PREFIX = "P";
@@ -109,11 +93,11 @@
//Used when bridging a message
public static final String JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST = "JBM_BRIDGE_MSG_ID_LIST";
- private static final Logger log = Logger.getLogger(JBossMessage.class);
-
+ private static final int TYPE = 0;
+
// Static --------------------------------------------------------
- private static final HashSet reservedIdentifiers = new HashSet();
+ private static final HashSet<String> reservedIdentifiers = new HashSet<String>();
static
{
reservedIdentifiers.add("NULL");
@@ -128,209 +112,96 @@
reservedIdentifiers.add("IS");
reservedIdentifiers.add("ESCAPE");
}
-
- public static MessageProxy createThinDelegate(long deliveryId, JBossMessage m, int deliveryCount)
- {
- MessageProxy del;
- if (m instanceof BytesMessage)
- {
- del = new BytesMessageProxy(deliveryId, (JBossBytesMessage)m, deliveryCount);
- }
- else if (m instanceof MapMessage)
- {
- del = new MapMessageProxy(deliveryId, (JBossMapMessage)m, deliveryCount);
- }
- else if (m instanceof ObjectMessage)
- {
- del = new ObjectMessageProxy(deliveryId, (JBossObjectMessage)m, deliveryCount);
- }
- else if (m instanceof StreamMessage)
- {
- del = new StreamMessageProxy(deliveryId, (JBossStreamMessage)m, deliveryCount);
- }
- else if (m instanceof TextMessage)
- {
- del = new TextMessageProxy(deliveryId, (JBossTextMessage)m, deliveryCount);
- }
- else
- {
- del = new MessageProxy(deliveryId, m, deliveryCount);
- }
-
- return del;
- }
-
- public static String dump(JBossMessage m)
+ public static JBossMessage createMessage(org.jboss.messaging.newcore.intf.Message message,
+ long deliveryID, int deliveryCount)
{
- String type = null;
- if (m instanceof BytesMessage)
- {
- type = "Bytes";
- }
- else if (m instanceof MapMessage)
- {
- type = "Map";
- }
- else if (m instanceof ObjectMessage)
- {
- type = "Object";
- }
- else if (m instanceof StreamMessage)
- {
- type = "Stream";
- }
- else if (m instanceof TextMessage)
- {
- type = "Text";
- }
- else
- {
- type = "Generic";
- }
-
- StringBuffer sb = new StringBuffer();
-
- sb.append("\n");
- sb.append(" MESSAGE DUMP\n");
- sb.append(" Core ID: ").append(m.messageID).append('\n');
- sb.append(" reliable: ").append(m.reliable).append('\n');
- sb.append(" expiration: ").append(m.expiration).append('\n');
- sb.append(" timestamp: ").append(m.timestamp).append('\n');
- sb.append(" headers: ");
-
- if (m.headers.size() == 0)
- {
- sb.append("NO HEADERS").append('\n');
- }
- else
- {
- sb.append('\n');
- for(Iterator i = m.headers.keySet().iterator(); i.hasNext(); )
- {
- String name = (String)i.next();
- sb.append(" ");
- sb.append(name).append(" - ").append(m.headers.get(name)).append('\n');
- }
- }
+ int type = message.getType();
- int deliveryCount = 0;
- try
+ switch(type)
{
- deliveryCount = m.getIntProperty("JMSXDeliveryCount");
+ case JBossMessage.TYPE:
+ return new JBossMessage(message, deliveryID, deliveryCount);
+ case JBossBytesMessage.TYPE:
+ return new JBossBytesMessage(message, deliveryID, deliveryCount);
+ case JBossMapMessage.TYPE:
+ return new JBossMapMessage(message, deliveryID, deliveryCount);
+ case JBossObjectMessage.TYPE:
+ return new JBossObjectMessage(message, deliveryID, deliveryCount);
+ case JBossStreamMessage.TYPE:
+ return new JBossStreamMessage(message, deliveryID, deliveryCount);
+ case JBossTextMessage.TYPE:
+ return new JBossTextMessage(message, deliveryID, deliveryCount);
+ default:
+ throw new IllegalArgumentException("Invalid message type " + type);
}
- catch (JMSException e)
- {
- log.error("Failed to get delivery count", e);
- }
-
- try
- {
- sb.append(" redelivered: ").append(deliveryCount >= 1).append('\n');
- sb.append(" priority: ").append(m.priority).append('\n');
- sb.append(" deliveryCount: ").append(deliveryCount).append('\n');
-
- sb.append(" JMS ID: ").append(m.getJMSMessageID()).append('\n');
- sb.append(" type: ").append(type).append('\n');
- sb.append(" destination: ").append(m.getJMSDestination()).append('\n');
- sb.append(" replyTo: ").append(m.getJMSReplyTo()).append('\n');
- sb.append(" jmsType: ").append(m.getJMSType()).append('\n');
- sb.append(" properties: ");
- }
- catch (Exception e)
- {
- log.error("Failed to dump message", e);
- }
-
- Iterator iter = m.headers.entrySet().iterator();
-
- int count = 0;
-
- while (iter.hasNext())
- {
- Map.Entry entry = (Map.Entry)iter.next();
-
- String propName = (String)entry.getKey();
-
- if (propName.charAt(0) == PROPERTY_PREFIX_CHAR)
- {
- if (count == 0)
- {
- sb.append("\n");
- }
-
- sb.append(" ");
- sb.append(propName).append(" - ").append(entry.getValue()).append('\n');
-
- count++;
- }
- }
-
- sb.append("\n");
-
- return sb.toString();
}
-
+
// Attributes ----------------------------------------------------
- protected transient String connectionID;
+ //The underlying message
+ protected org.jboss.messaging.newcore.intf.Message message;
- protected transient String jmsMessageID;
+ //The SessionDelegate - we need this when acknowledging the message directly
+ private SessionDelegate delegate;
- //Optimisation - we could just store this as a header like everything else - but we store
- //As an attribute so we can prevent an extra lookup on the server
- private long scheduledDeliveryTime;
+ //From a connection consumer?
+ private boolean cc;
- //Optimisation - we could just store this as a header like everything else - but we store
- //As an attribute so we can prevent an extra lookup on the server
- private Destination destination;
+ //The delivery count
+ private int deliveryCount;
+ //The delivery id
+ private long deliveryID;
+
+ //Read-only?
+ protected boolean readOnly;
+
// Constructors --------------------------------------------------
-
+
/*
- * Construct a message for deserialization or streaming
+ * Construct a new JBoss Message with default values
*/
public JBossMessage()
- {
- }
-
- /*
- * Construct a message using default values
- */
- public JBossMessage(long messageID)
{
- super(messageID, true, 0, System.currentTimeMillis(), (byte)4, null, null);
+ message =
+ new MessageImpl(-1, JBossMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4);
}
- /*
- * Constructor using specified values
- */
- public JBossMessage(long messageID, boolean reliable, long expiration, long timestamp,
- byte priority, Map headers, byte[] payloadAsByteArray)
- {
- super (messageID, reliable, expiration, timestamp, priority, headers, payloadAsByteArray);
- }
-
+// /**
+// *
+// * Create a new JBossMessage by making a shallow copy of another
+// *
+// * @param other The message to make a shallow copy from
+// */
+// protected JBossMessage(JBossMessage other)
+// {
+// super(other);
+// this.connectionID = other.connectionID;
+// this.scheduledDeliveryTime = other.scheduledDeliveryTime;
+// this.destination = other.destination;
+// }
+
/**
- *
- * Create a new JBossMessage by making a shallow copy of another
- *
- * @param other The message to make a shallow copy from
+ * Constructor for when receiving a message from the server
*/
- protected JBossMessage(JBossMessage other)
+ public JBossMessage(org.jboss.messaging.newcore.intf.Message message, long deliveryID, int deliveryCount)
{
- super(other);
- this.connectionID = other.connectionID;
- this.scheduledDeliveryTime = other.scheduledDeliveryTime;
- this.destination = other.destination;
+ this.message = message;
+
+ this.deliveryID = deliveryID;
+
+ this.deliveryCount = deliveryCount;
+
+ this.readOnly = true;
}
- /**
- * A copy constructor for non-JBoss Messaging JMS messages.
- */
- public JBossMessage(Message foreign, long messageID) throws JMSException
+ /*
+ * A constructor that takes a foreign message
+ */
+ public JBossMessage(Message foreign) throws JMSException
{
- super(messageID);
+ this();
setJMSTimestamp(foreign.getJMSTimestamp());
@@ -355,8 +226,9 @@
setJMSExpiration(foreign.getJMSExpiration());
setJMSPriority(foreign.getJMSPriority());
setJMSType(foreign.getJMSType());
-
- for (Enumeration props = foreign.getPropertyNames(); props.hasMoreElements(); )
+
+ //We can't avoid a cast warning here since getPropertyNames() is on the JMS API
+ for (Enumeration<String> props = foreign.getPropertyNames(); props.hasMoreElements(); )
{
String name = (String)props.nextElement();
@@ -366,31 +238,22 @@
}
}
-
- // Routable implementation ---------------------------------------
-
- public boolean isReference()
- {
- return false;
- }
-
// javax.jmx.Message implementation ------------------------------
public String getJMSMessageID()
{
- if (jmsMessageID == null)
+ String id = (String)message.getHeader(JBM_MESSAGE_ID);
+
+ if (id == null)
{
- String headerID = (String)headers.get(JBM_MESSAGE_ID);
- if (headerID == null)
- {
- jmsMessageID = "ID:JBM-" + messageID;
- }
- else
- {
- jmsMessageID = headerID;
- }
+ id = "ID:JBM-" + message.getMessageID();
+
+ //We cache the JMSMessageID in the header - this is because when moving a message between clusters
+ //the underlying message id can change but we want to preserve the JMSMessageID
+ message.putHeader(JBM_MESSAGE_ID, id);
}
- return jmsMessageID;
+
+ return id;
}
public void setJMSMessageID(String jmsMessageID) throws JMSException
@@ -401,28 +264,27 @@
}
if (jmsMessageID == null)
{
- headers.remove(JBM_MESSAGE_ID);
+ message.removeHeader(JBM_MESSAGE_ID);
}
else
{
- headers.put(JBM_MESSAGE_ID, jmsMessageID);
+ message.putHeader(JBM_MESSAGE_ID, jmsMessageID);
}
- this.jmsMessageID = jmsMessageID;
}
public long getJMSTimestamp() throws JMSException
{
- return timestamp;
+ return message.getTimestamp();
}
public void setJMSTimestamp(long timestamp) throws JMSException
{
- this.timestamp = timestamp;
+ message.setTimestamp(timestamp);
}
public byte[] getJMSCorrelationIDAsBytes() throws JMSException
{
- return (byte[]) headers.get(CORRELATIONIDBYTES_HEADER_NAME);
+ return (byte[]) message.getHeader(CORRELATIONIDBYTES_HEADER_NAME);
}
public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException
@@ -431,80 +293,57 @@
{
throw new JMSException("Please specify a non-zero length byte[]");
}
- headers.put(CORRELATIONIDBYTES_HEADER_NAME, correlationID);
+ message.putHeader(CORRELATIONIDBYTES_HEADER_NAME, correlationID);
- headers.remove(CORRELATIONID_HEADER_NAME);
+ message.removeHeader(CORRELATIONID_HEADER_NAME);
}
public void setJMSCorrelationID(String correlationID) throws JMSException
{
- headers.put(CORRELATIONID_HEADER_NAME, correlationID);
+ message.putHeader(CORRELATIONID_HEADER_NAME, correlationID);
- headers.remove(CORRELATIONIDBYTES_HEADER_NAME);
+ message.removeHeader(CORRELATIONIDBYTES_HEADER_NAME);
}
public String getJMSCorrelationID() throws JMSException
{
- return (String)headers.get(CORRELATIONID_HEADER_NAME);
+ return (String)message.getHeader(CORRELATIONID_HEADER_NAME);
}
public Destination getJMSReplyTo() throws JMSException
{
- return (Destination)headers.get(REPLYTO_HEADER_NAME);
+ return (Destination)message.getHeader(REPLYTO_HEADER_NAME);
}
public void setJMSReplyTo(Destination replyTo) throws JMSException
{
- headers.put(REPLYTO_HEADER_NAME, replyTo);
+ message.putHeader(REPLYTO_HEADER_NAME, replyTo);
}
public Destination getJMSDestination() throws JMSException
{
- if (destination != null)
- {
- return destination;
- }
- else
- {
- return (Destination)headers.get(DESTINATION_HEADER_NAME);
- }
+ return (Destination)message.getHeader(DESTINATION_HEADER_NAME);
}
public void setJMSDestination(Destination destination) throws JMSException
{
- //We don't store as a header when setting - this allows us to avoid a lookup on the server
- //when routing the message
- this.destination = destination;
+ message.putHeader(DESTINATION_HEADER_NAME, destination);
}
- //We need to override getHeaders - so the JMSDestination header gets persisted to the db
- //This is called by the persistence manager
- public Map getHeaders()
- {
- if (destination != null)
- {
- headers.put(DESTINATION_HEADER_NAME, destination);
- }
-
- destination = null;
-
- return headers;
- }
-
public int getJMSDeliveryMode() throws JMSException
{
- return reliable ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
+ return message.isReliable() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
}
public void setJMSDeliveryMode(int deliveryMode) throws JMSException
{
if (deliveryMode == DeliveryMode.PERSISTENT)
{
- reliable = true;
+ message.setReliable(true);
}
else if (deliveryMode == DeliveryMode.NON_PERSISTENT)
{
- reliable = false;
+ message.setReliable(false);
}
else
{
@@ -515,23 +354,28 @@
public boolean getJMSRedelivered() throws JMSException
{
- throw new IllegalStateException("This should never be called directly");
+ return deliveryCount >= 2;
}
public void setJMSRedelivered(boolean redelivered) throws JMSException
{
- //Always dealt with on the proxy
- throw new IllegalStateException("This should never be called directly");
+ if (deliveryCount == 1)
+ {
+ deliveryCount++;
+ }
+ else
+ {
+ //do nothing
+ }
}
- /**
- *
- * @return java.lang.String type
+ /**
+ * @return The JMSType header
* @throws JMSException
*/
public String getJMSType() throws JMSException
{
- return (String)headers.get(TYPE_HEADER_NAME);
+ return (String)message.getHeader(TYPE_HEADER_NAME);
}
/**
@@ -541,36 +385,36 @@
*/
public void setJMSType(String type) throws JMSException
{
- headers.put(TYPE_HEADER_NAME, type);
+ message.putHeader(TYPE_HEADER_NAME, type);
}
public long getJMSExpiration() throws JMSException
{
- return expiration;
+ return message.getExpiration();
}
public void setJMSExpiration(long expiration) throws JMSException
{
- this.expiration = expiration;
+ message.setExpiration(expiration);
}
public int getJMSPriority() throws JMSException
{
- return priority;
+ return message.getPriority();
}
public void setJMSPriority(int priority) throws JMSException
{
- this.priority = (byte)priority;
+ message.setPriority((byte)priority);
}
public void clearProperties() throws JMSException
{
- Iterator iter = headers.keySet().iterator();
+ Iterator<String> iter = message.getHeaders().keySet().iterator();
while (iter.hasNext())
{
- String propName = (String)iter.next();
+ String propName = iter.next();
if (propName.charAt(0) == PROPERTY_PREFIX_CHAR)
{
@@ -581,20 +425,18 @@
public void clearBody() throws JMSException
{
- payload = null;
-
- payloadAsByteArray = null;
+ readOnly = false;
}
public boolean propertyExists(String name) throws JMSException
{
- return headers.containsKey(PROPERTY_PREFIX + name)
+ return message.containsHeader(PROPERTY_PREFIX + name)
|| name.equals("JMSXDeliveryCount");
}
public boolean getBooleanProperty(String name) throws JMSException
{
- Object value = headers.get(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
if (value == null)
return Boolean.valueOf(null).booleanValue();
@@ -608,7 +450,7 @@
public byte getByteProperty(String name) throws JMSException
{
- Object value = headers.get(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
if (value == null)
throw new NumberFormatException("Message property '" + name + "' not set.");
@@ -622,7 +464,7 @@
public short getShortProperty(String name) throws JMSException
{
- Object value = headers.get(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
if (value == null)
throw new NumberFormatException("Message property '" + name + "' not set.");
@@ -638,7 +480,12 @@
public int getIntProperty(String name) throws JMSException
{
- Object value = headers.get(PROPERTY_PREFIX + name);
+ if ("JMSXDeliveryCount".equals(name))
+ {
+ return deliveryCount;
+ }
+
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
if (value == null)
{
@@ -669,19 +516,12 @@
public long getLongProperty(String name) throws JMSException
{
- if (JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME.equals(name))
- {
- if (this.scheduledDeliveryTime == 0)
- {
- throw new NumberFormatException("Message property '" + name + "' not set.");
- }
- else
- {
- return scheduledDeliveryTime;
- }
+ if ("JMSXDeliveryCount".equals(name))
+ {
+ return deliveryCount;
}
- Object value = headers.get(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
if (value == null)
{
@@ -716,7 +556,7 @@
public float getFloatProperty(String name) throws JMSException
{
- Object value = headers.get(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
if (value == null)
return Float.valueOf(null).floatValue();
@@ -730,7 +570,7 @@
public double getDoubleProperty(String name) throws JMSException
{
- Object value = headers.get(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
if (value == null)
return Double.valueOf(null).doubleValue();
@@ -746,19 +586,12 @@
public String getStringProperty(String name) throws JMSException
{
- if (JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME.equals(name))
- {
- if (this.scheduledDeliveryTime == 0)
- {
- throw new NumberFormatException("Message property '" + name + "' not set.");
- }
- else
- {
- return String.valueOf(scheduledDeliveryTime);
- }
+ if ("JMSXDeliveryCount".equals(name))
+ {
+ return Integer.toString(deliveryCount);
}
- Object value = headers.get(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(PROPERTY_PREFIX + name);
if (value == null)
return null;
@@ -802,31 +635,15 @@
public Object getObjectProperty(String name) throws JMSException
{
- if (JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME.equals(name))
- {
- if (scheduledDeliveryTime == 0)
- {
- return null;
- }
- else
- {
- return new Long(scheduledDeliveryTime);
- }
- }
-
- return headers.get(PROPERTY_PREFIX + name);
+ return message.getHeader(PROPERTY_PREFIX + name);
}
public Enumeration getPropertyNames() throws JMSException
{
- HashSet set = new HashSet();
+ HashSet<String> set = new HashSet<String>();
- Iterator iter = headers.keySet().iterator();
-
- while (iter.hasNext())
+ for (String propName: message.getHeaders().keySet())
{
- String propName = (String)iter.next();
-
if (propName.charAt(0) == PROPERTY_PREFIX_CHAR)
{
String name = propName.substring(1);
@@ -834,11 +651,6 @@
}
}
- if (scheduledDeliveryTime != 0)
- {
- set.add(JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME);
- }
-
return Collections.enumeration(set);
}
@@ -846,119 +658,119 @@
{
Boolean b = Primitives.valueOf(value);
checkProperty(name, b);
- headers.put(PROPERTY_PREFIX + name, b);
+ message.putHeader(PROPERTY_PREFIX + name, b);
}
public void setByteProperty(String name, byte value) throws JMSException
{
Byte b = new Byte(value);
checkProperty(name, b);
- headers.put(PROPERTY_PREFIX + name, b);
+ message.putHeader(PROPERTY_PREFIX + name, b);
}
public void setShortProperty(String name, short value) throws JMSException
{
Short s = new Short(value);
checkProperty(name, s);
- headers.put(PROPERTY_PREFIX + name, s);
+ message.putHeader(PROPERTY_PREFIX + name, s);
}
public void setIntProperty(String name, int value) throws JMSException
{
Integer i = new Integer(value);
checkProperty(name, i);
- headers.put(PROPERTY_PREFIX + name, i);
+ message.putHeader(PROPERTY_PREFIX + name, i);
}
public void setLongProperty(String name, long value) throws JMSException
- {
- // Optimisation - we don't actually store this as a header - but as an attribute
- if (JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME.equals(name))
- {
- this.scheduledDeliveryTime = value;
- }
- else
- {
- Long l = new Long(value);
- checkProperty(name, l);
- headers.put(PROPERTY_PREFIX + name, l);
- }
+ {
+ Long l = new Long(value);
+ checkProperty(name, l);
+ message.putHeader(PROPERTY_PREFIX + name, l);
}
public void setFloatProperty(String name, float value) throws JMSException
{
Float f = new Float(value);
checkProperty(name, f);
- headers.put(PROPERTY_PREFIX + name, f);
+ message.putHeader(PROPERTY_PREFIX + name, f);
}
public void setDoubleProperty(String name, double value) throws JMSException
{
Double d = new Double(value);
checkProperty(name, d);
- headers.put(PROPERTY_PREFIX + name, d);
+ message.putHeader(PROPERTY_PREFIX + name, d);
}
public void setStringProperty(String name, String value) throws JMSException
{
checkProperty(name, value);
- headers.put(PROPERTY_PREFIX + name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
}
public void setObjectProperty(String name, Object value) throws JMSException
{
- if (JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME.equals(name) && value instanceof Long)
- {
- this.scheduledDeliveryTime = ((Long)value).longValue();
- return;
- }
-
checkProperty(name, value);
if (value instanceof Boolean)
{
- headers.put(PROPERTY_PREFIX + name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
}
else if (value instanceof Byte)
{
- headers.put(PROPERTY_PREFIX + name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
}
else if (value instanceof Short)
{
- headers.put(PROPERTY_PREFIX + name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
}
else if (value instanceof Integer)
{
- headers.put(PROPERTY_PREFIX + name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
}
else if (value instanceof Long)
{
- headers.put(PROPERTY_PREFIX + name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
}
else if (value instanceof Float)
{
- headers.put(PROPERTY_PREFIX + name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
}
else if (value instanceof Double)
{
- headers.put(PROPERTY_PREFIX + name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
}
else if (value instanceof String)
{
- headers.put(PROPERTY_PREFIX + name, value);
+ message.putHeader(PROPERTY_PREFIX + name, value);
}
else if (value == null)
{
- headers.put(PROPERTY_PREFIX + name, null);
+ message.putHeader(PROPERTY_PREFIX + name, null);
}
else
{
throw new MessageFormatException("Invalid object type");
}
}
-
+
+ public void acknowledge() throws JMSException
+ {
+ if (!cc)
+ {
+ //Only acknowledge for client ack if is not in connection consumer
+ delegate.acknowledgeAll();
+ }
+ }
+
// Public --------------------------------------------------------
+ public org.jboss.messaging.newcore.intf.Message getCoreMessage()
+ {
+ return message;
+ }
+
public void doBeforeSend() throws JMSException
{
}
@@ -972,110 +784,68 @@
return JBossMessage.TYPE;
}
- public void copyPayload(Object payload) throws JMSException
- {
- }
-
- public String getConnectionID()
+ public void setSessionDelegate(SessionDelegate sd, boolean isConnectionConsumer)
{
- return connectionID;
+ this.delegate = sd;
+ this.cc = isConnectionConsumer;
}
- public void setConnectionID(String connectionID)
+ public SessionDelegate getSessionDelegate()
{
- this.connectionID = connectionID;
+ return delegate;
}
- public String toString()
+ public int getDeliveryCount()
{
- StringBuffer sb = new StringBuffer("JBossMessage[");
- sb.append("");
- sb.append(messageID);
- sb.append("]:");
- sb.append(isReliable() ? "PERSISTENT" : "NON-PERSISTENT");
- return sb.toString();
+ return deliveryCount;
}
- public JBossMessage doCopy() throws JMSException
+ public void incDeliveryCount()
{
- return new JBossMessage(this);
+ this.deliveryCount++;
}
-
- public void acknowledge()
- {
- throw new IllegalStateException("Should not be handled here!");
- }
- public void setMessageId(long messageID)
+ public long getDeliveryId()
{
- this.messageID = messageID;
+ return deliveryID;
}
- public long getScheduledDeliveryTime()
+ public String toString()
{
- return scheduledDeliveryTime;
+ StringBuffer sb = new StringBuffer("JBossMessage[");
+ sb.append("");
+ sb.append(getJMSMessageID());
+ sb.append("]:");
+ sb.append(message.isReliable() ? "PERSISTENT" : "NON-PERSISTENT");
+ return sb.toString();
}
-
- /* Only used for testing */
- public Map getJMSProperties()
- {
- Map newHeaders = new HashMap();
- Iterator iter = headers.entrySet().iterator();
-
- while (iter.hasNext())
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void checkWrite() throws JMSException
+ {
+ if (readOnly)
{
- Map.Entry entry = (Map.Entry)iter.next();
-
- String key = (String)entry.getKey();
-
- if (key.charAt(0) == PROPERTY_PREFIX_CHAR)
- {
- newHeaders.put(key, entry.getValue());
- }
+ throw new MessageNotWriteableException("Message is read-only");
}
-
- return newHeaders;
}
- //Only used for testing
- public boolean isCorrelationIDBytes()
+ protected void checkRead() throws JMSException
{
- return headers.get(CORRELATIONIDBYTES_HEADER_NAME) != null;
+ if (!readOnly)
+ {
+ throw new MessageNotReadableException("Message is write-only");
+ }
}
-
-
- // Streamable implementation ---------------------------------
- public void write(DataOutputStream out) throws Exception
+ // Private ------------------------------------------------------------
+
+ private void checkProperty(String name, Object value) throws JMSException
{
- super.write(out);
-
- out.writeLong(scheduledDeliveryTime);
+ checkWrite();
- JBossDestination.writeDestination(out, destination);
- }
-
- public void read(DataInputStream in) throws Exception
- {
- super.read(in);
-
- scheduledDeliveryTime = in.readLong();
-
- destination = JBossDestination.readDestination(in);
- }
-
- // Package protected ---------------------------------------------
-
- /**
- * Check a property is valid
- *
- * @param name the name
- * @param value the value
- * @throws JMSException for any error
- */
- void checkProperty(String name, Object value) throws JMSException
- {
if (name == null)
{
throw new IllegalArgumentException("The name of a property must not be null.");
@@ -1107,7 +877,5 @@
}
}
- // Protected -----------------------------------------------------
-
// Inner classes -------------------------------------------------
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossObjectMessage.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossObjectMessage.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossObjectMessage.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,14 +21,10 @@
*/
package org.jboss.jms.message;
-import org.jboss.messaging.util.StreamUtils;
-
import java.io.Serializable;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.Map;
import javax.jms.JMSException;
+import javax.jms.MessageNotWriteableException;
import javax.jms.ObjectMessage;
/**
@@ -45,58 +41,35 @@
{
// Constants -----------------------------------------------------
- private static final long serialVersionUID = -2374448267737763502L;
-
public static final byte TYPE = 2;
// Attributes ----------------------------------------------------
+
+ private Serializable object;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
- /**
- * Only deserialization should use this constructor directory
- */
- public JBossObjectMessage()
- {
- }
-
/*
* This constructor is used to construct messages prior to sending
*/
- public JBossObjectMessage(long messageID)
+ public JBossObjectMessage()
{
- super(messageID);
}
-
- /*
- * This constructor is used to construct messages when retrieved from persistence storage
- */
- public JBossObjectMessage(long messageID, boolean reliable, long expiration, long timestamp,
- byte priority, Map coreHeaders, byte[] payloadAsByteArray)
+
+ public JBossObjectMessage(org.jboss.messaging.newcore.intf.Message message, long deliveryID, int deliveryCount)
{
- super(messageID, reliable, expiration, timestamp, priority, coreHeaders, payloadAsByteArray);
+ super(message, deliveryID, deliveryCount);
}
-
/**
- *
- * Make a shallow copy of another JBossObjectMessage
- * @param other
+ * A copy constructor for foreign JMS ObjectMessages.
*/
- public JBossObjectMessage(JBossObjectMessage other)
+ public JBossObjectMessage(ObjectMessage foreign) throws JMSException
{
- super(other);
- }
+ super(foreign);
- /**
- * A copy constructor for non-JBoss Messaging JMS ObjectMessages.
- */
- public JBossObjectMessage(ObjectMessage foreign, long id) throws JMSException
- {
- super(foreign, id);
-
setObject(foreign.getObject());
}
@@ -107,40 +80,31 @@
return JBossObjectMessage.TYPE;
}
-
// ObjectMessage implementation ----------------------------------
public void setObject(Serializable object) throws JMSException
{
- payload = object;
+ checkWrite();
- //Trigger serialization
- getPayloadAsByteArray();
-
- payload = null;
+ this.object = object;
}
public Serializable getObject() throws JMSException
{
- return (Serializable)getPayload();
+ return object;
}
// JBossMessage overrides ----------------------------------------
- public JBossMessage doCopy()
- {
- return new JBossObjectMessage(this);
- }
-
+// public JBossMessage doCopy()
+// {
+// return new JBossObjectMessage(this);
+// }
+//
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
- protected void doWriteObject(DataOutputStream out, Object payload) throws IOException
- {
- StreamUtils.writeObject(out, payload, false, true);
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossStreamMessage.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossStreamMessage.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossStreamMessage.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,20 +21,14 @@
*/
package org.jboss.jms.message;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import javax.jms.JMSException;
import javax.jms.MessageEOFException;
import javax.jms.MessageFormatException;
import javax.jms.StreamMessage;
-import org.jboss.messaging.util.StreamUtils;
-import org.jboss.util.Primitives;
-
/**
* This class implements javax.jms.StreamMessage.
*
@@ -51,71 +45,40 @@
{
// Constants -----------------------------------------------------
- private static final long serialVersionUID = 7469150228071568233L;
-
public static final byte TYPE = 6;
// Attributes ----------------------------------------------------
- protected transient int position;
+ private int position;
- protected transient int offset;
+ private int offset;
- protected int size;
+ //private int size;
+ private List<Object> list = new ArrayList<Object>();
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
- /**
- * Only deserialization should use this constructor directory
+ /*
+ * This constructor is used to construct messages prior to sending
*/
public JBossStreamMessage()
- {
+ {
}
- /*
- * This constructor is used to construct messages prior to sending
- */
- public JBossStreamMessage(long messageID)
+ public JBossStreamMessage(org.jboss.messaging.newcore.intf.Message message, long deliveryID, int deliveryCount)
{
- super(messageID);
- payload = new ArrayList();
- position = 0;
- size = 0;
- offset = 0;
+ super(message, deliveryID, deliveryCount);
}
- /*
- * This constructor is used to construct messages when retrieved from persistence storage
- */
- public JBossStreamMessage(long messageID, boolean reliable, long expiration, long timestamp,
- byte priority, Map coreHeaders, byte[] payloadAsByteArray)
+ public JBossStreamMessage(StreamMessage foreign) throws JMSException
{
- super(messageID, reliable, expiration, timestamp, priority, coreHeaders, payloadAsByteArray);
- }
-
- /**
- *
- * Make a shallow copy of another JBossStreamMessage
- *
- * @param other
- */
- public JBossStreamMessage(JBossStreamMessage other)
- {
- super(other);
- }
-
- public JBossStreamMessage(StreamMessage foreign, long id) throws JMSException
- {
- super(foreign, id);
+ super(foreign);
foreign.reset();
- payload = new ArrayList();
- position = 0;
- size = 0;
- offset = 0;
try
{
while (true)
@@ -149,38 +112,46 @@
reset();
}
- public void copyPayload(Object other) throws JMSException
- {
- reset();
- payload = new ArrayList((List)other);
- payloadAsByteArray = null;
- }
+// public void copyPayload(Object other) throws JMSException
+// {
+// reset();
+// payload = new ArrayList((List)other);
+// payloadAsByteArray = null;
+// }
// StreamMessage implementation ----------------------------------
public boolean readBoolean() throws JMSException
{
-
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
+
offset = 0;
+
+ boolean result;
if (value == null)
+ {
throw new NullPointerException("Value is null");
+ }
else if (value instanceof Boolean)
- {
- position++;
- return ((Boolean) value).booleanValue();
+ {
+ result = ((Boolean)value).booleanValue();
}
else if (value instanceof String)
{
- boolean result = Boolean.valueOf((String) value).booleanValue();
- position++;
- return result;
+ result = Boolean.valueOf((String) value).booleanValue();
}
else
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
}
catch (IndexOutOfBoundsException e)
{
@@ -191,25 +162,35 @@
public byte readByte() throws JMSException
{
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
+
offset = 0;
+
+ byte result;
+
if (value == null)
+ {
throw new NullPointerException("Value is null");
+ }
else if (value instanceof Byte)
{
- position++;
- return ((Byte) value).byteValue();
+ result = ((Byte) value).byteValue();
}
else if (value instanceof String)
{
- byte result = Byte.parseByte((String) value);
- position++;
- return result;
+ result = Byte.parseByte((String) value);
}
else
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
}
catch (IndexOutOfBoundsException e)
{
@@ -219,31 +200,39 @@
public short readShort() throws JMSException
{
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
+
+ short result;
+
offset = 0;
if (value == null)
+ {
throw new NullPointerException("Value is null");
+ }
else if (value instanceof Byte)
{
- position++;
- return ((Byte) value).shortValue();
+ result = ((Byte) value).shortValue();
}
else if (value instanceof Short)
{
- position++;
- return ((Short) value).shortValue();
+ result = ((Short) value).shortValue();
}
else if (value instanceof String)
{
- short result = Short.parseShort((String) value);
- position++;
- return result;
+ result = Short.parseShort((String) value);
}
else
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
}
catch (IndexOutOfBoundsException e)
{
@@ -253,20 +242,31 @@
public char readChar() throws JMSException
{
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
+
+ char result;
+
offset = 0;
if (value == null)
+ {
throw new NullPointerException("Value is null");
+ }
else if (value instanceof Character)
{
- position++;
- return ((Character) value).charValue();
+ result = ((Character) value).charValue();
}
else
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
}
catch (IndexOutOfBoundsException e)
{
@@ -276,36 +276,43 @@
public int readInt() throws JMSException
{
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
+
+ int result;
+
offset = 0;
if (value == null)
+ {
throw new NullPointerException("Value is null");
+ }
else if (value instanceof Byte)
{
- position++;
- return ((Byte) value).intValue();
+ result = ((Byte) value).intValue();
}
else if (value instanceof Short)
{
- position++;
- return ((Short) value).intValue();
+ result = ((Short) value).intValue();
}
else if (value instanceof Integer)
{
- position++;
- return ((Integer) value).intValue();
+ result = ((Integer) value).intValue();
}
else if (value instanceof String)
{
- int result = Integer.parseInt((String) value);
- position++;
- return result;
+ result = Integer.parseInt((String) value);
}
else
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
}
catch (IndexOutOfBoundsException e)
{
@@ -315,41 +322,47 @@
public long readLong() throws JMSException
{
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
+
+ long result;
+
offset = 0;
if (value == null)
+ {
throw new NullPointerException("Value is null");
+ }
else if (value instanceof Byte)
{
- position++;
- return ((Byte) value).longValue();
+ result = ((Byte) value).longValue();
}
else if (value instanceof Short)
{
- position++;
- return ((Short) value).longValue();
+ result = ((Short) value).longValue();
}
else if (value instanceof Integer)
{
- position++;
- return ((Integer) value).longValue();
+ result = ((Integer) value).longValue();
}
else if (value instanceof Long)
{
- position++;
- return ((Long) value).longValue();
+ result = ((Long) value).longValue();
}
else if (value instanceof String)
{
- long result = Long.parseLong((String) value);
- position++;
- return result;
+ result = Long.parseLong((String) value);
}
else
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
}
catch (IndexOutOfBoundsException e)
{
@@ -359,26 +372,35 @@
public float readFloat() throws JMSException
{
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
+
+ float result;
+
offset = 0;
if (value == null)
+ {
throw new NullPointerException("Value is null");
+ }
else if (value instanceof Float)
{
- position++;
- return ((Float) value).floatValue();
+ result = ((Float) value).floatValue();
}
else if (value instanceof String)
{
- float result = Float.parseFloat((String) value);
- position++;
- return result;
+ result = Float.parseFloat((String) value);
}
else
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
}
catch (IndexOutOfBoundsException e)
{
@@ -388,31 +410,39 @@
public double readDouble() throws JMSException
{
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
+
offset = 0;
+
+ double result;
if (value == null)
+ {
throw new NullPointerException("Value is null");
+ }
else if (value instanceof Float)
{
- position++;
- return ((Float) value).doubleValue();
+ result = ((Float) value).doubleValue();
}
else if (value instanceof Double)
{
- position++;
- return ((Double) value).doubleValue();
+ result = ((Double) value).doubleValue();
}
else if (value instanceof String)
{
- double result = Double.parseDouble((String) value);
- position++;
- return result;
+ result = Double.parseDouble((String) value);
}
else
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
}
catch (IndexOutOfBoundsException e)
{
@@ -422,63 +452,63 @@
public String readString() throws JMSException
{
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
+
+ String result;
+
offset = 0;
if (value == null)
{
- position++;
- return null;
+ result = null;
}
else if (value instanceof Boolean)
{
- position++;
- return ((Boolean) value).toString();
+ result = ((Boolean) value).toString();
}
else if (value instanceof Byte)
{
- position++;
- return ((Byte) value).toString();
+ result = ((Byte) value).toString();
}
else if (value instanceof Short)
{
- position++;
- return ((Short) value).toString();
+ result = ((Short) value).toString();
}
else if (value instanceof Character)
{
- position++;
- return ((Character) value).toString();
+ result = ((Character) value).toString();
}
else if (value instanceof Integer)
{
- position++;
- return ((Integer) value).toString();
+ result = ((Integer) value).toString();
}
else if (value instanceof Long)
{
- position++;
- return ((Long) value).toString();
+ result = ((Long) value).toString();
}
else if (value instanceof Float)
{
- position++;
- return ((Float) value).toString();
+ result = ((Float) value).toString();
}
else if (value instanceof Double)
{
- position++;
- return ((Double) value).toString();
+ result = ((Double) value).toString();
}
else if (value instanceof String)
{
- position++;
- return (String) value;
+ result = (String) value;
}
else
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
+ position++;
+
+ return result;
}
catch (IndexOutOfBoundsException e)
{
@@ -488,13 +518,21 @@
public int readBytes(byte[] value) throws JMSException
{
+ checkRead();
try
{
- Object myObj = ((List)getPayload()).get(position);
+ Object myObj = list.get(position);
+
if (myObj == null)
+ {
throw new NullPointerException("Value is null");
- else if (!(myObj instanceof byte[]))
+ }
+
+ if (!(myObj instanceof byte[]))
+ {
throw new MessageFormatException("Invalid conversion");
+ }
+
byte[] obj = (byte[]) myObj;
if (obj.length == 0)
@@ -539,9 +577,10 @@
public Object readObject() throws JMSException
{
+ checkRead();
try
{
- Object value = ((List)getPayload()).get(position);
+ Object value = list.get(position);
position++;
offset = 0;
@@ -555,97 +594,111 @@
public void writeBoolean(boolean value) throws JMSException
{
-
- ((List)getPayload()).add(Primitives.valueOf(value));
+ checkWrite();
+ list.add(Boolean.valueOf(value));
}
public void writeByte(byte value) throws JMSException
{
- ((List)getPayload()).add(new Byte(value));
+ checkWrite();
+ list.add(Byte.valueOf(value));
}
public void writeShort(short value) throws JMSException
{
- ((List)getPayload()).add(new Short(value));
+ checkWrite();
+ list.add(Short.valueOf(value));
}
public void writeChar(char value) throws JMSException
{
- ((List)getPayload()).add(new Character(value));
+ checkWrite();
+ list.add(Character.valueOf(value));
}
public void writeInt(int value) throws JMSException
{
- ((List)getPayload()).add(new Integer(value));
+ checkWrite();
+ list.add(Integer.valueOf(value));
}
public void writeLong(long value) throws JMSException
{
- ((List)getPayload()).add(new Long(value));
+ checkWrite();
+ list.add(Long.valueOf(value));
}
public void writeFloat(float value) throws JMSException
{
- ((List)getPayload()).add(new Float(value));
+ checkWrite();
+ list.add(Float.valueOf(value));
}
public void writeDouble(double value) throws JMSException
{
- ((List)getPayload()).add(new Double(value));
+ checkWrite();
+ list.add(Double.valueOf(value));
}
public void writeString(String value) throws JMSException
{
+ checkWrite();
if (value == null)
{
- ((List)getPayload()).add(null);
+ list.add(null);
}
else
{
- ((List)getPayload()).add(value);
+ list.add(value);
}
}
public void writeBytes(byte[] value) throws JMSException
{
- ((List)getPayload()).add(value.clone());
+ checkWrite();
+ list.add(value.clone());
}
public void writeBytes(byte[] value, int offset, int length) throws JMSException
{
+ checkWrite();
if (offset + length > value.length)
- throw new JMSException("Array is too small");
- byte[] temp = new byte[length];
- for (int i = 0; i < length; i++)
- temp[i] = value[i + offset];
+ {
+ throw new JMSException("Invalid offset/length");
+ }
+
+ byte[] newBytes = new byte[length];
+
+ System.arraycopy(value, offset, newBytes, 0, length);
- ((List)getPayload()).add(temp);
+ list.add(newBytes);
}
public void writeObject(Object value) throws JMSException
{
+ checkWrite();
if (value == null)
- ((List)getPayload()).add(null);
+ list.add(null);
else if (value instanceof Boolean)
- ((List)getPayload()).add(value);
+ list.add(value);
else if (value instanceof Byte)
- ((List)getPayload()).add(value);
+ list.add(value);
else if (value instanceof Short)
- ((List)getPayload()).add(value);
+ list.add(value);
else if (value instanceof Character)
- ((List)getPayload()).add(value);
+ list.add(value);
else if (value instanceof Integer)
- ((List)getPayload()).add(value);
+ list.add(value);
else if (value instanceof Long)
- ((List)getPayload()).add(value);
+ list.add(value);
else if (value instanceof Float)
- ((List)getPayload()).add(value);
+ list.add(value);
else if (value instanceof Double)
- ((List)getPayload()).add(value);
+ list.add(value);
else if (value instanceof String)
- ((List)getPayload()).add(value);
+ list.add(value);
else if (value instanceof byte[])
- ((List)getPayload()).add(((byte[]) value).clone());
+ list.add(((byte[]) value).clone());
else
throw new MessageFormatException("Invalid object type");
}
@@ -653,7 +706,6 @@
public void reset() throws JMSException
{
position = 0;
- size = ((List)getPayload()).size();
offset = 0;
}
@@ -663,24 +715,21 @@
{
super.clearBody();
- payload = new ArrayList();
- payloadAsByteArray = null;
+ list.clear();
position = 0;
offset = 0;
- size = 0;
-
}
- public JBossMessage doCopy()
- {
- return new JBossStreamMessage(this);
- }
+// public JBossMessage doCopy()
+// {
+// return new JBossStreamMessage(this);
+// }
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
-
+
// Inner classes -------------------------------------------------
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossTextMessage.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossTextMessage.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossTextMessage.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,8 +21,6 @@
*/
package org.jboss.jms.message;
-import java.util.Map;
-
import javax.jms.JMSException;
import javax.jms.TextMessage;
@@ -43,63 +41,36 @@
{
// Constants -----------------------------------------------------
- private static final long serialVersionUID = -5661567664746852006L;
-
public static final byte TYPE = 3;
// Attributes ----------------------------------------------------
+
+ private String text;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
- /**
- * Only deserialization should use this constructor directory
- */
- public JBossTextMessage()
- {
- }
-
/*
* This constructor is used to construct messages prior to sending
*/
- public JBossTextMessage(long messageID)
+ public JBossTextMessage()
{
- super(messageID);
}
- /*
- * This constructor is used to construct messages when retrieved from persistence storage
- */
- public JBossTextMessage(long messageID, boolean reliable, long expiration, long timestamp,
- byte priority, Map coreHeaders, byte[] payloadAsByteArray)
+ public JBossTextMessage(org.jboss.messaging.newcore.intf.Message message, long deliveryID, int deliveryCount)
{
- super(messageID, reliable, expiration, timestamp, priority, coreHeaders, payloadAsByteArray);
+ super(message, deliveryID, deliveryCount);
}
-
+
/**
- *
- * Make a shallow copy of another JBossTextMessage
- *
- * @param other
- */
- public JBossTextMessage(JBossTextMessage other)
- {
- super(other);
- }
-
- /**
* A copy constructor for non-JBoss Messaging JMS TextMessages.
*/
- public JBossTextMessage(TextMessage foreign, long id) throws JMSException
+ public JBossTextMessage(TextMessage foreign) throws JMSException
{
- super(foreign, id);
- String text = foreign.getText();
- if (text != null)
- {
- setText(text);
- }
-
+ super(foreign);
+
+ text = foreign.getText();
}
// Public --------------------------------------------------------
@@ -111,23 +82,24 @@
// TextMessage implementation ------------------------------------
- public void setText(String string) throws JMSException
+ public void setText(String text) throws JMSException
{
- payload = string;
- payloadAsByteArray = null;
+ checkWrite();
+
+ this.text = text;
}
public String getText() throws JMSException
{
- return (String)getPayload();
+ return text;
}
// JBossMessage override -----------------------------------------
- public JBossMessage doCopy()
- {
- return new JBossTextMessage(this);
- }
+// public JBossMessage doCopy()
+// {
+// return new JBossTextMessage(this);
+// }
// Package protected ---------------------------------------------
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/MapMessageProxy.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/MapMessageProxy.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/MapMessageProxy.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,236 +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.message;
-
-import java.util.Enumeration;
-
-import javax.jms.JMSException;
-import javax.jms.MapMessage;
-import javax.jms.MessageNotWriteableException;
-
-/**
- *
- * Thin proxy for a JBossMapMessage
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * MapMessageProxy.java,v 1.1 2006/03/08 08:00:34 timfox Exp
- */
-public class MapMessageProxy extends MessageProxy implements MapMessage
-{
- private static final long serialVersionUID = 6953530870351885569L;
-
- public MapMessageProxy(long deliveryId, JBossMapMessage message, int deliveryCount)
- {
- super(deliveryId, message, deliveryCount);
- }
-
- public MapMessageProxy(JBossMapMessage message)
- {
- super(message);
- }
-
- public boolean getBoolean(String name) throws JMSException
- {
- return ((MapMessage)message).getBoolean(name);
- }
-
- public byte getByte(String name) throws JMSException
- {
- return ((MapMessage)message).getByte(name);
- }
-
- public short getShort(String name) throws JMSException
- {
- return ((MapMessage)message).getShort(name);
- }
-
- public char getChar(String name) throws JMSException
- {
- return ((MapMessage)message).getChar(name);
- }
-
- public int getInt(String name) throws JMSException
- {
- return ((MapMessage)message).getInt(name);
- }
-
- public long getLong(String name) throws JMSException
- {
- return ((MapMessage)message).getLong(name);
- }
-
- public float getFloat(String name) throws JMSException
- {
- return ((MapMessage)message).getFloat(name);
- }
-
- public double getDouble(String name) throws JMSException
- {
- return ((MapMessage)message).getDouble(name);
- }
-
- public String getString(String name) throws JMSException
- {
- return ((MapMessage)message).getString(name);
- }
-
- public byte[] getBytes(String name) throws JMSException
- {
- return ((MapMessage)message).getBytes(name);
- }
-
- public Object getObject(String name) throws JMSException
- {
- return ((MapMessage)message).getObject(name);
- }
-
- public Enumeration getMapNames() throws JMSException
- {
- return ((MapMessage)message).getMapNames();
- }
-
- public void setBoolean(String name, boolean value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setBoolean(name, value);
- }
-
- public void setByte(String name, byte value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setByte(name, value);
- }
-
- public void setShort(String name, short value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setShort(name, value);
- }
-
- public void setChar(String name, char value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setChar(name, value);
- }
-
- public void setInt(String name, int value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setInt(name, value);
- }
-
- public void setLong(String name, long value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setLong(name, value);
- }
-
- public void setFloat(String name, float value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setFloat(name, value);
- }
-
- public void setDouble(String name, double value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setDouble(name, value);
- }
-
- public void setString(String name, String value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setString(name, value);
- }
-
- public void setBytes(String name, byte[] value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setBytes(name, value);
- }
-
- public void setBytes(String name, byte[] value, int offset, int length) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setBytes(name, value, offset, length);
- }
-
- public void setObject(String name, Object value) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("Message is ReadOnly !");
- }
- bodyChange();
- ((MapMessage)message).setObject(name, value);
- }
-
- public boolean itemExists(String name) throws JMSException
- {
- return ((MapMessage)message).itemExists(name);
- }
-}
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/MessageProxy.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/MessageProxy.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/MessageProxy.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,510 +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.message;
-
-import java.io.Serializable;
-import java.util.Enumeration;
-
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageNotWriteableException;
-
-import org.jboss.jms.delegate.SessionDelegate;
-import org.jboss.logging.Logger;
-
-/**
- *
- * MessageProxy is a thin proxy for JBossMessage.
- *
- * JMS Users actually handle MessageProxy instances rather than JBossMessage instances. The purpose
- * of this class and subclasses is to prevent unnecessary copying of a message. After a message is
- * sent, the message can be changed, but this should not affect the sent message. This class
- * accomplishes this by intercepting any methods which change the state of the message and copying
- * either the headers, jms properties or body as appropriate. This enables up to make the minimum
- * amount of copies while still preserving JMS semantics. Similarly on receive.
- *
- * See JMS1.1 Spec 3.9, 3.10 for more details.
- *
- * If nothing is changed, nothing is copied.
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * MessageProxy.java,v 1.1 2006/03/08 08:00:34 timfox Exp
- */
-public class MessageProxy implements Message, Serializable
-{
- // Constants -----------------------------------------------------
-
- private static final long serialVersionUID = 5903095946142192468L;
-
- protected Logger log = Logger.getLogger(MessageProxy.class);
-
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- //The actual session delegate for the message - needed for doing recovery
- //so we can recover locally
- private transient SessionDelegate delegate;
-
- private transient boolean cc;
-
- private int deliveryCount;
-
- private long deliveryId;
-
- private transient boolean needToCopyHeader;
-
- private transient boolean needToCopyBody;
-
- public void beforeSend()
- {
- this.needToCopyHeader = true;
-
- this.needToCopyBody = true;
-
- this.propertiesReadOnly = false;
-
- this.bodyReadOnly = false;
- }
-
- private transient boolean propertiesReadOnly;
-
- protected transient boolean bodyReadOnly;
-
-
- protected JBossMessage message;
-
- // Constructors --------------------------------------------------
-
- public MessageProxy()
- {
- }
-
- /*
- * Constructor for a new message
- */
- public MessageProxy(JBossMessage message)
- {
- this.message = message;
-
- this.needToCopyHeader = false;
-
- this.needToCopyBody = false;
- }
-
- /*
- * COnstructor for a message received by a consumer
- */
- public MessageProxy(long deliveryId, JBossMessage message, int deliveryCount)
- {
- this.deliveryId = deliveryId;
-
- this.message = message;
-
- this.deliveryCount = deliveryCount;
-
- this.needToCopyHeader = true;
-
- this.needToCopyBody = true;
-
- this.propertiesReadOnly = true;
-
- this.bodyReadOnly = true;
- }
-
- // Message implementation ----------------------------------------
-
- public String getJMSMessageID() throws JMSException
- {
- return message.getJMSMessageID();
- }
-
- public void setJMSMessageID(String id) throws JMSException
- {
- headerChange();
- message.setJMSMessageID(id);
- }
-
- public long getJMSTimestamp() throws JMSException
- {
- return message.getJMSTimestamp();
- }
-
- public void setJMSTimestamp(long timestamp) throws JMSException
- {
- headerChange();
- message.setJMSTimestamp(timestamp);
- }
-
- public byte[] getJMSCorrelationIDAsBytes() throws JMSException
- {
- return message.getJMSCorrelationIDAsBytes();
- }
-
- public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException
- {
- headerChange();
- message.setJMSCorrelationIDAsBytes(correlationID);
- }
-
- public void setJMSCorrelationID(String correlationID) throws JMSException
- {
- headerChange();
- message.setJMSCorrelationID(correlationID);
- }
-
- public String getJMSCorrelationID() throws JMSException
- {
- return message.getJMSCorrelationID();
- }
-
- public Destination getJMSReplyTo() throws JMSException
- {
- return message.getJMSReplyTo();
- }
-
- public void setJMSReplyTo(Destination replyTo) throws JMSException
- {
- headerChange();
- message.setJMSReplyTo(replyTo);
- }
-
- public Destination getJMSDestination() throws JMSException
- {
- return message.getJMSDestination();
- }
-
- public void setJMSDestination(Destination destination) throws JMSException
- {
- headerChange();
- message.setJMSDestination(destination);
- }
-
- public int getJMSDeliveryMode() throws JMSException
- {
- return message.getJMSDeliveryMode();
- }
-
- public void setJMSDeliveryMode(int deliveryMode) throws JMSException
- {
- headerChange();
- message.setJMSDeliveryMode(deliveryMode);
- }
-
- public boolean getJMSRedelivered() throws JMSException
- {
- //Always handled in the delegate
- //This is because when sending a message to a topic (for instance)
- //with multiple subscriptions all in the same VM, then we don't copy the original
- //message for performance reasons, unless necessary, but each reference might have
- //it's own value for delivery count
- return deliveryCount >= 2;
- }
-
- public void setJMSRedelivered(boolean redelivered) throws JMSException
- {
- //Always handled in the delegate
- if (deliveryCount == 1)
- {
- deliveryCount++;
- }
- else
- {
- //do nothing
- }
- }
-
- public String getJMSType() throws JMSException
- {
- return message.getJMSType();
- }
-
- public void setJMSType(String type) throws JMSException
- {
- headerChange();
- message.setJMSType(type);
- }
-
- public long getJMSExpiration() throws JMSException
- {
- return message.getJMSExpiration();
- }
-
- public void setJMSExpiration(long expiration) throws JMSException
- {
- headerChange();
- message.setJMSExpiration(expiration);
- }
-
- public int getJMSPriority() throws JMSException
- {
- return message.getJMSPriority();
- }
-
- public void setJMSPriority(int priority) throws JMSException
- {
- headerChange();
- message.setJMSPriority(priority);
- }
-
- public void clearProperties() throws JMSException
- {
- headerChange();
- message.clearProperties();
- propertiesReadOnly = false;
- }
-
- public boolean propertyExists(String name) throws JMSException
- {
- return message.propertyExists(name);
- }
-
- public boolean getBooleanProperty(String name) throws JMSException
- {
- return message.getBooleanProperty(name);
- }
-
- public byte getByteProperty(String name) throws JMSException
- {
- return message.getByteProperty(name);
- }
-
- public short getShortProperty(String name) throws JMSException
- {
- return message.getShortProperty(name);
- }
-
- public int getIntProperty(String name) throws JMSException
- {
- //JMSDeliveryCount is always dealt within inside the proxy
- if ("JMSXDeliveryCount".equals(name))
- {
- return deliveryCount;
- }
- return message.getIntProperty(name);
- }
-
- public long getLongProperty(String name) throws JMSException
- {
- //JMSDeliveryCount is always dealt within inside the proxy
- if ("JMSXDeliveryCount".equals(name))
- {
- return deliveryCount;
- }
- return message.getLongProperty(name);
- }
-
- public float getFloatProperty(String name) throws JMSException
- {
- return message.getFloatProperty(name);
- }
-
- public double getDoubleProperty(String name) throws JMSException
- {
- return message.getDoubleProperty(name);
- }
-
- public String getStringProperty(String name) throws JMSException
- {
- //JMSDeliveryCount is always dealt within inside the proxy
- if ("JMSXDeliveryCount".equals(name))
- {
- return Integer.toString(deliveryCount);
- }
- return message.getStringProperty(name);
- }
-
- public Object getObjectProperty(String name) throws JMSException
- {
- return message.getObjectProperty(name);
- }
-
- public Enumeration getPropertyNames() throws JMSException
- {
- return message.getPropertyNames();
- }
-
- public void setBooleanProperty(String name, boolean value) throws JMSException
- {
- if (propertiesReadOnly)
- throw new MessageNotWriteableException("Properties are read-only");
- headerChange();
- message.setBooleanProperty(name, value);
- }
-
- public void setByteProperty(String name, byte value) throws JMSException
- {
- if (propertiesReadOnly)
- throw new MessageNotWriteableException("Properties are read-only");
- headerChange();
- message.setByteProperty(name, value);
- }
-
- public void setShortProperty(String name, short value) throws JMSException
- {
- if (propertiesReadOnly)
- throw new MessageNotWriteableException("Properties are read-only");
- headerChange();
- message.setShortProperty(name, value);
- }
-
- public void setIntProperty(String name, int value) throws JMSException
- {
- if (propertiesReadOnly)
- throw new MessageNotWriteableException("Properties are read-only");
- headerChange();
- message.setIntProperty(name, value);
- }
-
- public void setLongProperty(String name, long value) throws JMSException
- {
- if (propertiesReadOnly)
- throw new MessageNotWriteableException("Properties are read-only");
- headerChange();
- message.setLongProperty(name, value);
- }
-
- public void setFloatProperty(String name, float value) throws JMSException
- {
- if (propertiesReadOnly)
- throw new MessageNotWriteableException("Properties are read-only");
- headerChange();
- message.setFloatProperty(name, value);
- }
-
- public void setDoubleProperty(String name, double value) throws JMSException
- {
- if (propertiesReadOnly)
- throw new MessageNotWriteableException("Properties are read-only");
- headerChange();
- message.setDoubleProperty(name, value);
- }
-
- public void setStringProperty(String name, String value) throws JMSException
- {
- if (propertiesReadOnly)
- throw new MessageNotWriteableException("Properties are read-only");
- headerChange();
- message.setStringProperty(name, value);
- }
-
- public void setObjectProperty(String name, Object value) throws JMSException
- {
- if (propertiesReadOnly)
- throw new MessageNotWriteableException("Properties are read-only");
- headerChange();
- message.setObjectProperty(name, value);
- }
-
- public void acknowledge() throws JMSException
- {
- if (!cc)
- {
- //Only acknowledge for client ack if is not in connection consumer
- delegate.acknowledgeAll();
- }
- }
-
- public void clearBody() throws JMSException
- {
- bodyChange();
- message.clearBody();
- bodyReadOnly = false;
- }
-
-
- // Public --------------------------------------------------------
-
- public void setSessionDelegate(SessionDelegate sd, boolean isConnectionConsumer)
- {
- this.delegate = sd;
- this.cc = isConnectionConsumer;
- }
-
- public SessionDelegate getSessionDelegate()
- {
- return delegate;
- }
-
- public JBossMessage getMessage()
- {
- return message;
- }
-
- public int getDeliveryCount()
- {
- return deliveryCount;
- }
-
- public void incDeliveryCount()
- {
- this.deliveryCount++;
- }
-
- public long getDeliveryId()
- {
- return deliveryId;
- }
-
- public String toString()
- {
- return "delegator->" + message + ", deliveryId=" + deliveryId;
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- protected void headerChange() throws JMSException
- {
- if (needToCopyHeader)
- {
- copyMessage();
- }
- }
-
- protected void bodyChange() throws JMSException
- {
- if (needToCopyBody)
- {
- headerChange();
-
- message.copyPayload(message.getPayload());
-
- needToCopyBody = false;
- }
- }
-
- // Private -------------------------------------------------------
-
- private void copyMessage() throws JMSException
- {
- message = message.doCopy();
-
- needToCopyHeader = false;
- }
-
- // Inner classes -------------------------------------------------
-}
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/ObjectMessageProxy.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/ObjectMessageProxy.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/ObjectMessageProxy.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,66 +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.message;
-
-import java.io.Serializable;
-
-import javax.jms.JMSException;
-import javax.jms.MessageNotWriteableException;
-import javax.jms.ObjectMessage;
-
-/**
- *
- * Thin proxy for a JBossObjectMessage
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * ObjectMessageProxy.java,v 1.1 2006/03/08 08:00:34 timfox Exp
- */
-public class ObjectMessageProxy extends MessageProxy implements ObjectMessage
-{
- private static final long serialVersionUID = 8797295997477962825L;
-
- public ObjectMessageProxy(long deliveryId, JBossObjectMessage message, int deliveryCount)
- {
- super(deliveryId, message, deliveryCount);
- }
-
- public ObjectMessageProxy(JBossObjectMessage message)
- {
- super(message);
- }
-
- public void setObject(Serializable object) throws JMSException
- {
- if (bodyReadOnly)
- {
- throw new MessageNotWriteableException("setObject");
- }
- bodyChange();
- ((ObjectMessage)message).setObject(object);
- }
-
- public Serializable getObject() throws JMSException
- {
- return ((ObjectMessage)message).getObject();
- }
-}
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/StreamMessageProxy.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/StreamMessageProxy.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/StreamMessageProxy.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,241 +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.message;
-
-import javax.jms.JMSException;
-import javax.jms.MessageNotReadableException;
-import javax.jms.MessageNotWriteableException;
-import javax.jms.StreamMessage;
-
-/**
- *
- * Thin proxy for a JBossStreamMessage
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * StreamMessageProxy.java,v 1.1 2006/03/08 08:00:34 timfox Exp
- */
-public class StreamMessageProxy extends MessageProxy implements StreamMessage
-{
- private static final long serialVersionUID = 856367553964704474L;
-
- public StreamMessageProxy(long deliveryId, JBossStreamMessage message, int deliveryCount)
- {
- super(deliveryId, message, deliveryCount);
- }
-
- public StreamMessageProxy(JBossStreamMessage message)
- {
- super(message);
- }
-
- public boolean readBoolean() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readBoolean();
- }
-
- public byte readByte() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readByte();
- }
-
- public int readBytes(byte[] value) throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readBytes(value);
- }
-
- public char readChar() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readChar();
- }
-
- public double readDouble() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readDouble();
- }
-
- public float readFloat() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readFloat();
- }
-
- public int readInt() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readInt();
- }
-
- public long readLong() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readLong();
- }
-
- public Object readObject() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readObject();
- }
-
- public short readShort() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readShort();
- }
-
- public String readString() throws JMSException
- {
- if (!bodyReadOnly)
- throw new MessageNotReadableException("The message body is writeonly");
-
- return ((StreamMessage)message).readString();
- }
-
- public void reset() throws JMSException
- {
- bodyReadOnly = true;
- ((StreamMessage)message).reset();
- }
-
- public void writeBoolean(boolean value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeBoolean(value);
- }
-
- public void writeByte(byte value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeByte(value);
- }
-
- public void writeBytes(byte[] value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeBytes(value);
- }
-
- public void writeBytes(byte[] value, int offset, int length) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeBytes(value, offset, length);
- }
-
- public void writeChar(char value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeChar(value);
- }
-
- public void writeDouble(double value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeDouble(value);
- }
-
- public void writeFloat(float value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeFloat(value);
- }
-
- public void writeInt(int value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeInt(value);
- }
-
- public void writeLong(long value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeLong(value);
- }
-
- public void writeObject(Object value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeObject(value);
- }
-
- public void writeShort(short value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeShort(value);
- }
-
- public void writeString(String value) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("The message body is readonly");
- bodyChange();
- ((StreamMessage)message).writeString(value);
- }
-}
-
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/jms/message/TextMessageProxy.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/message/TextMessageProxy.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/TextMessageProxy.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,61 +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.message;
-
-import javax.jms.JMSException;
-import javax.jms.MessageNotWriteableException;
-import javax.jms.TextMessage;
-
-/**
- *
- * Thin proxy for a JBossTextMessage
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class TextMessageProxy extends MessageProxy implements TextMessage
-{
- private static final long serialVersionUID = -3530143417050205123L;
-
- public TextMessageProxy(long deliveryId, JBossTextMessage message, int deliveryCount)
- {
- super(deliveryId, message, deliveryCount);
- }
-
- public TextMessageProxy(JBossTextMessage message)
- {
- super(message);
- }
-
- public void setText(String string) throws JMSException
- {
- if (bodyReadOnly)
- throw new MessageNotWriteableException("Cannot set the content; message is read-only");
- bodyChange();
- ((TextMessage)message).setText(string);
- }
-
- public String getText() throws JMSException
- {
- return ((TextMessage)message).getText();
- }
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectionFactoryManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectionFactoryManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectionFactoryManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -23,7 +23,7 @@
import org.jboss.jms.client.plugin.LoadBalancingFactory;
import org.jboss.jms.server.connectionfactory.JNDIBindings;
-import org.jboss.messaging.core.contract.MessagingComponent;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectionManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectionManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectionManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,7 +24,7 @@
import java.util.List;
import org.jboss.jms.delegate.ConnectionEndpoint;
-import org.jboss.messaging.core.contract.MessagingComponent;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectorManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectorManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ConnectorManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,7 +21,7 @@
*/
package org.jboss.jms.server;
-import org.jboss.messaging.core.contract.MessagingComponent;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
/**
*
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/DestinationManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/DestinationManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/DestinationManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,7 +24,7 @@
import java.util.Set;
import org.jboss.jms.server.destination.ManagedDestination;
-import org.jboss.messaging.core.contract.MessagingComponent;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
/**
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/bridge/Bridge.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/bridge/Bridge.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/bridge/Bridge.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -50,7 +50,7 @@
import org.jboss.jms.client.state.SessionState;
import org.jboss.jms.message.JBossMessage;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.MessagingComponent;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import org.jboss.tm.TransactionManagerLocator;
/**
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/bridge/BridgeService.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/bridge/BridgeService.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/bridge/BridgeService.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -25,7 +25,7 @@
import javax.management.ObjectName;
-import org.jboss.messaging.core.contract.MessagingComponent;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import org.jboss.system.ServiceMBeanSupport;
/**
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/DestinationServiceSupport.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/DestinationServiceSupport.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/DestinationServiceSupport.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -17,9 +17,9 @@
import org.jboss.jms.server.ServerPeer;
import org.jboss.jms.server.messagecounter.MessageCounter;
import org.jboss.messaging.core.contract.Condition;
-import org.jboss.messaging.core.contract.MessagingComponent;
import org.jboss.messaging.core.contract.PostOffice;
import org.jboss.messaging.core.contract.Queue;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import org.jboss.messaging.util.ExceptionUtil;
import org.jboss.messaging.util.JMXAccessor;
import org.jboss.system.ServiceMBeanSupport;
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedDestination.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedDestination.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedDestination.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -28,9 +28,9 @@
import org.jboss.jms.server.ServerPeer;
import org.jboss.messaging.core.contract.Binding;
import org.jboss.messaging.core.contract.Condition;
-import org.jboss.messaging.core.contract.MessagingComponent;
import org.jboss.messaging.core.contract.PostOffice;
import org.jboss.messaging.core.contract.Queue;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import org.w3c.dom.Element;
/**
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedQueue.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedQueue.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedQueue.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -28,8 +28,8 @@
import org.jboss.jms.server.messagecounter.MessageCounter;
import org.jboss.jms.server.selector.Selector;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Message;
import org.jboss.messaging.core.contract.Queue;
+import org.jboss.messaging.newcore.intf.Message;
/**
* A ManagedQueue
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedTopic.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedTopic.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedTopic.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -31,8 +31,8 @@
import org.jboss.jms.server.selector.Selector;
import org.jboss.logging.Logger;
import org.jboss.messaging.core.contract.Binding;
-import org.jboss.messaging.core.contract.Message;
import org.jboss.messaging.core.contract.Queue;
+import org.jboss.messaging.newcore.intf.Message;
import org.jboss.messaging.util.MessageQueueNameHelper;
/**
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -26,15 +26,14 @@
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
-import javax.jms.Message;
import org.jboss.jms.delegate.BrowserEndpoint;
-import org.jboss.jms.message.JBossMessage;
import org.jboss.jms.server.selector.Selector;
import org.jboss.jms.wireformat.Dispatcher;
import org.jboss.logging.Logger;
import org.jboss.messaging.core.contract.Channel;
import org.jboss.messaging.core.contract.Filter;
+import org.jboss.messaging.newcore.intf.Message;
import org.jboss.messaging.util.ExceptionUtil;
/**
@@ -125,7 +124,7 @@
}
}
- public JBossMessage nextMessage() throws JMSException
+ public Message nextMessage() throws JMSException
{
try
{
@@ -139,7 +138,7 @@
iterator = createIterator();
}
- JBossMessage r = (JBossMessage)iterator.next();
+ Message r = (Message)iterator.next();
if (trace) { log.trace(this + " returning " + r); }
@@ -151,7 +150,7 @@
}
}
- public JBossMessage[] nextMessageBlock(int maxMessages) throws JMSException
+ public Message[] nextMessageBlock(int maxMessages) throws JMSException
{
if (trace) { log.trace(this + " returning next message block of " + maxMessages); }
@@ -185,7 +184,7 @@
}
else break;
}
- return (JBossMessage[])messages.toArray(new JBossMessage[messages.size()]);
+ return (Message[])messages.toArray(new Message[messages.size()]);
}
catch (Throwable t)
{
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -42,7 +42,6 @@
import org.jboss.jms.delegate.IDBlock;
import org.jboss.jms.delegate.SessionDelegate;
import org.jboss.jms.destination.JBossDestination;
-import org.jboss.jms.message.JBossMessage;
import org.jboss.jms.server.ConnectionManager;
import org.jboss.jms.server.JMSCondition;
import org.jboss.jms.server.SecurityStore;
@@ -57,13 +56,13 @@
import org.jboss.logging.Logger;
import org.jboss.messaging.core.contract.Binding;
import org.jboss.messaging.core.contract.Delivery;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.MessageStore;
import org.jboss.messaging.core.contract.PostOffice;
import org.jboss.messaging.core.contract.Queue;
import org.jboss.messaging.core.impl.tx.Transaction;
import org.jboss.messaging.core.impl.tx.TransactionRepository;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
import org.jboss.messaging.util.ExceptionUtil;
import org.jboss.messaging.util.GUIDGenerator;
import org.jboss.messaging.util.Util;
@@ -648,7 +647,7 @@
return remotingClientSessionID;
}
- void sendMessage(JBossMessage msg, Transaction tx, boolean checkForDuplicates) throws Exception
+ void sendMessage(Message msg, Transaction tx, boolean checkForDuplicates) throws Exception
{
if (trace) { log.trace(this + " sending message " + msg + (tx == null ? " non-transactionally" : " in " + tx)); }
@@ -673,38 +672,41 @@
}
}
- JBossDestination dest = (JBossDestination)msg.getJMSDestination();
-
+ String dest = msg.getDestination();
+
// This allows the no-local consumers to filter out the messages that come from the same
// connection.
-
- // TODO Do we want to set this for ALL messages. Optimisation is possible here.
+
msg.setConnectionID(id);
-
// We must reference the message *before* we send it the destination to be handled. This is
// so we can guarantee that the message doesn't disappear from the store before the
// handling is complete. Each channel then takes copies of the reference if they decide to
// maintain it internally
MessageReference ref = msg.createReference();
-
- long schedDeliveryTime = msg.getScheduledDeliveryTime();
-
+
+ //TODO - we could optimise here to avoid a hash lookup
+ Long l = (Long)msg.getHeader(Message.SCHEDULED_DELIVERY_TIME);
+ long schedDeliveryTime = l == null ? 0 : l.longValue();
+
if (schedDeliveryTime > 0)
{
ref.setScheduledDeliveryTime(schedDeliveryTime);
}
- if (dest.isDirect())
+ String actualDest = dest.substring(1);
+
+ //FIXME temp kludge which will be removed before refactoring is complete
+ if (dest.charAt(0) == 'D')
{
//Route directly to queue - temp kludge for clustering
- Binding binding = postOffice.getBindingForQueueName(dest.getName());
+ Binding binding = postOffice.getBindingForQueueName(actualDest);
if (binding == null)
{
- throw new IllegalArgumentException("Cannot find binding for queue " + dest.getName());
+ throw new IllegalArgumentException("Cannot find binding for queue " + actualDest);
}
Queue queue = binding.queue;
@@ -715,19 +717,23 @@
if (del == null)
{
- throw new JMSException("Failed to route " + ref + " to " + dest.getName());
+ throw new JMSException("Failed to route " + ref + " to " + actualDest);
}
}
- else if (dest.isQueue())
+ else if (dest.charAt(0) == 'Q')
{
- if (!postOffice.route(ref, new JMSCondition(true, dest.getName()), tx))
+ if (!postOffice.route(ref, new JMSCondition(true, actualDest), tx))
{
- throw new JMSException("Failed to route " + ref + " to " + dest.getName());
+ throw new JMSException("Failed to route " + ref + " to " + actualDest);
}
}
+ else if (dest.charAt(0) == 'T')
+ {
+ postOffice.route(ref, new JMSCondition(false, actualDest), tx);
+ }
else
{
- postOffice.route(ref, new JMSCondition(false, dest.getName()), tx);
+ throw new IllegalArgumentException("Invalid dest " + dest);
}
if (trace) { log.trace("sent " + msg); }
@@ -787,7 +793,7 @@
for (Iterator j = sessionState.getMsgs().iterator(); j.hasNext(); )
{
- JBossMessage message = (JBossMessage)j.next();
+ Message message = (Message)j.next();
sendMessage(message, tx, checkForDuplicates);
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -27,7 +27,6 @@
import org.jboss.jms.delegate.ConsumerEndpoint;
import org.jboss.jms.destination.JBossDestination;
-import org.jboss.jms.message.JBossMessage;
import org.jboss.jms.server.ServerPeer;
import org.jboss.jms.server.destination.ManagedDestination;
import org.jboss.jms.server.destination.TopicService;
@@ -37,14 +36,14 @@
import org.jboss.logging.Logger;
import org.jboss.messaging.core.contract.Delivery;
import org.jboss.messaging.core.contract.DeliveryObserver;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.PostOffice;
import org.jboss.messaging.core.contract.Queue;
import org.jboss.messaging.core.contract.Receiver;
import org.jboss.messaging.core.contract.Replicator;
import org.jboss.messaging.core.impl.SimpleDelivery;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
import org.jboss.messaging.util.ExceptionUtil;
/**
@@ -268,7 +267,7 @@
if (noLocal)
{
- String conId = ((JBossMessage) message).getConnectionID();
+ String conId = message.getConnectionID();
if (trace) { log.trace("message connection id: " + conId + " current connection connection id: " + sessionEndpoint.getConnectionEndpoint().getConnectionID()); }
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -50,7 +50,6 @@
import org.jboss.jms.destination.JBossDestination;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
-import org.jboss.jms.message.JBossMessage;
import org.jboss.jms.server.DestinationManager;
import org.jboss.jms.server.JMSCondition;
import org.jboss.jms.server.ServerPeer;
@@ -70,8 +69,6 @@
import org.jboss.messaging.core.contract.Condition;
import org.jboss.messaging.core.contract.Delivery;
import org.jboss.messaging.core.contract.DeliveryObserver;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.MessageStore;
import org.jboss.messaging.core.contract.PersistenceManager;
import org.jboss.messaging.core.contract.PostOffice;
@@ -83,6 +80,8 @@
import org.jboss.messaging.core.impl.tx.TransactionException;
import org.jboss.messaging.core.impl.tx.TransactionRepository;
import org.jboss.messaging.core.impl.tx.TxCallback;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
import org.jboss.messaging.util.ExceptionUtil;
import org.jboss.messaging.util.GUIDGenerator;
import org.jboss.messaging.util.MessageQueueNameHelper;
@@ -373,14 +372,14 @@
private volatile long expectedSequence = 0;
- private Map<Long, JBossMessage> heldBack = new HashMap<Long, JBossMessage>();
+ private Map<Long, Message> heldBack = new HashMap<Long, Message>();
- public void send(JBossMessage message, boolean checkForDuplicates) throws JMSException
+ public void send(Message message, boolean checkForDuplicates) throws JMSException
{
throw new IllegalStateException("Should not be handled on the server");
}
- public void send(JBossMessage message, boolean checkForDuplicates, long thisSequence) throws JMSException
+ public void send(Message message, boolean checkForDuplicates, long thisSequence) throws JMSException
{
try
{
@@ -402,7 +401,7 @@
expectedSequence++;
- message = (JBossMessage)heldBack.remove(expectedSequence);
+ message = (Message)heldBack.remove(expectedSequence);
} while (message != null);
}
@@ -1111,7 +1110,7 @@
{
if (trace) { log.trace(this + " sending expired message to expiry queue " + expiryQueue); }
- JBossMessage copy = makeCopyForDLQOrExpiry(true, del);
+ Message copy = makeCopyForDLQOrExpiry(true, del);
moveInTransaction(copy, del, expiryQueue, true);
}
@@ -1659,7 +1658,7 @@
{
//Sent to expiry queue
- JBossMessage copy = makeCopyForDLQOrExpiry(true, del);
+ Message copy = makeCopyForDLQOrExpiry(true, del);
moveInTransaction(copy, del, rec.expiryQueue, false);
}
@@ -1667,7 +1666,7 @@
{
//Send to DLQ
- JBossMessage copy = makeCopyForDLQOrExpiry(false, del);
+ Message copy = makeCopyForDLQOrExpiry(false, del);
moveInTransaction(copy, del, rec.dlq, true);
}
@@ -1679,7 +1678,7 @@
return rec.del;
}
- private JBossMessage makeCopyForDLQOrExpiry(boolean expiry, Delivery del) throws Exception
+ private Message makeCopyForDLQOrExpiry(boolean expiry, Delivery del) throws Exception
{
//We copy the message and send that to the dlq/expiry queue - this is because
//otherwise we may end up with a ref with the same message id in the queue more than once
@@ -1689,17 +1688,21 @@
if (trace) { log.trace("Making copy of message for DLQ or expiry " + del); }
- JBossMessage msg = ((JBossMessage)del.getReference().getMessage());
+ Message msg = del.getReference().getMessage();
- JBossMessage copy = msg.doCopy();
+ Message copy = msg.copy();
long newMessageId = sp.getMessageIDManager().getID();
- copy.setMessageId(newMessageId);
+ copy.setMessageID(newMessageId);
//reset expiry
copy.setExpiration(0);
+ //FIXME - this stuff is JMS specific - shouldn't be on server
+
+ /*
+
String origMessageId = msg.getJMSMessageID();
String origDest = msg.getJMSDestination().toString();
@@ -1714,11 +1717,14 @@
copy.setLongProperty(JBossMessage.JBOSS_MESSAGING_ACTUAL_EXPIRY_TIME, actualExpiryTime);
}
+ */
+ //end FIXME
+
return copy;
}
- private void moveInTransaction(JBossMessage msg, Delivery del, Queue queue, boolean dlq) throws Throwable
+ private void moveInTransaction(Message msg, Delivery del, Queue queue, boolean dlq) throws Throwable
{
Transaction tx = tr.createTransaction();
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/SessionInternalEndpoint.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/SessionInternalEndpoint.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/SessionInternalEndpoint.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,7 +24,7 @@
import javax.jms.JMSException;
import org.jboss.jms.delegate.SessionEndpoint;
-import org.jboss.jms.message.JBossMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
*
@@ -36,5 +36,5 @@
*/
public interface SessionInternalEndpoint extends SessionEndpoint
{
- void send(JBossMessage msg, boolean checkForDuplicates, long seq) throws JMSException;
+ void send(Message msg, boolean checkForDuplicates, long seq) throws JMSException;
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/advised/BrowserAdvised.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/advised/BrowserAdvised.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/advised/BrowserAdvised.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,7 +24,7 @@
import javax.jms.JMSException;
import org.jboss.jms.delegate.BrowserEndpoint;
-import org.jboss.jms.message.JBossMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
* The server-side advised instance corresponding to a Browser. It is bound to the AOP
@@ -75,12 +75,12 @@
return endpoint.hasNextMessage();
}
- public JBossMessage nextMessage() throws JMSException
+ public Message nextMessage() throws JMSException
{
return endpoint.nextMessage();
}
- public JBossMessage[] nextMessageBlock(int maxMessages) throws JMSException
+ public Message[] nextMessageBlock(int maxMessages) throws JMSException
{
return endpoint.nextMessageBlock(maxMessages);
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/advised/SessionAdvised.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/advised/SessionAdvised.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/advised/SessionAdvised.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -33,9 +33,9 @@
import org.jboss.jms.destination.JBossDestination;
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
-import org.jboss.jms.message.JBossMessage;
import org.jboss.jms.server.endpoint.ServerSessionEndpoint;
import org.jboss.jms.server.endpoint.SessionInternalEndpoint;
+import org.jboss.messaging.newcore.intf.Message;
/**
* The server-side advised instance corresponding to a Session. It is bound to the AOP
@@ -77,12 +77,12 @@
return endpoint.closing(sequence);
}
- public void send(JBossMessage msg, boolean checkForDuplicates) throws JMSException
+ public void send(Message msg, boolean checkForDuplicates) throws JMSException
{
throw new IllegalStateException("Invocation should not be handle here");
}
- public void send(JBossMessage msg, boolean checkForDuplicates, long seq) throws JMSException
+ public void send(Message msg, boolean checkForDuplicates, long seq) throws JMSException
{
((ServerSessionEndpoint)endpoint).send(msg, checkForDuplicates, seq);
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/messagecounter/MessageCounterManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/messagecounter/MessageCounterManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/messagecounter/MessageCounterManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -30,7 +30,7 @@
import java.util.TimerTask;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.MessagingComponent;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
/**
*
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManagerService.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManagerService.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManagerService.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,8 +24,8 @@
import javax.transaction.TransactionManager;
import org.jboss.jms.server.plugin.contract.JMSUserManager;
-import org.jboss.messaging.core.contract.MessagingComponent;
import org.jboss.messaging.core.jmx.JDBCServiceSupport;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import org.jboss.messaging.util.ExceptionUtil;
/**
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/plugin/contract/JMSUserManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/plugin/contract/JMSUserManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/plugin/contract/JMSUserManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,7 +21,7 @@
*/
package org.jboss.jms.server.plugin.contract;
-import org.jboss.messaging.core.contract.MessagingComponent;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
/**
* A JMSUserManager
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/Selector.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/Selector.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/Selector.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -113,7 +113,7 @@
return selector;
}
- public synchronized boolean accept(org.jboss.messaging.core.contract.Message message)
+ public synchronized boolean accept(org.jboss.messaging.newcore.intf.Message message)
{
try
{
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ClientTransaction.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ClientTransaction.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ClientTransaction.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -35,7 +35,8 @@
import org.jboss.jms.delegate.DeliveryInfo;
import org.jboss.jms.message.JBossMessage;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.impl.message.MessageFactory;
+import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
* Holds the state of a transaction on the client side
@@ -99,7 +100,7 @@
}
SessionTxState sessionTxState = getSessionTxState(sessionId);
- sessionTxState.addMessage(msg);
+ sessionTxState.addMessage(msg.getCoreMessage());
}
public void addAck(String sessionId, DeliveryInfo info)
@@ -112,7 +113,7 @@
sessionTxState.addAck(info);
- if (info.getMessageProxy().getMessage().isReliable())
+ if (info.getMessage().getCoreMessage().isReliable())
{
hasPersistentAcks = true;
}
@@ -280,9 +281,9 @@
{
JBossMessage m = (JBossMessage)iter2.next();
- out.writeByte(m.getType());
-
- m.write(out);
+ Message cm = m.getCoreMessage();
+
+ cm.write(out);
}
List acks = state.getAcks();
@@ -297,7 +298,7 @@
if (ack.isShouldAck())
{
//We only need the delivery id written
- out.writeLong(ack.getMessageProxy().getDeliveryId());
+ out.writeLong(ack.getMessage().getDeliveryId());
}
}
@@ -331,11 +332,9 @@
int numMsgs = in.readInt();
for (int j = 0; j < numMsgs; j++)
- {
- byte type = in.readByte();
+ {
+ Message msg = new MessageImpl();
- JBossMessage msg = (JBossMessage)MessageFactory.createMessage(type);
-
msg.read(in);
sessionState.addMessage(msg);
@@ -394,7 +393,7 @@
this.sessionID = sessionID;
}
- void addMessage(JBossMessage msg)
+ void addMessage(Message msg)
{
msgs.add(msg);
}
@@ -436,7 +435,7 @@
{
DeliveryInfo di = (DeliveryInfo)i.next();
- if (!di.getMessageProxy().getMessage().isReliable())
+ if (!di.getMessage().getCoreMessage().isReliable())
{
if (trace) { log.trace(this + " discarded non-persistent " + di + " on failover"); }
i.remove();
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ResourceManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ResourceManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ResourceManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -40,7 +40,6 @@
import org.jboss.jms.exception.MessagingTransactionRolledBackException;
import org.jboss.jms.exception.MessagingXAException;
import org.jboss.jms.message.JBossMessage;
-import org.jboss.jms.message.MessageProxy;
import org.jboss.jms.tx.ClientTransaction.SessionTxState;
import org.jboss.logging.Logger;
@@ -615,7 +614,7 @@
{
DeliveryInfo info = (DeliveryInfo)acks.get(0);
- MessageProxy mp = info.getMessageProxy();
+ JBossMessage mp = info.getMessage();
SessionDelegate del = mp.getSessionDelegate();
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageBlockResponse.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageBlockResponse.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageBlockResponse.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -25,7 +25,8 @@
import java.io.DataOutputStream;
import org.jboss.jms.message.JBossMessage;
-import org.jboss.messaging.core.impl.message.MessageFactory;
+import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
*
@@ -39,13 +40,13 @@
*/
public class BrowserNextMessageBlockResponse extends ResponseSupport
{
- private JBossMessage[] msgs;
+ private Message[] msgs;
public BrowserNextMessageBlockResponse()
{
}
- public BrowserNextMessageBlockResponse(JBossMessage[] msgs)
+ public BrowserNextMessageBlockResponse(Message[] msgs)
{
super(PacketSupport.RESP_BROWSER_NEXTMESSAGEBLOCK);
@@ -67,10 +68,8 @@
for (int i = 0; i < len; i++)
{
- JBossMessage msg = msgs[i];
+ Message msg = msgs[i];
- os.writeByte(msg.getType());
-
msg.write(os);
}
@@ -83,10 +82,8 @@
for (int i = 0; i < len; i++)
{
- byte type = is.readByte();
+ Message msg = new MessageImpl();
- JBossMessage msg = (JBossMessage)MessageFactory.createMessage(type);
-
msg.read(is);
msgs[i] = msg;
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageResponse.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageResponse.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageResponse.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,8 +24,8 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import org.jboss.jms.message.JBossMessage;
-import org.jboss.messaging.core.impl.message.MessageFactory;
+import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
*
@@ -39,13 +39,13 @@
*/
public class BrowserNextMessageResponse extends ResponseSupport
{
- private JBossMessage msg;
+ private Message msg;
public BrowserNextMessageResponse()
{
}
- public BrowserNextMessageResponse(JBossMessage msg)
+ public BrowserNextMessageResponse(Message msg)
{
super(PacketSupport.RESP_BROWSER_NEXTMESSAGE);
@@ -61,8 +61,6 @@
{
super.write(os);
- os.writeByte(msg.getType());
-
msg.write(os);
os.flush();
@@ -70,10 +68,8 @@
public void read(DataInputStream is) throws Exception
{
- byte type = is.readByte();
+ msg = new MessageImpl();
- msg = (JBossMessage)MessageFactory.createMessage(type);
-
msg.read(is);
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/ClientDelivery.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/ClientDelivery.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/ClientDelivery.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,8 +24,8 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.impl.message.MessageFactory;
+import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
*
@@ -86,8 +86,6 @@
out.writeLong(deliveryId);
- out.writeByte(msg.getType());
-
msg.write(out);
out.flush();
@@ -100,11 +98,9 @@
deliveryCount = in.readInt();
deliveryId = in.readLong();
+
+ msg = new MessageImpl();
- byte type = in.readByte();
-
- msg = MessageFactory.createMessage(type);
-
msg.read(in);
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/SessionSendRequest.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/SessionSendRequest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/SessionSendRequest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -25,12 +25,12 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import org.jboss.jms.message.JBossMessage;
import org.jboss.jms.server.ServerPeer;
import org.jboss.jms.server.endpoint.advised.SessionAdvised;
-import org.jboss.messaging.core.impl.message.MessageFactory;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.invocation.OnewayInvocation;
+import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
*
@@ -43,9 +43,8 @@
*
*/
public class SessionSendRequest extends RequestSupport
-{
-
- private JBossMessage msg;
+{
+ private Message msg;
private boolean checkForDuplicates;
private long sequence;
@@ -55,7 +54,7 @@
public SessionSendRequest(String objectId,
byte version,
- JBossMessage msg,
+ Message msg,
boolean checkForDuplicates,
long sequence)
{
@@ -69,9 +68,7 @@
{
super.read(is);
- byte messageType = is.readByte();
-
- msg = (JBossMessage)MessageFactory.createMessage(messageType);
+ msg = new MessageImpl();
msg.read(is);
@@ -111,8 +108,6 @@
{
super.write(os);
- os.writeByte(msg.getType());
-
msg.write(os);
os.writeBoolean(checkForDuplicates);
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Channel.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Channel.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Channel.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -23,6 +23,9 @@
import java.util.List;
+import org.jboss.messaging.newcore.intf.Filter;
+
+
/**
* A Channel is a transactional, reliable message delivery mechanism that forwards a message from a
* sender to one or more receivers.
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Delivery.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Delivery.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Delivery.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -22,6 +22,7 @@
package org.jboss.messaging.core.contract;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.MessageReference;
/**
* A message delivery. It can be "done" or active.
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Filter.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Filter.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Filter.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -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.messaging.core.contract;
-
-
-/**
- * A filter encapsulates the logic of whether to accept a message or not. Filters are used when
- * browsing to restrict the messages browsed, or when routing messages.
- *
- * @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 Filter
-{
- /**
- * Tests whether the message should be accepted.
- *
- * @return true if the Filter accepts the message - i.e. let's it pass.
- */
- boolean accept(Message message);
-
- String getFilterString();
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/FilterFactory.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/FilterFactory.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/FilterFactory.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,8 +21,11 @@
*/
package org.jboss.messaging.core.contract;
+import org.jboss.messaging.newcore.intf.Filter;
+
+
/**
* A FilterFactory
*
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MemoryManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MemoryManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MemoryManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -21,7 +21,9 @@
*/
package org.jboss.messaging.core.contract;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
+
/**
* A MemoryManager
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Message.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Message.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Message.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,162 +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.messaging.core.contract;
-
-import java.util.Map;
-
-import org.jboss.messaging.util.Streamable;
-
-/**
- * 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>
- * @author <a href="mailto:tim.fox"jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public interface Message extends Streamable
-{
- /**
- * 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";
-
- /**
- * @return The unique id of the message
- */
- long getMessageID();
-
- /**
- * @return true if the delivery must be guaranteed for this routable, false otherwise.
- */
- boolean isReliable();
-
- /**
- * @return the time when this routable expires and must be removed
- * from the system. A zero value means this routable never expires.
- */
- long getExpiration();
-
- /**
- *
- * @return true if the message has expired
- */
- boolean isExpired();
-
- /**
- * Set the expiration for this message
- *
- * @param expiration
- */
- void setExpiration(long expiration);
-
- /**
- * @return the time (in GMT milliseconds) when this routable was delivered to the provider.
- */
- long getTimestamp();
-
- byte getPriority();
-
- /**
- * Get the priority of the message. Priorities range from 0 to 9.
- * Where 0 is the lowest priority and 9 is the highest priority
- * @param priority
- */
- void setPriority(byte priority);
-
- /**
- * Binds a header. If the header map previously contained a mapping for this name, the old value
- * is replaced by the specified value.
- *
- * @return the value associated with the name or null if there is no mapping for the name. A null
- * can also indicate that the header map previously associated null with the specified
- * name.
- */
- Object putHeader(String name, Object value);
-
- /**
- * Returns the value corresponding to the header name. Returns null if the map contains no
- * mapping for the name. A return value of null does not necessarily indicate that the map
- * contains no mapping for the name; it's also possible that the map explicitly maps the name to
- * null. The containsHeader() operation may be used to distinguish these two cases.
- *
- * @return the value associated with the header, or null if there is no mapping for the header.
- */
- Object getHeader(String name);
-
- /**
- * Removes the header.
- *
- * @return previous value associated with the header, or null if there was no mapping.
- */
- Object removeHeader(String name);
-
- /**
- * Returns true if the Routable contains the specified header.
- */
- boolean containsHeader(String name);
-
- /**
- *
- * @return The message's headers
- */
- Map getHeaders();
-
- /**
- *
- * @return The message's payload
- */
- Object getPayload();
-
- /**
- *
- * @return The message's payload in byte[] form
- */
- byte[] getPayloadAsByteArray();
-
- /**
- *
- * @return the type of the message
- */
- byte getType();
-
- /*
- * @return a reference for this message
- */
- MessageReference createReference();
-
- boolean isPersisted();
-
- void setPersisted(boolean persisted);
-}
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessageReference.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessageReference.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessageReference.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,62 +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.messaging.core.contract;
-
-/**
- * A reference to a message.
- *
- * Channels store message references rather than the messages themselves.
- *
- * If many channels have contain the same reference this makes a lot of sense
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public interface MessageReference
-{
- long getPagingOrder();
-
- void setPagingOrder(long order);
-
- Message getMessage();
-
- MessageReference copy();
-
- /**
- *
- * @return The time in the future that delivery will be delayed until, or zero if
- * no scheduled delivery will occur
- */
- long getScheduledDeliveryTime();
-
- void setScheduledDeliveryTime(long scheduledDeliveryTime);
-
- /**
- * @return the number of times delivery has been attempted for this routable
- */
- int getDeliveryCount();
-
- void setDeliveryCount(int deliveryCount);
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessageStore.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessageStore.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessageStore.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -6,7 +6,11 @@
*/
package org.jboss.messaging.core.contract;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
+
/**
* When loading a message from storage, references from different channels can reference the same message.
* In order to avoid loading the message more than once, loaded or paged references are stored in the message store
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessagingComponent.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessagingComponent.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/MessagingComponent.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.contract;
-
-/**
- * A MessagingComponent
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public interface MessagingComponent
-{
- void start() throws Exception;
-
- void stop() throws Exception;
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/PersistenceManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/PersistenceManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/PersistenceManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,6 +24,9 @@
import java.util.List;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
/**
* The interface to the persistence manager.
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/PostOffice.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/PostOffice.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/PostOffice.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -26,6 +26,8 @@
import java.util.Set;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.MessageReference;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
/**
*
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Queue.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Queue.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Queue.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -25,6 +25,8 @@
import java.util.Map;
import org.jboss.messaging.core.impl.clusterconnection.MessageSucker;
+import org.jboss.messaging.newcore.intf.Filter;
+import org.jboss.messaging.newcore.intf.MessageReference;
/**
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Receiver.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Receiver.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Receiver.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -22,6 +22,7 @@
package org.jboss.messaging.core.contract;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.MessageReference;
/**
* A component that handles MessageReferences.
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/ChannelSupport.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/ChannelSupport.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/ChannelSupport.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,1030 +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.messaging.core.impl;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import org.jboss.jms.server.MessagingTimeoutFactory;
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Channel;
-import org.jboss.messaging.core.contract.Delivery;
-import org.jboss.messaging.core.contract.DeliveryObserver;
-import org.jboss.messaging.core.contract.Distributor;
-import org.jboss.messaging.core.contract.Filter;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.core.contract.PersistenceManager;
-import org.jboss.messaging.core.impl.tx.Transaction;
-import org.jboss.messaging.core.impl.tx.TransactionException;
-import org.jboss.messaging.core.impl.tx.TxCallback;
-import org.jboss.messaging.util.prioritylinkedlist.BasicPriorityLinkedList;
-import org.jboss.messaging.util.prioritylinkedlist.PriorityLinkedList;
-import org.jboss.util.timeout.Timeout;
-import org.jboss.util.timeout.TimeoutTarget;
-
-import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt;
-
-/**
- *
- * This class provides much of the functionality needed to implement a channel.
- *
- * This partial implementation supports atomicity, isolation and recoverability for reliable messages.
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt> $Id: ChannelSupport.java,v 1.65
- * 2006/06/27 19:44:39 timfox Exp $
- */
-public abstract class ChannelSupport implements Channel
-{
- // Constants ------------------------------------------------------------------------------------
-
- private static final Logger log = Logger.getLogger(ChannelSupport.class);
-
- // Static ---------------------------------------------------------------------------------------
-
- // Attributes -----------------------------------------------------------------------------------
-
- private boolean trace = log.isTraceEnabled();
-
- protected long channelID;
-
- protected Distributor distributor;
-
- protected boolean receiversReady;
-
- protected PriorityLinkedList messageRefs;
-
- protected boolean recoverable;
-
- protected PersistenceManager pm;
-
- protected Object lock;
-
- protected volatile boolean active;
-
- //TODO - I would like to get rid of this - the only reason we still keep a count of
- //refs being delivered is because many tests require this
- //Having to keep this count requires synchronization between delivery thread and acknowledgement
- //thread which will hamper concurrency
- //Suggest that we have a flag that disables this for production systems
- protected SynchronizedInt deliveringCount;
-
- protected Set scheduledDeliveries;
-
- //The maximum number of refs this queue can hold, or -1 if no limit
- //If any more refs are added after this point they are dropped
- protected int maxSize;
-
- protected SynchronizedInt messagesAdded;
-
- // Constructors ---------------------------------------------------------------------------------
-
- protected ChannelSupport(long channelID, PersistenceManager pm,
- boolean recoverable, int maxSize)
- {
- if (trace) { log.trace("creating " + (pm != null ? "recoverable " : "non-recoverable ") + "channel[" + channelID + "]"); }
-
- this.pm = pm;
-
- this.channelID = channelID;
-
- this.recoverable = recoverable;
-
- messageRefs = new BasicPriorityLinkedList(10);
-
- lock = new Object();
-
- deliveringCount = new SynchronizedInt(0);
-
- scheduledDeliveries = new HashSet();
-
- this.maxSize = maxSize;
-
- messagesAdded = new SynchronizedInt(0);
- }
-
- // Receiver implementation ----------------------------------------------------------------------
-
- //Optimisation
- public Delivery handleMove(MessageReference ref, long sourceChannelID)
- {
- if (!isActive())
- {
- if (trace) { log.trace(this + " is not active, returning null delivery for " + ref); }
-
- return null;
- }
-
- checkClosed();
-
- if (trace) { log.trace(this + " moving ref " + ref + " from channel " + sourceChannelID); }
-
- if (maxSize != -1 && getMessageCount() >= maxSize)
- {
- //Have reached maximum size - will drop message
-
- log.warn(this + " has reached maximum size, " + ref + " will be dropped");
-
- return null;
- }
-
- // Each channel has its own copy of the reference
- ref = ref.copy();
-
- try
- {
- if (ref.getMessage().isReliable() && recoverable)
- {
- // Reliable message in a recoverable state - also add to db
- if (trace) { log.trace(this + " adding " + ref + " to database non-transactionally"); }
-
- pm.moveReference(sourceChannelID, channelID, ref);
- }
-
- synchronized (lock)
- {
- addReferenceInMemory(ref);
-
- deliverInternal();
- }
-
- messagesAdded.increment();
- }
- catch (Throwable t)
- {
- log.error("Failed to handle message", t);
-
- return null;
- }
-
- return new SimpleDelivery(this, ref, true, false);
- }
-
- public Delivery handle(DeliveryObserver sender, MessageReference ref, Transaction tx)
- {
- if (!isActive())
- {
- if (trace) { log.trace(this + " is not active, returning null delivery for " + ref); }
-
- return null;
- }
-
- checkClosed();
-
- if (ref == null)
- {
- return null;
- }
-
- if (trace) { log.trace(this + " handles " + ref + (tx == null ? " non-transactionally" : " in transaction: " + tx)); }
-
- if (maxSize != -1 && getMessageCount() >= maxSize)
- {
- //Have reached maximum size - will drop message
-
- log.warn(this + " has reached maximum size, " + ref + " will be dropped");
-
- return null;
- }
-
- // Each channel has its own copy of the reference
- ref = ref.copy();
-
- try
- {
- if (tx == null)
- {
- if (ref.getMessage().isReliable() && recoverable)
- {
- // Reliable message in a recoverable state - also add to db
- if (trace) { log.trace(this + " adding " + ref + " to database non-transactionally"); }
-
- pm.addReference(channelID, ref, null);
- }
-
- // If the ref has a scheduled delivery time then we don't add to the in memory queue
- // instead we create a timeout, so when that time comes delivery will attempted directly
-
- if (!checkAndSchedule(ref))
- {
- synchronized (lock)
- {
- addReferenceInMemory(ref);
-
- deliverInternal();
- }
- }
- }
- else
- {
- if (trace) { log.trace(this + " adding " + ref + " to state " + (tx == null ? "non-transactionally" : "in transaction: " + tx)); }
-
- // add to post commit callback
- getCallback(tx).addRef(ref);
-
- if (trace) { log.trace(this + " added transactionally " + ref + " in memory"); }
-
- if (ref.getMessage().isReliable() && recoverable)
- {
- // Reliable message in a recoverable state - also add to db
- if (trace) { log.trace(this + " adding " + ref + (tx == null ? " to database non-transactionally" : " in transaction: " + tx)); }
-
- pm.addReference(channelID, ref, tx);
- }
- }
-
- messagesAdded.increment();
- }
- catch (Throwable t)
- {
- log.error("Failed to handle message", t);
-
- return null;
- }
-
- return new SimpleDelivery(this, ref, true, false);
- }
-
- // DeliveryObserver implementation --------------------------------------------------------------
-
- public void acknowledge(Delivery d, Transaction tx) throws Throwable
- {
- if (trace) { log.trace("acknowledging " + d + (tx == null ? " non-transactionally" : " transactionally in " + tx)); }
-
- acknowledgeInternal(d, tx, true);
- }
-
- public void acknowledgeNoPersist(Delivery d) throws Throwable
- {
- acknowledgeInternal(d, null, false);
- }
-
- public void cancel(Delivery del) throws Throwable
- {
- //We may need to update the delivery count in the database
-
- MessageReference ref = del.getReference();
-
- if (ref.getMessage().isReliable())
- {
- pm.updateDeliveryCount(this.channelID, ref);
- }
-
- if (!del.isRecovered())
- {
- deliveringCount.decrement();
- }
-
- if (!checkAndSchedule(ref))
- {
- cancelInternal(ref);
- }
- }
-
- // Channel implementation -----------------------------------------------------------------------
-
- public long getChannelID()
- {
- return channelID;
- }
-
- public boolean isRecoverable()
- {
- return recoverable;
- }
-
- public List browse(Filter filter)
- {
- if (trace) { log.trace(this + " browse" + (filter == null ? "" : ", filter = " + filter)); }
-
- synchronized (lock)
- {
- //FIXME - This is currently broken since it doesn't take into account
- // refs paged into persistent storage
- // Also is very inefficient since it makes a copy
- // The way to implement this properly is to use the Prioritized deque iterator
- // combined with an iterator over the refs in storage
-
- //TODO use the ref queue iterator
- List references = undelivered(filter);
-
- // dereference pass
- ArrayList messages = new ArrayList(references.size());
- for (Iterator i = references.iterator(); i.hasNext();)
- {
- MessageReference ref = (MessageReference) i.next();
- messages.add(ref.getMessage());
- }
- return messages;
- }
- }
-
- public void deliver()
- {
- checkClosed();
-
- synchronized (lock)
- {
- if (distributor != null && distributor.getNumberOfReceivers() > 0)
- {
- setReceiversReady(true);
-
- deliverInternal();
- }
- }
- }
-
- public void close()
- {
- synchronized (lock)
- {
- if (distributor != null)
- {
- distributor.clear();
-
- distributor = null;
- }
-
- clearAllScheduledDeliveries();
- }
- }
-
- /*
- * This method clears the channel.
- * Basically it consumes the rest of the messages in the channel.
- * We can't just delete the corresponding references directly from the database since
- * a) We might be paging
- * b) The message might remain in the message store causing a leak
- *
- */
- public void removeAllReferences() throws Throwable
- {
- synchronized (lock)
- {
- if (deliveringCount.get() > 0)
- {
- throw new IllegalStateException("Cannot remove references while deliveries are in progress, there are " +
- deliveringCount.get());
- }
-
- log.trace(this + " removing all references, there are " + this.messageRefs.size());
-
- //Now we consume the rest of the messages
- //This may take a while if we have a lot of messages including perhaps millions
- //paged in the database - but there's no obvious other way to do it.
- //We cannot just delete them directly from the database - because we may end up with messages leaking
- //in the message store,
- //also we might get race conditions when other channels are updating the same message in the db
-
- //Note - we don't do this in a tx - because the tx could be too big if we have millions of refs
- //paged in storage
-
- MessageReference ref;
- while ((ref = removeFirstInMemory()) != null)
- {
- log.trace("Removing ref " + ref);
-
- SimpleDelivery del = new SimpleDelivery(this, ref);
-
- del.acknowledge(null);
- }
-
- deliveringCount.set(0);
-
- log.trace(this + " done removing all references, there are " + this.messageRefs.size());
- }
-
- clearAllScheduledDeliveries();
- }
-
- public List undelivered(Filter filter)
- {
- List undelivered = new ArrayList();
-
- synchronized (lock)
- {
- Iterator iter = messageRefs.getAll().iterator();
-
- while (iter.hasNext())
- {
- MessageReference r = (MessageReference) iter.next();
-
- // TODO: I need to dereference the message each time I apply the
- // filter. Refactor so the message reference will also contain JMS
- // properties
- if (filter == null || filter.accept(r.getMessage()))
- {
- undelivered.add(r);
- }
- else
- {
- if (trace) { log.trace(this + ": " + r + " NOT accepted by filter so won't add to list"); }
- }
- }
- }
- if (trace) { log.trace(this + ": undelivered() returns a list of " + undelivered.size() + " undelivered memory messages"); }
-
- return undelivered;
- }
-
- /**
- * Returns the count of messages stored AND being delivered AND scheduled
- */
- public int getMessageCount()
- {
- synchronized (lock)
- {
- if (trace) { log.trace("Getting message count mr: "+ messageRefs.size() + " dc " + getDeliveringCount() + " sc " + getScheduledCount()); }
-
- return messageRefs.size() + getDeliveringCount() + getScheduledCount();
- }
- }
-
- public int getDeliveringCount()
- {
- return deliveringCount.get();
- }
-
- public int getScheduledCount()
- {
- synchronized (scheduledDeliveries)
- {
- return scheduledDeliveries.size();
- }
- }
-
- public void activate()
- {
- active = true;
- }
-
- public void deactivate()
- {
- active = false;
- }
-
- public boolean isActive()
- {
- return active;
- }
-
- public int getMaxSize()
- {
- synchronized (lock)
- {
- return maxSize;
- }
- }
-
- public void setMaxSize(int newSize)
- {
- synchronized (lock)
- {
- int count = getMessageCount();
-
- if (newSize != -1 && count > newSize)
- {
- log.warn("Cannot set maxSize to " + newSize + " since there are already " + count + " refs");
- }
- else
- {
- maxSize = newSize;
- }
- }
- }
-
- public int getMessagesAdded()
- {
- return messagesAdded.get();
- }
-
- // Public ---------------------------------------------------------------------------------------
-
- //Only used for testing
- public int memoryRefCount()
- {
- synchronized (lock)
- {
- return messageRefs.size();
- }
- }
-
- // Package protected ----------------------------------------------------------------------------
-
- // Protected ------------------------------------------------------------------------------------
-
- protected void clearAllScheduledDeliveries()
- {
- synchronized (scheduledDeliveries)
- {
- Set clone = new HashSet(scheduledDeliveries);
-
- Iterator iter = clone.iterator();
-
- while (iter.hasNext())
- {
- Timeout timeout = (Timeout)iter.next();
-
- timeout.cancel();
- }
-
- scheduledDeliveries.clear();
- }
- }
-
- protected void cancelInternal(MessageReference ref) throws Exception
- {
- if (trace) { log.trace(this + " cancelling " + ref + " in memory"); }
-
- synchronized (lock)
- {
- messageRefs.addFirst(ref, ref.getMessage().getPriority());
- }
-
- if (trace) { log.trace(this + " added " + ref + " back into state"); }
- }
-
- /**
- * This methods delivers as many messages as possible to the distributor until no more deliveries are
- * returned. This method should never be called at the same time as handle.
- *
- * @see org.jboss.messaging.core.contract.Channel#deliver()
- */
- protected void deliverInternal()
- {
- if (trace) { log.trace(this + " was prompted delivery"); }
-
- try
- {
- // The iterator is used to iterate through the refs in the channel in the case that they
- // don't match the selectors of any receivers.
- ListIterator iter = null;
-
- MessageReference ref = null;
-
- if (!getReceiversReady())
- {
- if (trace) { log.trace(this + " receivers not ready so not delivering"); }
-
- return;
- }
-
- while (true)
- {
- ref = nextReference(iter);
-
- if (ref != null)
- {
- // Attempt to push the ref to a receiver
-
- if (trace) { log.trace(this + " pushing " + ref); }
-
- Delivery del = distributor.handle(this, ref, null);
-
- setReceiversReady(del != null);
-
- if (del == null)
- {
- // No receiver, broken receiver or full receiver so we stop delivering
- if (trace) { log.trace(this + " got no delivery for " + ref + " so no receiver got the message. Stopping delivery."); }
-
- break;
- }
- else if (!del.isSelectorAccepted())
- {
- // No receiver accepted the message because no selectors matched, so we create
- // an iterator (if we haven't already created it) to iterate through the refs
- // in the channel. No delivery was really performed
-
- if (iter == null)
- {
- iter = messageRefs.iterator();
-
- //We just tried the first one, so we don't want to try it again
- iter.next();
- }
- }
- else
- {
- if (trace) { log.trace(this + ": " + del + " returned for message " + ref); }
-
- // Receiver accepted the reference
-
- synchronized (lock)
- {
- if (iter == null)
- {
- if (trace) { log.trace(this + " removing first ref in memory"); }
-
- removeFirstInMemory();
- }
- else
- {
- if (trace) { log.trace(this + " removed current message from iterator"); }
-
- iter.remove();
- }
- }
-
- deliveringCount.increment();
- }
- }
- else
- {
- // No more refs in channel or only ones that don't match any selectors
- if (trace) { log.trace(this + " no more refs to deliver "); }
-
- break;
- }
- }
- }
- catch (Throwable t)
- {
- log.error(this + " Failed to deliver", t);
- }
- }
-
- protected boolean deliverScheduled(MessageReference ref)
- {
- try
- {
- // We synchonize on the ref lock to prevent scheduled deivery kicking in before
- // load has finished
- synchronized (lock)
- {
- // Attempt to push the ref to a receiver
-
- if (trace) { log.trace(this + " pushing " + ref); }
-
- Delivery del = distributor.handle(this, ref, null);
-
- setReceiversReady(del != null);
-
- if (del == null)
- {
- // No receiver, broken receiver or full receiver so we stop delivering
- if (trace) { log.trace(this + ": no delivery returned for message" + ref + " so no receiver got the message. Delivery is now complete"); }
-
- return false;
- }
- else if (del.isSelectorAccepted())
- {
- if (trace) { log.trace(this + ": " + del + " returned for message:" + ref); }
-
- // Receiver accepted the reference
-
- deliveringCount.increment();
-
- return true;
- }
- }
- }
- catch (Throwable t)
- {
- log.error(this + " Failed to deliver", t);
- }
-
- return false;
- }
-
- protected boolean checkAndSchedule(MessageReference ref)
- {
- if (ref.getScheduledDeliveryTime() > System.currentTimeMillis())
- {
- if (trace) { log.trace("Scheduling delivery for " + ref + " to occur at " + ref.getScheduledDeliveryTime()); }
-
- // Schedule the cancel to actually occur at the specified time. Need to synchronize to
- // prevent timeout being removed before it is added.
- synchronized (scheduledDeliveries)
- {
- Timeout timeout =
- MessagingTimeoutFactory.instance.getFactory().
- schedule(ref.getScheduledDeliveryTime(), new DeliverRefTimeoutTarget(ref));
-
- scheduledDeliveries.add(timeout);
- }
-
- return true;
- }
- else
- {
- return false;
- }
- }
-
- protected void acknowledgeInternal(Delivery d, Transaction tx, boolean persist) throws Exception
- {
- if (tx == null)
- {
- if (persist && recoverable && d.getReference().getMessage().isReliable())
- {
- pm.removeReference(channelID, d.getReference(), null);
- }
-
- if (!d.isRecovered())
- {
- deliveringCount.decrement();
- }
- }
- else
- {
- this.getCallback(tx).addDelivery(d);
-
- if (trace) { log.trace(this + " added " + d + " to memory on transaction " + tx); }
-
- if (recoverable && d.getReference().getMessage().isReliable())
- {
- pm.removeReference(channelID, d.getReference(), tx);
- }
- }
- }
-
- protected InMemoryCallback getCallback(Transaction tx)
- {
- InMemoryCallback callback = (InMemoryCallback) tx.getCallback(this);
-
- if (callback == null)
- {
- callback = new InMemoryCallback();
-
- tx.addCallback(callback, this);
- }
-
- return callback;
- }
-
- protected MessageReference removeFirstInMemory() throws Exception
- {
- MessageReference result = (MessageReference) messageRefs.removeFirst();
-
- return (MessageReference) result;
- }
-
- protected void addReferenceInMemory(MessageReference ref) throws Exception
- {
- messageRefs.addLast(ref, ref.getMessage().getPriority());
-
- if (trace){ log.trace(this + " added " + ref + " non-transactionally in memory"); }
- }
-
- protected boolean getReceiversReady()
- {
- return receiversReady;
- }
-
- protected void setReceiversReady(boolean receiversReady)
- {
- this.receiversReady = receiversReady;
- }
-
- // Private --------------------------------------------------------------------------------------
-
- private MessageReference nextReference(ListIterator iter) throws Throwable
- {
- MessageReference ref;
-
- if (iter == null)
- {
- //We just get the next ref from the head of the queue
- ref = (MessageReference) messageRefs.peekFirst();
- }
- else
- {
- // TODO This will not work with paged refs - see http://jira.jboss.com/jira/browse/JBMESSAGING-275
- // We need to extend it to work with refs from the db
-
- //We have an iterator - this means we are iterating through the queue to find a ref that matches
- if (iter.hasNext())
- {
- ref = (MessageReference)iter.next();
- }
- else
- {
- ref = null;
- }
- }
-
- return ref;
- }
-
- // Inner classes --------------------------------------------------------------------------------
-
- private class InMemoryCallback implements TxCallback
- {
- private List refsToAdd;
-
- private List deliveriesToRemove;
-
- private InMemoryCallback()
- {
- refsToAdd = new ArrayList();
-
- deliveriesToRemove = new ArrayList();
- }
-
- private void addRef(MessageReference ref)
- {
- refsToAdd.add(ref);
- }
-
- private void addDelivery(Delivery del)
- {
- deliveriesToRemove.add(del);
- }
-
- public void beforePrepare()
- {
- // NOOP
- }
-
- public void beforeCommit(boolean onePhase)
- {
- // NOOP
- }
-
- public void beforeRollback(boolean onePhase)
- {
- // NOOP
- }
-
- public void afterPrepare()
- {
- // NOOP
- }
-
- public void afterCommit(boolean onePhase) throws Exception
- {
- try
- {
- // We add the references to the state (or schedule them if appropriate)
-
- boolean promptDelivery = false;
-
- for(Iterator i = refsToAdd.iterator(); i.hasNext(); )
- {
- MessageReference ref = (MessageReference)i.next();
-
- if (checkAndSchedule(ref))
- {
- if (trace) { log.trace(this + ": scheduled " + ref); }
- }
- else
- {
- if (trace) { log.trace(this + ": adding " + ref + " to memory"); }
-
- try
- {
- synchronized (lock)
- {
- addReferenceInMemory(ref);
- }
- }
- catch (Throwable t)
- {
- throw new TransactionException("Failed to add reference", t);
- }
-
- //Only need to prompt delivery if refs were added
- promptDelivery = true;
- }
- }
-
- // Remove deliveries
-
- for(Iterator i = deliveriesToRemove.iterator(); i.hasNext(); )
- {
- Delivery del = (Delivery)i.next();
-
- if (trace) { log.trace(this + " removing " + del + " after commit"); }
-
- if (!del.isRecovered())
- {
- deliveringCount.decrement();
- }
- }
-
- // prompt delivery
- if (promptDelivery)
- {
- synchronized (lock)
- {
- deliverInternal();
- }
- }
- }
- catch (Throwable t)
- {
- log.error("failed to commit", t);
- throw new Exception("Failed to commit", t);
- }
-
- }
-
- public void afterRollback(boolean onePhase) throws Exception
- {
- //NOOP
- }
-
- public String toString()
- {
- return ChannelSupport.this + ".InMemoryCallback[" +
- Integer.toHexString(InMemoryCallback.this.hashCode()) + "]";
- }
- }
-
- /**
- * Give subclass a chance to process the message before storing it internally.
- * TODO - Do we really need this?
- */
- protected void processMessageBeforeStorage(MessageReference reference)
- {
- // by default a noop
- }
-
- protected void checkClosed()
- {
- if (distributor == null)
- {
- throw new IllegalStateException(this + " closed");
- }
- }
-
- // Private --------------------------------------------------------------------------------------
-
- // Inner classes --------------------------------------------------------------------------------
-
- private class DeliverRefTimeoutTarget implements TimeoutTarget
- {
- private MessageReference ref;
-
- public DeliverRefTimeoutTarget(MessageReference ref)
- {
- this.ref = ref;
- }
-
- public void timedOut(Timeout timeout)
- {
- if (trace) { log.trace("Scheduled delivery timeout " + ref); }
-
- synchronized (scheduledDeliveries)
- {
- boolean removed = scheduledDeliveries.remove(timeout);
-
- if (!removed)
- {
- throw new IllegalStateException("Failed to remove timeout " + timeout);
- }
- }
-
- ref.setScheduledDeliveryTime(0);
-
- boolean delivered = false;
-
- if (distributor.getNumberOfReceivers() > 0)
- {
- delivered = deliverScheduled(ref);
- }
-
- if (!delivered)
- {
- try
- {
- cancelInternal(ref);
- }
- catch (Exception e)
- {
- log.error("Failed to cancel", e);
- }
- }
- else
- {
- if (trace) { log.trace("Delivered scheduled delivery at " + System.currentTimeMillis() + " for " + ref); }
- }
- }
- }
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/ClusterRoundRobinDistributor.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/ClusterRoundRobinDistributor.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/ClusterRoundRobinDistributor.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -27,9 +27,9 @@
import org.jboss.messaging.core.contract.Delivery;
import org.jboss.messaging.core.contract.DeliveryObserver;
import org.jboss.messaging.core.contract.Distributor;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.Receiver;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.MessageReference;
/**
*
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/FirstReceiverDistributor.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/FirstReceiverDistributor.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/FirstReceiverDistributor.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -29,9 +29,9 @@
import org.jboss.messaging.core.contract.Delivery;
import org.jboss.messaging.core.contract.DeliveryObserver;
import org.jboss.messaging.core.contract.Distributor;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.Receiver;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.MessageReference;
/**
*
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/IDManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/IDManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/IDManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -23,8 +23,8 @@
import org.jboss.jms.delegate.IDBlock;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.MessagingComponent;
import org.jboss.messaging.core.contract.PersistenceManager;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
/**
*
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,2848 +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.messaging.core.impl;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-import javax.transaction.xa.Xid;
-
-import org.jboss.jms.tx.MessagingXid;
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.core.contract.PersistenceManager;
-import org.jboss.messaging.core.impl.message.MessageFactory;
-import org.jboss.messaging.core.impl.message.MessageSupport;
-import org.jboss.messaging.core.impl.tx.PreparedTxInfo;
-import org.jboss.messaging.core.impl.tx.Transaction;
-import org.jboss.messaging.core.impl.tx.TxCallback;
-import org.jboss.messaging.util.JDBCUtil;
-import org.jboss.messaging.util.StreamUtils;
-import org.jboss.messaging.util.Util;
-
-/**
- * JDBC implementation of PersistenceManager
- *
- * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
- * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
- *
- * @version <tt>1.1</tt>
- *
- * JDBCPersistenceManager.java,v 1.1 2006/02/22 17:33:41 timfox Exp
- */
-public class JDBCPersistenceManager extends JDBCSupport implements
- PersistenceManager
-{
- // Constants -----------------------------------------------------
-
- private static final Logger log = Logger
- .getLogger(JDBCPersistenceManager.class);
-
- // Static --------------------------------------------------------
-
- private boolean trace = log.isTraceEnabled();
-
- private boolean usingBinaryStream = true;
-
- private boolean usingTrailingByte = false;
-
- private int maxParams;
-
- private short orderCount;
-
- private int nodeID;
-
- private boolean nodeIDSet;
-
- // Some versions of the oracle driver don't support binding blobs on select
- // clauses,
- // what would force us to use a two stage insert (insert and if successful,
- // update)
- private boolean supportsBlobSelect;
-
- // Constructors --------------------------------------------------
-
- public JDBCPersistenceManager(DataSource ds, TransactionManager tm,
- Properties sqlProperties, boolean createTablesOnStartup,
- boolean usingBatchUpdates, boolean usingBinaryStream,
- boolean usingTrailingByte, int maxParams, boolean supportsBlobSelect)
- {
- super(ds, tm, sqlProperties, createTablesOnStartup);
-
- // usingBatchUpdates is currently ignored due to sketchy support from
- // databases
-
- this.usingBinaryStream = usingBinaryStream;
-
- this.usingTrailingByte = usingTrailingByte;
-
- this.maxParams = maxParams;
-
- this.supportsBlobSelect = supportsBlobSelect;
- }
-
- // MessagingComponent overrides ---------------------------------
-
- public void start() throws Exception
- {
- super.start();
-
- Connection conn = null;
-
- PreparedStatement ps = null;
-
- TransactionWrapper wrap = new TransactionWrapper();
-
- try
- {
- conn = ds.getConnection();
- // JBossMessaging requires transaction isolation of READ_COMMITTED
- // Any looser isolation level and we cannot maintain consistency for
- // paging (HSQL)
- if (conn.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED)
- {
- int level = conn.getTransactionIsolation();
-
- String warn = "\n\n"
- + "JBoss Messaging Warning: DataSource connection transaction isolation should be READ_COMMITTED, but it is currently "
- + Util.transactionIsolationToString(level)
- + ".\n"
- + " Using an isolation level less strict than READ_COMMITTED may lead to data consistency problems.\n"
- + " Using an isolation level more strict than READ_COMMITTED may lead to deadlock.\n";
- log.warn(warn);
- }
-
- log.debug("Adding record on JBM_DUAL");
-
- // Now we need to insert a row in the DUAL table if it doesn't contain
- // one already
- ps = conn.prepareStatement(this.getSQLStatement("INSERT_DUAL"));
-
- try
- {
- int rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace("Inserted " + rows + " rows into dual");
- }
- }
- catch (SQLException e)
- {
- wrap.exceptionOccurred();
- wrap.end();
- wrap = new TransactionWrapper();
-
- log.debug("Checking for existance on JBM_DUAL");
-
- Statement selectCount = conn.createStatement();
- ResultSet rset = selectCount.executeQuery(this
- .getSQLStatement("CHECK_DUAL"));
- try
- {
- // if JBM_DUAL is empty, and if an exception happened, we should
- // warn!
- // if JBM_DUAL has a line already, we don't care about the
- // exception...
- if (!rset.next())
- {
- log
- .debug(
- "JBM_DUAL didn't have a record.. throwing exception",
- e);
- throw e;
- }
-
- // if there are two lines or more on JBM_DUAL, that is also a
- // problem
- if (rset.next())
- {
- log
- .debug("duplicated record found on JBM_DUAL... throwing exception");
- throw new IllegalStateException(
- "JBM_DUAL is missing a primary key as it allowed a duplicate value");
- }
- }
- finally
- {
- try
- {
- rset.close();
- selectCount.close();
- }
- catch (Throwable ignored)
- {
- }
- }
- }
- }
- catch (Exception e)
- {
- wrap.exceptionOccurred();
- throw e;
- }
- finally
- {
- closeStatement(ps);
- closeConnection(conn);
- wrap.end();
- }
-
- log.debug(this + " started");
- }
-
- // Injection -------------------------------------------------
-
- // This is only known by server peer so we inject it after startup
-
- public void injectNodeID(int nodeID)
- {
- this.nodeID = nodeID;
-
- this.nodeIDSet = true;
- }
-
- // PersistenceManager implementation -------------------------
-
- // Related to XA Recovery
- // ======================
-
- public List getMessageChannelPairRefsForTx(long transactionId)
- throws Exception
- {
- String sql = this.getSQLStatement("SELECT_MESSAGE_ID_FOR_REF");
- return getMessageChannelPair(sql, transactionId);
- }
-
- public List getMessageChannelPairAcksForTx(long transactionId)
- throws Exception
- {
- String sql = this.getSQLStatement("SELECT_MESSAGE_ID_FOR_ACK");
- return getMessageChannelPair(sql, transactionId);
- }
-
- public List retrievePreparedTransactions() throws Exception
- {
- if (!this.nodeIDSet)
- {
- // Sanity
- throw new IllegalStateException("Node id has not been set");
- }
-
- /*
- * Note the API change for 1.0.2 XA Recovery -- List now contains
- * instances of PreparedTxInfo<TxId, Xid> instead of direct Xids [JPL]
- */
-
- Connection conn = null;
- PreparedStatement st = null;
- ResultSet rs = null;
- PreparedTxInfo txInfo = null;
- TransactionWrapper wrap = new TransactionWrapper();
-
- try
- {
- List<PreparedTxInfo> transactions = new ArrayList<PreparedTxInfo>();
-
- conn = ds.getConnection();
-
- st = conn
- .prepareStatement(getSQLStatement("SELECT_PREPARED_TRANSACTIONS"));
-
- st.setInt(1, nodeID);
-
- rs = st.executeQuery();
-
- while (rs.next())
- {
- // get the existing tx id --MK START
- long txId = rs.getLong(1);
-
- byte[] branchQual = getVarBinaryColumn(rs, 2);
-
- int formatId = rs.getInt(3);
-
- byte[] globalTxId = getVarBinaryColumn(rs, 4);
-
- Xid xid = new MessagingXid(branchQual, formatId, globalTxId);
-
- // create a tx info object with the result set detailsdetails
- txInfo = new PreparedTxInfo(txId, xid);
-
- transactions.add(txInfo);
- }
-
- return transactions;
-
- }
- catch (Exception e)
- {
- wrap.exceptionOccurred();
- throw e;
- }
- finally
- {
- closeResultSet(rs);
- closeStatement(st);
- closeConnection(conn);
- wrap.end();
- }
- }
-
- // Related to counters
- // ===================
-
- public long reserveIDBlock(final String counterName, final int size)
- throws Exception
- {
- if (trace)
- {
- log.trace("Getting ID block for counter " + counterName + ", size "
- + size);
- }
-
- if (size <= 0) { throw new IllegalArgumentException(
- "block size must be > 0"); }
-
- class ReserveIDBlockRunner extends JDBCTxRunner2<Long>
- {
- public Long doTransaction() throws Exception
- {
- // For the clustered case - this MUST use SELECT .. FOR UPDATE or a
- // similar
- // construct the locks the row
- String selectCounterSQL = getSQLStatement("SELECT_COUNTER");
-
- PreparedStatement ps = null;
- ResultSet rs = null;
-
- try
- {
- ps = conn.prepareStatement(selectCounterSQL);
-
- ps.setString(1, counterName);
-
- rs = ps.executeQuery();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(selectCounterSQL,
- counterName));
- }
-
- if (!rs.next())
- {
- rs.close();
- ps.close();
-
- // There is a very small possibility that two threads will
- // attempt to insert the same counter
- // at the same time, if so, then the second one will fail
- // eventually after a few retries by throwing
- // a primary key violation.
-
- String insertCounterSQL = getSQLStatement("INSERT_COUNTER");
-
- ps = conn.prepareStatement(insertCounterSQL);
-
- ps.setString(1, counterName);
- ps.setLong(2, size);
-
- int rows = ps.executeUpdate();
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(insertCounterSQL,
- counterName, new Integer(size))
- + " inserted " + rows + " rows");
- }
-
- return 0L;
- }
- else
- {
- long nextId = rs.getLong(1);
-
- rs.close();
- ps.close();
-
- String updateCounterSQL = getSQLStatement("UPDATE_COUNTER");
-
- ps = conn.prepareStatement(updateCounterSQL);
-
- ps.setLong(1, nextId + size);
- ps.setString(2, counterName);
-
- int rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(updateCounterSQL,
- new Long(nextId + size), counterName)
- + " updated " + rows + " rows");
- }
-
- return nextId;
- }
- }
- finally
- {
- closeResultSet(rs);
- closeStatement(ps);
- }
- }
- }
-
- return new ReserveIDBlockRunner().executeWithRetry();
- }
-
- /*
- * Retrieve a List of messages corresponding to the specified List of message
- * ids. The implementation here for HSQLDB does this by using a
- * PreparedStatment with an IN clause with a maximum of 100 elements. If
- * there are more than maxParams message to retrieve this is repeated a
- * number of times. For "Enterprise" databases (Oracle, DB2, Sybase etc) a
- * more sophisticated technique should be used e.g. Oracle ARRAY types in
- * Oracle which can be submitted as a param to an Oracle prepared statement
- * Although this would all be DB specific.
- */
- public List getMessages(final List messageIds) throws Exception
- {
- if (trace)
- {
- log.trace("Getting batch of messages for " + messageIds);
- }
-
- class GetMessageListTX extends JDBCTxRunner2<List>
- {
-
- public List<Message> doTransaction() throws Exception
- {
- PreparedStatement ps = null;
- ResultSet rs = null;
-
- try
- {
- Iterator iter = messageIds.iterator();
-
- int size = messageIds.size();
-
- int count = 0;
-
- List<Message> msgs = new ArrayList<Message>();
-
- while (iter.hasNext())
- {
- if (ps == null)
- {
- // PreparedStatements are cached in the JCA layer so we
- // will never actually have more than
- // 100 distinct ones
- int numParams;
- if (count < (size / maxParams) * maxParams)
- {
- numParams = maxParams;
- }
- else
- {
- numParams = size % maxParams;
- }
- StringBuffer buff = new StringBuffer(
- getSQLStatement("LOAD_MESSAGES"));
- buff.append(" WHERE ").append(
- getSQLStatement("MESSAGE_ID_COLUMN"))
- .append(" IN (");
- for (int i = 0; i < numParams; i++)
- {
- buff.append("?");
- if (i < numParams - 1)
- {
- buff.append(",");
- }
- }
- buff.append(")");
- ps = conn.prepareStatement(buff.toString());
-
- if (trace)
- {
- log.trace(buff.toString());
- }
- }
-
- long msgId = ((Long) iter.next()).longValue();
-
- ps.setLong((count % maxParams) + 1, msgId);
-
- count++;
-
- if (!iter.hasNext() || count % maxParams == 0)
- {
- rs = ps.executeQuery();
-
- while (rs.next())
- {
- long messageId = rs.getLong(1);
-
- boolean reliable = rs.getString(2).equals("Y");
-
- long expiration = rs.getLong(3);
-
- long timestamp = rs.getLong(4);
-
- byte priority = rs.getByte(5);
-
- byte[] bytes = getBytes(rs, 6);
-
- HashMap headers = bytesToMap(bytes);
-
- byte[] payload = getBytes(rs, 7);
-
- byte type = rs.getByte(8);
-
- Message m = MessageFactory.createMessage(messageId,
- reliable, expiration, timestamp, priority,
- headers, payload, type);
- msgs.add(m);
- }
-
- rs.close();
- ps.close();
- ps = null;
- }
- }
-
- if (trace)
- {
- log.trace("Loaded " + msgs.size() + " messages in total");
- }
-
- return msgs;
- }
- catch (Exception e)
- {
- throw e;
- }
- finally
- {
- closeResultSet(rs);
- closeStatement(ps);
- }
- }
- }
-
- return new GetMessageListTX().executeWithRetry();
-
- }
-
- // Related to paging functionality
- // ===============================
-
- // Used to page NP messages or P messages in a non recoverable queue
-
- public void pageReferences(final long channelID, final List references,
- final boolean page) throws Exception
- {
- if (trace)
- {
- log.trace("Paging references in channel " + channelID + " refs "
- + references.size());
- }
-
- class PageReferencesRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement psInsertReference = null;
- PreparedStatement psInsertMessage = null;
- PreparedStatement psUpdateMessage = null;
-
- try
- {
- Iterator iter = references.iterator();
-
- psInsertReference = conn
- .prepareStatement(getSQLStatement("INSERT_MESSAGE_REF"));
-
- if (supportsBlobSelect)
- {
- psInsertMessage = conn
- .prepareStatement(getSQLStatement("INSERT_MESSAGE_CONDITIONAL_FULL"));
- }
- else
- {
- psInsertMessage = conn
- .prepareStatement(getSQLStatement("INSERT_MESSAGE_CONDITIONAL"));
- psUpdateMessage = conn
- .prepareStatement(getSQLStatement("UPDATE_MESSAGE_4CONDITIONAL"));
- }
-
- while (iter.hasNext())
- {
- // We may need to persist the message itself
- MessageReference ref = (MessageReference) iter.next();
-
- // For non reliable refs we insert the ref (and maybe the
- // message) itself
-
- // Now store the reference
-
- log
- .trace("Paged ref with page order "
- + ref.getPagingOrder());
-
- addReference(channelID, ref, psInsertReference, page);
-
- int rows = psInsertReference.executeUpdate();
-
- if (trace)
- {
- log.trace("Inserted " + rows + " rows");
- }
-
- // Maybe we need to persist the message itself
- Message m = ref.getMessage();
-
- rows = storeMessage(m, psInsertMessage, psUpdateMessage);
-
- if (trace)
- {
- log.trace("Inserted " + rows + " rows");
- }
- }
-
- return null;
- }
- finally
- {
- closeStatement(psInsertReference);
- closeStatement(psInsertMessage);
- closeStatement(psUpdateMessage);
- }
- }
- }
-
- new PageReferencesRunner().executeWithRetry();
- }
-
- // After loading paged refs this is used to remove any NP or P messages in a
- // unrecoverable channel
- public void removeDepagedReferences(final long channelID,
- final List references) throws Exception
- {
- if (trace)
- {
- log.trace(this + " Removing depaged " + references.size()
- + " refs from channel " + channelID);
- }
-
- class RemoveDepagedReferencesRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement psDeleteReference = null;
-
- try
- {
- psDeleteReference = conn
- .prepareStatement(getSQLStatement("DELETE_MESSAGE_REF"));
-
- Iterator iter = references.iterator();
-
- while (iter.hasNext())
- {
- MessageReference ref = (MessageReference) iter.next();
-
- removeReference(channelID, ref, psDeleteReference);
-
- int rows = psDeleteReference.executeUpdate();
-
- if (trace)
- {
- log.trace("Deleted " + rows + " references");
- }
-
- }
-
- return null;
- }
- finally
- {
- closeStatement(psDeleteReference);
- }
- }
- }
-
- new RemoveDepagedReferencesRunner().executeWithRetry();
-
- deleteMessages(references);
- }
-
- // After loading paged refs this is used to update P messages to non paged
- public void updateReferencesNotPagedInRange(final long channelID,
- final long orderStart, final long orderEnd, final long num)
- throws Exception
- {
- if (trace)
- {
- log.trace("Updating paged references for channel " + channelID
- + " between " + orderStart + " and " + orderEnd);
- }
-
- class UpdateReferencesNotPagedInRangeRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement ps = null;
-
- try
- {
- ps = conn
- .prepareStatement(getSQLStatement("UPDATE_REFS_NOT_PAGED"));
-
- ps.setLong(1, orderStart);
-
- ps.setLong(2, orderEnd);
-
- ps.setLong(3, channelID);
-
- int rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(
- getSQLStatement("UPDATE_REFS_NOT_PAGED"), new Long(
- channelID), new Long(orderStart), new Long(
- orderEnd))
- + " updated " + rows + " rows");
- }
-
- // Sanity check
- if (rows != num) { throw new IllegalStateException(
- "Did not update correct number of rows"); }
-
- return null;
- }
- finally
- {
- closeStatement(ps);
- }
- }
- }
-
- new UpdateReferencesNotPagedInRangeRunner().executeWithRetry();
- }
-
- public void updatePageOrder(final long channelID, final List references)
- throws Exception
- {
- if (trace)
- {
- log.trace("Updating page order for channel:" + channelID);
- }
-
- class UpdatePageOrderRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement psUpdateReference = null;
- try
- {
- Iterator iter = references.iterator();
-
- psUpdateReference = conn
- .prepareStatement(getSQLStatement("UPDATE_PAGE_ORDER"));
-
- while (iter.hasNext())
- {
- MessageReference ref = (MessageReference) iter.next();
-
- psUpdateReference.setLong(1, ref.getPagingOrder());
-
- psUpdateReference.setLong(2, ref.getMessage().getMessageID());
-
- psUpdateReference.setLong(3, channelID);
-
- int rows = psUpdateReference.executeUpdate();
-
- if (trace)
- {
- log.trace("Updated " + rows + " rows");
- }
- }
-
- return null;
- }
- finally
- {
- closeStatement(psUpdateReference);
- }
- }
- }
-
- new UpdatePageOrderRunner().executeWithRetry();
- }
-
- public List getPagedReferenceInfos(final long channelID,
- final long orderStart, final int number) throws Exception
- {
- if (trace)
- {
- log.trace("loading message reference info for channel " + channelID
- + " from " + orderStart + " number " + number);
- }
-
- List<ReferenceInfo> refs = new ArrayList<ReferenceInfo>();
-
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- TransactionWrapper wrap = new TransactionWrapper();
-
- try
- {
- conn = ds.getConnection();
-
- ps = conn.prepareStatement(getSQLStatement("LOAD_PAGED_REFS"));
-
- ps.setLong(1, channelID);
-
- ps.setLong(2, orderStart);
-
- ps.setLong(3, orderStart + number - 1);
-
- rs = ps.executeQuery();
-
- long ord = orderStart;
-
- while (rs.next())
- {
- long msgId = rs.getLong(1);
- int deliveryCount = rs.getInt(2);
- int pageOrd = rs.getInt(3);
- long sched = rs.getLong(4);
-
- // Sanity check
- if (pageOrd != ord) { throw new IllegalStateException(
- "Unexpected pageOrd: " + pageOrd + " expected: " + ord); }
-
- ReferenceInfo ri = new ReferenceInfo(msgId, deliveryCount, sched);
-
- refs.add(ri);
- ord++;
- }
-
- // Sanity check
- if (ord != orderStart + number) { throw new IllegalStateException(
- "Didn't load expected number of references, loaded: "
- + (ord - orderStart) + " expected: " + number); }
-
- return refs;
- }
- catch (Exception e)
- {
- wrap.exceptionOccurred();
- throw e;
- }
- finally
- {
- closeResultSet(rs);
- closeStatement(ps);
- closeConnection(conn);
- wrap.end();
- }
- }
-
- /*
- * Load the initial, non paged refs
- */
- public InitialLoadInfo loadFromStart(final long channelID, final int number)
- throws Exception
- {
- if (trace)
- {
- log.trace("loading initial reference infos for channel " + channelID);
- }
-
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- TransactionWrapper wrap = new TransactionWrapper();
-
- try
- {
- conn = ds.getConnection();
-
- // First we get the values for min() and max() page order
- ps = conn.prepareStatement(getSQLStatement("SELECT_MIN_MAX_PAGE_ORD"));
-
- ps.setLong(1, channelID);
-
- rs = ps.executeQuery();
-
- rs.next();
-
- Long minOrdering = new Long(rs.getLong(1));
-
- if (rs.wasNull())
- {
- minOrdering = null;
- }
-
- Long maxOrdering = new Long(rs.getLong(2));
-
- if (rs.wasNull())
- {
- maxOrdering = null;
- }
-
- ps.close();
-
- ps = conn.prepareStatement(getSQLStatement("LOAD_UNPAGED_REFS"));
-
- ps.setLong(1, channelID);
-
- rs = ps.executeQuery();
-
- List<ReferenceInfo> refs = new ArrayList<ReferenceInfo>();
-
- List<ReferenceInfo> refsToUpdate = new ArrayList<ReferenceInfo>();
-
- int count = 0;
- while (rs.next())
- {
- long msgId = rs.getLong(1);
- int deliveryCount = rs.getInt(2);
- long sched = rs.getLong(3);
-
- ReferenceInfo ri = new ReferenceInfo(msgId, deliveryCount, sched);
-
- if (count < number)
- {
- refs.add(ri);
- }
- else
- {
- refsToUpdate.add(ri);
- }
-
- count++;
- }
-
- // No refs paged
-
- if (!refsToUpdate.isEmpty())
- {
- // Take any overflow and convert them to paged refs
-
- ps.close();
- ps = conn.prepareStatement(getSQLStatement("UPDATE_PAGE_ORDER"));
-
- Iterator<ReferenceInfo> iter = refsToUpdate.iterator();
-
- long ordering = 0;
-
- if (maxOrdering != null)
- {
- ordering = maxOrdering.longValue() + 1;
- }
-
- while (iter.hasNext())
- {
- ReferenceInfo ri = (ReferenceInfo) iter.next();
-
- ps.setLong(1, ordering);
-
- ps.setLong(2, ri.getMessageId());
-
- ps.setLong(3, channelID);
-
- int rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace("Updated " + rows + " rows");
- }
-
- ordering++;
- }
-
- if (minOrdering == null)
- {
- minOrdering = new Long(0);
- }
-
- maxOrdering = new Long(ordering - 1);
- }
-
- return new InitialLoadInfo(minOrdering, maxOrdering, refs);
- }
- catch (Exception e)
- {
- wrap.exceptionOccurred();
- throw e;
- }
- finally
- {
- closeResultSet(rs);
- closeStatement(ps);
- closeConnection(conn);
- wrap.end();
- }
- }
-
- // Merging functionality
- // --------------------
-
- public void mergeTransactions(final long fromChannelID,
- final long toChannelID) throws Exception
- {
- if (trace)
- {
- log.trace("Merging transactions from channel " + fromChannelID
- + " to " + toChannelID);
- }
-
- // Sanity check
-
- if (fromChannelID == toChannelID) { throw new IllegalArgumentException(
- "Cannot merge transactions - they have the same channel id!!"); }
-
- class MergeTransactionsRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement statement = null;
- try
- {
- statement = conn.prepareStatement(getSQLStatement("UPDATE_TX"));
- statement.setLong(1, toChannelID);
- statement.setLong(2, fromChannelID);
- int affected = statement.executeUpdate();
-
- log.debug("Merged " + affected + " transactions from channel "
- + fromChannelID + " into node " + toChannelID);
-
- return null;
- }
- finally
- {
- closeStatement(statement);
- }
- }
- }
-
- new MergeTransactionsRunner().executeWithRetry();
- }
-
- public InitialLoadInfo mergeAndLoad(final long fromChannelID,
- final long toChannelID, final int numberToLoad,
- final long firstPagingOrder, final long nextPagingOrder)
- throws Exception
- {
- if (trace)
- {
- log.trace("Merging channel from " + fromChannelID + " to "
- + toChannelID + " numberToLoad:" + numberToLoad
- + " firstPagingOrder:" + firstPagingOrder + " nextPagingOrder:"
- + nextPagingOrder);
- }
-
- // Sanity
-
- if (fromChannelID == toChannelID) { throw new IllegalArgumentException(
- "Cannot merge queues - they have the same channel id!!"); }
-
- class MergeAndLoadRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement ps = null;
- ResultSet rs = null;
- PreparedStatement ps2 = null;
-
- try
- {
- /*
- * If channel is paging and has full size f
- *
- * then we don't need to load any refs but we need to:
- *
- * make sure the page ord is correct across the old paged and new
- * refs
- *
- * we know the max page ord (from the channel) for the old refs
- * so we just need to:
- *
- * 1) Iterate through the failed channel and update page_ord =
- * max + 1, max + 2 etc
- *
- * 2) update channel id
- *
- *
- * If channel is not paging and the total refs before and after
- * <=f
- *
- * 1) Load all refs from failed channel
- *
- * 2) Update channel id
- *
- * return those refs
- *
- *
- * If channel is not paging but total new refs > f
- *
- * 1) Iterate through failed channel refs and take the first x to
- * make the channel full
- *
- * 2) Update the others with page_ord starting at zero
- *
- * 3) Update channel id
- *
- * In general:
- *
- * We have number to load n, max page size p
- *
- * 1) Iterate through failed channel refs in page_ord order
- *
- * 2) Put the first n in a List.
- *
- * 3) Initialise page_ord_count to be p or 0 depending on whether
- * it was specified
- *
- * 4) Update the page_ord of the remaining refs accordiningly
- *
- * 5) Update the channel id
- *
- */
-
- // First load the refs from the failed channel
- List<ReferenceInfo> refs = new ArrayList<ReferenceInfo>();
-
- ps = conn.prepareStatement(getSQLStatement("LOAD_REFS"));
-
- ps.setLong(1, fromChannelID);
-
- rs = ps.executeQuery();
-
- int count = 0;
-
- boolean arePaged = false;
-
- long pageOrd = nextPagingOrder;
-
- while (rs.next())
- {
- long msgId = rs.getLong(1);
- int deliveryCount = rs.getInt(2);
- long sched = rs.getLong(3);
-
- if (count < numberToLoad)
- {
- ReferenceInfo ri = new ReferenceInfo(msgId, deliveryCount,
- sched);
-
- refs.add(ri);
- }
-
- // Set page ord
-
- if (ps2 == null)
- {
- ps2 = conn
- .prepareStatement(getSQLStatement("UPDATE_PAGE_ORDER"));
- }
-
- if (count < numberToLoad)
- {
- ps2.setNull(1, Types.BIGINT);
-
- if (trace)
- {
- log.trace("Set page ord to null");
- }
- }
- else
- {
- ps2.setLong(1, pageOrd);
-
- if (trace)
- {
- log.trace("Set page ord to " + pageOrd);
- }
-
- arePaged = true;
-
- pageOrd++;
- }
-
- ps2.setLong(2, msgId);
-
- ps2.setLong(3, fromChannelID);
-
- int rows = ps2.executeUpdate();
-
- if (trace)
- {
- log.trace("Update page ord updated " + rows + " rows");
- }
-
- count++;
- }
-
- ps.close();
-
- // Now swap the channel id
-
- ps = conn.prepareStatement(getSQLStatement("UPDATE_CHANNEL_ID"));
-
- ps.setLong(1, toChannelID);
-
- ps.setLong(2, fromChannelID);
-
- int rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace("Update channel id updated " + rows + " rows");
- }
-
- if (arePaged)
- {
- return new InitialLoadInfo(new Long(firstPagingOrder),
- new Long(pageOrd - 1), refs);
- }
- else
- {
- return new InitialLoadInfo(null, null, refs);
- }
- }
- finally
- {
- closeResultSet(rs);
- closeStatement(ps);
- closeStatement(ps2);
- }
- }
- }
- return (InitialLoadInfo) new MergeAndLoadRunner().executeWithRetry();
- }
-
- public void testSpeed() throws Exception
- {
-
- }
-
- // End of paging functionality
- // ===========================
-
- public void addReference(final long channelID, final MessageReference ref,
- final Transaction tx) throws Exception
- {
- if (trace) { log.trace("Adding reference " + ref + " in channel " + channelID + " tx " + tx); }
-
- class AddReferenceRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement psReference = null;
- PreparedStatement psInsertMessage = null;
-
- Message m = ref.getMessage();
-
- try
- {
- psReference = conn
- .prepareStatement(getSQLStatement("INSERT_MESSAGE_REF"));
-
- // Add the reference
- addReference(channelID, ref, psReference, false);
-
- int rows = psReference.executeUpdate();
-
- if (trace)
- {
- log.trace("Inserted " + rows + " rows");
- }
-
- if (!m.isPersisted())
- {
- // First time so persist the message
- psInsertMessage = conn
- .prepareStatement(getSQLStatement("INSERT_MESSAGE"));
-
- storeMessage(m, psInsertMessage, true);
- rows = psInsertMessage.executeUpdate();
-
- if (trace)
- {
- log.trace("Inserted/updated " + rows + " rows");
- }
-
- log.trace("message Inserted/updated " + rows + " rows");
-
- // Needs to be at the end - in case an exception is thrown in
- // which case retry will be attempted and we want to insert it
- // again
- m.setPersisted(true);
- }
-
- return null;
- }
- finally
- {
- closeStatement(psReference);
- closeStatement(psInsertMessage);
- }
- }
- }
-
- if (tx != null)
- {
- // In a tx so we just add the ref in the tx in memory for now
- TransactionCallback callback = getCallback(tx);
-
- callback.addReferenceToAdd(channelID, ref);
- }
- else
- {
- // No tx so add the ref directly in the db
- new AddReferenceRunner().executeWithRetry();
- }
- }
-
- public void moveReference(final long sourceChannelID, final long destChannelID, final MessageReference ref)
- throws Exception
- {
- if (trace) { log.trace("Moving reference " + ref + " from " + sourceChannelID + " to " + destChannelID); }
-
- class MoveReferenceRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement psReference = null;
-
- try
- {
- psReference = conn.prepareStatement(getSQLStatement("MOVE_REFERENCE"));
-
- psReference.setLong(1, destChannelID);
- psReference.setLong(2, sourceChannelID);
- psReference.setLong(3, ref.getMessage().getMessageID());
-
- int rows = psReference.executeUpdate();
-
- if (trace)
- {
- log.trace("Updated " + rows + " rows");
- }
-
- return null;
- }
- finally
- {
- closeStatement(psReference);
- }
- }
- }
-
- new MoveReferenceRunner().executeWithRetry();
- }
-
- public void updateDeliveryCount(final long channelID,
- final MessageReference ref) throws Exception
- {
- class UpdateDeliveryCountRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement psReference = null;
-
- try
- {
- psReference = conn
- .prepareStatement(getSQLStatement("UPDATE_DELIVERY_COUNT"));
-
- psReference.setInt(1, ref.getDeliveryCount());
-
- psReference.setLong(2, channelID);
-
- psReference.setLong(3, ref.getMessage().getMessageID());
-
- int rows = psReference.executeUpdate();
-
- if (trace)
- {
- log.trace("Updated " + rows + " rows");
- }
-
- return null;
- }
- finally
- {
- closeStatement(psReference);
- }
- }
- }
-
- new UpdateDeliveryCountRunner().executeWithRetry();
- }
-
- public void removeReference(final long channelID,
- final MessageReference ref, final Transaction tx) throws Exception
- {
- if (trace) { log.trace("Removing reference " + ref + " in channel " + channelID + " tx " + tx); }
-
- class RemoveReferenceRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement psReference = null;
-
- try
- {
- psReference = conn
- .prepareStatement(getSQLStatement("DELETE_MESSAGE_REF"));
-
- // Remove the message reference
- removeReference(channelID, ref, psReference);
-
- int rows = psReference.executeUpdate();
-
- if (rows != 1)
- {
- log.warn("Failed to remove row for: " + ref);
- return null;
- }
-
- if (trace)
- {
- log.trace("Deleted " + rows + " references");
- }
-
- return null;
- }
- finally
- {
- closeStatement(psReference);
- }
- }
- }
-
- if (tx != null)
- {
- // In a tx so we just add the ref in the tx in memory for now
-
- TransactionCallback callback = getCallback(tx);
-
- callback.addReferenceToRemove(channelID, ref);
- }
- else
- {
- // No tx so we remove the reference directly from the db
-
- new RemoveReferenceRunner().executeWithRetry();
-
- deleteMessage(ref.getMessage().getMessageID());
- }
- }
-
- public boolean referenceExists(long messageID) throws Exception
- {
- Connection conn = null;
- PreparedStatement st = null;
- ResultSet rs = null;
- TransactionWrapper wrap = new TransactionWrapper();
-
- try
- {
- conn = ds.getConnection();
-
- st = conn
- .prepareStatement(getSQLStatement("SELECT_EXISTS_REF_MESSAGE_ID"));
- st.setLong(1, messageID);
-
- rs = st.executeQuery();
-
- if (rs.next())
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception e)
- {
- wrap.exceptionOccurred();
- throw e;
- }
- finally
- {
- closeResultSet(rs);
- closeStatement(st);
- closeConnection(conn);
- wrap.end();
- }
- }
-
- // Public --------------------------------------------------------
-
- public String toString()
- {
- return "JDBCPersistenceManager[" + Integer.toHexString(hashCode()) + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- protected TransactionCallback getCallback(Transaction tx)
- {
- TransactionCallback callback = (TransactionCallback) tx.getCallback(this);
-
- if (callback == null)
- {
- callback = new TransactionCallback(tx);
-
- tx.addCallback(callback, this);
- }
-
- return callback;
- }
-
- protected void handleBeforeCommit1PC(final List refsToAdd,
- final List refsToRemove, final Transaction tx) throws Exception
- {
- class HandleBeforeCommit1PCRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- // For one phase we simply add rows corresponding to the refs and
- // remove rows corresponding to
- // the deliveries in one jdbc tx. We also need to store messages as
- // necessary,
- // depending on whether they've already been stored or still
- // referenced by other channels.
-
- PreparedStatement psReference = null;
- PreparedStatement psInsertMessage = null;
- PreparedStatement psDeleteReference = null;
-
- List<Message> messagesStored = new ArrayList<Message>();
-
- try
- {
- // First the adds
-
- for (Iterator i = refsToAdd.iterator(); i.hasNext();)
- {
- ChannelRefPair pair = (ChannelRefPair) i.next();
- MessageReference ref = pair.ref;
-
- psReference = conn
- .prepareStatement(getSQLStatement("INSERT_MESSAGE_REF"));
-
- // Now store the reference
- addReference(pair.channelID, ref, psReference, false);
-
- int rows = psReference.executeUpdate();
-
- if (trace)
- {
- log.trace("Inserted " + rows + " rows");
- }
-
- Message m = ref.getMessage();
-
- synchronized (m)
- {
- if (!m.isPersisted())
- {
- if (psInsertMessage == null)
- {
- psInsertMessage = conn
- .prepareStatement(getSQLStatement("INSERT_MESSAGE"));
- }
-
- // First time so add message
- // And in case of clustered queues/topics, the message
- // could possibly be already persisted on the different
- // node
- // so we persist also using the Conditional Update
- if (trace)
- {
- log
- .trace("Message does not already exist so inserting it");
- }
- storeMessage(m, psInsertMessage, true);
- rows = psInsertMessage.executeUpdate();
- if (trace)
- {
- log.trace("Inserted " + rows + " rows");
- }
-
- m.setPersisted(true);
-
- messagesStored.add(m);
- }
- }
- }
-
- // Now the removes
-
- for (Iterator i = refsToRemove.iterator(); i.hasNext();)
- {
- ChannelRefPair pair = (ChannelRefPair) i.next();
-
- if (psDeleteReference == null)
- {
- psDeleteReference = conn
- .prepareStatement(getSQLStatement("DELETE_MESSAGE_REF"));
- }
-
- removeReference(pair.channelID, pair.ref, psDeleteReference);
-
- int rows = psDeleteReference.executeUpdate();
-
- if (trace)
- {
- log.trace("Deleted " + rows + " references");
- }
-
- }
-
- return null;
- }
- catch (Exception e)
- {
- for (Iterator i = messagesStored.iterator(); i.hasNext();)
- {
- Message msg = (Message) i.next();
-
- msg.setPersisted(false);
- }
- throw e;
- }
- finally
- {
- closeStatement(psReference);
- closeStatement(psDeleteReference);
- closeStatement(psInsertMessage);
- }
- }
- }
-
- new HandleBeforeCommit1PCRunner().executeWithRetry();
-
- this.deleteMessages(refsToRemove);
- }
-
- protected void handleBeforeCommit2PC(final List refsToRemove,
- final Transaction tx) throws Exception
- {
- class HandleBeforeCommit2PCRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement ps = null;
-
- if (trace)
- {
- log.trace(this + " commitPreparedTransaction, tx= " + tx);
- }
-
- try
- {
- ps = conn
- .prepareStatement(getSQLStatement("COMMIT_MESSAGE_REF1"));
-
- ps.setLong(1, tx.getId());
-
- int rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(
- getSQLStatement("COMMIT_MESSAGE_REF1"), new Long(tx
- .getId()))
- + " removed " + rows + " row(s)");
- }
-
- ps.close();
-
- ps = conn
- .prepareStatement(getSQLStatement("COMMIT_MESSAGE_REF2"));
- ps.setLong(1, tx.getId());
-
- rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(
- getSQLStatement("COMMIT_MESSAGE_REF2"), new Long(tx
- .getId()))
- + " updated " + rows + " row(s)");
- }
-
- removeTXRecord(conn, tx);
-
- return null;
- }
- finally
- {
- closeStatement(ps);
- }
- }
- }
-
- new HandleBeforeCommit2PCRunner().executeWithRetry();
-
- this.deleteMessages(refsToRemove);
- }
-
- protected void handleBeforePrepare(final List refsToAdd,
- final List refsToRemove, final Transaction tx) throws Exception
- {
- class HandleBeforePrepareRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- // We insert a tx record and
- // a row for each ref with +
- // and update the row for each delivery with "-"
-
- PreparedStatement psReference = null;
- PreparedStatement psInsertMessage = null;
- PreparedStatement psUpdateReference = null;
-
- List<Message> messagesStored = new ArrayList<Message>();
-
- try
- {
- // Insert the tx record
- if (!refsToAdd.isEmpty() || !refsToRemove.isEmpty())
- {
- addTXRecord(conn, tx);
- }
-
- Iterator iter = refsToAdd.iterator();
-
- while (iter.hasNext())
- {
- ChannelRefPair pair = (ChannelRefPair) iter.next();
-
- if (psReference == null)
- {
- psReference = conn
- .prepareStatement(getSQLStatement("INSERT_MESSAGE_REF"));
- }
-
- prepareToAddReference(pair.channelID, pair.ref, tx,
- psReference);
-
- int rows = psReference.executeUpdate();
-
- if (trace)
- {
- log.trace("Inserted " + rows + " rows");
- }
-
- Message m = pair.ref.getMessage();
-
- synchronized (m)
- {
- if (!m.isPersisted())
- {
- if (psInsertMessage == null)
- {
- psInsertMessage = conn
- .prepareStatement(getSQLStatement("INSERT_MESSAGE"));
- }
-
- storeMessage(m, psInsertMessage, true);
- rows = psInsertMessage.executeUpdate();
-
- if (trace)
- {
- log.trace("Inserted " + rows + " rows");
- }
-
- m.setPersisted(true);
-
- messagesStored.add(m);
- }
- }
- }
-
- // Now the removes
-
- iter = refsToRemove.iterator();
-
- while (iter.hasNext())
- {
- if (psUpdateReference == null)
- {
- psUpdateReference = conn
- .prepareStatement(getSQLStatement("UPDATE_MESSAGE_REF"));
- }
-
- ChannelRefPair pair = (ChannelRefPair) iter.next();
-
- prepareToRemoveReference(pair.channelID, pair.ref, tx,
- psUpdateReference);
-
- int rows = psUpdateReference.executeUpdate();
-
- if (trace)
- {
- log.trace("updated " + rows + " rows");
- }
- }
-
- return null;
- }
- catch (Exception e)
- {
- for (Iterator i = messagesStored.iterator(); i.hasNext();)
- {
- Message msg = (Message) i.next();
-
- msg.setPersisted(false);
- }
- throw e;
- }
- finally
- {
- closeStatement(psReference);
- closeStatement(psInsertMessage);
- closeStatement(psUpdateReference);
- }
- }
- }
-
- new HandleBeforePrepareRunner().executeWithRetry();
- }
-
- protected void handleBeforeRollback(final List refsToAdd,
- final Transaction tx) throws Exception
- {
- class HandleBeforeRollbackRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
- PreparedStatement ps = null;
-
- try
- {
- ps = conn
- .prepareStatement(getSQLStatement("ROLLBACK_MESSAGE_REF1"));
-
- ps.setLong(1, tx.getId());
-
- int rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(
- getSQLStatement("ROLLBACK_MESSAGE_REF1"), new Long(tx
- .getId()))
- + " removed " + rows + " row(s)");
- }
-
- ps.close();
-
- ps = conn
- .prepareStatement(getSQLStatement("ROLLBACK_MESSAGE_REF2"));
- ps.setLong(1, tx.getId());
-
- rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(
- getSQLStatement("ROLLBACK_MESSAGE_REF2"), new Long(tx
- .getId()))
- + " updated " + rows + " row(s)");
- }
-
- removeTXRecord(conn, tx);
-
- return null;
- }
- finally
- {
- closeStatement(ps);
- }
- }
- }
-
- new HandleBeforeRollbackRunner().executeWithRetry();
-
- this.deleteMessages(refsToAdd);
- }
-
- protected void addTXRecord(Connection conn, Transaction tx) throws Exception
- {
- if (trace)
- {
- log.trace("Inserting tx record for " + tx);
- }
-
- if (!this.nodeIDSet)
- {
- // Sanity
- throw new IllegalStateException("Node id has not been set");
- }
-
- PreparedStatement ps = null;
- String statement = "UNDEFINED";
- int rows = -1;
- int formatID = -1;
- try
- {
- statement = getSQLStatement("INSERT_TRANSACTION");
-
- ps = conn.prepareStatement(statement);
-
- ps.setInt(1, nodeID);
-
- ps.setLong(2, tx.getId());
-
- Xid xid = tx.getXid();
-
- formatID = xid.getFormatId();
-
- setVarBinaryColumn(3, ps, xid.getBranchQualifier());
-
- ps.setInt(4, formatID);
-
- setVarBinaryColumn(5, ps, xid.getGlobalTransactionId());
-
- rows = ps.executeUpdate();
- }
- finally
- {
- if (trace)
- {
- String s = JDBCUtil.statementToString(statement,
- new Integer(nodeID), new Long(tx.getId()), "<byte-array>",
- new Integer(formatID), "<byte-array>");
- log
- .trace(s
- + (rows == -1 ? " failed!" : " inserted " + rows
- + " row(s)"));
- }
- closeStatement(ps);
- }
- }
-
- protected void removeTXRecord(Connection conn, Transaction tx)
- throws Exception
- {
- if (!this.nodeIDSet)
- {
- // Sanity
- throw new IllegalStateException("Node id has not been set");
- }
-
- PreparedStatement ps = null;
- try
- {
- ps = conn.prepareStatement(getSQLStatement("DELETE_TRANSACTION"));
-
- ps.setInt(1, nodeID);
-
- ps.setLong(2, tx.getId());
-
- int rows = ps.executeUpdate();
-
- if (trace)
- {
- log.trace(JDBCUtil.statementToString(
- getSQLStatement("DELETE_TRANSACTION"), new Integer(nodeID),
- new Long(tx.getId()))
- + " removed " + rows + " row(s)");
- }
- }
- finally
- {
- closeStatement(ps);
- }
- }
-
- protected void addReference(long channelID, MessageReference ref,
- PreparedStatement ps, boolean paged) throws Exception
- {
- if (trace)
- {
- log.trace("adding " + ref + " to channel " + channelID);
- }
-
- ps.setLong(1, channelID);
- ps.setLong(2, ref.getMessage().getMessageID());
- ps.setNull(3, Types.BIGINT);
- ps.setString(4, "C");
- ps.setLong(5, getOrdering());
- if (paged)
- {
- ps.setLong(6, ref.getPagingOrder());
- }
- else
- {
- ps.setNull(6, Types.BIGINT);
- }
- ps.setInt(7, ref.getDeliveryCount());
- ps.setLong(8, ref.getScheduledDeliveryTime());
- }
-
- protected void removeReference(long channelID, MessageReference ref,
- PreparedStatement ps) throws Exception
- {
- if (trace)
- {
- log.trace("removing " + ref + " from channel " + channelID);
- }
-
- ps.setLong(1, ref.getMessage().getMessageID());
- ps.setLong(2, channelID);
- }
-
- protected void prepareToAddReference(long channelID, MessageReference ref,
- Transaction tx, PreparedStatement ps) throws Exception
- {
- if (trace)
- {
- log.trace("adding "
- + ref
- + " to channel "
- + channelID
- + (tx == null ? " non-transactionally" : " on transaction: "
- + tx));
- }
-
- ps.setLong(1, channelID);
- ps.setLong(2, ref.getMessage().getMessageID());
- ps.setLong(3, tx.getId());
- ps.setString(4, "+");
- ps.setLong(5, getOrdering());
- ps.setNull(6, Types.BIGINT);
- ps.setInt(7, ref.getDeliveryCount());
- ps.setLong(8, ref.getScheduledDeliveryTime());
- }
-
- protected void prepareToRemoveReference(long channelID,
- MessageReference ref, Transaction tx, PreparedStatement ps)
- throws Exception
- {
- if (trace)
- {
- log.trace("removing "
- + ref
- + " from channel "
- + channelID
- + (tx == null ? " non-transactionally" : " on transaction: "
- + tx));
- }
-
- ps.setLong(1, tx.getId());
- ps.setLong(2, ref.getMessage().getMessageID());
- ps.setLong(3, channelID);
- }
-
- protected byte[] mapToBytes(Map map) throws Exception
- {
- if (map == null || map.isEmpty()) { return null; }
-
- final int BUFFER_SIZE = 1024;
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE);
-
- DataOutputStream oos = new DataOutputStream(bos);
-
- StreamUtils.writeMap(oos, map, true);
-
- oos.close();
-
- return bos.toByteArray();
- }
-
- protected HashMap bytesToMap(byte[] bytes) throws Exception
- {
- if (bytes == null) { return new HashMap(); }
-
- ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
-
- DataInputStream dais = new DataInputStream(bis);
-
- HashMap map = StreamUtils.readMap(dais, true);
-
- dais.close();
-
- return map;
- }
-
- /**
- * Stores the message in the MESSAGE table.
- */
- protected void storeMessage(Message m, PreparedStatement ps, boolean bindBlobs) throws Exception
- {
- // physically insert the row in the database
- // first set the fields from org.jboss.messaging.core.Routable
- ps.setLong(1, m.getMessageID());
- ps.setString(2, m.isReliable() ? "Y" : "N");
- ps.setLong(3, m.getExpiration());
- ps.setLong(4, m.getTimestamp());
- ps.setByte(5, m.getPriority());
- ps.setByte(6, m.getType());
-
- if (bindBlobs)
- {
- bindBlobs(m, ps, 7, 8);
- }
- }
-
- protected int storeMessage(Message message, PreparedStatement psInsertMessage, PreparedStatement psUpdateMessage)
- throws Exception
- {
- int rows;
- if (!supportsBlobSelect)
- {
- // Need to store in two phases
- storeMessage(message, psInsertMessage, false);
- psInsertMessage.setLong(7, message.getMessageID());
- rows = psInsertMessage.executeUpdate();
-
- if (rows == 1)
- {
- bindBlobs(message, psUpdateMessage, 1, 2);
- psUpdateMessage.setLong(3, message.getMessageID());
- rows = psUpdateMessage.executeUpdate();
- if (rows != 1) { throw new IllegalStateException(
- "Couldn't update messageId=" + message.getMessageID()
- + " on paging"); }
- }
- }
- else
- {
- // Can store in one go
- storeMessage(message, psInsertMessage, true);
- psInsertMessage.setLong(9, message.getMessageID());
- rows = psInsertMessage.executeUpdate();
- }
- return rows;
- }
-
- private void bindBlobs(Message m, PreparedStatement ps, int headerPosition,
- int payloadPosition) throws Exception
- {
- // headers
- byte[] bytes = mapToBytes(((MessageSupport) m).getHeaders());
- if (bytes != null)
- {
- setBytes(ps, headerPosition, bytes);
- }
- else
- {
- ps.setNull(headerPosition, Types.LONGVARBINARY);
- }
-
- byte[] payload = m.getPayloadAsByteArray();
- if (payload != null)
- {
- setBytes(ps, payloadPosition, payload);
- }
- else
- {
- ps.setNull(payloadPosition, Types.LONGVARBINARY);
- }
- }
-
- protected void setVarBinaryColumn(int column, PreparedStatement ps,
- byte[] bytes) throws Exception
- {
- if (usingTrailingByte)
- {
- // Sybase has the stupid characteristic of truncating all trailing in
- // zeros
- // in varbinary columns
- // So we add an extra byte on the end when we store the varbinary data
- // otherwise we might lose data
- // http://jira.jboss.org/jira/browse/JBMESSAGING-825
-
- byte[] res = new byte[bytes.length + 1];
-
- System.arraycopy(bytes, 0, res, 0, bytes.length);
-
- res[bytes.length] = 127;
-
- bytes = res;
- }
-
- ps.setBytes(column, bytes);
-
- if (trace)
- {
- log.trace("Setting varbinary column of length: " + bytes.length);
- }
- }
-
- protected byte[] getVarBinaryColumn(ResultSet rs, int columnIndex)
- throws Exception
- {
- byte[] bytes = rs.getBytes(columnIndex);
-
- if (usingTrailingByte)
- {
- // Get rid of the trailing byte
-
- // http://jira.jboss.org/jira/browse/JBMESSAGING-825
-
- byte[] newBytes = new byte[bytes.length - 1];
-
- System.arraycopy(bytes, 0, newBytes, 0, bytes.length - 1);
-
- bytes = newBytes;
- }
-
- return bytes;
- }
-
- // Used for storing message headers and bodies
- protected void setBytes(PreparedStatement ps, int columnIndex, byte[] bytes)
- throws Exception
- {
- if (usingBinaryStream)
- {
- // Set the bytes using a binary stream - likely to be better for large
- // byte[]
-
- InputStream is = null;
-
- try
- {
- is = new ByteArrayInputStream(bytes);
-
- ps.setBinaryStream(columnIndex, is, bytes.length);
- }
- finally
- {
- if (is != null)
- {
- is.close();
- }
- }
- }
- else
- {
- // Set the bytes using setBytes() - likely to be better for smaller
- // byte[]
-
- setVarBinaryColumn(columnIndex, ps, bytes);
- }
- }
-
- protected byte[] getBytes(ResultSet rs, int columnIndex) throws Exception
- {
- if (usingBinaryStream)
- {
- // Get the bytes using a binary stream - likely to be better for large
- // byte[]
-
- InputStream is = null;
- ByteArrayOutputStream os = null;
-
- final int BUFFER_SIZE = 4096;
-
- try
- {
- InputStream i = rs.getBinaryStream(columnIndex);
-
- if (i == null) { return null; }
-
- is = new BufferedInputStream(rs.getBinaryStream(columnIndex),
- BUFFER_SIZE);
-
- os = new ByteArrayOutputStream(BUFFER_SIZE);
-
- int b;
- while ((b = is.read()) != -1)
- {
- os.write(b);
- }
-
- return os.toByteArray();
- }
- finally
- {
- if (is != null)
- {
- is.close();
- }
- if (os != null)
- {
- os.close();
- }
- }
- }
- else
- {
- // Get the bytes using getBytes() - better for smaller byte[]
- return getVarBinaryColumn(rs, columnIndex);
- }
- }
-
- protected void logBatchUpdate(String name, int[] rows, String action)
- {
- int count = 0;
- for (int i = 0; i < rows.length; i++)
- {
- count += rows[i];
- }
- log.trace("Batch update " + name + ", " + action + " total of " + count
- + " rows");
- }
-
- // PersistentServiceSupport overrides ----------------------------
-
- protected Map getDefaultDDLStatements()
- {
- Map<String, String> map = new LinkedHashMap<String, String>();
- map.put("CREATE_DUAL", "CREATE TABLE JBM_DUAL (DUMMY INTEGER)");
- // Message reference
- map.put("CREATE_MESSAGE_REFERENCE",
- "CREATE TABLE JBM_MSG_REF (CHANNEL_ID BIGINT, "
- + "MESSAGE_ID BIGINT, TRANSACTION_ID BIGINT, STATE CHAR(1), ORD BIGINT, PAGE_ORD BIGINT, "
- + "DELIVERY_COUNT INTEGER, SCHED_DELIVERY BIGINT, PRIMARY KEY(CHANNEL_ID, MESSAGE_ID))");
- map.put("CREATE_IDX_MESSAGE_REF_TX",
- "CREATE INDEX JBM_MSG_REF_TX ON JBM_MSG_REF (TRANSACTION_ID)");
- map.put("CREATE_IDX_MESSAGE_REF_ORD",
- "CREATE INDEX JBM_MSG_REF_ORD ON JBM_MSG_REF (ORD)");
- map.put("CREATE_IDX_MESSAGE_REF_PAGE_ORD",
- "CREATE INDEX JBM_MSG_REF__PAGE_ORD ON JBM_MSG_REF (PAGE_ORD)");
- map.put("CREATE_IDX_MESSAGE_REF_MESSAGE_ID",
- "CREATE INDEX JBM_MSG_REF_MESSAGE_ID ON JBM_MSG_REF (MESSAGE_ID)");
- map.put("CREATE_IDX_MESSAGE_REF_SCHED_DELIVERY",
- "CREATE INDEX JBM_MSG_REF_SCHED_DELIVERY ON JBM_MSG_REF (SCHED_DELIVERY)");
- // Message
- map.put("CREATE_MESSAGE",
- "CREATE TABLE JBM_MSG (MESSAGE_ID BIGINT, RELIABLE CHAR(1), "
- + "EXPIRATION BIGINT, TIMESTAMP BIGINT, PRIORITY TINYINT, TYPE TINYINT, HEADERS LONGVARBINARY, "
- + "PAYLOAD LONGVARBINARY, "
- + "PRIMARY KEY (MESSAGE_ID))");
- // Transaction
- map.put("CREATE_TRANSACTION",
- "CREATE TABLE JBM_TX ("
- + "NODE_ID INTEGER, TRANSACTION_ID BIGINT, BRANCH_QUAL VARBINARY(254), "
- + "FORMAT_ID INTEGER, GLOBAL_TXID VARBINARY(254), PRIMARY KEY (TRANSACTION_ID))");
- // Counter
- map.put("CREATE_COUNTER",
- "CREATE TABLE JBM_COUNTER (NAME VARCHAR(255), NEXT_ID BIGINT, PRIMARY KEY(NAME))");
- return map;
- }
-
- protected Map getDefaultDMLStatements()
- {
- Map<String, String> map = new LinkedHashMap<String, String>();
- map.put("INSERT_DUAL", "INSERT INTO JBM_DUAL VALUES (1)");
- map.put("CHECK_DUAL", "SELECT 1 FROM JBM_DUAL");
- // Message reference
- map.put("INSERT_MESSAGE_REF",
- "INSERT INTO JBM_MSG_REF (CHANNEL_ID, MESSAGE_ID, TRANSACTION_ID, STATE, ORD, PAGE_ORD, DELIVERY_COUNT, SCHED_DELIVERY) "
- + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
- map.put("DELETE_MESSAGE_REF",
- "DELETE FROM JBM_MSG_REF WHERE MESSAGE_ID=? AND CHANNEL_ID=? AND STATE='C'");
- map.put("UPDATE_MESSAGE_REF",
- "UPDATE JBM_MSG_REF SET TRANSACTION_ID=?, STATE='-' "
- + "WHERE MESSAGE_ID=? AND CHANNEL_ID=? AND STATE='C'");
- map.put("UPDATE_PAGE_ORDER",
- "UPDATE JBM_MSG_REF SET PAGE_ORD = ? WHERE MESSAGE_ID=? AND CHANNEL_ID=?");
- map.put("COMMIT_MESSAGE_REF1",
- "UPDATE JBM_MSG_REF SET STATE='C', TRANSACTION_ID = NULL WHERE TRANSACTION_ID=? AND STATE='+'");
- map.put("COMMIT_MESSAGE_REF2",
- "DELETE FROM JBM_MSG_REF WHERE TRANSACTION_ID=? AND STATE='-'");
- map.put("ROLLBACK_MESSAGE_REF1",
- "DELETE FROM JBM_MSG_REF WHERE TRANSACTION_ID=? AND STATE='+'");
- map.put("ROLLBACK_MESSAGE_REF2",
- "UPDATE JBM_MSG_REF SET STATE='C', TRANSACTION_ID = NULL WHERE TRANSACTION_ID=? AND STATE='-'");
- map.put("LOAD_PAGED_REFS",
- "SELECT MESSAGE_ID, DELIVERY_COUNT, PAGE_ORD, SCHED_DELIVERY FROM JBM_MSG_REF "
- + "WHERE CHANNEL_ID = ? AND PAGE_ORD BETWEEN ? AND ? ORDER BY PAGE_ORD");
- map.put("LOAD_UNPAGED_REFS",
- "SELECT MESSAGE_ID, DELIVERY_COUNT, SCHED_DELIVERY FROM JBM_MSG_REF WHERE STATE = 'C' "
- + "AND CHANNEL_ID = ? AND PAGE_ORD IS NULL ORDER BY ORD");
- map.put("LOAD_REFS",
- "SELECT MESSAGE_ID, DELIVERY_COUNT, SCHED_DELIVERY FROM JBM_MSG_REF WHERE STATE = 'C' "
- + "AND CHANNEL_ID = ? ORDER BY ORD");
- map.put("UPDATE_REFS_NOT_PAGED",
- "UPDATE JBM_MSG_REF SET PAGE_ORD = NULL WHERE PAGE_ORD BETWEEN ? AND ? AND CHANNEL_ID=?");
- map.put("SELECT_MIN_MAX_PAGE_ORD",
- "SELECT MIN(PAGE_ORD), MAX(PAGE_ORD) FROM JBM_MSG_REF WHERE CHANNEL_ID = ?");
- map.put("SELECT_EXISTS_REF_MESSAGE_ID",
- "SELECT MESSAGE_ID FROM JBM_MSG_REF WHERE MESSAGE_ID = ?");
- map.put("UPDATE_DELIVERY_COUNT",
- "UPDATE JBM_MSG_REF SET DELIVERY_COUNT = ? WHERE CHANNEL_ID = ? AND MESSAGE_ID = ?");
- map.put("UPDATE_CHANNEL_ID",
- "UPDATE JBM_MSG_REF SET CHANNEL_ID = ? WHERE CHANNEL_ID = ?");
- map.put("MOVE_REFERENCE",
- "UPDATE JBM_MSG_REF SET CHANNEL_ID = ? WHERE CHANNEL_ID = ? AND MESSAGE_ID = ?");
-
- // Message
- map.put("LOAD_MESSAGES",
- "SELECT MESSAGE_ID, RELIABLE, EXPIRATION, TIMESTAMP, "
- + "PRIORITY, HEADERS, PAYLOAD, TYPE " + "FROM JBM_MSG");
- map.put("INSERT_MESSAGE",
- "INSERT INTO JBM_MSG (MESSAGE_ID, RELIABLE, EXPIRATION, "
- + "TIMESTAMP, PRIORITY, TYPE, HEADERS, PAYLOAD) "
- + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
- map.put("INSERT_MESSAGE_CONDITIONAL",
- "INSERT INTO JBM_MSG (MESSAGE_ID, RELIABLE, EXPIRATION, "
- + "TIMESTAMP, PRIORITY, TYPE) "
- + "SELECT ?, ?, ?, ?, ?, ? "
- + "FROM JBM_DUAL WHERE NOT EXISTS (SELECT MESSAGE_ID FROM JBM_MSG WHERE MESSAGE_ID = ?)");
- map.put("INSERT_MESSAGE_CONDITIONAL_FULL",
- "INSERT INTO JBM_MSG (MESSAGE_ID, RELIABLE, EXPIRATION, TIMESTAMP, PRIORITY, TYPE, HEADERS, PAYLOAD) SELECT ?, ?, ?, ?, ?, ?, ?, ? FROM JBM_DUAL WHERE NOT EXISTS (SELECT MESSAGE_ID FROM JBM_MSG WHERE MESSAGE_ID = ?)");
- map.put("UPDATE_MESSAGE_4CONDITIONAL",
- "UPDATE JBM_MSG SET HEADERS=?, PAYLOAD=? WHERE MESSAGE_ID=?");
- map.put("MESSAGE_ID_COLUMN", "MESSAGE_ID");
- map.put("DELETE_MESSAGE",
- "DELETE FROM JBM_MSG WHERE MESSAGE_ID = ? AND NOT EXISTS (SELECT * FROM JBM_MSG_REF WHERE JBM_MSG_REF.MESSAGE_ID = ?)");
- // Transaction
- map.put("INSERT_TRANSACTION",
- "INSERT INTO JBM_TX (NODE_ID, TRANSACTION_ID, BRANCH_QUAL, FORMAT_ID, GLOBAL_TXID) "
- + "VALUES(?, ?, ?, ?, ?)");
- map.put("DELETE_TRANSACTION",
- "DELETE FROM JBM_TX WHERE NODE_ID = ? AND TRANSACTION_ID = ?");
- map.put("SELECT_PREPARED_TRANSACTIONS",
- "SELECT TRANSACTION_ID, BRANCH_QUAL, FORMAT_ID, GLOBAL_TXID FROM JBM_TX WHERE NODE_ID = ?");
- map.put("SELECT_MESSAGE_ID_FOR_REF",
- "SELECT MESSAGE_ID, CHANNEL_ID FROM JBM_MSG_REF WHERE TRANSACTION_ID = ? AND STATE = '+' ORDER BY ORD");
- map.put("SELECT_MESSAGE_ID_FOR_ACK",
- "SELECT MESSAGE_ID, CHANNEL_ID FROM JBM_MSG_REF WHERE TRANSACTION_ID = ? AND STATE = '-' ORDER BY ORD");
- map.put("UPDATE_TX", "UPDATE JBM_TX SET NODE_ID=? WHERE NODE_ID=?");
-
- // Counter
- map.put("UPDATE_COUNTER",
- "UPDATE JBM_COUNTER SET NEXT_ID = ? WHERE NAME=?");
- map.put("SELECT_COUNTER", "SELECT NEXT_ID FROM JBM_COUNTER WHERE NAME=?");
- map.put("INSERT_COUNTER",
- "INSERT INTO JBM_COUNTER (NAME, NEXT_ID) VALUES (?, ?)");
- // Other
- map.put("SELECT_ALL_CHANNELS",
- "SELECT DISTINCT(CHANNEL_ID) FROM JBM_MSG_REF");
-
- return map;
- }
-
- // Private -------------------------------------------------------
-
- private void deleteMessages(final List references) throws Exception
- {
- class DeleteMessagesRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
-
- PreparedStatement psMessage = null;
-
- try
- {
- psMessage = conn
- .prepareStatement(getSQLStatement("DELETE_MESSAGE"));
-
- Iterator iter = references.iterator();
-
- while (iter.hasNext())
- {
- Object obj = iter.next();
-
- MessageReference ref;
- if (obj instanceof MessageReference)
- {
- ref = (MessageReference) obj;
- }
- else
- {
- ref = ((ChannelRefPair) obj).ref;
- }
-
- psMessage.setLong(1, ref.getMessage().getMessageID());
- psMessage.setLong(2, ref.getMessage().getMessageID());
-
- int rows = psMessage.executeUpdate();
-
- if (trace)
- {
- log.trace("Deleted " + rows + " messages");
- }
-
- }
-
- return null;
- }
- finally
- {
- closeStatement(psMessage);
- }
- }
- }
-
- // Order to avoid deadlock
- orderReferences(references);
-
- new DeleteMessagesRunner().executeWithRetry();
- }
-
- private void deleteMessage(final long messageID) throws Exception
- {
- class DeleteMessageRunner extends JDBCTxRunner2
- {
- public Object doTransaction() throws Exception
- {
-
- PreparedStatement psMessage = null;
-
- try
- {
- psMessage = conn
- .prepareStatement(getSQLStatement("DELETE_MESSAGE"));
-
- psMessage.setLong(1, messageID);
- psMessage.setLong(2, messageID);
-
- int rows = psMessage.executeUpdate();
-
- if (trace)
- {
- log.trace("Deleted " + rows + " messages");
- }
-
- return null;
- }
- finally
- {
- closeStatement(psMessage);
- }
- }
- }
-
- new DeleteMessageRunner().executeWithRetry();
- }
-
- private List getMessageChannelPair(String sqlQuery, long transactionId)
- throws Exception
- {
- if (trace) log.trace("loading message and channel ids for tx ["
- + transactionId + "]");
-
- if (!this.nodeIDSet)
- {
- // Sanity
- throw new IllegalStateException("Node id has not been set");
- }
-
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- TransactionWrapper wrap = new TransactionWrapper();
-
- try
- {
- conn = ds.getConnection();
-
- ps = conn.prepareStatement(sqlQuery);
-
- ps.setLong(1, transactionId);
-
- rs = ps.executeQuery();
-
- // Don't use a Map. A message could be in multiple channels in a tx, so
- // if you use a map
- // when you put the same message again it's going to overwrite the
- // previous put!!
-
- class Holder
- {
- long messageId;
- long channelId;
-
- Holder(long messageId, long channelId)
- {
- this.messageId = messageId;
- this.channelId = channelId;
- }
- }
-
- List<Holder> holders = new ArrayList<Holder>();
-
- // Unique set of messages
- Set<Long> msgIds = new HashSet<Long>();
-
- // TODO it would probably have been simpler just to have done all this
- // in a SQL JOIN rather
- // than do the join in memory.....
-
- while (rs.next())
- {
- long messageId = rs.getLong(1);
- long channelId = rs.getLong(2);
-
- Holder holder = new Holder(messageId, channelId);
-
- holders.add(holder);
-
- msgIds.add(messageId);
-
- if (trace) log.trace("Loaded MsgID: " + messageId
- + " and ChannelID: " + channelId);
- }
-
- Map messageMap = new HashMap();
-
- List messages = getMessages(new ArrayList(msgIds));
-
- for (Iterator iter = messages.iterator(); iter.hasNext();)
- {
- Message msg = (Message) iter.next();
-
- messageMap.put(new Long(msg.getMessageID()), msg);
- }
-
- List returnList = new ArrayList();
-
- for (Iterator iter = holders.iterator(); iter.hasNext();)
- {
- Holder holder = (Holder) iter.next();
-
- Message msg = (Message) messageMap.get(new Long(holder.messageId));
-
- if (msg == null) { throw new IllegalStateException(
- "Cannot find message " + holder.messageId); }
-
- MessageChannelPair pair = new MessageChannelPair(msg,
- holder.channelId);
-
- returnList.add(pair);
- }
-
- return returnList;
- }
- catch (Exception e)
- {
- wrap.exceptionOccurred();
- throw e;
- }
- finally
- {
- closeResultSet(rs);
- closeStatement(ps);
- closeConnection(conn);
- wrap.end();
- }
- }
-
- private synchronized long getOrdering()
- {
- // We generate the ordering for the message reference by taking the lowest
- // 48 bits of the current time and
- // concatenating with a 15 bit rotating counter to form a string of 63
- // bits which we then place
- // in the right most bits of a long, giving a positive signed 63 bit
- // integer.
-
- // Having a time element in the ordering means we don't have to maintain a
- // counter in the database
- // It also helps with failover since if two queues merge after failover
- // then, the ordering will mean
- // their orderings interleave nicely and they still get consumed in pretty
- // much time order
-
- // We only have to guarantee ordering per session, so having slight
- // differences of time on different nodes is
- // not a problem
-
- // The time element is good for about 8919 years - if you're still running
- // JBoss Messaging then, I suggest you need an
- // upgrade!
-
- long order = System.currentTimeMillis();
-
- order = order << 15;
-
- order = order | orderCount;
-
- if (orderCount == Short.MAX_VALUE)
- {
- orderCount = 0;
- }
- else
- {
- orderCount++;
- }
-
- return order;
- }
-
- // Inner classes -------------------------------------------------
-
- private static class ChannelRefPair
- {
- private long channelID;
- private MessageReference ref;
-
- private ChannelRefPair(long channelID, MessageReference ref)
- {
- this.channelID = channelID;
- this.ref = ref;
- }
- }
-
- private class TransactionCallback implements TxCallback
- {
- private Transaction tx;
-
- private List refsToAdd;
-
- private List refsToRemove;
-
- private TransactionCallback(Transaction tx)
- {
- this.tx = tx;
-
- refsToAdd = new ArrayList();
-
- refsToRemove = new ArrayList();
- }
-
- private void addReferenceToAdd(long channelId, MessageReference ref)
- {
- refsToAdd.add(new ChannelRefPair(channelId, ref));
- }
-
- private void addReferenceToRemove(long channelId, MessageReference ref)
- {
- refsToRemove.add(new ChannelRefPair(channelId, ref));
- }
-
- public void afterCommit(boolean onePhase)
- {
- // NOOP
- }
-
- public void afterPrepare()
- {
- // NOOP
- }
-
- public void afterRollback(boolean onePhase)
- {
- // NOOP
- }
-
- public void beforeCommit(boolean onePhase) throws Exception
- {
- if (onePhase)
- {
- handleBeforeCommit1PC(refsToAdd, refsToRemove, tx);
- }
- else
- {
- handleBeforeCommit2PC(refsToRemove, tx);
- }
- }
-
- public void beforePrepare() throws Exception
- {
- handleBeforePrepare(refsToAdd, refsToRemove, tx);
- }
-
- public void beforeRollback(boolean onePhase) throws Exception
- {
- if (onePhase)
- {
- // NOOP - nothing in db
- }
- else
- {
- handleBeforeRollback(refsToAdd, tx);
- }
- }
- }
-
- private void orderReferences(List references)
- {
- Collections.sort(references, MessageOrderComparator.instance);
- }
-
- private static class MessageOrderComparator implements Comparator
- {
- static MessageOrderComparator instance = new MessageOrderComparator();
-
- public int compare(Object o1, Object o2)
- {
- MessageReference ref1;
- MessageReference ref2;
-
- if (o1 instanceof MessageReference)
- {
- ref1 = (MessageReference) o1;
- ref2 = (MessageReference) o2;
- }
- else
- {
- ref1 = ((ChannelRefPair) o1).ref;
- ref2 = ((ChannelRefPair) o2).ref;
- }
-
- long id1 = ref1.getMessage().getMessageID();
- long id2 = ref2.getMessage().getMessageID();
-
- return (id1 < id2 ? -1 : (id1 == id2 ? 0 : 1));
- }
- }
-
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/JDBCSupport.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/JDBCSupport.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/JDBCSupport.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -37,7 +37,7 @@
import javax.transaction.TransactionManager;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.MessagingComponent;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import org.jboss.util.NestedSQLException;
/**
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/MessagingQueue.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/MessagingQueue.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/MessagingQueue.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -37,14 +37,14 @@
import org.jboss.messaging.core.contract.DeliveryObserver;
import org.jboss.messaging.core.contract.Distributor;
import org.jboss.messaging.core.contract.Filter;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.MessageStore;
import org.jboss.messaging.core.contract.PersistenceManager;
import org.jboss.messaging.core.contract.Queue;
import org.jboss.messaging.core.contract.Receiver;
import org.jboss.messaging.core.impl.clusterconnection.MessageSucker;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
import org.jboss.util.timeout.Timeout;
import org.jboss.util.timeout.TimeoutTarget;
@@ -64,7 +64,7 @@
* $Id: Queue.java 1295 2006-09-15 17:44:02Z timfox $
*
*/
-public class MessagingQueue extends PagingChannelSupport implements Queue
+public class MessagingQueue extends ChannelSupport implements Queue
{
// Constants -----------------------------------------------------
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/PagingChannelSupport.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/PagingChannelSupport.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/PagingChannelSupport.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,592 +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.messaging.core.impl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.core.contract.MessageStore;
-import org.jboss.messaging.core.contract.PersistenceManager;
-import org.jboss.messaging.core.contract.PersistenceManager.InitialLoadInfo;
-import org.jboss.messaging.core.contract.PersistenceManager.ReferenceInfo;
-
-/**
- * This channel implementation automatically pages message references to and from storage to prevent
- * more than a maximum number of references being stored in memory at once.
- *
- * This allows us to support logical channels holding many millions of messages without running out
- * of memory.
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public abstract class PagingChannelSupport extends ChannelSupport
-{
- private static final Logger log = Logger.getLogger(PagingChannelSupport.class);
-
- private boolean trace = log.isTraceEnabled();
-
- protected List downCache;
-
- /**
- * The maximum number of references this channel will hold before going into paging mode
- */
- protected int fullSize = 200000;
-
- /**
- * The maximum number of references to load from storage in one go when unpaging
- */
- protected int pageSize = 2000;
-
- /**
- * The maximum number of references paged to storage in one operation
- */
- protected int downCacheSize = 2000;
-
- /**
- * Are we in paging mode?
- */
- protected boolean paging;
-
- /**
- * The page order value for the first reference paged in storage
- */
- protected long firstPagingOrder;
-
- /**
- * The value of page order for the next reference to page
- */
- protected long nextPagingOrder;
-
- protected MessageStore ms;
-
- /**
- * Constructor with default paging params.
- */
- public PagingChannelSupport(long channelID, MessageStore ms, PersistenceManager pm,
- boolean recoverable, int maxSize)
- {
- super(channelID, pm, recoverable, maxSize);
-
- downCache = new ArrayList(downCacheSize);
-
- this.ms = ms;
- }
-
- /**
- * Constructor specifying paging params.
- */
- public PagingChannelSupport(long channelID, MessageStore ms, PersistenceManager pm,
- boolean recoverable, int maxSize,
- int fullSize, int pageSize, int downCacheSize)
- {
- super(channelID, pm, recoverable, maxSize);
-
- if (pageSize >= fullSize)
- {
- throw new IllegalArgumentException("pageSize must be less than full size " + pageSize + ", " + fullSize);
- }
- if (downCacheSize > pageSize)
- {
- throw new IllegalArgumentException("pageSize cannot be smaller than downCacheSize");
- }
- if (pageSize <= 0)
- {
- throw new IllegalArgumentException("pageSize must be greater than zero");
- }
- if (downCacheSize <= 0)
- {
- throw new IllegalArgumentException("downCacheSize must be greater than zero");
- }
-
- downCache = new ArrayList(downCacheSize);
-
- this.fullSize = fullSize;
-
- this.pageSize = pageSize;
-
- this.downCacheSize = downCacheSize;
-
- this.ms = ms;
- }
-
- // Receiver implementation ----------------------------------------------------------------------
-
- // Channel implementation -----------------------------------------------------------------------
-
- public int getMessageCount()
- {
- int count = super.getMessageCount();
-
- // Also need to add the paged refs
-
- synchronized (lock)
- {
- count += nextPagingOrder - firstPagingOrder;
- }
-
- return count;
- }
-
- // Public ---------------------------------------------------------------------------------------
-
- //Only used in testing
- public int downCacheCount()
- {
- synchronized (lock)
- {
- return downCache.size();
- }
- }
-
- //Only used in testing
- public boolean isPaging()
- {
- synchronized (lock)
- {
- return paging;
- }
- }
-
- public void setPagingParams(int fullSize, int pageSize, int downCacheSize)
- {
- synchronized (lock)
- {
- if (active)
- {
- throw new IllegalStateException("Cannot set paging params when active");
- }
-
- this.fullSize = fullSize;
-
- this.pageSize = pageSize;
-
- this.downCacheSize = downCacheSize;
- }
- }
-
- public void load() throws Exception
- {
- synchronized (lock)
- {
- if (active)
- {
- throw new IllegalStateException("Cannot load channel when active");
- }
-
- if (trace) { log.trace(this + " loading channel state"); }
-
- unload();
-
- //Load the unpaged references
- InitialLoadInfo ili = pm.loadFromStart(channelID, fullSize);
-
- doLoad(ili);
-
- //Maybe we need to load some paged refs too since we might not be full (fullSize might have been increased from last
- //load)
-
- while (checkLoad()) {}
- }
- }
-
- public void unload() throws Exception
- {
- synchronized (lock)
- {
- if (active)
- {
- throw new IllegalStateException("Cannot unload channel when active");
- }
-
- messageRefs.clear();
-
- downCache.clear();
-
- paging = false;
-
- firstPagingOrder = nextPagingOrder = 0;
-
- clearAllScheduledDeliveries();
- }
- }
-
-
- // Protected ------------------------------------------------------------------------------------
-
- protected void loadPagedReferences(int number) throws Exception
- {
- if (trace) { log.trace(this + " Loading " + number + " paged references from storage"); }
-
- // Must flush the down cache first
- flushDownCache();
-
- List refInfos = pm.getPagedReferenceInfos(channelID, firstPagingOrder, number);
-
- Map refMap = processReferences(refInfos);
-
- boolean loadedReliable = false;
-
- List toRemove = new ArrayList();
-
- int unreliableNumber = 0;
-
- Iterator iter = refInfos.iterator();
- while (iter.hasNext())
- {
- ReferenceInfo info = (ReferenceInfo)iter.next();
-
- MessageReference ref = addFromRefInfo(info, refMap);
-
- if (recoverable && ref.getMessage().isReliable())
- {
- loadedReliable = true;
- }
- else
- {
- // We put the non reliable refs (or reliable in a non-recoverable store)
- // in a list to be removed
- toRemove.add(ref);
-
- unreliableNumber++;
- }
- }
-
- if (!toRemove.isEmpty())
- {
- // Now we remove the references we loaded (only the non persistent or persistent in a non-recoverable store)
- if (trace) { log.trace(this + " removing depaged refs " + toRemove.size()); }
-
- pm.removeDepagedReferences(channelID, toRemove);
- }
-
- if (loadedReliable)
- {
- // If we loaded any reliable refs then we must set the page ordering to null in
- // the store otherwise they may get loaded again, the next time we do a load
- // We can't delete them since they're reliable and haven't been acked yet
-
- if (trace) { log.trace("Updating refs not paged"); }
-
- pm.updateReferencesNotPagedInRange(channelID, firstPagingOrder, firstPagingOrder + number - 1, number - unreliableNumber);
- }
-
- firstPagingOrder += number;
-
- if (trace) { log.trace(this + " set firstPagingOrder to " + firstPagingOrder); }
-
- if (firstPagingOrder == nextPagingOrder)
- {
- //No more refs in storage
- firstPagingOrder = nextPagingOrder = 0;
-
- if (messageRefs.size() != fullSize)
- {
- paging = false;
- }
- }
- }
-
- protected void cancelInternal(MessageReference ref) throws Exception
- {
- synchronized (lock)
- {
- super.cancelInternal(ref);
-
- if (paging)
- {
- // if paging and the in memory queue is exactly full we need to evict the end reference to storage to
- // preserve the number of refs in the queue
- if (messageRefs.size() == fullSize + 1)
- {
- MessageReference refCancel = (MessageReference)messageRefs.removeLast();
-
- addToDownCache(refCancel, true);
- }
- }
-
- if (trace) { log.trace(this + " added " + ref + " back into state"); }
- }
- }
-
- protected MessageReference removeFirstInMemory() throws Exception
- {
- MessageReference result = super.removeFirstInMemory();
-
- checkLoad();
-
- return result;
- }
-
- private boolean checkLoad() throws Exception
- {
- long refNum = nextPagingOrder - firstPagingOrder;
-
- if (refNum > 0)
- {
- int numberLoadable = (int)Math.min(refNum, pageSize);
-
- if (messageRefs.size() <= fullSize - numberLoadable)
- {
- //This will flush the down cache too
- loadPagedReferences(numberLoadable);
-
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- paging = false;
-
- return false;
- }
- }
-
- protected void addReferenceInMemory(MessageReference ref) throws Exception
- {
- if (paging)
- {
- addToDownCache(ref, false);
- }
- else
- {
- super.addReferenceInMemory(ref);
-
- if (messageRefs.size() == fullSize)
- {
- // We are full in memory - go into paging mode
- if (trace) { log.trace(this + " going into paging mode"); }
-
- paging = true;
- }
- }
- }
-
- protected void addToDownCache(MessageReference ref, boolean cancelling) throws Exception
- {
- // If the down cache exists then refs are not spilled over immediately,
- // but store in the cache and spilled over in one go when the next load is requested,
- // or when it is full
-
- // Both non reliable and reliable references can go in the down cache,
- // however only non-reliable
- // references actually get added to storage, reliable references instead
- // just get their page ordering column updated since they will already be in storage
-
- //If cancelling then the ref is supposed to go back on the front of the queue segment in storage
- //so we set the page ordering to be firstPageOrdering - 1
- //If not cancelling, then the ref should go on the end of the queue in storage so
- //we set the page ordering to be nextPageOrdering
-
- if (cancelling)
- {
- ref.setPagingOrder(firstPagingOrder - 1);
-
- firstPagingOrder--;
- }
- else
- {
- ref.setPagingOrder(nextPagingOrder);
-
- nextPagingOrder++;
- }
-
- downCache.add(ref);
-
- if (trace) { log.trace(ref + " sent to downcache"); }
-
- if (downCache.size() == downCacheSize)
- {
- if (trace) { log.trace(this + "'s downcache is full (" + downCache.size() + " messages)"); }
-
- flushDownCache();
- }
- }
-
- protected void flushDownCache() throws Exception
- {
- if (trace) { log.trace(this + " flushing " + downCache.size() + " refs from downcache"); }
-
- // Non persistent refs won't already be in the db so they need to be inserted
- // Persistent refs in a recoverable state will already be there so need to be updated
-
- List toUpdate = new ArrayList();
-
- List toAdd = new ArrayList();
-
- Iterator iter = downCache.iterator();
-
- while (iter.hasNext())
- {
- MessageReference ref = (MessageReference) iter.next();
-
- if (ref.getMessage().isReliable() && recoverable)
- {
- toUpdate.add(ref);
- }
- else
- {
- toAdd.add(ref);
- }
- }
-
- if (!toAdd.isEmpty())
- {
- pm.pageReferences(channelID, toAdd, true);
- }
-
- if (!toUpdate.isEmpty())
- {
- pm.updatePageOrder(channelID, toUpdate);
- }
-
- downCache.clear();
-
- if (trace) { log.trace(this + " cleared downcache"); }
- }
-
-
-
- protected void doLoad(InitialLoadInfo ili) throws Exception
- {
- if (ili.getMaxPageOrdering() != null)
- {
- firstPagingOrder = ili.getMinPageOrdering().longValue();
-
- nextPagingOrder = ili.getMaxPageOrdering().longValue() + 1;
-
- paging = true;
- }
- else
- {
- firstPagingOrder = nextPagingOrder = 0;
-
- paging = false;
- }
-
- Map refMap = processReferences(ili.getRefInfos());
-
- Iterator iter = ili.getRefInfos().iterator();
- while (iter.hasNext())
- {
- ReferenceInfo info = (ReferenceInfo)iter.next();
-
- addFromRefInfo(info, refMap);
- }
- }
-
- // Private --------------------------------------------------------------------------------------
-
- protected MessageReference addFromRefInfo(ReferenceInfo info, Map refMap)
- {
- long msgId = info.getMessageId();
-
- MessageReference ref = (MessageReference)refMap.get(new Long(msgId));
-
- ref.setDeliveryCount(info.getDeliveryCount());
-
- ref.setPagingOrder(-1);
-
- ref.setScheduledDeliveryTime(info.getScheduledDelivery());
-
- //Schedule the delivery if necessary, or just add to the in memory queue
- if (!checkAndSchedule(ref))
- {
- messageRefs.addLast(ref, ref.getMessage().getPriority());
- }
-
- return ref;
- }
-
-
- protected Map processReferences(List refInfos) throws Exception
- {
- Map<Long, MessageReference> refMap = new HashMap<Long, MessageReference>(refInfos.size());
-
- List<Long> msgIdsToLoad = new ArrayList<Long>(refInfos.size());
-
- Iterator iter = refInfos.iterator();
-
- // Put the refs that we already have messages for in a map
- while (iter.hasNext())
- {
- ReferenceInfo info = (ReferenceInfo) iter.next();
-
- long msgId = info.getMessageId();
-
- MessageReference ref = ms.reference(msgId);
-
- if (ref != null)
- {
- refMap.put(msgId, ref);
- }
- else
- {
- // Add id to list of msg ids to load
- msgIdsToLoad.add(msgId);
- }
- }
-
- // Load the messages (if any)
- List messages = null;
- if (!msgIdsToLoad.isEmpty())
- {
- messages = pm.getMessages(msgIdsToLoad);
-
- if (messages.size() != msgIdsToLoad.size())
- {
- // Sanity check
-
- throw new IllegalStateException("Did not load correct number of messages, wanted:" +
- msgIdsToLoad.size() + " but got:" +
- messages.size());
- }
-
- // Create references for these messages and add them to the reference map
- iter = messages.iterator();
-
- while (iter.hasNext())
- {
- Message m = (Message)iter.next();
-
- MessageReference ref = ms.reference(m);
-
- refMap.put(new Long(m.getMessageID()), ref);
- }
- }
-
- return refMap;
- }
-
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/RoundRobinDistributor.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/RoundRobinDistributor.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/RoundRobinDistributor.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -28,9 +28,9 @@
import org.jboss.messaging.core.contract.Delivery;
import org.jboss.messaging.core.contract.DeliveryObserver;
import org.jboss.messaging.core.contract.Distributor;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.Receiver;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.MessageReference;
/**
*
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/SimpleDelivery.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/SimpleDelivery.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/SimpleDelivery.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,8 +24,8 @@
import org.jboss.logging.Logger;
import org.jboss.messaging.core.contract.Delivery;
import org.jboss.messaging.core.contract.DeliveryObserver;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.MessageReference;
/**
* A simple Delivery implementation.
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/clusterconnection/MessageSucker.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/clusterconnection/MessageSucker.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/clusterconnection/MessageSucker.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -319,17 +319,17 @@
}
*/
- org.jboss.messaging.core.contract.Message coreMessage = ((MessageProxy)msg).getMessage();
+ org.jboss.messaging.newcore.intf.Message coreMessage = ((MessageProxy)msg).getMessage();
if (preserveOrdering)
{
//Add a header saying we have sucked the message
- coreMessage.putHeader(org.jboss.messaging.core.contract.Message.CLUSTER_SUCKED, "x");
+ coreMessage.putHeader(org.jboss.messaging.newcore.intf.Message.CLUSTER_SUCKED, "x");
}
//Add a header with the node id of the node we sucked from - this is used on the sending end to do
//the move optimisation
- coreMessage.putHeader(org.jboss.messaging.core.contract.Message.SOURCE_CHANNEL_ID, sourceChannelID);
+ coreMessage.putHeader(org.jboss.messaging.newcore.intf.Message.SOURCE_CHANNEL_ID, sourceChannelID);
long timeToLive = msg.getJMSExpiration();
if (timeToLive != 0)
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/CoreMessage.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/CoreMessage.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/CoreMessage.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,83 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.impl.message;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 2202 $</tt>
- *
- * $Id: CoreMessage.java 2202 2007-02-08 10:50:26Z timfox $
- */
-public class CoreMessage extends MessageSupport
-{
- // Constants -----------------------------------------------------
-
- private static final long serialVersionUID = -4740357138097778538L;
-
- public static final byte TYPE = 127;
-
- // Attributes ----------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- /**
- * Required by externalization.
- */
- public CoreMessage()
- {
- }
-
- public CoreMessage(long messageID,
- boolean reliable,
- long expiration,
- long timestamp,
- byte priority,
- Map headers,
- byte[] payload)
- {
- super(messageID, reliable, expiration, timestamp, priority, headers, payload);
- }
-
- // Public --------------------------------------------------------
-
- public String toString()
- {
- return "CoreMessage["+messageID+"]";
- }
-
- public byte getType()
- {
- return TYPE;
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/MessageFactory.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/MessageFactory.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/MessageFactory.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,171 +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.messaging.core.impl.message;
-
-import java.util.Map;
-
-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.contract.Message;
-
-/**
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 2284 $</tt>
- *
- * $Id: MessageFactory.java 2284 2007-02-13 06:47:23Z ovidiu.feodorov at jboss.com $
- */
-public class MessageFactory
-{
- // Constants ------------------------------------------------------------------------------------
-
- // Static ---------------------------------------------------------------------------------------
-
- public static Message createMessage(byte type)
- {
- Message m = null;
-
- if (type == JBossMessage.TYPE) //1
- {
- m = new JBossMessage();
- }
- else if (type == JBossObjectMessage.TYPE) //2
- {
- m = new JBossObjectMessage();
- }
- else if (type == JBossTextMessage.TYPE) //3
- {
- m = new JBossTextMessage();
- }
- else if (type == JBossBytesMessage.TYPE) //4
- {
- m = new JBossBytesMessage();
- }
- else if (type == JBossMapMessage.TYPE) //5
- {
- m = new JBossMapMessage();
- }
- else if (type == JBossStreamMessage.TYPE) //6
- {
- m = new JBossStreamMessage();
- }
- else if (type == CoreMessage.TYPE) //127
- {
- m = new CoreMessage();
- }
- else
- {
- throw new IllegalArgumentException("Invalid type " + type);
- }
-
- return m;
- }
-
- /*
- * Create a message from persistent storage
- */
- public static Message createMessage(long messageID,
- boolean reliable,
- long expiration,
- long timestamp,
- byte priority,
- Map headers,
- byte[] payload,
- byte type)
-
- {
- Message m = null;
-
- switch (type)
- {
- case JBossMessage.TYPE:
- {
- m = new JBossMessage(messageID, reliable, expiration,
- timestamp, priority, headers, payload);
- break;
- }
- case JBossObjectMessage.TYPE:
- {
- m = new JBossObjectMessage(messageID, reliable, expiration,
- timestamp, priority, headers, payload);
- break;
- }
- case JBossTextMessage.TYPE:
- {
- m = new JBossTextMessage(messageID, reliable, expiration,
- timestamp, priority, headers, payload);
- break;
- }
- case JBossBytesMessage.TYPE:
- {
- m = new JBossBytesMessage(messageID, reliable, expiration,
- timestamp, priority, headers, payload);
- break;
- }
- case JBossMapMessage.TYPE:
- {
- m = new JBossMapMessage(messageID, reliable, expiration,
- timestamp, priority, headers, payload);
- break;
- }
- case JBossStreamMessage.TYPE:
- {
- m = new JBossStreamMessage(messageID, reliable, expiration,
- timestamp, priority, headers, payload);
- break;
- }
- case CoreMessage.TYPE:
- {
- m = new CoreMessage(messageID, reliable, expiration,
- timestamp, priority, headers, payload);
- break;
- }
- default:
- {
- throw new IllegalArgumentException("Unknown type " + type);
- }
- }
-
- m.setPersisted(true);
-
- return m;
- }
-
- // Attributes -----------------------------------------------------------------------------------
-
- // Constructors ---------------------------------------------------------------------------------
-
- // Public ---------------------------------------------------------------------------------------
-
- // Package protected ----------------------------------------------------------------------------
-
- // Protected ------------------------------------------------------------------------------------
-
- // Private --------------------------------------------------------------------------------------
-
- // Inner classes --------------------------------------------------------------------------------
-}
-
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/MessageSupport.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/MessageSupport.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/MessageSupport.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,404 +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.messaging.core.impl.message;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import java.io.IOException;
-
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.util.StreamUtils;
-
-/**
- * A message base.
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 2740 $</tt>
- *
- * Note this class is only serializable so messages can be returned from JMX operations
- * e.g. listAllMessages.
- *
- * For normal message transportation serialization is not used
- *
- * $Id: MessageSupport.java 2740 2007-05-30 11:36:28Z timfox $
- */
-public abstract class MessageSupport implements Message, Serializable
-{
- // Constants -----------------------------------------------------
-
- private static final Logger log = Logger.getLogger(MessageSupport.class);
-
- // Attributes ----------------------------------------------------
-
- private boolean trace = log.isTraceEnabled();
-
- protected long messageID;
-
- protected boolean reliable;
-
- /** GMT milliseconds at which this message expires. 0 means never expires * */
- protected long expiration;
-
- protected long timestamp;
-
- protected Map headers;
-
- protected byte priority;
-
- protected transient Object payload;
-
- protected byte[] payloadAsByteArray;
-
- private transient volatile boolean persisted;
-
- // Constructors --------------------------------------------------
-
- /*
- * Construct a message for deserialization or streaming
- */
- public MessageSupport()
- {
- }
-
- /*
- * Construct a message using default values
- */
- public MessageSupport(long messageID)
- {
- this(messageID, false, 0, System.currentTimeMillis(), (byte) 4, null,
- null);
- }
-
- /*
- * Construct a message using specified values
- */
- public MessageSupport(long messageID, boolean reliable, long expiration,
- long timestamp, byte priority, Map headers, byte[] payloadAsByteArray)
- {
- this.messageID = messageID;
- this.reliable = reliable;
- this.expiration = expiration;
- this.timestamp = timestamp;
- this.priority = priority;
- if (headers == null)
- {
- this.headers = new HashMap();
- }
- else
- {
- this.headers = new HashMap(headers);
- }
-
- this.payloadAsByteArray = payloadAsByteArray;
- }
-
- /*
- * Copy constructor
- *
- * Does a shallow copy of the payload
- */
- protected MessageSupport(MessageSupport that)
- {
- this.messageID = that.messageID;
- this.reliable = that.reliable;
- this.expiration = that.expiration;
- this.timestamp = that.timestamp;
- this.headers = new HashMap(that.headers);
- this.priority = that.priority;
- this.payload = that.payload;
- this.payloadAsByteArray = that.payloadAsByteArray;
- }
-
- // Message implementation ----------------------------------------
-
- public long getMessageID()
- {
- return messageID;
- }
-
- public boolean isReliable()
- {
- return reliable;
- }
-
- public long getExpiration()
- {
- return expiration;
- }
-
- public void setExpiration(long expiration)
- {
- this.expiration = expiration;
- }
-
- public long getTimestamp()
- {
- return timestamp;
- }
-
- public Object putHeader(String name, Object value)
- {
- return headers.put(name, value);
- }
-
- public Object getHeader(String name)
- {
- return headers.get(name);
- }
-
- public Object removeHeader(String name)
- {
- return headers.remove(name);
- }
-
- public boolean containsHeader(String name)
- {
- return headers.containsKey(name);
- }
-
- public Map getHeaders()
- {
- return headers;
- }
-
- public byte getPriority()
- {
- return priority;
- }
-
- public void setPriority(byte priority)
- {
- this.priority = priority;
- }
-
- public boolean isReference()
- {
- return false;
- }
-
- public synchronized byte[] getPayloadAsByteArray()
- {
- if (payloadAsByteArray == null && payload != null)
- {
- final int BUFFER_SIZE = 2048;
-
- try
- {
- ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE);
- DataOutputStream daos = new DataOutputStream(bos);
- doWriteObject(daos, payload);
- daos.close();
- payloadAsByteArray = bos.toByteArray();
-
- //Note we set payload to null - if we didn't then we'd end up with the message stored in memory twice -
- //once as the payload, once as the byte[] - this means it would take up twice the RAM
- payload = null;
- }
- catch (Exception e)
- {
- RuntimeException e2 = new RuntimeException(e.getMessage());
- e2.setStackTrace(e.getStackTrace());
- throw e2;
- }
- }
- return payloadAsByteArray;
- }
-
- public synchronized Object getPayload()
- {
- if (payload != null)
- {
- return payload;
- }
- else if (payloadAsByteArray != null)
- {
- ByteArrayInputStream bis = new ByteArrayInputStream(payloadAsByteArray);
- DataInputStream dis = new DataInputStream(bis);
- try
- {
- payload = StreamUtils.readObject(dis, true);
- }
- catch (Exception e)
- {
- RuntimeException e2 = new RuntimeException(e.getMessage());
- e2.setStackTrace(e.getStackTrace());
- throw e2;
- }
-
- payloadAsByteArray = null;
-
- return payload;
- }
- else
- {
- return null;
- }
- }
-
- public void setPayload(Object payload)
- {
- this.payload = payload;
- }
-
- public boolean isExpired()
- {
- if (expiration == 0)
- {
- return false;
- }
- long overtime = System.currentTimeMillis() - expiration;
- if (overtime >= 0)
- {
- // discard it
- if (trace)
- {
- log.trace(this + " expired by " + overtime + " ms");
- }
-
- return true;
- }
- return false;
- }
-
- public MessageReference createReference()
- {
- return new SimpleMessageReference(this);
- }
-
- public boolean isPersisted()
- {
- return persisted;
- }
-
- public void setPersisted(boolean persisted)
- {
- this.persisted = persisted;
- }
-
- // Public --------------------------------------------------------
-
- public boolean equals(Object o)
- {
- if (this == o)
- {
- return true;
- }
- if (!(o instanceof MessageSupport))
- {
- return false;
- }
- MessageSupport that = (MessageSupport) o;
- return that.messageID == this.messageID;
- }
-
- public int hashCode()
- {
- return (int) ((this.messageID >>> 32) ^ this.messageID);
- }
-
- public String toString()
- {
- return "M[" + messageID + "]";
- }
-
- // Streamable implementation ---------------------------------
-
- public void write(DataOutputStream out) throws Exception
- {
- out.writeLong(messageID);
-
- out.writeBoolean(reliable);
-
- out.writeLong(expiration);
-
- out.writeLong(timestamp);
-
- StreamUtils.writeMap(out, headers, true);
-
- out.writeByte(priority);
-
- byte[] bytes = getPayloadAsByteArray();
-
- if (bytes != null)
- {
- out.writeInt(bytes.length);
-
- out.write(bytes);
- }
- else
- {
- out.writeInt(0);
- }
- }
-
- public void read(DataInputStream in) throws Exception
- {
- messageID = in.readLong();
-
- reliable = in.readBoolean();
-
- expiration = in.readLong();
-
- timestamp = in.readLong();
-
- headers = StreamUtils.readMap(in, true);
-
- priority = in.readByte();
-
- int length = in.readInt();
-
- if (length == 0)
- {
- // no payload
- payloadAsByteArray = null;
- }
- else
- {
- payloadAsByteArray = new byte[length];
-
- in.readFully(payloadAsByteArray);
- }
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Certain MessageTypes will need different behaviors. For example ObjectMessages won't use container types
- protected void doWriteObject(DataOutputStream out, Object payload) throws IOException
- {
- StreamUtils.writeObject(out, payload, true, true);
- }
-
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/SimpleMessageReference.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/SimpleMessageReference.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/SimpleMessageReference.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,138 +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.messaging.core.impl.message;
-
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
-
-/**
- * A Simple MessageReference implementation.
- *
- * Note that we do not need WeakReferences to message/holder objects since with the new
- * lazy loading schema we guarantee that if a message ref is in memory - it's corresponding message is
- * in memory too
- *
- * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
- * @version <tt>1.3</tt>
- *
- * SimpleMessageReference.java,v 1.3 2006/02/23 17:45:57 timfox Exp
- */
-public class SimpleMessageReference implements MessageReference
-{
- private static final Logger log = Logger.getLogger(SimpleMessageReference.class);
-
- // Attributes ----------------------------------------------------
-
- private boolean trace = log.isTraceEnabled();
-
- private long pagingOrder = -1;
-
- private int deliveryCount;
-
- private long scheduledDeliveryTime;
-
- private Message message;
-
- // Constructors --------------------------------------------------
-
- /**
- * Required by externalization.
- */
- public SimpleMessageReference()
- {
- if (trace) { log.trace("Creating using default constructor"); }
- }
-
- public SimpleMessageReference(SimpleMessageReference other)
- {
- this.pagingOrder = other.pagingOrder;
-
- this.deliveryCount = other.deliveryCount;
-
- this.scheduledDeliveryTime = other.scheduledDeliveryTime;
-
- this.message = other.message;
- }
-
- protected SimpleMessageReference(Message message)
- {
- this.message = message;
- }
-
- // MessageReference implementation -------------------------------
-
- public MessageReference copy()
- {
- return new SimpleMessageReference(this);
- }
-
- public int getDeliveryCount()
- {
- return deliveryCount;
- }
-
- public void setDeliveryCount(int deliveryCount)
- {
- this.deliveryCount = deliveryCount;
- }
-
- public long getScheduledDeliveryTime()
- {
- return scheduledDeliveryTime;
- }
-
- public void setScheduledDeliveryTime(long scheduledDeliveryTime)
- {
- this.scheduledDeliveryTime = scheduledDeliveryTime;
- }
-
- public Message getMessage()
- {
- return message;
- }
-
- public long getPagingOrder()
- {
- return pagingOrder;
- }
-
- public void setPagingOrder(long order)
- {
- this.pagingOrder = order;
- }
-
- // Public --------------------------------------------------------
-
- public String toString()
- {
- return "Reference[" + getMessage().getMessageID() + "]:" + (getMessage().isReliable() ? "RELIABLE" : "NON-RELIABLE");
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
\ No newline at end of file
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/SimpleMessageStore.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/SimpleMessageStore.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/SimpleMessageStore.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -25,9 +25,9 @@
import java.util.WeakHashMap;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.MessageStore;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
/**
* A MessageStore implementation.
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageHolder.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageHolder.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageHolder.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -25,11 +25,12 @@
import java.io.DataOutputStream;
import java.util.Map;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.impl.message.MessageFactory;
+import org.jboss.messaging.newcore.intf.Message;
import org.jboss.messaging.util.StreamUtils;
import org.jboss.messaging.util.Streamable;
+import org.jboss.messaging.core.impl.message.CoreMessage;
+
/**
* A MessageHolder
*
@@ -81,7 +82,7 @@
byte type = in.readByte();
- message = MessageFactory.createMessage(type);
+ message = new MessageImpl();
message.read(in);
queueNameToNodeIdMap = (Map)StreamUtils.readObject(in, false);
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageRequest.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageRequest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageRequest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -27,8 +27,8 @@
import java.util.Iterator;
import java.util.Set;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.impl.message.MessageFactory;
+import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.intf.Message;
/**
* A MessageRequest
@@ -78,10 +78,8 @@
{
routingConditionText = in.readUTF();
- byte type = in.readByte();
+ message = new MessageImpl();
- message = MessageFactory.createMessage(type);
-
message.read(in);
byte b = in.readByte();
@@ -105,8 +103,6 @@
{
out.writeUTF(routingConditionText);
- out.writeByte(message.getType());
-
message.write(out);
if (queueNames == null)
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -60,10 +60,7 @@
import org.jboss.messaging.core.contract.Delivery;
import org.jboss.messaging.core.contract.Filter;
import org.jboss.messaging.core.contract.FilterFactory;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.MessageStore;
-import org.jboss.messaging.core.contract.MessagingComponent;
import org.jboss.messaging.core.contract.PersistenceManager;
import org.jboss.messaging.core.contract.PostOffice;
import org.jboss.messaging.core.contract.Queue;
@@ -74,6 +71,9 @@
import org.jboss.messaging.core.impl.tx.Transaction;
import org.jboss.messaging.core.impl.tx.TransactionRepository;
import org.jboss.messaging.core.impl.tx.TxCallback;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import org.jboss.messaging.util.ClearableSemaphore;
import org.jboss.messaging.util.ConcurrentHashSet;
import org.jboss.messaging.util.StreamUtils;
@@ -1538,7 +1538,7 @@
// out.println("<tr><td>Reference#</td><td>Message</td></tr>");
// for (Iterator i = undelivered.iterator();i.hasNext();)
// {
-// SimpleMessageReference reference = (SimpleMessageReference)i.next();
+// MessageReferenceImpl reference = (MessageReferenceImpl)i.next();
// out.println("<tr><td>" + reference.getInMemoryChannelCount() +
// "</td><td>" + reference.getMessage() +"</td></tr>");
// }
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/RequestTarget.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/RequestTarget.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/RequestTarget.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -25,7 +25,7 @@
import java.util.Map;
import java.util.Set;
-import org.jboss.messaging.core.contract.Message;
+import org.jboss.messaging.newcore.intf.Message;
import org.jgroups.Address;
/**
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -31,15 +31,15 @@
import org.jboss.logging.Logger;
import org.jboss.messaging.core.contract.Binding;
import org.jboss.messaging.core.contract.Delivery;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.MessageStore;
-import org.jboss.messaging.core.contract.MessagingComponent;
import org.jboss.messaging.core.contract.PersistenceManager;
import org.jboss.messaging.core.contract.PostOffice;
import org.jboss.messaging.core.contract.Queue;
import org.jboss.messaging.core.impl.IDManager;
import org.jboss.messaging.core.impl.SimpleDelivery;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/jmx/JDBCPersistenceManagerService.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/jmx/JDBCPersistenceManagerService.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/jmx/JDBCPersistenceManagerService.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,177 +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.messaging.core.jmx;
-
-import javax.transaction.TransactionManager;
-
-import org.jboss.messaging.core.contract.MessagingComponent;
-import org.jboss.messaging.core.contract.PersistenceManager;
-import org.jboss.messaging.core.impl.JDBCPersistenceManager;
-import org.jboss.messaging.util.ExceptionUtil;
-
-/**
- * A JDBCPersistenceManagerService
- *
- * MBean wrapper around a JDBCPersistenceManager
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 2684 $</tt>
- *
- * $Id: JDBCPersistenceManagerService.java 2684 2007-05-15 07:31:30Z timfox $
- *
- */
-public class JDBCPersistenceManagerService extends JDBCServiceSupport
-{
- private PersistenceManager persistenceManager;
-
- private boolean started;
-
- private boolean usingBatchUpdates;
-
- private boolean usingBinaryStream = true;
-
- private boolean usingTrailingByte;
-
- private int maxParams = 100;
-
- private boolean supportsBlobOnSelect = true;
-
- // Constructors --------------------------------------------------------
-
- public JDBCPersistenceManagerService()
- {
- }
-
- // ServerPlugin implementation ------------------------------------------
-
- public MessagingComponent getInstance()
- {
- return persistenceManager;
- }
-
- // ServiceMBeanSupport overrides -----------------------------------------
-
- protected synchronized void startService() throws Exception
- {
- if (started)
- {
- throw new IllegalStateException("Service is already started");
- }
-
- super.startService();
-
- try
- {
- TransactionManager tm = getTransactionManagerReference();
-
- persistenceManager =
- new JDBCPersistenceManager(ds, tm, sqlProperties,
- createTablesOnStartup, usingBatchUpdates,
- usingBinaryStream, usingTrailingByte, maxParams,
- supportsBlobOnSelect);
-
- persistenceManager.start();
-
- started = true;
- }
- catch (Throwable t)
- {
- throw ExceptionUtil.handleJMXInvocation(t, this + " startService");
- }
- }
-
- protected void stopService() throws Exception
- {
- if (!started)
- {
- throw new IllegalStateException("Service is not started");
- }
-
- try
- {
- persistenceManager.stop();
-
- persistenceManager = null;
-
- started = false;
- }
- catch (Throwable t)
- {
- throw ExceptionUtil.handleJMXInvocation(t, this + " startService");
- }
-
- log.debug(this + " stopped");
- }
-
- // MBean attributes -------------------------------------------------------
-
- public boolean isUsingBatchUpdates()
- {
- return usingBatchUpdates;
- }
-
- public void setUsingBatchUpdates(boolean b)
- {
- usingBatchUpdates = b;
- }
-
- public int getMaxParams()
- {
- return maxParams;
- }
-
- public void setMaxParams(int maxParams)
- {
- this.maxParams = maxParams;
- }
-
- public boolean isUsingBinaryStream()
- {
- return usingBinaryStream;
- }
-
- public void setUsingBinaryStream(boolean b)
- {
- usingBinaryStream = b;
- }
-
- public boolean isUsingTrailingByte()
- {
- return usingTrailingByte;
- }
-
- public void setUsingTrailingByte(boolean b)
- {
- usingTrailingByte = b;
- }
-
- public boolean isSupportsBlobOnSelect()
- {
- return supportsBlobOnSelect;
- }
-
- public void setSupportsBlobOnSelect(boolean b)
- {
- this.supportsBlobOnSelect = b;
- }
-
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/jmx/MessagingPostOfficeService.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/jmx/MessagingPostOfficeService.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/jmx/MessagingPostOfficeService.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -38,13 +38,13 @@
import org.jboss.messaging.core.contract.FilterFactory;
import org.jboss.messaging.core.contract.ChannelFactory;
import org.jboss.messaging.core.contract.MessageStore;
-import org.jboss.messaging.core.contract.MessagingComponent;
import org.jboss.messaging.core.contract.PersistenceManager;
import org.jboss.messaging.core.impl.IDManager;
import org.jboss.messaging.core.impl.jchannelfactory.MultiplexerChannelFactory;
import org.jboss.messaging.core.impl.jchannelfactory.XMLChannelFactory;
import org.jboss.messaging.core.impl.postoffice.MessagingPostOffice;
import org.jboss.messaging.core.impl.tx.TransactionRepository;
+import org.jboss.messaging.newcore.intf.MessagingComponent;
import org.jboss.messaging.util.ExceptionUtil;
import org.jboss.messaging.util.JMXAccessor;
import org.w3c.dom.Element;
Added: branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Message.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Message.java (rev 0)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Message.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -0,0 +1,233 @@
+/*
+ * 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.messaging.newcore.intf;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.messaging.util.Streamable;
+
+/**
+ * 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>
+ * @author <a href="mailto:tim.fox"jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 3341 $</tt>
+ *
+ * $Id: Message.java 3341 2007-11-19 14:34:57Z timfox $
+ */
+public interface Message extends Streamable
+{
+ /**
+ * 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
+ */
+ long getMessageID();
+
+ /**
+ * Set the message id
+ *
+ * @param id
+ */
+ void setMessageID(long id);
+
+ /**
+ * Get the destination
+ * @return
+ */
+ String getDestination();
+
+ /**
+ * Set the destination
+ * @param destination
+ */
+ void setDestination(String destination);
+
+ /**
+ * @return true if the delivery must be guaranteed for this routable, false otherwise.
+ */
+ boolean isReliable();
+
+ /**
+ * Set whether message is reliable or not
+ * @param reliable
+ */
+ void setReliable(boolean reliable);
+
+ /**
+ * @return the time when this routable expires and must be removed
+ * from the system. A zero value means this routable never expires.
+ */
+ long getExpiration();
+
+ /**
+ *
+ * @return true if the message has expired
+ */
+ boolean isExpired();
+
+ /**
+ * Set the expiration for this message
+ *
+ * @param expiration
+ */
+ void setExpiration(long expiration);
+
+ /**
+ * @return the time (in GMT milliseconds) when this routable was delivered to the provider.
+ */
+ long getTimestamp();
+
+ /**
+ * Set the timestamp for this message
+ * @param timestamp The timestamp
+ */
+ void setTimestamp(long timestamp);
+
+ /**
+ *
+ * @return The priority (0-9) of the message
+ */
+ byte getPriority();
+
+ /**
+ * Get the priority of the message. Priorities range from 0 to 9.
+ * Where 0 is the lowest priority and 9 is the highest priority
+ * @param priority
+ */
+ void setPriority(byte priority);
+
+ /**
+ * Binds a header. If the header map previously contained a mapping for this name, the old value
+ * is replaced by the specified value.
+ *
+ * @return the value associated with the name or null if there is no mapping for the name. A null
+ * can also indicate that the header map previously associated null with the specified
+ * name.
+ */
+ Object putHeader(String name, Object value);
+
+ /**
+ * Returns the value corresponding to the header name. Returns null if the map contains no
+ * mapping for the name. A return value of null does not necessarily indicate that the map
+ * contains no mapping for the name; it's also possible that the map explicitly maps the name to
+ * null. The containsHeader() operation may be used to distinguish these two cases.
+ *
+ * @return the value associated with the header, or null if there is no mapping for the header.
+ */
+ Object getHeader(String name);
+
+ /**
+ * Removes the header.
+ *
+ * @return previous value associated with the header, or null if there was no mapping.
+ */
+ Object removeHeader(String name);
+
+ /**
+ * Returns true if the Routable contains the specified header.
+ */
+ boolean containsHeader(String name);
+
+ /**
+ *
+ * @return The message's headers
+ */
+ Map<String, Object> getHeaders();
+
+ /**
+ *
+ * @return The message's payload
+ */
+ byte[] getPayload();
+
+
+ /**
+ * Set the payload
+ *
+ * @param payload
+ */
+ void setPayload(byte[] payload);
+
+ /**
+ *
+ * @return The message's headers as byte array
+ */
+ byte[] getHeadersAsByteArray() throws Exception;
+
+ /**
+ *
+ * @return the type of the message
+ */
+ int getType();
+
+ /**
+ * Get the connection id
+ * @return
+ */
+ String getConnectionID();
+
+ /**
+ * Set the connection id
+ * @param connectionID
+ */
+ void setConnectionID(String connectionID);
+
+
+ /**
+ * @return a reference for this message
+ */
+ MessageReference createReference(Queue queue);
+
+ /**
+ *
+ * @return List of persisted references for this message
+ */
+ List<MessageReference> getReferences();
+
+ /**
+ * Make a copy of the message
+ *
+ * @return The copy
+ */
+ Message copy();
+}
Added: branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/MessageReference.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/MessageReference.java (rev 0)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/MessageReference.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -0,0 +1,60 @@
+/*
+ * 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.messaging.newcore.intf;
+
+/**
+ * A reference to a message.
+ *
+ * Channels store message references rather than the messages themselves.
+ *
+ * If many channels have contain the same reference this makes a lot of sense
+ *
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 3020 $</tt>
+ *
+ * $Id: MessageReference.java 3020 2007-08-21 15:46:38Z timfox $
+ */
+public interface MessageReference
+{
+ Message getMessage();
+
+ MessageReference copy(Queue queue);
+
+ /**
+ *
+ * @return The time in the future that delivery will be delayed until, or zero if
+ * no scheduled delivery will occur
+ */
+ long getScheduledDeliveryTime();
+
+ void setScheduledDeliveryTime(long scheduledDeliveryTime);
+
+ /**
+ * @return the number of times delivery has been attempted for this routable
+ */
+ int getDeliveryCount();
+
+ void setDeliveryCount(int deliveryCount);
+
+ Queue getQueue();
+}
Added: branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/MessagingComponent.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/MessagingComponent.java (rev 0)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/MessagingComponent.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.newcore.intf;
+
+/**
+ * A MessagingComponent
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 2796 $</tt>
+ *
+ * $Id: MessagingComponent.java 2796 2007-06-25 22:24:41Z timfox $
+ *
+ */
+public interface MessagingComponent
+{
+ void start() throws Exception;
+
+ void stop() throws Exception;
+}
Deleted: branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/BasicPriorityLinkedList.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/BasicPriorityLinkedList.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/BasicPriorityLinkedList.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,306 +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.messaging.util.prioritylinkedlist;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.NoSuchElementException;
-
-import org.jboss.logging.Logger;
-
-/**
- * A basic priority linked list
- *
- * It implements this by maintaining an
- * individual LinkedList for each priority level.
- *
- * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
- * @version <tt>$Revision: 1174 $</tt>
- *
- * $Id: BasicPrioritizedDeque.java 1174 2006-08-02 14:14:32Z timfox $
- */
-public class BasicPriorityLinkedList implements PriorityLinkedList
-{
- private static final Logger log = Logger.getLogger(BasicPriorityLinkedList.class);
-
- protected LinkedList[] linkedLists;
-
- protected int priorities;
-
- protected int size;
-
- public void dump()
- {
- log.debug("Dumping " + this);
- log.debug("Size:" + size);
- log.debug("===============");
-
- for (int i = 0; i < linkedLists.length; i++)
- {
- log.debug("Priority:" + i);
- log.debug("----------------");
-
- Iterator iter = linkedLists[i].iterator();
-
- while (iter.hasNext())
- {
- log.debug("Ref: "+ iter.next());
- }
- }
- }
-
- public BasicPriorityLinkedList(int priorities)
- {
- this.priorities = priorities;
-
- initDeques();
- }
-
- public void addFirst(Object obj, int priority)
- {
- linkedLists[priority].addFirst(obj);
-
- size++;
- }
-
- public void addLast(Object obj, int priority)
- {
- linkedLists[priority].addLast(obj);
-
- size++;
- }
-
- public Object removeFirst()
- {
- Object obj = null;
-
- //Initially we are just using a simple prioritization algorithm:
- //Highest priority refs always get returned first.
- //This could cause starvation of lower priority refs.
-
- //TODO - A better prioritization algorithm
-
- for (int i = priorities - 1; i >= 0; i--)
- {
- LinkedList ll = linkedLists[i];
-
- if (!ll.isEmpty())
- {
- obj = ll.removeFirst();
- break;
- }
-
- }
-
- if (obj != null)
- {
- size--;
- }
-
- return obj;
- }
-
- public Object removeLast()
- {
- Object obj = null;
-
- //Initially we are just using a simple prioritization algorithm:
- //Lowest priority refs always get returned first.
-
- //TODO - A better prioritization algorithm
-
- for (int i = 0; i < priorities; i++)
- {
- LinkedList ll = linkedLists[i];
- if (!ll.isEmpty())
- {
- obj = ll.removeLast();
- }
- if (obj != null)
- {
- break;
- }
- }
-
- if (obj != null)
- {
- size--;
- }
-
- return obj;
- }
-
- public Object peekFirst()
- {
- Object obj = null;
-
- //Initially we are just using a simple prioritization algorithm:
- //Highest priority refs always get returned first.
- //This could cause starvation of lower priority refs.
-
- //TODO - A better prioritization algorithm
-
- for (int i = priorities - 1; i >= 0; i--)
- {
- LinkedList ll = linkedLists[i];
- if (!ll.isEmpty())
- {
- obj = ll.getFirst();
- }
- if (obj != null)
- {
- break;
- }
- }
-
- return obj;
- }
-
- public List getAll()
- {
- List all = new ArrayList();
- for (int i = priorities - 1; i >= 0; i--)
- {
- LinkedList deque = linkedLists[i];
- all.addAll(deque);
- }
- return all;
- }
-
- public void clear()
- {
- initDeques();
- }
-
- public int size()
- {
- return size;
- }
-
- public boolean isEmpty()
- {
- return size == 0;
- }
-
- public ListIterator iterator()
- {
- return new PriorityLinkedListIterator(linkedLists);
- }
-
- protected void initDeques()
- {
- linkedLists = new LinkedList[priorities];
- for (int i = 0; i < priorities; i++)
- {
- linkedLists[i] = new LinkedList();
- }
-
- size = 0;
- }
-
-
- class PriorityLinkedListIterator implements ListIterator
- {
- private LinkedList[] lists;
-
- private int index;
-
- private ListIterator currentIter;
-
- PriorityLinkedListIterator(LinkedList[] lists)
- {
- this.lists = lists;
-
- index = lists.length - 1;
-
- currentIter = lists[index].listIterator();
- }
-
- public void add(Object arg0)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean hasNext()
- {
- if (currentIter.hasNext())
- {
- return true;
- }
- while (index >= 0)
- {
- if (index == 0 || currentIter.hasNext())
- {
- break;
- }
- index--;
- currentIter = lists[index].listIterator();
- }
- return currentIter.hasNext();
- }
-
- public boolean hasPrevious()
- {
- throw new UnsupportedOperationException();
- }
-
- public Object next()
- {
- if (!hasNext())
- {
- throw new NoSuchElementException();
- }
- return currentIter.next();
- }
-
- public int nextIndex()
- {
- throw new UnsupportedOperationException();
- }
-
- public Object previous()
- {
- throw new UnsupportedOperationException();
- }
-
- public int previousIndex()
- {
- throw new UnsupportedOperationException();
- }
-
- public void remove()
- {
- currentIter.remove();
-
- size--;
- }
-
- public void set(Object obj)
- {
- throw new UnsupportedOperationException();
- }
- }
-
-}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedList.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedList.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedList.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -33,25 +33,25 @@
*
* $Id: PrioritizedDeque.java 1174 2006-08-02 14:14:32Z timfox $
*/
-public interface PriorityLinkedList
+public interface PriorityLinkedList<T>
{
- void addFirst(Object obj, int priority);
+ void addFirst(T t, int priority);
- void addLast(Object obj, int priority);
+ void addLast(T t, int priority);
- Object removeFirst();
+ T removeFirst();
- Object removeLast();
+ T removeLast();
- Object peekFirst();
+ T peekFirst();
- List getAll();
+ List<T> getAll();
void clear();
int size();
- ListIterator iterator();
+ ListIterator<T> iterator();
boolean isEmpty();
Copied: branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedListImpl.java (from rev 3351, branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/BasicPriorityLinkedList.java)
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedListImpl.java (rev 0)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/util/prioritylinkedlist/PriorityLinkedListImpl.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -0,0 +1,290 @@
+/*
+ * 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.messaging.util.prioritylinkedlist;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A priority linked list implementation
+ *
+ * It implements this by maintaining an individual LinkedList for each priority level.
+ *
+ * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
+ * @version <tt>$Revision: 1174 $</tt>
+ *
+ * $Id: BasicPrioritizedDeque.java 1174 2006-08-02 14:14:32Z timfox $
+ */
+public class PriorityLinkedListImpl<T> implements PriorityLinkedList<T>
+{
+ private static final Logger log = Logger.getLogger(PriorityLinkedListImpl.class);
+
+ private List<LinkedList<T>> linkedLists;
+
+ private int priorities;
+
+ private int size;
+
+ public PriorityLinkedListImpl(int priorities)
+ {
+ this.priorities = priorities;
+
+ initDeques();
+ }
+
+ public void addFirst(T t, int priority)
+ {
+ linkedLists.get(priority).addFirst(t);
+
+ size++;
+ }
+
+ public void addLast(T t, int priority)
+ {
+ linkedLists.get(priority).addLast(t);
+
+ size++;
+ }
+
+ public T removeFirst()
+ {
+ T t = null;
+
+ //Initially we are just using a simple prioritization algorithm:
+ //Highest priority refs always get returned first.
+ //This could cause starvation of lower priority refs.
+
+ //TODO - A better prioritization algorithm
+
+ for (int i = priorities - 1; i >= 0; i--)
+ {
+ LinkedList<T> ll = linkedLists.get(i);
+
+ if (!ll.isEmpty())
+ {
+ t = ll.removeFirst();
+ break;
+ }
+ }
+
+ if (t != null)
+ {
+ size--;
+ }
+
+ return t;
+ }
+
+ public T removeLast()
+ {
+ T t = null;
+
+ for (int i = 0; i < priorities; i++)
+ {
+ LinkedList<T> ll = linkedLists.get(i);
+ if (!ll.isEmpty())
+ {
+ t = ll.removeLast();
+ }
+ if (t != null)
+ {
+ break;
+ }
+ }
+
+ if (t != null)
+ {
+ size--;
+ }
+
+ return t;
+ }
+
+ public T peekFirst()
+ {
+ T t = null;
+
+ for (int i = priorities - 1; i >= 0; i--)
+ {
+ LinkedList<T> ll = linkedLists.get(i);
+ if (!ll.isEmpty())
+ {
+ t = ll.getFirst();
+ }
+ if (t != null)
+ {
+ break;
+ }
+ }
+
+ return t;
+ }
+
+ public List<T> getAll()
+ {
+ List<T> all = new ArrayList<T>();
+
+ for (int i = priorities - 1; i >= 0; i--)
+ {
+ LinkedList<T> deque = linkedLists.get(i);
+ all.addAll(deque);
+ }
+
+ return all;
+ }
+
+ public void clear()
+ {
+ initDeques();
+ }
+
+ public int size()
+ {
+ return size;
+ }
+
+ public boolean isEmpty()
+ {
+ return size == 0;
+ }
+
+ public ListIterator<T> iterator()
+ {
+ return new PriorityLinkedListIterator();
+ }
+
+ public void dump()
+ {
+ log.debug("Dumping " + this);
+ log.debug("Size:" + size);
+ log.debug("===============");
+
+ for (int i = 0; i < linkedLists.size(); i++)
+ {
+ log.debug("Priority:" + i);
+ log.debug("----------------");
+
+ Iterator<T> iter = linkedLists.get(i).iterator();
+
+ while (iter.hasNext())
+ {
+ log.debug("Ref: "+ iter.next());
+ }
+ }
+ }
+
+ private void initDeques()
+ {
+ linkedLists = new ArrayList<LinkedList<T>>();
+
+ for (int i = 0; i < priorities; i++)
+ {
+ linkedLists.add(new LinkedList<T>());
+ }
+
+ size = 0;
+ }
+
+ private class PriorityLinkedListIterator implements ListIterator<T>
+ {
+ private int index;
+
+ private ListIterator<T> currentIter;
+
+ PriorityLinkedListIterator()
+ {
+ index = linkedLists.size() - 1;
+
+ currentIter = linkedLists.get(index).listIterator();
+ }
+
+ public void add(Object arg0)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean hasNext()
+ {
+ if (currentIter.hasNext())
+ {
+ return true;
+ }
+ while (index >= 0)
+ {
+ if (index == 0 || currentIter.hasNext())
+ {
+ break;
+ }
+ index--;
+ currentIter = linkedLists.get(index).listIterator();
+ }
+ return currentIter.hasNext();
+ }
+
+ public boolean hasPrevious()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public T next()
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+ return currentIter.next();
+ }
+
+ public int nextIndex()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public T previous()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int previousIndex()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void remove()
+ {
+ currentIter.remove();
+
+ size--;
+ }
+
+ public void set(Object obj)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/BrokenReceiver.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/BrokenReceiver.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/BrokenReceiver.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,101 +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.test.messaging.core;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.messaging.core.contract.Delivery;
-import org.jboss.messaging.core.contract.DeliveryObserver;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.core.contract.Receiver;
-import org.jboss.messaging.core.impl.SimpleDelivery;
-import org.jboss.messaging.core.impl.tx.Transaction;
-
-
-/**
- * A simple Receiver that "breaks" after the
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class BrokenReceiver implements Receiver
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private int counter;
- private int failurePoint;
- private List refs;
-
-
- // Constructors --------------------------------------------------
-
- public BrokenReceiver(int failurePoint)
- {
- refs = new ArrayList();
- this.failurePoint = failurePoint;
- }
-
- // Receiver implementation ---------------------------------------
-
- public Delivery handle(DeliveryObserver observer, MessageReference ref, Transaction tx)
- {
- counter++;
-
- if (counter == failurePoint)
- {
- throw new RuntimeException("I AM BROKEN!");
- }
-
- refs.add(ref);
- return new SimpleDelivery(observer, ref, true, false);
- }
-
- // Public --------------------------------------------------------
-
- public List getMessages()
- {
- return refs;
- }
-
- public String toString()
- {
- return "BrokenReceiver";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/JDBCPersistenceManagerTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/JDBCPersistenceManagerTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/JDBCPersistenceManagerTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,1461 +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.test.messaging.core;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.transaction.xa.Xid;
-
-import org.jboss.messaging.core.contract.Channel;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.core.contract.MessageStore;
-import org.jboss.messaging.core.contract.PersistenceManager;
-import org.jboss.messaging.core.impl.IDManager;
-import org.jboss.messaging.core.impl.JDBCPersistenceManager;
-import org.jboss.messaging.core.impl.message.SimpleMessageStore;
-import org.jboss.messaging.core.impl.tx.Transaction;
-import org.jboss.messaging.core.impl.tx.TransactionRepository;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.test.messaging.tools.container.ServiceContainer;
-import org.jboss.test.messaging.util.CoreMessageFactory;
-import org.jboss.util.id.GUID;
-
-
-/**
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>1.1</tt>
- *
- * JDBCPersistenceManagerTest.java,v 1.1 2006/02/22 17:33:44 timfox Exp
- */
-public class JDBCPersistenceManagerTest extends MessagingTestCase
-{
- // Attributes ----------------------------------------------------
-
- protected ServiceContainer sc;
-
- protected JDBCPersistenceManager pm;
-
- protected MessageStore ms;
-
-
- // Constructors --------------------------------------------------
-
- public JDBCPersistenceManagerTest(String name)
- {
- super(name);
- }
-
- public void setUp() throws Exception
- {
- if (ServerManagement.isRemote())
- {
- fail("This test is not supposed to run remotely!");
- }
-
- super.setUp();
-
- ServerManagement.stop();
-
- sc = new ServiceContainer("all");
- sc.start();
- }
-
- protected void doSetup(boolean batch, boolean useBinaryStream,
- boolean trailingByte, int maxParams) throws Throwable
- {
- pm = createPM(batch, useBinaryStream, trailingByte, maxParams);
- ms = new SimpleMessageStore();
- }
-
- protected JDBCPersistenceManager createPM(boolean batch, boolean useBinaryStream,
- boolean trailingByte, int maxParams) throws Throwable
- {
- JDBCPersistenceManager p =
- new JDBCPersistenceManager(sc.getDataSource(), sc.getTransactionManager(),
- sc.getPersistenceManagerSQLProperties(),
- true, batch, useBinaryStream, trailingByte, maxParams, !sc.getDatabaseName().equals("oracle"));
- ((JDBCPersistenceManager)p).injectNodeID(1);
- p.start();
- return p;
- }
-
- public void tearDown() throws Exception
- {
- sc.stop();
- sc = null;
-
- pm.stop();
- ms.stop();
- super.tearDown();
- }
-
- public void testAddRemoveGetReferences_Batch() throws Throwable
- {
- addRemoveGetReferences(true);
- }
-
- public void testAddRemoveGetReferences_NoBatch() throws Throwable
- {
- addRemoveGetReferences(false);
- }
-
- public void testAddRemoveReference() throws Throwable
- {
- doSetup(false, false, false, 100);
-
- Channel channel1 = new SimpleChannel(0, ms);
- Channel channel2 = new SimpleChannel(1, ms);
-
- Message[] messages = createMessages(10);
-
- for (int i = 0; i < 5; i++)
- {
- Message m1 = messages[i * 2];
- Message m2 = messages[i * 2 + 1];
-
- MessageReference ref1_1 = ms.reference(m1);
- MessageReference ref1_2 = ms.reference(m1);
-
- MessageReference ref2_1 = ms.reference(m2);
- MessageReference ref2_2 = ms.reference(m2);
-
- pm.addReference(channel1.getChannelID(), ref1_1, null);
- pm.addReference(channel1.getChannelID(), ref2_1, null);
-
- pm.addReference(channel2.getChannelID(), ref1_2, null);
- pm.addReference(channel2.getChannelID(), ref2_2, null);
-
- List refs = getReferenceIds(channel1.getChannelID());
-
- assertNotNull(refs);
- assertEquals(2, refs.size());
- assertTrue(refs.contains(new Long(m1.getMessageID())));
- assertTrue(refs.contains(new Long(m2.getMessageID())));
-
- refs = getReferenceIds(channel2.getChannelID());
-
- assertNotNull(refs);
- assertEquals(2, refs.size());
- assertTrue(refs.contains(new Long(m1.getMessageID())));
- assertTrue(refs.contains(new Long(m2.getMessageID())));
-
- List msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- assertTrue(msgs.contains(new Long(m1.getMessageID())));
- assertTrue(msgs.contains(new Long(m2.getMessageID())));
-
- pm.removeReference(channel1.getChannelID(), ref1_1, null);
-
- refs = getReferenceIds(channel1.getChannelID());
- assertNotNull(refs);
- assertEquals(1, refs.size());
- assertTrue(refs.contains(new Long(m2.getMessageID())));
-
- refs = getReferenceIds(channel2.getChannelID());
- assertNotNull(refs);
- assertEquals(2, refs.size());
- assertTrue(refs.contains(new Long(m1.getMessageID())));
- assertTrue(refs.contains(new Long(m2.getMessageID())));
-
- msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- assertTrue(msgs.contains(new Long(m1.getMessageID())));
- assertTrue(msgs.contains(new Long(m2.getMessageID())));
-
- pm.removeReference(channel2.getChannelID(), ref1_2, null);
-
- refs = getReferenceIds(channel1.getChannelID());
- assertNotNull(refs);
- assertEquals(1, refs.size());
- assertTrue(refs.contains(new Long(m2.getMessageID())));
-
- refs = getReferenceIds(channel2.getChannelID());
- assertNotNull(refs);
- assertEquals(1, refs.size());
- assertTrue(refs.contains(new Long(m2.getMessageID())));
-
- msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- assertTrue(msgs.contains(new Long(m2.getMessageID())));
-
- pm.removeReference(channel1.getChannelID(), ref2_1, null);
-
- refs = getReferenceIds(channel1.getChannelID());
- assertNotNull(refs);
- assertTrue(refs.isEmpty());
-
- refs = getReferenceIds(channel2.getChannelID());
- assertNotNull(refs);
- assertEquals(1, refs.size());
- assertTrue(refs.contains(new Long(m2.getMessageID())));
-
- msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- assertTrue(msgs.contains(new Long(m2.getMessageID())));
-
- pm.removeReference(channel2.getChannelID(), ref2_2, null);
-
- refs = getReferenceIds(channel1.getChannelID());
- assertNotNull(refs);
- assertTrue(refs.isEmpty());
-
- refs = getReferenceIds(channel2.getChannelID());
- assertNotNull(refs);
- assertTrue(refs.isEmpty());
-
- msgs = getMessageIds();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- }
- }
-
- // Trailing zero
- // -----------------
-
- // Binary Stream
-
- //non batch
-
- public void testCommit_NotXA_Long_NB_BS_TZ() throws Throwable
- {
- doTransactionCommit(false, false, true, true);
- }
-
- public void testCommit_XA_Long_NB_BS_TZ() throws Throwable
- {
- doTransactionCommit(true, false, true, true);
- }
-
- public void testRollback_NotXA_Long_NB_BS_TZ() throws Throwable
- {
- doTransactionRollback(false, false, true, true);
- }
-
- public void testRollback_XA_Long_NB_BS_TZ() throws Throwable
- {
- doTransactionRollback(true, false, true, true);
- }
-
-
- //batch
-
- public void testCommit_NotXA_Long_B_BS_TZ() throws Throwable
- {
- doTransactionCommit(false, true, true, true);
- }
-
- public void testCommit_XA_Long_B_BS_TZ() throws Throwable
- {
- doTransactionCommit(true, true, true, true);
- }
-
- public void testRollback_NotXA_Long_B_BS_TZ() throws Throwable
- {
- doTransactionRollback(false, true, true, true);
- }
-
- public void testRollback_XA_Long_B_BS_TZ() throws Throwable
- {
- doTransactionRollback(true, true, true, true);
- }
-
- // No binary stream
-
- //non batch
-
- public void testCommit_NotXA_Long_NB_BNS_TZ() throws Throwable
- {
- doTransactionCommit(false, false, false, true);
- }
-
- public void testCommit_XA_Long_NB_NBS_TZ() throws Throwable
- {
- doTransactionCommit(true, false, false, true);
- }
-
- public void testRollback_NotXA_Long_NB_NBS_TZ() throws Throwable
- {
- doTransactionRollback(false, false, false, true);
- }
-
- public void testRollback_XA_Long_NB_NBS_TZ() throws Throwable
- {
- doTransactionRollback(true, false, false, true);
- }
-
-
- //batch
-
- public void testCommit_NotXA_Long_B_NBS_TZ() throws Throwable
- {
- doTransactionCommit(false, true, false, true);
- }
-
- public void testCommit_XA_Long_B_NBS_TZ() throws Throwable
- {
- doTransactionCommit(true, true, false, true);
- }
-
- public void testRollback_NotXA_Long_B_NBS_TZ() throws Throwable
- {
- doTransactionRollback(false, true, false, true);
- }
-
- public void testRollback_XA_Long_B_NBS_TZ() throws Throwable
- {
- doTransactionRollback(true, true, false, true);
- }
-
-
- // Non trailing zero
- // -----------------
-
- // Binary Stream
-
- //non batch
-
- public void testCommit_NotXA_Long_NB_BS_NTZ() throws Throwable
- {
- doTransactionCommit(false, false, true, false);
- }
-
- public void testCommit_XA_Long_NB_BS_NTZ() throws Throwable
- {
- doTransactionCommit(true, false, true, false);
- }
-
- public void testRollback_NotXA_Long_NB_BS_NTZ() throws Throwable
- {
- doTransactionRollback(false, false, true, false);
- }
-
- public void testRollback_XA_Long_NB_BS_NTZ() throws Throwable
- {
- doTransactionRollback(true, false, true, false);
- }
-
-
- //batch
-
- public void testCommit_NotXA_Long_B_BS_NTZ() throws Throwable
- {
- doTransactionCommit(false, true, true, false);
- }
-
- public void testCommit_XA_Long_B_BS_NTZ() throws Throwable
- {
- doTransactionCommit(true, true, true, false);
- }
-
- public void testRollback_NotXA_Long_B_BS_NTZ() throws Throwable
- {
- doTransactionRollback(false, true, true, false);
- }
-
- public void testRollback_XA_Long_B_BS_NTZ() throws Throwable
- {
- doTransactionRollback(true, true, true, false);
- }
-
- // No binary stream
-
- //non batch
-
- public void testCommit_NotXA_Long_NB_BNS_NTZ() throws Throwable
- {
- doTransactionCommit(false, false, false, false);
- }
-
- public void testCommit_XA_Long_NB_NBS_NTZ() throws Throwable
- {
- doTransactionCommit(true, false, false, false);
- }
-
- public void testRollback_NotXA_Long_NB_NBS_NTZ() throws Throwable
- {
- doTransactionRollback(false, false, false, false);
- }
-
- public void testRollback_XA_Long_NB_NBS_NTZ() throws Throwable
- {
- doTransactionRollback(true, false, false, false);
- }
-
-
- //batch
-
- public void testCommit_NotXA_Long_B_NBS_NTZ() throws Throwable
- {
- doTransactionCommit(false, true, false, false);
- }
-
- public void testCommit_XA_Long_B_NBS_NTZ() throws Throwable
- {
- doTransactionCommit(true, true, false, false);
- }
-
- public void testRollback_NotXA_Long_B_NBS_NTZ() throws Throwable
- {
- doTransactionRollback(false, true, false, false);
- }
-
- public void testRollback_XA_Long_B_NBS_NTZ() throws Throwable
- {
- doTransactionRollback(true, true, false, false);
- }
-
-
-
-
- protected void addRemoveGetReferences(boolean batch) throws Throwable
- {
- doSetup(false, false, false, 100);
-
- Channel channel1 = new SimpleChannel(0, ms);
-
- Channel channel2 = new SimpleChannel(1, ms);
-
- Message[] m = createMessages(10);
-
- MessageReference ref1 = ms.reference(m[0]);
- MessageReference ref2 = ms.reference(m[1]);
- MessageReference ref3 = ms.reference(m[2]);
- MessageReference ref4 = ms.reference(m[3]);
- MessageReference ref5 = ms.reference(m[4]);
- MessageReference ref6 = ms.reference(m[5]);
- MessageReference ref7 = ms.reference(m[6]);
- MessageReference ref8 = ms.reference(m[7]);
- MessageReference ref9 = ms.reference(m[8]);
- MessageReference ref10 = ms.reference(m[9]);
-
- MessageReference ref11 = ms.reference(m[0]);
- MessageReference ref12 = ms.reference(m[1]);
- MessageReference ref13 = ms.reference(m[2]);
- MessageReference ref14 = ms.reference(m[3]);
- MessageReference ref15 = ms.reference(m[4]);
-
- List refs = new ArrayList();
- refs.add(ref1);
- refs.add(ref2);
- refs.add(ref3);
- refs.add(ref4);
- refs.add(ref5);
- refs.add(ref6);
- refs.add(ref7);
- refs.add(ref8);
- refs.add(ref9);
- refs.add(ref10);
-
- pm.pageReferences(channel1.getChannelID(), refs, false);
-
- refs = new ArrayList();
- refs.add(ref11);
- refs.add(ref12);
- refs.add(ref13);
- refs.add(ref14);
- refs.add(ref15);
-
- pm.pageReferences(channel2.getChannelID(), refs, false);
-
- List refIds = getReferenceIds(channel1.getChannelID());
- assertNotNull(refIds);
- assertEquals(10, refIds.size());
- assertTrue(refIds.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref2.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref3.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref5.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref6.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref7.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref8.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref9.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref10.getMessage().getMessageID())));
-
- refIds = getReferenceIds(channel2.getChannelID());
- assertNotNull(refIds);
- assertEquals(5, refIds.size());
- assertTrue(refIds.contains(new Long(ref11.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref12.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref13.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref14.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref15.getMessage().getMessageID())));
-
- List msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(10, msgs.size());
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref3.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref5.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref6.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref7.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref8.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref9.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref10.getMessage().getMessageID())));
-
- List msgIds = new ArrayList();
- msgIds.add(new Long(ref3.getMessage().getMessageID()));
- msgIds.add(new Long(ref4.getMessage().getMessageID()));
- msgIds.add(new Long(ref7.getMessage().getMessageID()));
- msgIds.add(new Long(ref9.getMessage().getMessageID()));
- msgIds.add(new Long(ref1.getMessage().getMessageID()));
-
- List ms = pm.getMessages(msgIds);
- assertNotNull(ms);
- assertEquals(5, ms.size());
- assertTrue(containsMessage(ms, ref3.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref4.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref7.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref9.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref1.getMessage().getMessageID()));
-
- refs = new ArrayList();
- refs.add(ref12);
- refs.add(ref13);
- refs.add(ref14);
- refs.add(ref15);
- pm.removeDepagedReferences(channel2.getChannelID(), refs);
-
- refIds = getReferenceIds(channel2.getChannelID());
- assertNotNull(refIds);
- assertEquals(1, refIds.size());
- assertTrue(refIds.contains(new Long(ref11.getMessage().getMessageID())));
-
- ms = getMessageIds();
-
- assertNotNull(ms);
- assertEquals(10, ms.size());
-
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref3.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref5.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref6.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref7.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref8.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref9.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref10.getMessage().getMessageID())));
-
-
- refs = new ArrayList();
- refs.add(ref1);
- refs.add(ref2);
- refs.add(ref3);
- pm.removeDepagedReferences(channel1.getChannelID(), refs);
-
- refIds = getReferenceIds(channel1.getChannelID());
- assertNotNull(refIds);
- assertEquals(7, refIds.size());
- assertTrue(refIds.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref5.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref6.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref7.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref8.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref9.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref10.getMessage().getMessageID())));
-
- ms = getMessageIds();
-
- assertNotNull(ms);
- assertEquals(8, ms.size());
-
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref5.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref6.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref7.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref8.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref9.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref10.getMessage().getMessageID())));
-
- refs = new ArrayList();
- refs.add(ref11);
- pm.removeDepagedReferences(channel2.getChannelID(), refs);
-
- refs = new ArrayList();
- refs.add(ref4);
- refs.add(ref5);
- refs.add(ref6);
- refs.add(ref7);
- refs.add(ref8);
- refs.add(ref9);
- refs.add(ref10);
- pm.removeDepagedReferences(channel1.getChannelID(), refs);
-
- ms = getMessageIds();
- assertNotNull(ms);
- assertEquals(0, ms.size());
- }
-
- public void testPageOrders() throws Throwable
- {
- doSetup(false, false, false, 100);
-
- Channel channel = new SimpleChannel(0, ms);
-
- Message[] m = createMessages(10);
-
- List refs = new ArrayList();
-
- MessageReference ref1 = ms.reference(m[0]);
- MessageReference ref2 = ms.reference(m[1]);
- MessageReference ref3 = ms.reference(m[2]);
- MessageReference ref4 = ms.reference(m[3]);
- MessageReference ref5 = ms.reference(m[4]);
- MessageReference ref6 = ms.reference(m[5]);
- MessageReference ref7 = ms.reference(m[6]);
- MessageReference ref8 = ms.reference(m[7]);
- MessageReference ref9 = ms.reference(m[8]);
- MessageReference ref10 = ms.reference(m[9]);
-
- refs.add(ref1);
- refs.add(ref2);
- refs.add(ref3);
- refs.add(ref4);
- refs.add(ref5);
- refs.add(ref6);
- refs.add(ref7);
- refs.add(ref8);
- refs.add(ref9);
- refs.add(ref10);
-
- pm.pageReferences(channel.getChannelID(), refs, false);
-
- ref1.setPagingOrder(0);
- ref2.setPagingOrder(1);
- ref3.setPagingOrder(2);
- ref4.setPagingOrder(3);
- ref5.setPagingOrder(4);
- ref6.setPagingOrder(5);
- ref7.setPagingOrder(6);
- ref8.setPagingOrder(7);
- ref9.setPagingOrder(8);
- ref10.setPagingOrder(9);
-
- pm.updatePageOrder(channel.getChannelID(), refs);
-
- List refInfos = pm.getPagedReferenceInfos(channel.getChannelID(), 0, 10);
-
- assertNotNull(refInfos);
-
- assertEquals(10, refInfos.size());
-
- assertEquals(ref1.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(0)).getMessageId());
- assertEquals(ref2.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(1)).getMessageId());
- assertEquals(ref3.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(2)).getMessageId());
- assertEquals(ref4.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
- assertEquals(ref5.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(4)).getMessageId());
- assertEquals(ref6.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(5)).getMessageId());
- assertEquals(ref7.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(6)).getMessageId());
- assertEquals(ref8.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(7)).getMessageId());
- assertEquals(ref9.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(8)).getMessageId());
- assertEquals(ref10.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(9)).getMessageId());
-
- refInfos = pm.getPagedReferenceInfos(channel.getChannelID(), 3, 5);
-
- assertNotNull(refInfos);
-
- assertEquals(5, refInfos.size());
-
- assertEquals(ref4.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(0)).getMessageId());
- assertEquals(ref5.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(1)).getMessageId());
- assertEquals(ref6.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(2)).getMessageId());
- assertEquals(ref7.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
- assertEquals(ref8.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(4)).getMessageId());
-
- pm.updateReferencesNotPagedInRange(channel.getChannelID(), 0, 3, 4);
-
- refInfos = pm.getPagedReferenceInfos(channel.getChannelID(), 5, 5);
-
- assertNotNull(refInfos);
-
- assertEquals(5, refInfos.size());
-
- assertEquals(ref6.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(0)).getMessageId());
- assertEquals(ref7.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(1)).getMessageId());
- assertEquals(ref8.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(2)).getMessageId());
- assertEquals(ref9.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
- assertEquals(ref10.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(4)).getMessageId());
- }
-
- public void testGetMessages() throws Throwable
- {
- doSetup(false, false, false, 100);
-
- Channel channel = new SimpleChannel(0, ms);
-
- Message[] m = createMessages(10);
-
- MessageReference ref1 = ms.reference(m[0]);
- MessageReference ref2 = ms.reference(m[1]);
- MessageReference ref3 = ms.reference(m[2]);
- MessageReference ref4 = ms.reference(m[3]);
- MessageReference ref5 = ms.reference(m[4]);
- MessageReference ref6 = ms.reference(m[5]);
- MessageReference ref7 = ms.reference(m[6]);
- MessageReference ref8 = ms.reference(m[7]);
- MessageReference ref9 = ms.reference(m[8]);
- MessageReference ref10 = ms.reference(m[9]);
-
- pm.addReference(channel.getChannelID(), ref1, null);
- pm.addReference(channel.getChannelID(), ref2, null);
- pm.addReference(channel.getChannelID(), ref3, null);
- pm.addReference(channel.getChannelID(), ref4, null);
- pm.addReference(channel.getChannelID(), ref5, null);
- pm.addReference(channel.getChannelID(), ref6, null);
- pm.addReference(channel.getChannelID(), ref7, null);
- pm.addReference(channel.getChannelID(), ref8, null);
- pm.addReference(channel.getChannelID(), ref9, null);
- pm.addReference(channel.getChannelID(), ref10, null);
-
- List refIds = getReferenceIds(channel.getChannelID());
- assertNotNull(refIds);
- assertEquals(10, refIds.size());
- assertTrue(refIds.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref2.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref3.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref5.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref6.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref7.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref8.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref9.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref10.getMessage().getMessageID())));
-
- List msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(10, msgs.size());
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref3.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref5.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref6.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref7.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref8.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref9.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref10.getMessage().getMessageID())));
-
- List msgIds = new ArrayList();
- msgIds.add(new Long(ref3.getMessage().getMessageID()));
- msgIds.add(new Long(ref4.getMessage().getMessageID()));
- msgIds.add(new Long(ref7.getMessage().getMessageID()));
- msgIds.add(new Long(ref9.getMessage().getMessageID()));
- msgIds.add(new Long(ref1.getMessage().getMessageID()));
-
- List ms = pm.getMessages(msgIds);
- assertNotNull(ms);
- assertEquals(5, ms.size());
-
- assertTrue(containsMessage(ms, ref3.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref4.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref7.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref9.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref1.getMessage().getMessageID()));
-
- }
-
- public void testGetInitialRefInfos() throws Throwable
- {
- doSetup(false, false, false, 100);
-
- Channel channel = new SimpleChannel(0, ms);
-
- Message[] m = createMessages(10);
-
- List refs = new ArrayList();
-
- MessageReference ref1 = ms.reference(m[0]);
- MessageReference ref2 = ms.reference(m[1]);
- MessageReference ref3 = ms.reference(m[2]);
- MessageReference ref4 = ms.reference(m[3]);
- MessageReference ref5 = ms.reference(m[4]);
- MessageReference ref6 = ms.reference(m[5]);
- MessageReference ref7 = ms.reference(m[6]);
- MessageReference ref8 = ms.reference(m[7]);
- MessageReference ref9 = ms.reference(m[8]);
- MessageReference ref10 = ms.reference(m[9]);
-
- refs.add(ref1);
- refs.add(ref2);
- refs.add(ref3);
- refs.add(ref4);
- refs.add(ref5);
- refs.add(ref6);
- refs.add(ref7);
- refs.add(ref8);
- refs.add(ref9);
- refs.add(ref10);
-
- pm.pageReferences(channel.getChannelID(), refs, false);
-
- //First load exactly 10
- PersistenceManager.InitialLoadInfo info = pm.loadFromStart(channel.getChannelID(), 10);
-
- assertNull(info.getMinPageOrdering());
- assertNull(info.getMaxPageOrdering());
-
- List refInfos = info.getRefInfos();
-
- assertNotNull(refInfos);
- assertEquals(10, refInfos.size());
-
- assertEquals(ref1.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(0)).getMessageId());
- assertEquals(ref2.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(1)).getMessageId());
- assertEquals(ref3.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(2)).getMessageId());
- assertEquals(ref4.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(3)).getMessageId());
- assertEquals(ref5.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(4)).getMessageId());
- assertEquals(ref6.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(5)).getMessageId());
- assertEquals(ref7.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(6)).getMessageId());
- assertEquals(ref8.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(7)).getMessageId());
- assertEquals(ref9.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(8)).getMessageId());
- assertEquals(ref10.getMessage().getMessageID(), ((PersistenceManager.ReferenceInfo)refInfos.get(9)).getMessageId());
- }
-
-
- protected boolean containsMessage(List msgs, long msgId)
- {
- Iterator iter = msgs.iterator();
- while (iter.hasNext())
- {
- Message m = (Message)iter.next();
- if (m.getMessageID() == msgId)
- {
- return true;
- }
- }
- return false;
- }
-
- public void testGetMessagesMaxParams() throws Throwable
- {
- doSetup(false, false, false, 5);
-
- Channel channel = new SimpleChannel(0, ms);
-
- Message[] m = createMessages(10);
-
- MessageReference ref1 = ms.reference(m[0]);
- MessageReference ref2 = ms.reference(m[1]);
- MessageReference ref3 = ms.reference(m[2]);
- MessageReference ref4 = ms.reference(m[3]);
- MessageReference ref5 = ms.reference(m[4]);
- MessageReference ref6 = ms.reference(m[5]);
- MessageReference ref7 = ms.reference(m[6]);
- MessageReference ref8 = ms.reference(m[7]);
- MessageReference ref9 = ms.reference(m[8]);
- MessageReference ref10 = ms.reference(m[9]);
-
- pm.addReference(channel.getChannelID(), ref1, null);
- pm.addReference(channel.getChannelID(), ref2, null);
- pm.addReference(channel.getChannelID(), ref3, null);
- pm.addReference(channel.getChannelID(), ref4, null);
- pm.addReference(channel.getChannelID(), ref5, null);
- pm.addReference(channel.getChannelID(), ref6, null);
- pm.addReference(channel.getChannelID(), ref7, null);
- pm.addReference(channel.getChannelID(), ref8, null);
- pm.addReference(channel.getChannelID(), ref9, null);
- pm.addReference(channel.getChannelID(), ref10, null);
-
- List refIds = getReferenceIds(channel.getChannelID());
- assertNotNull(refIds);
- assertEquals(10, refIds.size());
- assertTrue(refIds.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref2.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref3.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref5.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref6.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref7.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref8.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref9.getMessage().getMessageID())));
- assertTrue(refIds.contains(new Long(ref10.getMessage().getMessageID())));
-
- List msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(10, msgs.size());
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref3.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref5.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref6.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref7.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref8.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref9.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref10.getMessage().getMessageID())));
-
- List msgIds = new ArrayList();
- msgIds.add(new Long(ref3.getMessage().getMessageID()));
- msgIds.add(new Long(ref4.getMessage().getMessageID()));
- msgIds.add(new Long(ref7.getMessage().getMessageID()));
- msgIds.add(new Long(ref9.getMessage().getMessageID()));
- msgIds.add(new Long(ref1.getMessage().getMessageID()));
-
- List ms = pm.getMessages(msgIds);
- assertNotNull(ms);
- assertEquals(5, ms.size());
- assertTrue(containsMessage(ms, ref3.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref4.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref7.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref9.getMessage().getMessageID()));
- assertTrue(containsMessage(ms, ref1.getMessage().getMessageID()));
- }
-
-
- protected Message createMessage(byte i, boolean reliable) throws Throwable
- {
- Map headers = generateFilledMap(true);
-
- return CoreMessageFactory.
- createCoreMessage(i,
- reliable,
- System.currentTimeMillis() + 1000 * 60 * 60,
- System.currentTimeMillis(),
- (byte)(i % 10),
- headers,
- i % 2 == 0 ? new WibblishObject() : null);
- }
-
- protected Message[] createMessages(int num) throws Throwable
- {
- //Generate some messages with a good range of attribute values
- Message[] messages = new Message[num];
- for (int i = 0; i < num; i++)
- {
- messages[i] = createMessage((byte)i, true);
- }
- return messages;
- }
-
- protected void checkEquivalent(Message m1, Message m2) throws Throwable
- {
- if (m1 == m2)
- {
- fail();
- }
-
- if (m1 == null || m2 == null)
- {
- fail();
- }
-
- //Attributes from org.jboss.messaging.core.Message
- assertEquals(m1.getMessageID(), m2.getMessageID());
- assertEquals(m1.isReliable(), m2.isReliable());
- assertEquals(m1.getExpiration(), m2.getExpiration());
- assertEquals(m1.isExpired(), m2.isExpired());
- assertEquals(m1.getTimestamp(), m2.getTimestamp());
- assertEquals(m1.getPriority(), m2.getPriority());
- Map m1Headers = m1.getHeaders();
- Map m2Headers = m2.getHeaders();
- checkMapsEquivalent(m1Headers, m2Headers);
- checkMapsEquivalent(m2Headers, m1Headers);
-
- if (m1.getPayload() instanceof byte[] && m2.getPayload() instanceof byte[])
- {
- this.checkByteArraysEqual((byte[])m1.getPayload(), (byte[])m2.getPayload());
- }
- else if (m1.getPayload() instanceof Map && m2.getPayload() instanceof Map)
- {
- this.checkMapsEquivalent((Map)m1.getPayload(), (Map)m2.getPayload());
- }
- else if (m1.getPayload() instanceof List && m2.getPayload() instanceof List)
- {
- this.checkListsEquivalent((List)m1.getPayload(), (List)m2.getPayload());
- }
- else
- {
- assertEquals(m1.getPayload(), m2.getPayload());
- }
-
- }
-
- protected void checkMapsEquivalent(Map headers1, Map headers2)
- {
- Iterator iter = headers1.entrySet().iterator();
- while (iter.hasNext())
- {
- Map.Entry entry1 = (Map.Entry)iter.next();
- Object value2 = headers2.get(entry1.getKey());
- assertNotNull(value2);
- if (value2 instanceof byte[])
- {
- checkByteArraysEqual((byte[])entry1.getValue(), (byte[])value2);
- }
- else
- {
- assertEquals(entry1.getValue(), value2);
- }
- }
- }
-
- protected void checkListsEquivalent(List l1, List l2)
- {
- Iterator iter1 = l1.iterator();
- Iterator iter2 = l2.iterator();
- while (iter1.hasNext())
- {
- Object o1 = iter1.next();
- Object o2 = iter2.next();
-
- if (o1 instanceof byte[])
- {
- checkByteArraysEqual((byte[])o1, (byte[])o2);
- }
- else
- {
- assertEquals(o1, o2);
- }
- }
- }
-
- public static class WibblishObject implements Serializable
- {
- private static final long serialVersionUID = -822739710811857027L;
- public String wibble;
- public WibblishObject()
- {
- this.wibble = new GUID().toString();
- }
- public boolean equals(Object other)
- {
- if (!(other instanceof WibblishObject))
- {
- return false;
- }
- WibblishObject oo = (WibblishObject)other;
- return oo.wibble.equals(this.wibble);
- }
- }
-
- protected HashMap generateFilledMap(boolean useObject)
- {
- HashMap headers = new HashMap();
- for (int j = 0; j < 27; j++)
- {
- //put some crap in the map
- int k;
- if (useObject)
- {
- k = j % 11;
- }
- else
- {
- k = j % 10;
- }
-
- switch (k)
- {
- case 0:
- headers.put(new GUID().toString(), randString(1000));
- case 1:
- headers.put(new GUID().toString(), randByte());
- case 2:
- headers.put(new GUID().toString(), randShort());
- case 3:
- headers.put(new GUID().toString(), randInt());
- case 4:
- headers.put(new GUID().toString(), randLong());
- case 5:
- headers.put(new GUID().toString(), randBool());
- case 6:
- headers.put(new GUID().toString(), randFloat());
- case 7:
- headers.put(new GUID().toString(), randDouble());
- case 8:
- headers.put(new GUID().toString(), randLong());
- case 9:
- headers.put(new GUID().toString(), randByteArray(500));
- case 10:
- headers.put(new GUID().toString(), new WibblishObject());
- }
- }
- return headers;
- }
-
- protected Byte randByte()
- {
- return new Byte((byte)(Math.random() * (2^8 - 1) - (2^7)));
- }
-
- protected Short randShort()
- {
- return new Short((short)(Math.random() * (2^16 - 1) - (2^15)));
- }
-
- protected Integer randInt()
- {
- return new Integer((int)(Math.random() * (2^32 - 1) - (2^31)));
- }
-
- protected Long randLong()
- {
- return new Long((long)(Math.random() * (2^64 - 1) - (2^64)));
- }
-
- protected Boolean randBool()
- {
- return new Boolean(Math.random() > 0.5);
- }
-
- protected Float randFloat()
- {
- return new Float((float)(Math.random() * 1000000));
- }
-
- protected Double randDouble()
- {
- return new Double(Math.random() * 1000000);
- }
-
- protected String randString(int length)
- {
- StringBuffer buf = new StringBuffer(length);
- for (int i = 0; i < length; i++)
- {
- buf.append(randChar().charValue());
- }
- return buf.toString();
- }
-
- protected byte[] randByteArray(int size)
- {
- String s = randString(size / 2);
- return s.getBytes();
- }
-
- protected Character randChar()
- {
- return new Character((char)randShort().shortValue());
- }
-
- protected void checkByteArraysEqual(byte[] b1, byte[] b2)
- {
- if (b1 == null || b2 == null)
- {
- fail();
- }
- if (b1.length != b2.length)
- {
- fail();
- }
-
- for (int i = 0; i < b1.length; i++)
- {
- assertEquals(b1[i], b2[i]);
- }
-
- }
-
- protected class MockXid implements Xid
- {
- byte[] branchQual;
- int formatID;
- byte[] globalTxId;
-
- protected MockXid()
- {
- branchQual = new GUID().toString().getBytes();
- formatID = randInt().intValue();
- globalTxId = new GUID().toString().getBytes();
- }
-
- public byte[] getBranchQualifier()
- {
- return branchQual;
- }
-
- public int getFormatId()
- {
- return formatID;
- }
-
- public byte[] getGlobalTransactionId()
- {
- return globalTxId;
- }
-
- public boolean equals(Object other)
- {
- if (!(other instanceof Xid))
- {
- return false;
- }
- Xid xother = (Xid)other;
- if (xother.getFormatId() != this.formatID)
- {
- return false;
- }
- if (xother.getBranchQualifier().length != this.branchQual.length)
- {
- return false;
- }
- if (xother.getGlobalTransactionId().length != this.globalTxId.length)
- {
- return false;
- }
- for (int i = 0; i < this.branchQual.length; i++)
- {
- byte[] otherBQ = xother.getBranchQualifier();
- if (this.branchQual[i] != otherBQ[i])
- {
- return false;
- }
- }
- for (int i = 0; i < this.globalTxId.length; i++)
- {
- byte[] otherGtx = xother.getGlobalTransactionId();
- if (this.globalTxId[i] != otherGtx[i])
- {
- return false;
- }
- }
- return true;
- }
-
- }
-
- protected void doTransactionCommit(boolean xa, boolean batch, boolean useBinaryStream, boolean trailingByte) throws Throwable
- {
- doSetup(batch, useBinaryStream, trailingByte, 100);
-
- Channel channel = new SimpleChannel(0, ms);
-
- IDManager idm = new IDManager("TRANSACTION_ID", 10, pm);
- idm.start();
-
- TransactionRepository txRep = new TransactionRepository(pm, ms, idm);
- txRep.start();
-
- log.debug("transaction log started");
-
- Message[] messages = createMessages(10);
-
- Message m1 = messages[0];
- Message m2 = messages[1];
- Message m3 = messages[2];
- Message m4 = messages[3];
- Message m5 = messages[4];
-
- Transaction tx = null;
- if (xa)
- {
- tx = txRep.createTransaction(new MockXid());
- }
- else
- {
- tx = txRep.createTransaction();
- }
-
- if (xa)
- {
- assertEquals(1,txRep.getNumberOfRegisteredTransactions());
- }
- else
- {
- assertEquals(0,txRep.getNumberOfRegisteredTransactions());
- }
-
- MessageReference ref1 = ms.reference(m1);
- MessageReference ref2 = ms.reference(m2);
- MessageReference ref3 = ms.reference(m3);
- MessageReference ref4 = ms.reference(m4);
- MessageReference ref5 = ms.reference(m5);
-
- log.debug("adding references non-transactionally");
-
- // Add first two refs non transactionally
- pm.addReference(channel.getChannelID(), ref1, null);
- pm.addReference(channel.getChannelID(), ref2, null);
-
- //check they're there
- List refs = getReferenceIds(channel.getChannelID());
- assertNotNull(refs);
- assertEquals(2, refs.size());
- assertTrue(refs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(refs.contains(new Long(ref2.getMessage().getMessageID())));
-
- List msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
-
- log.debug("ref1 and ref2 are there");
-
- //Add the next 3 refs transactionally
- pm.addReference(channel.getChannelID(), ref3, tx);
- pm.addReference(channel.getChannelID(), ref4, tx);
- pm.addReference(channel.getChannelID(), ref5, tx);
-
- //Remove the other 2 transactionally
- pm.removeReference(channel.getChannelID(), ref1, tx);
- pm.removeReference(channel.getChannelID(), ref2, tx);
-
- //Check the changes aren't visible
- refs = getReferenceIds(channel.getChannelID());
- assertNotNull(refs);
- assertEquals(2, refs.size());
- assertTrue(refs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(refs.contains(new Long(ref2.getMessage().getMessageID())));
-
- msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
-
- //commit transaction
- tx.commit();
-
- assertEquals("numberOfRegisteredTransactions",0,txRep.getNumberOfRegisteredTransactions());
-
- //check we can see only the last 3 refs
- refs = getReferenceIds(channel.getChannelID());
- assertNotNull(refs);
- assertEquals(3, refs.size());
- assertTrue(refs.contains(new Long(ref3.getMessage().getMessageID())));
- assertTrue(refs.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(refs.contains(new Long(ref5.getMessage().getMessageID())));
-
- msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(3, msgs.size());
- assertTrue(msgs.contains(new Long(ref3.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref4.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref5.getMessage().getMessageID())));
- }
-
- protected void doTransactionRollback(boolean xa, boolean batch, boolean useBinaryStream, boolean trailingByte) throws Throwable
- {
- doSetup(batch, useBinaryStream, trailingByte, 100);
-
- Channel channel = new SimpleChannel(0, ms);
-
- IDManager idm = new IDManager("TRANSACTION_ID", 10, pm);
- idm.start();
-
- TransactionRepository txRep = new TransactionRepository(pm, ms, idm);
- txRep.start();
-
- Message[] messages = createMessages(10);
-
- Message m1 = messages[0];
- Message m2 = messages[1];
- Message m3 = messages[2];
- Message m4 = messages[3];
- Message m5 = messages[4];
-
-
- Transaction tx = null;
- if (xa)
- {
- tx = txRep.createTransaction(new MockXid());
- }
- else
- {
- tx = txRep.createTransaction();
- }
-
- MessageReference ref1 = ms.reference(m1);
- MessageReference ref2 = ms.reference(m2);
- MessageReference ref3 = ms.reference(m3);
- MessageReference ref4 = ms.reference(m4);
- MessageReference ref5 = ms.reference(m5);
-
- //Add first two refs non transactionally
- pm.addReference(channel.getChannelID(), ref1, null);
- pm.addReference(channel.getChannelID(), ref2, null);
-
- //check they're there
- List refs = getReferenceIds(channel.getChannelID());
- assertNotNull(refs);
- assertEquals(2, refs.size());
- assertTrue(refs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(refs.contains(new Long(ref2.getMessage().getMessageID())));
-
- List msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
-
-
- //Add the next 3 refs transactionally
- pm.addReference(channel.getChannelID(), ref3, tx);
- pm.addReference(channel.getChannelID(), ref4, tx);
- pm.addReference(channel.getChannelID(), ref5, tx);
-
- //Remove the other 2 transactionally
- pm.removeReference(channel.getChannelID(), ref1, tx);
- pm.removeReference(channel.getChannelID(), ref2, tx);
-
- //Check the changes aren't visible
- refs = getReferenceIds(channel.getChannelID());
- assertNotNull(refs);
- assertEquals(2, refs.size());
- assertTrue(refs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(refs.contains(new Long(ref2.getMessage().getMessageID())));
-
- msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
-
- //rollback transaction
- tx.rollback();
-
- refs = getReferenceIds(channel.getChannelID());
- assertNotNull(refs);
- assertEquals(2, refs.size());
- assertTrue(refs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(refs.contains(new Long(ref2.getMessage().getMessageID())));
-
- msgs = getMessageIds();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- assertTrue(msgs.contains(new Long(ref1.getMessage().getMessageID())));
- assertTrue(msgs.contains(new Long(ref2.getMessage().getMessageID())));
- }
-
-
-
-}
-
-
-
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/MessagingQueueTestBase.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/MessagingQueueTestBase.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/MessagingQueueTestBase.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,5400 +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.test.messaging.core;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jboss.messaging.core.contract.Delivery;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.core.contract.MessageStore;
-import org.jboss.messaging.core.contract.PersistenceManager;
-import org.jboss.messaging.core.contract.Receiver;
-import org.jboss.messaging.core.impl.IDManager;
-import org.jboss.messaging.core.impl.JDBCPersistenceManager;
-import org.jboss.messaging.core.impl.MessagingQueue;
-import org.jboss.messaging.core.impl.message.SimpleMessageStore;
-import org.jboss.messaging.core.impl.tx.Transaction;
-import org.jboss.messaging.core.impl.tx.TransactionRepository;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.container.ServiceContainer;
-import org.jboss.test.messaging.util.CoreMessageFactory;
-
-/**
- * The QueueTest test strategy is to try as many combination as it makes sense of the following
- * variables:
- *
- * 1. The Queue can be non-recoverable or
- * recoverable.
- * 2. The Queue may have zero or one receivers (the behavior for more than one receiver depends
- * on the particular router implementation).
- * 3. The receiver may be ACKING or NACKING (the case when it throws unchecked exceptions is handled
- * at the Router level).
- * 4. The sender can send message(s) non-transactionally or transactionally (and then can commit
- * or rollback the transaction).
- * 5. The NACKING receiver can send acknowledgment(s) non-transactionally or transactionally (and
- * then can commit or rollback the transaction).
- * 6. The message can be non-reliable or reliable.
- * 7. The sender can send one or multiple messages.
- * 8. A recoverable channel may be crashed and tested if it successfully recovers.
- *
- * This test base also tests the Distributor interface.
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1019 $</tt>
- *
- * $Id: ChannelTestBase.java 1019 2006-07-17 17:15:04Z timfox $
- */
-public abstract class MessagingQueueTestBase extends MessagingTestCase
-{
- // Constants -----------------------------------------------------
-
- public static final int NUMBER_OF_MESSAGES = 10;
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- protected PersistenceManager pm;
-
- protected TransactionRepository tr;
-
- protected MessageStore ms;
-
- protected ServiceContainer sc;
-
- protected MessagingQueue queue;
-
- protected IDManager idm;
-
- // Constructors --------------------------------------------------
-
- public MessagingQueueTestBase(String name)
- {
- super(name);
- }
-
- // Public --------------------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- sc = new ServiceContainer("all,-remoting,-security");
- sc.start();
-
- pm = new JDBCPersistenceManager(sc.getDataSource(), sc.getTransactionManager(),
- sc.getPersistenceManagerSQLProperties(),
- true, true, true, false, 100, !sc.getDatabaseName().equals("oracle"));
- ((JDBCPersistenceManager)pm).injectNodeID(1);
- pm.start();
-
- idm = new IDManager("TRANSACTION_ID", 10, pm);
- idm.start();
-
- ms = new SimpleMessageStore();
- ms.start();
-
- tr = new TransactionRepository(pm, ms, idm);
- tr.start();
-
- }
-
- public void tearDown() throws Exception
- {
- sc.stop();
-
- pm.stop();
- idm.stop();
- tr.stop();
- ms.stop();
-
- sc = null;
- pm = null;
- idm = null;
- ms = null;
- tr = null;
- super.tearDown();
- }
-
- public static void assertEqualSets(MessageReference[] a, List msgs)
- {
- assertEquals(a.length, msgs.size());
- List l = new ArrayList(msgs);
-
- for(int i = 0; i < a.length; i++)
- {
- for(Iterator j = l.iterator(); j.hasNext(); )
- {
- Object o = j.next();
- Message m = (Message)o;
-
- if (a[i].getMessage().getMessageID() == m.getMessageID() &&
- m.getPayload().equals(a[i].getMessage().getPayload()))
- {
- j.remove();
- break;
- }
- }
- }
-
- if (!l.isEmpty())
- {
- fail("Messages " + l + " do not match!");
- }
- }
-
- public static void assertEqualSets(Delivery[] a, List deliveries)
- {
- assertEquals(a.length, deliveries.size());
- List l = new ArrayList(deliveries);
-
- for(int i = 0; i < a.length; i++)
- {
- for(Iterator j = l.iterator(); j.hasNext(); )
- {
- Delivery d = (Delivery)j.next();
- MessageReference ref = d.getReference();
-
- if (a[i].getReference().getMessage().getMessageID() == ref.getMessage().getMessageID())
- {
- j.remove();
- break;
- }
- }
- }
-
- if (!l.isEmpty())
- {
- fail("Deliveries " + l + " do not match!");
- }
- }
-
-
- // Channel tests -------------------------------------------------
-
- public void testUnreliableSynchronousDeliveryTwoReceivers() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
- SimpleReceiver r1 = new SimpleReceiver("ONE", SimpleReceiver.ACKING);
- SimpleReceiver r2 = new SimpleReceiver("TWO", SimpleReceiver.ACKING);
-
- queue.getLocalDistributor().add(r1);
- queue.getLocalDistributor().add(r2);
-
- Delivery d = queue.handle(observer, createReference(0, false, "payload"), null);
-
- List l1 = r1.getMessages();
- List l2 = r2.getMessages();
- if (l2.isEmpty())
- {
- assertEquals(1, l1.size());
- Message m = (Message)l1.get(0);
- assertEquals("payload", m.getPayload());
- }
- else
- {
- assertTrue(l1.isEmpty());
- assertEquals(1, l2.size());
- Message m = (Message)l2.get(0);
- assertEquals("payload", m.getPayload());
- }
- }
-
-
- public void testReliableSynchronousDeliveryTwoReceivers() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
- SimpleReceiver r1 = new SimpleReceiver("ONE", SimpleReceiver.ACKING);
- SimpleReceiver r2 = new SimpleReceiver("TWO", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r1));
- assertTrue(queue.getLocalDistributor().add(r2));
-
- Delivery d = queue.handle(observer, createReference(0, true, "payload"), null);
-
- List l1 = r1.getMessages();
- List l2 = r2.getMessages();
- if (l2.isEmpty())
- {
- assertEquals(1, l1.size());
- Message m = (Message)l1.get(0);
- assertEquals("payload", m.getPayload());
- }
- else
- {
- assertTrue(l1.isEmpty());
- assertEquals(1, l2.size());
- Message m = (Message)l2.get(0);
- assertEquals("payload", m.getPayload());
- }
- }
-
- /*
- * If a channel has a set a receiver and remove is called with a different receiver
- * need to ensure the receiver is not removed (since it doesn't match)
- */
- public void testRemoveDifferentReceiver() throws Exception
- {
- Receiver receiver1 = new SimpleReceiver();
-
- Receiver receiver2 = new SimpleReceiver();
-
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- queue.getLocalDistributor().add(receiver1);
-
- assertTrue(queue.getLocalDistributor().contains(receiver1));
-
- queue.getLocalDistributor().remove(receiver1);
-
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- assertFalse(queue.getLocalDistributor().contains(receiver1));
-
- queue.getLocalDistributor().add(receiver1);
-
- assertTrue(queue.getLocalDistributor().contains(receiver1));
-
- queue.getLocalDistributor().remove(receiver2);
-
- assertTrue(queue.getLocalDistributor().contains(receiver1));
-
- }
-
- public void testClosedChannel() throws Exception
- {
- queue.close();
- try
- {
- queue.handle(null, createReference(0), null);
- fail("should throw exception");
- }
- catch(IllegalStateException e)
- {
- //OK
- }
- }
-
- public void testHandleNullRoutable() throws Exception
- {
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
- assertNull(queue.handle(observer, null, null));
- }
-
- //////////////////////////////////
- ////////////////////////////////// Test matrix
- //////////////////////////////////
-
- //
- // Non-recoverable channel
- //
-
- ////
- //// Zero receivers
- ////
-
- //////
- ////// Non-transacted send
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_1() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- Message sm = (Message)stored.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
-
- SimpleReceiver receiver = new SimpleReceiver("ACKING", SimpleReceiver.ACKING);
- queue.getLocalDistributor().add(receiver);
- queue.deliver();
- assertEquals(1, receiver.getMessages().size());
- assertEquals(0, ((Message)receiver.getMessages().get(0)).getMessageID());
-
- queue.deliver();
- assertEquals(1, receiver.getMessages().size());
-
-
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- List stored = queue.browse(null);
- assertEqualSets(refs, stored);
-
- SimpleReceiver receiver = new SimpleReceiver("ACKING", SimpleReceiver.ACKING);
- queue.getLocalDistributor().add(receiver);
- queue.deliver();
- assertEquals(10, receiver.getMessages().size());
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- assertEquals(i, ((Message)receiver.getMessages().get(i)).getMessageID());
- }
- receiver.clear();
-
- queue.deliver();
- assertEquals(0, receiver.getMessages().size());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_3_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- log.trace("ref is reliable:" + ref.getMessage().isReliable());
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- Message sm = (Message)stored.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
-
- queue.deliver();
-
- SimpleReceiver receiver = new SimpleReceiver("ACKING", SimpleReceiver.ACKING);
- queue.getLocalDistributor().add(receiver);
- queue.deliver();
- assertEquals(1, receiver.getMessages().size());
- assertEquals(0, ((Message)receiver.getMessages().get(0)).getMessageID());
-
- queue.deliver();
- assertEquals(1, receiver.getMessages().size());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_4_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // non-transacted send, reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEqualSets(refs, queue.browse(null));
-
- SimpleReceiver receiver = new SimpleReceiver("ACKING", SimpleReceiver.ACKING);
- queue.getLocalDistributor().add(receiver);
- queue.deliver();
- assertEquals(10, receiver.getMessages().size());
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- assertEquals(i, ((Message)receiver.getMessages().get(i)).getMessageID());
- }
- receiver.clear();
-
- queue.deliver();
- assertEquals(0, receiver.getMessages().size());
- }
-
-
-
- //////
- ////// Transacted send and commit
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_5() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- Message sm = (Message)stored.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
-
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_6() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- List stored = queue.browse(null);
- assertEqualSets(refs, stored);
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_7_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- Message sm = (Message)stored.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
-
- public void testNonRecoverableChannel_8_1_mixed_1() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES * 2];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i + NUMBER_OF_MESSAGES] = createReference(i + NUMBER_OF_MESSAGES , true, "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i + NUMBER_OF_MESSAGES], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- assertEqualSets(refs, queue.browse(null));
- }
-
-
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_8_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- assertEqualSets(refs, queue.browse(null));
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testNonRecoverableChannel_8_2_mixed() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- assertEqualSets(refs, queue.browse(null));
- }
-
-
- //////
- ////// Transacted send and rollback
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_9() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_10() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_11() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_12() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testNonRecoverableChannel_12_mixed() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- ////
- //// One receiver
- ////
-
- //////
- ////// ACKING receiver
- //////
-
- //////
- ////// Non-transacted send
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_13() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- queue.handle(observer, ref, null);
-
- assertTrue(queue.browse(null).isEmpty());
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message sm = (Message)received.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_14() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
-
- List received = r.getMessages();
- assertEqualSets(refs, received);
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_15_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- assertTrue(queue.browse(null).isEmpty());
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message sm = (Message)received.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_16_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // non-transacted send, reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- assertEqualSets(refs, r.getMessages());
- }
-
- //////
- ////// Transacted send and commit
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_17() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message sm = (Message)received.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_18() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
- assertEqualSets(refs, r.getMessages());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
-
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_19_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message sm = (Message)received.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
-
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testNonRecoverableChannel_20_1_mixed() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- // messages at the receiver
- assertEqualSets(refs, r.getMessages());
- }
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_20_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- assertEqualSets(refs, r.getMessages());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testNonRecoverableChannel_20_2_mixed() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- assertEqualSets(refs, r.getMessages());
- }
-
- //////
- ////// Transacted send and rollback
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_21() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_22() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_23() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_24() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testNonRecoverableChannel_24_mixed() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- //////
- ////// NACKING receiver
- //////
-
- //////
- ////// Non-transacted send
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- ////////////
- //////////// Non-transacted acknowledgment
- ////////////
-
- public void testNonRecoverableChannel_25() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- /**
- * The same test as before, but with a Receiver configured to acknowledge immediately
- * on the Delivery. Simulates a race condition in which the acknoledgment arrives before
- * the Delivery is returned to channel.
- *
- * @throws Throwable
- */
- public void testNonRecoverableChannel_25_race() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- r.setImmediateAsynchronousAcknowledgment(true);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- // the receiver should have returned a "done" delivery
- assertTrue(queue.browse(null).isEmpty());
-
- List messages = r.getMessages();
- assertEquals(1, messages.size());
- Message ackm = (Message)messages.get(0);
- assertEquals(0, ackm.getMessageID());
-
- // an extra acknowledgment should be discarded
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- ////////////
- //////////// Transacted acknowledgment and commit
- ////////////
-
- public void testNonRecoverableChannel_25_1() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- Transaction tx = tr.createTransaction();
-
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(0, deliveringCount);
- }
-
-
- ////////////
- //////////// Transacted acknowledgment and rollback
- ////////////
-
- public void testNonRecoverableChannel_25_2() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- Transaction tx = tr.createTransaction();
-
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- tx.rollback();
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- // acknowledge non-transactionally
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- //////////
- ////////// Multiple message
- //////////
-
- ////////////
- //////////// Non-transacted acknowledgment
- ////////////
-
- public void testNonRecoverableChannel_26() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEqualSets(refs, r.getMessages());
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
-
- }
-
- ////////////
- //////////// Transacted acknowledgment and commit
- ////////////
-
- public void testNonRecoverableChannel_26_1() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEqualSets(refs, r.getMessages());
-
- Transaction tx = tr.createTransaction();
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
- }
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- ////////////
- //////////// Transacted acknowledgment and rollback
- ////////////
-
- public void testNonRecoverableChannel_26_2() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEqualSets(refs, r.getMessages());
-
- Transaction tx = tr.createTransaction();
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
- }
-
- tx.rollback();
-
- // acknowledge non-transactionally
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- ////////////
- //////////// Non-transacted acknowledgment
- ////////////
-
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_27_1_2() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message rm = (Message)received.iterator().next();
- assertTrue(rm.isReliable());
- assertEquals(0, rm.getMessageID());
-
- r.acknowledge(rm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- ////////////
- //////////// Transacted acknowledgment
- ////////////
-
- ///////////
- /////////// Channel does NOT accept reliable messages
- ///////////
-
-
- // Doesn't make sense, the message won't be accepted anyway.
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
-
- public void testNonRecoverableChannel_27_2_2() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message rm = (Message)received.iterator().next();
- assertTrue(rm.isReliable());
- assertEquals(0, rm.getMessageID());
-
- Transaction tx = tr.createTransaction();
-
- r.acknowledge(rm, tx);
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- ////////////
- //////////// Non-transacted acknowledgment
- ////////////
-
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_28_1_2() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // non-transacted send, reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEqualSets(refs, r.getMessages());
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- ////////////
- //////////// Transacted acknowledgment
- ////////////
-
- ///////////
- /////////// Channel does NOT accept reliable messages
- ///////////
-
- // Doesn't make sense, the message won't be accepted anyway.
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_28_2_2() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // non-transacted send, reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEqualSets(refs, r.getMessages());
-
- Transaction tx = tr.createTransaction();
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- r.acknowledge(ackm, tx);
- }
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- //////
- ////// Transacted send and commit
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_29() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_30() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- assertEqualSets(refs, r.getMessages());
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- ///////////
- /////////// Channel does accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_31_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message rm = (Message)received.iterator().next();
- assertTrue(rm.isReliable());
- assertEquals(0, rm.getMessageID());
- }
-
-
- //////////
- ////////// Multiple message
- //////////
-
-
-
-
- ///////////
- /////////// Channel accepts reliable messages
- ///////////
-
- public void testNonRecoverableChannel_32_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(NUMBER_OF_MESSAGES, deliveringCount);
-
- assertEqualSets(refs, r.getMessages());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testNonRecoverableChannel_32_2_mixed() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(NUMBER_OF_MESSAGES, deliveringCount);
- assertEqualSets(refs, r.getMessages());
- }
-
-
-
- //////
- ////// Transacted send and rollback
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_33() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_34() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testNonRecoverableChannel_35() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testNonRecoverableChannel_36() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testNonRecoverableChannel_36_mixed() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
-
- ////
- //// Zero receivers
- ////
-
- //////
- ////// Non-transacted send
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_1() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- Message sm = (Message)stored.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_2() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
-
- }
-
- assertEqualSets(refs, queue.browse(null));
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_3() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- Message sm = (Message)stored.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_4() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // non-transacted send, reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEqualSets(refs, queue.browse(null));
-
- }
-
- //////
- ////// Transacted send and commit
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_5() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- Message sm = (Message)stored.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_6() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- assertEqualSets(refs, queue.browse(null));
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_7() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- Message sm = (Message)stored.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_8() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- assertEqualSets(refs, queue.browse(null));
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testRecoverableChannel_8_mixed() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- assertEqualSets(refs, queue.browse(null));
- }
-
-
- //////
- ////// Transacted send and rollback
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_9() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_10() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_11() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_12() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testRecoverableChannel_12_mixed() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- tx.rollback();
-
- // still no messages in the channel
- assertEquals(0, queue.browse(null).size());
- }
-
- ////
- //// One receiver
- ////
-
- //////
- ////// ACKING receiver
- //////
-
- //////
- ////// Non-transacted send
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_13() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- assertTrue(queue.browse(null).isEmpty());
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message sm = (Message)received.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_14() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
-
- List received = r.getMessages();
- assertEqualSets(refs, received);
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_15() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- assertTrue(queue.browse(null).isEmpty());
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message sm = (Message)received.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_16() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // non-transacted send, reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- assertEqualSets(refs, r.getMessages());
- }
-
- //////
- ////// Transacted send and commit
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_17() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message sm = (Message)received.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
-
- public void testRecoverableChannel_17_1() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- BrokenReceiver brokenReceiver = new BrokenReceiver(2);
- assertTrue(queue.getLocalDistributor().add(brokenReceiver));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
-
- log.debug("sending message 1");
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- ref = createReference(1, false, "payload");
-
- log.debug("sending message 2");
- queue.handle(observer, ref, tx);
-
- ref = createReference(2, false, "payload");
-
- log.debug("sending message 3");
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- tx.commit();
-
- assertEquals(2, queue.browse(null).size());
- assertEquals(1, brokenReceiver.getMessages().size());
- }
-
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_18() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
- assertEqualSets(refs, r.getMessages());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_19() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- List received = r.getMessages();
- assertEquals(1, received.size());
- Message sm = (Message)received.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_20() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- assertEqualSets(refs, r.getMessages());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testRecoverableChannel_20_mixed() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- assertEqualSets(refs, r.getMessages());
- }
-
-
- //////
- ////// Transacted send and rollback
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_21() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_22() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_23() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_24() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testRecoverableChannel_24_mixed() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an ACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("AckingReceiver", SimpleReceiver.ACKING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- //////
- ////// NACKING receiver
- //////
-
- //////
- ////// Non-transacted send
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- ////////////
- //////////// Non-transacted acknowledgment
- ////////////
-
- public void testRecoverableChannel_25() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- /**
- * The same test as before, but with a Receiver configured to acknowledge immediately
- * on the Delivery. Simulates a race condition in which the acknoledgment arrives before
- * the Delivery is returned to channel.
- *
- * @throws Throwable
- */
- public void testRecoverableChannel_25_race() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- r.setImmediateAsynchronousAcknowledgment(true);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- // the receiver should have returned a "done" delivery
- assertTrue(queue.browse(null).isEmpty());
-
- List messages = r.getMessages();
- assertEquals(1, messages.size());
- Message ackm = (Message)messages.get(0);
- assertEquals(0, ackm.getMessageID());
-
- // an extra acknowledgment should be discarded
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- ////////////
- //////////// Transacted acknowledgment and commit
- ////////////
-
- public void testRecoverableChannel_25_1() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- Transaction tx = tr.createTransaction();
-
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- ////////////
- //////////// Transacted acknowledgment and rollback
- ////////////
-
- public void testRecoverableChannel_25_2() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, non-reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- Transaction tx = tr.createTransaction();
-
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- tx.rollback();
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- // acknowledge non-transactionally
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- //////////
- ////////// Multiple message
- //////////
-
- ////////////
- //////////// Non-transacted acknowledgment
- ////////////
-
- public void testRecoverableChannel_26() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
- assertEqualSets(refs, r.getMessages());
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
-
- }
-
- ////////////
- //////////// Transacted acknowledgment and commit
- ////////////
-
- public void testRecoverableChannel_26_1() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
- assertEqualSets(refs, r.getMessages());
-
- Transaction tx = tr.createTransaction();
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- ////////////
- //////////// Transacted acknowledgment and rollback
- ////////////
-
- public void testRecoverableChannel_26_2() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // non-transacted send, non-reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
- assertEqualSets(refs, r.getMessages());
-
- Transaction tx = tr.createTransaction();
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
-
- tx.rollback();
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
-
- // acknowledge non-transactionally
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- ////////////
- //////////// Non-transacted acknowledgment
- ////////////
-
- public void testRecoverableChannel_27() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- /**
- * Test duplicate acknowledgment.
- */
- public void testRecoverableChannel_27_Duplicate_ACK() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- queue.handle(observer, ref, null);
-
- Message ackm = (Message)r.getMessages().get(0);
-
- // acknowledge once
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
-
- // acknowledge twice
- try
- {
- r.acknowledge(ackm, null);
- }
- catch(IllegalStateException e)
- {
- // OK
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- /**
- * The same test as before, but with a Receiver configured to acknowledge immediately
- * on the Delivery. Simulates a race condition in which the acknoledgment arrives before
- * the Delivery is returned to channel.
- *
- * @throws Throwable
- */
- public void testRecoverableChannel_27_race() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- r.setImmediateAsynchronousAcknowledgment(true);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- // the receiver should have returned a "done" delivery
- assertTrue(queue.browse(null).isEmpty());
-
- List messages = r.getMessages();
- assertEquals(1, messages.size());
- Message ackm = (Message)messages.get(0);
- assertEquals(0, ackm.getMessageID());
-
- // Acknowledgment handling implemenation is NOT idempotent, the channel DOES NOT allow
- // extraneous duplicate acknowlegments, so we test for that.
-
- try
- {
- r.acknowledge(ackm, null);
- }
- catch(IllegalStateException e)
- {
- // OK
- log.trace(e);
-
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- ////////////
- //////////// Transacted acknowledgment and commit
- ////////////
-
- public void testRecoverableChannel_27_1() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- Transaction tx = tr.createTransaction();
-
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- ////////////
- //////////// Transacted acknowledgment and rollback
- ////////////
-
- public void testRecoverableChannel_27_2() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-transacted send, reliable message, one message
- Delivery delivery = queue.handle(observer, ref, null);
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- Transaction tx = tr.createTransaction();
-
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- tx.rollback();
-
- deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- // acknowledge non-transactionally
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- //////////
- ////////// Multiple message
- //////////
-
- ////////////
- //////////// Non-transacted acknowledgment
- ////////////
-
- public void testRecoverableChannel_28() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // non-transacted send, reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
-
- assertEqualSets(refs, r.getMessages());
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- ////////////
- //////////// Transacted acknowledgment and commit
- ////////////
-
- public void testRecoverableChannel_28_1() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // non-transacted send, reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
- assertEqualSets(refs, r.getMessages());
-
- Transaction tx = tr.createTransaction();
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
-
- tx.commit();
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- ////////////
- //////////// Transacted acknowledgment and rollback
- ////////////
-
- public void testRecoverableChannel_28_2() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // non-transacted send, reliable message, multiple messages
- Delivery delivery = queue.handle(observer, refs[i], null);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
- assertEqualSets(refs, r.getMessages());
-
- Transaction tx = tr.createTransaction();
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // transacted acknowledgment
- r.acknowledge(ackm, tx);
- }
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
-
- tx.rollback();
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
-
- // acknowledge non-transactionally
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- //////
- ////// Transacted send and commit
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_29() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_30() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
- assertEqualSets(refs, r.getMessages());
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_31() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List acknowledging = r.getMessages();
- assertEquals(1, acknowledging.size());
- Message ackm = (Message)acknowledging.get(0);
- assertEquals(0, ackm.getMessageID());
-
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_32() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel yet
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
- assertEqualSets(refs, r.getMessages());
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testRecoverableChannel_32_mixed() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.commit();
-
- assertEquals(NUMBER_OF_MESSAGES, queue.getDeliveringCount());
- assertEqualSets(refs, r.getMessages());
-
- for(Iterator i = r.getMessages().iterator(); i.hasNext();)
- {
- Message ackm = (Message)i.next();
- // non-transacted acknowledgment
- r.acknowledge(ackm, null);
- }
-
- assertTrue(queue.browse(null).isEmpty());
- }
-
-
- //////
- ////// Transacted send and rollback
- //////
-
- ////////
- //////// Non-reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_33() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, non-reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_34() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, false, "payload" + i);
-
- // transacted send, non-reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- ////////
- //////// Reliable message
- ////////
-
- //////////
- ////////// One message
- //////////
-
- public void testRecoverableChannel_35() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- // transacted send, reliable message, one message
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, ref, tx);
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- //////////
- ////////// Multiple message
- //////////
-
- public void testRecoverableChannel_36() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- refs[i] = createReference(i, true, "payload" + i);
-
- // transacted send, reliable message, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- /**
- * This is a variation where I send a mixture of reliable and non-reliable messages,
- */
- public void testRecoverableChannel_36_mixed() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // add an NACKING receiver to the channel
- SimpleReceiver r = new SimpleReceiver("NackingReceiver", SimpleReceiver.ACCEPTING);
- assertTrue(queue.getLocalDistributor().add(r));
-
-
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- Transaction tx = tr.createTransaction();
-
- MessageReference[] refs = new MessageReference[NUMBER_OF_MESSAGES];
- for(int i = 0; i < NUMBER_OF_MESSAGES; i++)
- {
- // send a mixture of reliable and non-reliable messages
- refs[i] = createReference(i, (i % 2 == 1), "payload" + i);
-
- // transacted send, reliable/non-reliable messages, multiple messages
- // for a transactional send, handle() return value is unspecified
- queue.handle(observer, refs[i], tx);
- }
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
-
- tx.rollback();
-
- // no messages in the channel
- assertEquals(0, queue.browse(null).size());
-
- // no message at the receiver
- assertTrue(r.getMessages().isEmpty());
- }
-
- ///////////////////////////////
- /////////////////////////////// Add receiver tests
- ///////////////////////////////
- ///////////////////////////////
- ///////////////////////////////
-
- //
- // Non-recoverable channel
- //
-
- ////
- //// Non-reliable message
- ////
-
- //////
- ////// Broken receiver
- //////
-
- public void testAddReceiver_1() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-recoverable channel, non-reliable message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
-
- SimpleReceiver receiver = new SimpleReceiver("BrokenReceiver", SimpleReceiver.BROKEN);
- assertTrue(queue.getLocalDistributor().add(receiver));
-
- stored = queue.browse(null);
- assertEquals(1, stored.size());
- Message sm = (Message)stored.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
-
- assertTrue(receiver.getMessages().isEmpty());
- }
-
- //////
- ////// ACKING receiver
- //////
-
- public void testAddReceiver_2() throws Exception
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-recoverable channel, non-reliable message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- SimpleReceiver receiver =
- new SimpleReceiver("ACKINGReceiver", SimpleReceiver.ACKING, queue);
- assertTrue(queue.getLocalDistributor().add(receiver));
-
- assertEquals(1, queue.browse(null).size());
-
- // receiver explicitely asks for message
- receiver.requestMessages();
-
- assertTrue(queue.browse(null).isEmpty());
-
- List messages = receiver.getMessages();
- assertEquals(1, messages.size());
- Message sm = (Message)messages.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////
- ////// NACKING receiver
- //////
-
- public void testAddReceiver_3() throws Throwable
- {
- if (queue.isRecoverable())
- {
- // we test only non-recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, false, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-recoverable channel, non-reliable message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- SimpleReceiver receiver =
- new SimpleReceiver("NACKINGReceiver", SimpleReceiver.ACCEPTING, queue);
- assertTrue(queue.getLocalDistributor().add(receiver));
-
- assertEquals(1, queue.browse(null).size());
-
- // receiver explicitely asks for message
- receiver.requestMessages();
-
- int deliveringCount = queue.getDeliveringCount();
- assertEquals(1, deliveringCount);
-
- List messages = receiver.getMessages();
- assertEquals(1, messages.size());
- Message sm = (Message)messages.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
-
- receiver.acknowledge(sm, null);
-
- assertTrue(queue.browse(null).isEmpty());
-
- messages = receiver.getMessages();
- assertEquals(1, messages.size());
- sm = (Message)messages.iterator().next();
- assertFalse(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //
- // Recoverable channel
- //
-
- ////
- //// Reliable message
- ////
-
- public void testAddReceiver_4() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-recoverable channel, non-reliable message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
-
- SimpleReceiver receiver = new SimpleReceiver("BrokenReceiver", SimpleReceiver.BROKEN);
- assertTrue(queue.getLocalDistributor().add(receiver));
-
- stored = queue.browse(null);
- assertEquals(1, stored.size());
- Message sm = (Message)stored.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
-
- assertTrue(receiver.getMessages().isEmpty());
- }
-
- //////
- ////// ACKING receiver
- //////
-
- public void testAddReceiver_5() throws Exception
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-recoverable channel, non-reliable message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- SimpleReceiver receiver =
- new SimpleReceiver("ACKINGReceiver", SimpleReceiver.ACKING, queue);
- assertTrue(queue.getLocalDistributor().add(receiver));
-
- // receiver explicitely asks for message
- receiver.requestMessages();
-
- assertTrue(queue.browse(null).isEmpty());
-
- List messages = receiver.getMessages();
- assertEquals(1, messages.size());
- Message sm = (Message)messages.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- //////
- ////// NACKING receiver
- //////
-
- public void testAddReceiver_6() throws Throwable
- {
- if (!queue.isRecoverable())
- {
- // we test only recoverable channels now
- return;
- }
-
- // the channel has no receivers
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
-
- MessageReference ref = createReference(0, true, "payload");
- SimpleDeliveryObserver observer = new SimpleDeliveryObserver();
-
- // non-recoverable channel, non-reliable message
- Delivery delivery = queue.handle(observer, ref, null);
-
- List stored = queue.browse(null);
- assertEquals(1, stored.size());
-
- SimpleReceiver receiver =
- new SimpleReceiver("NACKINGReceiver", SimpleReceiver.ACCEPTING, queue);
- assertTrue(queue.getLocalDistributor().add(receiver));
-
- assertEquals(1, queue.browse(null).size());
-
- // receiver explicitely asks for message
- receiver.requestMessages();
-
- assertEquals(1, queue.getDeliveringCount());
-
- List messages = receiver.getMessages();
- assertEquals(1, messages.size());
- Message sm = (Message)messages.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
-
- receiver.acknowledge(sm, null);
-
- assertTrue(queue.browse(null).isEmpty());
-
- messages = receiver.getMessages();
- assertEquals(1, messages.size());
- sm = (Message)messages.iterator().next();
- assertTrue(sm.isReliable());
- assertEquals(0, sm.getMessageID());
- }
-
- // Distributor tests ---------------------------------------------
-
- public void testAddOneReceiver()
- {
- Receiver r = new SimpleReceiver("ONE");
-
- assertTrue(queue.getLocalDistributor().add(r));
- assertFalse(queue.getLocalDistributor().add(r));
-
- assertTrue(queue.getLocalDistributor().contains(r));
-
- Iterator i = queue.getLocalDistributor().iterator();
- assertEquals(r, i.next());
- assertFalse(i.hasNext());
-
- queue.getLocalDistributor().clear();
- assertFalse(queue.getLocalDistributor().iterator().hasNext());
- }
-
- public void testRemoveInexistentReceiver()
- {
- assertFalse(queue.getLocalDistributor().remove(new SimpleReceiver("INEXISTENT")));
- }
-
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
-// protected abstract void crashChannel() throws Exception;
-//
-// protected abstract void recoverChannel() throws Exception;
-
- // Private -------------------------------------------------------
-
- private MessageReference createReference(long id, boolean reliable, Serializable payload)
- {
- return ms.reference(CoreMessageFactory.createCoreMessage(id, reliable, payload));
- }
-
- private MessageReference createReference(long id)
- {
- return ms.reference(CoreMessageFactory.createCoreMessage(id));
- }
-
- // Inner classes -------------------------------------------------
-
-}
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/NonRecoverableMessagingQueueTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/NonRecoverableMessagingQueueTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/NonRecoverableMessagingQueueTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,75 +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.test.messaging.core;
-
-import org.jboss.messaging.core.impl.MessagingQueue;
-
-/**
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 2386 $</tt>
- *
- * $Id: NonRecoverablePagingFilteredQueueTest.java 2386 2007-02-21 18:07:44Z timfox $
- */
-public class NonRecoverableMessagingQueueTest extends MessagingQueueTestBase
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
-
- // Constructors --------------------------------------------------
-
- public NonRecoverableMessagingQueueTest(String name)
- {
- super(name);
- }
-
- // ChannelTestBase overrides ------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- queue = new MessagingQueue(1, "queue1", 1, ms, pm, false, -1, null, false);
- queue.activate();
- }
-
- public void tearDown() throws Exception
- {
- queue.close();
- super.tearDown();
- }
-
- // Public --------------------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
-
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -29,8 +29,6 @@
import org.jboss.messaging.core.contract.Condition;
import org.jboss.messaging.core.contract.ConditionFactory;
import org.jboss.messaging.core.contract.FilterFactory;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.MessageStore;
import org.jboss.messaging.core.contract.PersistenceManager;
import org.jboss.messaging.core.contract.PostOffice;
@@ -42,6 +40,8 @@
import org.jboss.messaging.core.impl.postoffice.MessagingPostOffice;
import org.jboss.messaging.core.impl.tx.Transaction;
import org.jboss.messaging.core.impl.tx.TransactionRepository;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
import org.jboss.test.messaging.MessagingTestCase;
import org.jboss.test.messaging.core.postoffice.ClusteredPersistenceServiceConfigFileJChannelFactory;
import org.jboss.test.messaging.tools.container.ServiceContainer;
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/RecoverableMessagingQueueTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/RecoverableMessagingQueueTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/RecoverableMessagingQueueTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -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.test.messaging.core;
-
-import org.jboss.messaging.core.impl.MessagingQueue;
-
-/**
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1019 $</tt>
- *
- * $Id: RecoverableQueueTest.java 1019 2006-07-17 17:15:04Z timfox $
- */
-public class RecoverableMessagingQueueTest extends MessagingQueueTestBase
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public RecoverableMessagingQueueTest(String name)
- {
- super(name);
- }
-
- // ChannelTestBase overrides ------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- queue = new MessagingQueue(1, "queue1", 1, ms, pm, true, -1, null, false);
- queue.activate();
- }
-
- public void tearDown() throws Exception
- {
- queue.close();
- super.tearDown();
- }
-
- // Public --------------------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/RoundRobinDistributorTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/RoundRobinDistributorTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/RoundRobinDistributorTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,562 +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.test.messaging.core;
-
-import org.jboss.messaging.core.contract.Delivery;
-import org.jboss.messaging.core.contract.DeliveryObserver;
-import org.jboss.messaging.core.contract.Distributor;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.core.contract.MessageStore;
-import org.jboss.messaging.core.contract.Receiver;
-import org.jboss.messaging.core.impl.RoundRobinDistributor;
-import org.jboss.messaging.core.impl.SimpleDelivery;
-import org.jboss.messaging.core.impl.message.SimpleMessageStore;
-import org.jboss.messaging.core.impl.tx.Transaction;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.util.CoreMessageFactory;
-
-/**
- * @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: 1 $</tt>
- * $Id: $
- */
-public class RoundRobinDistributorTest extends MessagingTestCase
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- protected MessageStore ms;
-
- // Constructors --------------------------------------------------
-
- public RoundRobinDistributorTest(String name)
- {
- super(name);
- }
-
- // ChannelTestBase overrides ------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- ms = new SimpleMessageStore();
-
- ms.start();
- }
-
- public void tearDown() throws Exception
- {
- super.tearDown();
-
- ms.stop();
- }
-
- // Public --------------------------------------------------------
-
- public void testAllAccepting()
- {
- Distributor distributor = new RoundRobinDistributor();
-
- final int numReceivers = 10;
-
- SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
-
- for (int i = 0; i < numReceivers; i++)
- {
- receivers[i] = new SimpleReceiver();
-
- distributor.add(receivers[i]);
- }
-
- Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
-
- MessageReference ref = ms.reference(msg);
-
- Delivery del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 0);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 1);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 2);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 3);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 4);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 5);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 6);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 7);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 8);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 9);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 0);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 1);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 2);
- resetReceivers(receivers);
-
- }
-
- public void testSomeClosed()
- {
- Distributor distributor = new RoundRobinDistributor();
-
- final int numReceivers = 10;
-
- SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
-
- for (int i = 0; i < numReceivers; i++)
- {
- receivers[i] = new SimpleReceiver();
-
- distributor.add(receivers[i]);
- }
-
- receivers[2].closed = true;
-
- receivers[5].closed = true;
- receivers[6].closed = true;
-
- receivers[9].closed = true;
-
- Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
-
- MessageReference ref = ms.reference(msg);
-
- Delivery del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 0);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 1);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 3);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 4);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 7);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 8);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 0);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 1);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 3);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 4);
- resetReceivers(receivers);
-
-
- }
-
- public void testAllClosed()
- {
- Distributor distributor = new RoundRobinDistributor();
-
- final int numReceivers = 10;
-
- SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
-
- for (int i = 0; i < numReceivers; i++)
- {
- receivers[i] = new SimpleReceiver();
-
- receivers[i].closed = true;
-
- distributor.add(receivers[i]);
- }
-
-
- Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
-
- MessageReference ref = ms.reference(msg);
-
- Delivery del = distributor.handle(null, ref, null);
- assertNull(del);
-
- del = distributor.handle(null, ref, null);
- assertNull(del);
-
- del = distributor.handle(null, ref, null);
- assertNull(del);
-
-
-
- }
-
- public void testSomeNoSelectorMatch()
- {
- Distributor distributor = new RoundRobinDistributor();
-
- final int numReceivers = 10;
-
- SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
-
- for (int i = 0; i < numReceivers; i++)
- {
- receivers[i] = new SimpleReceiver();
-
- distributor.add(receivers[i]);
- }
-
- receivers[2].selectorMatches = false;
-
- receivers[5].selectorMatches = false;
- receivers[6].selectorMatches = false;
-
- receivers[9].selectorMatches = false;
-
- Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
-
- MessageReference ref = ms.reference(msg);
-
- Delivery del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 0);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 1);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 3);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 4);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 7);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 8);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 0);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 1);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 3);
- resetReceivers(receivers);
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- checkReceiverGotRef(receivers, 4);
- resetReceivers(receivers);
-
- }
-
- public void testAllNoSelectorMatch()
- {
- Distributor distributor = new RoundRobinDistributor();
-
- final int numReceivers = 10;
-
- SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
-
- for (int i = 0; i < numReceivers; i++)
- {
- receivers[i] = new SimpleReceiver();
-
- receivers[i].selectorMatches = false;
-
- distributor.add(receivers[i]);
- }
-
-
- Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
-
- MessageReference ref = ms.reference(msg);
-
- Delivery del = distributor.handle(null, ref, null);
- assertNotNull(del);
- assertFalse(del.isSelectorAccepted());
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- assertFalse(del.isSelectorAccepted());
-
- del = distributor.handle(null, ref, null);
- assertNotNull(del);
- assertFalse(del.isSelectorAccepted());
-
- }
-
- public void testNoReceivers()
- {
- Distributor distributor = new RoundRobinDistributor();
-
- Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
-
- MessageReference ref = ms.reference(msg);
-
- Delivery del = distributor.handle(null, ref, null);
- assertNull(del);
-
- del = distributor.handle(null, ref, null);
- assertNull(del);
-
- del = distributor.handle(null, ref, null);
- assertNull(del);
- }
-
-
- /**
- * http://jira.jboss.org/jira/browse/JBMESSAGING-491
- */
- public void testDeadlock() throws Exception
- {
- final Distributor distributor = new RoundRobinDistributor();
-
- LockingReceiver receiver = new LockingReceiver();
- distributor.add(receiver);
-
- final Thread t = new Thread(new Runnable()
- {
- public void run()
- {
- // sends the message to the router on a separate thread
-
- Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
-
- MessageReference ref = ms.reference(msg);
-
- distributor.handle(null, ref, null);
- }
- }, "Message sending thread");
-
- // start the sending tread, which will immediately grab the router's "receivers" lock, and it
- // will sleep for 3 seconds before attempting to grab LockingReceiver's lock.
- t.start();
-
-
- // in the mean time, the main thread immediately grabs receiver's lock ...
-
- synchronized(receiver.getLock())
- {
- // ... sleeps for 500 ms to allow sender thread time to grab router's "receivers" lock
- Thread.sleep(500);
-
- // ... and try to remove the receiver form router
- distributor.remove(receiver);
- }
-
- // normally, receiver removal should be immediate, as the router releases receiver's lock
- // immediately, so test should complete. Pre-JBMESSAGING-491, the test deadlocks.
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- protected void checkReceiverGotRef(SimpleReceiver[] receivers, int pos)
- {
- for (int i = 0; i < receivers.length; i++)
- {
- SimpleReceiver r = receivers[i];
-
- if (i == pos)
- {
- assertTrue(r.gotRef);
- }
- else
- {
- assertFalse(r.gotRef);
- }
- }
- }
-
- protected void resetReceivers(SimpleReceiver[] receivers)
- {
- for (int i = 0; i < receivers.length; i++)
- {
- SimpleReceiver r = receivers[i];
-
- r.gotRef = false;
- }
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
- class LockingReceiver implements Receiver
- {
- private Object lock;
-
- public LockingReceiver()
- {
- lock = new Object();
- }
-
- public Delivery handle(DeliveryObserver observer, MessageReference ref, Transaction tx)
- {
- // The delivering thread needs to grab the receiver's lock to complete delivery; this
- // is how Messaging receivers are written, anyway. We simulate the race condition by
- // putting the sending thread to sleep for 3 seconds before allowing it to attempt to
- // grab the lock
-
- try
- {
- Thread.sleep(3000);
- }
- catch(InterruptedException e)
- {
- // this shouldn't happen in the test
- return null;
- }
-
- synchronized(lock)
- {
- return new SimpleDelivery(null, null, true, false);
- }
- }
-
- public Object getLock()
- {
- return lock;
- }
- }
-
- class SimpleReceiver implements Receiver
- {
- boolean selectorMatches = true;
-
- boolean closed;
-
- boolean gotRef;
-
- public Delivery handle(DeliveryObserver observer, MessageReference ref, Transaction tx)
- {
- if (closed)
- {
- return null;
- }
-
- Delivery del = new SimpleDelivery(null, null, selectorMatches, false);
-
- if (selectorMatches)
- {
- gotRef = true;
- }
-
- return del;
- }
-
- }
-
-
-
-
-}
-
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleChannel.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleChannel.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleChannel.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,268 +0,0 @@
-/**
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-package org.jboss.test.messaging.core;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Channel;
-import org.jboss.messaging.core.contract.Delivery;
-import org.jboss.messaging.core.contract.DeliveryObserver;
-import org.jboss.messaging.core.contract.Filter;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.core.contract.MessageStore;
-import org.jboss.messaging.core.contract.Receiver;
-import org.jboss.messaging.core.impl.tx.Transaction;
-import org.jboss.messaging.util.NotYetImplementedException;
-
-/**
- * A test Channel implementation.
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class SimpleChannel implements Channel
-{
- // Constants -----------------------------------------------------
-
- private static final Logger log = Logger.getLogger(SimpleChannel.class);
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private long channelID;
- private MessageStore ms;
- private boolean deliveryNotification = false;
-
- // Constructors --------------------------------------------------
-
- public SimpleChannel(long channelID, MessageStore ms)
- {
- this.channelID = channelID;
- this.ms = ms;
- }
-
- // Channel implementation ----------------------------------------
-
- public long getChannelID()
- {
- return channelID;
- }
-
- public boolean isRecoverable()
- {
- throw new NotYetImplementedException();
- }
-
- public boolean acceptReliableMessages()
- {
- throw new NotYetImplementedException();
- }
-
- public List browse()
- {
- throw new NotYetImplementedException();
- }
-
- public List browse(Filter filter)
- {
- throw new NotYetImplementedException();
- }
-
- public MessageStore getMessageStore()
- {
- return ms;
- }
-
- public void deliver()
- {
- log.debug("deliver()");
- deliveryNotification = true;
- }
-
-
- public void close()
- {
- throw new NotYetImplementedException();
- }
-
-
- public void add(Delivery delivery)
- {
- throw new NotYetImplementedException();
- }
-
- public void removeAllReferences()
- {
- }
-
-
- // DeliveryObserver implementation -------------------------------
-
- public void acknowledge(Delivery d, Transaction tx)
- {
- throw new NotYetImplementedException();
- }
-
-
- public void acknowledgeNoPersist(Delivery d) throws Throwable
- {
- throw new NotYetImplementedException();
- }
-
-
- public void cancel(Delivery d) throws Exception
- {
- throw new NotYetImplementedException();
- }
-
- // Receiver implementation ---------------------------------------
-
- public Delivery handle(DeliveryObserver observer, MessageReference ref, Transaction tx)
- {
- throw new NotYetImplementedException();
- }
-
- // Distributor implementation ------------------------------------
-
- public boolean contains(Receiver receiver)
- {
- throw new NotYetImplementedException();
- }
-
- public Iterator iterator()
- {
- throw new NotYetImplementedException();
- }
-
- public boolean add(Receiver receiver)
- {
- throw new NotYetImplementedException();
- }
-
- public boolean remove(Receiver receiver)
- {
- throw new NotYetImplementedException();
- }
-
- public void clear()
- {
- throw new NotYetImplementedException();
- }
-
- // Public --------------------------------------------------------
-
- public void reset()
- {
- deliveryNotification = false;
- }
-
- public boolean wasNotifiedToDeliver()
- {
- return deliveryNotification;
- }
-
- public String toString()
- {
- return "SimpleChannel[" + getChannelID() + "]";
- }
-
- public List delivering(Filter filter)
- {
- throw new NotYetImplementedException();
- }
-
- public void load() throws Exception
- {
- throw new NotYetImplementedException();
- }
-
- public int getMessageCount()
- {
- throw new NotYetImplementedException();
- }
-
- public List undelivered(Filter filter)
- {
- throw new NotYetImplementedException();
- }
-
- public int getNumberOfReceivers()
- {
- throw new NotYetImplementedException();
- }
-
- public void activate()
- {
- throw new NotYetImplementedException();
- }
-
- public void deactivate()
- {
- throw new NotYetImplementedException();
- }
-
- public void unload() throws Exception
- {
- throw new NotYetImplementedException();
- }
-
- public boolean isActive()
- {
- throw new UnsupportedOperationException();
- }
-
- public List recoverDeliveries(List messageIds)
- {
- throw new UnsupportedOperationException();
- }
-
- public void addDelivery(Delivery del)
- {
- throw new UnsupportedOperationException();
- }
-
- public int getDeliveringCount()
- {
- throw new UnsupportedOperationException();
- }
-
- public int getMaxSize()
- {
- throw new UnsupportedOperationException();
- }
-
- public int getMessagesAdded()
- {
- throw new UnsupportedOperationException();
- }
-
- public void setMaxSize(int newSize)
- {
- throw new UnsupportedOperationException();
- }
-
- public int getScheduledCount()
- {
- throw new UnsupportedOperationException();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleDeliveryObserver.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleDeliveryObserver.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleDeliveryObserver.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,132 +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.test.messaging.core;
-
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Delivery;
-import org.jboss.messaging.core.contract.DeliveryObserver;
-import org.jboss.messaging.core.impl.tx.Transaction;
-
-/**
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @version <tt>$Revision$</tt>
- * $Id$
- */
-public class SimpleDeliveryObserver implements DeliveryObserver
-{
- // Constants -----------------------------------------------------
-
- private static final Logger log = Logger.getLogger(SimpleDeliveryObserver.class);
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- protected Delivery toBeCancelled;
- protected Delivery toBeAcknowledged;
-
- // Constructors --------------------------------------------------
-
- // DeliveryObserver implementation --------------------------
-
- public synchronized void acknowledge(Delivery d, Transaction tx)
- {
- if (toBeAcknowledged == d)
- {
- toBeAcknowledged = null;
- notifyAll();
- }
- }
-
- public void acknowledgeNoPersist(Delivery d) throws Throwable
- {
- // TODO Auto-generated method stub
- }
-
- public synchronized void cancel(Delivery d)
- {
- if (toBeCancelled == d)
- {
- toBeCancelled = null;
- notifyAll();
- }
- return;
- }
-
- // Public --------------------------------------------------------
-
- public synchronized boolean waitForAcknowledgment(Delivery delivery) throws Exception
- {
- return waitForAcknowledgment(delivery, 0);
- }
-
- /**
- * Waits until the delivery is positively acknowledged (done), or timeout expires. If the
- * delivery is already done, exits immediately.
- * @return true if a positive acknowledgment was received before or during the method call,
- * false if the method exists with timeout.
- */
- public synchronized boolean waitForAcknowledgment(Delivery delivery, long timeout)
- throws Exception
- {
- try
- {
- if (toBeAcknowledged != null)
- {
- throw new IllegalStateException("already waiting for another delivery acknowlegment");
- }
-
- toBeAcknowledged = delivery;
-
- if (timeout <= 0)
- {
- this.wait();
- }
- else
- {
- this.wait(timeout);
- }
-
- if (toBeAcknowledged == null)
- {
- return true;
- }
- else
- {
- log.warn("exiting on timeout");
- return false;
- }
- }
- finally
- {
- toBeAcknowledged = null;
- }
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleFilter.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleFilter.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleFilter.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,55 +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.test.messaging.core;
-
-import org.jboss.messaging.core.contract.Filter;
-import org.jboss.messaging.core.contract.Message;
-
-/**
- * A SimpleFilter
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public class SimpleFilter implements Filter
-{
- long idMatch;
-
- public SimpleFilter(long idMatch)
- {
- this.idMatch = idMatch;
- }
-
- public boolean accept(Message message)
- {
- return message.getMessageID() == idMatch;
- }
-
- public String getFilterString()
- {
- return String.valueOf(idMatch);
- }
-
-}
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleFilterFactory.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleFilterFactory.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleFilterFactory.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,44 +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.test.messaging.core;
-
-import org.jboss.messaging.core.contract.Filter;
-import org.jboss.messaging.core.contract.FilterFactory;
-
-/**
- * A SimpleFilterFactory
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public class SimpleFilterFactory implements FilterFactory
-{
-
- public Filter createFilter(String filterString) throws Exception
- {
- return filterString == null ? null : new SimpleFilter(Long.valueOf(filterString).longValue());
- }
-
-}
Deleted: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -1,439 +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.test.messaging.core;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Channel;
-import org.jboss.messaging.core.contract.Delivery;
-import org.jboss.messaging.core.contract.DeliveryObserver;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
-import org.jboss.messaging.core.contract.Receiver;
-import org.jboss.messaging.core.impl.SimpleDelivery;
-import org.jboss.messaging.core.impl.tx.Transaction;
-import org.jboss.messaging.core.impl.tx.TxCallback;
-import org.jboss.util.id.GUID;
-
-/**
- * A simple Receiver implementation that consumes undelivered by storing them internally. Used for
- * testing. The receiver can be configured to immediately return a "done" delivery (ACKING),
- * an "active" delivery (NACKING) undelivered, or throw unchecked exceptions.
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- */
-public class SimpleReceiver implements Receiver
-{
- // Constants -----------------------------------------------------
-
- private static final Logger log = Logger.getLogger(SimpleReceiver.class);
-
- public static final String ACKING = "ACKING";
- public static final String ACCEPTING = "ACCEPTING";
- public static final String BROKEN = "BROKEN";
- public static final String REJECTING = "REJECTING";
- public static final String SELECTOR_REJECTING = "SELECTOR_REJECTING";
- public static final String ACCEPTING_TO_MAX = "ACCEPTING_TO_MAX";
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // <Object[2] { Routable, Delivery }>
- private List messages;
- private String state;
- private String name;
- private Channel channel;
-
- private boolean immediateAsynchronousAcknowledgment;
- private int maxRefs;
-
- private int count;
- private int waitForCount = -1;
-
-
- // Constructors --------------------------------------------------
-
- public SimpleReceiver()
- {
- this(ACKING);
- }
-
- public SimpleReceiver(String name)
- {
- this(name, ACKING);
- }
-
- /**
- *
- * @param name
- * @param state:
- * ACKING - the receiver returns synchronously a "done" delivery.
- * NACKING - the receiver returns an active delivery, and has the option of acking it later
- * BROKEN - throws exception
- */
- public SimpleReceiver(String name, String state)
- {
- this(name, state, null);
- }
-
-
- public SimpleReceiver(String name, String state, Channel channel)
- {
- checkValid(state);
-
- this.name = name;
- this.state = state;
- this.channel = channel;
- messages = new ArrayList();
- immediateAsynchronousAcknowledgment = false;
- }
-
- // Receiver implementation ---------------------------------------
-
- public Delivery handle(DeliveryObserver observer, MessageReference ref, Transaction tx)
- {
- log.trace(this + " got routable:" + ref);
-
- log.info(this + " got routable:" + ref);
-
- try
- {
- if (ref == null)
- {
- log.trace("Receiver [" + name + "] is rejecting a null reference");
- return null;
- }
-
- if (SELECTOR_REJECTING.equals(state))
- {
- log.trace(this + " is rejecting message since doesn't match selector");
- return new SimpleDelivery(null, null, false, false);
- }
-
- if (REJECTING.equals(state))
- {
-
- log.trace(this + " is rejecting reference " + ref);
- return null;
- }
-
- if (ACCEPTING_TO_MAX.equals(state))
- {
- //Only accept up to maxRefs references
- if (messages.size() == maxRefs)
- {
- return null;
- }
- }
-
- if (BROKEN.equals(state))
- {
- throw new RuntimeException("THIS IS AN EXCEPTION THAT SIMULATES "+
- "THE BEHAVIOUR OF A BROKEN RECEIVER");
- }
-
- log.trace("State is:" + state);
-
- boolean done = ACKING.equals(state);
-
- //NOTE! it is NOT Nacking, it is keeping - don't say NACKing - it is misleading (nack means cancel)
- log.trace(this + " is " + (done ? "ACKing" : "Keeping") + " message " + ref);
-
- Message m = ref.getMessage();
-
- SimpleDelivery delivery = new SimpleDelivery(observer, ref, true, false);
- messages.add(new Object[] {m, done ? null : delivery});
-
- if (immediateAsynchronousAcknowledgment)
- {
- log.trace("simulating an asynchronous ACK that arrives before we return the delivery to channel");
- try
- {
- delivery.acknowledge(null);
- }
- catch(Throwable t)
- {
- log.error("Cannot acknowledge", t);
- }
- }
- return delivery;
- }
- finally
- {
- synchronized (this)
- {
- count++;
- if (waitForCount != -1 && count >= waitForCount)
- {
- this.notify();
- }
- }
- }
- }
-
- // Public --------------------------------------------------------
-
- public void setMaxRefs(int max)
- {
- this.maxRefs = max;
- }
-
- public void setImmediateAsynchronousAcknowledgment(boolean b)
- {
- immediateAsynchronousAcknowledgment = b;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void requestMessages()
- {
- if (channel == null)
- {
- log.error("No channel, cannot request messages");
- return;
- }
- log.trace("receiver explicitely requesting message from the channel");
- channel.deliver();
- }
-
- public void clear()
- {
- messages.clear();
- }
-
- public List getMessages()
- {
- List l = new ArrayList();
- for (Iterator i = messages.iterator(); i.hasNext(); )
- {
- Object[] o = (Object[])i.next();
- l.add(o[0]);
- }
- return l;
- }
-
- /**
- * Blocks until handle() is called for the specified number of times.
- *
- * @return true if the handle was invoked the specified number of times or false if the method
- * exited with timeout.
- */
- public boolean waitForHandleInvocations(int waitFor, long timeout)
- {
- long start = System.currentTimeMillis();
-
- synchronized(this)
- {
- this.waitForCount = waitFor;
-
- while (this.count < waitForCount)
- {
- if (timeout < 0)
- {
- log.trace(this + ".waitForHandleInvocations() current timeout is " + timeout);
- resetInvocationCount();
- return false;
- }
-
- try
- {
- this.wait(timeout);
- long now = System.currentTimeMillis();
- timeout -= now - start;
- start = now;
- }
- catch(InterruptedException e)
- {
- log.debug(e);
- }
- }
- }
-
- resetInvocationCount();
- return true;
- }
-
- public void acknowledge(Message r, Transaction tx) throws Throwable
- {
- log.debug(this + " acknowledging " + r);
-
- Object[] touple = null;
- Delivery d = null;
- for (Iterator i = messages.iterator(); i.hasNext(); )
- {
- Object[] o = (Object[])i.next();
- Message m = (Message)o[0];
- if (m == r)
- {
- log.trace("*** found it");
- d = (Delivery)o[1];
- touple = o;
- break;
- }
- }
-
- if (touple == null)
- {
- throw new IllegalStateException("The message " + r + " hasn't been received yet!");
- }
-
- if (d == null)
- {
- throw new IllegalStateException("The message " + r + " has already been acknowledged!");
- }
-
- d.acknowledge(tx);
-
- log.trace(this + " acknowledged " + r);
-
- // make sure I get rid of message if the transaction is rolled back
- if (tx != null)
- {
- tx.addCallback(new PostAcknowledgeCommitCallback(touple), new GUID().toString());
- }
- }
-
- public void cancel(Message r) throws Throwable
- {
- Object[] touple = null;
- Delivery d = null;
- for (Iterator i = messages.iterator(); i.hasNext(); )
- {
- Object[] o = (Object[])i.next();
- Message m = (Message)o[0];
- if (m == r)
- {
- d = (Delivery)o[1];
- touple = o;
- i.remove();
- break;
- }
- }
-
- if (touple == null)
- {
- throw new IllegalStateException("The message " + r + " hasn't been received yet!");
- }
-
- if (d == null)
- {
- throw new IllegalStateException("The message " + r + " has already been acknowledged!");
- }
-
- d.cancel();
-
- log.trace(this + " cancelled " + r);
- }
-
- public String toString()
- {
- return "Receiver["+ name +":" + System.identityHashCode(this) + "](" + state + ")";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- private static void checkValid(String state)
- {
- if (!ACKING.equals(state) &&
- !ACCEPTING.equals(state) &&
- !BROKEN.equals(state) &&
- !REJECTING.equals(state) &&
- !SELECTOR_REJECTING.equals(state) &&
- !ACCEPTING_TO_MAX.equals(state))
- {
- throw new IllegalArgumentException("Unknown receiver state: " + state);
- }
- }
-
- private void resetInvocationCount()
- {
- this.waitForCount = -1;
- this.count = 0;
- }
-
- // Inner classes -------------------------------------------------
-
- private class PostAcknowledgeCommitCallback implements TxCallback
- {
- private Object[] touple;
-
-
- /**
- * @param touple - touple[0] contains the message, touple[1] contains the delivery
- */
- public PostAcknowledgeCommitCallback(Object[] touple)
- {
- this.touple = touple;
- }
-
- public void afterRollback(boolean onePhase)
- {
-
- }
-
- public void afterCommit()
- {
- // clear the delivery
- touple[1] = null;
- }
-
- public void afterCommit(boolean onePhase) throws Exception
- {
-
- }
-
- public void afterPrepare() throws Exception
- {
-
- }
-
- public void beforeCommit(boolean onePhase) throws Exception
- {
-
- }
-
- public void beforePrepare() throws Exception
- {
-
- }
-
- public void beforeRollback(boolean onePhase) throws Exception
- {
-
- }
- }
-}
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/postoffice/ClusteredPostOfficeTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/postoffice/ClusteredPostOfficeTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/postoffice/ClusteredPostOfficeTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -29,12 +29,12 @@
import org.jboss.messaging.core.contract.Binding;
import org.jboss.messaging.core.contract.Condition;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.PostOffice;
import org.jboss.messaging.core.contract.Queue;
import org.jboss.messaging.core.impl.MessagingQueue;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
import org.jboss.test.messaging.core.PostOfficeTestBase;
import org.jboss.test.messaging.core.SimpleCondition;
import org.jboss.test.messaging.core.SimpleFilter;
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/core/postoffice/PostOfficeTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -26,12 +26,12 @@
import org.jboss.messaging.core.contract.Binding;
import org.jboss.messaging.core.contract.Condition;
-import org.jboss.messaging.core.contract.Message;
-import org.jboss.messaging.core.contract.MessageReference;
import org.jboss.messaging.core.contract.PostOffice;
import org.jboss.messaging.core.contract.Queue;
import org.jboss.messaging.core.impl.MessagingQueue;
import org.jboss.messaging.core.impl.tx.Transaction;
+import org.jboss.messaging.newcore.intf.Message;
+import org.jboss.messaging.newcore.intf.MessageReference;
import org.jboss.test.messaging.core.PostOfficeTestBase;
import org.jboss.test.messaging.core.SimpleCondition;
import org.jboss.test.messaging.core.SimpleFilter;
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -38,8 +38,8 @@
import org.jboss.jms.client.FailoverEvent;
import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.JBossSession;
import org.jboss.jms.client.JBossConnectionFactory;
+import org.jboss.jms.client.JBossSession;
import org.jboss.jms.client.delegate.ClientClusteredConnectionFactoryDelegate;
import org.jboss.jms.client.delegate.ClientConnectionDelegate;
import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
@@ -47,7 +47,6 @@
import org.jboss.jms.client.remoting.JMSRemotingConnection;
import org.jboss.jms.client.state.ConnectionState;
import org.jboss.jms.client.state.SessionState;
-import org.jboss.jms.message.MessageProxy;
import org.jboss.test.messaging.tools.ServerManagement;
/**
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/BytesMessagePersistenceManagerTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/BytesMessagePersistenceManagerTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/BytesMessagePersistenceManagerTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,7 +24,7 @@
import java.util.HashMap;
import org.jboss.jms.message.JBossBytesMessage;
-import org.jboss.messaging.core.contract.Message;
+import org.jboss.messaging.newcore.intf.Message;
/**
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/MapMessagePersistenceManagerTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/MapMessagePersistenceManagerTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/MapMessagePersistenceManagerTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -26,7 +26,7 @@
import java.util.Map;
import org.jboss.jms.message.JBossMapMessage;
-import org.jboss.messaging.core.contract.Message;
+import org.jboss.messaging.newcore.intf.Message;
/**
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/MessagePersistenceManagerTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/MessagePersistenceManagerTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/MessagePersistenceManagerTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -29,8 +29,8 @@
import org.jboss.jms.destination.JBossQueue;
import org.jboss.jms.destination.JBossTopic;
import org.jboss.jms.message.JBossMessage;
-import org.jboss.messaging.core.contract.Message;
import org.jboss.messaging.core.impl.JDBCPersistenceManager;
+import org.jboss.messaging.newcore.intf.Message;
import org.jboss.test.messaging.core.JDBCPersistenceManagerTest;
import org.jboss.test.messaging.tools.ServerManagement;
import org.jboss.util.id.GUID;
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/ObjectMessagePersistenceManagerTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/ObjectMessagePersistenceManagerTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/ObjectMessagePersistenceManagerTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,7 +24,7 @@
import java.util.HashMap;
import org.jboss.jms.message.JBossObjectMessage;
-import org.jboss.messaging.core.contract.Message;
+import org.jboss.messaging.newcore.intf.Message;
/**
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/StreamMessagePersistenceManagerTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/StreamMessagePersistenceManagerTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/StreamMessagePersistenceManagerTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -25,7 +25,7 @@
import java.util.HashMap;
import org.jboss.jms.message.JBossStreamMessage;
-import org.jboss.messaging.core.contract.Message;
+import org.jboss.messaging.newcore.intf.Message;
/**
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/TextMessagePersistenceManagerTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/TextMessagePersistenceManagerTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/jms/persistence/TextMessagePersistenceManagerTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,7 +24,7 @@
import java.util.HashMap;
import org.jboss.jms.message.JBossTextMessage;
-import org.jboss.messaging.core.contract.Message;
+import org.jboss.messaging.newcore.intf.Message;
/**
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/util/CoreMessageFactory.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/util/CoreMessageFactory.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/util/CoreMessageFactory.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -39,19 +39,19 @@
// Static --------------------------------------------------------
- public static CoreMessage createCoreMessage(long messageID)
+ public static MessageImpl createCoreMessage(long messageID)
{
return createCoreMessage(messageID, false, 0, 0, (byte)4, null, null);
}
- public static CoreMessage createCoreMessage(long messageID,
+ public static MessageImpl createCoreMessage(long messageID,
boolean reliable,
Serializable payload)
{
return createCoreMessage(messageID, reliable, 0, 0, (byte)4, null, payload);
}
- public static CoreMessage createCoreMessage(long messageID,
+ public static MessageImpl createCoreMessage(long messageID,
boolean reliable,
long expiration,
long timestamp,
@@ -59,8 +59,8 @@
Map coreHeaders,
Serializable payload)
{
- CoreMessage cm =
- new CoreMessage(messageID, reliable, expiration, timestamp, priority, coreHeaders, null);
+ MessageImpl cm =
+ new MessageImpl(messageID, reliable, expiration, timestamp, priority, coreHeaders, null);
cm.setPayload(payload);
return cm;
}
Modified: branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/util/prioritylinkedlist/PriorityLinkedListTest.java
===================================================================
--- branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/util/prioritylinkedlist/PriorityLinkedListTest.java 2007-12-05 15:15:37 UTC (rev 3411)
+++ branches/Branch_New_Persistence/tests/src/org/jboss/test/messaging/util/prioritylinkedlist/PriorityLinkedListTest.java 2007-12-05 19:41:47 UTC (rev 3412)
@@ -24,7 +24,7 @@
import java.util.Iterator;
import java.util.ListIterator;
-import org.jboss.messaging.util.prioritylinkedlist.BasicPriorityLinkedList;
+import org.jboss.messaging.util.prioritylinkedlist.PriorityLinkedListImpl;
import org.jboss.test.messaging.MessagingTestCase;
/**
@@ -34,7 +34,7 @@
*/
public class PriorityLinkedListTest extends MessagingTestCase
{
- protected BasicPriorityLinkedList list;
+ protected PriorityLinkedListImpl list;
protected Wibble a;
protected Wibble b;
@@ -72,7 +72,7 @@
{
super.setUp();
- list = new BasicPriorityLinkedList(10);
+ list = new PriorityLinkedListImpl(10);
a = new Wibble("a");
b = new Wibble("b");
More information about the jboss-cvs-commits
mailing list