ARTEMIS-2990 - update wildcard address map on creation only, avoid duplicates and duplicate checks
This commit is contained in:
parent
130afe7aea
commit
d0bf65ea65
|
@ -447,6 +447,25 @@ public final class SimpleString implements CharSequence, Serializable, Comparabl
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean containsEitherOf(final char c, final char d) {
|
||||
if (this.str != null) {
|
||||
return this.str.indexOf(c) != -1 || this.str.indexOf(d) != -1;
|
||||
}
|
||||
final byte lowc = (byte) (c & 0xFF); // low byte
|
||||
final byte highc = (byte) (c >> 8 & 0xFF); // high byte
|
||||
|
||||
final byte lowd = (byte) (d & 0xFF); // low byte
|
||||
final byte highd = (byte) (d >> 8 & 0xFF); // high byte
|
||||
|
||||
for (int i = 0; i + 1 < data.length; i += 2) {
|
||||
if ( data[i] == lowc && data[i + 1] == highc ||
|
||||
data[i] == lowd && data[i + 1] == highd ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates a SimpleString and a String
|
||||
*
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.activemq.artemis.core.postoffice.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
|
@ -37,7 +36,7 @@ public class AddressImpl implements Address {
|
|||
|
||||
private final boolean containsWildCard;
|
||||
|
||||
private List<Address> linkedAddresses = null;
|
||||
private final List<Address> linkedAddresses = new ArrayList<>();
|
||||
|
||||
private final WildcardConfiguration wildcardConfiguration;
|
||||
|
||||
|
@ -49,7 +48,7 @@ public class AddressImpl implements Address {
|
|||
this.address = address;
|
||||
this.wildcardConfiguration = wildcardConfiguration;
|
||||
addressParts = address.split(wildcardConfiguration.getDelimiter());
|
||||
containsWildCard = address.contains(wildcardConfiguration.getSingleWord()) || address.contains(wildcardConfiguration.getAnyWords());
|
||||
containsWildCard = address.containsEitherOf(wildcardConfiguration.getSingleWord(), wildcardConfiguration.getAnyWords());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,24 +68,16 @@ public class AddressImpl implements Address {
|
|||
|
||||
@Override
|
||||
public List<Address> getLinkedAddresses() {
|
||||
return linkedAddresses == null ? Collections.emptyList() : linkedAddresses;
|
||||
return linkedAddresses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLinkedAddress(final Address address) {
|
||||
if (linkedAddresses == null) {
|
||||
linkedAddresses = new ArrayList<>(1);
|
||||
}
|
||||
if (!linkedAddresses.contains(address)) {
|
||||
linkedAddresses.add(address);
|
||||
}
|
||||
linkedAddresses.add(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLinkedAddress(final Address actualAddress) {
|
||||
if (linkedAddresses == null) {
|
||||
return;
|
||||
}
|
||||
linkedAddresses.remove(actualAddress);
|
||||
}
|
||||
|
||||
|
|
|
@ -183,29 +183,30 @@ public class WildcardAddressManager extends SimpleAddressManager {
|
|||
}
|
||||
|
||||
private synchronized Address addAndUpdateAddressMap(final SimpleString address) {
|
||||
Address add = new AddressImpl(address, wildcardConfiguration);
|
||||
Address actualAddress;
|
||||
if (add.containsWildCard()) {
|
||||
final boolean containsWildcard = address.containsEitherOf(wildcardConfiguration.getAnyWords(), wildcardConfiguration.getSingleWord());
|
||||
if (containsWildcard) {
|
||||
actualAddress = wildCardAddresses.get(address);
|
||||
} else {
|
||||
actualAddress = addresses.get(address);
|
||||
}
|
||||
if (actualAddress == null) {
|
||||
actualAddress = add;
|
||||
actualAddress = new AddressImpl(address, wildcardConfiguration);
|
||||
addAddress(address, actualAddress);
|
||||
}
|
||||
if (actualAddress.containsWildCard()) {
|
||||
for (Address destAdd : addresses.values()) {
|
||||
if (destAdd.matches(actualAddress)) {
|
||||
destAdd.addLinkedAddress(actualAddress);
|
||||
actualAddress.addLinkedAddress(destAdd);
|
||||
|
||||
if (containsWildcard) {
|
||||
for (Address destAdd : addresses.values()) {
|
||||
if (destAdd.matches(actualAddress)) {
|
||||
destAdd.addLinkedAddress(actualAddress);
|
||||
actualAddress.addLinkedAddress(destAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Address destAdd : wildCardAddresses.values()) {
|
||||
if (actualAddress.matches(destAdd)) {
|
||||
destAdd.addLinkedAddress(actualAddress);
|
||||
actualAddress.addLinkedAddress(destAdd);
|
||||
} else {
|
||||
for (Address destAdd : wildCardAddresses.values()) {
|
||||
if (actualAddress.matches(destAdd)) {
|
||||
destAdd.addLinkedAddress(actualAddress);
|
||||
actualAddress.addLinkedAddress(destAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue