[jboss-cvs] JBoss Messaging SVN: r3466 - in branches/Branch_New_Persistence/src/main/org/jboss: jms/server and 13 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 10 13:44:52 EST 2007
Author: timfox
Date: 2007-12-10 13:44:52 -0500 (Mon, 10 Dec 2007)
New Revision: 3466
Added:
branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/ClusteredQueue.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/QueueStatistics.java
Modified:
branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMessage.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ServerPeer.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/destination/QueueService.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/TopicService.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/messagecounter/MessageCounter.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/Selector.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/SelectorFactory.java
branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ClientTransaction.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/Binding.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/FailoverWaiter.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/clusterconnection/ClusterConnectionManager.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/tx/Transaction.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Filter.java
branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Queue.java
Log:
More work
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/message/JBossMessage.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -36,7 +36,7 @@
import org.jboss.jms.delegate.SessionDelegate;
import org.jboss.jms.exception.MessagingJMSException;
-import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.impl.MessageImpl;
import org.jboss.util.Primitives;
import org.jboss.util.Strings;
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ServerPeer.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ServerPeer.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/ServerPeer.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -62,12 +62,11 @@
import org.jboss.messaging.core.contract.MessageStore;
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.newcore.intf.Queue;
import org.jboss.messaging.core.contract.Replicator;
import org.jboss.messaging.core.impl.DefaultClusterNotifier;
import org.jboss.messaging.core.impl.FailoverWaiter;
import org.jboss.messaging.core.impl.IDManager;
-import org.jboss.messaging.core.impl.JDBCPersistenceManager;
import org.jboss.messaging.core.impl.clusterconnection.ClusterConnectionManager;
import org.jboss.messaging.core.impl.memory.SimpleMemoryManager;
import org.jboss.messaging.core.impl.message.SimpleMessageStore;
@@ -169,11 +168,11 @@
private IDManager channelIDManager;
private IDManager transactionIDManager;
private MemoryManager memoryManager;
- private MessageStore messageStore;
+ // private MessageStore messageStore;
private MessageCounterManager messageCounterManager;
- private ClusterConnectionManager clusterConnectionManager;
+ // private ClusterConnectionManager clusterConnectionManager;
private ClusterNotifier clusterNotifier;
- private FailoverWaiter failoverWaiter;
+ // private FailoverWaiter failoverWaiter;
// plugins
@@ -235,8 +234,8 @@
// circumventing the MBeanServer. However, they are installed as services to take advantage
// of their automatically-creating management interface.
- persistenceManager = (PersistenceManager)JMXAccessor.getJMXAttributeOverSecurity(mbeanServer, persistenceManagerObjectName, "Instance");
- ((JDBCPersistenceManager)persistenceManager).injectNodeID(serverPeerID);
+// persistenceManager = (PersistenceManager)JMXAccessor.getJMXAttributeOverSecurity(mbeanServer, persistenceManagerObjectName, "Instance");
+// ((JDBCPersistenceManager)persistenceManager).injectNodeID(serverPeerID);
jmsUserManager = (JMSUserManager)JMXAccessor.getJMXAttributeOverSecurity(mbeanServer, jmsUserManagerObjectName, "Instance");
@@ -254,28 +253,28 @@
connectionManager = new SimpleConnectionManager();
connectorManager = new SimpleConnectorManager();
memoryManager = new SimpleMemoryManager();
- messageStore = new SimpleMessageStore();
- txRepository =
- new TransactionRepository(persistenceManager, messageStore, transactionIDManager);
+// messageStore = new SimpleMessageStore();
+// txRepository =
+// new TransactionRepository(persistenceManager, messageStore, transactionIDManager);
messageCounterManager = new MessageCounterManager(messageCounterSamplePeriod);
clusterNotifier = new DefaultClusterNotifier();
clusterNotifier.registerListener(connectionManager);
clusterNotifier.registerListener(connFactoryJNDIMapper);
- failoverWaiter = new FailoverWaiter(serverPeerID, failoverStartTimeout, failoverCompleteTimeout, txRepository);
- clusterNotifier.registerListener(failoverWaiter);
+ // failoverWaiter = new FailoverWaiter(serverPeerID, failoverStartTimeout, failoverCompleteTimeout, txRepository);
+ // clusterNotifier.registerListener(failoverWaiter);
if (suckerPassword == null)
{
suckerPassword = SecurityMetadataStore.DEFAULT_SUCKER_USER_PASSWORD;
}
- if (clusterPullConnectionFactoryName != null)
- {
- clusterConnectionManager = new ClusterConnectionManager(useXAForMessagePull, serverPeerID,
- clusterPullConnectionFactoryName, defaultPreserveOrdering,
- SecurityMetadataStore.SUCKER_USER, suckerPassword);
- clusterNotifier.registerListener(clusterConnectionManager);
- }
+// if (clusterPullConnectionFactoryName != null)
+// {
+// clusterConnectionManager = new ClusterConnectionManager(useXAForMessagePull, serverPeerID,
+// clusterPullConnectionFactoryName, defaultPreserveOrdering,
+// SecurityMetadataStore.SUCKER_USER, suckerPassword);
+// clusterNotifier.registerListener(clusterConnectionManager);
+// }
// Start the wired components
@@ -287,18 +286,18 @@
connectionManager.start();
connectorManager.start();
memoryManager.start();
- messageStore.start();
+ // messageStore.start();
securityStore.setSuckerPassword(suckerPassword);
securityStore.start();
- txRepository.start();
- clusterConnectionManager.start();
+ // txRepository.start();
+ // clusterConnectionManager.start();
// Note we do not start the message counter manager by default. This must be done
// explicitly by the user by calling enableMessageCounters(). This is because message
// counter history takes up growing memory to store the stats and could theoretically
// eventually cause the server to run out of RAM
- txRepository.loadPreparedTransactions();
+ // txRepository.loadPreparedTransactions();
JMSWireFormat wf = new JMSWireFormat();
MarshalFactory.addMarshaller("jms", wf, wf);
@@ -354,16 +353,16 @@
connectorManager = null;
memoryManager.stop();
memoryManager = null;
- messageStore.stop();
- messageStore = null;
+ // messageStore.stop();
+ // messageStore = null;
securityStore.stop();
//securityStore = null; - if securitySTore is set to null, The ServerPeer won't survive a restart of the service (stop/start)
- txRepository.stop();
+ // txRepository.stop();
txRepository = null;
messageCounterManager.stop();
messageCounterManager = null;
- clusterConnectionManager.stop();
- clusterConnectionManager = null;
+ // clusterConnectionManager.stop();
+ // clusterConnectionManager = null;
postOffice = null;
unloadServerAOPConfig();
@@ -1045,27 +1044,31 @@
public List retrievePreparedTransactions()
{
- return txRepository.getPreparedTransactions();
+ //return txRepository.getPreparedTransactions();
+
+ return null;
}
public String showPreparedTransactionsAsHTML()
{
- List txs = txRepository.getPreparedTransactions();
- JBossStringBuilder buffer = new JBossStringBuilder();
- buffer.append("<table width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">");
- buffer.append("<tr><th>Xid</th></tr>");
- for (Iterator i = txs.iterator(); i.hasNext();)
- {
- Xid xid = (Xid)i.next();
- if (xid != null)
- {
- buffer.append("<tr><td>");
- buffer.append(xid);
- buffer.append("</td></tr>");
- }
- }
- buffer.append("</table>");
- return buffer.toString();
+// List txs = txRepository.getPreparedTransactions();
+// JBossStringBuilder buffer = new JBossStringBuilder();
+// buffer.append("<table width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">");
+// buffer.append("<tr><th>Xid</th></tr>");
+// for (Iterator i = txs.iterator(); i.hasNext();)
+// {
+// Xid xid = (Xid)i.next();
+// if (xid != null)
+// {
+// buffer.append("<tr><td>");
+// buffer.append(xid);
+// buffer.append("</td></tr>");
+// }
+// }
+// buffer.append("</table>");
+// return buffer.toString();
+
+ return null;
}
public String showActiveClientsAsHTML() throws Exception
@@ -1098,7 +1101,7 @@
public void resetAllSuckers()
{
- clusterConnectionManager.resetAllSuckers();
+ //clusterConnectionManager.resetAllSuckers();
}
public byte[] getClientAOPStack()
@@ -1297,9 +1300,9 @@
// Also inject into the cluster connection manager
- this.clusterConnectionManager.injectPostOffice(postOffice);
+ //this.clusterConnectionManager.injectPostOffice(postOffice);
- this.clusterConnectionManager.injectReplicator((Replicator)postOffice);
+ // this.clusterConnectionManager.injectReplicator((Replicator)postOffice);
this.connectionManager.injectReplicator((Replicator)postOffice);
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedDestination.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -29,7 +29,7 @@
import org.jboss.messaging.core.contract.Binding;
import org.jboss.messaging.core.contract.Condition;
import org.jboss.messaging.core.contract.PostOffice;
-import org.jboss.messaging.core.contract.Queue;
+import org.jboss.messaging.newcore.intf.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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedQueue.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -28,7 +28,7 @@
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.Queue;
+import org.jboss.messaging.newcore.intf.Queue;
import org.jboss.messaging.newcore.intf.Message;
/**
@@ -99,11 +99,15 @@
public int getDeliveringCount() throws Exception
{
- int count = queue.getDeliveringCount();
-
- if (trace) { log.trace(this + " returning DeliveringCount = " + count); }
-
- return count;
+// int count = queue.getDeliveringCount();
+//
+// if (trace) { log.trace(this + " returning DeliveringCount = " + count); }
+//
+// return count;
+
+ //TODO
+
+ return 0;
}
public int getScheduledMessageCount() throws Exception
@@ -117,7 +121,7 @@
public int getConsumersCount() throws Exception
{
- int count = queue.getLocalDistributor().getNumberOfReceivers();
+ int count = queue.getConsumerCount();
if (trace) { log.trace(this + " returning ConsumersCount = " + count); }
@@ -160,8 +164,10 @@
List msgs = new ArrayList();
- List allMsgs = queue.browse(sel);
+ //List allMsgs = queue.browse(sel);
+ List allMsgs = queue.list(sel);
+
Iterator iter = allMsgs.iterator();
while (iter.hasNext())
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/ManagedTopic.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -230,7 +230,7 @@
sel = new Selector(selector);
}
- List allMsgs = binding.queue.browse(sel);
+ List allMsgs = binding.queue.list(sel);
Iterator iter = allMsgs.iterator();
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/QueueService.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/QueueService.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/QueueService.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -16,8 +16,8 @@
import org.jboss.jms.server.messagecounter.MessageStatistics;
import org.jboss.messaging.core.contract.Binding;
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.newcore.intf.Queue;
+import org.jboss.messaging.newcore.impl.QueueImpl;
import org.jboss.messaging.util.ExceptionUtil;
import org.jboss.messaging.util.XMLUtil;
@@ -82,9 +82,9 @@
throw new IllegalStateException("Cannot deploy queue " + destination.getName() + " it is already deployed");
}
- queue.setPagingParams(destination.getFullSize(),
- destination.getPageSize(),
- destination.getDownCacheSize());
+// queue.setPagingParams(destination.getFullSize(),
+// destination.getPageSize(),
+// destination.getDownCacheSize());
queue.load();
@@ -99,14 +99,16 @@
JMSCondition queueCond = new JMSCondition(true, destination.getName());
- queue = new MessagingQueue(nodeId, destination.getName(),
- serverPeer.getChannelIDManager().getID(),
- serverPeer.getMessageStore(), serverPeer.getPersistenceManagerInstance(),
- true,
- destination.getMaxSize(), null,
- destination.getFullSize(), destination.getPageSize(),
- destination.getDownCacheSize(), destination.isClustered(),
- serverPeer.getRecoverDeliveriesTimeout());
+// queue = new MessagingQueue(nodeId, destination.getName(),
+// serverPeer.getChannelIDManager().getID(),
+// serverPeer.getMessageStore(), serverPeer.getPersistenceManagerInstance(),
+// true,
+// destination.getMaxSize(), null,
+// destination.getFullSize(), destination.getPageSize(),
+// destination.getDownCacheSize(), destination.isClustered(),
+// serverPeer.getRecoverDeliveriesTimeout());
+
+ queue = new QueueImpl(serverPeer.getChannelIDManager().getID(), null);
po.addBinding(new Binding(queueCond, queue, false), false);
queue.activate();
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/TopicService.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/TopicService.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/destination/TopicService.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -15,7 +15,7 @@
import org.jboss.jms.server.JMSCondition;
import org.jboss.jms.server.messagecounter.MessageCounter;
import org.jboss.messaging.core.contract.PostOffice;
-import org.jboss.messaging.core.contract.Queue;
+import org.jboss.messaging.newcore.intf.Queue;
import org.jboss.messaging.util.ExceptionUtil;
import org.jboss.messaging.util.MessageQueueNameHelper;
import org.jboss.messaging.util.XMLUtil;
@@ -77,7 +77,7 @@
//TODO We need to set the paging params this way since the post office doesn't store them
//instead we should never create queues inside the postoffice - only do it at deploy time
- queue.setPagingParams(destination.getFullSize(), destination.getPageSize(), destination.getDownCacheSize());
+ //queue.setPagingParams(destination.getFullSize(), destination.getPageSize(), destination.getDownCacheSize());
queue.load();
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -32,7 +32,7 @@
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.Filter;
import org.jboss.messaging.newcore.intf.Message;
import org.jboss.messaging.util.ExceptionUtil;
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -58,7 +58,7 @@
import org.jboss.messaging.core.contract.Delivery;
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.newcore.intf.Queue;
import org.jboss.messaging.core.impl.tx.Transaction;
import org.jboss.messaging.core.impl.tx.TransactionRepository;
import org.jboss.messaging.newcore.intf.Message;
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -328,7 +328,7 @@
// to do the check twice
if (messageSelector != null)
{
- accept = messageSelector.accept(msg);
+ accept = messageSelector.match(msg);
if (trace) { log.trace("message selector " + (accept ? "accepts " : "DOES NOT accept ") + "the message"); }
}
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -72,7 +72,7 @@
import org.jboss.messaging.core.contract.MessageStore;
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.newcore.intf.Queue;
import org.jboss.messaging.core.contract.Replicator;
import org.jboss.messaging.core.impl.IDManager;
import org.jboss.messaging.core.impl.MessagingQueue;
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/messagecounter/MessageCounter.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/messagecounter/MessageCounter.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/messagecounter/MessageCounter.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -30,7 +30,7 @@
import java.util.List;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Queue;
+import org.jboss.messaging.newcore.intf.Queue;
/**
* This class stores message count informations for a given queue
@@ -164,6 +164,7 @@
// update message history
updateHistory(true);
}
+
/**
* Gets the related destination name
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/Selector.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -23,12 +23,14 @@
import java.util.HashMap;
import java.util.Iterator;
+
import javax.jms.DeliveryMode;
import javax.jms.InvalidSelectorException;
import javax.jms.JMSException;
import javax.jms.Message;
+
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Filter;
+import org.jboss.messaging.newcore.intf.Filter;
/**
@@ -113,7 +115,7 @@
return selector;
}
- public synchronized boolean accept(org.jboss.messaging.newcore.intf.Message message)
+ public synchronized boolean match(org.jboss.messaging.newcore.intf.Message message)
{
try
{
Modified: branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/SelectorFactory.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/SelectorFactory.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/server/selector/SelectorFactory.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -21,8 +21,8 @@
*/
package org.jboss.jms.server.selector;
-import org.jboss.messaging.core.contract.Filter;
import org.jboss.messaging.core.contract.FilterFactory;
+import org.jboss.messaging.newcore.intf.Filter;
/**
* A SelectorFactory
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/tx/ClientTransaction.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -35,7 +35,7 @@
import org.jboss.jms.delegate.DeliveryInfo;
import org.jboss.jms.message.JBossMessage;
import org.jboss.logging.Logger;
-import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.impl.MessageImpl;
import org.jboss.messaging.newcore.intf.Message;
/**
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageBlockResponse.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -24,8 +24,7 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import org.jboss.jms.message.JBossMessage;
-import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.impl.MessageImpl;
import org.jboss.messaging.newcore.intf.Message;
/**
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/BrowserNextMessageResponse.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -24,7 +24,7 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.impl.MessageImpl;
import org.jboss.messaging.newcore.intf.Message;
/**
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/ClientDelivery.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -24,7 +24,7 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.impl.MessageImpl;
import org.jboss.messaging.newcore.intf.Message;
/**
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/jms/wireformat/SessionSendRequest.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -27,10 +27,10 @@
import org.jboss.jms.server.ServerPeer;
import org.jboss.jms.server.endpoint.advised.SessionAdvised;
+import org.jboss.messaging.newcore.impl.MessageImpl;
+import org.jboss.messaging.newcore.intf.Message;
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;
/**
*
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Binding.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Binding.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/contract/Binding.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -32,7 +32,7 @@
*/
public class Binding
{
- public Binding(Condition condition, Queue queue, boolean allNodes)
+ public Binding(Condition condition, org.jboss.messaging.newcore.intf.Queue queue, boolean allNodes)
{
this.condition = condition;
@@ -43,7 +43,7 @@
public Condition condition;
- public Queue queue;
+ public org.jboss.messaging.newcore.intf.Queue queue;
public boolean allNodes;
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/FailoverWaiter.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/FailoverWaiter.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/FailoverWaiter.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -142,51 +142,51 @@
public void notify(ClusterNotification notification)
{
- if (notification.type == ClusterNotification.TYPE_FAILOVER_START)
- {
- synchronized (failoverStatusLock)
- {
- failingOverFor = notification.nodeID;
-
- failoverStatusLock.notifyAll();
- }
- }
- else if (notification.type == ClusterNotification.TYPE_FAILOVER_END)
- {
- // We prompt txRepository to load any prepared txs - so we can take over
- // responsibility for in doubt transactions from other nodes
- try
- {
- txRepository.loadPreparedTransactions();
- }
- catch (Exception e)
- {
- log.error("Failed to load prepared transactions", e);
- }
-
- synchronized (failoverStatusLock)
- {
- failedOverFor = failingOverFor;
-
- failingOverFor = -1;
-
- failoverStatusLock.notifyAll();
- }
- }
- else if (notification.type == ClusterNotification.TYPE_NODE_JOIN)
- {
- synchronized (failoverStatusLock)
- {
- //A node that we previously failed over for has been restarted so we wipe the failover status
- //It is vital that we do this otherwise if the resurrected node subsequently fails again
- //when connections try to reconnect they will think that failover is already complete
- if (notification.nodeID == failedOverFor)
- {
- failedOverFor = -1;
-
- failoverStatusLock.notifyAll();
- }
- }
- }
+// if (notification.type == ClusterNotification.TYPE_FAILOVER_START)
+// {
+// synchronized (failoverStatusLock)
+// {
+// failingOverFor = notification.nodeID;
+//
+// failoverStatusLock.notifyAll();
+// }
+// }
+// else if (notification.type == ClusterNotification.TYPE_FAILOVER_END)
+// {
+// // We prompt txRepository to load any prepared txs - so we can take over
+// // responsibility for in doubt transactions from other nodes
+// try
+// {
+// txRepository.loadPreparedTransactions();
+// }
+// catch (Exception e)
+// {
+// log.error("Failed to load prepared transactions", e);
+// }
+//
+// synchronized (failoverStatusLock)
+// {
+// failedOverFor = failingOverFor;
+//
+// failingOverFor = -1;
+//
+// failoverStatusLock.notifyAll();
+// }
+// }
+// else if (notification.type == ClusterNotification.TYPE_NODE_JOIN)
+// {
+// synchronized (failoverStatusLock)
+// {
+// //A node that we previously failed over for has been restarted so we wipe the failover status
+// //It is vital that we do this otherwise if the resurrected node subsequently fails again
+// //when connections try to reconnect they will think that failover is already complete
+// if (notification.nodeID == failedOverFor)
+// {
+// failedOverFor = -1;
+//
+// failoverStatusLock.notifyAll();
+// }
+// }
+// }
}
}
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/MessagingQueue.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -21,36 +21,7 @@
*/
package org.jboss.messaging.core.impl;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.jboss.jms.server.MessagingTimeoutFactory;
-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.Distributor;
-import org.jboss.messaging.core.contract.Filter;
-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;
-
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-
/**
*
* A MessagingQueue
@@ -63,653 +34,656 @@
*
* $Id: Queue.java 1295 2006-09-15 17:44:02Z timfox $
*
+ *
*/
-public class MessagingQueue extends ChannelSupport implements Queue
+public class MessagingQueue //extends ChannelSupport implements Queue
{
- // Constants -----------------------------------------------------
+//
+// // Constants -----------------------------------------------------
+//
+// // Static --------------------------------------------------------
+//
+// private static final Logger log = Logger.getLogger(MessagingQueue.class);
+//
+// private static final long DEFAULT_RECOVER_DELIVERIES_TIMEOUT = 5 * 60 * 10000;
+//
+// // Attributes ----------------------------------------------------
+//
+// private int nodeID;
+//
+// protected String name;
+//
+// protected Filter filter;
+//
+// protected boolean clustered;
+//
+// protected Distributor remoteDistributor;
+//
+// protected Distributor localDistributor;
+//
+// private boolean trace = log.isTraceEnabled();
+//
+// private Set suckers;
+//
+// private boolean handleFlowControlForConsumers;
+//
+// private Map recoveryArea;
+//
+// private Map recoveryMap;
+//
+// private long recoverDeliveriesTimeout;
+//
+// // Constructors --------------------------------------------------
+//
+// public MessagingQueue(int nodeID, String name, long id, MessageStore ms, PersistenceManager pm,
+// boolean recoverable, int maxSize, Filter filter,
+// int fullSize, int pageSize, int downCacheSize, boolean clustered,
+// long recoverDeliveriesTimeout)
+// {
+// super(id, ms, pm, recoverable, maxSize, fullSize, pageSize, downCacheSize);
+//
+// setup(nodeID, name, filter, clustered, recoverDeliveriesTimeout);
+// }
+//
+// /** This constructor is used when loading queue from storage - the paging params, maxSize and recoverDeliveriesTimeout don't matter
+// * they are injected when the queue or topic service is started
+// */
+// public MessagingQueue(int nodeID, String name, long id, MessageStore ms, PersistenceManager pm,
+// boolean recoverable, Filter filter,
+// boolean clustered)
+// {
+// super(id, ms, pm, recoverable, -1, 100000, 2000, 2000); //paging params etc are actually ignored
+//
+// setup(nodeID, name, filter, clustered, DEFAULT_RECOVER_DELIVERIES_TIMEOUT);
+// }
+//
+// /* This constructor is only used in tests - should we remove it? */
+// public MessagingQueue(int nodeID, String name, long id, MessageStore ms, PersistenceManager pm,
+// boolean recoverable, int maxSize, Filter filter, boolean clustered)
+// {
+// super(id, ms, pm, recoverable, maxSize);
+//
+// setup(nodeID, name, filter, clustered, DEFAULT_RECOVER_DELIVERIES_TIMEOUT);
+// }
+//
+// /* Constructor for a remote queue representation in a cluster */
+// public MessagingQueue(int nodeID, String name, long id, boolean recoverable,
+// Filter filter, boolean clustered)
+// {
+// super(id, null, null, recoverable, -1);
+//
+// setup(nodeID, name, filter, clustered, DEFAULT_RECOVER_DELIVERIES_TIMEOUT);
+// }
+//
+// private void setup(int nodeID, String name, Filter filter, boolean clustered, long recoverDeliveriesTimeout)
+// {
+// this.nodeID = nodeID;
+//
+// this.name = name;
+//
+// this.filter = filter;
+//
+// this.clustered = clustered;
+//
+// this.recoverDeliveriesTimeout = recoverDeliveriesTimeout;
+//
+// localDistributor = new DistributorWrapper(new RoundRobinDistributor());
+//
+// remoteDistributor = new DistributorWrapper(new RoundRobinDistributor());
+//
+// distributor = new ClusterRoundRobinDistributor(localDistributor, remoteDistributor);
+//
+// suckers = new HashSet();
+//
+// recoveryArea = new ConcurrentReaderHashMap();
+//
+// recoveryMap = Collections.synchronizedMap(new LinkedHashMap());
+// }
+//
+// // Queue implementation
+// // ---------------------------------------------------------------
+//
+// public int getNodeID()
+// {
+// return nodeID;
+// }
+//
+// public String getName()
+// {
+// return name;
+// }
+//
+// public Filter getFilter()
+// {
+// return filter;
+// }
+//
+// public boolean isClustered()
+// {
+// return clustered;
+// }
+//
+// public Distributor getLocalDistributor()
+// {
+// return localDistributor;
+// }
+//
+// public Distributor getRemoteDistributor()
+// {
+// return remoteDistributor;
+// }
+//
+// /**
+// * Merge the contents of one queue with another - this happens at failover when a queue is failed
+// * over to another node, but a queue with the same name already exists. In this case we merge the
+// * two queues.
+// */
+// public void mergeIn(long theChannelID, int nodeID) throws Exception
+// {
+// if (trace) { log.trace("Merging queue " + channelID + " node id " + nodeID + " into " + this +
+// " initially refs:" + messageRefs.size()); }
+//
+// synchronized (lock)
+// {
+// flushDownCache();
+//
+// PersistenceManager.InitialLoadInfo ili =
+// pm.mergeAndLoad(theChannelID, this.channelID, fullSize - messageRefs.size(),
+// firstPagingOrder, nextPagingOrder);
+//
+// if (trace) { log.trace("Loaded " + ili.getRefInfos().size() + " refs"); }
+//
+// doLoad(ili);
+//
+// Map toRecover = (Map)recoveryArea.remove(new Integer(nodeID));
+//
+// if (trace) { log.trace("To recover is: " + toRecover); }
+//
+// LinkedList toTimeout = new LinkedList();
+//
+// if (toRecover != null)
+// {
+// //TODO this can be optimised to avoid a second scan - we could do this in load
+//
+// if (trace) { log.trace("Recovery area is not empty, putting refs in recovery map"); }
+//
+// Iterator iter = messageRefs.iterator();
+//
+// while (iter.hasNext())
+// {
+// MessageReference ref = (MessageReference)iter.next();
+//
+// Message message = ref.getMessage();
+//
+// String sessionID = (String)toRecover.remove(new Long(message.getMessageID()));
+//
+// if (sessionID != null)
+// {
+// if (trace) { log.trace("Added ref " + ref + " to recovery map"); }
+//
+// RecoveryEntry re = new RecoveryEntry();
+// re.ref = ref;
+// re.sessionID = sessionID;
+//
+// recoveryMap.put(new Long(message.getMessageID()), re);
+//
+// deliveringCount.increment();
+//
+// iter.remove();
+//
+// toTimeout.addLast(ref);
+// }
+// }
+//
+// //Note!
+// //It is possible there are message ids in the toRecover that are not in the queue
+// //This can happen if a delivery is replicated, the message delivered, then acked, then the node crashes
+// //before the ack is replicated.
+// //This is ok
+//
+// //Set up a timeout to put the refs back in the queue if they don't get claimed by failed over consumers
+//
+// MessagingTimeoutFactory.instance.getFactory().
+// schedule(System.currentTimeMillis() + recoverDeliveriesTimeout, new ClearRecoveryMapTimeoutTarget(toTimeout));
+//
+// if (trace) { log.trace("Set timeout to fire in " + recoverDeliveriesTimeout); }
+// }
+//
+// deliverInternal();
+// }
+// }
+//
+// public List recoverDeliveries(List messageIds)
+// {
+// if (trace) { log.trace("Recovering deliveries"); }
+//
+// List refs = new ArrayList();
+//
+// Iterator iter = messageIds.iterator();
+//
+// while (iter.hasNext())
+// {
+// Long messageID = (Long)iter.next();
+//
+// RecoveryEntry re = (RecoveryEntry)recoveryMap.remove(messageID);
+//
+// //This can actually be null - e.g. if failure happened right after a successful Ack so the client doesn't
+// //remove the delivery but is no longer on the server
+// if (re != null)
+// {
+// Delivery del = new SimpleDelivery(this, re.ref);
+//
+// if (trace) { log.trace("Recovered ref " + re.ref); }
+//
+// refs.add(del);
+// }
+// }
+//
+// return refs;
+// }
+//
+// public void removeStrandedReferences(String sessionID)
+// {
+// if (trace) { log.trace("Removing stranded references for session " + sessionID); }
+//
+// // TODO this can be optimised - remove any remaining deliveries for the session id
+// //these correspond to messages buffered on the client side for that client and should go back on the queue
+//
+// Iterator iter = recoveryMap.values().iterator();
+//
+// if (trace) { log.trace("Scanning recovery map for stray entries for session"); }
+//
+// List toCancel = new ArrayList();
+//
+// while (iter.hasNext())
+// {
+// RecoveryEntry re = (RecoveryEntry)iter.next();
+//
+// if (trace) { log.trace("Session id id " + re.sessionID); }
+//
+// if (re.sessionID.equals(sessionID))
+// {
+// MessageReference ref = re.ref;
+//
+// iter.remove();
+//
+// //Put back on queue
+//
+// toCancel.add(ref);
+// }
+// }
+//
+// for (int i = toCancel.size() - 1; i >= 0; i--)
+// {
+// MessageReference ref = (MessageReference)toCancel.get(i);
+//
+// synchronized (lock)
+// {
+// messageRefs.addFirst(ref, ref.getMessage().getPriority());
+//
+// //Need to decrement the delivery count too
+// deliveringCount.decrement();
+// }
+//
+// if (trace) { log.trace("Found one, added back on queue"); }
+// }
+//
+// }
+//
+// public void registerSucker(MessageSucker sucker)
+// {
+// if (trace) { log.trace(this + " Registering sucker " + sucker); }
+//
+// synchronized (lock)
+// {
+// if (!suckers.contains(sucker))
+// {
+// suckers.add(sucker);
+//
+// handleFlowControlForConsumers = true;
+//
+// if (getReceiversReady() && localDistributor.getNumberOfReceivers() > 0)
+// {
+// if (trace) { log.trace(this + " receivers ready so setting consumer to true"); }
+//
+// sucker.setConsuming(true);
+// }
+// }
+// }
+// }
+//
+// public boolean unregisterSucker(MessageSucker sucker)
+// {
+// synchronized (lock)
+// {
+// boolean removed = suckers.remove(sucker);
+//
+// if (removed && suckers.isEmpty())
+// {
+// handleFlowControlForConsumers = false;
+// }
+//
+// return removed;
+// }
+// }
+//
+// public int getFullSize()
+// {
+// return fullSize;
+// }
+//
+// public int getPageSize()
+// {
+// return pageSize;
+// }
+//
+// public int getDownCacheSize()
+// {
+// return downCacheSize;
+// }
+//
+// public void addToRecoveryArea(int nodeID, long messageID, String sessionID)
+// {
+// if (trace) { log.trace("Adding message id " + messageID + " to recovery area from node " + nodeID); }
+//
+// //Note. The add might find the id already there
+// //This could happen after the failover node has moved
+// //When the batch add happens, then an add comes in shortly after but has already been taken into account
+//
+// Integer nid = new Integer(nodeID);
+//
+// Map ids = (Map)recoveryArea.get(nid);
+//
+// if (ids == null)
+// {
+// ids = new ConcurrentHashMap();
+//
+// recoveryArea.put(nid, ids);
+// }
+//
+// ids.put(new Long(messageID), sessionID);
+// }
+//
+// public void removeFromRecoveryArea(int nodeID, long messageID)
+// {
+// if (trace) { log.trace("Removing message id " + messageID + " to recovery area from node " + nodeID); }
+//
+// Integer nid = new Integer(nodeID);
+//
+// Map ids = (Map)recoveryArea.get(nid);
+//
+// //The remove might fail to find the id
+// //This can happen if the removal has already be done - this could happen after the failover node has moved
+// //When the batch add happens, then an ack comes in shortly after but has already been taken into account
+//
+// if (ids != null && ids.remove(new Long(messageID)) != null)
+// {
+// if (ids.isEmpty())
+// {
+// recoveryArea.remove(nid);
+// }
+// }
+// }
+//
+// public void removeAllFromRecoveryArea(int nodeID)
+// {
+// if (trace) { log.trace("Removing all from recovery area for node " + nodeID); }
+//
+// boolean removed = recoveryArea.remove(new Integer(nodeID)) != null;
+//
+// if (trace) { log.trace("Removed:" + removed); }
+// }
+//
+// public void addAllToRecoveryArea(int nodeID, Map ids)
+// {
+// if (trace) { log.trace("Adding all from recovery area for node " + nodeID +" set " + ids); }
+//
+// Integer nid = new Integer(nodeID);
+//
+// if (!(ids instanceof ConcurrentHashMap))
+// {
+// ids = new ConcurrentHashMap(ids);
+// }
+//
+// if (trace) { log.trace("Adding " + ids.size() + " ids to recovery area for node " + nodeID); }
+//
+// recoveryArea.put(nid, ids);
+//
+// if (trace) { log.trace("Added"); }
+// }
+//
+// public long getRecoverDeliveriesTimeout()
+// {
+// return recoverDeliveriesTimeout;
+// }
+//
+// //testing only
+//
+// public Map getRecoveryArea()
+// {
+// if (trace) { log.trace("Getting recovery area, it is " + this.recoveryArea); }
+//
+// return this.recoveryArea;
+// }
+//
+// public int getRecoveryMapSize()
+// {
+// return this.recoveryMap.size();
+// }
+//
+// // ChannelSupport overrides --------------------------------------
+//
+// protected void deliverInternal()
+// {
+// super.deliverInternal();
+//
+// if (trace) { log.trace(this + " deliverInternal"); }
+//
+// if (handleFlowControlForConsumers && getReceiversReady() &&
+// localDistributor.getNumberOfReceivers() > 0 && messageRefs.isEmpty())
+// {
+// if (trace) { log.trace("Informing suckers"); }
+// //The receivers are still ready for more messages but there is nothing left in the local queue
+// //so we inform the message suckers to start consuming (if they aren't already)
+// informSuckers(true);
+// }
+// }
+//
+// protected void setReceiversReady(boolean receiversReady)
+// {
+// if (trace) { log.trace(this + " setReceiversReady " + receiversReady); }
+//
+// this.receiversReady = receiversReady;
+//
+// if (handleFlowControlForConsumers && receiversReady == false)
+// {
+// //No receivers are ready to accept message so tell the suckers to stop consuming
+// informSuckers(false);
+// }
+// }
+//
+// // Public --------------------------------------------------------
+//
+// public String toString()
+// {
+// return "Queue[" + System.identityHashCode(this) + "/" + nodeID + "/" + channelID + "-" + name + "]";
+// }
+//
+// public boolean equals(Object other)
+// {
+// if (!(other instanceof MessagingQueue))
+// {
+// return false;
+// }
+//
+// MessagingQueue queue = (MessagingQueue)other;
+//
+// return (this.nodeID == queue.nodeID && this.name.equals(queue.name));
+// }
+//
+// // Package protected ---------------------------------------------
+//
+// // Protected -----------------------------------------------------
+//
+// // Private -------------------------------------------------------
+//
+// private void informSuckers(boolean consume)
+// {
+// Iterator iter = suckers.iterator();
+//
+// while (iter.hasNext())
+// {
+// MessageSucker sucker = (MessageSucker)iter.next();
+//
+// sucker.setConsuming(consume);
+// }
+// }
+//
+// // Inner classes -------------------------------------------------
+//
+// protected class DistributorWrapper implements Distributor
+// {
+// private Distributor distributor;
+//
+// protected DistributorWrapper(Distributor distributor)
+// {
+// this.distributor = distributor;
+// }
+//
+// public Delivery handle(DeliveryObserver observer, MessageReference reference, Transaction tx)
+// {
+// return distributor.handle(observer, reference, tx);
+// }
+//
+// public boolean add(Receiver receiver)
+// {
+// if (trace) { log.trace(this + " attempting to add receiver " + receiver); }
+//
+// synchronized (lock)
+// {
+// boolean added = distributor.add(receiver);
+//
+// if (trace) { log.trace("receiver " + receiver + (added ? "" : " NOT") + " added"); }
+//
+// setReceiversReady(true);
+//
+// return added;
+// }
+// }
+//
+// public void clear()
+// {
+// synchronized (lock)
+// {
+// distributor.clear();
+// }
+// }
+//
+// public boolean contains(Receiver receiver)
+// {
+// synchronized (lock)
+// {
+// return distributor.contains(receiver);
+// }
+// }
+//
+// public int getNumberOfReceivers()
+// {
+// synchronized (lock)
+// {
+// return distributor.getNumberOfReceivers();
+// }
+// }
+//
+// public Iterator iterator()
+// {
+// synchronized (lock)
+// {
+// return distributor.iterator();
+// }
+// }
+//
+// public boolean remove(Receiver receiver)
+// {
+// synchronized (lock)
+// {
+// boolean removed = distributor.remove(receiver);
+//
+// if (removed)
+// {
+// if (localDistributor.getNumberOfReceivers() == 0)
+// {
+// //Stop pulling from other queues into this one.
+// informSuckers(false);
+//
+// if (remoteDistributor.getNumberOfReceivers() == 0)
+// {
+// setReceiversReady(false);
+// }
+// }
+// }
+//
+// if (trace) { log.trace(this + (removed ? " removed " : " did NOT remove ") + receiver); }
+//
+// return removed;
+// }
+// }
+// }
+//
+// static class RecoveryEntry
+// {
+// String sessionID;
+//
+// MessageReference ref;
+// }
+//
+//
+// private class ClearRecoveryMapTimeoutTarget implements TimeoutTarget
+// {
+// private List ids;
+//
+// ClearRecoveryMapTimeoutTarget(List ids)
+// {
+// this.ids = ids;
+// }
+//
+// public void timedOut(Timeout timeout)
+// {
+// if (trace) { log.trace("ClearRecoveryMap timeout fired"); }
+//
+// Iterator iter = ids.iterator();
+//
+// boolean added = false;
+//
+// while (iter.hasNext())
+// {
+// MessageReference ref = (MessageReference)iter.next();
+//
+// Object obj = recoveryMap.remove(new Long(ref.getMessage().getMessageID()));
+//
+// if (obj != null)
+// {
+// if (trace) { log.trace("Adding ref " + ref + " back into queue"); }
+//
+// synchronized (lock)
+// {
+// messageRefs.addFirst(ref, ref.getMessage().getPriority());
+//
+// deliveringCount.decrement();
+// }
+//
+// added = true;
+// }
+// }
+//
+// if (added)
+// {
+// synchronized (lock)
+// {
+// deliverInternal();
+// }
+// }
+// }
+// }
- // Static --------------------------------------------------------
-
- private static final Logger log = Logger.getLogger(MessagingQueue.class);
-
- private static final long DEFAULT_RECOVER_DELIVERIES_TIMEOUT = 5 * 60 * 10000;
-
- // Attributes ----------------------------------------------------
-
- private int nodeID;
-
- protected String name;
-
- protected Filter filter;
-
- protected boolean clustered;
-
- protected Distributor remoteDistributor;
-
- protected Distributor localDistributor;
-
- private boolean trace = log.isTraceEnabled();
-
- private Set suckers;
-
- private boolean handleFlowControlForConsumers;
-
- private Map recoveryArea;
-
- private Map recoveryMap;
-
- private long recoverDeliveriesTimeout;
-
- // Constructors --------------------------------------------------
-
- public MessagingQueue(int nodeID, String name, long id, MessageStore ms, PersistenceManager pm,
- boolean recoverable, int maxSize, Filter filter,
- int fullSize, int pageSize, int downCacheSize, boolean clustered,
- long recoverDeliveriesTimeout)
- {
- super(id, ms, pm, recoverable, maxSize, fullSize, pageSize, downCacheSize);
-
- setup(nodeID, name, filter, clustered, recoverDeliveriesTimeout);
- }
-
- /** This constructor is used when loading queue from storage - the paging params, maxSize and recoverDeliveriesTimeout don't matter
- * they are injected when the queue or topic service is started
- */
- public MessagingQueue(int nodeID, String name, long id, MessageStore ms, PersistenceManager pm,
- boolean recoverable, Filter filter,
- boolean clustered)
- {
- super(id, ms, pm, recoverable, -1, 100000, 2000, 2000); //paging params etc are actually ignored
-
- setup(nodeID, name, filter, clustered, DEFAULT_RECOVER_DELIVERIES_TIMEOUT);
- }
-
- /* This constructor is only used in tests - should we remove it? */
- public MessagingQueue(int nodeID, String name, long id, MessageStore ms, PersistenceManager pm,
- boolean recoverable, int maxSize, Filter filter, boolean clustered)
- {
- super(id, ms, pm, recoverable, maxSize);
-
- setup(nodeID, name, filter, clustered, DEFAULT_RECOVER_DELIVERIES_TIMEOUT);
- }
-
- /* Constructor for a remote queue representation in a cluster */
- public MessagingQueue(int nodeID, String name, long id, boolean recoverable,
- Filter filter, boolean clustered)
- {
- super(id, null, null, recoverable, -1);
-
- setup(nodeID, name, filter, clustered, DEFAULT_RECOVER_DELIVERIES_TIMEOUT);
- }
-
- private void setup(int nodeID, String name, Filter filter, boolean clustered, long recoverDeliveriesTimeout)
- {
- this.nodeID = nodeID;
-
- this.name = name;
-
- this.filter = filter;
-
- this.clustered = clustered;
-
- this.recoverDeliveriesTimeout = recoverDeliveriesTimeout;
-
- localDistributor = new DistributorWrapper(new RoundRobinDistributor());
-
- remoteDistributor = new DistributorWrapper(new RoundRobinDistributor());
-
- distributor = new ClusterRoundRobinDistributor(localDistributor, remoteDistributor);
-
- suckers = new HashSet();
-
- recoveryArea = new ConcurrentReaderHashMap();
-
- recoveryMap = Collections.synchronizedMap(new LinkedHashMap());
- }
-
- // Queue implementation
- // ---------------------------------------------------------------
-
- public int getNodeID()
- {
- return nodeID;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Filter getFilter()
- {
- return filter;
- }
-
- public boolean isClustered()
- {
- return clustered;
- }
-
- public Distributor getLocalDistributor()
- {
- return localDistributor;
- }
-
- public Distributor getRemoteDistributor()
- {
- return remoteDistributor;
- }
-
- /**
- * Merge the contents of one queue with another - this happens at failover when a queue is failed
- * over to another node, but a queue with the same name already exists. In this case we merge the
- * two queues.
- */
- public void mergeIn(long theChannelID, int nodeID) throws Exception
- {
- if (trace) { log.trace("Merging queue " + channelID + " node id " + nodeID + " into " + this +
- " initially refs:" + messageRefs.size()); }
-
- synchronized (lock)
- {
- flushDownCache();
-
- PersistenceManager.InitialLoadInfo ili =
- pm.mergeAndLoad(theChannelID, this.channelID, fullSize - messageRefs.size(),
- firstPagingOrder, nextPagingOrder);
-
- if (trace) { log.trace("Loaded " + ili.getRefInfos().size() + " refs"); }
-
- doLoad(ili);
-
- Map toRecover = (Map)recoveryArea.remove(new Integer(nodeID));
-
- if (trace) { log.trace("To recover is: " + toRecover); }
-
- LinkedList toTimeout = new LinkedList();
-
- if (toRecover != null)
- {
- //TODO this can be optimised to avoid a second scan - we could do this in load
-
- if (trace) { log.trace("Recovery area is not empty, putting refs in recovery map"); }
-
- Iterator iter = messageRefs.iterator();
-
- while (iter.hasNext())
- {
- MessageReference ref = (MessageReference)iter.next();
-
- Message message = ref.getMessage();
-
- String sessionID = (String)toRecover.remove(new Long(message.getMessageID()));
-
- if (sessionID != null)
- {
- if (trace) { log.trace("Added ref " + ref + " to recovery map"); }
-
- RecoveryEntry re = new RecoveryEntry();
- re.ref = ref;
- re.sessionID = sessionID;
-
- recoveryMap.put(new Long(message.getMessageID()), re);
-
- deliveringCount.increment();
-
- iter.remove();
-
- toTimeout.addLast(ref);
- }
- }
-
- //Note!
- //It is possible there are message ids in the toRecover that are not in the queue
- //This can happen if a delivery is replicated, the message delivered, then acked, then the node crashes
- //before the ack is replicated.
- //This is ok
-
- //Set up a timeout to put the refs back in the queue if they don't get claimed by failed over consumers
-
- MessagingTimeoutFactory.instance.getFactory().
- schedule(System.currentTimeMillis() + recoverDeliveriesTimeout, new ClearRecoveryMapTimeoutTarget(toTimeout));
-
- if (trace) { log.trace("Set timeout to fire in " + recoverDeliveriesTimeout); }
- }
-
- deliverInternal();
- }
- }
-
- public List recoverDeliveries(List messageIds)
- {
- if (trace) { log.trace("Recovering deliveries"); }
-
- List refs = new ArrayList();
-
- Iterator iter = messageIds.iterator();
-
- while (iter.hasNext())
- {
- Long messageID = (Long)iter.next();
-
- RecoveryEntry re = (RecoveryEntry)recoveryMap.remove(messageID);
-
- //This can actually be null - e.g. if failure happened right after a successful Ack so the client doesn't
- //remove the delivery but is no longer on the server
- if (re != null)
- {
- Delivery del = new SimpleDelivery(this, re.ref);
-
- if (trace) { log.trace("Recovered ref " + re.ref); }
-
- refs.add(del);
- }
- }
-
- return refs;
- }
-
- public void removeStrandedReferences(String sessionID)
- {
- if (trace) { log.trace("Removing stranded references for session " + sessionID); }
-
- // TODO this can be optimised - remove any remaining deliveries for the session id
- //these correspond to messages buffered on the client side for that client and should go back on the queue
-
- Iterator iter = recoveryMap.values().iterator();
-
- if (trace) { log.trace("Scanning recovery map for stray entries for session"); }
-
- List toCancel = new ArrayList();
-
- while (iter.hasNext())
- {
- RecoveryEntry re = (RecoveryEntry)iter.next();
-
- if (trace) { log.trace("Session id id " + re.sessionID); }
-
- if (re.sessionID.equals(sessionID))
- {
- MessageReference ref = re.ref;
-
- iter.remove();
-
- //Put back on queue
-
- toCancel.add(ref);
- }
- }
-
- for (int i = toCancel.size() - 1; i >= 0; i--)
- {
- MessageReference ref = (MessageReference)toCancel.get(i);
-
- synchronized (lock)
- {
- messageRefs.addFirst(ref, ref.getMessage().getPriority());
-
- //Need to decrement the delivery count too
- deliveringCount.decrement();
- }
-
- if (trace) { log.trace("Found one, added back on queue"); }
- }
-
- }
-
- public void registerSucker(MessageSucker sucker)
- {
- if (trace) { log.trace(this + " Registering sucker " + sucker); }
-
- synchronized (lock)
- {
- if (!suckers.contains(sucker))
- {
- suckers.add(sucker);
-
- handleFlowControlForConsumers = true;
-
- if (getReceiversReady() && localDistributor.getNumberOfReceivers() > 0)
- {
- if (trace) { log.trace(this + " receivers ready so setting consumer to true"); }
-
- sucker.setConsuming(true);
- }
- }
- }
- }
-
- public boolean unregisterSucker(MessageSucker sucker)
- {
- synchronized (lock)
- {
- boolean removed = suckers.remove(sucker);
-
- if (removed && suckers.isEmpty())
- {
- handleFlowControlForConsumers = false;
- }
-
- return removed;
- }
- }
-
- public int getFullSize()
- {
- return fullSize;
- }
-
- public int getPageSize()
- {
- return pageSize;
- }
-
- public int getDownCacheSize()
- {
- return downCacheSize;
- }
-
- public void addToRecoveryArea(int nodeID, long messageID, String sessionID)
- {
- if (trace) { log.trace("Adding message id " + messageID + " to recovery area from node " + nodeID); }
-
- //Note. The add might find the id already there
- //This could happen after the failover node has moved
- //When the batch add happens, then an add comes in shortly after but has already been taken into account
-
- Integer nid = new Integer(nodeID);
-
- Map ids = (Map)recoveryArea.get(nid);
-
- if (ids == null)
- {
- ids = new ConcurrentHashMap();
-
- recoveryArea.put(nid, ids);
- }
-
- ids.put(new Long(messageID), sessionID);
- }
-
- public void removeFromRecoveryArea(int nodeID, long messageID)
- {
- if (trace) { log.trace("Removing message id " + messageID + " to recovery area from node " + nodeID); }
-
- Integer nid = new Integer(nodeID);
-
- Map ids = (Map)recoveryArea.get(nid);
-
- //The remove might fail to find the id
- //This can happen if the removal has already be done - this could happen after the failover node has moved
- //When the batch add happens, then an ack comes in shortly after but has already been taken into account
-
- if (ids != null && ids.remove(new Long(messageID)) != null)
- {
- if (ids.isEmpty())
- {
- recoveryArea.remove(nid);
- }
- }
- }
-
- public void removeAllFromRecoveryArea(int nodeID)
- {
- if (trace) { log.trace("Removing all from recovery area for node " + nodeID); }
-
- boolean removed = recoveryArea.remove(new Integer(nodeID)) != null;
-
- if (trace) { log.trace("Removed:" + removed); }
- }
-
- public void addAllToRecoveryArea(int nodeID, Map ids)
- {
- if (trace) { log.trace("Adding all from recovery area for node " + nodeID +" set " + ids); }
-
- Integer nid = new Integer(nodeID);
-
- if (!(ids instanceof ConcurrentHashMap))
- {
- ids = new ConcurrentHashMap(ids);
- }
-
- if (trace) { log.trace("Adding " + ids.size() + " ids to recovery area for node " + nodeID); }
-
- recoveryArea.put(nid, ids);
-
- if (trace) { log.trace("Added"); }
- }
-
- public long getRecoverDeliveriesTimeout()
- {
- return recoverDeliveriesTimeout;
- }
-
- //testing only
-
- public Map getRecoveryArea()
- {
- if (trace) { log.trace("Getting recovery area, it is " + this.recoveryArea); }
-
- return this.recoveryArea;
- }
-
- public int getRecoveryMapSize()
- {
- return this.recoveryMap.size();
- }
-
- // ChannelSupport overrides --------------------------------------
-
- protected void deliverInternal()
- {
- super.deliverInternal();
-
- if (trace) { log.trace(this + " deliverInternal"); }
-
- if (handleFlowControlForConsumers && getReceiversReady() &&
- localDistributor.getNumberOfReceivers() > 0 && messageRefs.isEmpty())
- {
- if (trace) { log.trace("Informing suckers"); }
- //The receivers are still ready for more messages but there is nothing left in the local queue
- //so we inform the message suckers to start consuming (if they aren't already)
- informSuckers(true);
- }
- }
-
- protected void setReceiversReady(boolean receiversReady)
- {
- if (trace) { log.trace(this + " setReceiversReady " + receiversReady); }
-
- this.receiversReady = receiversReady;
-
- if (handleFlowControlForConsumers && receiversReady == false)
- {
- //No receivers are ready to accept message so tell the suckers to stop consuming
- informSuckers(false);
- }
- }
-
- // Public --------------------------------------------------------
-
- public String toString()
- {
- return "Queue[" + System.identityHashCode(this) + "/" + nodeID + "/" + channelID + "-" + name + "]";
- }
-
- public boolean equals(Object other)
- {
- if (!(other instanceof MessagingQueue))
- {
- return false;
- }
-
- MessagingQueue queue = (MessagingQueue)other;
-
- return (this.nodeID == queue.nodeID && this.name.equals(queue.name));
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- private void informSuckers(boolean consume)
- {
- Iterator iter = suckers.iterator();
-
- while (iter.hasNext())
- {
- MessageSucker sucker = (MessageSucker)iter.next();
-
- sucker.setConsuming(consume);
- }
- }
-
- // Inner classes -------------------------------------------------
-
- protected class DistributorWrapper implements Distributor
- {
- private Distributor distributor;
-
- protected DistributorWrapper(Distributor distributor)
- {
- this.distributor = distributor;
- }
-
- public Delivery handle(DeliveryObserver observer, MessageReference reference, Transaction tx)
- {
- return distributor.handle(observer, reference, tx);
- }
-
- public boolean add(Receiver receiver)
- {
- if (trace) { log.trace(this + " attempting to add receiver " + receiver); }
-
- synchronized (lock)
- {
- boolean added = distributor.add(receiver);
-
- if (trace) { log.trace("receiver " + receiver + (added ? "" : " NOT") + " added"); }
-
- setReceiversReady(true);
-
- return added;
- }
- }
-
- public void clear()
- {
- synchronized (lock)
- {
- distributor.clear();
- }
- }
-
- public boolean contains(Receiver receiver)
- {
- synchronized (lock)
- {
- return distributor.contains(receiver);
- }
- }
-
- public int getNumberOfReceivers()
- {
- synchronized (lock)
- {
- return distributor.getNumberOfReceivers();
- }
- }
-
- public Iterator iterator()
- {
- synchronized (lock)
- {
- return distributor.iterator();
- }
- }
-
- public boolean remove(Receiver receiver)
- {
- synchronized (lock)
- {
- boolean removed = distributor.remove(receiver);
-
- if (removed)
- {
- if (localDistributor.getNumberOfReceivers() == 0)
- {
- //Stop pulling from other queues into this one.
- informSuckers(false);
-
- if (remoteDistributor.getNumberOfReceivers() == 0)
- {
- setReceiversReady(false);
- }
- }
- }
-
- if (trace) { log.trace(this + (removed ? " removed " : " did NOT remove ") + receiver); }
-
- return removed;
- }
- }
- }
-
- static class RecoveryEntry
- {
- String sessionID;
-
- MessageReference ref;
- }
-
-
- private class ClearRecoveryMapTimeoutTarget implements TimeoutTarget
- {
- private List ids;
-
- ClearRecoveryMapTimeoutTarget(List ids)
- {
- this.ids = ids;
- }
-
- public void timedOut(Timeout timeout)
- {
- if (trace) { log.trace("ClearRecoveryMap timeout fired"); }
-
- Iterator iter = ids.iterator();
-
- boolean added = false;
-
- while (iter.hasNext())
- {
- MessageReference ref = (MessageReference)iter.next();
-
- Object obj = recoveryMap.remove(new Long(ref.getMessage().getMessageID()));
-
- if (obj != null)
- {
- if (trace) { log.trace("Adding ref " + ref + " back into queue"); }
-
- synchronized (lock)
- {
- messageRefs.addFirst(ref, ref.getMessage().getPriority());
-
- deliveringCount.decrement();
- }
-
- added = true;
- }
- }
-
- if (added)
- {
- synchronized (lock)
- {
- deliverInternal();
- }
- }
- }
- }
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/clusterconnection/ClusterConnectionManager.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/clusterconnection/ClusterConnectionManager.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/clusterconnection/ClusterConnectionManager.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -22,29 +22,7 @@
package org.jboss.messaging.core.impl.clusterconnection;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import javax.jms.JMSException;
-
-import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.JBossConnectionFactory;
-import org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate;
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Binding;
-import org.jboss.messaging.core.contract.ClusterNotification;
-import org.jboss.messaging.core.contract.ClusterNotificationListener;
-import org.jboss.messaging.core.contract.PostOffice;
-import org.jboss.messaging.core.contract.Queue;
-import org.jboss.messaging.core.contract.Replicator;
-
-import EDU.oswego.cs.dl.util.concurrent.Callable;
-import EDU.oswego.cs.dl.util.concurrent.TimedCallable;
-
/**
*
* This class handles connections to other nodes that are used to pull messages from remote queues to local queues
@@ -55,710 +33,710 @@
* $Id: $
*
*/
-public class ClusterConnectionManager implements ClusterNotificationListener
+public class ClusterConnectionManager //implements ClusterNotificationListener
{
- private static final Logger log = Logger.getLogger(ClusterConnectionManager.class);
-
- private static final long CLOSE_TIMEOUT = 2000;
-
- private boolean trace = log.isTraceEnabled();
-
- private Map connections;
-
- private boolean xa;
-
- private boolean started;
-
- private int nodeID;
-
- private String connectionFactoryUniqueName;
-
- private Replicator replicator;
-
- private PostOffice postOffice;
-
- private boolean preserveOrdering;
-
- private String suckerUser;
-
- private String suckerPassword;
-
- public ClusterConnectionManager(boolean xa, int nodeID,
- String connectionFactoryUniqueName, boolean preserveOrdering,
- String suckerUser,
- String suckerPassword)
- {
- connections = new HashMap();
-
- this.xa = xa;
-
- this.nodeID = nodeID;
-
- this.connectionFactoryUniqueName = connectionFactoryUniqueName;
-
- this.preserveOrdering = preserveOrdering;
-
- this.suckerUser = suckerUser;
-
- this.suckerPassword = suckerPassword;
-
- if (trace) { log.trace("Created " + this); }
- }
-
- public void injectReplicator(Replicator replicator)
- {
- this.replicator = replicator;
- }
-
- public void injectPostOffice(PostOffice postOffice)
- {
- this.postOffice = postOffice;
- }
-
- public synchronized void start() throws Exception
- {
- if (started)
- {
- return;
- }
-
- if (trace) { log.trace(this + " started"); }
-
- started = true;
- }
-
- public synchronized void stop()
- {
- if (!started)
- {
- return;
- }
-
- Iterator iter = connections.values().iterator();
-
- while (iter.hasNext())
- {
- ConnectionInfo info = (ConnectionInfo)iter.next();
-
- info.close();
- }
-
- connections.clear();
-
- started = false;
-
- if (trace) { log.trace(this + " stopped"); }
- }
-
- public Map getAllConnections()
- {
- return connections;
- }
-
- public void resetAllSuckers()
- {
- Iterator iter = connections.values().iterator();
-
- while (iter.hasNext())
- {
- ConnectionInfo conn = (ConnectionInfo)iter.next();
-
- conn.resetAllSuckers();
- }
- }
-
- public void setIsXA(boolean xa) throws Exception
- {
- boolean needToClose = this.xa != xa;
- if (needToClose)
- {
- closeAllSuckers();
- }
- this.xa = xa;
- if (needToClose)
- {
- createAllSuckers();
- }
- }
-
- public void closeAllSuckers()
- {
- Iterator iter = connections.values().iterator();
-
- while (iter.hasNext())
- {
- ConnectionInfo conn = (ConnectionInfo)iter.next();
-
- conn.closeAllSuckers();
- }
- }
-
- /*
- * We respond to two types of events -
- *
- * 1) Connection factory deployment / undeployment
- *
- * We need to know the connection factories for the nodes so we can create the connections
- *
- * Which connection factory should we use?
- *
- * Clustering uses a "special connection factory" which is deployed on each node
- * this connection factory has no JNDI bindings - since it is only replicated via the replicator
- * it is configured in the connection-factories-service.xml file
- *
- * 2) Binds or unbinds
- *
- * When a bind or unbind (either remote or local) of a durable queue comes in we look to see if we have a local queue of the same
- * name, then look to see if we have a remote queue of the same name, and if so, create a connection to suck from the remote queue
- * We need to listen for both remote and local binds since the queue may be deployed on the remote node before the local one
- * or vice versa, in both cases we need to create the connection
- *
- */
- public synchronized void notify(ClusterNotification notification)
- {
- if (replicator == null)
- {
- //Non clustered
-
- return;
- }
-
- if (trace) { log.trace(this + " notification received " + notification); }
-
- try
- {
- if (notification.type == ClusterNotification.TYPE_REPLICATOR_PUT && notification.data instanceof String)
- {
- String key = (String)notification.data;
-
- if (key.startsWith(Replicator.CF_PREFIX))
- {
- //A connection factory has been deployed
- //We are only interested in the deployment of our special connection factory
-
- String uniqueName = key.substring(Replicator.CF_PREFIX.length());
-
- if (uniqueName.equals(connectionFactoryUniqueName))
- {
- log.trace(this + " deployment of ClusterConnectionFactory");
-
- synchronized (this)
- {
- ensureAllConnectionsCreated();
-
- //Now create any suckers for already deployed remote queues - this copes with the case where the CF
- //is deployed AFTER the queues are deployed
-
- createAllSuckers();
- }
- }
- }
- }
- else if (notification.type == ClusterNotification.TYPE_REPLICATOR_REMOVE && notification.data instanceof String)
- {
- String key = (String)notification.data;
-
- if (key.startsWith(Replicator.CF_PREFIX))
- {
- //A connection factory has been undeployed
- //We are only interested in the undeployment of our special connection factory
-
- String uniqueName = key.substring(Replicator.CF_PREFIX.length());
-
- if (uniqueName.equals(connectionFactoryUniqueName))
- {
- Map updatedReplicantMap = replicator.get(key);
-
- List toRemove = new ArrayList();
-
- Iterator iter = connections.entrySet().iterator();
-
- while (iter.hasNext())
- {
- Map.Entry entry = (Map.Entry)iter.next();
-
- Integer nid = (Integer)entry.getKey();
-
- if (updatedReplicantMap.get(nid) == null)
- {
- toRemove.add(nid);
- }
- }
-
- iter = toRemove.iterator();
-
- while (iter.hasNext())
- {
- Integer nid = (Integer)iter.next();
-
- ConnectionInfo info = (ConnectionInfo)connections.remove(nid);
-
- info.close();
- }
- }
- }
- }
- else if (notification.type == ClusterNotification.TYPE_BIND)
- {
- String queueName = (String)notification.data;
-
- if (trace) { log.trace(this + " bind of queue " + queueName); }
-
- if (notification.nodeID == this.nodeID)
- {
- //Local bind
-
- if (trace) { log.trace(this + " Local bind"); }
-
- ensureAllConnectionsCreated();
-
- //Loook for remote queues
-
- Collection bindings = postOffice.getAllBindingsForQueueName(queueName);
-
- Iterator iter = bindings.iterator();
-
- if (trace) { log.trace(this + " Looking for remote bindings"); }
-
- while (iter.hasNext())
- {
- Binding binding = (Binding)iter.next();
-
- if (trace) { log.trace(this + " Remote binding is " + binding); }
-
- //This will only create it if it doesn't already exist
-
- if (binding.queue.getNodeID() != this.nodeID)
- {
- if (trace) { log.trace(this + " Creating sucker"); }
-
- createSucker(queueName, binding.queue.getNodeID());
- }
- }
- }
- else
- {
- //Remote bind
-
- if (trace) { log.trace(this + " Remote bind"); }
-
- ensureAllConnectionsCreated();
-
- //Look for local queue
-
- Binding localBinding = postOffice.getBindingForQueueName(queueName);
-
- if (localBinding == null)
- {
- //This is ok - the queue was deployed on the remote node before being deployed on the local node - do nothing for now
- if (trace) { log.trace(this + " There's no local binding"); }
- }
- else
- {
- //The queue has already been deployed on the local node so create a sucker
-
- if (trace) { log.trace(this + " Creating sucker"); }
-
- createSucker(queueName, notification.nodeID);
- }
- }
- }
- else if (notification.type == ClusterNotification.TYPE_UNBIND)
- {
- String queueName = (String)notification.data;
-
- if (notification.nodeID == this.nodeID)
- {
- //Local unbind
-
- //We need to remove any suckers corresponding to remote nodes
-
- removeAllSuckers(queueName);
- }
- else
- {
- //Remote unbind
-
- //We need to remove the sucker corresponding to the remote queue
-
- removeSucker(queueName, notification.nodeID);
- }
- }
- }
- catch (Exception e)
- {
- log.error("Failed to process notification", e);
- }
- }
-
- public String toString()
- {
- return "ClusterConnectionManager:" + System.identityHashCode(this) +
- " xa: " + xa + " nodeID: " + nodeID + " connectionFactoryName: " + connectionFactoryUniqueName;
- }
-
- private void ensureAllConnectionsCreated() throws Exception
- {
- Map updatedReplicantMap = replicator.get(Replicator.CF_PREFIX + connectionFactoryUniqueName);
-
- // Make sure all connections are created
-
- Iterator iter = updatedReplicantMap.entrySet().iterator();
-
- while (iter.hasNext())
- {
- Map.Entry entry = (Map.Entry)iter.next();
-
- Integer nid = (Integer)entry.getKey();
-
- ClientConnectionFactoryDelegate delegate = (ClientConnectionFactoryDelegate)entry.getValue();
-
- if (connections.get(nid) == null)
- {
- try
- {
- ConnectionInfo info = new ConnectionInfo(new JBossConnectionFactory(delegate), suckerUser, suckerPassword);
-
- log.trace(this + " created connection info " + info);
-
- connections.put(nid, info);
-
- info.start();
-
- }
- catch (Exception e)
- {
- log.error("Failed to start connection info ", e);
- }
- }
- }
- }
-
- private void createSucker(String queueName, int nodeID) throws Exception
- {
- log.debug("createSucker " + queueName + " nodeID=" + nodeID);
-
- ConnectionInfo info = (ConnectionInfo)connections.get(new Integer(nodeID));
-
- if (info == null)
- {
- if (trace) { log.trace("Cluster pull connection factory has not yet been deployed on node " + nodeID); }
-
- return;
- }
-
- ConnectionInfo localInfo = (ConnectionInfo)connections.get(new Integer(this.nodeID));
-
- if (localInfo == null)
- {
- if (trace) { log.trace("Cluster pull connection factory has not yet been deployed on local node"); }
-
- return;
- }
-
- //Only create if it isn't already there
-
- if (!info.hasSucker(queueName))
- {
- if (trace) { log.trace("Creating Sucker for queue " + queueName + " node " + nodeID); }
-
- // Need to lookup the local queue
-
- Binding binding = this.postOffice.getBindingForQueueName(queueName);
-
- Queue localQueue = binding.queue;
-
- if (localQueue.isClustered())
- {
- //Find channel id for remote queue - we need this for doing shared DB optimisation
- Collection coll = this.postOffice.getAllBindingsForQueueName(queueName);
- Iterator iter = coll.iterator();
- long sourceChannelID = -1;
- while (iter.hasNext())
- {
- Binding b = (Binding)iter.next();
- if (b.queue.getNodeID() == nodeID)
- {
- sourceChannelID = b.queue.getChannelID();
- }
- }
- if (sourceChannelID == -1)
- {
- throw new IllegalArgumentException("Cannot find source channel id");
- }
-
- MessageSucker sucker = new MessageSucker(localQueue, info.connection, localInfo.connection,
- xa, preserveOrdering, sourceChannelID);
-
- info.addSucker(sucker);
-
- sucker.start();
-
- if (trace) { log.trace("Started it"); }
- }
- }
- else
- {
- if (trace) { log.trace("Sucker for queue " + queueName + " node " + nodeID + " already exists, not creating it"); }
- }
- }
-
- private void removeSucker(String queueName, int nodeID)
- {
- log.debug("removeSucker " + queueName + " nodeID=" + nodeID);
-
- ConnectionInfo info = (ConnectionInfo)connections.get(new Integer(nodeID));
-
- if (info == null)
- {
- //This is OK, the ClusterPullConnectionfactory might never have been deployed
- return;
- }
-
- MessageSucker sucker = info.removeSucker(queueName);
-
- if (sucker == null)
- {
- //This is OK too
- }
- else
- {
- sucker.stop();
- }
- }
-
- private void removeAllSuckers(String queueName)
- {
- log.debug("removeAllSuckers " + queueName);
-
- Iterator iter = connections.values().iterator();
-
- while (iter.hasNext())
- {
- ConnectionInfo info = (ConnectionInfo)iter.next();
-
- MessageSucker sucker = info.removeSucker(queueName);
-
- //Sucker may not exist - this is ok
-
- if (sucker != null)
- {
- sucker.stop();
- }
- }
- }
-
- private void createAllSuckers() throws Exception
- {
- Collection allBindings = postOffice.getAllBindings();
-
- Iterator iter = allBindings.iterator();
-
- Map nameMap = new HashMap();
-
- //This can probably be greatly optimised
-
- while (iter.hasNext())
- {
- Binding binding = (Binding)iter.next();
-
- if (binding.queue.isClustered())
- {
- List queues = (List)nameMap.get(binding.queue.getName());
-
- if (queues == null)
- {
- queues = new ArrayList();
-
- nameMap.put(binding.queue.getName(), queues);
- }
-
- queues.add(binding.queue);
- }
- }
-
- iter = nameMap.entrySet().iterator();
-
- while (iter.hasNext())
- {
- Map.Entry entry = (Map.Entry)iter.next();
-
- String queueName = (String)entry.getKey();
-
- List queues = (List)entry.getValue();
-
- //Find a local queue if any
-
- Iterator iter2 = queues.iterator();
-
- Queue localQueue = null;
-
- while (iter2.hasNext())
- {
- Queue queue = (Queue)iter2.next();
-
- if (queue.getNodeID() == this.nodeID)
- {
- localQueue = queue;
-
- break;
- }
- }
-
- if (localQueue != null)
- {
- iter2 = queues.iterator();
-
- while (iter2.hasNext())
- {
- Queue queue = (Queue)iter2.next();
-
- if (queue.getNodeID() != this.nodeID && queue.isClustered())
- {
- //Now we have found a local and remote with matching names - so we can create a sucker
-
- createSucker(queueName, queue.getNodeID());
- }
- }
- }
- }
- }
-
- class ConnectionInfo
- {
- private JBossConnectionFactory connectionFactory;
-
- private JBossConnection connection;
-
- private Map suckers;
-
- private boolean started;
-
- private String suckerUser;
-
- private String suckerPassword;
-
- ConnectionInfo(JBossConnectionFactory connectionFactory, String suckerUser, String suckerPassword) throws Exception
- {
- this.connectionFactory = connectionFactory;
-
- this.suckers = new HashMap();
-
- this.suckerUser = suckerUser;
-
- this.suckerPassword = suckerPassword;
- }
-
- synchronized void start() throws Exception
- {
- if (started)
- {
- return;
- }
-
- if (connection == null)
- {
- connection = (JBossConnection)connectionFactory.createConnection(suckerUser, suckerPassword);
- }
-
- connection.start();
-
- started = true;
- }
-
- synchronized void stop() throws Exception
- {
- if (!started)
- {
- return;
- }
-
- connection.stop();
-
- started = false;
- }
-
- synchronized void resetAllSuckers()
- {
- Iterator iter = suckers.values().iterator();
-
- while (iter.hasNext())
- {
- MessageSucker sucker = (MessageSucker)iter.next();
-
- sucker.setConsuming(false);
- }
- }
-
- synchronized void closeAllSuckers()
- {
- Iterator iter = suckers.values().iterator();
-
- while (iter.hasNext())
- {
- MessageSucker sucker = (MessageSucker)iter.next();
-
- sucker.stop();
- }
-
- suckers.clear();
- }
-
- synchronized void close()
- {
- closeAllSuckers();
-
- //Note we use a timed callable since remoting has a habit of hanging on attempting to close
- //We do not want this to hang the system - especially failover
-
- Callable callable = new Callable() { public Object call()
- {
- try
- {
- connection.close();
- }
- catch (JMSException ignore)
- {
- }
- return null;
- } };
-
- Callable timedCallable = new TimedCallable(callable, CLOSE_TIMEOUT);
-
- try
- {
- timedCallable.call();
- }
- catch (Throwable t)
- {
- //Ignore - the server might have already closed - so this is ok
- }
-
- connection = null;
-
- started = false;
- }
-
- synchronized boolean hasSucker(String queueName)
- {
- return suckers.containsKey(queueName);
- }
-
- synchronized void addSucker(MessageSucker sucker)
- {
- if (suckers.containsKey(sucker.getQueueName()))
- {
- throw new IllegalStateException("Already has sucker for queue " + sucker.getQueueName());
- }
-
- suckers.put(sucker.getQueueName(), sucker);
- }
-
- synchronized MessageSucker removeSucker(String queueName)
- {
- MessageSucker sucker = (MessageSucker)suckers.remove(queueName);
-
- return sucker;
- }
- }
+// private static final Logger log = Logger.getLogger(ClusterConnectionManager.class);
+//
+// private static final long CLOSE_TIMEOUT = 2000;
+//
+// private boolean trace = log.isTraceEnabled();
+//
+// private Map connections;
+//
+// private boolean xa;
+//
+// private boolean started;
+//
+// private int nodeID;
+//
+// private String connectionFactoryUniqueName;
+//
+// private Replicator replicator;
+//
+// private PostOffice postOffice;
+//
+// private boolean preserveOrdering;
+//
+// private String suckerUser;
+//
+// private String suckerPassword;
+//
+// public ClusterConnectionManager(boolean xa, int nodeID,
+// String connectionFactoryUniqueName, boolean preserveOrdering,
+// String suckerUser,
+// String suckerPassword)
+// {
+// connections = new HashMap();
+//
+// this.xa = xa;
+//
+// this.nodeID = nodeID;
+//
+// this.connectionFactoryUniqueName = connectionFactoryUniqueName;
+//
+// this.preserveOrdering = preserveOrdering;
+//
+// this.suckerUser = suckerUser;
+//
+// this.suckerPassword = suckerPassword;
+//
+// if (trace) { log.trace("Created " + this); }
+// }
+//
+// public void injectReplicator(Replicator replicator)
+// {
+// this.replicator = replicator;
+// }
+//
+// public void injectPostOffice(PostOffice postOffice)
+// {
+// this.postOffice = postOffice;
+// }
+//
+// public synchronized void start() throws Exception
+// {
+// if (started)
+// {
+// return;
+// }
+//
+// if (trace) { log.trace(this + " started"); }
+//
+// started = true;
+// }
+//
+// public synchronized void stop()
+// {
+// if (!started)
+// {
+// return;
+// }
+//
+// Iterator iter = connections.values().iterator();
+//
+// while (iter.hasNext())
+// {
+// ConnectionInfo info = (ConnectionInfo)iter.next();
+//
+// info.close();
+// }
+//
+// connections.clear();
+//
+// started = false;
+//
+// if (trace) { log.trace(this + " stopped"); }
+// }
+//
+// public Map getAllConnections()
+// {
+// return connections;
+// }
+//
+// public void resetAllSuckers()
+// {
+// Iterator iter = connections.values().iterator();
+//
+// while (iter.hasNext())
+// {
+// ConnectionInfo conn = (ConnectionInfo)iter.next();
+//
+// conn.resetAllSuckers();
+// }
+// }
+//
+// public void setIsXA(boolean xa) throws Exception
+// {
+// boolean needToClose = this.xa != xa;
+// if (needToClose)
+// {
+// closeAllSuckers();
+// }
+// this.xa = xa;
+// if (needToClose)
+// {
+// createAllSuckers();
+// }
+// }
+//
+// public void closeAllSuckers()
+// {
+// Iterator iter = connections.values().iterator();
+//
+// while (iter.hasNext())
+// {
+// ConnectionInfo conn = (ConnectionInfo)iter.next();
+//
+// conn.closeAllSuckers();
+// }
+// }
+//
+// /*
+// * We respond to two types of events -
+// *
+// * 1) Connection factory deployment / undeployment
+// *
+// * We need to know the connection factories for the nodes so we can create the connections
+// *
+// * Which connection factory should we use?
+// *
+// * Clustering uses a "special connection factory" which is deployed on each node
+// * this connection factory has no JNDI bindings - since it is only replicated via the replicator
+// * it is configured in the connection-factories-service.xml file
+// *
+// * 2) Binds or unbinds
+// *
+// * When a bind or unbind (either remote or local) of a durable queue comes in we look to see if we have a local queue of the same
+// * name, then look to see if we have a remote queue of the same name, and if so, create a connection to suck from the remote queue
+// * We need to listen for both remote and local binds since the queue may be deployed on the remote node before the local one
+// * or vice versa, in both cases we need to create the connection
+// *
+// */
+// public synchronized void notify(ClusterNotification notification)
+// {
+// if (replicator == null)
+// {
+// //Non clustered
+//
+// return;
+// }
+//
+// if (trace) { log.trace(this + " notification received " + notification); }
+//
+// try
+// {
+// if (notification.type == ClusterNotification.TYPE_REPLICATOR_PUT && notification.data instanceof String)
+// {
+// String key = (String)notification.data;
+//
+// if (key.startsWith(Replicator.CF_PREFIX))
+// {
+// //A connection factory has been deployed
+// //We are only interested in the deployment of our special connection factory
+//
+// String uniqueName = key.substring(Replicator.CF_PREFIX.length());
+//
+// if (uniqueName.equals(connectionFactoryUniqueName))
+// {
+// log.trace(this + " deployment of ClusterConnectionFactory");
+//
+// synchronized (this)
+// {
+// ensureAllConnectionsCreated();
+//
+// //Now create any suckers for already deployed remote queues - this copes with the case where the CF
+// //is deployed AFTER the queues are deployed
+//
+// createAllSuckers();
+// }
+// }
+// }
+// }
+// else if (notification.type == ClusterNotification.TYPE_REPLICATOR_REMOVE && notification.data instanceof String)
+// {
+// String key = (String)notification.data;
+//
+// if (key.startsWith(Replicator.CF_PREFIX))
+// {
+// //A connection factory has been undeployed
+// //We are only interested in the undeployment of our special connection factory
+//
+// String uniqueName = key.substring(Replicator.CF_PREFIX.length());
+//
+// if (uniqueName.equals(connectionFactoryUniqueName))
+// {
+// Map updatedReplicantMap = replicator.get(key);
+//
+// List toRemove = new ArrayList();
+//
+// Iterator iter = connections.entrySet().iterator();
+//
+// while (iter.hasNext())
+// {
+// Map.Entry entry = (Map.Entry)iter.next();
+//
+// Integer nid = (Integer)entry.getKey();
+//
+// if (updatedReplicantMap.get(nid) == null)
+// {
+// toRemove.add(nid);
+// }
+// }
+//
+// iter = toRemove.iterator();
+//
+// while (iter.hasNext())
+// {
+// Integer nid = (Integer)iter.next();
+//
+// ConnectionInfo info = (ConnectionInfo)connections.remove(nid);
+//
+// info.close();
+// }
+// }
+// }
+// }
+// else if (notification.type == ClusterNotification.TYPE_BIND)
+// {
+// String queueName = (String)notification.data;
+//
+// if (trace) { log.trace(this + " bind of queue " + queueName); }
+//
+// if (notification.nodeID == this.nodeID)
+// {
+// //Local bind
+//
+// if (trace) { log.trace(this + " Local bind"); }
+//
+// ensureAllConnectionsCreated();
+//
+// //Loook for remote queues
+//
+// Collection bindings = postOffice.getAllBindingsForQueueName(queueName);
+//
+// Iterator iter = bindings.iterator();
+//
+// if (trace) { log.trace(this + " Looking for remote bindings"); }
+//
+// while (iter.hasNext())
+// {
+// Binding binding = (Binding)iter.next();
+//
+// if (trace) { log.trace(this + " Remote binding is " + binding); }
+//
+// //This will only create it if it doesn't already exist
+//
+// if (binding.queue.getNodeID() != this.nodeID)
+// {
+// if (trace) { log.trace(this + " Creating sucker"); }
+//
+// createSucker(queueName, binding.queue.getNodeID());
+// }
+// }
+// }
+// else
+// {
+// //Remote bind
+//
+// if (trace) { log.trace(this + " Remote bind"); }
+//
+// ensureAllConnectionsCreated();
+//
+// //Look for local queue
+//
+// Binding localBinding = postOffice.getBindingForQueueName(queueName);
+//
+// if (localBinding == null)
+// {
+// //This is ok - the queue was deployed on the remote node before being deployed on the local node - do nothing for now
+// if (trace) { log.trace(this + " There's no local binding"); }
+// }
+// else
+// {
+// //The queue has already been deployed on the local node so create a sucker
+//
+// if (trace) { log.trace(this + " Creating sucker"); }
+//
+// createSucker(queueName, notification.nodeID);
+// }
+// }
+// }
+// else if (notification.type == ClusterNotification.TYPE_UNBIND)
+// {
+// String queueName = (String)notification.data;
+//
+// if (notification.nodeID == this.nodeID)
+// {
+// //Local unbind
+//
+// //We need to remove any suckers corresponding to remote nodes
+//
+// removeAllSuckers(queueName);
+// }
+// else
+// {
+// //Remote unbind
+//
+// //We need to remove the sucker corresponding to the remote queue
+//
+// removeSucker(queueName, notification.nodeID);
+// }
+// }
+// }
+// catch (Exception e)
+// {
+// log.error("Failed to process notification", e);
+// }
+// }
+//
+// public String toString()
+// {
+// return "ClusterConnectionManager:" + System.identityHashCode(this) +
+// " xa: " + xa + " nodeID: " + nodeID + " connectionFactoryName: " + connectionFactoryUniqueName;
+// }
+//
+// private void ensureAllConnectionsCreated() throws Exception
+// {
+// Map updatedReplicantMap = replicator.get(Replicator.CF_PREFIX + connectionFactoryUniqueName);
+//
+// // Make sure all connections are created
+//
+// Iterator iter = updatedReplicantMap.entrySet().iterator();
+//
+// while (iter.hasNext())
+// {
+// Map.Entry entry = (Map.Entry)iter.next();
+//
+// Integer nid = (Integer)entry.getKey();
+//
+// ClientConnectionFactoryDelegate delegate = (ClientConnectionFactoryDelegate)entry.getValue();
+//
+// if (connections.get(nid) == null)
+// {
+// try
+// {
+// ConnectionInfo info = new ConnectionInfo(new JBossConnectionFactory(delegate), suckerUser, suckerPassword);
+//
+// log.trace(this + " created connection info " + info);
+//
+// connections.put(nid, info);
+//
+// info.start();
+//
+// }
+// catch (Exception e)
+// {
+// log.error("Failed to start connection info ", e);
+// }
+// }
+// }
+// }
+//
+// private void createSucker(String queueName, int nodeID) throws Exception
+// {
+// log.debug("createSucker " + queueName + " nodeID=" + nodeID);
+//
+// ConnectionInfo info = (ConnectionInfo)connections.get(new Integer(nodeID));
+//
+// if (info == null)
+// {
+// if (trace) { log.trace("Cluster pull connection factory has not yet been deployed on node " + nodeID); }
+//
+// return;
+// }
+//
+// ConnectionInfo localInfo = (ConnectionInfo)connections.get(new Integer(this.nodeID));
+//
+// if (localInfo == null)
+// {
+// if (trace) { log.trace("Cluster pull connection factory has not yet been deployed on local node"); }
+//
+// return;
+// }
+//
+// //Only create if it isn't already there
+//
+// if (!info.hasSucker(queueName))
+// {
+// if (trace) { log.trace("Creating Sucker for queue " + queueName + " node " + nodeID); }
+//
+// // Need to lookup the local queue
+//
+// Binding binding = this.postOffice.getBindingForQueueName(queueName);
+//
+// Queue localQueue = binding.queue;
+//
+// if (localQueue.isClustered())
+// {
+// //Find channel id for remote queue - we need this for doing shared DB optimisation
+// Collection coll = this.postOffice.getAllBindingsForQueueName(queueName);
+// Iterator iter = coll.iterator();
+// long sourceChannelID = -1;
+// while (iter.hasNext())
+// {
+// Binding b = (Binding)iter.next();
+// if (b.queue.getNodeID() == nodeID)
+// {
+// sourceChannelID = b.queue.getChannelID();
+// }
+// }
+// if (sourceChannelID == -1)
+// {
+// throw new IllegalArgumentException("Cannot find source channel id");
+// }
+//
+// MessageSucker sucker = new MessageSucker(localQueue, info.connection, localInfo.connection,
+// xa, preserveOrdering, sourceChannelID);
+//
+// info.addSucker(sucker);
+//
+// sucker.start();
+//
+// if (trace) { log.trace("Started it"); }
+// }
+// }
+// else
+// {
+// if (trace) { log.trace("Sucker for queue " + queueName + " node " + nodeID + " already exists, not creating it"); }
+// }
+// }
+//
+// private void removeSucker(String queueName, int nodeID)
+// {
+// log.debug("removeSucker " + queueName + " nodeID=" + nodeID);
+//
+// ConnectionInfo info = (ConnectionInfo)connections.get(new Integer(nodeID));
+//
+// if (info == null)
+// {
+// //This is OK, the ClusterPullConnectionfactory might never have been deployed
+// return;
+// }
+//
+// MessageSucker sucker = info.removeSucker(queueName);
+//
+// if (sucker == null)
+// {
+// //This is OK too
+// }
+// else
+// {
+// sucker.stop();
+// }
+// }
+//
+// private void removeAllSuckers(String queueName)
+// {
+// log.debug("removeAllSuckers " + queueName);
+//
+// Iterator iter = connections.values().iterator();
+//
+// while (iter.hasNext())
+// {
+// ConnectionInfo info = (ConnectionInfo)iter.next();
+//
+// MessageSucker sucker = info.removeSucker(queueName);
+//
+// //Sucker may not exist - this is ok
+//
+// if (sucker != null)
+// {
+// sucker.stop();
+// }
+// }
+// }
+//
+// private void createAllSuckers() throws Exception
+// {
+// Collection allBindings = postOffice.getAllBindings();
+//
+// Iterator iter = allBindings.iterator();
+//
+// Map nameMap = new HashMap();
+//
+// //This can probably be greatly optimised
+//
+// while (iter.hasNext())
+// {
+// Binding binding = (Binding)iter.next();
+//
+// if (binding.queue.isClustered())
+// {
+// List queues = (List)nameMap.get(binding.queue.getName());
+//
+// if (queues == null)
+// {
+// queues = new ArrayList();
+//
+// nameMap.put(binding.queue.getName(), queues);
+// }
+//
+// queues.add(binding.queue);
+// }
+// }
+//
+// iter = nameMap.entrySet().iterator();
+//
+// while (iter.hasNext())
+// {
+// Map.Entry entry = (Map.Entry)iter.next();
+//
+// String queueName = (String)entry.getKey();
+//
+// List queues = (List)entry.getValue();
+//
+// //Find a local queue if any
+//
+// Iterator iter2 = queues.iterator();
+//
+// Queue localQueue = null;
+//
+// while (iter2.hasNext())
+// {
+// Queue queue = (Queue)iter2.next();
+//
+// if (queue.getNodeID() == this.nodeID)
+// {
+// localQueue = queue;
+//
+// break;
+// }
+// }
+//
+// if (localQueue != null)
+// {
+// iter2 = queues.iterator();
+//
+// while (iter2.hasNext())
+// {
+// Queue queue = (Queue)iter2.next();
+//
+// if (queue.getNodeID() != this.nodeID && queue.isClustered())
+// {
+// //Now we have found a local and remote with matching names - so we can create a sucker
+//
+// createSucker(queueName, queue.getNodeID());
+// }
+// }
+// }
+// }
+// }
+//
+// class ConnectionInfo
+// {
+// private JBossConnectionFactory connectionFactory;
+//
+// private JBossConnection connection;
+//
+// private Map suckers;
+//
+// private boolean started;
+//
+// private String suckerUser;
+//
+// private String suckerPassword;
+//
+// ConnectionInfo(JBossConnectionFactory connectionFactory, String suckerUser, String suckerPassword) throws Exception
+// {
+// this.connectionFactory = connectionFactory;
+//
+// this.suckers = new HashMap();
+//
+// this.suckerUser = suckerUser;
+//
+// this.suckerPassword = suckerPassword;
+// }
+//
+// synchronized void start() throws Exception
+// {
+// if (started)
+// {
+// return;
+// }
+//
+// if (connection == null)
+// {
+// connection = (JBossConnection)connectionFactory.createConnection(suckerUser, suckerPassword);
+// }
+//
+// connection.start();
+//
+// started = true;
+// }
+//
+// synchronized void stop() throws Exception
+// {
+// if (!started)
+// {
+// return;
+// }
+//
+// connection.stop();
+//
+// started = false;
+// }
+//
+// synchronized void resetAllSuckers()
+// {
+// Iterator iter = suckers.values().iterator();
+//
+// while (iter.hasNext())
+// {
+// MessageSucker sucker = (MessageSucker)iter.next();
+//
+// sucker.setConsuming(false);
+// }
+// }
+//
+// synchronized void closeAllSuckers()
+// {
+// Iterator iter = suckers.values().iterator();
+//
+// while (iter.hasNext())
+// {
+// MessageSucker sucker = (MessageSucker)iter.next();
+//
+// sucker.stop();
+// }
+//
+// suckers.clear();
+// }
+//
+// synchronized void close()
+// {
+// closeAllSuckers();
+//
+// //Note we use a timed callable since remoting has a habit of hanging on attempting to close
+// //We do not want this to hang the system - especially failover
+//
+// Callable callable = new Callable() { public Object call()
+// {
+// try
+// {
+// connection.close();
+// }
+// catch (JMSException ignore)
+// {
+// }
+// return null;
+// } };
+//
+// Callable timedCallable = new TimedCallable(callable, CLOSE_TIMEOUT);
+//
+// try
+// {
+// timedCallable.call();
+// }
+// catch (Throwable t)
+// {
+// //Ignore - the server might have already closed - so this is ok
+// }
+//
+// connection = null;
+//
+// started = false;
+// }
+//
+// synchronized boolean hasSucker(String queueName)
+// {
+// return suckers.containsKey(queueName);
+// }
+//
+// synchronized void addSucker(MessageSucker sucker)
+// {
+// if (suckers.containsKey(sucker.getQueueName()))
+// {
+// throw new IllegalStateException("Already has sucker for queue " + sucker.getQueueName());
+// }
+//
+// suckers.put(sucker.getQueueName(), sucker);
+// }
+//
+// synchronized MessageSucker removeSucker(String queueName)
+// {
+// MessageSucker sucker = (MessageSucker)suckers.remove(queueName);
+//
+// return sucker;
+// }
+// }
}
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/clusterconnection/MessageSucker.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -22,26 +22,7 @@
package org.jboss.messaging.core.impl.clusterconnection;
-import javax.jms.DeliveryMode;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.Session;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.xa.XAResource;
-import org.jboss.jms.client.JBossConnection;
-import org.jboss.jms.client.JBossSession;
-import org.jboss.jms.delegate.ConsumerDelegate;
-import org.jboss.jms.delegate.ProducerDelegate;
-import org.jboss.jms.delegate.SessionDelegate;
-import org.jboss.jms.destination.JBossDestination;
-import org.jboss.jms.destination.JBossQueue;
-import org.jboss.jms.message.MessageProxy;
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.Queue;
-import org.jboss.tm.TransactionManagerLocator;
-
/**
*
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -50,319 +31,319 @@
* $Id: $
*
*/
-public class MessageSucker implements MessageListener
+public class MessageSucker //implements MessageListener
{
- private static final Logger log = Logger.getLogger(MessageSucker.class);
-
- private boolean trace = log.isTraceEnabled();
-
- private JBossConnection sourceConnection;
-
- private JBossConnection localConnection;
-
- private Queue localQueue;
-
- private SessionDelegate sourceSession;
-
- private SessionDelegate localSession;
-
- private ProducerDelegate producer;
-
- private volatile boolean started;
-
- private boolean xa;
-
- private TransactionManager tm;
-
- private boolean consuming;
-
- private ConsumerDelegate consumer;
-
- private boolean preserveOrdering;
-
- private long sourceChannelID;
-
- public String toString()
- {
- return "MessageSucker:" + System.identityHashCode(this) + " queue:" + localQueue.getName();
- }
-
- MessageSucker(Queue localQueue, JBossConnection sourceConnection, JBossConnection localConnection,
- boolean xa, boolean preserveOrdering, long sourceChannelID)
- {
- if (trace) { log.trace("Creating message sucker, localQueue:" + localQueue + " xa:" + xa + " preserveOrdering:" + preserveOrdering); }
-
- this.localQueue = localQueue;
-
- this.sourceConnection = sourceConnection;
-
- this.localConnection = localConnection;
-
- //this.xa = xa;
-
- //XA is currently disabled for message sucking - this is because JBM 1.4.0 uses shared database so XA is
- //unnecesary - we can move the ref from one channel to another with a database update
- this.xa = false;
-
- this.preserveOrdering = preserveOrdering;
-
- this.sourceChannelID = sourceChannelID;
-
- if (xa)
- {
- tm = TransactionManagerLocator.getInstance().locate();
- }
- }
-
- synchronized void start() throws Exception
- {
- if (started)
- {
- return;
- }
-
- if (trace) { log.trace(this + " starting"); }
-
- if (!xa)
- {
- //If not XA then we use a client ack session for consuming - this allows us to get the message, send it to the destination
- //then ack the message.
- //This means that if a failure occurs between sending and acking the message won't be lost but may get delivered
- //twice - i.e we have dups_ok behaviour
-
- JBossSession sess = (JBossSession)sourceConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- sourceSession = (SessionDelegate)sess.getDelegate();
-
- sess = (JBossSession)localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- localSession = (SessionDelegate)sess.getDelegate();
- }
- else
- {
- JBossSession sess = (JBossSession)sourceConnection.createXASession();
-
- sourceSession = (SessionDelegate)sess.getDelegate();
-
- sess = (JBossSession)localConnection.createXASession();
-
- localSession = (SessionDelegate)sess.getDelegate();
- }
-
- JBossDestination dest = new JBossQueue(localQueue.getName(), true);
-
- producer = localSession.createProducerDelegate(dest);
-
- //We create the consumer with autoFlowControl = false
- //In this mode, the consumer does not handle it's own flow control, but it must be handled
- //manually using changeRate() methods
- //The local queue itself will manually send these messages depending on its state -
- //So effectively the message buffering is handled by the local queue, not the ClientConsumer
- consumer = sourceSession.createConsumerDelegate(dest, null, false, null, false, false);
-
- consumer.setMessageListener(this);
-
- //Register ourselves with the local queue - this queue will handle flow control for us
-
- if (trace) { log.trace(this + " Registering sucker"); }
-
- localQueue.registerSucker(this);
-
- started = true;
-
- if (trace) { log.trace(this + " Registered sucker"); }
- }
-
- synchronized void stop()
- {
- if (!started)
- {
- return;
- }
-
- setConsuming(false);
-
- localQueue.unregisterSucker(this);
-
- try
- {
- sourceSession.close();
- }
- catch (Throwable t)
- {
- //Ignore
- }
-
- try
- {
- localSession.close();
- }
- catch (Throwable t)
- {
- //Ignore
- }
-
- started = false;
- }
-
- public String getQueueName()
- {
- return this.localQueue.getName();
- }
-
- public synchronized void setConsuming(boolean consume)
- {
- if (trace) { log.trace(this + " setConsuming " + consume); }
-
- try
- {
- if (consume && !consuming)
- {
- //Send a changeRate(1) message - to start consumption
-
- consumer.changeRate(1f);
-
- if (trace) { log.trace(this + " sent changeRate(1) message"); }
-
- consuming = true;
- }
- else if (!consume && consuming)
- {
- //Send a changeRate(0) message to stop consumption
-
- consumer.changeRate(0f);
-
- if (trace) { log.trace(this + " sent changeRate(0) message"); }
-
- consuming = false;
- }
- }
- catch (Exception e)
- {
- //We ignore the exception - we might fail to change rate when stoping a sucker for a dead server
- }
- }
-
- public void onMessage(Message msg)
- {
- Transaction tx = null;
-
- if (trace) { log.trace(this + " sucked message " + msg); }
-
- try
- {
- /*
- Commented out until JBM 2.0
-
- boolean startTx = xa && msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT;
-
- if (startTx)
- {
- //Start a JTA transaction
-
- if (trace) { log.trace("Starting JTA transactions"); }
-
- tm.begin();
-
- tx = tm.getTransaction();
-
- tx.enlistResource(sourceSession.getXAResource());
-
- tx.enlistResource(localSession.getXAResource());
-
- if (trace) { log.trace("Started JTA transaction"); }
- }
-
- org.jboss.messaging.core.contract.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");
- }
-
- //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);
-
- long timeToLive = msg.getJMSExpiration();
- if (timeToLive != 0)
- {
- timeToLive -= System.currentTimeMillis();
- if (timeToLive <= 0)
- {
- timeToLive = 1; //Should have already expired - set to 1 so it expires when it is consumed or delivered
- }
- }
-
- producer.send(null, msg, msg.getJMSDeliveryMode(), msg.getJMSPriority(), timeToLive, true);
-
- if (trace) { log.trace(this + " forwarded message to queue"); }
-
- if (startTx)
- {
- if (trace) { log.trace("Committing JTA transaction"); }
-
- tx.delistResource(sourceSession.getXAResource(), XAResource.TMSUCCESS);
-
- tx.delistResource(localSession.getXAResource(), XAResource.TMSUCCESS);
-
- tm.commit();
-
- if (trace) { log.trace("Committed JTA transaction"); }
- }
- else
- {
- msg.acknowledge();
-
- if (trace) { log.trace("Acknowledged message"); }
- }
- */
-
- 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.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.newcore.intf.Message.SOURCE_CHANNEL_ID, sourceChannelID);
-
- long timeToLive = msg.getJMSExpiration();
- if (timeToLive != 0)
- {
- timeToLive -= System.currentTimeMillis();
- if (timeToLive <= 0)
- {
- timeToLive = 1; //Should have already expired - set to 1 so it expires when it is consumed or delivered
- }
- }
-
- //First we ack it - this ack only occurs in memory even if it is a persistent message
- msg.acknowledge();
-
- if (trace) { log.trace("Acknowledged message"); }
-
- //Then we send - this causes the ref to be moved (SQL UPDATE) in the database
- producer.send(null, msg, msg.getJMSDeliveryMode(), msg.getJMSPriority(), timeToLive, true);
-
- if (trace) { log.trace(this + " forwarded message to queue"); }
- }
- catch (Exception e)
- {
- log.error("Failed to forward message", e);
-
- try
- {
- if (tx != null) tm.rollback();
- }
- catch (Throwable t)
- {
- if (trace) { log.trace("Failed to rollback tx", t); }
- }
- }
- }
+// private static final Logger log = Logger.getLogger(MessageSucker.class);
+//
+// private boolean trace = log.isTraceEnabled();
+//
+// private JBossConnection sourceConnection;
+//
+// private JBossConnection localConnection;
+//
+// private Queue localQueue;
+//
+// private SessionDelegate sourceSession;
+//
+// private SessionDelegate localSession;
+//
+// private ProducerDelegate producer;
+//
+// private volatile boolean started;
+//
+// private boolean xa;
+//
+// private TransactionManager tm;
+//
+// private boolean consuming;
+//
+// private ConsumerDelegate consumer;
+//
+// private boolean preserveOrdering;
+//
+// private long sourceChannelID;
+//
+// public String toString()
+// {
+// return "MessageSucker:" + System.identityHashCode(this) + " queue:" + localQueue.getName();
+// }
+//
+// MessageSucker(Queue localQueue, JBossConnection sourceConnection, JBossConnection localConnection,
+// boolean xa, boolean preserveOrdering, long sourceChannelID)
+// {
+// if (trace) { log.trace("Creating message sucker, localQueue:" + localQueue + " xa:" + xa + " preserveOrdering:" + preserveOrdering); }
+//
+// this.localQueue = localQueue;
+//
+// this.sourceConnection = sourceConnection;
+//
+// this.localConnection = localConnection;
+//
+// //this.xa = xa;
+//
+// //XA is currently disabled for message sucking - this is because JBM 1.4.0 uses shared database so XA is
+// //unnecesary - we can move the ref from one channel to another with a database update
+// this.xa = false;
+//
+// this.preserveOrdering = preserveOrdering;
+//
+// this.sourceChannelID = sourceChannelID;
+//
+// if (xa)
+// {
+// tm = TransactionManagerLocator.getInstance().locate();
+// }
+// }
+//
+// synchronized void start() throws Exception
+// {
+// if (started)
+// {
+// return;
+// }
+//
+// if (trace) { log.trace(this + " starting"); }
+//
+// if (!xa)
+// {
+// //If not XA then we use a client ack session for consuming - this allows us to get the message, send it to the destination
+// //then ack the message.
+// //This means that if a failure occurs between sending and acking the message won't be lost but may get delivered
+// //twice - i.e we have dups_ok behaviour
+//
+// JBossSession sess = (JBossSession)sourceConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+//
+// sourceSession = (SessionDelegate)sess.getDelegate();
+//
+// sess = (JBossSession)localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+// localSession = (SessionDelegate)sess.getDelegate();
+// }
+// else
+// {
+// JBossSession sess = (JBossSession)sourceConnection.createXASession();
+//
+// sourceSession = (SessionDelegate)sess.getDelegate();
+//
+// sess = (JBossSession)localConnection.createXASession();
+//
+// localSession = (SessionDelegate)sess.getDelegate();
+// }
+//
+// JBossDestination dest = new JBossQueue(localQueue.getName(), true);
+//
+// producer = localSession.createProducerDelegate(dest);
+//
+// //We create the consumer with autoFlowControl = false
+// //In this mode, the consumer does not handle it's own flow control, but it must be handled
+// //manually using changeRate() methods
+// //The local queue itself will manually send these messages depending on its state -
+// //So effectively the message buffering is handled by the local queue, not the ClientConsumer
+// consumer = sourceSession.createConsumerDelegate(dest, null, false, null, false, false);
+//
+// consumer.setMessageListener(this);
+//
+// //Register ourselves with the local queue - this queue will handle flow control for us
+//
+// if (trace) { log.trace(this + " Registering sucker"); }
+//
+// localQueue.registerSucker(this);
+//
+// started = true;
+//
+// if (trace) { log.trace(this + " Registered sucker"); }
+// }
+//
+// synchronized void stop()
+// {
+// if (!started)
+// {
+// return;
+// }
+//
+// setConsuming(false);
+//
+// localQueue.unregisterSucker(this);
+//
+// try
+// {
+// sourceSession.close();
+// }
+// catch (Throwable t)
+// {
+// //Ignore
+// }
+//
+// try
+// {
+// localSession.close();
+// }
+// catch (Throwable t)
+// {
+// //Ignore
+// }
+//
+// started = false;
+// }
+//
+// public String getQueueName()
+// {
+// return this.localQueue.getName();
+// }
+//
+// public synchronized void setConsuming(boolean consume)
+// {
+// if (trace) { log.trace(this + " setConsuming " + consume); }
+//
+// try
+// {
+// if (consume && !consuming)
+// {
+// //Send a changeRate(1) message - to start consumption
+//
+// consumer.changeRate(1f);
+//
+// if (trace) { log.trace(this + " sent changeRate(1) message"); }
+//
+// consuming = true;
+// }
+// else if (!consume && consuming)
+// {
+// //Send a changeRate(0) message to stop consumption
+//
+// consumer.changeRate(0f);
+//
+// if (trace) { log.trace(this + " sent changeRate(0) message"); }
+//
+// consuming = false;
+// }
+// }
+// catch (Exception e)
+// {
+// //We ignore the exception - we might fail to change rate when stoping a sucker for a dead server
+// }
+// }
+//
+// public void onMessage(Message msg)
+// {
+// Transaction tx = null;
+//
+// if (trace) { log.trace(this + " sucked message " + msg); }
+//
+// try
+// {
+// /*
+// Commented out until JBM 2.0
+//
+// boolean startTx = xa && msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT;
+//
+// if (startTx)
+// {
+// //Start a JTA transaction
+//
+// if (trace) { log.trace("Starting JTA transactions"); }
+//
+// tm.begin();
+//
+// tx = tm.getTransaction();
+//
+// tx.enlistResource(sourceSession.getXAResource());
+//
+// tx.enlistResource(localSession.getXAResource());
+//
+// if (trace) { log.trace("Started JTA transaction"); }
+// }
+//
+// org.jboss.messaging.core.contract.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");
+// }
+//
+// //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);
+//
+// long timeToLive = msg.getJMSExpiration();
+// if (timeToLive != 0)
+// {
+// timeToLive -= System.currentTimeMillis();
+// if (timeToLive <= 0)
+// {
+// timeToLive = 1; //Should have already expired - set to 1 so it expires when it is consumed or delivered
+// }
+// }
+//
+// producer.send(null, msg, msg.getJMSDeliveryMode(), msg.getJMSPriority(), timeToLive, true);
+//
+// if (trace) { log.trace(this + " forwarded message to queue"); }
+//
+// if (startTx)
+// {
+// if (trace) { log.trace("Committing JTA transaction"); }
+//
+// tx.delistResource(sourceSession.getXAResource(), XAResource.TMSUCCESS);
+//
+// tx.delistResource(localSession.getXAResource(), XAResource.TMSUCCESS);
+//
+// tm.commit();
+//
+// if (trace) { log.trace("Committed JTA transaction"); }
+// }
+// else
+// {
+// msg.acknowledge();
+//
+// if (trace) { log.trace("Acknowledged message"); }
+// }
+// */
+//
+// 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.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.newcore.intf.Message.SOURCE_CHANNEL_ID, sourceChannelID);
+//
+// long timeToLive = msg.getJMSExpiration();
+// if (timeToLive != 0)
+// {
+// timeToLive -= System.currentTimeMillis();
+// if (timeToLive <= 0)
+// {
+// timeToLive = 1; //Should have already expired - set to 1 so it expires when it is consumed or delivered
+// }
+// }
+//
+// //First we ack it - this ack only occurs in memory even if it is a persistent message
+// msg.acknowledge();
+//
+// if (trace) { log.trace("Acknowledged message"); }
+//
+// //Then we send - this causes the ref to be moved (SQL UPDATE) in the database
+// producer.send(null, msg, msg.getJMSDeliveryMode(), msg.getJMSPriority(), timeToLive, true);
+//
+// if (trace) { log.trace(this + " forwarded message to queue"); }
+// }
+// catch (Exception e)
+// {
+// log.error("Failed to forward message", e);
+//
+// try
+// {
+// if (tx != null) tm.rollback();
+// }
+// catch (Throwable t)
+// {
+// if (trace) { log.trace("Failed to rollback tx", t); }
+// }
+// }
+// }
}
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/message/SimpleMessageStore.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -21,14 +21,7 @@
*/
package org.jboss.messaging.core.impl.message;
-import java.util.Map;
-import java.util.WeakHashMap;
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.contract.MessageStore;
-import org.jboss.messaging.newcore.intf.Message;
-import org.jboss.messaging.newcore.intf.MessageReference;
-
/**
* A MessageStore implementation.
*
@@ -38,89 +31,89 @@
*
* $Id: SimpleMessageStore.java 2202 2007-02-08 10:50:26Z timfox $
*/
-public class SimpleMessageStore implements MessageStore
+public class SimpleMessageStore //implements MessageStore
{
// Constants -----------------------------------------------------
- private static final Logger log = Logger.getLogger(SimpleMessageStore.class);
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private Map<Long, Message> messages;
-
- // Constructors --------------------------------------------------
-
- public SimpleMessageStore()
- {
- messages = new WeakHashMap<Long, Message>();
-
- log.debug(this + " initialized");
- }
-
- // MessageStore implementation ---------------------------
+// private static final Logger log = Logger.getLogger(SimpleMessageStore.class);
+//
+// // Static --------------------------------------------------------
+//
+// // Attributes ----------------------------------------------------
+//
+// private Map<Long, Message> messages;
+//
+// // Constructors --------------------------------------------------
+//
+// public SimpleMessageStore()
+// {
+// messages = new WeakHashMap<Long, Message>();
+//
+// log.debug(this + " initialized");
+// }
+//
+// // MessageStore implementation ---------------------------
+//
+// public synchronized MessageReference reference(Message m)
+// {
+// //If already exists, return reference to existing message
+//
+// Message message = (Message)messages.get(m.getMessageID());
+//
+// if (message == null)
+// {
+// messages.put(m.getMessageID(), m);
+//
+// message = m;
+// }
+//
+// return message.createReference();
+// }
+//
+// public synchronized MessageReference reference(long messageID)
+// {
+// Message message = (Message)messages.get(messageID);
+//
+// if (message == null)
+// {
+// return null;
+// }
+// else
+// {
+// return message.createReference();
+// }
+// }
+//
+// public synchronized void clear()
+// {
+// messages.clear();
+// }
+//
+// // MessagingComponent implementation --------------------------------
+//
+// public void start() throws Exception
+// {
+// //NOOP
+// }
+//
+// public void stop() throws Exception
+// {
+// //NOOP
+// }
+//
+// // Public --------------------------------------------------------
+//
+// public String toString()
+// {
+// return "MemoryStore[" + System.identityHashCode(this) + "]";
+// }
+//
+// // Package protected ---------------------------------------------
+//
+// // Protected -----------------------------------------------------
+//
+// // Private -------------------------------------------------------
+//
+// // Inner classes -------------------------------------------------
- public synchronized MessageReference reference(Message m)
- {
- //If already exists, return reference to existing message
-
- Message message = (Message)messages.get(m.getMessageID());
-
- if (message == null)
- {
- messages.put(m.getMessageID(), m);
-
- message = m;
- }
-
- return message.createReference();
- }
-
- public synchronized MessageReference reference(long messageID)
- {
- Message message = (Message)messages.get(messageID);
-
- if (message == null)
- {
- return null;
- }
- else
- {
- return message.createReference();
- }
- }
-
- public synchronized void clear()
- {
- messages.clear();
- }
-
- // MessagingComponent implementation --------------------------------
-
- public void start() throws Exception
- {
- //NOOP
- }
-
- public void stop() throws Exception
- {
- //NOOP
- }
-
- // Public --------------------------------------------------------
-
- public String toString()
- {
- return "MemoryStore[" + System.identityHashCode(this) + "]";
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
}
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageHolder.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -25,12 +25,11 @@
import java.io.DataOutputStream;
import java.util.Map;
+import org.jboss.messaging.newcore.impl.MessageImpl;
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
*
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessageRequest.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -27,7 +27,7 @@
import java.util.Iterator;
import java.util.Set;
-import org.jboss.messaging.core.impl.message.CoreMessage;
+import org.jboss.messaging.newcore.impl.MessageImpl;
import org.jboss.messaging.newcore.intf.Message;
/**
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -58,7 +58,6 @@
import org.jboss.messaging.core.contract.Condition;
import org.jboss.messaging.core.contract.ConditionFactory;
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.MessageStore;
import org.jboss.messaging.core.contract.PersistenceManager;
@@ -71,6 +70,7 @@
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.Filter;
import org.jboss.messaging.newcore.intf.Message;
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/impl/tx/Transaction.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/tx/Transaction.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/tx/Transaction.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -44,365 +44,365 @@
*/
public class Transaction
{
- // Constants -----------------------------------------------------
-
- private static final Logger log = Logger.getLogger(Transaction.class);
-
- // Attributes ----------------------------------------------------
-
- private boolean trace = log.isTraceEnabled();
-
- private long id;
-
- private int state;
-
- private Xid xid;
-
- private List callbacks;
-
- private Map callbackMap;
-
- private boolean recoveredFromStorage;
-
- /**
- * If this is a XA transaction, when a commit is executed the transaction has to be removed from the transaction repository.
- * This reference will guarantee the reference back to the repository where the transaction was created
- *
- */
- protected TransactionRepository repository;
-
- //A special first callback that is ensured to be executed first
- protected TxCallback firstCallback;
-
- // Static --------------------------------------------------------
-
- public static final int STATE_ACTIVE = 0;
-
- public static final int STATE_PREPARED = 1;
-
- public static final int STATE_COMMITTED = 2;
-
- public static final int STATE_ROLLEDBACK = 3;
-
- public static final int STATE_ROLLBACK_ONLY = 4;
-
- public static String stateToString(int state)
- {
- if (state == STATE_ACTIVE)
- {
- return "ACTIVE";
- }
- else if (state == STATE_PREPARED)
- {
- return "PREPARED";
- }
- else if (state == STATE_COMMITTED)
- {
- return "COMMITTED";
- }
- else if (state == STATE_ROLLEDBACK)
- {
- return "ROLLEDBACK";
- }
- else if (state == STATE_ROLLBACK_ONLY)
- {
- return "ROLLBACK_ONLY";
- }
- else
- {
- return "UNKNOWN";
- }
- }
-
- // Constructors --------------------------------------------------
-
- Transaction(long id)
- {
- this.id = id;
- state = STATE_ACTIVE;
- callbacks = new ArrayList();
- callbackMap = new HashMap();
- }
-
- Transaction(long id, Xid xid, TransactionRepository tr)
- {
- this(id);
- this.xid = xid;
- this.repository = tr;
- }
-
- // Public --------------------------------------------------------
-
- public int getState()
- {
- return state;
- }
-
- public Xid getXid()
- {
- return xid;
- }
-
- public void addCallback(TxCallback callback, Object key)
- {
- callbacks.add(callback);
-
- callbackMap.put(key, callback);
- }
-
- public void addFirstCallback(TxCallback callback, Object key)
- {
- if (firstCallback != null)
- {
- throw new IllegalStateException("There is already a first callback");
- }
-
- this.firstCallback = callback;
-
- callbackMap.put(key, callback);
- }
-
- public TxCallback getCallback(Object key)
- {
- return (TxCallback)callbackMap.get(key);
- }
-
- public synchronized void commit() throws Exception
- {
- if (state == STATE_ROLLBACK_ONLY)
- {
- throw new TransactionException("Transaction marked rollback only, cannot commit");
- }
- if (state == STATE_COMMITTED)
- {
- throw new TransactionException("Transaction already committed, cannot commit");
- }
- if (state == STATE_ROLLEDBACK)
- {
- throw new TransactionException("Transaction already rolled back, cannot commit");
- }
-
- if (recoveredFromStorage)
- {
- //Commit can come in for an in doubt tx that has been recovered from storage
- //but for which recover() has not yet been called
- //therefore we might need to load it's state
- loadState();
- }
-
- if (trace) { log.trace(this + " executing before commit hooks"); }
-
- boolean onePhase = state != STATE_PREPARED;
-
- if (firstCallback != null)
- {
- firstCallback.beforeCommit(onePhase);
- }
-
- Iterator iter = callbacks.iterator();
-
- while (iter.hasNext())
- {
- TxCallback callback = (TxCallback)iter.next();
-
- callback.beforeCommit(onePhase);
- }
-
- state = STATE_COMMITTED;
-
- if (trace) { log.trace(this + " committed"); }
-
- iter = callbacks.iterator();
-
- if (trace) { log.trace(this + " executing after commit hooks"); }
-
- if (firstCallback != null)
- {
- firstCallback.afterCommit(onePhase);
- }
-
- while (iter.hasNext())
- {
- TxCallback callback = (TxCallback)iter.next();
-
- callback.afterCommit(onePhase);
- }
-
- callbacks = null;
-
- callbackMap = null;
-
- firstCallback = null;
-
- if (repository != null)
- {
- repository.deleteTransaction(this);
- }
-
- if (trace) { log.trace(this + " commit process complete"); }
- }
-
- public synchronized void prepare() throws Exception
- {
- if (state != STATE_ACTIVE)
- {
- throw new TransactionException("Transaction not active, cannot prepare");
- }
-
- if (trace) { log.trace(this + " executing before prepare hooks"); }
-
- if (firstCallback != null)
- {
- firstCallback.beforePrepare();
- }
-
- Iterator iter = callbacks.iterator();
-
- while (iter.hasNext())
- {
- TxCallback callback = (TxCallback)iter.next();
-
- callback.beforePrepare();
- }
-
- state = STATE_PREPARED;
-
- if (trace) { log.trace(this + " prepared"); }
-
- if (firstCallback != null)
- {
- firstCallback.afterPrepare();
- }
-
- iter = callbacks.iterator();
-
- if (trace) { log.trace(this + " executing after prepare hooks"); }
-
- while (iter.hasNext())
- {
- TxCallback callback = (TxCallback)iter.next();
-
- callback.afterPrepare();
- }
-
- if (trace) { log.trace(this + " prepare process complete"); }
- }
-
- public synchronized void rollback() throws Exception
- {
- if (state == STATE_COMMITTED)
- {
- throw new TransactionException("Transaction already committed, cannot rollback");
- }
- if (state == STATE_ROLLEDBACK)
- {
- throw new TransactionException("Transaction already rolled back, cannot rollback");
- }
-
- if (recoveredFromStorage)
- {
- //Commit can come in for an in doubt tx that has been recovered from storage
- //but for which recover() has not yet been called
- //therefore we might need to load it's state
- loadState();
- }
-
- if (trace) { log.trace(this + " executing before rollback hooks"); }
-
- boolean onePhase = state != STATE_PREPARED;
-
- if (firstCallback != null)
- {
- firstCallback.beforeRollback(onePhase);
- }
-
- for(Iterator i = callbacks.iterator(); i.hasNext(); )
- {
- TxCallback callback = (TxCallback)i.next();
- callback.beforeRollback(onePhase);
- }
-
- state = STATE_ROLLEDBACK;
-
- if (trace) { log.trace(this + " rolled back"); }
-
- if (trace) { log.trace(this + " executing after rollback hooks"); }
-
- if (firstCallback != null)
- {
- firstCallback.afterRollback(onePhase);
- }
-
- for(Iterator i = callbacks.iterator(); i.hasNext();)
- {
- TxCallback callback = (TxCallback)i.next();
- callback.afterRollback(onePhase);
- }
-
- callbacks = null;
- callbackMap = null;
-
- if (repository != null)
- {
- repository.deleteTransaction(this);
- }
-
- if (trace) { log.trace(this + " rollback process complete"); }
- }
-
- public void loadState() throws Exception
- {
- repository.handleReferences(this);
-
- repository.handleAcks(this);
-
- recoveredFromStorage = false;
- }
-
- public synchronized void setRollbackOnly() throws Exception
- {
- if (trace) { log.trace("setting ROLLBACK_ONLY on " + this); }
-
- state = STATE_ROLLBACK_ONLY;
- }
-
- public long getId()
- {
- return id;
- }
-
- public boolean isRecoveredFromStorage()
- {
- return this.recoveredFromStorage;
- }
-
- public void setRecoveredFromStorage(boolean recoveredFromStorage)
- {
- this.recoveredFromStorage = recoveredFromStorage;
- }
-
- public void setState(int state)
- {
- this.state = state;
- }
-
- public String toString()
- {
- StringBuffer sb = new StringBuffer("TX(");
- sb.append(id);
- sb.append("):");
- sb.append(stateToString(state));
- return sb.toString();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
+// // Constants -----------------------------------------------------
+//
+// private static final Logger log = Logger.getLogger(Transaction.class);
+//
+// // Attributes ----------------------------------------------------
+//
+// private boolean trace = log.isTraceEnabled();
+//
+// private long id;
+//
+// private int state;
+//
+// private Xid xid;
+//
+// private List callbacks;
+//
+// private Map callbackMap;
+//
+// private boolean recoveredFromStorage;
+//
+// /**
+// * If this is a XA transaction, when a commit is executed the transaction has to be removed from the transaction repository.
+// * This reference will guarantee the reference back to the repository where the transaction was created
+// *
+// */
+// protected TransactionRepository repository;
+//
+// //A special first callback that is ensured to be executed first
+// protected TxCallback firstCallback;
+//
+// // Static --------------------------------------------------------
+//
+// public static final int STATE_ACTIVE = 0;
+//
+// public static final int STATE_PREPARED = 1;
+//
+// public static final int STATE_COMMITTED = 2;
+//
+// public static final int STATE_ROLLEDBACK = 3;
+//
+// public static final int STATE_ROLLBACK_ONLY = 4;
+//
+// public static String stateToString(int state)
+// {
+// if (state == STATE_ACTIVE)
+// {
+// return "ACTIVE";
+// }
+// else if (state == STATE_PREPARED)
+// {
+// return "PREPARED";
+// }
+// else if (state == STATE_COMMITTED)
+// {
+// return "COMMITTED";
+// }
+// else if (state == STATE_ROLLEDBACK)
+// {
+// return "ROLLEDBACK";
+// }
+// else if (state == STATE_ROLLBACK_ONLY)
+// {
+// return "ROLLBACK_ONLY";
+// }
+// else
+// {
+// return "UNKNOWN";
+// }
+// }
+//
+// // Constructors --------------------------------------------------
+//
+// Transaction(long id)
+// {
+// this.id = id;
+// state = STATE_ACTIVE;
+// callbacks = new ArrayList();
+// callbackMap = new HashMap();
+// }
+//
+// Transaction(long id, Xid xid, TransactionRepository tr)
+// {
+// this(id);
+// this.xid = xid;
+// this.repository = tr;
+// }
+//
+// // Public --------------------------------------------------------
+//
+// public int getState()
+// {
+// return state;
+// }
+//
+// public Xid getXid()
+// {
+// return xid;
+// }
+//
+// public void addCallback(TxCallback callback, Object key)
+// {
+// callbacks.add(callback);
+//
+// callbackMap.put(key, callback);
+// }
+//
+// public void addFirstCallback(TxCallback callback, Object key)
+// {
+// if (firstCallback != null)
+// {
+// throw new IllegalStateException("There is already a first callback");
+// }
+//
+// this.firstCallback = callback;
+//
+// callbackMap.put(key, callback);
+// }
+//
+// public TxCallback getCallback(Object key)
+// {
+// return (TxCallback)callbackMap.get(key);
+// }
+//
+// public synchronized void commit() throws Exception
+// {
+// if (state == STATE_ROLLBACK_ONLY)
+// {
+// throw new TransactionException("Transaction marked rollback only, cannot commit");
+// }
+// if (state == STATE_COMMITTED)
+// {
+// throw new TransactionException("Transaction already committed, cannot commit");
+// }
+// if (state == STATE_ROLLEDBACK)
+// {
+// throw new TransactionException("Transaction already rolled back, cannot commit");
+// }
+//
+// if (recoveredFromStorage)
+// {
+// //Commit can come in for an in doubt tx that has been recovered from storage
+// //but for which recover() has not yet been called
+// //therefore we might need to load it's state
+// loadState();
+// }
+//
+// if (trace) { log.trace(this + " executing before commit hooks"); }
+//
+// boolean onePhase = state != STATE_PREPARED;
+//
+// if (firstCallback != null)
+// {
+// firstCallback.beforeCommit(onePhase);
+// }
+//
+// Iterator iter = callbacks.iterator();
+//
+// while (iter.hasNext())
+// {
+// TxCallback callback = (TxCallback)iter.next();
+//
+// callback.beforeCommit(onePhase);
+// }
+//
+// state = STATE_COMMITTED;
+//
+// if (trace) { log.trace(this + " committed"); }
+//
+// iter = callbacks.iterator();
+//
+// if (trace) { log.trace(this + " executing after commit hooks"); }
+//
+// if (firstCallback != null)
+// {
+// firstCallback.afterCommit(onePhase);
+// }
+//
+// while (iter.hasNext())
+// {
+// TxCallback callback = (TxCallback)iter.next();
+//
+// callback.afterCommit(onePhase);
+// }
+//
+// callbacks = null;
+//
+// callbackMap = null;
+//
+// firstCallback = null;
+//
+// if (repository != null)
+// {
+// repository.deleteTransaction(this);
+// }
+//
+// if (trace) { log.trace(this + " commit process complete"); }
+// }
+//
+// public synchronized void prepare() throws Exception
+// {
+// if (state != STATE_ACTIVE)
+// {
+// throw new TransactionException("Transaction not active, cannot prepare");
+// }
+//
+// if (trace) { log.trace(this + " executing before prepare hooks"); }
+//
+// if (firstCallback != null)
+// {
+// firstCallback.beforePrepare();
+// }
+//
+// Iterator iter = callbacks.iterator();
+//
+// while (iter.hasNext())
+// {
+// TxCallback callback = (TxCallback)iter.next();
+//
+// callback.beforePrepare();
+// }
+//
+// state = STATE_PREPARED;
+//
+// if (trace) { log.trace(this + " prepared"); }
+//
+// if (firstCallback != null)
+// {
+// firstCallback.afterPrepare();
+// }
+//
+// iter = callbacks.iterator();
+//
+// if (trace) { log.trace(this + " executing after prepare hooks"); }
+//
+// while (iter.hasNext())
+// {
+// TxCallback callback = (TxCallback)iter.next();
+//
+// callback.afterPrepare();
+// }
+//
+// if (trace) { log.trace(this + " prepare process complete"); }
+// }
+//
+// public synchronized void rollback() throws Exception
+// {
+// if (state == STATE_COMMITTED)
+// {
+// throw new TransactionException("Transaction already committed, cannot rollback");
+// }
+// if (state == STATE_ROLLEDBACK)
+// {
+// throw new TransactionException("Transaction already rolled back, cannot rollback");
+// }
+//
+// if (recoveredFromStorage)
+// {
+// //Commit can come in for an in doubt tx that has been recovered from storage
+// //but for which recover() has not yet been called
+// //therefore we might need to load it's state
+// loadState();
+// }
+//
+// if (trace) { log.trace(this + " executing before rollback hooks"); }
+//
+// boolean onePhase = state != STATE_PREPARED;
+//
+// if (firstCallback != null)
+// {
+// firstCallback.beforeRollback(onePhase);
+// }
+//
+// for(Iterator i = callbacks.iterator(); i.hasNext(); )
+// {
+// TxCallback callback = (TxCallback)i.next();
+// callback.beforeRollback(onePhase);
+// }
+//
+// state = STATE_ROLLEDBACK;
+//
+// if (trace) { log.trace(this + " rolled back"); }
+//
+// if (trace) { log.trace(this + " executing after rollback hooks"); }
+//
+// if (firstCallback != null)
+// {
+// firstCallback.afterRollback(onePhase);
+// }
+//
+// for(Iterator i = callbacks.iterator(); i.hasNext();)
+// {
+// TxCallback callback = (TxCallback)i.next();
+// callback.afterRollback(onePhase);
+// }
+//
+// callbacks = null;
+// callbackMap = null;
+//
+// if (repository != null)
+// {
+// repository.deleteTransaction(this);
+// }
+//
+// if (trace) { log.trace(this + " rollback process complete"); }
+// }
+//
+// public void loadState() throws Exception
+// {
+// repository.handleReferences(this);
+//
+// repository.handleAcks(this);
+//
+// recoveredFromStorage = false;
+// }
+//
+// public synchronized void setRollbackOnly() throws Exception
+// {
+// if (trace) { log.trace("setting ROLLBACK_ONLY on " + this); }
+//
+// state = STATE_ROLLBACK_ONLY;
+// }
+//
+// public long getId()
+// {
+// return id;
+// }
+//
+// public boolean isRecoveredFromStorage()
+// {
+// return this.recoveredFromStorage;
+// }
+//
+// public void setRecoveredFromStorage(boolean recoveredFromStorage)
+// {
+// this.recoveredFromStorage = recoveredFromStorage;
+// }
+//
+// public void setState(int state)
+// {
+// this.state = state;
+// }
+//
+// public String toString()
+// {
+// StringBuffer sb = new StringBuffer("TX(");
+// sb.append(id);
+// sb.append("):");
+// sb.append(stateToString(state));
+// return sb.toString();
+// }
+//
+// // Package protected ---------------------------------------------
+//
+// // Protected -----------------------------------------------------
+//
+// // Private -------------------------------------------------------
+//
+// // Inner classes -------------------------------------------------
+//
}
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-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/core/impl/tx/TransactionRepository.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -21,28 +21,7 @@
*/
package org.jboss.messaging.core.impl.tx;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import javax.transaction.xa.Xid;
-
-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.MessageStore;
-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;
-
/**
* This class maintains JMS Server local transactions.
*
@@ -54,460 +33,460 @@
*
* $Id$
*/
-public class TransactionRepository implements MessagingComponent
+public class TransactionRepository //implements MessagingComponent
{
- // Constants -----------------------------------------------------
-
- private static final Logger log = Logger.getLogger(TransactionRepository.class);
-
- // Attributes ----------------------------------------------------
+// // Constants -----------------------------------------------------
+//
+// private static final Logger log = Logger.getLogger(TransactionRepository.class);
+//
+// // Attributes ----------------------------------------------------
+//
+// private boolean trace = log.isTraceEnabled();
+//
+// private Map map;
+//
+// private PersistenceManager persistenceManager;
+//
+// protected MessageStore messageStore;
+//
+// private IDManager idManager;
+//
+// private PostOffice postOffice;
+//
+// // Static --------------------------------------------------------
+//
+// // Constructors --------------------------------------------------
+//
+// public TransactionRepository(PersistenceManager persistenceManager, MessageStore store, IDManager idManager)
+// {
+// this.persistenceManager = persistenceManager;
+//
+// this.messageStore = store;
+//
+// this.idManager = idManager;
+//
+// map = new ConcurrentHashMap();
+// }
+//
+// // Injection ----------------------------------------
+//
+// //Unfortunately we have to do this for now, since PostOffice is not started until after this is constructed
+// //We will sort out dependencies properly when we go to the micro container
+// public void injectPostOffice(PostOffice po)
+// {
+// postOffice = po;
+// }
+//
+//
+// // MessagingComponent implementation --------------------------------
+//
+// public void start() throws Exception
+// {
+// //NOOP
+// }
+//
+// // Public --------------------------------------------------------
+//
+// public void stop() throws Exception
+// {
+// //NOOP
+// }
+//
+// // Public --------------------------------------------------------
+//
+// /**
+// * Attempts to recover existing prepared transactions by redelivering unhandled messages and acknowledgements
+// * on the appropriate channels.
+// *
+// * @return List of Xid instances
+// */
+// public synchronized List recoverPreparedTransactions()
+// {
+// if (trace) { log.trace(this + " recoverPreparedTransactions()"); }
+//
+// ArrayList prepared = new ArrayList();
+//
+// Iterator iter = map.values().iterator();
+//
+// while (iter.hasNext())
+// {
+// Transaction tx = (Transaction) iter.next();
+//
+// if (tx.getXid() != null && tx.getState() == Transaction.STATE_PREPARED)
+// {
+// try
+// {
+// if (trace) log.trace("Loading and handling refs and acks to the Tx "+tx);
+//
+// //The transaction might have been created, prepared, without the server crashing
+// //in which case the tx will already have the references and acks in them
+// //in this case we DO NOT want to replay them again, since they will end up in the transaction state
+// //twice
+// //In other words we only want to replay acks and sends if this tx was recovered from the db
+// if (tx.isRecoveredFromStorage())
+// {
+// tx.loadState();
+// }
+// }
+// catch (Exception e)
+// {
+// log.warn("Failed to replay transaction (XID: " + tx.getXid() + ", LocalID: " + tx.getId() + ") during recovery.", e);
+// }
+//
+// prepared.add(tx.getXid());
+// }
+// }
+//
+// if (trace) { log.trace("Returning " + prepared.size() + " transactions"); }
+//
+// return prepared;
+// }
+//
+// /*
+// * Load any prepared transactions into the repository so they can be
+// * recovered
+// */
+// public void loadPreparedTransactions() throws Exception
+// {
+// if (trace) log.trace("load prepared transactions...");
+//
+// List prepared = null;
+//
+// prepared = persistenceManager.retrievePreparedTransactions();
+//
+// if (trace) log.trace ("found " + prepared.size() + " transactions in prepared state");
+//
+// if (prepared != null)
+// {
+// Iterator iter = prepared.iterator();
+//
+// while (iter.hasNext())
+// {
+// PreparedTxInfo txInfo = (PreparedTxInfo) iter.next();
+//
+// //This method may be called more than once - e.g. when failover occurs so we don't want to add the
+// //prepared tx if it is already in memory
+//
+// if (!map.containsKey(txInfo.getXid()))
+// {
+// Transaction tx = createTransaction(txInfo);
+//
+// tx.setState(Transaction.STATE_PREPARED);
+//
+// tx.setRecoveredFromStorage(true);
+//
+// if (trace) log.trace("reinstating TX(XID: " + txInfo.getXid() + ", LocalId " + txInfo.getTxId() +")");
+//
+// }
+// else
+// {
+// if (trace) log.trace("Not adding to map since it's already in map");
+// }
+// }
+// }
+// }
+//
+// public List getPreparedTransactions()
+// {
+// return new ArrayList(map.keySet());
+// }
+//
+// public Transaction getPreparedTx(Xid xid) throws Exception
+// {
+// Transaction tx = (Transaction)map.get(xid);
+//
+// if (tx == null)
+// {
+// throw new TransactionException("Cannot find entry for xid:" + xid);
+// }
+// if (tx.getState() != Transaction.STATE_PREPARED)
+// {
+// throw new TransactionException("Transaction with xid " + xid + " is not in prepared state");
+// }
+// return tx;
+// }
+//
+// public void deleteTransaction(Transaction transaction) throws Exception
+// {
+// final Xid id = transaction.getXid();
+// final int state = transaction.getState();
+//
+// if (id == null)
+// {
+// throw new IllegalArgumentException("DeleteTransaction was called for non XA transaction");
+// }
+//
+// if (state != Transaction.STATE_COMMITTED && state != Transaction.STATE_ROLLEDBACK)
+// {
+// throw new TransactionException("Transaction with xid " + id + " can't be removed as it's not yet commited or rolledback: (Current state is " + Transaction.stateToString(state));
+// }
+//
+// map.remove(id);
+// }
+//
+// public Transaction createTransaction(Xid xid) throws Exception
+// {
+// if (map.containsKey(xid))
+// {
+// throw new TransactionException("There is already an entry for xid " + xid);
+// }
+// Transaction tx = new Transaction(idManager.getID(), xid, this);
+//
+// if (trace) { log.trace("created transaction " + tx); }
+//
+// map.put(xid, tx);
+//
+// return tx;
+// }
+//
+// public Transaction createTransaction() throws Exception
+// {
+// Transaction tx = new Transaction(idManager.getID());
+//
+// if (trace) { log.trace("created transaction " + tx); }
+//
+// return tx;
+// }
+//
+// public boolean removeTransaction(Xid xid)
+// {
+// return map.remove(xid) != null;
+// }
+//
+// /** To be used only by testcases */
+// public int getNumberOfRegisteredTransactions()
+// {
+// return this.map.size();
+// }
+//
+//
+//
+// // Package protected ---------------------------------------------
+//
+// /**
+// * Load the references and invoke the channel to handle those refs
+// */
+// void handleReferences(Transaction tx) throws Exception
+// {
+// if (trace) log.trace("Handle references for TX(XID: " + tx.getXid() + ", LocalID: " + tx.getId()+ "):");
+//
+// long txId = tx.getId();
+//
+// List pairs = persistenceManager.getMessageChannelPairRefsForTx(txId);
+//
+// if (trace) log.trace("Found " + pairs.size() + " unhandled references.");
+//
+// for (Iterator iter = pairs.iterator(); iter.hasNext();)
+// {
+// PersistenceManager.MessageChannelPair pair = (PersistenceManager.MessageChannelPair)iter.next();
+//
+// Message msg = pair.getMessage();
+//
+// long channelID = pair.getChannelId();
+//
+// MessageReference ref = messageStore.reference(msg);
+//
+// ref.getMessage().setPersisted(true);
+//
+// Binding binding = postOffice.getBindingForChannelID(channelID);
+//
+// if (binding == null)
+// {
+// throw new IllegalStateException("Cannot find binding for channel id " + channelID);
+// }
+//
+// Queue queue = binding.queue;
+//
+// if (trace) log.trace("Destination for message[ID=" + ref.getMessage().getMessageID() + "] is: " + queue);
+//
+// // The actual jmx queue may not have been deployed yet, so we need to activate the core queue if so,
+// // or the handle will have no effect
+//
+// boolean deactivate = false;
+//
+// if (!queue.isActive())
+// {
+// queue.activate();
+//
+// deactivate = true;
+// }
+//
+// queue.handle(null, ref, tx);
+//
+// if (deactivate)
+// {
+// queue.deactivate();
+// }
+// }
+// }
+//
+// /**
+// * Load the acks and acknowledge them
+// */
+// void handleAcks(Transaction tx) throws Exception
+// {
+// long txId = tx.getId();
+//
+// List pairs = persistenceManager.getMessageChannelPairAcksForTx(txId);
+//
+// if (trace) log.trace("Found " + pairs.size() + " unhandled acks.");
+//
+// List dels = new ArrayList();
+//
+// for (Iterator iter = pairs.iterator(); iter.hasNext();)
+// {
+// PersistenceManager.MessageChannelPair pair = (PersistenceManager.MessageChannelPair)iter.next();
+//
+// Message msg = pair.getMessage();
+//
+// long channelID = pair.getChannelId();
+//
+// MessageReference ref = null;
+//
+// ref = messageStore.reference(msg);
+//
+// ref.getMessage().setPersisted(true);
+//
+// Binding binding = postOffice.getBindingForChannelID(channelID);
+//
+// if (binding == null)
+// {
+// throw new IllegalStateException("Cannot find binding for channel id " + channelID);
+// }
+//
+// Queue queue = binding.queue;
+//
+// if (trace) log.trace("Destination for message[ID=" + ref.getMessage().getMessageID() + "] is: " + queue);
+//
+// //Create a new delivery - note that it must have a delivery observer otherwise acknowledge will fail
+// Delivery del = new SimpleDelivery(queue, ref, true, true);
+//
+// if (trace) log.trace("Acknowledging..");
+//
+// try
+// {
+// // The actual jmx queue may not have been deployed yet, so we need to the core queue if so,
+// // or the acknowledge will have no effect
+//
+// boolean deactivate = false;
+//
+// if (!queue.isActive())
+// {
+// queue.activate();
+//
+// deactivate = true;
+// }
+//
+// del.acknowledge(tx);
+//
+// if (deactivate)
+// {
+// queue.deactivate();
+// }
+// }
+// catch (Throwable t)
+// {
+// log.error("Failed to acknowledge " + del + " during recovery", t);
+// }
+//
+// dels.add(del);
+// }
+//
+// if (!dels.isEmpty())
+// {
+// //Add a callback so these dels get cancelled on rollback
+// tx.addCallback(new CancelCallback(dels), this);
+// }
+// }
+//
+// // Protected -----------------------------------------------------
+//
+// // Private -------------------------------------------------------
+//
+//
+//
+// /**
+// * Creates a prepared transaction
+// *
+// * @param txInfo
+// * @return
+// * @throws Exception
+// */
+// private Transaction createTransaction(PreparedTxInfo txInfo) throws Exception
+// {
+// if (map.containsKey(txInfo.getXid()))
+// {
+// throw new TransactionException(
+// "There is already an entry for xid " + txInfo.getXid());
+// }
+//
+// // Resurrected tx
+// Transaction tx = new Transaction(txInfo.getTxId(), txInfo.getXid(), this);
+//
+// if (trace) {
+// log.trace("created transaction " + tx);
+// }
+//
+// map.put(txInfo.getXid(), tx);
+//
+// return tx;
+// }
+//
+// // Inner classes -------------------------------------------------
+//
+// private class CancelCallback implements TxCallback
+// {
+// private List toCancel;
+//
+// private CancelCallback(List toCancel)
+// {
+// this.toCancel = toCancel;
+// }
+//
+// public void afterCommit(boolean onePhase) throws Exception
+// {
+// }
+//
+// public void afterPrepare() throws Exception
+// {
+// }
+//
+// public void afterRollback(boolean onePhase) throws Exception
+// {
+// //On rollback we need to cancel the ref back into the channel
+// //We only need to do this if the tx was reloaded since otherwise the
+// //cancel will come from the SCE
+//
+// //Need to cancel in reverse
+//
+// for (int i = toCancel.size() - 1; i >= 0; i--)
+// {
+// Delivery del = (Delivery)toCancel.get(i);
+//
+// try
+// {
+// del.cancel();
+// }
+// catch (Throwable t)
+// {
+// log.error("Failed to cancel delivery", t);
+// throw new TransactionException(t.getMessage(), t);
+// }
+// }
+// }
+//
+// public void beforeCommit(boolean onePhase) throws Exception
+// {
+// }
+//
+// public void beforePrepare() throws Exception
+// {
+// }
+//
+// public void beforeRollback(boolean onePhase) throws Exception
+// {
+// }
+//
+// }
- private boolean trace = log.isTraceEnabled();
-
- private Map map;
-
- private PersistenceManager persistenceManager;
-
- protected MessageStore messageStore;
-
- private IDManager idManager;
-
- private PostOffice postOffice;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public TransactionRepository(PersistenceManager persistenceManager, MessageStore store, IDManager idManager)
- {
- this.persistenceManager = persistenceManager;
-
- this.messageStore = store;
-
- this.idManager = idManager;
-
- map = new ConcurrentHashMap();
- }
-
- // Injection ----------------------------------------
-
- //Unfortunately we have to do this for now, since PostOffice is not started until after this is constructed
- //We will sort out dependencies properly when we go to the micro container
- public void injectPostOffice(PostOffice po)
- {
- postOffice = po;
- }
-
-
- // MessagingComponent implementation --------------------------------
-
- public void start() throws Exception
- {
- //NOOP
- }
-
- // Public --------------------------------------------------------
-
- public void stop() throws Exception
- {
- //NOOP
- }
-
- // Public --------------------------------------------------------
-
- /**
- * Attempts to recover existing prepared transactions by redelivering unhandled messages and acknowledgements
- * on the appropriate channels.
- *
- * @return List of Xid instances
- */
- public synchronized List recoverPreparedTransactions()
- {
- if (trace) { log.trace(this + " recoverPreparedTransactions()"); }
-
- ArrayList prepared = new ArrayList();
-
- Iterator iter = map.values().iterator();
-
- while (iter.hasNext())
- {
- Transaction tx = (Transaction) iter.next();
-
- if (tx.getXid() != null && tx.getState() == Transaction.STATE_PREPARED)
- {
- try
- {
- if (trace) log.trace("Loading and handling refs and acks to the Tx "+tx);
-
- //The transaction might have been created, prepared, without the server crashing
- //in which case the tx will already have the references and acks in them
- //in this case we DO NOT want to replay them again, since they will end up in the transaction state
- //twice
- //In other words we only want to replay acks and sends if this tx was recovered from the db
- if (tx.isRecoveredFromStorage())
- {
- tx.loadState();
- }
- }
- catch (Exception e)
- {
- log.warn("Failed to replay transaction (XID: " + tx.getXid() + ", LocalID: " + tx.getId() + ") during recovery.", e);
- }
-
- prepared.add(tx.getXid());
- }
- }
-
- if (trace) { log.trace("Returning " + prepared.size() + " transactions"); }
-
- return prepared;
- }
-
- /*
- * Load any prepared transactions into the repository so they can be
- * recovered
- */
- public void loadPreparedTransactions() throws Exception
- {
- if (trace) log.trace("load prepared transactions...");
-
- List prepared = null;
-
- prepared = persistenceManager.retrievePreparedTransactions();
-
- if (trace) log.trace ("found " + prepared.size() + " transactions in prepared state");
-
- if (prepared != null)
- {
- Iterator iter = prepared.iterator();
-
- while (iter.hasNext())
- {
- PreparedTxInfo txInfo = (PreparedTxInfo) iter.next();
-
- //This method may be called more than once - e.g. when failover occurs so we don't want to add the
- //prepared tx if it is already in memory
-
- if (!map.containsKey(txInfo.getXid()))
- {
- Transaction tx = createTransaction(txInfo);
-
- tx.setState(Transaction.STATE_PREPARED);
-
- tx.setRecoveredFromStorage(true);
-
- if (trace) log.trace("reinstating TX(XID: " + txInfo.getXid() + ", LocalId " + txInfo.getTxId() +")");
-
- }
- else
- {
- if (trace) log.trace("Not adding to map since it's already in map");
- }
- }
- }
- }
-
- public List getPreparedTransactions()
- {
- return new ArrayList(map.keySet());
- }
-
- public Transaction getPreparedTx(Xid xid) throws Exception
- {
- Transaction tx = (Transaction)map.get(xid);
-
- if (tx == null)
- {
- throw new TransactionException("Cannot find entry for xid:" + xid);
- }
- if (tx.getState() != Transaction.STATE_PREPARED)
- {
- throw new TransactionException("Transaction with xid " + xid + " is not in prepared state");
- }
- return tx;
- }
-
- public void deleteTransaction(Transaction transaction) throws Exception
- {
- final Xid id = transaction.getXid();
- final int state = transaction.getState();
-
- if (id == null)
- {
- throw new IllegalArgumentException("DeleteTransaction was called for non XA transaction");
- }
-
- if (state != Transaction.STATE_COMMITTED && state != Transaction.STATE_ROLLEDBACK)
- {
- throw new TransactionException("Transaction with xid " + id + " can't be removed as it's not yet commited or rolledback: (Current state is " + Transaction.stateToString(state));
- }
-
- map.remove(id);
- }
-
- public Transaction createTransaction(Xid xid) throws Exception
- {
- if (map.containsKey(xid))
- {
- throw new TransactionException("There is already an entry for xid " + xid);
- }
- Transaction tx = new Transaction(idManager.getID(), xid, this);
-
- if (trace) { log.trace("created transaction " + tx); }
-
- map.put(xid, tx);
-
- return tx;
- }
-
- public Transaction createTransaction() throws Exception
- {
- Transaction tx = new Transaction(idManager.getID());
-
- if (trace) { log.trace("created transaction " + tx); }
-
- return tx;
- }
-
- public boolean removeTransaction(Xid xid)
- {
- return map.remove(xid) != null;
- }
-
- /** To be used only by testcases */
- public int getNumberOfRegisteredTransactions()
- {
- return this.map.size();
- }
-
-
-
- // Package protected ---------------------------------------------
-
- /**
- * Load the references and invoke the channel to handle those refs
- */
- void handleReferences(Transaction tx) throws Exception
- {
- if (trace) log.trace("Handle references for TX(XID: " + tx.getXid() + ", LocalID: " + tx.getId()+ "):");
-
- long txId = tx.getId();
-
- List pairs = persistenceManager.getMessageChannelPairRefsForTx(txId);
-
- if (trace) log.trace("Found " + pairs.size() + " unhandled references.");
-
- for (Iterator iter = pairs.iterator(); iter.hasNext();)
- {
- PersistenceManager.MessageChannelPair pair = (PersistenceManager.MessageChannelPair)iter.next();
-
- Message msg = pair.getMessage();
-
- long channelID = pair.getChannelId();
-
- MessageReference ref = messageStore.reference(msg);
-
- ref.getMessage().setPersisted(true);
-
- Binding binding = postOffice.getBindingForChannelID(channelID);
-
- if (binding == null)
- {
- throw new IllegalStateException("Cannot find binding for channel id " + channelID);
- }
-
- Queue queue = binding.queue;
-
- if (trace) log.trace("Destination for message[ID=" + ref.getMessage().getMessageID() + "] is: " + queue);
-
- // The actual jmx queue may not have been deployed yet, so we need to activate the core queue if so,
- // or the handle will have no effect
-
- boolean deactivate = false;
-
- if (!queue.isActive())
- {
- queue.activate();
-
- deactivate = true;
- }
-
- queue.handle(null, ref, tx);
-
- if (deactivate)
- {
- queue.deactivate();
- }
- }
- }
-
- /**
- * Load the acks and acknowledge them
- */
- void handleAcks(Transaction tx) throws Exception
- {
- long txId = tx.getId();
-
- List pairs = persistenceManager.getMessageChannelPairAcksForTx(txId);
-
- if (trace) log.trace("Found " + pairs.size() + " unhandled acks.");
-
- List dels = new ArrayList();
-
- for (Iterator iter = pairs.iterator(); iter.hasNext();)
- {
- PersistenceManager.MessageChannelPair pair = (PersistenceManager.MessageChannelPair)iter.next();
-
- Message msg = pair.getMessage();
-
- long channelID = pair.getChannelId();
-
- MessageReference ref = null;
-
- ref = messageStore.reference(msg);
-
- ref.getMessage().setPersisted(true);
-
- Binding binding = postOffice.getBindingForChannelID(channelID);
-
- if (binding == null)
- {
- throw new IllegalStateException("Cannot find binding for channel id " + channelID);
- }
-
- Queue queue = binding.queue;
-
- if (trace) log.trace("Destination for message[ID=" + ref.getMessage().getMessageID() + "] is: " + queue);
-
- //Create a new delivery - note that it must have a delivery observer otherwise acknowledge will fail
- Delivery del = new SimpleDelivery(queue, ref, true, true);
-
- if (trace) log.trace("Acknowledging..");
-
- try
- {
- // The actual jmx queue may not have been deployed yet, so we need to the core queue if so,
- // or the acknowledge will have no effect
-
- boolean deactivate = false;
-
- if (!queue.isActive())
- {
- queue.activate();
-
- deactivate = true;
- }
-
- del.acknowledge(tx);
-
- if (deactivate)
- {
- queue.deactivate();
- }
- }
- catch (Throwable t)
- {
- log.error("Failed to acknowledge " + del + " during recovery", t);
- }
-
- dels.add(del);
- }
-
- if (!dels.isEmpty())
- {
- //Add a callback so these dels get cancelled on rollback
- tx.addCallback(new CancelCallback(dels), this);
- }
- }
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
-
-
- /**
- * Creates a prepared transaction
- *
- * @param txInfo
- * @return
- * @throws Exception
- */
- private Transaction createTransaction(PreparedTxInfo txInfo) throws Exception
- {
- if (map.containsKey(txInfo.getXid()))
- {
- throw new TransactionException(
- "There is already an entry for xid " + txInfo.getXid());
- }
-
- // Resurrected tx
- Transaction tx = new Transaction(txInfo.getTxId(), txInfo.getXid(), this);
-
- if (trace) {
- log.trace("created transaction " + tx);
- }
-
- map.put(txInfo.getXid(), tx);
-
- return tx;
- }
-
- // Inner classes -------------------------------------------------
-
- private class CancelCallback implements TxCallback
- {
- private List toCancel;
-
- private CancelCallback(List toCancel)
- {
- this.toCancel = toCancel;
- }
-
- public void afterCommit(boolean onePhase) throws Exception
- {
- }
-
- public void afterPrepare() throws Exception
- {
- }
-
- public void afterRollback(boolean onePhase) throws Exception
- {
- //On rollback we need to cancel the ref back into the channel
- //We only need to do this if the tx was reloaded since otherwise the
- //cancel will come from the SCE
-
- //Need to cancel in reverse
-
- for (int i = toCancel.size() - 1; i >= 0; i--)
- {
- Delivery del = (Delivery)toCancel.get(i);
-
- try
- {
- del.cancel();
- }
- catch (Throwable t)
- {
- log.error("Failed to cancel delivery", t);
- throw new TransactionException(t.getMessage(), t);
- }
- }
- }
-
- public void beforeCommit(boolean onePhase) throws Exception
- {
- }
-
- public void beforePrepare() throws Exception
- {
- }
-
- public void beforeRollback(boolean onePhase) throws Exception
- {
- }
-
- }
-
}
\ No newline at end of file
Added: branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/ClusteredQueue.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/ClusteredQueue.java (rev 0)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/ClusteredQueue.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -0,0 +1,34 @@
+/*
+ * 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 ClusteredQueue
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface ClusteredQueue extends Queue
+{
+
+}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Filter.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Filter.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Filter.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -31,4 +31,6 @@
public interface Filter
{
boolean match(Message message);
+
+ String getFilterString();
}
Modified: branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Queue.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Queue.java 2007-12-10 17:32:22 UTC (rev 3465)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/Queue.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -69,5 +69,5 @@
DistributionPolicy getDistributionPolicy();
- void setDistributionPolicy(DistributionPolicy policy);
+ void setDistributionPolicy(DistributionPolicy policy);
}
Added: branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/QueueStatistics.java
===================================================================
--- branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/QueueStatistics.java (rev 0)
+++ branches/Branch_New_Persistence/src/main/org/jboss/messaging/newcore/intf/QueueStatistics.java 2007-12-10 18:44:52 UTC (rev 3466)
@@ -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 QueueStatistics
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface QueueStatistics
+{
+ int getMessageCount();
+
+ int getScheduledCount();
+
+ int getGetDeliveringCount();
+}
More information about the jboss-cvs-commits
mailing list