[jboss-cvs] JBoss Messaging SVN: r5590 - in trunk: src/main/org/jboss/messaging/core/management and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jan 7 08:24:12 EST 2009
Author: ataylor
Date: 2009-01-07 08:24:12 -0500 (Wed, 07 Jan 2009)
New Revision: 5590
Modified:
trunk/build-messaging.xml
trunk/src/main/org/jboss/messaging/core/management/ManagementService.java
trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
trunk/src/main/org/jboss/messaging/core/postoffice/Address.java
trunk/src/main/org/jboss/messaging/core/postoffice/AddressManager.java
trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/AddressImpl.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/SimpleAddressManager.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java
trunk/tests/src/org/jboss/messaging/tests/integration/wildcard/WildCardRoutingTest.java
trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
Log:
wildcard fix - made more scalable only adding permutations when needed.
Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/build-messaging.xml 2009-01-07 13:24:12 UTC (rev 5590)
@@ -614,6 +614,7 @@
<include name="org/jboss/messaging/core/version/**/*.class"/>
<include name="org/jboss/messaging/core/management/**/*.class"/>
<!-- FIXME - why are these classes in the client jar ??? -->
+ <include name="org/jboss/messaging/core/server/MessagingComponent.class"/>
<include name="org/jboss/messaging/core/server/JournalType.class"/>
<include name="org/jboss/messaging/core/journal/EncodingSupport.class"/>
<include name="org/jboss/messaging/core/server/ServerMessage.class"/>
@@ -1015,6 +1016,8 @@
<formatter type="plain" usefile="${junit.formatter.usefile}"/>
<fileset dir="${test.classes.dir}">
<include name="${tests.param}"/>
+ <exclude name="**/**/MultiThreadRandomFailoverTest.class"/>
+ <exclude name="**/**/RandomFailoverTest.class"/>
</fileset>
</batchtest>
</junit>
Modified: trunk/src/main/org/jboss/messaging/core/management/ManagementService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/ManagementService.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/src/main/org/jboss/messaging/core/management/ManagementService.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -22,10 +22,6 @@
package org.jboss.messaging.core.management;
-import java.util.Set;
-
-import javax.management.ObjectName;
-
import org.jboss.messaging.core.client.management.impl.ManagementHelper;
import org.jboss.messaging.core.cluster.DiscoveryGroup;
import org.jboss.messaging.core.config.Configuration;
@@ -51,6 +47,9 @@
import org.jboss.messaging.util.SimpleString;
import org.jboss.messaging.util.TypedProperties;
+import javax.management.ObjectName;
+import java.util.Set;
+
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
*
@@ -124,4 +123,5 @@
*/
void sendNotification(NotificationType type, String message, TypedProperties props) throws Exception;
+ void enableNotifications(boolean enable);
}
Modified: trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -24,23 +24,6 @@
package org.jboss.messaging.core.management.impl;
-import static javax.management.ObjectName.quote;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.MBeanServer;
-import javax.management.NotificationBroadcasterSupport;
-import javax.management.ObjectName;
-import javax.management.StandardMBean;
-
import org.jboss.messaging.core.client.management.impl.ManagementHelper;
import org.jboss.messaging.core.cluster.DiscoveryGroup;
import org.jboss.messaging.core.config.Configuration;
@@ -69,7 +52,6 @@
import org.jboss.messaging.core.remoting.impl.ByteBufferWrapper;
import org.jboss.messaging.core.remoting.spi.Acceptor;
import org.jboss.messaging.core.security.Role;
-import org.jboss.messaging.core.server.MessageReference;
import org.jboss.messaging.core.server.MessagingServer;
import org.jboss.messaging.core.server.Queue;
import org.jboss.messaging.core.server.ServerMessage;
@@ -82,6 +64,21 @@
import org.jboss.messaging.util.SimpleString;
import org.jboss.messaging.util.TypedProperties;
+import javax.management.MBeanServer;
+import javax.management.NotificationBroadcasterSupport;
+import javax.management.ObjectName;
+import static javax.management.ObjectName.quote;
+import javax.management.StandardMBean;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/*
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
*
@@ -121,6 +118,8 @@
private boolean started = false;
+ private boolean noticationsEnabled;
+
// Static --------------------------------------------------------
public static ObjectName getMessagingServerObjectName() throws Exception
@@ -176,6 +175,7 @@
this.jmxManagementEnabled = jmxManagementEnabled;
registry = new HashMap<ObjectName, Object>();
broadcaster = new NotificationBroadcasterSupport();
+ noticationsEnabled = true;
}
// Public --------------------------------------------------------
@@ -481,7 +481,7 @@
public void sendNotification(final NotificationType type, final String message, TypedProperties props) throws Exception
{
// TODO - we need a parameter to determine if the notification is durable or not
- if (managedServer != null)
+ if (managedServer != null && noticationsEnabled)
{
ServerMessage notificationMessage = new ServerMessageImpl(storageManager.generateUniqueID());
notificationMessage.setDestination(managementNotificationAddress);
@@ -514,6 +514,11 @@
}
}
+ public void enableNotifications(boolean enabled)
+ {
+ noticationsEnabled = enabled;
+ }
+
public Object getAttribute(final String objectNameStr, final String attribute)
{
try
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/Address.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/Address.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/Address.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -21,10 +21,10 @@
*/
package org.jboss.messaging.core.postoffice;
+import org.jboss.messaging.util.SimpleString;
+
import java.util.List;
-import org.jboss.messaging.util.SimpleString;
-
/**
* USed to hold a hierarchichal style address, delimited by a '.'.
*
@@ -42,7 +42,9 @@
void addLinkedAddress(Address address);
- void removLinkedAddress(Address actualAddress);
+ void removeLinkedAddress(Address actualAddress);
void removeAddressPart(int pos);
+
+ boolean matches(Address add);
}
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/AddressManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/AddressManager.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/AddressManager.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -21,14 +21,14 @@
*/
package org.jboss.messaging.core.postoffice;
+import org.jboss.messaging.util.SimpleString;
+
import java.util.Map;
import java.util.Set;
-import org.jboss.messaging.util.SimpleString;
-
/**
* Used to maintain addresses and Bindings.
- *
+ *
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
* @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
@@ -58,6 +58,4 @@
Binding getBinding(SimpleString queueName);
Map<SimpleString, Binding> getBindings();
-
- int numMappings();
}
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -22,9 +22,6 @@
package org.jboss.messaging.core.postoffice;
-import java.util.List;
-import java.util.Set;
-
import org.jboss.messaging.core.filter.Filter;
import org.jboss.messaging.core.paging.PagingManager;
import org.jboss.messaging.core.server.MessagingComponent;
@@ -34,6 +31,9 @@
import org.jboss.messaging.core.transaction.Transaction;
import org.jboss.messaging.util.SimpleString;
+import java.util.List;
+import java.util.Set;
+
/**
*
* A PostOffice instance maintains a mapping of a String address to a Queue. Multiple Queue instances can be bound
@@ -95,6 +95,4 @@
SendLock getAddressLock(SimpleString address);
DuplicateIDCache getDuplicateIDCache(SimpleString address);
-
- int numMappings();
}
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/AddressImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/AddressImpl.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/AddressImpl.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -21,17 +21,20 @@
*/
package org.jboss.messaging.core.postoffice.impl;
+import org.jboss.messaging.core.postoffice.Address;
+import static org.jboss.messaging.core.postoffice.impl.WildcardAddressManager.ANY_WORDS;
+import static org.jboss.messaging.core.postoffice.impl.WildcardAddressManager.ANY_WORDS_SIMPLESTRING;
import static org.jboss.messaging.core.postoffice.impl.WildcardAddressManager.DELIM;
import static org.jboss.messaging.core.postoffice.impl.WildcardAddressManager.SINGLE_WORD;
-import static org.jboss.messaging.core.postoffice.impl.WildcardAddressManager.ANY_WORDS;
+import static org.jboss.messaging.core.postoffice.impl.WildcardAddressManager.SINGLE_WORD_SIMPLESTRING;
+import org.jboss.messaging.util.SimpleString;
import java.util.ArrayList;
import java.util.List;
-import org.jboss.messaging.core.postoffice.Address;
-import org.jboss.messaging.util.SimpleString;
-
-/**splits an address string into its hierarchical parts split by '.'
+/**
+ * splits an address string into its hierarchical parts split by '.'
+ *
* @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
*/
public class AddressImpl implements Address
@@ -41,6 +44,7 @@
private SimpleString[] addressParts;
private boolean containsWildCard;
+
private List<Address> linkedAddresses = new ArrayList<Address>();
public AddressImpl(final SimpleString address)
@@ -75,7 +79,7 @@
linkedAddresses.add(address);
}
- public void removLinkedAddress(Address actualAddress)
+ public void removeLinkedAddress(Address actualAddress)
{
linkedAddresses.remove(actualAddress);
}
@@ -83,18 +87,18 @@
public void removeAddressPart(final int pos)
{
SimpleString newAddress = new SimpleString("");
- boolean started=false;
+ boolean started = false;
for (int i = 0; i < addressParts.length; i++)
{
SimpleString addressPart = addressParts[i];
- if(i != pos)
+ if (i != pos)
{
- if(started)
+ if (started)
{
newAddress = newAddress.concat('.');
}
newAddress = newAddress.concat(addressPart);
- started=true;
+ started = true;
}
}
this.address = newAddress;
@@ -102,14 +106,91 @@
containsWildCard = address.contains(SINGLE_WORD);
}
+ public boolean matches(final Address add)
+ {
+ if (containsWildCard == add.containsWildCard())
+ {
+ return false;
+ }
+ int pos = 0;
+ int matchPos = 0;
+
+ SimpleString nextToMatch;
+ for (; matchPos < add.getAddressParts().length;)
+ {
+ SimpleString curr = addressParts[pos];
+ SimpleString next = addressParts.length > pos + 1 ? addressParts[pos + 1] : null;
+ SimpleString currMatch = add.getAddressParts()[matchPos];
+ if (currMatch.equals(SINGLE_WORD_SIMPLESTRING))
+ {
+ pos++;
+ matchPos++;
+ }
+ else if (currMatch.equals(ANY_WORDS_SIMPLESTRING))
+ {
+ if (matchPos == addressParts.length - 1)
+ {
+ pos++;
+ matchPos++;
+ }
+ else if (next == null)
+ {
+ return false;
+ }
+ else if (matchPos == add.getAddressParts().length - 1)
+ {
+ return true;
+ }
+ else
+ {
+ nextToMatch = add.getAddressParts()[matchPos + 1];
+ while (curr != null)
+ {
+ if (curr.equals(nextToMatch))
+ {
+ break;
+ }
+ pos++;
+ curr = next;
+ next = addressParts.length > pos + 1 ? addressParts[pos + 1] : null;
+ }
+ if (curr == null)
+ {
+ return false;
+ }
+ matchPos++;
+ }
+ }
+ else
+ {
+ if (!curr.equals(currMatch))
+ {
+ return false;
+ }
+ pos++;
+ matchPos++;
+ }
+ }
+ return pos == addressParts.length;
+ }
+
public boolean equals(Object o)
{
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
AddressImpl address1 = (AddressImpl) o;
- if (!address.equals(address1.address)) return false;
+ if (!address.equals(address1.address))
+ {
+ return false;
+ }
return true;
}
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -22,17 +22,6 @@
package org.jboss.messaging.core.postoffice.impl;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.filter.Filter;
import org.jboss.messaging.core.logging.Logger;
@@ -60,6 +49,17 @@
import org.jboss.messaging.util.Pair;
import org.jboss.messaging.util.SimpleString;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
/**
* A PostOfficeImpl
*
@@ -448,11 +448,6 @@
return cache;
}
- public int numMappings()
- {
- return addressManager.numMappings();
- }
-
// Private -----------------------------------------------------------------
private Binding createQueueBinding(final SimpleString name,
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/SimpleAddressManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/SimpleAddressManager.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/SimpleAddressManager.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -21,11 +21,6 @@
*/
package org.jboss.messaging.core.postoffice.impl;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
import org.jboss.messaging.core.postoffice.AddressManager;
import org.jboss.messaging.core.postoffice.Binding;
import org.jboss.messaging.core.postoffice.Bindings;
@@ -33,6 +28,11 @@
import org.jboss.messaging.util.ConcurrentSet;
import org.jboss.messaging.util.SimpleString;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
/**
* A simple address manager that maintains the addresses and bindings.
*
@@ -59,31 +59,29 @@
public boolean addMapping(final SimpleString address, final Binding binding)
{
Bindings bindings = mappings.get(address);
-
+
Bindings prevBindings = null;
-
+
if (bindings == null)
{
bindings = new BindingsImpl();
-
+
prevBindings = mappings.putIfAbsent(address, bindings);
-
+
if (prevBindings != null)
{
bindings = prevBindings;
}
}
-
+
bindings.addBinding(binding);
-
+
return prevBindings != null;
}
-
+
public Bindings getBindings(final SimpleString address)
{
- Bindings bindings = mappings.get(address);
-
- return bindings;
+ return mappings.get(address);
}
public boolean addDestination(final SimpleString address)
@@ -123,11 +121,6 @@
mappings.clear();
}
- public int numMappings()
- {
- return mappings.size();
- }
-
public Binding removeBinding(final SimpleString bindableName)
{
Binding binding = nameMap.remove(bindableName);
@@ -142,26 +135,26 @@
public boolean removeMapping(final SimpleString address, final SimpleString bindableName)
{
Bindings bindings = mappings.get(address);
-
+
if (bindings != null)
{
removeMapping(bindableName, bindings);
-
+
if (bindings.getBindings().isEmpty())
{
mappings.remove(address);
}
-
+
return true;
- }
-
+ }
+
return false;
}
protected Binding removeMapping(final SimpleString bindableName, final Bindings bindings)
{
Binding theBinding = null;
-
+
for (Binding binding: bindings.getBindings())
{
if (binding.getBindable().getName().equals(bindableName))
@@ -178,7 +171,7 @@
}
bindings.removeBinding(theBinding);
-
+
return theBinding;
}
}
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/WildcardAddressManager.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -21,19 +21,18 @@
*/
package org.jboss.messaging.core.postoffice.impl;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.postoffice.Address;
import org.jboss.messaging.core.postoffice.Binding;
import org.jboss.messaging.core.postoffice.Bindings;
import org.jboss.messaging.util.SimpleString;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
- * extends the simple manager to allow wilcard addresses to be used.
+ * extends the simple manager to allow wildcard addresses to be used.
*
* @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
*/
@@ -52,11 +51,40 @@
static final SimpleString ANY_WORDS_SIMPLESTRING = new SimpleString("#");
/**
- * This is all the addresses, we use this so we can link back from the actual address to its linked wilcard addresses
+ * These are all the addresses, we use this so we can link back from the actual address to its linked wilcard addresses
* or vice versa
*/
private final Map<SimpleString, Address> addresses = new HashMap<SimpleString, Address>();
+ private final Map<SimpleString, Address> wildCardAddresses = new HashMap<SimpleString, Address>();
+
+ public Bindings getBindings(final SimpleString address)
+ {
+ Bindings bindings = super.getBindings(address);
+ //this should only happen if we're routing to an address that has no mappings when we're running checkAllowable
+ if (bindings == null && !wildCardAddresses.isEmpty())
+ {
+ Address add = addAndUpdateAddressMap(address);
+ if (!add.containsWildCard())
+ {
+ for (Address destAdd : add.getLinkedAddresses())
+ {
+ Bindings b = super.getBindings(destAdd.getAddress());
+ if (b != null)
+ {
+ List<Binding> theBindings = b.getBindings();
+ for (Binding theBinding : theBindings)
+ {
+ super.addMapping(address, theBinding);
+ }
+ }
+ }
+ }
+ bindings = super.getBindings(address);
+ }
+ return bindings;
+ }
+
/**
* If the address to add the binding to contains a wildcard then a copy of the binding (with the same underlying queue)
* will be added to the actual mappings. Otherwise the binding is added as normal.
@@ -67,67 +95,83 @@
*/
public boolean addMapping(final SimpleString address, final Binding binding)
{
- Address add = addAndUpdateAddressMap(address);
- if (!add.containsWildCard())
+ boolean exists = super.addMapping(address, binding);
+ if (!exists)
{
- for (Address destination : add.getLinkedAddresses())
+ Address add = addAndUpdateAddressMap(address);
+ if (add.containsWildCard())
{
- Bindings bindings = getBindings(destination.getAddress());
- if (bindings != null)
+ for (Address destAdd : add.getLinkedAddresses())
{
+ super.addMapping(destAdd.getAddress(), binding);
+ }
+ }
+ else
+ {
+ for (Address destAdd : add.getLinkedAddresses())
+ {
+ Bindings bindings = super.getBindings(destAdd.getAddress());
for (Binding b : bindings.getBindings())
{
super.addMapping(address, b);
}
}
}
- return super.addMapping(address, binding);
}
- else
- {
- for (Address destination : add.getLinkedAddresses())
- {
- BindingImpl binding1 = new BindingImpl(binding.getType(), destination.getAddress(), binding.getBindable(), binding.isExclusive());
- super.addMapping(destination.getAddress(), binding1);
- }
- return super.addMapping(address, binding);
- }
+ return exists;
}
+
/**
* If the address is a wild card then the binding will be removed from the actual mappings for any linked address.
* otherwise it will be removed as normal.
*
- * @param address the address to remove the binding from
+ * @param address the address to remove the binding from
* @param bindableName the name of the queue for the binding to remove
* @return true if this was the last mapping for a specific address
*/
public boolean removeMapping(final SimpleString address, final SimpleString bindableName)
{
- Address add = removeAndUpdateAddressMap(address);
- if (!add.containsWildCard())
+ boolean removed = super.removeMapping(address, bindableName);
+ if (removed)
{
- boolean removed = super.removeMapping(address, bindableName);
- for (Address destination : add.getLinkedAddresses())
+ Address add = getAddress(address);
+ if (!add.containsWildCard())
{
- Bindings bindings = getBindings(destination.getAddress());
- if (bindings != null)
+ for (Address destination : add.getLinkedAddresses())
{
- for (Binding b : bindings.getBindings())
+ Bindings bindings = super.getBindings(destination.getAddress());
+ if (bindings != null)
{
- super.removeMapping(address, b.getBindable().getName());
+ for (Binding b : bindings.getBindings())
+ {
+ super.removeMapping(address, b.getBindable().getName());
+ }
}
}
}
- return removed;
+ else
+ {
+ for (Address destination : add.getLinkedAddresses())
+ {
+ super.removeMapping(destination.getAddress(), bindableName);
+ }
+ }
+ removeAndUpdateAddressMap(add);
}
+ return removed;
+ }
+
+ public boolean containsDestination(final SimpleString address)
+ {
+ Address add = new AddressImpl(address);
+ if (add.containsWildCard())
+ {
+ return true;
+ }
else
{
- for (Address destination : add.getLinkedAddresses())
- {
- super.removeMapping(destination.getAddress(), bindableName);
- }
- return super.removeMapping(address, bindableName);
+ return super.containsDestination(address);
}
}
@@ -135,152 +179,108 @@
{
super.clear();
addresses.clear();
+ wildCardAddresses.clear();
}
- private synchronized Address addAndUpdateAddressMap(SimpleString address)
- {
- Address add = addresses.get(address);
- if (add == null)
+ private Address getAddress(final SimpleString address)
+ {
+ Address add = new AddressImpl(address);
+ Address actualAddress;
+ if (add.containsWildCard())
{
- add = new AddressImpl(address);
- addresses.put(address, add);
+ actualAddress = wildCardAddresses.get(address);
}
- if (!add.containsWildCard())
+ else
{
- List<SimpleString> adds = getAddresses(add);
- for (SimpleString simpleString : adds)
- {
- Address addressToAdd = addresses.get(simpleString);
- if (addressToAdd == null)
- {
- addressToAdd = new AddressImpl(simpleString);
- addresses.put(simpleString, addressToAdd);
- }
- addressToAdd.addLinkedAddress(add);
- add.addLinkedAddress(addressToAdd);
- }
+ actualAddress = addresses.get(address);
}
- return add;
+ return actualAddress != null ? actualAddress : add;
}
- private synchronized Address removeAndUpdateAddressMap(SimpleString address)
+ private synchronized Address addAndUpdateAddressMap(final SimpleString address)
{
- Address add = addresses.get(address);
- if (add == null)
+ Address add = new AddressImpl(address);
+ Address actualAddress;
+ if (add.containsWildCard())
{
- return new AddressImpl(address);
+ actualAddress = wildCardAddresses.get(address);
}
- if (!add.containsWildCard())
+ else
{
- Bindings bindings1 = getBindings(address);
- if (bindings1 == null || bindings1.getBindings().size() == 0)
+ actualAddress = addresses.get(address);
+ }
+ if (actualAddress == null)
+ {
+ actualAddress = add;
+ addAddress(address, actualAddress);
+ }
+ if (actualAddress.containsWildCard())
+ {
+ for (Address destAdd : addresses.values())
{
- add = addresses.remove(address);
+ if (destAdd.matches(actualAddress))
+ {
+ destAdd.addLinkedAddress(actualAddress);
+ actualAddress.addLinkedAddress(destAdd);
+ }
}
- List<Address> addresses = add.getLinkedAddresses();
- for (Address address1 : addresses)
+ }
+ else
+ {
+ for (Address destAdd : wildCardAddresses.values())
{
- address1.removLinkedAddress(add);
- if (address1.getLinkedAddresses().size() == 0)
+ if (actualAddress.matches(destAdd))
{
- this.addresses.remove(address1.getAddress());
+ destAdd.addLinkedAddress(actualAddress);
+ actualAddress.addLinkedAddress(destAdd);
+
}
}
}
- return add;
+ return actualAddress;
}
- private List<SimpleString> getAddresses(final Address address)
- {
- List<SimpleString> addresses = new ArrayList<SimpleString>();
- SimpleString[] parts = address.getAddressParts();
-
- addresses.add(parts[0]);
- addresses.add(SINGLE_WORD_SIMPLESTRING);
- addresses.add(ANY_WORDS_SIMPLESTRING);
- if (address.getAddressParts().length > 1)
- {
- addresses = addPart(addresses, address, 1);
-
- }
- addresses.remove(address.getAddress());
-
- return addresses;
- }
-
- private List<SimpleString> addPart(final List<SimpleString> addresses, final Address address, final int pos)
- {
- List<SimpleString> newAddresses = new ArrayList<SimpleString>();
- for (SimpleString add : addresses)
- {
- newAddresses.add(add.concat(DELIM).concat(SINGLE_WORD));
- newAddresses.add(add.concat(DELIM).concat(ANY_WORDS));
- newAddresses.add(add.concat(DELIM).concat(address.getAddressParts()[pos]));
- }
- if (pos + 1 < address.getAddressParts().length)
+ private void addAddress(final SimpleString address, final Address actualAddress)
+ {
+ if (actualAddress.containsWildCard())
{
- return addPart(newAddresses, address, pos + 1);
+ wildCardAddresses.put(address, actualAddress);
}
else
{
- return mergeAddresses(newAddresses);
+ addresses.put(address, actualAddress);
}
}
- private List<SimpleString> mergeAddresses(final List<SimpleString> adds)
+ private synchronized void removeAndUpdateAddressMap(final Address address)
{
- List<SimpleString> newAddresses = new ArrayList<SimpleString>();
- for (int j = 0; j < adds.size(); j++)
+ //we only remove if there are no bindings left
+ Bindings bindings = super.getBindings(address.getAddress());
+ if (bindings == null || bindings.getBindings().size() == 0)
{
- SimpleString add = adds.get(j);
- Address address = new AddressImpl(add);
- SimpleString prev = null;
- SimpleString next;
- for (int i = 0; i < address.getAddressParts().length; i++)
+ List<Address> addresses = address.getLinkedAddresses();
+ for (Address address1 : addresses)
{
- SimpleString current = address.getAddressParts()[i];
- if (i < address.getAddressParts().length - 1)
+ address1.removeLinkedAddress(address);
+ Bindings linkedBindings = super.getBindings(address1.getAddress());
+ if (linkedBindings == null || linkedBindings.getBindings().size() == 0)
{
- next = address.getAddressParts()[i + 1];
+ removeAddress(address1);
}
- else
- {
- next = null;
- }
- if (current.equals(SINGLE_WORD_SIMPLESTRING) && (ANY_WORDS_SIMPLESTRING.equals(next)))
- {
- address.removeAddressPart(i);
- prev = null;
- i = -1;
- }
- else if (current.equals(ANY_WORDS_SIMPLESTRING) && (ANY_WORDS_SIMPLESTRING.equals(next)))
- {
- address.removeAddressPart(i);
- prev = null;
- i = -1;
- }
- else if (current.equals(ANY_WORDS_SIMPLESTRING) && (SINGLE_WORD_SIMPLESTRING.equals(next)))
- {
- address.removeAddressPart(i + 1);
- prev = null;
- i = -1;
- }
- else if (current.equals(ANY_WORDS_SIMPLESTRING) && (ANY_WORDS_SIMPLESTRING.equals(prev)))
- {
- address.removeAddressPart(i + 1);
- prev = null;
- i = -1;
- }
- else
- {
- prev = current;
- }
}
- if (!newAddresses.contains(address.getAddress()))
- {
- newAddresses.add(address.getAddress());
- }
+ removeAddress(address);
}
- return newAddresses;
}
+
+ private void removeAddress(final Address add)
+ {
+ if (add.containsWildCard())
+ {
+ wildCardAddresses.remove(add.getAddress());
+ }
+ else
+ {
+ addresses.remove(add.getAddress());
+ }
+ }
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/wildcard/WildCardRoutingTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/wildcard/WildCardRoutingTest.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/wildcard/WildCardRoutingTest.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -21,18 +21,18 @@
*/
package org.jboss.messaging.tests.integration.wildcard;
-import org.jboss.messaging.tests.util.UnitTestCase;
-import org.jboss.messaging.core.server.MessagingService;
-import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.client.ClientConsumer;
import org.jboss.messaging.core.client.ClientSessionFactory;
-import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.TransportConfiguration;
import org.jboss.messaging.core.config.impl.ConfigurationImpl;
-import org.jboss.messaging.core.config.TransportConfiguration;
import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.server.MessagingService;
+import org.jboss.messaging.core.server.impl.MessagingServiceImpl;
+import org.jboss.messaging.tests.util.UnitTestCase;
import org.jboss.messaging.util.SimpleString;
/**
@@ -73,6 +73,76 @@
assertNull(m);
}
+ public void testBasicWildcardRoutingQueuesDontExist() throws Exception
+ {
+ SimpleString addressAB = new SimpleString("a.b");
+ SimpleString addressAC = new SimpleString("a.c");
+ SimpleString address = new SimpleString("a.*");
+ SimpleString queueName = new SimpleString("Q");
+ clientSession.createQueue(address, queueName, null, false, false);
+ ClientProducer producer = clientSession.createProducer(addressAB);
+ ClientProducer producer2 = clientSession.createProducer(addressAC);
+ ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
+ clientSession.start();
+ producer.send(createTextMessage("m1", clientSession));
+ producer2.send(createTextMessage("m2", clientSession));
+ ClientMessage m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m1", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m2", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNull(m);
+ clientConsumer.close();
+ clientSession.deleteQueue(queueName);
+
+ assertEquals(0, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAB).getBindings().size());
+ assertEquals(0, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAC).getBindings().size());
+ assertEquals(0, messagingService.getServer().getPostOffice().getBindingsForAddress(address).getBindings().size());
+ }
+
+ public void testBasicWildcardRoutingQueuesDontExist2() throws Exception
+ {
+ SimpleString addressAB = new SimpleString("a.b");
+ SimpleString addressAC = new SimpleString("a.c");
+ SimpleString address = new SimpleString("a.*");
+ SimpleString queueName = new SimpleString("Q");
+ SimpleString queueName2 = new SimpleString("Q2");
+ clientSession.createQueue(address, queueName, null, false, false);
+ clientSession.createQueue(address, queueName2, null, false, false);
+ ClientProducer producer = clientSession.createProducer(addressAB);
+ ClientProducer producer2 = clientSession.createProducer(addressAC);
+ ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
+ clientSession.start();
+ producer.send(createTextMessage("m1", clientSession));
+ producer2.send(createTextMessage("m2", clientSession));
+ ClientMessage m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m1", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m2", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNull(m);
+ clientConsumer.close();
+ clientSession.deleteQueue(queueName);
+
+ assertEquals(1, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAB).getBindings().size());
+ assertEquals(1, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAC).getBindings().size());
+ assertEquals(1, messagingService.getServer().getPostOffice().getBindingsForAddress(address).getBindings().size());
+
+ clientSession.deleteQueue(queueName2);
+
+ assertEquals(0, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAB).getBindings().size());
+ assertEquals(0, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAC).getBindings().size());
+ assertEquals(0, messagingService.getServer().getPostOffice().getBindingsForAddress(address).getBindings().size());
+ }
+
public void testBasicWildcardRoutingWithHash() throws Exception
{
SimpleString addressAB = new SimpleString("a.b");
@@ -178,15 +248,21 @@
ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
clientSession.start();
clientSession.deleteQueue(queueName1);
- assertEquals(messagingService.getServer().getPostOffice().getBindingsForAddress(addressAB).getBindings().size(), 0);
+ //the wildcard binding should still exist
+ assertEquals(messagingService.getServer().getPostOffice().getBindingsForAddress(addressAB).getBindings().size(), 1);
producer.send(createTextMessage("m1", clientSession));
producer2.send(createTextMessage("m2", clientSession));
ClientMessage m = clientConsumer.receive(500);
assertNotNull(m);
+ assertEquals("m1", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNotNull(m);
assertEquals("m2", m.getBody().getString());
m.acknowledge();
- m = clientConsumer.receive(500);
- assertNull(m);
+ clientConsumer.close();
+ clientSession.deleteQueue(queueName);
+ assertEquals(messagingService.getServer().getPostOffice().getBindingsForAddress(addressAB).getBindings().size(), 0);
}
public void testWildcardRoutingLotsOfQueuesAddedThenDeleted() throws Exception
@@ -282,11 +358,8 @@
clientSession.deleteQueue(queueName7);
clientSession.deleteQueue(queueName8);
clientSession.deleteQueue(queueName9);
- //there should only be the wilcard binding left
- assertEquals(messagingService.getServer().getPostOffice().numMappings(), 1);
clientConsumer.close();
clientSession.deleteQueue(queueName);
- assertEquals(messagingService.getServer().getPostOffice().numMappings(), 0);
}
public void testWildcardRoutingLotsOfQueuesAddedThenDeletedHash() throws Exception
@@ -382,11 +455,8 @@
clientSession.deleteQueue(queueName7);
clientSession.deleteQueue(queueName8);
clientSession.deleteQueue(queueName9);
- //there should only be the wilcard binding left
- assertEquals(messagingService.getServer().getPostOffice().numMappings(), 1);
clientConsumer.close();
clientSession.deleteQueue(queueName);
- assertEquals(messagingService.getServer().getPostOffice().numMappings(), 0);
}
@@ -419,6 +489,65 @@
assertNull(m);
}
+ public void testWildcardRoutingWithHash() throws Exception
+ {
+ SimpleString addressAB = new SimpleString("a.b.f");
+ SimpleString addressAC = new SimpleString("a.c.f");
+ SimpleString address = new SimpleString("a.#.f");
+ SimpleString queueName1 = new SimpleString("Q1");
+ SimpleString queueName2 = new SimpleString("Q2");
+ SimpleString queueName = new SimpleString("Q");
+ clientSession.createQueue(addressAB, queueName1, null, false, false);
+ clientSession.createQueue(addressAC, queueName2, null, false, false);
+ clientSession.createQueue(address, queueName, null, false, false);
+ ClientProducer producer = clientSession.createProducer(addressAB);
+ ClientProducer producer2 = clientSession.createProducer(addressAC);
+ ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
+ clientSession.start();
+ producer.send(createTextMessage("m1", clientSession));
+ producer2.send(createTextMessage("m2", clientSession));
+ ClientMessage m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m1", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m2", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNull(m);
+ }
+
+ public void testWildcardRoutingWithHashMultiLengthAddresses() throws Exception
+ {
+ SimpleString addressAB = new SimpleString("a.b.c.f");
+ SimpleString addressAC = new SimpleString("a.c.f");
+ SimpleString addressAD = new SimpleString("a.d");
+ SimpleString address = new SimpleString("a.#.f");
+ SimpleString queueName1 = new SimpleString("Q1");
+ SimpleString queueName2 = new SimpleString("Q2");
+ SimpleString queueName = new SimpleString("Q");
+ clientSession.createQueue(addressAB, queueName1, null, false, false);
+ clientSession.createQueue(addressAC, queueName2, null, false, false);
+ clientSession.createQueue(address, queueName, null, false, false);
+ ClientProducer producer = clientSession.createProducer(addressAB);
+ ClientProducer producer2 = clientSession.createProducer(addressAC);
+ ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
+ clientSession.start();
+ producer.send(createTextMessage("m1", clientSession));
+ producer2.send(createTextMessage("m2", clientSession));
+ ClientMessage m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m1", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m2", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNull(m);
+ }
+
public void testWildcardRoutingWithDoubleStar() throws Exception
{
SimpleString addressAB = new SimpleString("a.b");
@@ -625,6 +754,42 @@
assertNull(m);
}
+ public void testLargeWildcardRouting() throws Exception
+ {
+ SimpleString addressAB = new SimpleString("a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z");
+ SimpleString addressAC = new SimpleString("a.c");
+ SimpleString address = new SimpleString("a.#");
+ SimpleString queueName1 = new SimpleString("Q1");
+ SimpleString queueName2 = new SimpleString("Q2");
+ SimpleString queueName = new SimpleString("Q");
+ clientSession.createQueue(addressAB, queueName1, null, false, false);
+ clientSession.createQueue(addressAC, queueName2, null, false, false);
+ clientSession.createQueue(address, queueName, null, false, false);
+ assertEquals(2, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAB).getBindings().size());
+ assertEquals(2, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAC).getBindings().size());
+ assertEquals(1, messagingService.getServer().getPostOffice().getBindingsForAddress(address).getBindings().size());
+ ClientProducer producer = clientSession.createProducer(addressAB);
+ ClientProducer producer2 = clientSession.createProducer(addressAC);
+ ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
+ clientSession.start();
+ producer.send(createTextMessage("m1", clientSession));
+ producer2.send(createTextMessage("m2", clientSession));
+ ClientMessage m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m1", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNotNull(m);
+ assertEquals("m2", m.getBody().getString());
+ m.acknowledge();
+ m = clientConsumer.receive(500);
+ assertNull(m);
+ clientConsumer.close();
+ clientSession.deleteQueue(queueName);
+ assertEquals(1, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAB).getBindings().size());
+ assertEquals(1, messagingService.getServer().getPostOffice().getBindingsForAddress(addressAC).getBindings().size());
+ assertEquals(0, messagingService.getServer().getPostOffice().getBindingsForAddress(address).getBindings().size());
+ }
@Override
protected void setUp() throws Exception
@@ -638,6 +803,7 @@
messagingService = MessagingServiceImpl.newNullStorageMessagingService(configuration);
//start the server
messagingService.start();
+ messagingService.getServer().getManagementService().enableNotifications(false);
//then we create a client as normal
ClientSessionFactory sessionFactory = new ClientSessionFactoryImpl(new TransportConfiguration(INVM_CONNECTOR_FACTORY));
clientSession = sessionFactory.createSession(false, true, true);
Modified: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java 2009-01-07 00:02:26 UTC (rev 5589)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/FakePostOffice.java 2009-01-07 13:24:12 UTC (rev 5590)
@@ -22,11 +22,6 @@
package org.jboss.messaging.tests.performance.persistence;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
import org.jboss.messaging.core.filter.Filter;
import org.jboss.messaging.core.paging.PagingManager;
import org.jboss.messaging.core.postoffice.Binding;
@@ -44,10 +39,15 @@
import org.jboss.messaging.util.ConcurrentHashSet;
import org.jboss.messaging.util.SimpleString;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
/**
- *
+ *
* A FakePostOffice
- *
+ *
* @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
*
*/
@@ -102,7 +102,7 @@
public void route(ServerMessage message, Transaction tx) throws Exception
{
}
-
+
public void route(ServerMessage message) throws Exception
{
}
@@ -187,11 +187,6 @@
return null;
}
- public int numMappings()
- {
- return 0;
- }
-
/* (non-Javadoc)
* @see org.jboss.messaging.core.postoffice.PostOffice#deliver(java.util.List)
*/
More information about the jboss-cvs-commits
mailing list