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;
|
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
|
* Concatenates a SimpleString and a String
|
||||||
*
|
*
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package org.apache.activemq.artemis.core.postoffice.impl;
|
package org.apache.activemq.artemis.core.postoffice.impl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||||
|
@ -37,7 +36,7 @@ public class AddressImpl implements Address {
|
||||||
|
|
||||||
private final boolean containsWildCard;
|
private final boolean containsWildCard;
|
||||||
|
|
||||||
private List<Address> linkedAddresses = null;
|
private final List<Address> linkedAddresses = new ArrayList<>();
|
||||||
|
|
||||||
private final WildcardConfiguration wildcardConfiguration;
|
private final WildcardConfiguration wildcardConfiguration;
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ public class AddressImpl implements Address {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.wildcardConfiguration = wildcardConfiguration;
|
this.wildcardConfiguration = wildcardConfiguration;
|
||||||
addressParts = address.split(wildcardConfiguration.getDelimiter());
|
addressParts = address.split(wildcardConfiguration.getDelimiter());
|
||||||
containsWildCard = address.contains(wildcardConfiguration.getSingleWord()) || address.contains(wildcardConfiguration.getAnyWords());
|
containsWildCard = address.containsEitherOf(wildcardConfiguration.getSingleWord(), wildcardConfiguration.getAnyWords());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,24 +68,16 @@ public class AddressImpl implements Address {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Address> getLinkedAddresses() {
|
public List<Address> getLinkedAddresses() {
|
||||||
return linkedAddresses == null ? Collections.emptyList() : linkedAddresses;
|
return linkedAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLinkedAddress(final Address address) {
|
public void addLinkedAddress(final Address address) {
|
||||||
if (linkedAddresses == null) {
|
linkedAddresses.add(address);
|
||||||
linkedAddresses = new ArrayList<>(1);
|
|
||||||
}
|
|
||||||
if (!linkedAddresses.contains(address)) {
|
|
||||||
linkedAddresses.add(address);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeLinkedAddress(final Address actualAddress) {
|
public void removeLinkedAddress(final Address actualAddress) {
|
||||||
if (linkedAddresses == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
linkedAddresses.remove(actualAddress);
|
linkedAddresses.remove(actualAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,29 +183,30 @@ public class WildcardAddressManager extends SimpleAddressManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized Address addAndUpdateAddressMap(final SimpleString address) {
|
private synchronized Address addAndUpdateAddressMap(final SimpleString address) {
|
||||||
Address add = new AddressImpl(address, wildcardConfiguration);
|
|
||||||
Address actualAddress;
|
Address actualAddress;
|
||||||
if (add.containsWildCard()) {
|
final boolean containsWildcard = address.containsEitherOf(wildcardConfiguration.getAnyWords(), wildcardConfiguration.getSingleWord());
|
||||||
|
if (containsWildcard) {
|
||||||
actualAddress = wildCardAddresses.get(address);
|
actualAddress = wildCardAddresses.get(address);
|
||||||
} else {
|
} else {
|
||||||
actualAddress = addresses.get(address);
|
actualAddress = addresses.get(address);
|
||||||
}
|
}
|
||||||
if (actualAddress == null) {
|
if (actualAddress == null) {
|
||||||
actualAddress = add;
|
actualAddress = new AddressImpl(address, wildcardConfiguration);
|
||||||
addAddress(address, actualAddress);
|
addAddress(address, actualAddress);
|
||||||
}
|
|
||||||
if (actualAddress.containsWildCard()) {
|
if (containsWildcard) {
|
||||||
for (Address destAdd : addresses.values()) {
|
for (Address destAdd : addresses.values()) {
|
||||||
if (destAdd.matches(actualAddress)) {
|
if (destAdd.matches(actualAddress)) {
|
||||||
destAdd.addLinkedAddress(actualAddress);
|
destAdd.addLinkedAddress(actualAddress);
|
||||||
actualAddress.addLinkedAddress(destAdd);
|
actualAddress.addLinkedAddress(destAdd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
for (Address destAdd : wildCardAddresses.values()) {
|
||||||
for (Address destAdd : wildCardAddresses.values()) {
|
if (actualAddress.matches(destAdd)) {
|
||||||
if (actualAddress.matches(destAdd)) {
|
destAdd.addLinkedAddress(actualAddress);
|
||||||
destAdd.addLinkedAddress(actualAddress);
|
actualAddress.addLinkedAddress(destAdd);
|
||||||
actualAddress.addLinkedAddress(destAdd);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue