[Jboss-cvs] JBoss Messaging SVN: r1321 - in trunk: src/etc/server/default/deploy src/main/org/jboss/jms/client src/main/org/jboss/jms/client/container src/main/org/jboss/jms/selector src/main/org/jboss/jms/server src/main/org/jboss/jms/server/destination src/main/org/jboss/jms/server/endpoint src/main/org/jboss/jms/server/remoting src/main/org/jboss/jms/tx src/main/org/jboss/jms/util src/main/org/jboss/messaging/core src/main/org/jboss/messaging/core/local src/main/org/jboss/messaging/core/plugin src/main/org/jboss/messaging/core/plugin/postoffice src/main/org/jboss/messaging/core/plugin/postoffice/cluster tests/src/org/jboss/test/messaging/core tests/src/org/jboss/test/messaging/core/plugin/postoffice tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster tests/src/org/jboss/test/messaging/jms
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 19 15:17:38 EDT 2006
Author: timfox
Date: 2006-09-19 15:17:09 -0400 (Tue, 19 Sep 2006)
New Revision: 1321
Added:
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/DefaultPostOffice.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/StandardRedistributionPolicy.java
trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/DefaultPostOfficeTest.java
Removed:
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/PostOfficeImpl.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/BasicRedistributionPolicy.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusterRouter.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/DefaultRedistributionPolicy.java
trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/SimplePostOfficeTest.java
Modified:
trunk/src/etc/server/default/deploy/hsqldb-persistence-service.xml
trunk/src/main/org/jboss/jms/client/JBossConnection.java
trunk/src/main/org/jboss/jms/client/container/SessionAspect.java
trunk/src/main/org/jboss/jms/client/container/TransactionAspect.java
trunk/src/main/org/jboss/jms/selector/SelectorFactory.java
trunk/src/main/org/jboss/jms/server/ServerPeer.java
trunk/src/main/org/jboss/jms/server/destination/QueueService.java
trunk/src/main/org/jboss/jms/server/destination/TopicService.java
trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
trunk/src/main/org/jboss/jms/server/remoting/JMSWireFormat.java
trunk/src/main/org/jboss/jms/tx/ResourceManager.java
trunk/src/main/org/jboss/jms/util/ExceptionUtil.java
trunk/src/main/org/jboss/messaging/core/Channel.java
trunk/src/main/org/jboss/messaging/core/ChannelSupport.java
trunk/src/main/org/jboss/messaging/core/Distributor.java
trunk/src/main/org/jboss/messaging/core/PagingChannelSupport.java
trunk/src/main/org/jboss/messaging/core/local/FirstReceiverPointToPointRouter.java
trunk/src/main/org/jboss/messaging/core/local/PagingFilteredQueue.java
trunk/src/main/org/jboss/messaging/core/local/RoundRobinPointToPointRouter.java
trunk/src/main/org/jboss/messaging/core/plugin/ClusteredPostOfficeService.java
trunk/src/main/org/jboss/messaging/core/plugin/SimplePostOfficeService.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/BindingImpl.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/CastMessagesCallback.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusterRouterFactory.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredBindingsImpl.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeImpl.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredQueue.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/FavourLocalRouter.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/FavourLocalRouterFactory.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/LocalClusteredQueue.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/QueueStats.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/RedistributionPolicy.java
trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/RemoteQueueStub.java
trunk/tests/src/org/jboss/test/messaging/core/SimpleChannel.java
trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java
trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java
trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/FavourLocalRouterTest.java
trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/JGroupsUtil.java
trunk/tests/src/org/jboss/test/messaging/jms/ReferencingTest.java
trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java
trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java
Log:
More clustering work
Modified: trunk/src/etc/server/default/deploy/hsqldb-persistence-service.xml
===================================================================
--- trunk/src/etc/server/default/deploy/hsqldb-persistence-service.xml 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/etc/server/default/deploy/hsqldb-persistence-service.xml 2006-09-19 19:17:09 UTC (rev 1321)
@@ -89,27 +89,29 @@
Do we need failure detection and group management in this stack ??
<attribute name="AsyncChannelConfig">
- <UDP mcast_addr="228.8.8.8" mcast_port="45569"
- ip_ttl="8" ip_mcast="true"
- mcast_send_buf_size="800000" mcast_recv_buf_size="150000"
- ucast_send_buf_size="800000" ucast_recv_buf_size="150000"
- loopback="false"/>
- <PING timeout="2000" num_initial_members="3"
- up_thread="true" down_thread="true"/>
- <MERGE2 min_interval="10000" max_interval="20000"/>
- <FD shun="true" up_thread="true" down_thread="true"
- timeout="2500" max_tries="5"/>
- <VERIFY_SUSPECT timeout="3000" num_msgs="3"
- up_thread="true" down_thread="true"/>
- <pbcast.NAKACK gc_lag="50" retransmit_timeout="300,600,1200,2400,4800"
- max_xmit_size="8192"
- up_thread="true" down_thread="true"/>
- <pbcast.STABLE desired_avg_gossip="20000"
- up_thread="true" down_thread="true"/>
- <FRAG frag_size="8192"
- down_thread="true" up_thread="true"/>
- <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
- shun="true" print_local_addr="true"/>
+ <UDP mcast_addr="${jboss.partition.udpGroup:228.1.2.3}" mcast_port="45566"
+ ip_ttl="8" ip_mcast="true"
+ mcast_send_buf_size="800000" mcast_recv_buf_size="150000"
+ ucast_send_buf_size="800000" ucast_recv_buf_size="150000"
+ loopback="false"/>
+ <PING timeout="2000" num_initial_members="3"
+ up_thread="true" down_thread="true"/>
+ <MERGE2 min_interval="10000" max_interval="20000"/>
+ <FD shun="true" up_thread="true" down_thread="true"
+ timeout="2500" max_tries="5"/>
+ <VERIFY_SUSPECT timeout="3000" num_msgs="3"
+ up_thread="true" down_thread="true"/>
+ <pbcast.NAKACK gc_lag="50" retransmit_timeout="300,600,1200,2400,4800"
+ max_xmit_size="8192"
+ up_thread="true" down_thread="true"/>
+ <UNICAST timeout="300,600,1200,2400,4800" window_size="100" min_threshold="10"
+ down_thread="true"/>
+ <pbcast.STABLE desired_avg_gossip="20000"
+ up_thread="true" down_thread="true"/>
+ <FRAG frag_size="8192"
+ down_thread="true" up_thread="true"/>
+ <pbcast.GMS join_timeout="5000" join_retry_timeout="2000"
+ shun="true" print_local_addr="true"/>
</attribute>
</mbean>
Modified: trunk/src/main/org/jboss/jms/client/JBossConnection.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/JBossConnection.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/client/JBossConnection.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -75,6 +75,7 @@
protected ConnectionDelegate delegate;
private int connectionType;
+ private boolean closed;
// Constructors --------------------------------------------------
@@ -130,6 +131,7 @@
{
delegate.closing();
delegate.close();
+ closed = true;
}
public ConnectionConsumer createConnectionConsumer(Destination destination,
@@ -261,6 +263,17 @@
tccc.restore();
}
}
+
+ protected void finalize() throws Throwable
+ {
+ super.finalize();
+ //If a user hasn't explicitly closed the connection due to sloppy programming
+ //then we close it here
+ if (!closed)
+ {
+ close();
+ }
+ }
// Private -------------------------------------------------------
Modified: trunk/src/main/org/jboss/jms/client/container/SessionAspect.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/SessionAspect.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/client/container/SessionAspect.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -224,13 +224,6 @@
*
* So on rollback we do session recovery (local redelivery) in the same as if session.recover()
* was called.
- *
- * There is a conflict here though. It seems a CTS test requires messages to be available to
- * OTHER sessions on rollback - see CTSMiscellaneousTest.testContestedQueueOnRollback(), which
- * seems in direct contradiction to the spec.
- *
- * In order to satisfy the test, on session recovery, if there are no local consumers available
- * to consume the message, we cancel the message back to the channel.
*/
public Object handleRedeliver(Invocation invocation) throws Throwable
{
Modified: trunk/src/main/org/jboss/jms/client/container/TransactionAspect.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/TransactionAspect.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/client/container/TransactionAspect.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -35,8 +35,9 @@
import org.jboss.jms.message.MessageProxy;
import org.jboss.jms.tx.AckInfo;
import org.jboss.jms.tx.LocalTx;
+import org.jboss.jms.tx.ResourceManager;
import org.jboss.jms.tx.TxState;
-import org.jboss.jms.tx.ResourceManager;
+import org.jboss.jms.util.MessagingTransactionRolledBackException;
/**
* This aspect handles transaction related logic
Modified: trunk/src/main/org/jboss/jms/selector/SelectorFactory.java
===================================================================
--- trunk/src/main/org/jboss/jms/selector/SelectorFactory.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/selector/SelectorFactory.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -39,5 +39,4 @@
{
return filterString == null ? null : new Selector(filterString);
}
-
}
Modified: trunk/src/main/org/jboss/jms/server/ServerPeer.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/ServerPeer.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/server/ServerPeer.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -53,7 +53,7 @@
import org.jboss.messaging.core.plugin.contract.PersistenceManager;
import org.jboss.messaging.core.plugin.contract.PostOffice;
import org.jboss.messaging.core.plugin.contract.ShutdownLogger;
-import org.jboss.messaging.core.plugin.postoffice.PostOfficeImpl;
+import org.jboss.messaging.core.plugin.postoffice.DefaultPostOffice;
import org.jboss.messaging.core.tx.TransactionRepository;
import org.jboss.messaging.util.Util;
import org.jboss.mx.loading.UnifiedClassLoader3;
@@ -127,10 +127,10 @@
protected PersistenceManager persistenceManager;
protected ObjectName queuePostOfficeObjectName;
- protected PostOfficeImpl queuePostOffice;
+ protected DefaultPostOffice queuePostOffice;
protected ObjectName topicPostOfficeObjectName;
- protected PostOfficeImpl topicPostOffice;
+ protected DefaultPostOffice topicPostOffice;
protected ObjectName jmsUserManagerObjectName;
protected JMSUserManager jmsUserManager;
@@ -642,7 +642,7 @@
// We get the reference lazily to avoid problems with MBean circular dependencies
if (queuePostOffice == null)
{
- queuePostOffice = (PostOfficeImpl)getServer().
+ queuePostOffice = (DefaultPostOffice)getServer().
getAttribute(queuePostOfficeObjectName, "Instance");
}
return queuePostOffice;
@@ -653,7 +653,7 @@
// We get the reference lazily to avoid problems with MBean circular dependencies
if (topicPostOffice == null)
{
- topicPostOffice = (PostOfficeImpl)getServer().
+ topicPostOffice = (DefaultPostOffice)getServer().
getAttribute(topicPostOfficeObjectName, "Instance");
}
return topicPostOffice;
Modified: trunk/src/main/org/jboss/jms/server/destination/QueueService.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/destination/QueueService.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/server/destination/QueueService.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -94,9 +94,9 @@
{
PagingFilteredQueue queue = (PagingFilteredQueue)binding.getQueue();
- //Activate it - this causes it's state to be loaded
- queue.deactivate();
- queue.activate(destination.getFullSize(), destination.getPageSize(), destination.getDownCacheSize());
+ queue.setPagingParams(destination.getFullSize(), destination.getPageSize(), destination.getDownCacheSize());
+ queue.load();
+ queue.activate();
}
else
{
@@ -155,6 +155,7 @@
PagingFilteredQueue queue = (PagingFilteredQueue)binding.getQueue();
queue.deactivate();
+ queue.unload();
started = false;
Modified: trunk/src/main/org/jboss/jms/server/destination/TopicService.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/destination/TopicService.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/server/destination/TopicService.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -72,9 +72,10 @@
Binding binding = (Binding)iter.next();
PagingFilteredQueue queue = (PagingFilteredQueue)binding.getQueue();
-
- queue.deactivate();
- queue.activate(destination.getFullSize(), destination.getPageSize(), destination.getDownCacheSize());
+
+ queue.setPagingParams(destination.getFullSize(), destination.getPageSize(), destination.getDownCacheSize());
+ queue.load();
+ queue.activate();
}
// push security update to the server
@@ -123,6 +124,7 @@
}
queue.deactivate();
+ queue.unload();
}
started = false;
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -350,96 +350,33 @@
{
if (trace) { log.trace("one phase commit request received"); }
- Transaction tx = null;
- try
- {
- tx = tr.createTransaction();
- processTransaction(request.getState(), tx);
- tx.commit();
- }
- catch (Throwable t)
- {
- log.error("Exception occured", t);
- if (tx != null)
- {
- try
- {
- tx.rollback();
- throw new MessagingTransactionRolledBackException("Transaction was rolled back.", t);
- }
- catch (Exception e)
- {
- log.error("Failed to rollback tx", e);
- throw new MessagingJMSException("Failed to rollback tx after commit failure", e);
- }
- }
- }
+ Transaction tx = tr.createTransaction();
+ processTransaction(request.getState(), tx);
+ tx.commit();
}
else if (request.getRequestType() == TransactionRequest.TWO_PHASE_PREPARE_REQUEST)
{
if (trace) { log.trace("Two phase commit prepare request received"); }
- Transaction tx = null;
- try
- {
- tx = tr.createTransaction(request.getXid());
- processTransaction(request.getState(), tx);
- tx.prepare();
- }
- catch (Throwable t)
- {
- log.error("Exception occured", t);
- if (tx != null)
- {
- try
- {
- tx.rollback();
- throw new MessagingTransactionRolledBackException("Transaction was rolled back.", t);
- }
- catch (Exception e)
- {
- log.error("Failed to rollback tx", e);
- throw new MessagingJMSException("Failed to rollback transaction after failure in prepare", e);
- }
- }
- }
+ Transaction tx = tr.createTransaction(request.getXid());
+ processTransaction(request.getState(), tx);
+ tx.prepare();
}
else if (request.getRequestType() == TransactionRequest.TWO_PHASE_COMMIT_REQUEST)
{
if (trace) { log.trace("Two phase commit commit request received"); }
- Transaction tx = null;
- try
- {
- tx = tr.getPreparedTx(request.getXid());
- if (trace) { log.trace("Committing " + tx); }
- tx.commit();
- }
- catch (Throwable t)
- {
- log.error("Exception occured", t);
- //For 2PC commit we don't rollback if failure occurs - this allows the transaction manager
- //to try again if the problem was transitory
- throw new MessagingJMSException("Failed to commit transaction", t);
- }
+ Transaction tx = tr.getPreparedTx(request.getXid());
+ if (trace) { log.trace("Committing " + tx); }
+ tx.commit();
}
else if (request.getRequestType() == TransactionRequest.TWO_PHASE_ROLLBACK_REQUEST)
{
if (trace) { log.trace("Two phase commit rollback request received"); }
- Transaction tx = null;
- try
- {
- tx = tr.getPreparedTx(request.getXid());
- if (trace) { log.trace("Rolling back " + tx); }
- tx.rollback();
- }
- catch (Throwable t)
- {
- log.error("Exception occured", t);
-
- throw new MessagingJMSException("Failed to rollback transaction", t);
- }
+ Transaction tx = tr.getPreparedTx(request.getXid());
+ if (trace) { log.trace("Rolling back " + tx); }
+ tx.rollback();
}
if (trace) { log.trace(this + " processed transaction successfully"); }
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -206,6 +206,8 @@
{
if (trace) { log.trace(this + " receives " + ref + " for delivery"); }
+ log.info("BEING OFFERED -------- " + ref);
+
// This is ok to have outside lock - is volatile
if (bufferFull)
{
Modified: trunk/src/main/org/jboss/jms/server/remoting/JMSWireFormat.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/remoting/JMSWireFormat.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/server/remoting/JMSWireFormat.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -33,6 +33,8 @@
import java.util.List;
import java.util.Map;
+import javax.jms.Message;
+
import org.jboss.aop.Dispatcher;
import org.jboss.aop.joinpoint.MethodInvocation;
import org.jboss.jms.client.remoting.CallbackServerFactory;
@@ -99,6 +101,8 @@
protected static final byte NULL_RESPONSE = 101;
protected static final byte ID_BLOCK_RESPONSE = 102;
protected static final byte HANDLE_MESSAGE_RESPONSE = 103;
+ protected static final byte BROWSE_MESSAGE_RESPONSE = 104;
+ protected static final byte BROWSE_MESSAGES_RESPONSE = 105;
// Static --------------------------------------------------------
@@ -367,6 +371,44 @@
if (trace) { log.trace("wrote handle message response"); }
}
+ else if (res instanceof JBossMessage)
+ {
+ //Return value from browsing message
+ dos.write(BROWSE_MESSAGE_RESPONSE);
+
+ JBossMessage msg = (JBossMessage)res;
+
+ dos.writeByte(msg.getType());
+
+ msg.write(dos);
+
+ dos.flush();
+
+ if (trace) { log.trace("wrote browse message response"); }
+ }
+
+ else if (res instanceof Message[])
+ {
+ //Return value from browsing messages
+ dos.write(BROWSE_MESSAGES_RESPONSE);
+
+ Message[] msgs = (Message[])res;
+
+ dos.writeInt(msgs.length);
+
+ for (int i = 0; i < msgs.length; i++)
+ {
+ JBossMessage m = (JBossMessage)msgs[i];
+
+ dos.writeByte(m.getType());
+
+ m.write(dos);
+ }
+
+ dos.flush();
+
+ if (trace) { log.trace("wrote browse message response"); }
+ }
else
{
dos.write(SERIALIZED);
@@ -603,6 +645,43 @@
return resp;
}
+ case BROWSE_MESSAGE_RESPONSE:
+ {
+ byte type = dis.readByte();
+
+ JBossMessage msg = (JBossMessage)MessageFactory.createMessage(type);
+
+ msg.read(dis);
+
+ InvocationResponse resp = new InvocationResponse(null, new MessagingMarshallable(version, msg), false, null);
+
+ if (trace) { log.trace("read browse message response"); }
+
+ return resp;
+ }
+ case BROWSE_MESSAGES_RESPONSE:
+ {
+ int num = dis.readInt();
+
+ Message[] msgs = new Message[num];
+
+ for (int i = 0; i < num; i++)
+ {
+ byte type = dis.readByte();
+
+ JBossMessage msg = (JBossMessage)MessageFactory.createMessage(type);
+
+ msg.read(dis);
+
+ msgs[i] = msg;
+ }
+
+ InvocationResponse resp = new InvocationResponse(null, new MessagingMarshallable(version, msgs), false, null);
+
+ if (trace) { log.trace("read browse message response"); }
+
+ return resp;
+ }
case NULL_RESPONSE:
{
InvocationResponse resp =
Modified: trunk/src/main/org/jboss/jms/tx/ResourceManager.java
===================================================================
--- trunk/src/main/org/jboss/jms/tx/ResourceManager.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/tx/ResourceManager.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -38,6 +38,7 @@
import org.jboss.jms.delegate.ConnectionDelegate;
import org.jboss.jms.delegate.SessionDelegate;
+import org.jboss.jms.util.MessagingTransactionRolledBackException;
import org.jboss.jms.util.MessagingXAException;
import org.jboss.logging.Logger;
@@ -145,7 +146,7 @@
{
if (trace) { log.trace("commiting local xid " + xid); }
- TxState tx = removeTx(xid);
+ TxState tx = this.getTx(xid);
//Invalid xid
if (tx == null)
@@ -156,7 +157,23 @@
TransactionRequest request =
new TransactionRequest(TransactionRequest.ONE_PHASE_COMMIT_REQUEST, null, tx);
- connection.sendTransaction(request);
+ try
+ {
+ connection.sendTransaction(request);
+
+ //If we get this far we can remove the transaction
+
+ this.removeTx(xid);
+ }
+ catch (Throwable t)
+ {
+ //If a problem occurs during commit processing the session should be rolled back
+ rollbackLocal(xid, connection);
+
+ JMSException e = new MessagingTransactionRolledBackException(t.getMessage());
+
+ throw e;
+ }
}
public void rollbackLocal(LocalTx xid, ConnectionDelegate connection) throws JMSException
@@ -220,7 +237,7 @@
request.xid = xid;
- sendTransactionXA(request, connection);
+ sendTransactionXA(request, connection);
}
if (tx != null)
Modified: trunk/src/main/org/jboss/jms/util/ExceptionUtil.java
===================================================================
--- trunk/src/main/org/jboss/jms/util/ExceptionUtil.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/jms/util/ExceptionUtil.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -64,7 +64,7 @@
log.error(msg + " [" + id + "]", t);
if (t instanceof JMSException)
- {
+ {
return (JMSException)t;
}
else
Modified: trunk/src/main/org/jboss/messaging/core/Channel.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/Channel.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/Channel.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -135,6 +135,16 @@
* @throws Throwable
*/
void removeAllReferences() throws Throwable;
+
+ void load() throws Exception;
+
+ void unload() throws Exception;
+
+ void activate();
+
+ void deactivate();
+
+ boolean isActive();
}
Modified: trunk/src/main/org/jboss/messaging/core/ChannelSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/ChannelSupport.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/ChannelSupport.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -97,7 +97,9 @@
protected Object refLock;
protected Object deliveryLock;
-
+
+ protected boolean active = true;
+
// Constructors --------------------------------------------------
protected ChannelSupport(long channelID, MessageStore ms,
@@ -142,6 +144,11 @@
public Delivery handle(DeliveryObserver sender, MessageReference ref, Transaction tx)
{
+ if (!active)
+ {
+ return null;
+ }
+
checkClosed();
Future result = new Future();
@@ -238,6 +245,11 @@
{
return router.iterator();
}
+
+ public int numberOfReceivers()
+ {
+ return router.numberOfReceivers();
+ }
// Channel implementation ----------------------------------------
@@ -445,6 +457,39 @@
}
}
}
+
+ public void activate()
+ {
+ synchronized (refLock)
+ {
+ synchronized (deliveryLock)
+ {
+ active = true;
+ }
+ }
+ }
+
+ public void deactivate()
+ {
+ synchronized (refLock)
+ {
+ synchronized (deliveryLock)
+ {
+ active = false;
+ }
+ }
+ }
+
+ public boolean isActive()
+ {
+ synchronized (refLock)
+ {
+ synchronized (deliveryLock)
+ {
+ return active;
+ }
+ }
+ }
// Public --------------------------------------------------------
@@ -743,7 +788,7 @@
}
// I might as well return null, the sender shouldn't care
- return new SimpleDelivery(sender, ref, true);
+ return new SimpleDelivery(this, ref, true);
}
protected void acknowledgeInternal(Delivery d) throws Exception
Modified: trunk/src/main/org/jboss/messaging/core/Distributor.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/Distributor.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/Distributor.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -62,5 +62,11 @@
* Remove all receivers.
*/
void clear();
+
+ /**
+ *
+ * @return The number of receivers in the distributor
+ */
+ int numberOfReceivers();
}
Modified: trunk/src/main/org/jboss/messaging/core/PagingChannelSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/PagingChannelSupport.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/PagingChannelSupport.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -89,12 +89,6 @@
protected long nextPagingOrder;
/**
- * Is the queue active?
- */
- protected boolean active;
-
-
- /**
* Constructor with default paging params
* @param channelID
* @param ms
@@ -169,12 +163,7 @@
// -----------------------------------------------------------------
public Delivery handle(DeliveryObserver sender, MessageReference ref, Transaction tx)
- {
- if (!active)
- {
- return null;
- }
-
+ {
return super.handle(sender, ref, tx);
}
@@ -213,23 +202,39 @@
}
}
- public void activate(int fullSize, int pageSize, int downCacheSize) throws Exception
+ public void setPagingParams(int fullSize, int pageSize, int downCacheSize)
+ {
+ synchronized (refLock)
+ {
+ synchronized (deliveryLock)
+ {
+ if (active)
+ {
+ throw new IllegalStateException("Cannot set paging params when active");
+ }
+
+ this.fullSize = fullSize;
+
+ this.pageSize = pageSize;
+
+ this.downCacheSize = downCacheSize;
+ }
+ }
+ }
+
+ public void load() throws Exception
{
synchronized (refLock)
{
if (active)
{
- return;
+ throw new IllegalStateException("Cannot load channel when active");
}
- this.fullSize = fullSize;
+ if (trace) { log.trace(this + " loading channel state"); }
- this.pageSize = pageSize;
+ unload();
- this.downCacheSize = downCacheSize;
-
- if (trace) { log.trace(this + " loading channel state"); }
-
InitialLoadInfo ili = pm.getInitialReferenceInfos(channelID, fullSize);
if (ili.getMaxPageOrdering() != null)
@@ -255,16 +260,19 @@
addFromRefInfo(info, refMap);
}
}
-
- active = true;
}
- public void deactivate() throws Exception
+ public void unload() throws Exception
{
synchronized (refLock)
{
synchronized (deliveryLock)
{
+ if (active)
+ {
+ throw new IllegalStateException("Cannot unload channel when active");
+ }
+
messageRefs.clear();
deliveries.clear();
@@ -274,8 +282,6 @@
paging = false;
firstPagingOrder = nextPagingOrder = 0;
-
- active = true;
}
}
}
Modified: trunk/src/main/org/jboss/messaging/core/local/FirstReceiverPointToPointRouter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/local/FirstReceiverPointToPointRouter.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/local/FirstReceiverPointToPointRouter.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -163,6 +163,14 @@
return receivers.iterator();
}
}
+
+ public int numberOfReceivers()
+ {
+ synchronized(receivers)
+ {
+ return receivers.size();
+ }
+ }
// Public --------------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/local/PagingFilteredQueue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/local/PagingFilteredQueue.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/local/PagingFilteredQueue.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -28,6 +28,7 @@
import org.jboss.messaging.core.MessageReference;
import org.jboss.messaging.core.PagingChannelSupport;
import org.jboss.messaging.core.Queue;
+import org.jboss.messaging.core.SimpleDelivery;
import org.jboss.messaging.core.plugin.contract.MessageStore;
import org.jboss.messaging.core.plugin.contract.PersistenceManager;
import org.jboss.messaging.core.tx.Transaction;
@@ -65,9 +66,9 @@
// Attributes ----------------------------------------------------
- private String name;
+ protected String name;
- private Filter filter;
+ protected Filter filter;
// Constructors --------------------------------------------------
@@ -102,13 +103,15 @@
public Delivery handle(DeliveryObserver sender, MessageReference ref, Transaction tx)
{
- if (filter.accept(ref))
+ if (filter == null || filter.accept(ref))
{
return super.handle(sender, ref, tx);
}
else
{
- return null;
+ Delivery del = new SimpleDelivery(this, ref, true, false);
+
+ return del;
}
}
Modified: trunk/src/main/org/jboss/messaging/core/local/RoundRobinPointToPointRouter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/local/RoundRobinPointToPointRouter.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/local/RoundRobinPointToPointRouter.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -86,6 +86,9 @@
// try to release the lock as quickly as possible and make a copy of the receivers array
// to avoid deadlock (http://jira.jboss.org/jira/browse/JBMESSAGING-491)
+
+ //FIXME - we shouldn't be cloning an ArrayList for the delivery of each message
+ //on the primary execution path!
receiversCopy = new ArrayList(receivers.size());
receiversCopy.addAll(receivers);
@@ -198,6 +201,14 @@
return receivers.iterator();
}
}
+
+ public int numberOfReceivers()
+ {
+ synchronized(receivers)
+ {
+ return receivers.size();
+ }
+ }
// Public --------------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/plugin/ClusteredPostOfficeService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/ClusteredPostOfficeService.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/ClusteredPostOfficeService.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -32,11 +32,11 @@
import org.jboss.messaging.core.plugin.contract.MessageStore;
import org.jboss.messaging.core.plugin.contract.MessagingComponent;
import org.jboss.messaging.core.plugin.contract.PersistenceManager;
-import org.jboss.messaging.core.plugin.postoffice.cluster.DefaultRedistributionPolicy;
+import org.jboss.messaging.core.plugin.postoffice.cluster.ClusterRouterFactory;
import org.jboss.messaging.core.plugin.postoffice.cluster.ClusteredPostOfficeImpl;
import org.jboss.messaging.core.plugin.postoffice.cluster.FavourLocalRouterFactory;
import org.jboss.messaging.core.plugin.postoffice.cluster.RedistributionPolicy;
-import org.jboss.messaging.core.plugin.postoffice.cluster.ClusterRouterFactory;
+import org.jboss.messaging.core.plugin.postoffice.cluster.StandardRedistributionPolicy;
import org.jboss.messaging.core.tx.TransactionRepository;
import org.w3c.dom.Element;
@@ -205,7 +205,7 @@
String nodeId = serverPeer.getServerPeerID();
- RedistributionPolicy redistPolicy = new DefaultRedistributionPolicy(nodeId);
+ RedistributionPolicy redistPolicy = new StandardRedistributionPolicy(nodeId);
FilterFactory ff = new SelectorFactory();
Modified: trunk/src/main/org/jboss/messaging/core/plugin/SimplePostOfficeService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/SimplePostOfficeService.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/SimplePostOfficeService.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -32,7 +32,7 @@
import org.jboss.messaging.core.plugin.contract.MessageStore;
import org.jboss.messaging.core.plugin.contract.MessagingComponent;
import org.jboss.messaging.core.plugin.contract.PersistenceManager;
-import org.jboss.messaging.core.plugin.postoffice.PostOfficeImpl;
+import org.jboss.messaging.core.plugin.postoffice.DefaultPostOffice;
import org.jboss.messaging.core.tx.TransactionRepository;
/**
@@ -48,7 +48,7 @@
*/
public class SimplePostOfficeService extends JDBCServiceSupport
{
- private PostOfficeImpl postOffice;
+ private DefaultPostOffice postOffice;
private ObjectName serverPeerObjectName;
@@ -130,7 +130,7 @@
FilterFactory ff = new SelectorFactory();
- postOffice = new PostOfficeImpl(ds, tm, sqlProperties,
+ postOffice = new DefaultPostOffice(ds, tm, sqlProperties,
createTablesOnStartup,
nodeId, officeName, ms, pm, tr, ff, pool);
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/BindingImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/BindingImpl.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/BindingImpl.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -68,4 +68,5 @@
{
return queue;
}
+
}
Copied: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/DefaultPostOffice.java (from rev 1298, trunk/src/main/org/jboss/messaging/core/plugin/postoffice/PostOfficeImpl.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/PostOfficeImpl.java 2006-09-17 17:58:08 UTC (rev 1298)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/DefaultPostOffice.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -0,0 +1,647 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.plugin.postoffice;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Types;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+
+import org.jboss.jms.server.QueuedExecutorPool;
+import org.jboss.logging.Logger;
+import org.jboss.messaging.core.Delivery;
+import org.jboss.messaging.core.Filter;
+import org.jboss.messaging.core.FilterFactory;
+import org.jboss.messaging.core.MessageReference;
+import org.jboss.messaging.core.Queue;
+import org.jboss.messaging.core.plugin.JDBCSupport;
+import org.jboss.messaging.core.plugin.contract.MessageStore;
+import org.jboss.messaging.core.plugin.contract.PersistenceManager;
+import org.jboss.messaging.core.plugin.contract.PostOffice;
+import org.jboss.messaging.core.plugin.postoffice.cluster.LocalClusteredQueue;
+import org.jboss.messaging.core.tx.Transaction;
+import org.jboss.messaging.core.tx.TransactionRepository;
+
+import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
+import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
+import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
+
+/**
+ *
+ * A DefaultPostOffice
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public class DefaultPostOffice extends JDBCSupport implements PostOffice
+{
+ private static final Logger log = Logger.getLogger(DefaultPostOffice.class);
+
+ private String officeName;
+
+ protected ReadWriteLock lock;
+
+ protected MessageStore ms;
+
+ protected PersistenceManager pm;
+
+ protected TransactionRepository tr;
+
+ protected String nodeId;
+
+ //Map <node id, Map < queue name, binding > >
+ protected Map nameMaps;
+
+ //Map <condition, List <binding> >
+ protected Map conditionMap;
+
+ protected FilterFactory filterFactory;
+
+ protected QueuedExecutorPool pool;
+
+ public DefaultPostOffice()
+ {
+ }
+
+ public DefaultPostOffice(DataSource ds, TransactionManager tm, Properties sqlProperties,
+ boolean createTablesOnStartup,
+ String nodeId, String officeName, MessageStore ms,
+ PersistenceManager pm,
+ TransactionRepository tr, FilterFactory filterFactory,
+ QueuedExecutorPool pool)
+ {
+ super (ds, tm, sqlProperties, createTablesOnStartup);
+
+ lock = new WriterPreferenceReadWriteLock();
+
+ nameMaps = new LinkedHashMap();
+
+ conditionMap = new LinkedHashMap();
+
+ this.nodeId = nodeId;
+
+ this.officeName = officeName;
+
+ this.ms = ms;
+
+ this.pm = pm;
+
+ this.tr = tr;
+
+ this.filterFactory = filterFactory;
+
+ this.pool = pool;
+ }
+
+ // MessagingComponent implementation --------------------------------
+
+ public void start() throws Exception
+ {
+ super.start();
+
+ loadBindings();
+ }
+
+ public void stop() throws Exception
+ {
+ super.stop();
+ }
+
+ // PostOffice implementation ---------------------------------------
+
+ public Binding bindQueue(String condition, Queue queue) throws Exception
+ {
+ if (queue.getName() == null)
+ {
+ throw new IllegalArgumentException("Queue name is null");
+ }
+
+ if (condition == null)
+ {
+ throw new IllegalArgumentException("Condition is null");
+ }
+
+ lock.writeLock().acquire();
+
+ try
+ {
+ //We currently only allow one binding per name per node
+ Map nameMap = (Map)nameMaps.get(this.nodeId);
+
+ Binding binding = null;
+
+ if (nameMap != null)
+ {
+ binding = (Binding)nameMap.get(queue.getName());
+ }
+
+ if (binding != null)
+ {
+ throw new IllegalArgumentException("Binding already exists for name " + queue.getName());
+ }
+
+ binding = new BindingImpl(this.nodeId, condition, queue);
+
+ addBinding(binding);
+
+ if (queue.isRecoverable())
+ {
+ //Need to write the binding to the db
+ insertBinding(binding);
+ }
+
+ return binding;
+ }
+ finally
+ {
+ lock.writeLock().release();
+ }
+ }
+
+ public Binding unbindQueue(String queueName) throws Throwable
+ {
+ if (queueName == null)
+ {
+ throw new IllegalArgumentException("Queue name is null");
+ }
+
+ lock.writeLock().acquire();
+
+ try
+ {
+ Binding binding = removeBinding(this.nodeId, queueName);
+
+ if (binding.getQueue().isRecoverable())
+ {
+ //Need to remove from db too
+
+ deleteBinding(binding.getQueue().getName());
+ }
+
+ binding.getQueue().removeAllReferences();
+
+ return binding;
+ }
+ finally
+ {
+ lock.writeLock().release();
+ }
+ }
+
+ public Collection listBindingsForCondition(String condition) throws Exception
+ {
+ if (condition == null)
+ {
+ throw new IllegalArgumentException("Condition is null");
+ }
+
+ lock.readLock().acquire();
+
+ try
+ {
+ Bindings cb = (Bindings)conditionMap.get(condition);
+
+ if (cb == null)
+ {
+ return Collections.EMPTY_LIST;
+ }
+ else
+ {
+ return cb.getAllBindings();
+ }
+ }
+ finally
+ {
+ lock.readLock().release();
+ }
+ }
+
+ public Binding getBindingForQueueName(String queueName) throws Exception
+ {
+ if (queueName == null)
+ {
+ throw new IllegalArgumentException("Queue name is null");
+ }
+
+ lock.readLock().acquire();
+
+ try
+ {
+ Map nameMap = (Map)nameMaps.get(this.nodeId);
+
+ Binding binding = null;
+
+ if (nameMap != null)
+ {
+ binding = (Binding)nameMap.get(queueName);
+ }
+
+ return binding;
+ }
+ finally
+ {
+ lock.readLock().release();
+ }
+ }
+
+ public void recover() throws Exception
+ {
+ //NOOP
+ }
+
+ public boolean route(MessageReference ref, String condition, Transaction tx) throws Exception
+ {
+ if (ref == null)
+ {
+ throw new IllegalArgumentException("Message reference is null");
+ }
+
+ if (condition == null)
+ {
+ throw new IllegalArgumentException("Condition key is null");
+ }
+
+ boolean routed = false;
+
+ lock.readLock().acquire();
+
+ try
+ {
+ Bindings bd = (Bindings)conditionMap.get(condition);
+
+ if (bd != null)
+ {
+ boolean startInternalTx = false;
+
+ if (tx == null && ref.isReliable())
+ {
+ if (bd.getDurableCount() > 1)
+ {
+ // When routing a persistent message without a transaction then we may need to start an
+ // internal transaction in order to route it.
+ // This is so we can guarantee the message is delivered to all or none of the subscriptions.
+ // We need to do this if there is more than one durable sub
+ startInternalTx = true;
+ }
+ }
+
+ if (startInternalTx)
+ {
+ tx = tr.createTransaction();
+ }
+
+ Collection bindings = bd.getAllBindings();
+
+ Iterator iter = bindings.iterator();
+
+ while (iter.hasNext())
+ {
+ Binding binding = (Binding)iter.next();
+
+ //Sanity check
+ if (!binding.getNodeId().equals(this.nodeId))
+ {
+ throw new IllegalStateException("Local post office has foreign bindings!");
+ }
+
+ Queue queue = binding.getQueue();
+
+ Delivery del = queue.handle(null, ref, tx);
+
+ if (del != null && del.isSelectorAccepted())
+ {
+ routed = true;
+ }
+ }
+
+ if (startInternalTx)
+ {
+ //TODO - do we need to rollback if an exception is thrown??
+ tx.commit();
+ }
+ }
+
+ return routed;
+ }
+ finally
+ {
+ lock.readLock().release();
+ }
+ }
+
+ public boolean isLocal()
+ {
+ return true;
+ }
+
+ // Protected -----------------------------------------------------
+
+ protected void loadBindings() throws Exception
+ {
+ lock.writeLock().acquire();
+
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ TransactionWrapper wrap = new TransactionWrapper();
+
+ try
+ {
+ conn = ds.getConnection();
+
+ ps = conn.prepareStatement(getSQLStatement("LOAD_BINDINGS"));
+
+ ps.setString(1, this.officeName);
+
+ rs = ps.executeQuery();
+
+ while (rs.next())
+ {
+ String nodeId = rs.getString(1);
+
+ String queueName = rs.getString(2);
+
+ String condition = rs.getString(3);
+
+ String selector = rs.getString(4);
+
+ if (rs.wasNull())
+ {
+ selector = null;
+ }
+
+ long channelId = rs.getLong(5);
+
+ Binding binding = this.createBinding(nodeId, condition, queueName, channelId, selector, true);
+ binding.getQueue().deactivate();
+
+ addBinding(binding);
+ }
+ }
+ finally
+ {
+ lock.writeLock().release();
+
+ if (rs != null)
+ {
+ rs.close();
+ }
+ if (ps != null)
+ {
+ ps.close();
+ }
+ if (conn != null)
+ {
+ conn.close();
+ }
+ wrap.end();
+ }
+ }
+
+ protected Binding createBinding(String nodeId, String condition, String queueName, long channelId, String filterString, boolean durable) throws Exception
+ {
+
+ Filter filter = filterFactory.createFilter(filterString);
+
+ Queue queue;
+ if (nodeId.equals(this.nodeId))
+ {
+ QueuedExecutor executor = (QueuedExecutor)pool.get();
+
+ queue = new LocalClusteredQueue(nodeId, queueName, channelId, ms, pm, true,
+ true, executor, filter);
+ }
+ else
+ {
+ throw new IllegalStateException("This is a non clustered post office - should not have bindings from different nodes!");
+ }
+
+ Binding binding = new BindingImpl(nodeId, condition, queue);
+
+ return binding;
+ }
+
+ protected void insertBinding(Binding binding) throws Exception
+ {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ TransactionWrapper wrap = new TransactionWrapper();
+
+ try
+ {
+ conn = ds.getConnection();
+
+ ps = conn.prepareStatement(getSQLStatement("INSERT_BINDING"));
+
+ String filterString = binding.getQueue().getFilter() == null ? null : binding.getQueue().getFilter().getFilterString();
+
+ ps.setString(1, this.officeName);
+ ps.setString(2, this.nodeId);
+ ps.setString(3, binding.getQueue().getName());
+ ps.setString(4, binding.getCondition());
+ if (filterString != null)
+ {
+ ps.setString(5, filterString);
+ }
+ else
+ {
+ ps.setNull(5, Types.VARCHAR);
+ }
+ ps.setLong(6, binding.getQueue().getChannelID());
+
+ ps.executeUpdate();
+ }
+ finally
+ {
+ if (ps != null)
+ {
+ ps.close();
+ }
+ if (conn != null)
+ {
+ conn.close();
+ }
+ wrap.end();
+ }
+ }
+
+ protected boolean deleteBinding(String queueName) throws Exception
+ {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ TransactionWrapper wrap = new TransactionWrapper();
+
+ try
+ {
+ conn = ds.getConnection();
+
+ ps = conn.prepareStatement(getSQLStatement("DELETE_BINDING"));
+
+ ps.setString(1, this.officeName);
+ ps.setString(2, this.nodeId);
+ ps.setString(3, queueName);
+
+ int rows = ps.executeUpdate();
+
+ return rows == 1;
+ }
+ finally
+ {
+ if (ps != null)
+ {
+ ps.close();
+ }
+ if (conn != null)
+ {
+ conn.close();
+ }
+ wrap.end();
+ }
+ }
+
+ protected void addBinding(Binding binding)
+ {
+ Map nameMap = (Map)nameMaps.get(binding.getNodeId());
+
+ if (nameMap == null)
+ {
+ nameMap = new LinkedHashMap();
+
+ nameMaps.put(binding.getNodeId(), nameMap);
+ }
+
+ nameMap.put(binding.getQueue().getName(), binding);
+
+ String condition = binding.getCondition();
+
+ Bindings bindings = (Bindings)conditionMap.get(condition);
+
+ if (bindings == null)
+ {
+ bindings = createBindings();
+
+ conditionMap.put(condition, bindings);
+ }
+
+ bindings.addBinding(binding);
+ }
+
+ protected Binding removeBinding(String nodeId, String queueName)
+ {
+ if (queueName == null)
+ {
+ throw new IllegalArgumentException("Queue name is null");
+ }
+
+ Map nameMap = (Map)nameMaps.get(nodeId);
+
+ if (nameMap == null)
+ {
+ throw new IllegalArgumentException("Cannot find any bindings for node Id: " + nodeId);
+ }
+
+ Binding binding = null;
+
+ if (nameMap != null)
+ {
+ binding = (Binding)nameMap.remove(queueName);
+ }
+
+ if (binding == null)
+ {
+ throw new IllegalArgumentException("Name map does not contain binding for " + queueName);
+ }
+
+ if (nameMap.isEmpty())
+ {
+ nameMaps.remove(nodeId);
+ }
+
+ Bindings bindings = (Bindings)conditionMap.get(binding.getCondition());
+
+ if (bindings == null)
+ {
+ throw new IllegalStateException("Cannot find condition bindings for " + binding.getCondition());
+ }
+
+ boolean removed = bindings.removeBinding(binding);
+
+ if (!removed)
+ {
+ throw new IllegalStateException("Cannot find binding in condition binding list");
+ }
+
+ if (bindings.isEmpty())
+ {
+ conditionMap.remove(binding.getCondition());
+ }
+
+ return binding;
+ }
+
+ protected Bindings createBindings()
+ {
+ return new BindingsImpl();
+ }
+
+ protected Map getDefaultDMLStatements()
+ {
+ Map map = new HashMap();
+ map.put("INSERT_BINDING",
+ "INSERT INTO JMS_POSTOFFICE (POSTOFFICE_NAME, NODE_ID, QUEUE_NAME, CONDITION, SELECTOR, CHANNEL_ID) " +
+ "VALUES (?, ?, ?, ?, ?, ?)");
+ map.put("DELETE_BINDING",
+ "DELETE FROM JMS_POSTOFFICE WHERE POSTOFFICE_NAME=? AND NODE_ID=? AND QUEUE_NAME=?");
+ map.put("LOAD_BINDINGS",
+ "SELECT NODE_ID, QUEUE_NAME, CONDITION, SELECTOR, CHANNEL_ID FROM JMS_POSTOFFICE " +
+ "WHERE POSTOFFICE_NAME = ?");
+ return map;
+ }
+
+ protected Map getDefaultDDLStatements()
+ {
+ Map map = new HashMap();
+ map.put("CREATE_POSTOFFICE_TABLE",
+ "CREATE TABLE JMS_POSTOFFICE (POSTOFFICE_NAME VARCHAR(256), NODE_ID VARCHAR(256)," +
+ "QUEUE_NAME VARCHAR(1024), CONDITION VARCHAR(1024), " +
+ "SELECTOR VARCHAR(1024), CHANNEL_ID BIGINT)");
+ return map;
+ }
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Deleted: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/PostOfficeImpl.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/PostOfficeImpl.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -1,646 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.plugin.postoffice;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Types;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-
-import org.jboss.jms.server.QueuedExecutorPool;
-import org.jboss.logging.Logger;
-import org.jboss.messaging.core.Delivery;
-import org.jboss.messaging.core.Filter;
-import org.jboss.messaging.core.FilterFactory;
-import org.jboss.messaging.core.MessageReference;
-import org.jboss.messaging.core.Queue;
-import org.jboss.messaging.core.plugin.JDBCSupport;
-import org.jboss.messaging.core.plugin.contract.MessageStore;
-import org.jboss.messaging.core.plugin.contract.PersistenceManager;
-import org.jboss.messaging.core.plugin.contract.PostOffice;
-import org.jboss.messaging.core.plugin.postoffice.cluster.LocalClusteredQueue;
-import org.jboss.messaging.core.tx.Transaction;
-import org.jboss.messaging.core.tx.TransactionRepository;
-
-import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
-import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
-import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
-
-/**
- *
- * A PostOfficeImpl
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class PostOfficeImpl extends JDBCSupport implements PostOffice
-{
- private static final Logger log = Logger.getLogger(PostOfficeImpl.class);
-
- private String officeName;
-
- protected ReadWriteLock lock;
-
- protected MessageStore ms;
-
- protected PersistenceManager pm;
-
- protected TransactionRepository tr;
-
- protected String nodeId;
-
- //Map <node id, Map < queue name, binding > >
- protected Map nameMaps;
-
- //Map <condition, List <binding> >
- protected Map conditionMap;
-
- protected FilterFactory filterFactory;
-
- protected QueuedExecutorPool pool;
-
- public PostOfficeImpl()
- {
- }
-
- public PostOfficeImpl(DataSource ds, TransactionManager tm, Properties sqlProperties,
- boolean createTablesOnStartup,
- String nodeId, String officeName, MessageStore ms,
- PersistenceManager pm,
- TransactionRepository tr, FilterFactory filterFactory,
- QueuedExecutorPool pool)
- {
- super (ds, tm, sqlProperties, createTablesOnStartup);
-
- lock = new WriterPreferenceReadWriteLock();
-
- nameMaps = new LinkedHashMap();
-
- conditionMap = new LinkedHashMap();
-
- this.nodeId = nodeId;
-
- this.officeName = officeName;
-
- this.ms = ms;
-
- this.pm = pm;
-
- this.tr = tr;
-
- this.filterFactory = filterFactory;
-
- this.pool = pool;
- }
-
- // MessagingComponent implementation --------------------------------
-
- public void start() throws Exception
- {
- super.start();
-
- loadBindings();
- }
-
- public void stop() throws Exception
- {
- super.stop();
- }
-
- // PostOffice implementation ---------------------------------------
-
- public Binding bindQueue(String condition, Queue queue) throws Exception
- {
- if (queue.getName() == null)
- {
- throw new IllegalArgumentException("Queue name is null");
- }
-
- if (condition == null)
- {
- throw new IllegalArgumentException("Condition is null");
- }
-
- lock.writeLock().acquire();
-
- try
- {
- //We currently only allow one binding per name per node
- Map nameMap = (Map)nameMaps.get(this.nodeId);
-
- Binding binding = null;
-
- if (nameMap != null)
- {
- binding = (Binding)nameMap.get(queue.getName());
- }
-
- if (binding != null)
- {
- throw new IllegalArgumentException("Binding already exists for name " + queue.getName());
- }
-
- binding = new BindingImpl(this.nodeId, condition, queue);
-
- addBinding(binding);
-
- if (queue.isRecoverable())
- {
- //Need to write the binding to the db
- insertBinding(binding);
- }
-
- return binding;
- }
- finally
- {
- lock.writeLock().release();
- }
- }
-
- public Binding unbindQueue(String queueName) throws Throwable
- {
- if (queueName == null)
- {
- throw new IllegalArgumentException("Queue name is null");
- }
-
- lock.writeLock().acquire();
-
- try
- {
- Binding binding = removeBinding(this.nodeId, queueName);
-
- if (binding.getQueue().isRecoverable())
- {
- //Need to remove from db too
-
- deleteBinding(binding.getQueue().getName());
- }
-
- binding.getQueue().removeAllReferences();
-
- return binding;
- }
- finally
- {
- lock.writeLock().release();
- }
- }
-
- public Collection listBindingsForCondition(String condition) throws Exception
- {
- if (condition == null)
- {
- throw new IllegalArgumentException("Condition is null");
- }
-
- lock.readLock().acquire();
-
- try
- {
- Bindings cb = (Bindings)conditionMap.get(condition);
-
- if (cb == null)
- {
- return Collections.EMPTY_LIST;
- }
- else
- {
- return cb.getAllBindings();
- }
- }
- finally
- {
- lock.readLock().release();
- }
- }
-
- public Binding getBindingForQueueName(String queueName) throws Exception
- {
- if (queueName == null)
- {
- throw new IllegalArgumentException("Queue name is null");
- }
-
- lock.readLock().acquire();
-
- try
- {
- Map nameMap = (Map)nameMaps.get(this.nodeId);
-
- Binding binding = null;
-
- if (nameMap != null)
- {
- binding = (Binding)nameMap.get(queueName);
- }
-
- return binding;
- }
- finally
- {
- lock.readLock().release();
- }
- }
-
- public void recover() throws Exception
- {
- //NOOP
- }
-
- public boolean route(MessageReference ref, String condition, Transaction tx) throws Exception
- {
- if (ref == null)
- {
- throw new IllegalArgumentException("Message reference is null");
- }
-
- if (condition == null)
- {
- throw new IllegalArgumentException("Condition key is null");
- }
-
- boolean routed = false;
-
- lock.readLock().acquire();
-
- try
- {
- Bindings bd = (Bindings)conditionMap.get(condition);
-
- if (bd != null)
- {
- boolean startInternalTx = false;
-
- if (tx == null && ref.isReliable())
- {
- if (bd.getDurableCount() > 1)
- {
- // When routing a persistent message without a transaction then we may need to start an
- // internal transaction in order to route it.
- // This is so we can guarantee the message is delivered to all or none of the subscriptions.
- // We need to do this if there is more than one durable sub
- startInternalTx = true;
- }
- }
-
- if (startInternalTx)
- {
- tx = tr.createTransaction();
- }
-
- Collection bindings = bd.getAllBindings();
-
- Iterator iter = bindings.iterator();
-
- while (iter.hasNext())
- {
- Binding binding = (Binding)iter.next();
-
- //Sanity check
- if (!binding.getNodeId().equals(this.nodeId))
- {
- throw new IllegalStateException("Local post office has foreign bindings!");
- }
-
- Queue queue = binding.getQueue();
-
- Delivery del = queue.handle(null, ref, tx);
-
- if (del != null && del.isSelectorAccepted())
- {
- routed = true;
- }
- }
-
- if (startInternalTx)
- {
- //TODO - do we need to rollback if an exception is thrown??
- tx.commit();
- }
- }
-
- return routed;
- }
- finally
- {
- lock.readLock().release();
- }
- }
-
- public boolean isLocal()
- {
- return true;
- }
-
- // Protected -----------------------------------------------------
-
- protected void loadBindings() throws Exception
- {
- lock.writeLock().acquire();
-
- Connection conn = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- TransactionWrapper wrap = new TransactionWrapper();
-
- try
- {
- conn = ds.getConnection();
-
- ps = conn.prepareStatement(getSQLStatement("LOAD_BINDINGS"));
-
- ps.setString(1, this.officeName);
-
- rs = ps.executeQuery();
-
- while (rs.next())
- {
- String nodeId = rs.getString(1);
-
- String queueName = rs.getString(2);
-
- String condition = rs.getString(3);
-
- String selector = rs.getString(4);
-
- if (rs.wasNull())
- {
- selector = null;
- }
-
- long channelId = rs.getLong(5);
-
- Binding binding = this.createBinding(nodeId, condition, queueName, channelId, selector, true);
-
- addBinding(binding);
- }
- }
- finally
- {
- lock.writeLock().release();
-
- if (rs != null)
- {
- rs.close();
- }
- if (ps != null)
- {
- ps.close();
- }
- if (conn != null)
- {
- conn.close();
- }
- wrap.end();
- }
- }
-
- protected Binding createBinding(String nodeId, String condition, String queueName, long channelId, String filterString, boolean durable) throws Exception
- {
-
- Filter filter = filterFactory.createFilter(filterString);
-
- Queue queue;
- if (nodeId.equals(this.nodeId))
- {
- QueuedExecutor executor = (QueuedExecutor)pool.get();
-
- queue = new LocalClusteredQueue(nodeId, queueName, channelId, ms, pm, true,
- true, executor, filter);
- }
- else
- {
- throw new IllegalStateException("This is a non clustered post office - should not have bindings from different nodes!");
- }
-
- Binding binding = new BindingImpl(nodeId, condition, queue);
-
- return binding;
- }
-
- protected void insertBinding(Binding binding) throws Exception
- {
- Connection conn = null;
- PreparedStatement ps = null;
- TransactionWrapper wrap = new TransactionWrapper();
-
- try
- {
- conn = ds.getConnection();
-
- ps = conn.prepareStatement(getSQLStatement("INSERT_BINDING"));
-
- String filterString = binding.getQueue().getFilter() == null ? null : binding.getQueue().getFilter().getFilterString();
-
- ps.setString(1, this.officeName);
- ps.setString(2, this.nodeId);
- ps.setString(3, binding.getQueue().getName());
- ps.setString(4, binding.getCondition());
- if (filterString != null)
- {
- ps.setString(5, filterString);
- }
- else
- {
- ps.setNull(5, Types.VARCHAR);
- }
- ps.setLong(6, binding.getQueue().getChannelID());
-
- ps.executeUpdate();
- }
- finally
- {
- if (ps != null)
- {
- ps.close();
- }
- if (conn != null)
- {
- conn.close();
- }
- wrap.end();
- }
- }
-
- protected boolean deleteBinding(String queueName) throws Exception
- {
- Connection conn = null;
- PreparedStatement ps = null;
- TransactionWrapper wrap = new TransactionWrapper();
-
- try
- {
- conn = ds.getConnection();
-
- ps = conn.prepareStatement(getSQLStatement("DELETE_BINDING"));
-
- ps.setString(1, this.officeName);
- ps.setString(2, this.nodeId);
- ps.setString(3, queueName);
-
- int rows = ps.executeUpdate();
-
- return rows == 1;
- }
- finally
- {
- if (ps != null)
- {
- ps.close();
- }
- if (conn != null)
- {
- conn.close();
- }
- wrap.end();
- }
- }
-
- protected void addBinding(Binding binding)
- {
- Map nameMap = (Map)nameMaps.get(binding.getNodeId());
-
- if (nameMap == null)
- {
- nameMap = new LinkedHashMap();
-
- nameMaps.put(binding.getNodeId(), nameMap);
- }
-
- nameMap.put(binding.getQueue().getName(), binding);
-
- String condition = binding.getCondition();
-
- Bindings bindings = (Bindings)conditionMap.get(condition);
-
- if (bindings == null)
- {
- bindings = createBindings();
-
- conditionMap.put(condition, bindings);
- }
-
- bindings.addBinding(binding);
- }
-
- protected Binding removeBinding(String nodeId, String queueName)
- {
- if (queueName == null)
- {
- throw new IllegalArgumentException("Queue name is null");
- }
-
- Map nameMap = (Map)nameMaps.get(nodeId);
-
- if (nameMap == null)
- {
- throw new IllegalArgumentException("Cannot find any bindings for node Id: " + nodeId);
- }
-
- Binding binding = null;
-
- if (nameMap != null)
- {
- binding = (Binding)nameMap.remove(queueName);
- }
-
- if (binding == null)
- {
- throw new IllegalArgumentException("Name map does not contain binding for " + queueName);
- }
-
- if (nameMap.isEmpty())
- {
- nameMaps.remove(nodeId);
- }
-
- Bindings bindings = (Bindings)conditionMap.get(binding.getCondition());
-
- if (bindings == null)
- {
- throw new IllegalStateException("Cannot find condition bindings for " + binding.getCondition());
- }
-
- boolean removed = bindings.removeBinding(binding);
-
- if (!removed)
- {
- throw new IllegalStateException("Cannot find binding in condition binding list");
- }
-
- if (bindings.isEmpty())
- {
- conditionMap.remove(binding.getCondition());
- }
-
- return binding;
- }
-
- protected Bindings createBindings()
- {
- return new BindingsImpl();
- }
-
- protected Map getDefaultDMLStatements()
- {
- Map map = new HashMap();
- map.put("INSERT_BINDING",
- "INSERT INTO JMS_POSTOFFICE (POSTOFFICE_NAME, NODE_ID, QUEUE_NAME, CONDITION, SELECTOR, CHANNEL_ID) " +
- "VALUES (?, ?, ?, ?, ?, ?)");
- map.put("DELETE_BINDING",
- "DELETE FROM JMS_POSTOFFICE WHERE POSTOFFICE_NAME=? AND NODE_ID=? AND QUEUE_NAME=?");
- map.put("LOAD_BINDINGS",
- "SELECT NODE_ID, QUEUE_NAME, CONDITION, SELECTOR, CHANNEL_ID FROM JMS_POSTOFFICE " +
- "WHERE POSTOFFICE_NAME = ?");
- return map;
- }
-
- protected Map getDefaultDDLStatements()
- {
- Map map = new HashMap();
- map.put("CREATE_POSTOFFICE_TABLE",
- "CREATE TABLE JMS_POSTOFFICE (POSTOFFICE_NAME VARCHAR(256), NODE_ID VARCHAR(256)," +
- "QUEUE_NAME VARCHAR(1024), CONDITION VARCHAR(1024), " +
- "SELECTOR VARCHAR(1024), CHANNEL_ID BIGINT)");
- return map;
- }
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Deleted: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/BasicRedistributionPolicy.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/BasicRedistributionPolicy.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/BasicRedistributionPolicy.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -1,119 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.plugin.postoffice.cluster;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.jboss.messaging.core.plugin.postoffice.Binding;
-
-/**
- * A BasicRedistributonPolicy
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class BasicRedistributionPolicy implements RedistributionPolicy
-{
- private String localNodeId;
-
- private int MAX_MESSAGES_TO_MOVE = 100;
-
- public BasicRedistributionPolicy(String localNodeId)
- {
- this.localNodeId = localNodeId;
- }
-
- public RedistributionOrder calculate(List bindings)
- {
- Iterator iter = bindings.iterator();
-
- Binding localBinding = null;
-
- while (iter.hasNext())
- {
- Binding binding = (Binding)iter.next();
-
- if (binding.getNodeId().equals(localNodeId))
- {
- localBinding = binding;
-
- break;
- }
- }
-
- if (localBinding == null)
- {
- return null;
- }
-
- ClusteredQueue queue = (ClusteredQueue)localBinding.getQueue();
-
- if (queue.getGrowthRate() == 0 && queue.getMessageCount() > 0)
- {
- //No consumers on the queue - the messages are stranded
- //We should consider moving them somewhere else
-
- //We move messages to the node with the highest consumption rate
-
- iter = bindings.iterator();
-
- double maxRate = 0;
-
- Binding maxRateBinding = null;
-
- while (iter.hasNext())
- {
- Binding binding = (Binding)iter.next();
-
- ClusteredQueue theQueue = (ClusteredQueue)binding.getQueue();
-
- if (!binding.getNodeId().equals(localNodeId))
- {
- double rate = theQueue.getGrowthRate();
-
- if (rate > maxRate)
- {
- maxRate = rate;
-
- maxRateBinding = binding;
- }
- }
- }
-
- if (maxRate > 0)
- {
- //Move messages to this node
-
- //How many should we move?
- int numberToMove = Math.min(MAX_MESSAGES_TO_MOVE, queue.getMessageCount());
-
- return new RedistributionOrder(numberToMove, queue, maxRateBinding.getNodeId());
- }
- }
-
- return null;
- }
-}
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/CastMessagesCallback.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/CastMessagesCallback.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/CastMessagesCallback.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -73,8 +73,30 @@
private PostOfficeInternal office;
- void addMessage(String routingKey, Message message, Map queueNameToNodeIdMap)
+ private boolean multicast;
+
+ private String toNodeId;
+
+ void addMessage(String routingKey, Message message, Map queueNameToNodeIdMap, String lastNodeId)
{
+ //If we only ever send messages to the same node for this tx, then we can unicast rather than multicast
+ //This is how we determine that
+ if (lastNodeId == null)
+ {
+ multicast = true;
+ }
+ else
+ {
+ if (!lastNodeId.equals(toNodeId))
+ {
+ multicast = true;
+ }
+ else
+ {
+ toNodeId = lastNodeId;
+ }
+ }
+
MessageHolder holder = new MessageHolder(routingKey, message, queueNameToNodeIdMap);
if (message.isReliable())
@@ -111,7 +133,7 @@
// Cast the non persistent - this don't need to go into a holding area on the receiving node
ClusterRequest req = new MessagesRequest(nonPersistent);
- office.asyncSendRequest(req);
+ sendRequest(req);
}
if (persistent != null)
@@ -119,13 +141,12 @@
// Cast a commit message
ClusterRequest req = new SendTransactionRequest(nodeId, txId);
- // Stack must be FIFO
- office.asyncSendRequest(req);
+ sendRequest(req);
}
nonPersistent = persistent = null;
}
-
+
public void afterPrepare() throws Exception
{
}
@@ -142,8 +163,7 @@
//the receiving nodes
ClusterRequest req = new SendTransactionRequest(nodeId, txId, persistent);
- //Stack must be FIFO
- office.asyncSendRequest(req);
+ sendRequest(req);
}
}
@@ -154,5 +174,19 @@
public void beforeRollback(boolean onePhase) throws Exception
{
}
+
+ private void sendRequest(ClusterRequest req) throws Exception
+ {
+ if (multicast)
+ {
+ office.asyncSendRequest(req);
+ }
+ else
+ {
+ //FIXME temp commented out until unicast works
+ //office.asyncSendRequest(req, toNodeId);
+ office.asyncSendRequest(req);
+ }
+ }
}
Deleted: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusterRouter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusterRouter.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusterRouter.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.plugin.postoffice.cluster;
-
-import org.jboss.messaging.core.Router;
-
-/**
- * A ClusterRouter
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public interface ClusterRouter extends Router
-{
- int size();
-}
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusterRouterFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusterRouterFactory.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusterRouterFactory.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -21,7 +21,9 @@
*/
package org.jboss.messaging.core.plugin.postoffice.cluster;
+import org.jboss.messaging.core.Router;
+
/**
* A RouterFactory
*
@@ -33,5 +35,5 @@
*/
public interface ClusterRouterFactory
{
- ClusterRouter createRouter();
+ Router createRouter();
}
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredBindingsImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredBindingsImpl.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredBindingsImpl.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.jboss.messaging.core.Router;
import org.jboss.messaging.core.plugin.postoffice.Binding;
import org.jboss.messaging.core.plugin.postoffice.BindingsImpl;
@@ -65,7 +66,7 @@
{
super.addBinding(binding);
- ClusterRouter router = (ClusterRouter)nameMap.get(binding.getQueue().getName());
+ Router router = (Router)nameMap.get(binding.getQueue().getName());
if (router == null)
{
@@ -91,7 +92,7 @@
return false;
}
- ClusterRouter router = (ClusterRouter)nameMap.get(binding.getQueue().getName());
+ Router router = (Router)nameMap.get(binding.getQueue().getName());
if (router == null)
{
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeImpl.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeImpl.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -50,7 +50,7 @@
import org.jboss.messaging.core.plugin.postoffice.Binding;
import org.jboss.messaging.core.plugin.postoffice.BindingImpl;
import org.jboss.messaging.core.plugin.postoffice.Bindings;
-import org.jboss.messaging.core.plugin.postoffice.PostOfficeImpl;
+import org.jboss.messaging.core.plugin.postoffice.DefaultPostOffice;
import org.jboss.messaging.core.tx.Transaction;
import org.jboss.messaging.core.tx.TransactionRepository;
import org.jboss.messaging.util.StreamUtils;
@@ -79,12 +79,10 @@
* $Id$
*
*/
-public class ClusteredPostOfficeImpl extends PostOfficeImpl implements ClusteredPostOffice, PostOfficeInternal
+public class ClusteredPostOfficeImpl extends DefaultPostOffice implements ClusteredPostOffice, PostOfficeInternal
{
private static final Logger log = Logger.getLogger(ClusteredPostOfficeImpl.class);
-
- private static final int STATS_DIFFERENCE_MARGIN_PERCENT = 10;
-
+
private Channel syncChannel;
private Channel asyncChannel;
@@ -267,6 +265,8 @@
super.start();
Address currentAddress = syncChannel.getLocalAddress();
+
+ log.info(this.nodeId + " address is " + currentAddress);
handleAddressNodeMapping(currentAddress, nodeId);
@@ -299,11 +299,9 @@
Binding binding = (Binding)super.bindQueue(condition, queue);
- boolean durable = queue.isRecoverable();
-
BindRequest request =
new BindRequest(nodeId, queue.getName(), condition, queue.getFilter() == null ? null : queue.getFilter().getFilterString(),
- binding.getQueue().getChannelID(), durable);
+ binding.getQueue().getChannelID(), queue.isRecoverable());
syncSendRequest(request);
@@ -384,7 +382,7 @@
while (iter.hasNext())
{
- ClusterRouter router = (ClusterRouter)iter.next();
+ Router router = (Router)iter.next();
Delivery del = router.handle(null, ref, tx);
@@ -392,17 +390,19 @@
{
routed = true;
}
-
+
ClusteredQueue queue = (ClusteredQueue)del.getObserver();
- if (!queue.isLocal())
+ log.info("sent " + ref.getMessageID() + " to " + queue.getName() + " on node " + queue.getNodeId() + " selector accepted " + del.isSelectorAccepted());
+
+ if (del.isSelectorAccepted() && !queue.isLocal())
{
//We need to send the message remotely
numberRemote++;
lastNodeId = queue.getNodeId();
- if (router.size() > 1 && queueNameNodeIdMap == null)
+ if (router.numberOfReceivers() > 1 && queueNameNodeIdMap == null)
{
//If there are more than one queues with the same node on the remote nodes
//We have now chosen which one will receive the message so we need to add this
@@ -421,22 +421,27 @@
//to send the message to the other office instances on the cluster if there are
//queues on those nodes that need to receive the message
+ //FIXME - there is a bug here, numberRemote does not take into account that more than one
+ //of the number remote may be on the same node, so we could end up multicasting
+ //when unicast would do
if (numberRemote > 0)
{
- //TODO - If numberRemote == 1, we could do unicast rather than multicast
- //This would avoid putting strain on nodes that don't need to receive the reference
- //This would be the case for load balancing queues where the routing policy
- //sometimes allows a remote queue to get the reference
-
+ log.info("Need to send remotely");
+
if (tx == null)
{
if (numberRemote == 1)
{
+ log.info("unicast no tx");
//Unicast - only one node is interested in the message
- asyncSendRequest(new MessageRequest(condition, ref.getMessage(), null), lastNodeId);
+
+ //FIXME - temporarily commented out until can get unicast to work
+ //asyncSendRequest(new MessageRequest(condition, ref.getMessage(), null), lastNodeId);
+ asyncSendRequest(new MessageRequest(condition, ref.getMessage(), null));
}
else
{
+ log.info("multicast no tx");
//Multicast - more than one node is interested
asyncSendRequest(new MessageRequest(condition, ref.getMessage(), queueNameNodeIdMap));
}
@@ -455,13 +460,13 @@
//Before commit:
//1. Cast messages across network - get added to holding area (if persistent) on receiving
//nodes
- //2. Persist messaage in persistent store
+ //2. Persist messages in persistent store
//After commit
//1. Cast commit message across network
tx.addFirstCallback(callback, this);
}
- callback.addMessage(condition, ref.getMessage(), queueNameNodeIdMap);
+ callback.addMessage(condition, ref.getMessage(), queueNameNodeIdMap, numberRemote == 1 ? lastNodeId : null);
}
}
@@ -614,6 +619,9 @@
public void routeFromCluster(org.jboss.messaging.core.Message message, String routingKey,
Map queueNameNodeIdMap) throws Exception
{
+ log.info(this.nodeId + " received route from cluster, ref = " + message.getMessageID() + " routing key " +
+ routingKey + " map " + queueNameNodeIdMap);
+
lock.readLock().acquire();
// Need to reference the message
@@ -624,6 +632,8 @@
// We route on the condition
ClusteredBindingsImpl cb = (ClusteredBindingsImpl)conditionMap.get(routingKey);
+
+ log.info("cb is: " + cb);
if (cb != null)
{
@@ -634,9 +644,12 @@
while (iter.hasNext())
{
Binding binding = (Binding)iter.next();
+
+ log.info("got binding: " + binding.getQueue().getName());
if (binding.getNodeId().equals(this.nodeId))
{
+ log.info("node id matches");
boolean handle = true;
if (queueNameNodeIdMap != null)
@@ -655,11 +668,16 @@
if (handle)
{
//It's a local binding so we pass the message on to the subscription
+
LocalClusteredQueue queue = (LocalClusteredQueue)binding.getQueue();
+
+ log.info("sending " + message.getMessageID() + " to queue: " + queue.getName() + " on node " + this.nodeId);
//TODO instead of adding a new method on the channel
//we should set a header and use the same method
- queue.handleFromCluster(null, ref, null);
+ Delivery del = queue.handleFromCluster(null, ref, null);
+
+ log.info("sending " + message.getMessageID() + " to queue: " + queue.getName() + " on node " + this.nodeId + " delivery is " + del + " accepted? " + del.isSelectorAccepted());
}
}
}
@@ -682,6 +700,8 @@
{
byte[] bytes = writeRequest(request);
+ log.info("async sending " + bytes);
+
asyncChannel.send(new Message(null, null, bytes));
}
@@ -692,6 +712,8 @@
{
Address address = (Address)nodeIdAddressMap.get(nodeId);
+ log.info("unicasting to address: " + address);
+
byte[] bytes = writeRequest(request);
Message m = new Message(address, null, bytes);
@@ -822,11 +844,10 @@
{
lock.writeLock().acquire();
- List stats = null;
+ List statsList = null;
try
- {
-
+ {
Map nameMap = (Map)nameMaps.get(nodeId);
if (nameMap != null)
@@ -840,29 +861,19 @@
LocalClusteredQueue q = (LocalClusteredQueue)bb.getQueue();
if (q.isActive())
- {
- //We don't bother sending the stat if there is less than STATS_DIFFERENCE_MARGIN_PERCENT % difference
+ {
+ QueueStats stats = q.getStats();
+
+ //We don't bother sending the stats if there's no significant change in the values
- double newRate = q.getGrowthRate();
-
- int newMessageCount = q.messageCount();
-
- boolean sendStats = decideToSendStats(q.getGrowthRate(), newRate);
-
- if (!sendStats)
+ if (q.changedSignificantly())
{
- sendStats = decideToSendStats(q.getMessageCount(), newMessageCount);
- }
-
- if (sendStats)
- {
- if (stats == null)
+ if (statsList == null)
{
- stats = new ArrayList();
+ statsList = new ArrayList();
}
- QueueStats qs = new QueueStats(bb.getQueue().getName(), newRate, newMessageCount);
-
- stats.add(qs);
+
+ statsList.add(stats);
}
}
}
@@ -873,73 +884,56 @@
lock.writeLock().release();
}
- if (stats != null)
+ if (statsList != null)
{
- ClusterRequest req = new QueueStatsRequest(nodeId, stats);
+ ClusterRequest req = new QueueStatsRequest(nodeId, statsList);
asyncSendRequest(req);
}
}
- public void updateQueueStats(String nodeId, List stats) throws Exception
+ public void updateQueueStats(String nodeId, List statsList) throws Exception
{
lock.writeLock().acquire();
+ log.info("I have a list of stats: " + statsList.size() + " from nodeId: " + nodeId);
+
Map nameMap = (Map)nameMaps.get(nodeId);
if (nameMap == null)
{
- throw new IllegalStateException("Cannot find name map for node id " + nodeId);
+ //This is ok, the node might have left
+ log.info("But I have no bindings for " + nodeId);
}
-
- try
- {
- Iterator iter = stats.iterator();
-
- while (iter.hasNext())
+ else
+ {
+ log.info("I do have bindings for " + nodeId);
+ try
{
- QueueStats st = (QueueStats)iter.next();
+ Iterator iter = statsList.iterator();
- Binding bb = (Binding)nameMap.get(st.getQueueName());
-
- if (bb == null)
+ while (iter.hasNext())
{
- throw new IllegalStateException("Cannot find binding for queue name: " + st.getQueueName());
- }
-
- RemoteQueueStub stub = (RemoteQueueStub)bb.getQueue();
-
- stub.setStats(st.getMessageCount(), st.getGrowthRate());
- }
- }
- finally
- {
- lock.writeLock().release();
- }
- }
-
- private boolean decideToSendStats(double oldValue, double newValue)
- {
- boolean sendStats = false;
-
- if (oldValue != 0)
- {
- int percentChange = (int)(100 * (oldValue - newValue) / oldValue);
-
- if (Math.abs(percentChange) >= STATS_DIFFERENCE_MARGIN_PERCENT)
- {
- sendStats = true;
+ QueueStats st = (QueueStats)iter.next();
+
+ Binding bb = (Binding)nameMap.get(st.getQueueName());
+
+ if (bb == null)
+ {
+ throw new IllegalStateException("Cannot find binding for queue name: " + st.getQueueName());
+ }
+
+ RemoteQueueStub stub = (RemoteQueueStub)bb.getQueue();
+
+ stub.setStats(st);
+ }
}
- }
- else
- {
- if (newValue != 0)
+ finally
{
- sendStats = true;
+ lock.writeLock().release();
}
}
- return sendStats;
- }
+ }
// Public ------------------------------------------------------------------------------------------
@@ -985,11 +979,11 @@
QueuedExecutor executor = (QueuedExecutor)pool.get();
queue = new LocalClusteredQueue(nodeId, queueName, channelId, ms, pm, true,
- true, executor, filter);
+ durable, executor, filter);
}
else
{
- queue = new RemoteQueueStub(nodeId, queueName, channelId, true, pm, filter);
+ queue = new RemoteQueueStub(nodeId, queueName, channelId, durable, pm, filter);
}
Binding binding = new BindingImpl(nodeId, condition, queue);
@@ -1408,7 +1402,7 @@
ClusterRequest request = readRequest(bytes);
- request.execute(ClusteredPostOfficeImpl.this);
+ request.execute(ClusteredPostOfficeImpl.this);
}
catch (Exception e)
{
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredQueue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredQueue.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/ClusteredQueue.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -23,6 +23,7 @@
import org.jboss.messaging.core.Queue;
+
/**
* A ClusteredQueue
*
@@ -34,11 +35,11 @@
*/
interface ClusteredQueue extends Queue
{
- double getGrowthRate();
+ QueueStats getStats();
- int getMessageCount();
-
String getNodeId();
boolean isLocal();
}
+
+
Deleted: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/DefaultRedistributionPolicy.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/DefaultRedistributionPolicy.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/DefaultRedistributionPolicy.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -1,119 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.core.plugin.postoffice.cluster;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.jboss.messaging.core.plugin.postoffice.Binding;
-
-/**
- * A BasicRedistributonPolicy
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class DefaultRedistributionPolicy implements RedistributionPolicy
-{
- private String localNodeId;
-
- private int MAX_MESSAGES_TO_MOVE = 100;
-
- public DefaultRedistributionPolicy(String localNodeId)
- {
- this.localNodeId = localNodeId;
- }
-
- public RedistributionOrder calculate(List bindings)
- {
- Iterator iter = bindings.iterator();
-
- Binding localBinding = null;
-
- while (iter.hasNext())
- {
- Binding binding = (Binding)iter.next();
-
- if (binding.getNodeId().equals(localNodeId))
- {
- localBinding = binding;
-
- break;
- }
- }
-
- if (localBinding == null)
- {
- return null;
- }
-
- ClusteredQueue queue = (ClusteredQueue)localBinding.getQueue();
-
- if (queue.getGrowthRate() == 0 && queue.getMessageCount() > 0)
- {
- //No consumers on the queue - the messages are stranded
- //We should consider moving them somewhere else
-
- //We move messages to the node with the highest consumption rate
-
- iter = bindings.iterator();
-
- double maxRate = 0;
-
- Binding maxRateBinding = null;
-
- while (iter.hasNext())
- {
- Binding binding = (Binding)iter.next();
-
- ClusteredQueue theQueue = (ClusteredQueue)binding.getQueue();
-
- if (!binding.getNodeId().equals(localNodeId))
- {
- double rate = theQueue.getGrowthRate();
-
- if (rate > maxRate)
- {
- maxRate = rate;
-
- maxRateBinding = binding;
- }
- }
- }
-
- if (maxRate > 0)
- {
- //Move messages to this node
-
- //How many should we move?
- int numberToMove = Math.min(MAX_MESSAGES_TO_MOVE, queue.getMessageCount());
-
- return new RedistributionOrder(numberToMove, queue, maxRateBinding.getNodeId());
- }
- }
-
- return null;
- }
-}
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/FavourLocalRouter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/FavourLocalRouter.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/FavourLocalRouter.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -29,11 +29,27 @@
import org.jboss.messaging.core.DeliveryObserver;
import org.jboss.messaging.core.MessageReference;
import org.jboss.messaging.core.Receiver;
+import org.jboss.messaging.core.Router;
import org.jboss.messaging.core.tx.Transaction;
/**
*
* A FavourLocalRouter
+ *
+ * This router always favours the local queue.
+ *
+ * If there is no local queue it will round robin between the others.
+ *
+ * In the case of a distributed point to point queue deployed at each node in the cluster
+ * there will always be a local queue.
+ *
+ * In this case, with the assumption that producers and consumers are distributed evenly across the cluster
+ * then sending the message to the local queue is the most efficient policy.
+ *
+ * In the case of a durable subscription, there may well be no local queue since the durable subscription lives
+ * only on the number of nodes that it is looked up at.
+ *
+ * In this case the round robin routing will kick in
*
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @version <tt>$Revision: 1.1 $</tt>
@@ -41,12 +57,15 @@
* $Id$
*
*/
-public class FavourLocalRouter implements ClusterRouter
+public class FavourLocalRouter implements Router
{
- private List queues;
+ //MUST be an arraylist for fast index access
+ private ArrayList queues;
private ClusteredQueue localQueue;
+ private int target;
+
public FavourLocalRouter()
{
queues = new ArrayList();
@@ -70,15 +89,20 @@
localQueue = queue;
}
- queues.add(queue);
+ queues.add(queue);
+ target = 0;
+
return true;
}
public void clear()
{
queues.clear();
+
localQueue = null;
+
+ target = 0;
}
public boolean contains(Receiver queue)
@@ -92,13 +116,16 @@
}
public boolean remove(Receiver queue)
- {
+ {
if (queues.remove(queue))
{
if (localQueue == queue)
{
localQueue = null;
}
+
+ target = 0;
+
return true;
}
else
@@ -113,40 +140,46 @@
if (localQueue != null)
{
- //But only if it has consumers
+ //The only time the local queue won't accept is if the selector doesn't
+ //match - in which case it won't match at any other nodes too so no point
+ //in trying them
Delivery del = localQueue.handle(observer, reference, tx);
- if (del != null && del.isSelectorAccepted())
- {
- return del;
- }
+ return del;
}
-
- //TODO make this round robin
-
- Iterator iter = queues.iterator();
-
- while (iter.hasNext())
+ else
{
- ClusteredQueue queue = (ClusteredQueue)iter.next();
+ //There is no local shared queue
- if (!queue.isLocal())
+ //We round robin among the rest
+ if (!queues.isEmpty())
{
+ ClusteredQueue queue = (ClusteredQueue)queues.get(target);
+
Delivery del = queue.handle(observer, reference, tx);
+
+ target++;
- if (del != null && del.isSelectorAccepted())
+ if (target == queues.size())
{
- return del;
+ target = 0;
}
- }
+
+ //Again, if the selector doesn't match then it won't on any others so no point trying them
+ return del;
+ }
}
-
- return null;
+ return null;
}
public List getQueues()
{
return queues;
}
+
+ public int numberOfReceivers()
+ {
+ return queues.size();
+ }
}
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/FavourLocalRouterFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/FavourLocalRouterFactory.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/FavourLocalRouterFactory.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -21,7 +21,9 @@
*/
package org.jboss.messaging.core.plugin.postoffice.cluster;
+import org.jboss.messaging.core.Router;
+
/**
* A FavourLocalRouterFactory
*
@@ -33,7 +35,7 @@
*/
public class FavourLocalRouterFactory implements ClusterRouterFactory
{
- public ClusterRouter createRouter()
+ public Router createRouter()
{
return new FavourLocalRouter();
}
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/LocalClusteredQueue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/LocalClusteredQueue.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/LocalClusteredQueue.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -51,15 +51,19 @@
{
private static final int MIN_PERIOD = 1000;
+ private static final int STATS_DIFFERENCE_MARGIN_PERCENT = 10;
+
private String nodeId;
private long lastTime;
- private double lastGrowthRate;
+ private QueueStats lastStats;
private volatile int numberAdded;
private volatile int numberConsumed;
+
+ private volatile boolean changedSignificantly;
public LocalClusteredQueue(String nodeId, String name, long id, MessageStore ms, PersistenceManager pm,
boolean acceptReliableMessages, boolean recoverable, QueuedExecutor executor,
@@ -88,13 +92,7 @@
numberAdded = numberConsumed = 0;
}
- /**
- *
- * @return The rate of growth in messages per second of the queue
- * Rate of growth is defined as follows:
- * growth = (number of messages added - number of messages consumed) / time
- */
- public synchronized double getGrowthRate()
+ public QueueStats getStats()
{
long now = System.currentTimeMillis();
@@ -103,33 +101,58 @@
if (period <= MIN_PERIOD)
{
//Cache the value to avoid recalculating too often
- return lastGrowthRate;
+ return lastStats;
}
- lastGrowthRate = 1000 * (numberAdded - numberConsumed) / ((double)period);
+ float addRate = 1000 * numberAdded / ((float)period);
+ float consumeRate = 1000 * numberConsumed / ((float)period);
+
+ int cnt = messageCount();
+
+ if (lastStats != null)
+ {
+ if (checkSignificant(lastStats.getAddRate(), addRate) ||
+ checkSignificant(lastStats.getConsumeRate(), consumeRate) ||
+ checkSignificant(lastStats.getMessageCount(), cnt))
+ {
+ changedSignificantly = true;
+ }
+ else
+ {
+ changedSignificantly = false;
+ }
+ }
+ else
+ {
+ changedSignificantly = true;
+ }
+
+ lastStats = new QueueStats(name, addRate, consumeRate, messageCount());
+
lastTime = now;
numberAdded = numberConsumed = 0;
- return lastGrowthRate;
+ return lastStats;
+ }
+
+ //Have the stats changed significantly since the last time we request them?
+ public boolean changedSignificantly()
+ {
+ return changedSignificantly;
}
public boolean isLocal()
{
return true;
}
-
+
public String getNodeId()
{
return nodeId;
}
-
- public int getMessageCount()
- {
- return messageCount();
- }
-
+
public List getDeliveries(int number) throws Exception
{
List dels = new ArrayList();
@@ -161,6 +184,13 @@
public Delivery handleFromCluster(DeliveryObserver sender, MessageReference ref, Transaction tx)
throws Exception
{
+ if (filter != null && !filter.accept(ref))
+ {
+ Delivery del = new SimpleDelivery(this, ref, true, false);
+
+ return del;
+ }
+
checkClosed();
Future result = new Future();
@@ -198,4 +228,27 @@
return acked;
}
+
+ private boolean checkSignificant(float oldValue, float newValue)
+ {
+ boolean significant = false;
+
+ if (oldValue != 0)
+ {
+ int percentChange = (int)(100 * (oldValue - newValue) / oldValue);
+
+ if (Math.abs(percentChange) >= STATS_DIFFERENCE_MARGIN_PERCENT)
+ {
+ significant = true;
+ }
+ }
+ else
+ {
+ if (newValue != 0)
+ {
+ significant = true;
+ }
+ }
+ return significant;
+ }
}
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/QueueStats.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/QueueStats.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/QueueStats.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -39,27 +39,36 @@
{
private String queueName;
- private double growthRate;
+ private float addRate;
+ private float consumeRate;
+
private int messageCount;
public QueueStats()
{
}
- QueueStats(String queueName, double growthRate, int messageCount)
+ QueueStats(String queueName, float addRate, float consumeRate, int messageCount)
{
this.queueName = queueName;
- this.growthRate = growthRate;
+ this.addRate = addRate;
+ this.consumeRate = consumeRate;
+
this.messageCount = messageCount;
}
- double getGrowthRate()
+ float getAddRate()
{
- return growthRate;
+ return addRate;
}
+
+ float getConsumeRate()
+ {
+ return consumeRate;
+ }
int getMessageCount()
{
@@ -75,8 +84,10 @@
{
queueName = in.readUTF();
- growthRate = in.readDouble();
+ addRate = in.readFloat();
+ consumeRate = in.readFloat();
+
messageCount = in.readInt();
}
@@ -84,8 +95,10 @@
{
out.writeUTF(queueName);
- out.writeDouble(growthRate);
+ out.writeFloat(addRate);
+ out.writeFloat(consumeRate);
+
out.writeInt(messageCount);
}
}
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/RedistributionPolicy.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/RedistributionPolicy.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/RedistributionPolicy.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -34,5 +34,5 @@
*/
public interface RedistributionPolicy
{
- RedistributionOrder calculate(List bindings);
+ RedistributionOrder calculate(List queues);
}
Modified: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/RemoteQueueStub.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/RemoteQueueStub.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/RemoteQueueStub.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -61,12 +61,10 @@
private boolean recoverable;
- private int messageCount;
+ private PersistenceManager pm;
- private double growthRate;
+ private QueueStats stats;
- private PersistenceManager pm;
-
RemoteQueueStub(String nodeId, String name, long id, boolean recoverable, PersistenceManager pm, Filter filter)
{
this.nodeId = nodeId;
@@ -92,32 +90,34 @@
return false;
}
- public void setStats(int messageCount, double growthRate)
+ public void setStats(QueueStats stats)
{
- this.messageCount = messageCount;
-
- this.growthRate = growthRate;
+ this.stats = stats;
}
- public double getGrowthRate()
+ public QueueStats getStats()
{
- return growthRate;
+ return stats;
}
- public int getMessageCount()
- {
- return messageCount;
- }
-
public Delivery handle(DeliveryObserver observer, MessageReference reference, Transaction tx)
{
- //If the message is persistent and we are recoverable then we persist here, *before*
- //the message is sent across the network
+ if (filter != null && !filter.accept(reference))
+ {
+ Delivery del = new SimpleDelivery(this, reference, false, false);
+
+ return del;
+ }
- if (recoverable && reference.isReference())
+ if (recoverable && reference.isReliable())
{
try
{
+ //If the message is persistent and we are recoverable then we persist here, *before*
+ //the message is sent across the network
+
+ log.info("Adding ref: " + reference + " in channel " + id);
+
pm.addReference(id, reference, tx);
}
catch (Exception e)
@@ -186,7 +186,7 @@
public int messageCount()
{
- return messageCount;
+ throw new UnsupportedOperationException();
}
public void removeAllReferences() throws Throwable
@@ -230,4 +230,34 @@
throw new UnsupportedOperationException();
}
+ public int numberOfReceivers()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void activate()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void deactivate()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void load() throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void unload() throws Exception
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isActive()
+ {
+ throw new UnsupportedOperationException();
+ }
+
}
Copied: trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/StandardRedistributionPolicy.java (from rev 1298, trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/BasicRedistributionPolicy.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/BasicRedistributionPolicy.java 2006-09-17 17:58:08 UTC (rev 1298)
+++ trunk/src/main/org/jboss/messaging/core/plugin/postoffice/cluster/StandardRedistributionPolicy.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.plugin.postoffice.cluster;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ *
+ * A StandardRedistributionPolicy
+ *
+ * In this simple redistribution policy, we only move messages from a particular local queue if
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public class StandardRedistributionPolicy implements RedistributionPolicy
+{
+ private String localNodeId;
+
+ public StandardRedistributionPolicy(String localNodeId)
+ {
+ this.localNodeId = localNodeId;
+ }
+
+ public RedistributionOrder calculate(List queues)
+ {
+ Iterator iter = queues.iterator();
+
+ ClusteredQueue localQueue = null;
+
+ while (iter.hasNext())
+ {
+ ClusteredQueue queue = (ClusteredQueue)iter.next();
+
+ if (queue.isLocal())
+ {
+ localQueue = queue;
+
+ break;
+ }
+ }
+
+ if (localQueue == null)
+ {
+ return null;
+ }
+
+ QueueStats stats = localQueue.getStats();
+
+ if (stats == null)
+ {
+ //We have not given the queue long enough to produce stats - so we can't move anything
+ //now
+ return null;
+ }
+
+ return null;
+ }
+}
Modified: trunk/tests/src/org/jboss/test/messaging/core/SimpleChannel.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/SimpleChannel.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/tests/src/org/jboss/test/messaging/core/SimpleChannel.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -191,6 +191,31 @@
throw new NotYetImplementedException();
}
+ public int numberOfReceivers()
+ {
+ throw new NotYetImplementedException();
+ }
+
+ public void activate()
+ {
+ throw new NotYetImplementedException();
+ }
+
+ public void deactivate()
+ {
+ throw new NotYetImplementedException();
+ }
+
+ public void unload() throws Exception
+ {
+ throw new NotYetImplementedException();
+ }
+
+ public boolean isActive()
+ {
+ throw new UnsupportedOperationException();
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/tests/src/org/jboss/test/messaging/core/SimpleReceiver.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -155,10 +155,14 @@
boolean done = ACKING.equals(state) ? true : false;
log.trace(this + " is " + (done ? "ACKing" : "NACKing") + " message " + ref);
+ log.info(this + " got message " + ref.getMessageID());
+
Message m = ref.getMessage();
SimpleDelivery delivery = new SimpleDelivery(observer, ref, done);
messages.add(new Object[] {m, done ? null : delivery});
+
+ log.info("Added it to messages");
if (immediateAsynchronousAcknowledgment)
{
Copied: trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/DefaultPostOfficeTest.java (from rev 1299, trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/SimplePostOfficeTest.java)
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/SimplePostOfficeTest.java 2006-09-17 20:24:02 UTC (rev 1299)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/DefaultPostOfficeTest.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -0,0 +1,1134 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.messaging.core.plugin.postoffice;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.jms.selector.Selector;
+import org.jboss.jms.server.QueuedExecutorPool;
+import org.jboss.messaging.core.Filter;
+import org.jboss.messaging.core.FilterFactory;
+import org.jboss.messaging.core.Message;
+import org.jboss.messaging.core.MessageReference;
+import org.jboss.messaging.core.local.PagingFilteredQueue;
+import org.jboss.messaging.core.plugin.IdManager;
+import org.jboss.messaging.core.plugin.JDBCPersistenceManager;
+import org.jboss.messaging.core.plugin.SimpleMessageStore;
+import org.jboss.messaging.core.plugin.contract.MessageStore;
+import org.jboss.messaging.core.plugin.contract.PersistenceManager;
+import org.jboss.messaging.core.plugin.contract.PostOffice;
+import org.jboss.messaging.core.plugin.postoffice.Binding;
+import org.jboss.messaging.core.plugin.postoffice.DefaultPostOffice;
+import org.jboss.messaging.core.tx.Transaction;
+import org.jboss.messaging.core.tx.TransactionRepository;
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.core.SimpleFilter;
+import org.jboss.test.messaging.core.SimpleFilterFactory;
+import org.jboss.test.messaging.core.SimpleReceiver;
+import org.jboss.test.messaging.tools.ServerManagement;
+import org.jboss.test.messaging.tools.jmx.ServiceContainer;
+import org.jboss.test.messaging.util.CoreMessageFactory;
+
+import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
+
+/**
+ *
+ * A DefaultPostOfficeTest
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public class DefaultPostOfficeTest extends MessagingTestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ protected ServiceContainer sc;
+
+ protected IdManager im;
+
+ protected PersistenceManager pm;
+
+ protected MessageStore ms;
+
+ protected TransactionRepository tr;
+
+ protected QueuedExecutorPool pool;
+
+ // Constructors --------------------------------------------------
+
+ public DefaultPostOfficeTest(String name)
+ {
+ super(name);
+ }
+
+ // Public --------------------------------------------------------
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ sc = new ServiceContainer("all");
+
+ sc.start();
+
+ pm =
+ new JDBCPersistenceManager(sc.getDataSource(), sc.getTransactionManager(), null,
+ true, true, true, 100);
+ pm.start();
+
+ tr = new TransactionRepository(pm, new IdManager("TRANSACTION_ID", 10, pm));
+ tr.start();
+
+ ms = new SimpleMessageStore();
+ ms.start();
+
+ pool = new QueuedExecutorPool(10);
+
+ im = new IdManager("CHANNEL_ID", 10, pm);
+
+ log.debug("setup done");
+ }
+
+ public void tearDown() throws Exception
+ {
+ if (!ServerManagement.isRemote())
+ {
+ sc.stop();
+ sc = null;
+ }
+ pm.stop();
+ tr.stop();
+ ms.stop();
+
+ super.tearDown();
+ }
+
+ // Public --------------------------------------------------------
+
+
+ public final void testBind() throws Throwable
+ {
+ PostOffice office1 = null;
+
+ PostOffice office2 = null;
+
+ PostOffice office3 = null;
+
+ try
+ {
+ office1 = createPostOffice();
+
+ //Bind one durable
+
+ Filter filter1 = new Selector("x = 'cheese'");
+ Filter filter2 = new Selector("y = 'bread'");
+
+ PagingFilteredQueue queue1 = new PagingFilteredQueue("durableQueue", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+
+
+ Binding binding1 =
+ office1.bindQueue("condition1", queue1);
+
+ //Binding twice with the same name should fail
+ try
+ {
+ Binding bindFail = office1.bindQueue("condition1", queue1);
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ //Ok
+ }
+
+ //Bind one non durable
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("nonDurableQueue", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding2 =
+ office1.bindQueue("condition2", queue2);
+
+ //Check they're there
+
+ Binding binding3 = office1.getBindingForQueueName("durableQueue");
+ assertNotNull(binding3);
+ assertTrue(binding1 == binding3);
+ assertEquivalent(binding1, binding3);
+ assertTrue(binding3.getQueue().isActive());
+ assertEquals(true, binding3.getQueue().isRecoverable());
+
+
+ Binding binding4 = office1.getBindingForQueueName("nonDurableQueue");
+ assertNotNull(binding4);
+ assertTrue(binding2 == binding4);
+ assertEquivalent(binding2, binding4);
+ assertTrue(binding4.getQueue().isActive());
+ assertEquals(false, binding4.getQueue().isRecoverable());
+
+ office1.stop();
+
+ //Throw away the office and create another
+ office2 = createPostOffice();
+
+ //Only one binding should be there
+ Binding binding5 = office2.getBindingForQueueName("durableQueue");
+ assertNotNull(binding5);
+ assertEquivalent(binding1, binding5);
+ //Should be inactive
+ assertFalse(binding5.getQueue().isActive());
+
+ Binding binding6 = office2.getBindingForQueueName("nonDurableQueue");
+ assertNull(binding6);
+
+ //Unbind the binding
+ Binding binding7 = office2.unbindQueue("durableQueue");
+ assertNotNull(binding7);
+ assertEquivalent(binding1, binding7);
+
+ //Make sure no longer there
+ Binding binding8 = office2.getBindingForQueueName("durableQueue");
+ assertNull(binding8);
+
+ office2.stop();
+
+ //Throw away office and start another
+ office3 = createPostOffice();
+
+ //Make sure not there
+ Binding binding9 = office3.getBindingForQueueName("durableQueue");
+ assertNull(binding9);
+
+ office3.stop();
+ }
+ finally
+ {
+ if (office1 != null)
+ {
+ office1.stop();
+ }
+
+ if (office2 != null)
+ {
+ office2.stop();
+ }
+
+ if (office3 != null)
+ {
+ office2.stop();
+ }
+ }
+
+ }
+
+ public final void testListBindings() throws Throwable
+ {
+ PostOffice office = null;
+
+ try
+ {
+ office = createPostOffice();
+
+ PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding1 =
+ office.bindQueue("condition1", queue1);
+
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding2 =
+ office.bindQueue("condition1", queue2);
+
+ PagingFilteredQueue queue3 = new PagingFilteredQueue("queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding3 =
+ office.bindQueue("condition1", queue3);
+
+ PagingFilteredQueue queue4 = new PagingFilteredQueue("queue4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding4 =
+ office.bindQueue("condition1", queue4);
+
+ PagingFilteredQueue queue5 = new PagingFilteredQueue("queue5", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding5 =
+ office.bindQueue("condition2", queue5);
+
+ PagingFilteredQueue queue6 = new PagingFilteredQueue("queue6", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding6 =
+ office.bindQueue("condition2", queue6);
+
+ PagingFilteredQueue queue7 = new PagingFilteredQueue("queue7", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding7 =
+ office.bindQueue("condition2", queue7);
+
+ PagingFilteredQueue queue8 = new PagingFilteredQueue("queue8", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding8 =
+ office.bindQueue("condition2", queue8);
+
+
+ Collection bindings = office.listBindingsForCondition("dummy");
+ assertNotNull(bindings);
+ assertTrue(bindings.isEmpty());
+
+ //We don't match on substrings
+ bindings = office.listBindingsForCondition("condition123");
+ assertNotNull(bindings);
+ assertTrue(bindings.isEmpty());
+
+ //We don't currently support hierarchies
+ bindings = office.listBindingsForCondition("condition1.subcondition");
+ assertNotNull(bindings);
+ assertTrue(bindings.isEmpty());
+
+ //We currently just do an exact match
+ bindings = office.listBindingsForCondition("condition1");
+ assertNotNull(bindings);
+ assertEquals(4, bindings.size());
+
+ Iterator iter = bindings.iterator();
+ assertEquivalent((Binding)iter.next(), binding1);
+ assertEquivalent((Binding)iter.next(), binding2);
+ assertEquivalent((Binding)iter.next(), binding3);
+ assertEquivalent((Binding)iter.next(), binding4);
+
+ bindings = office.listBindingsForCondition("condition2");
+ assertNotNull(bindings);
+ assertEquals(4, bindings.size());
+
+ iter = bindings.iterator();
+ assertEquivalent((Binding)iter.next(), binding5);
+ assertEquivalent((Binding)iter.next(), binding6);
+ assertEquivalent((Binding)iter.next(), binding7);
+ assertEquivalent((Binding)iter.next(), binding8);
+ }
+ finally
+ {
+ if (office != null)
+ {
+ office.stop();
+ }
+ }
+
+ }
+
+ public void testRouteNonPersistentWithFilter() throws Throwable
+ {
+ routeWithFilter(false);
+ }
+
+ public void testRoutePersistentWithFilter() throws Throwable
+ {
+ routeWithFilter(true);
+ }
+
+
+
+
+ public final void testRoutePersistent() throws Throwable
+ {
+ route(true);
+ }
+
+ public final void testRouteNonPersistent() throws Throwable
+ {
+ route(false);
+ }
+
+ public final void testRouteTransactionalPersistent() throws Throwable
+ {
+ routeTransactional(true);
+ }
+
+ public final void testRouteTransactionalNonPersistent() throws Throwable
+ {
+ routeTransactional(false);
+ }
+
+
+ public final void testRouteInactive() throws Throwable
+ {
+ PostOffice postOffice = null;
+
+ try
+ {
+
+ postOffice = createPostOffice();
+
+ PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding1 =
+ postOffice.bindQueue("topic1", queue1);
+
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding2 =
+ postOffice.bindQueue("topic1", queue2);
+
+ PagingFilteredQueue queue3 = new PagingFilteredQueue("queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding3 =
+ postOffice.bindQueue("topic1", queue3);
+
+ PagingFilteredQueue queue4 = new PagingFilteredQueue("queue4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding4 =
+ postOffice.bindQueue("topic2", queue4);
+
+ PagingFilteredQueue queue5 = new PagingFilteredQueue("queue5", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding5 =
+ postOffice.bindQueue("topic2", queue5);
+
+ PagingFilteredQueue queue6 = new PagingFilteredQueue("queue6", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding6 =
+ postOffice.bindQueue("topic2", queue6);
+
+ SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue1.add(receiver1);
+ SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue2.add(receiver2);
+ SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue3.add(receiver3);
+ SimpleReceiver receiver4 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue4.add(receiver4);
+ SimpleReceiver receiver5 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue5.add(receiver5);
+ SimpleReceiver receiver6 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue6.add(receiver6);
+
+ queue1.deactivate();
+ queue2.deactivate();
+ queue5.deactivate();
+ queue6.deactivate();
+
+ assertFalse(queue1.isActive());
+ assertFalse(queue2.isActive());
+ assertFalse(queue5.isActive());
+ assertFalse(queue6.isActive());
+ assertTrue(queue3.isActive());
+ assertTrue(queue4.isActive());
+
+ Message msg1 = CoreMessageFactory.createCoreMessage(1);
+ MessageReference ref1 = ms.reference(msg1);
+
+ boolean routed = postOffice.route(ref1, "topic1", null);
+ assertTrue(routed);
+
+ List msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver3.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ Message msgRec = (Message)msgs.get(0);
+ assertTrue(msg1 == msgRec);
+ receiver3.acknowledge(msgRec, null);
+ msgs = queue3.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver4.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver5.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver6.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ receiver3.clear();
+
+ Message msg2 = CoreMessageFactory.createCoreMessage(2);
+ MessageReference ref2 = ms.reference(msg2);
+
+ routed = postOffice.route(ref2, "topic2", null);
+ assertTrue(routed);
+
+ msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver3.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver4.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ msgRec = (Message)msgs.get(0);
+ assertTrue(msg2 == msgRec);
+ receiver4.acknowledge(msgRec, null);
+ msgs = queue4.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver5.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver6.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+ }
+ finally
+ {
+ if (postOffice != null)
+ {
+ postOffice.stop();
+ }
+ }
+
+ }
+
+ public final void testRouteNoBinding() throws Throwable
+ {
+ PostOffice postOffice = null;
+
+ try
+ {
+ postOffice = createPostOffice();
+
+ PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding1 =
+ postOffice.bindQueue("condition1", queue1);
+
+ SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
+ queue1.add(receiver1);
+
+ assertTrue(queue1.isActive());
+
+ Message msg1 = CoreMessageFactory.createCoreMessage(1);
+ MessageReference ref1 = ms.reference(msg1);
+
+ boolean routed = postOffice.route(ref1, "this won't match anything", null);
+
+ assertFalse(routed);
+
+ List msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ }
+ finally
+ {
+ if (postOffice != null)
+ {
+ postOffice.stop();
+ }
+ }
+ }
+
+
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ protected void routeWithFilter(boolean persistentMessage) throws Throwable
+ {
+ PostOffice postOffice = null;
+
+ try
+ {
+ postOffice = createPostOffice();
+
+ SimpleFilter filter = new SimpleFilter(2);
+
+ PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), filter);
+
+ Binding binding1 =
+ postOffice.bindQueue("topic1", queue1);
+
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding2 =
+ postOffice.bindQueue("topic1", queue2);
+
+ PagingFilteredQueue queue3 = new PagingFilteredQueue("queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding3 =
+ postOffice.bindQueue("topic1", queue3);
+
+ SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue1.add(receiver1);
+ SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue2.add(receiver2);
+ SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
+ queue3.add(receiver3);
+
+ Message msg1 = CoreMessageFactory.createCoreMessage(1);
+ MessageReference ref1 = ms.reference(msg1);
+ boolean routed = postOffice.route(ref1, "topic1", null);
+ assertTrue(routed);
+ Message msg2 = CoreMessageFactory.createCoreMessage(2);
+ MessageReference ref2 = ms.reference(msg2);
+ routed = postOffice.route(ref2, "topic1", null);
+ assertTrue(routed);
+ Message msg3 = CoreMessageFactory.createCoreMessage(3);
+ MessageReference ref3 = ms.reference(msg3);
+ routed = postOffice.route(ref3, "topic1", null);
+ assertTrue(routed);
+
+ List msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ Message msgRec = (Message)msgs.get(0);
+ assertTrue(msg2 == msgRec);
+ receiver1.acknowledge(msgRec, null);
+ msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertEquals(3, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ assertTrue(msg1 == msgRec1);
+ Message msgRec2 = (Message)msgs.get(1);
+ assertTrue(msg2 == msgRec2);
+ Message msgRec3 = (Message)msgs.get(2);
+ assertTrue(msg3 == msgRec3);
+
+ receiver2.acknowledge(msgRec1, null);
+ receiver2.acknowledge(msgRec2, null);
+ receiver2.acknowledge(msgRec3, null);
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver3.getMessages();
+ assertNotNull(msgs);
+ assertEquals(3, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ assertTrue(msg1 == msgRec1);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msg2 == msgRec2);
+ msgRec3 = (Message)msgs.get(2);
+ assertTrue(msg3 == msgRec3);
+
+ receiver3.acknowledge(msgRec1, null);
+ receiver3.acknowledge(msgRec2, null);
+ receiver3.acknowledge(msgRec3, null);
+ msgs = queue3.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ }
+ finally
+ {
+ if (postOffice != null)
+ {
+ postOffice.stop();
+ }
+ }
+ }
+
+ protected void route(boolean persistentMessage) throws Throwable
+ {
+ PostOffice postOffice = null;
+
+ try
+ {
+ postOffice = createPostOffice();
+
+ PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding1 =
+ postOffice.bindQueue("topic1", queue1);
+
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding2 =
+ postOffice.bindQueue("topic1", queue2);
+
+ PagingFilteredQueue queue3 = new PagingFilteredQueue("queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding3 =
+ postOffice.bindQueue("topic1", queue3);
+
+ PagingFilteredQueue queue4 = new PagingFilteredQueue("queue4", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+
+ Binding binding4 =
+ postOffice.bindQueue("topic2", queue4);
+
+ PagingFilteredQueue queue5 = new PagingFilteredQueue("queue5", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+
+ Binding binding5 =
+ postOffice.bindQueue("topic2", queue5);
+
+ PagingFilteredQueue queue6 = new PagingFilteredQueue("queue6", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+
+ Binding binding6 =
+ postOffice.bindQueue("topic2", queue6);
+
+ SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
+ queue1.add(receiver1);
+ SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
+ queue2.add(receiver2);
+ SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
+ queue3.add(receiver3);
+ SimpleReceiver receiver4 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
+ queue4.add(receiver4);
+ SimpleReceiver receiver5 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
+ queue5.add(receiver5);
+ SimpleReceiver receiver6 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
+ queue6.add(receiver6);
+
+ assertTrue(queue1.isActive());
+ assertTrue(queue2.isActive());
+ assertTrue(queue3.isActive());
+ assertTrue(queue4.isActive());
+ assertTrue(queue5.isActive());
+ assertTrue(queue6.isActive());
+
+ Message msg1 = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);
+ MessageReference ref1 = ms.reference(msg1);
+
+ boolean routed = postOffice.route(ref1, "topic1", null);
+ assertTrue(routed);
+
+ List msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ Message msgRec = (Message)msgs.get(0);
+ assertTrue(msg1 == msgRec);
+ receiver1.acknowledge(msgRec, null);
+ msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ msgRec = (Message)msgs.get(0);
+ assertTrue(msg1 == msgRec);
+ receiver2.acknowledge(msgRec, null);
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver3.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ msgRec = (Message)msgs.get(0);
+ assertTrue(msg1 == msgRec);
+ receiver3.acknowledge(msgRec, null);
+ msgs = queue3.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver4.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver5.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver6.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ receiver1.clear();
+ receiver2.clear();
+ receiver3.clear();
+
+
+ Message msg2 = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);
+ MessageReference ref2 = ms.reference(msg2);
+
+ routed = postOffice.route(ref2, "topic2", null);
+ assertTrue(routed);
+
+ msgs = receiver4.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ msgRec = (Message)msgs.get(0);
+ assertTrue(msg2 == msgRec);
+ receiver4.acknowledge(msgRec, null);
+ msgs = queue4.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver5.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ msgRec = (Message)msgs.get(0);
+ assertTrue(msg2 == msgRec);
+ receiver5.acknowledge(msgRec, null);
+ msgs = queue5.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver6.getMessages();
+ assertNotNull(msgs);
+ assertEquals(1, msgs.size());
+ msgRec = (Message)msgs.get(0);
+ assertTrue(msg2 == msgRec);
+ receiver6.acknowledge(msgRec, null);
+ msgs = queue6.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = receiver3.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ }
+ finally
+ {
+ if (postOffice != null)
+ {
+ postOffice.stop();
+ }
+ }
+ }
+
+ protected void routeTransactional(boolean persistentMessage) throws Throwable
+ {
+ PostOffice postOffice = null;
+
+ try
+ {
+ postOffice = createPostOffice();
+
+ PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+
+ Binding binding1 =
+ postOffice.bindQueue("topic1", queue1);
+
+ PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
+
+ Binding binding2 =
+ postOffice.bindQueue("topic1", queue2);
+
+ SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
+ queue1.add(receiver1);
+
+ SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
+ queue2.add(receiver2);
+
+ assertTrue(queue1.isActive());
+ assertTrue(queue2.isActive());
+
+ Message msg1 = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);
+ MessageReference ref1 = ms.reference(msg1);
+
+ Message msg2 = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);
+ MessageReference ref2 = ms.reference(msg2);
+
+ Transaction tx = tr.createTransaction();
+
+ boolean routed = postOffice.route(ref1, "topic1", tx);
+ assertTrue(routed);
+ routed = postOffice.route(ref2, "topic1", tx);
+ assertTrue(routed);
+
+ List msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ tx.commit();
+
+ msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ Message msgRec1 = (Message)msgs.get(0);
+ Message msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg1);
+ assertTrue(msgRec2 == msg2);
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg1);
+ assertTrue(msgRec2 == msg2);
+
+ //Acknowledge non transactionally
+ receiver1.acknowledge(msgRec1, null);
+ receiver1.acknowledge(msgRec2, null);
+
+ receiver2.acknowledge(msgRec1, null);
+ receiver2.acknowledge(msgRec2, null);
+
+ msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ receiver1.clear();
+
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ receiver2.clear();
+
+ Message msg3 = CoreMessageFactory.createCoreMessage(3, persistentMessage, null);
+ MessageReference ref3 = ms.reference(msg3);
+
+ Message msg4 = CoreMessageFactory.createCoreMessage(4, persistentMessage, null);
+ MessageReference ref4 = ms.reference(msg4);
+
+ tx = tr.createTransaction();
+
+ routed = postOffice.route(ref3, "topic1", tx);
+ assertTrue(routed);
+ routed = postOffice.route(ref4, "topic1", tx);
+ assertTrue(routed);
+
+ msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ tx.rollback();
+
+ msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ receiver1.clear();
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ receiver2.clear();
+
+
+ Message msg5 = CoreMessageFactory.createCoreMessage(5, persistentMessage, null);
+ MessageReference ref5 = ms.reference(msg5);
+
+ Message msg6 = CoreMessageFactory.createCoreMessage(6, persistentMessage, null);
+ MessageReference ref6 = ms.reference(msg6);
+
+ routed = postOffice.route(ref5, "topic1", null);
+ assertTrue(routed);
+ routed = postOffice.route(ref6, "topic1", null);
+ assertTrue(routed);
+
+ msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg5);
+ assertTrue(msgRec2 == msg6);
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg5);
+ assertTrue(msgRec2 == msg6);
+
+ //Acknowledge transactionally
+
+ tx = tr.createTransaction();
+
+ receiver1.acknowledge(msgRec1, tx);
+ receiver1.acknowledge(msgRec2, tx);
+
+ receiver2.acknowledge(msgRec1, tx);
+ receiver2.acknowledge(msgRec2, tx);
+
+ msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg5);
+ assertTrue(msgRec2 == msg6);
+
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg5);
+ assertTrue(msgRec2 == msg6);
+
+ tx.commit();
+
+ msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ receiver1.clear();
+
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertTrue(msgs.isEmpty());
+
+ receiver2.clear();
+
+ Message msg7 = CoreMessageFactory.createCoreMessage(7, persistentMessage, null);
+ MessageReference ref7 = ms.reference(msg7);
+
+ Message msg8 = CoreMessageFactory.createCoreMessage(8, persistentMessage, null);
+ MessageReference ref8 = ms.reference(msg8);
+
+ routed = postOffice.route(ref7, "topic1", null);
+ assertTrue(routed);
+ routed = postOffice.route(ref8, "topic1", null);
+ assertTrue(routed);
+
+ msgs = receiver1.getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg7);
+ assertTrue(msgRec2 == msg8);
+
+ msgs = receiver2.getMessages();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg7);
+ assertTrue(msgRec2 == msg8);
+
+ //Acknowledge transactionally
+
+ tx = tr.createTransaction();
+
+ receiver1.acknowledge(msgRec1, tx);
+ receiver1.acknowledge(msgRec2, tx);
+
+ receiver2.acknowledge(msgRec1, tx);
+ receiver2.acknowledge(msgRec2, tx);
+
+ msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg7);
+ assertTrue(msgRec2 == msg8);
+
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg7);
+ assertTrue(msgRec2 == msg8);
+
+ tx.rollback();
+
+ msgs = queue1.browse();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg7);
+ assertTrue(msgRec2 == msg8);
+
+ msgs = queue2.browse();
+ assertNotNull(msgs);
+ assertEquals(2, msgs.size());
+ msgRec1 = (Message)msgs.get(0);
+ msgRec2 = (Message)msgs.get(1);
+ assertTrue(msgRec1 == msg7);
+ assertTrue(msgRec2 == msg8);
+ }
+ finally
+ {
+ if (postOffice != null)
+ {
+ postOffice.stop();
+ }
+ }
+ }
+
+ protected void assertEquivalent(Binding binding1, Binding binding2)
+ {
+ assertEquals(binding1.getNodeId(), binding2.getNodeId());
+ assertEquals(binding1.getQueue().getName(), binding2.getQueue().getName());
+ String selector1 = binding1.getQueue().getFilter() != null ? binding1.getQueue().getFilter().getFilterString() : null;
+ String selector2 = binding2.getQueue().getFilter() != null ? binding2.getQueue().getFilter().getFilterString() : null;
+ assertEquals(selector1, selector2);
+ assertEquals(binding1.getQueue().getChannelID(), binding2.getQueue().getChannelID());
+ assertEquals(binding1.getQueue().isRecoverable(), binding2.getQueue().isRecoverable());
+ }
+
+ protected PostOffice createPostOffice() throws Exception
+ {
+ FilterFactory ff = new SimpleFilterFactory();
+
+ DefaultPostOffice postOffice =
+ new DefaultPostOffice(sc.getDataSource(), sc.getTransactionManager(),
+ null, true, "node1", "Simple", ms, pm, tr, ff, pool);
+
+ postOffice.start();
+
+ return postOffice;
+ }
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
+
Deleted: trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/SimplePostOfficeTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/SimplePostOfficeTest.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/SimplePostOfficeTest.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -1,1134 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.messaging.core.plugin.postoffice;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jboss.jms.selector.Selector;
-import org.jboss.jms.server.QueuedExecutorPool;
-import org.jboss.messaging.core.Filter;
-import org.jboss.messaging.core.FilterFactory;
-import org.jboss.messaging.core.Message;
-import org.jboss.messaging.core.MessageReference;
-import org.jboss.messaging.core.local.PagingFilteredQueue;
-import org.jboss.messaging.core.plugin.IdManager;
-import org.jboss.messaging.core.plugin.JDBCPersistenceManager;
-import org.jboss.messaging.core.plugin.SimpleMessageStore;
-import org.jboss.messaging.core.plugin.contract.MessageStore;
-import org.jboss.messaging.core.plugin.contract.PersistenceManager;
-import org.jboss.messaging.core.plugin.contract.PostOffice;
-import org.jboss.messaging.core.plugin.postoffice.Binding;
-import org.jboss.messaging.core.plugin.postoffice.PostOfficeImpl;
-import org.jboss.messaging.core.tx.Transaction;
-import org.jboss.messaging.core.tx.TransactionRepository;
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.core.SimpleFilter;
-import org.jboss.test.messaging.core.SimpleFilterFactory;
-import org.jboss.test.messaging.core.SimpleReceiver;
-import org.jboss.test.messaging.tools.ServerManagement;
-import org.jboss.test.messaging.tools.jmx.ServiceContainer;
-import org.jboss.test.messaging.util.CoreMessageFactory;
-
-import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
-
-/**
- *
- * A PostOfficeTestBase
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class SimplePostOfficeTest extends MessagingTestCase
-{
- // Constants -----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- protected ServiceContainer sc;
-
- protected IdManager im;
-
- protected PersistenceManager pm;
-
- protected MessageStore ms;
-
- protected TransactionRepository tr;
-
- protected QueuedExecutorPool pool;
-
- // Constructors --------------------------------------------------
-
- public SimplePostOfficeTest(String name)
- {
- super(name);
- }
-
- // Public --------------------------------------------------------
-
- public void setUp() throws Exception
- {
- super.setUp();
-
- sc = new ServiceContainer("all");
-
- sc.start();
-
- pm =
- new JDBCPersistenceManager(sc.getDataSource(), sc.getTransactionManager(), null,
- true, true, true, 100);
- pm.start();
-
- tr = new TransactionRepository(pm, new IdManager("TRANSACTION_ID", 10, pm));
- tr.start();
-
- ms = new SimpleMessageStore();
- ms.start();
-
- pool = new QueuedExecutorPool(10);
-
- im = new IdManager("CHANNEL_ID", 10, pm);
-
- log.debug("setup done");
- }
-
- public void tearDown() throws Exception
- {
- if (!ServerManagement.isRemote())
- {
- sc.stop();
- sc = null;
- }
- pm.stop();
- tr.stop();
- ms.stop();
-
- super.tearDown();
- }
-
- // Public --------------------------------------------------------
-
-
- public final void testBind() throws Throwable
- {
- PostOffice office1 = null;
-
- PostOffice office2 = null;
-
- PostOffice office3 = null;
-
- try
- {
- office1 = createPostOffice();
-
- //Bind one durable
-
- Filter filter1 = new Selector("x = 'cheese'");
- Filter filter2 = new Selector("y = 'bread'");
-
- PagingFilteredQueue queue1 = new PagingFilteredQueue("durableQueue", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
-
-
- Binding binding1 =
- office1.bindQueue("condition1", queue1);
-
- //Binding twice with the same name should fail
- try
- {
- Binding bindFail = office1.bindQueue("condition1", queue1);
- fail();
- }
- catch (IllegalArgumentException e)
- {
- //Ok
- }
-
- //Bind one non durable
- PagingFilteredQueue queue2 = new PagingFilteredQueue("nonDurableQueue", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding2 =
- office1.bindQueue("condition2", queue2);
-
- //Check they're there
-
- Binding binding3 = office1.getBindingForQueueName("durableQueue");
- assertNotNull(binding3);
- assertTrue(binding1 == binding3);
- assertEquivalent(binding1, binding3);
- assertNotNull(binding3.getQueue());
- assertEquals(true, binding3.getQueue().isRecoverable());
-
-
- Binding binding4 = office1.getBindingForQueueName("nonDurableQueue");
- assertNotNull(binding4);
- assertTrue(binding2 == binding4);
- assertEquivalent(binding2, binding4);
- assertNotNull(binding4.getQueue());
- assertEquals(false, binding4.getQueue().isRecoverable());
-
- office1.stop();
-
- //Throw away the office and create another
- office2 = createPostOffice();
-
- //Only one binding should be there
- Binding binding5 = office2.getBindingForQueueName("durableQueue");
- assertNotNull(binding5);
- assertEquivalent(binding1, binding5);
- //Should be unloaded
- assertNull(binding5.getQueue());
-
- Binding binding6 = office2.getBindingForQueueName("nonDurableQueue");
- assertNull(binding6);
-
- //Unbind the binding
- Binding binding7 = office2.unbindQueue("durableQueue");
- assertNotNull(binding7);
- assertEquivalent(binding1, binding7);
-
- //Make sure no longer there
- Binding binding8 = office2.getBindingForQueueName("durableQueue");
- assertNull(binding8);
-
- office2.stop();
-
- //Throw away office and start another
- office3 = createPostOffice();
-
- //Make sure not there
- Binding binding9 = office3.getBindingForQueueName("durableQueue");
- assertNull(binding9);
-
- office3.stop();
- }
- finally
- {
- if (office1 != null)
- {
- office1.stop();
- }
-
- if (office2 != null)
- {
- office2.stop();
- }
-
- if (office3 != null)
- {
- office2.stop();
- }
- }
-
- }
-
- public final void testListBindings() throws Throwable
- {
- PostOffice office = null;
-
- try
- {
- office = createPostOffice();
-
- PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding1 =
- office.bindQueue("condition1", queue1);
-
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding2 =
- office.bindQueue("condition1", queue2);
-
- PagingFilteredQueue queue3 = new PagingFilteredQueue("queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding3 =
- office.bindQueue("condition1", queue3);
-
- PagingFilteredQueue queue4 = new PagingFilteredQueue("queue4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding4 =
- office.bindQueue("condition1", queue4);
-
- PagingFilteredQueue queue5 = new PagingFilteredQueue("queue5", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding5 =
- office.bindQueue("condition2", queue5);
-
- PagingFilteredQueue queue6 = new PagingFilteredQueue("queue6", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding6 =
- office.bindQueue("condition2", queue6);
-
- PagingFilteredQueue queue7 = new PagingFilteredQueue("queue7", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding7 =
- office.bindQueue("condition2", queue7);
-
- PagingFilteredQueue queue8 = new PagingFilteredQueue("queue8", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding8 =
- office.bindQueue("condition2", queue8);
-
-
- Collection bindings = office.listBindingsForCondition("dummy");
- assertNotNull(bindings);
- assertTrue(bindings.isEmpty());
-
- //We don't match on substrings
- bindings = office.listBindingsForCondition("condition123");
- assertNotNull(bindings);
- assertTrue(bindings.isEmpty());
-
- //We don't currently support hierarchies
- bindings = office.listBindingsForCondition("condition1.subcondition");
- assertNotNull(bindings);
- assertTrue(bindings.isEmpty());
-
- //We currently just do an exact match
- bindings = office.listBindingsForCondition("condition1");
- assertNotNull(bindings);
- assertEquals(4, bindings.size());
-
- Iterator iter = bindings.iterator();
- assertEquivalent((Binding)iter.next(), binding1);
- assertEquivalent((Binding)iter.next(), binding2);
- assertEquivalent((Binding)iter.next(), binding3);
- assertEquivalent((Binding)iter.next(), binding4);
-
- bindings = office.listBindingsForCondition("condition2");
- assertNotNull(bindings);
- assertEquals(4, bindings.size());
-
- iter = bindings.iterator();
- assertEquivalent((Binding)iter.next(), binding5);
- assertEquivalent((Binding)iter.next(), binding6);
- assertEquivalent((Binding)iter.next(), binding7);
- assertEquivalent((Binding)iter.next(), binding8);
- }
- finally
- {
- if (office != null)
- {
- office.stop();
- }
- }
-
- }
-
- public void testRouteNonPersistentWithFilter() throws Throwable
- {
- routeWithFilter(false);
- }
-
- public void testRoutePersistentWithFilter() throws Throwable
- {
- routeWithFilter(true);
- }
-
-
-
-
- public final void testRoutePersistent() throws Throwable
- {
- route(true);
- }
-
- public final void testRouteNonPersistent() throws Throwable
- {
- route(false);
- }
-
- public final void testRouteTransactionalPersistent() throws Throwable
- {
- routeTransactional(true);
- }
-
- public final void testRouteTransactionalNonPersistent() throws Throwable
- {
- routeTransactional(false);
- }
-
-
- public final void testRouteInactive() throws Throwable
- {
- PostOffice postOffice = null;
-
- try
- {
-
- postOffice = createPostOffice();
-
- PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding1 =
- postOffice.bindQueue("topic1", queue1);
-
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding2 =
- postOffice.bindQueue("topic1", queue2);
-
- PagingFilteredQueue queue3 = new PagingFilteredQueue("queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding3 =
- postOffice.bindQueue("topic1", queue3);
-
- PagingFilteredQueue queue4 = new PagingFilteredQueue("queue4", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding4 =
- postOffice.bindQueue("topic2", queue4);
-
- PagingFilteredQueue queue5 = new PagingFilteredQueue("queue5", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding5 =
- postOffice.bindQueue("topic2", queue5);
-
- PagingFilteredQueue queue6 = new PagingFilteredQueue("queue6", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding6 =
- postOffice.bindQueue("topic2", queue6);
-
- SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue1.add(receiver1);
- SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue2.add(receiver2);
- SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue3.add(receiver3);
- SimpleReceiver receiver4 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue4.add(receiver4);
- SimpleReceiver receiver5 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue5.add(receiver5);
- SimpleReceiver receiver6 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue6.add(receiver6);
-
- queue1.deactivate();
- queue2.deactivate();
- queue5.deactivate();
- queue6.deactivate();
-
- assertFalse(queue1.isActive());
- assertFalse(queue2.isActive());
- assertFalse(queue5.isActive());
- assertFalse(queue6.isActive());
- assertTrue(queue3.isActive());
- assertTrue(queue4.isActive());
-
- Message msg1 = CoreMessageFactory.createCoreMessage(1);
- MessageReference ref1 = ms.reference(msg1);
-
- boolean routed = postOffice.route(ref1, "topic1", null);
- assertTrue(routed);
-
- List msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver3.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- Message msgRec = (Message)msgs.get(0);
- assertTrue(msg1 == msgRec);
- receiver3.acknowledge(msgRec, null);
- msgs = queue3.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver4.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver5.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver6.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- receiver3.clear();
-
- Message msg2 = CoreMessageFactory.createCoreMessage(2);
- MessageReference ref2 = ms.reference(msg2);
-
- routed = postOffice.route(ref2, "topic2", null);
- assertTrue(routed);
-
- msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver3.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver4.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- msgRec = (Message)msgs.get(0);
- assertTrue(msg2 == msgRec);
- receiver4.acknowledge(msgRec, null);
- msgs = queue4.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver5.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver6.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
- }
- finally
- {
- if (postOffice != null)
- {
- postOffice.stop();
- }
- }
-
- }
-
- public final void testRouteNoBinding() throws Throwable
- {
- PostOffice postOffice = null;
-
- try
- {
- postOffice = createPostOffice();
-
- PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding1 =
- postOffice.bindQueue("condition1", queue1);
-
- SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
- queue1.add(receiver1);
-
- assertTrue(queue1.isActive());
-
- Message msg1 = CoreMessageFactory.createCoreMessage(1);
- MessageReference ref1 = ms.reference(msg1);
-
- boolean routed = postOffice.route(ref1, "this won't match anything", null);
-
- assertFalse(routed);
-
- List msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- }
- finally
- {
- if (postOffice != null)
- {
- postOffice.stop();
- }
- }
- }
-
-
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- protected void routeWithFilter(boolean persistentMessage) throws Throwable
- {
- PostOffice postOffice = null;
-
- try
- {
- postOffice = createPostOffice();
-
- SimpleFilter filter = new SimpleFilter(2);
-
- PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), filter);
-
- Binding binding1 =
- postOffice.bindQueue("topic1", queue1);
-
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding2 =
- postOffice.bindQueue("topic1", queue2);
-
- PagingFilteredQueue queue3 = new PagingFilteredQueue("queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding3 =
- postOffice.bindQueue("topic1", queue3);
-
- SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue1.add(receiver1);
- SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue2.add(receiver2);
- SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
- queue3.add(receiver3);
-
- Message msg1 = CoreMessageFactory.createCoreMessage(1);
- MessageReference ref1 = ms.reference(msg1);
- boolean routed = postOffice.route(ref1, "topic1", null);
- assertTrue(routed);
- Message msg2 = CoreMessageFactory.createCoreMessage(2);
- MessageReference ref2 = ms.reference(msg2);
- routed = postOffice.route(ref2, "topic1", null);
- assertTrue(routed);
- Message msg3 = CoreMessageFactory.createCoreMessage(3);
- MessageReference ref3 = ms.reference(msg3);
- routed = postOffice.route(ref3, "topic1", null);
- assertTrue(routed);
-
- List msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- Message msgRec = (Message)msgs.get(0);
- assertTrue(msg2 == msgRec);
- receiver1.acknowledge(msgRec, null);
- msgs = queue1.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertEquals(3, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- assertTrue(msg1 == msgRec1);
- Message msgRec2 = (Message)msgs.get(1);
- assertTrue(msg2 == msgRec2);
- Message msgRec3 = (Message)msgs.get(2);
- assertTrue(msg3 == msgRec3);
-
- receiver2.acknowledge(msgRec1, null);
- receiver2.acknowledge(msgRec2, null);
- receiver2.acknowledge(msgRec3, null);
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver3.getMessages();
- assertNotNull(msgs);
- assertEquals(3, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- assertTrue(msg1 == msgRec1);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msg2 == msgRec2);
- msgRec3 = (Message)msgs.get(2);
- assertTrue(msg3 == msgRec3);
-
- receiver3.acknowledge(msgRec1, null);
- receiver3.acknowledge(msgRec2, null);
- receiver3.acknowledge(msgRec3, null);
- msgs = queue3.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- }
- finally
- {
- if (postOffice != null)
- {
- postOffice.stop();
- }
- }
- }
-
- protected void route(boolean persistentMessage) throws Throwable
- {
- PostOffice postOffice = null;
-
- try
- {
- postOffice = createPostOffice();
-
- PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding1 =
- postOffice.bindQueue("topic1", queue1);
-
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding2 =
- postOffice.bindQueue("topic1", queue2);
-
- PagingFilteredQueue queue3 = new PagingFilteredQueue("queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding3 =
- postOffice.bindQueue("topic1", queue3);
-
- PagingFilteredQueue queue4 = new PagingFilteredQueue("queue4", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
-
- Binding binding4 =
- postOffice.bindQueue("topic2", queue4);
-
- PagingFilteredQueue queue5 = new PagingFilteredQueue("queue5", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
-
- Binding binding5 =
- postOffice.bindQueue("topic2", queue5);
-
- PagingFilteredQueue queue6 = new PagingFilteredQueue("queue6", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
-
- Binding binding6 =
- postOffice.bindQueue("topic2", queue6);
-
- SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
- queue1.add(receiver1);
- SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
- queue2.add(receiver2);
- SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
- queue3.add(receiver3);
- SimpleReceiver receiver4 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
- queue4.add(receiver4);
- SimpleReceiver receiver5 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
- queue5.add(receiver5);
- SimpleReceiver receiver6 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
- queue6.add(receiver6);
-
- assertTrue(queue1.isActive());
- assertTrue(queue2.isActive());
- assertTrue(queue3.isActive());
- assertTrue(queue4.isActive());
- assertTrue(queue5.isActive());
- assertTrue(queue6.isActive());
-
- Message msg1 = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);
- MessageReference ref1 = ms.reference(msg1);
-
- boolean routed = postOffice.route(ref1, "topic1", null);
- assertTrue(routed);
-
- List msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- Message msgRec = (Message)msgs.get(0);
- assertTrue(msg1 == msgRec);
- receiver1.acknowledge(msgRec, null);
- msgs = queue1.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- msgRec = (Message)msgs.get(0);
- assertTrue(msg1 == msgRec);
- receiver2.acknowledge(msgRec, null);
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver3.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- msgRec = (Message)msgs.get(0);
- assertTrue(msg1 == msgRec);
- receiver3.acknowledge(msgRec, null);
- msgs = queue3.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver4.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver5.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver6.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- receiver1.clear();
- receiver2.clear();
- receiver3.clear();
-
-
- Message msg2 = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);
- MessageReference ref2 = ms.reference(msg2);
-
- routed = postOffice.route(ref2, "topic2", null);
- assertTrue(routed);
-
- msgs = receiver4.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- msgRec = (Message)msgs.get(0);
- assertTrue(msg2 == msgRec);
- receiver4.acknowledge(msgRec, null);
- msgs = queue4.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver5.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- msgRec = (Message)msgs.get(0);
- assertTrue(msg2 == msgRec);
- receiver5.acknowledge(msgRec, null);
- msgs = queue5.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver6.getMessages();
- assertNotNull(msgs);
- assertEquals(1, msgs.size());
- msgRec = (Message)msgs.get(0);
- assertTrue(msg2 == msgRec);
- receiver6.acknowledge(msgRec, null);
- msgs = queue6.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = receiver3.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- }
- finally
- {
- if (postOffice != null)
- {
- postOffice.stop();
- }
- }
- }
-
- protected void routeTransactional(boolean persistentMessage) throws Throwable
- {
- PostOffice postOffice = null;
-
- try
- {
- postOffice = createPostOffice();
-
- PagingFilteredQueue queue1 = new PagingFilteredQueue("queue1", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
-
- Binding binding1 =
- postOffice.bindQueue("topic1", queue1);
-
- PagingFilteredQueue queue2 = new PagingFilteredQueue("queue2", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
-
- Binding binding2 =
- postOffice.bindQueue("topic1", queue2);
-
- SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
- queue1.add(receiver1);
-
- SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);;
- queue2.add(receiver2);
-
- assertTrue(queue1.isActive());
- assertTrue(queue2.isActive());
-
- Message msg1 = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);
- MessageReference ref1 = ms.reference(msg1);
-
- Message msg2 = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);
- MessageReference ref2 = ms.reference(msg2);
-
- Transaction tx = tr.createTransaction();
-
- boolean routed = postOffice.route(ref1, "topic1", tx);
- assertTrue(routed);
- routed = postOffice.route(ref2, "topic1", tx);
- assertTrue(routed);
-
- List msgs = queue1.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- tx.commit();
-
- msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- Message msgRec1 = (Message)msgs.get(0);
- Message msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg1);
- assertTrue(msgRec2 == msg2);
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg1);
- assertTrue(msgRec2 == msg2);
-
- //Acknowledge non transactionally
- receiver1.acknowledge(msgRec1, null);
- receiver1.acknowledge(msgRec2, null);
-
- receiver2.acknowledge(msgRec1, null);
- receiver2.acknowledge(msgRec2, null);
-
- msgs = queue1.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- receiver1.clear();
-
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- receiver2.clear();
-
- Message msg3 = CoreMessageFactory.createCoreMessage(3, persistentMessage, null);
- MessageReference ref3 = ms.reference(msg3);
-
- Message msg4 = CoreMessageFactory.createCoreMessage(4, persistentMessage, null);
- MessageReference ref4 = ms.reference(msg4);
-
- tx = tr.createTransaction();
-
- routed = postOffice.route(ref3, "topic1", tx);
- assertTrue(routed);
- routed = postOffice.route(ref4, "topic1", tx);
- assertTrue(routed);
-
- msgs = queue1.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- tx.rollback();
-
- msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- receiver1.clear();
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- receiver2.clear();
-
-
- Message msg5 = CoreMessageFactory.createCoreMessage(5, persistentMessage, null);
- MessageReference ref5 = ms.reference(msg5);
-
- Message msg6 = CoreMessageFactory.createCoreMessage(6, persistentMessage, null);
- MessageReference ref6 = ms.reference(msg6);
-
- routed = postOffice.route(ref5, "topic1", null);
- assertTrue(routed);
- routed = postOffice.route(ref6, "topic1", null);
- assertTrue(routed);
-
- msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg5);
- assertTrue(msgRec2 == msg6);
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg5);
- assertTrue(msgRec2 == msg6);
-
- //Acknowledge transactionally
-
- tx = tr.createTransaction();
-
- receiver1.acknowledge(msgRec1, tx);
- receiver1.acknowledge(msgRec2, tx);
-
- receiver2.acknowledge(msgRec1, tx);
- receiver2.acknowledge(msgRec2, tx);
-
- msgs = queue1.browse();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg5);
- assertTrue(msgRec2 == msg6);
-
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg5);
- assertTrue(msgRec2 == msg6);
-
- tx.commit();
-
- msgs = queue1.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- receiver1.clear();
-
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertTrue(msgs.isEmpty());
-
- receiver2.clear();
-
- Message msg7 = CoreMessageFactory.createCoreMessage(7, persistentMessage, null);
- MessageReference ref7 = ms.reference(msg7);
-
- Message msg8 = CoreMessageFactory.createCoreMessage(8, persistentMessage, null);
- MessageReference ref8 = ms.reference(msg8);
-
- routed = postOffice.route(ref7, "topic1", null);
- assertTrue(routed);
- routed = postOffice.route(ref8, "topic1", null);
- assertTrue(routed);
-
- msgs = receiver1.getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg7);
- assertTrue(msgRec2 == msg8);
-
- msgs = receiver2.getMessages();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg7);
- assertTrue(msgRec2 == msg8);
-
- //Acknowledge transactionally
-
- tx = tr.createTransaction();
-
- receiver1.acknowledge(msgRec1, tx);
- receiver1.acknowledge(msgRec2, tx);
-
- receiver2.acknowledge(msgRec1, tx);
- receiver2.acknowledge(msgRec2, tx);
-
- msgs = queue1.browse();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg7);
- assertTrue(msgRec2 == msg8);
-
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg7);
- assertTrue(msgRec2 == msg8);
-
- tx.rollback();
-
- msgs = queue1.browse();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg7);
- assertTrue(msgRec2 == msg8);
-
- msgs = queue2.browse();
- assertNotNull(msgs);
- assertEquals(2, msgs.size());
- msgRec1 = (Message)msgs.get(0);
- msgRec2 = (Message)msgs.get(1);
- assertTrue(msgRec1 == msg7);
- assertTrue(msgRec2 == msg8);
- }
- finally
- {
- if (postOffice != null)
- {
- postOffice.stop();
- }
- }
- }
-
- protected void assertEquivalent(Binding binding1, Binding binding2)
- {
- assertEquals(binding1.getNodeId(), binding2.getNodeId());
- assertEquals(binding1.getQueue().getName(), binding2.getQueue().getName());
- String selector1 = binding1.getQueue().getFilter() != null ? binding1.getQueue().getFilter().getFilterString() : null;
- String selector2 = binding2.getQueue().getFilter() != null ? binding2.getQueue().getFilter().getFilterString() : null;
- assertEquals(selector1, selector2);
- assertEquals(binding1.getQueue().getChannelID(), binding2.getQueue().getChannelID());
- assertEquals(binding1.getQueue().isRecoverable(), binding2.getQueue().isRecoverable());
- }
-
- protected PostOffice createPostOffice() throws Exception
- {
- FilterFactory ff = new SimpleFilterFactory();
-
- PostOfficeImpl postOffice =
- new PostOfficeImpl(sc.getDataSource(), sc.getTransactionManager(),
- null, true, "node1", "Simple", ms, pm, tr, ff, pool);
-
- postOffice.start();
-
- return postOffice;
- }
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
-
Modified: trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPostOfficeTest.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -31,17 +31,16 @@
import org.jboss.messaging.core.local.PagingFilteredQueue;
import org.jboss.messaging.core.plugin.contract.ClusteredPostOffice;
import org.jboss.messaging.core.plugin.postoffice.Binding;
-import org.jboss.messaging.core.plugin.postoffice.cluster.DefaultRedistributionPolicy;
+import org.jboss.messaging.core.plugin.postoffice.cluster.ClusterRouterFactory;
import org.jboss.messaging.core.plugin.postoffice.cluster.ClusteredPostOfficeImpl;
import org.jboss.messaging.core.plugin.postoffice.cluster.FavourLocalRouterFactory;
import org.jboss.messaging.core.plugin.postoffice.cluster.LocalClusteredQueue;
import org.jboss.messaging.core.plugin.postoffice.cluster.RedistributionPolicy;
-import org.jboss.messaging.core.plugin.postoffice.cluster.ClusterRouterFactory;
import org.jboss.messaging.core.tx.Transaction;
import org.jboss.test.messaging.core.SimpleFilter;
import org.jboss.test.messaging.core.SimpleFilterFactory;
import org.jboss.test.messaging.core.SimpleReceiver;
-import org.jboss.test.messaging.core.plugin.postoffice.SimplePostOfficeTest;
+import org.jboss.test.messaging.core.plugin.postoffice.DefaultPostOfficeTest;
import org.jboss.test.messaging.util.CoreMessageFactory;
import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
@@ -56,7 +55,7 @@
* $Id$
*
*/
-public class ClusteredPostOfficeTest extends SimplePostOfficeTest
+public class ClusteredPostOfficeTest extends DefaultPostOfficeTest
{
// Constants -----------------------------------------------------
@@ -405,7 +404,14 @@
{
if (office1 != null)
{
- office1.unbindClusteredQueue("sub6");
+ try
+ {
+ office1.unbindClusteredQueue("sub6");
+ }
+ catch (Exception ignore)
+ {
+
+ }
office1.stop();
}
@@ -591,7 +597,7 @@
Binding binding2 =
office2.bindClusteredQueue("topic1", queue2);
- LocalClusteredQueue queue3 = new LocalClusteredQueue("node3", "queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ LocalClusteredQueue queue3 = new LocalClusteredQueue("node2", "queue3", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
Binding binding3 =
office2.bindClusteredQueue("topic1", queue3);
@@ -615,6 +621,8 @@
routed = office1.route(ref3, "topic1", null);
assertTrue(routed);
+ Thread.sleep(1000);
+
List msgs = receiver1.getMessages();
assertNotNull(msgs);
assertEquals(1, msgs.size());
@@ -707,10 +715,10 @@
queues[7] = new LocalClusteredQueue("node1", "sub8", im.getId(), ms, pm, true, true, (QueuedExecutor)pool.get(), null);
bindings[7] = office1.bindClusteredQueue("topic1", queues[7]);
- queues[8] = new LocalClusteredQueue("node2", "sub9", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ queues[8] = new LocalClusteredQueue("node1", "sub9", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
bindings[8] = office1.bindClusteredQueue("topic2", queues[8]);
- queues[9] = new LocalClusteredQueue("node2", "sub10", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
+ queues[9] = new LocalClusteredQueue("node1", "sub10", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
bindings[9] = office1.bindClusteredQueue("topic2", queues[9]);
queues[10] = new LocalClusteredQueue("node2", "sub11", im.getId(), ms, pm, true, false, (QueuedExecutor)pool.get(), null);
@@ -811,12 +819,19 @@
{
if (office1 != null)
{
- office2.unbindClusteredQueue("sub5");
- office1.unbindClusteredQueue("sub7");
- office1.unbindClusteredQueue("sub8");
- office2.unbindClusteredQueue("sub13");
- office1.unbindClusteredQueue("sub15");
- office1.unbindClusteredQueue("sub16");
+ try
+ {
+ office2.unbindClusteredQueue("sub5");
+ office1.unbindClusteredQueue("sub7");
+ office1.unbindClusteredQueue("sub8");
+ office2.unbindClusteredQueue("sub13");
+ office1.unbindClusteredQueue("sub15");
+ office1.unbindClusteredQueue("sub16");
+ }
+ catch (Exception ignore)
+ {
+
+ }
office1.stop();
}
@@ -1440,8 +1455,8 @@
new ClusteredPostOfficeImpl(sc.getDataSource(), sc.getTransactionManager(),
null, true, nodeId, "Clustered", ms, pm, tr, ff, pool,
groupName,
- JGroupsUtil.getControlStackProperties(50, 1),
- JGroupsUtil.getDataStackProperties(50, 1),
+ JGroupsUtil.getControlStackProperties(),
+ JGroupsUtil.getDataStackProperties(),
5000, 5000, redistPolicy, 1000, rf);
postOffice.start();
Modified: trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/FavourLocalRouterTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/FavourLocalRouterTest.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/FavourLocalRouterTest.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -21,32 +21,25 @@
*/
package org.jboss.test.messaging.core.plugin.postoffice.cluster;
-import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import org.jboss.messaging.core.FilterFactory;
import org.jboss.messaging.core.Message;
import org.jboss.messaging.core.MessageReference;
-import org.jboss.messaging.core.local.PagingFilteredQueue;
import org.jboss.messaging.core.plugin.contract.ClusteredPostOffice;
import org.jboss.messaging.core.plugin.postoffice.Binding;
-import org.jboss.messaging.core.plugin.postoffice.cluster.DefaultRedistributionPolicy;
+import org.jboss.messaging.core.plugin.postoffice.cluster.ClusterRouterFactory;
import org.jboss.messaging.core.plugin.postoffice.cluster.ClusteredPostOfficeImpl;
import org.jboss.messaging.core.plugin.postoffice.cluster.FavourLocalRouterFactory;
import org.jboss.messaging.core.plugin.postoffice.cluster.LocalClusteredQueue;
import org.jboss.messaging.core.plugin.postoffice.cluster.RedistributionPolicy;
-import org.jboss.messaging.core.plugin.postoffice.cluster.ClusterRouterFactory;
-import org.jboss.messaging.core.tx.Transaction;
-import org.jboss.test.messaging.core.SimpleFilter;
import org.jboss.test.messaging.core.SimpleFilterFactory;
-import org.jboss.test.messaging.core.SimpleReceiver;
-import org.jboss.test.messaging.core.plugin.postoffice.SimplePostOfficeTest;
+import org.jboss.test.messaging.core.plugin.postoffice.DefaultPostOfficeTest;
import org.jboss.test.messaging.util.CoreMessageFactory;
import EDU.oswego.cs.dl.util.concurrent.QueuedExecutor;
-public class FavourLocalRouterTest extends SimplePostOfficeTest
+public class FavourLocalRouterTest extends DefaultPostOfficeTest
{
// Constants -----------------------------------------------------
@@ -158,8 +151,8 @@
new ClusteredPostOfficeImpl(sc.getDataSource(), sc.getTransactionManager(),
null, true, nodeId, "Clustered", ms, pm, tr, ff, pool,
groupName,
- JGroupsUtil.getControlStackProperties(50, 1),
- JGroupsUtil.getDataStackProperties(50, 1),
+ JGroupsUtil.getControlStackProperties(),
+ JGroupsUtil.getDataStackProperties(),
5000, 5000, redistPolicy, 1000, rf);
postOffice.start();
Modified: trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/JGroupsUtil.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/JGroupsUtil.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/JGroupsUtil.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -37,8 +37,7 @@
// Static --------------------------------------------------------
- public static String getDataStackProperties(int PING_timeout,
- int PING_num_initial_members)
+ public static String getDataStackProperties()
{
String host = System.getProperty("test.bind.address");
if (host == null)
@@ -47,14 +46,16 @@
}
return
- "UDP(mcast_addr=228.8.8.8;mcast_port=45566;ip_ttl=32;bind_addr=" + host + "):" +
- "PING(timeout=" + PING_timeout + ";num_initial_members=" + PING_num_initial_members + "):"+
- "FD(timeout=3000):"+
- "VERIFY_SUSPECT(timeout=1500):"+
- "pbcast.NAKACK(gc_lag=10;retransmit_timeout=600,1200,2400,4800):"+
- "pbcast.STABLE(desired_avg_gossip=10000):"+
- "FRAG:"+
- "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=true;print_local_addr=true)";
+ "UDP(mcast_addr=228.8.8.8;mcast_port=45566;ip_ttl=32;bind_addr=" + host + "):" +
+ "PING(timeout=2000;num_initial_members=3):"+
+ "FD(timeout=3000):"+
+ "VERIFY_SUSPECT(timeout=1500):"+
+ "pbcast.NAKACK(gc_lag=10;retransmit_timeout=600,1200,2400,4800):"+
+ "UNICAST(timeout=600,1200,2400,4800):"+
+ "pbcast.STABLE(desired_avg_gossip=10000):"+
+ "FRAG:"+
+ "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=true;print_local_addr=true)";
+
}
@@ -63,8 +64,7 @@
* The control stack is used for sending control messages and maintaining state
* It must be reliable and have the state protocol enabled
*/
- public static String getControlStackProperties(int PING_timeout,
- int PING_num_initial_members)
+ public static String getControlStackProperties()
{
String host = System.getProperty("test.bind.address");
if (host == null)
@@ -74,7 +74,7 @@
return
"UDP(mcast_addr=228.8.8.8;mcast_port=45568;ip_ttl=32;bind_addr=" + host + "):" +
- "PING(timeout=" + PING_timeout + ";num_initial_members=" + PING_num_initial_members + "):"+
+ "PING(timeout=2000;num_initial_members=3):"+
"FD(timeout=3000):"+
"VERIFY_SUSPECT(timeout=1500):"+
"pbcast.NAKACK(gc_lag=10;retransmit_timeout=600,1200,2400,4800):"+
Modified: trunk/tests/src/org/jboss/test/messaging/jms/ReferencingTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/ReferencingTest.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/tests/src/org/jboss/test/messaging/jms/ReferencingTest.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -77,8 +77,7 @@
super.setUp();
ServerManagement.start("all");
-
-
+
initialContext = new InitialContext(ServerManagement.getJNDIEnvironment());
cf = (JBossConnectionFactory)initialContext.lookup("/ConnectionFactory");
@@ -118,15 +117,17 @@
TextMessage m = sess.createTextMessage("wibble");
prod.send(m);
-
+
TextMessage m2 = (TextMessage)cons.receive();
-
+
assertNotNull(m2);
assertEquals(m.getText(), m2.getText());
MessageReference ref = store.reference(((MessageProxy)m2).getMessage().getMessageID());
assertNull(ref);
+
+ conn.close();
}
public void testAutoAck2() throws Exception
@@ -149,14 +150,18 @@
MessageConsumer cons = sess.createConsumer(queue);
- TextMessage m2 = (TextMessage)cons.receive();
+ TextMessage m2 = (TextMessage)cons.receive(1000);
+
assertNotNull(m2);
+
assertEquals(m.getText(), m2.getText());
MessageReference ref = store.reference(((MessageProxy)m2).getMessage().getMessageID());
assertNull(ref);
+
+ conn.close();
}
public void testClientAck1() throws Exception
@@ -177,7 +182,7 @@
prod.send(m);
- TextMessage m2 = (TextMessage)cons.receive();
+ TextMessage m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals(m.getText(), m2.getText());
@@ -193,6 +198,8 @@
ref = store.reference(((MessageProxy)m2).getMessage().getMessageID());
assertNull(ref);
+
+ conn.close();
}
public void testClientAck2() throws Exception
@@ -215,7 +222,7 @@
MessageConsumer cons = sess.createConsumer(queue);
- TextMessage m2 = (TextMessage)cons.receive();
+ TextMessage m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals(m.getText(), m2.getText());
@@ -231,6 +238,8 @@
ref = store.reference(((MessageProxy)m2).getMessage().getMessageID());
assertNull(ref);
+
+ conn.close();
}
public void testRedelivery() throws Exception
@@ -253,7 +262,7 @@
MessageConsumer cons = sess.createConsumer(queue);
- TextMessage m2 = (TextMessage)cons.receive();
+ TextMessage m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals(m.getText(), m2.getText());
@@ -282,6 +291,8 @@
ref = store.reference(((MessageProxy)m2).getMessage().getMessageID());
assertNull(ref);
+
+ conn.close();
}
public void testTransactionCommit() throws Exception
@@ -303,7 +314,7 @@
prod.send(m);
sess.commit();
- TextMessage m2 = (TextMessage)cons.receive();
+ TextMessage m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals(m.getText(), m2.getText());
@@ -320,6 +331,8 @@
ref = store.reference(((MessageProxy)m2).getMessage().getMessageID());
assertNull(ref);
+
+ conn.close();
}
public void testTransactionRollback() throws Exception
@@ -341,7 +354,7 @@
prod.send(m);
sess.commit();
- TextMessage m2 = (TextMessage)cons.receive();
+ TextMessage m2 = (TextMessage)cons.receive(1000);
assertNotNull(m2);
assertEquals(m.getText(), m2.getText());
@@ -367,6 +380,8 @@
ref = store.reference(((MessageProxy)m2).getMessage().getMessageID());
assertNull(ref);
+
+ conn.close();
}
public void cancelTest() throws Exception
@@ -389,7 +404,7 @@
prod.send(m1);
prod.send(m2);
- TextMessage m3 = (TextMessage)cons.receive();
+ TextMessage m3 = (TextMessage)cons.receive(1000);
assertNotNull(m3);
assertEquals(m1.getText(), m3.getText());
@@ -416,6 +431,8 @@
MessageReference ref = store.reference(((MessageProxy)m2).getMessage().getMessageID());
assertNull(ref);
+
+ conn.close();
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/tests/src/org/jboss/test/messaging/jms/SessionTest.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -140,6 +140,8 @@
assertNotNull(xid);
assertNull(cState.getResourceManager().getTx(xid));
+ conn.close();
+
}
public void testCreateProducer() throws Exception
@@ -167,6 +169,8 @@
TextMessage rm = (TextMessage)c.receive(1000);
assertEquals("something", rm.getText());
+
+ conn.close();
}
public void testCreateConsumer() throws Exception
@@ -218,6 +222,7 @@
}
catch (JMSException e)
{}
+ conn.close();
}
public void testCreateQueueOnATopicSession() throws Exception
@@ -234,6 +239,7 @@
{
// OK
}
+ c.close();
}
public void testCreateQueueWhileTopicWithSameNameExists() throws Exception
@@ -249,6 +255,7 @@
{
// OK
}
+ conn.close();
}
public void testCreateQueue() throws Exception
@@ -267,6 +274,7 @@
Message m2 = consumer.receive(3000);
assertNotNull(m2);
+ conn.close();
}
public void testCreateNonExistentTopic() throws Exception
@@ -282,6 +290,7 @@
{
// OK
}
+ conn.close();
}
public void testCreateTopicOnAQueueSession() throws Exception
@@ -298,6 +307,7 @@
{
// OK
}
+ c.close();
}
public void testCreateTopicWhileQueueWithSameNameExists() throws Exception
@@ -313,6 +323,7 @@
{
// OK
}
+ conn.close();
}
public void testCreateTopic() throws Exception
@@ -363,6 +374,8 @@
assertFalse(tr1.exceptionThrown);
assertNotNull(tr1.m);
+
+ conn.close();
}
public void testGetXAResource() throws Exception
@@ -432,6 +445,8 @@
// this test whether session's transacted state is correctly scoped per instance (by an
// interceptor or othewise)
assertFalse(sessionOne.getTransacted());
+
+ conn.close();
}
public void testCloseAndCreateSession() throws Exception
@@ -444,6 +459,8 @@
// this test whether session's closed state is correctly scoped per instance (by an
// interceptor or othewise)
s = c.createSession(true, -1);
+
+ c.close();
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java 2006-09-19 18:44:43 UTC (rev 1320)
+++ trunk/tests/src/org/jboss/test/messaging/jms/WireFormatTest.java 2006-09-19 19:17:09 UTC (rev 1321)
@@ -26,6 +26,7 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
+import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -44,6 +45,8 @@
import org.jboss.jms.server.endpoint.ClientDelivery;
import org.jboss.jms.server.remoting.JMSWireFormat;
import org.jboss.jms.server.remoting.MessagingMarshallable;
+import org.jboss.jms.server.remoting.MessagingObjectInputStream;
+import org.jboss.jms.server.remoting.MessagingObjectOutputStream;
import org.jboss.jms.tx.AckInfo;
import org.jboss.jms.tx.TransactionRequest;
import org.jboss.jms.tx.TxState;
@@ -273,7 +276,7 @@
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DataOutputStream oos = new DataOutputStream(bos);
+ MessagingObjectOutputStream oos = new MessagingObjectOutputStream(new DataOutputStream(bos));
wf.write(ir, oos);
@@ -283,34 +286,34 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
- DataInputStream ois = new DataInputStream(bis);
+ DataInputStream dis = new DataInputStream(bis);
//Check the bytes
//First byte should be version
- assertEquals(77, ois.readByte());
+ assertEquals(77, dis.readByte());
//First byte should be ACKNOWLEDGE
- assertEquals(JMSWireFormat.ACKNOWLEDGE, ois.readByte());
+ assertEquals(JMSWireFormat.ACKNOWLEDGE, dis.readByte());
//Next int should be objectId
- assertEquals(objectId, ois.readInt());
+ assertEquals(objectId, dis.readInt());
//Next long should be methodHash
- assertEquals(methodHash, ois.readLong());
+ assertEquals(methodHash, dis.readLong());
//Next should be the externalized AckInfo
AckInfo ack2 = new AckInfo();
+
+ ack2.read(dis);
- ack2.read(ois);
-
assertEquals(ack.getMessageID(), ack2.getMessageID());
assertEquals(ack.getConsumerID(), ack2.getConsumerID());
//Now eos
try
{
- ois.readByte();
+ dis.readByte();
fail("End of stream expected");
}
catch (EOFException e)
@@ -320,7 +323,7 @@
bis.reset();
- ois = new DataInputStream(bis);
+ ObjectInputStream ois = new MessagingObjectInputStream(new DataInputStream(bis));
InvocationRequest ir2 = (InvocationRequest)wf.read(ois, null);
More information about the jboss-cvs-commits
mailing list