ARTEMIS-1606 - Change AddressInfo RoutingType Set to use EnumSet
Change all use from Set<RoutingType> to EnumSet<RoutingType> Deprecating any old exposed interfaces but keeping for back compatibility. Address info to avoid iterator on getRoutingType hotpath, like wise can be avoided where single RoutingType is passed in.
This commit is contained in:
parent
f1608d724a
commit
fd0ba69793
|
@ -38,11 +38,10 @@ import java.security.AccessController;
|
|||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -740,7 +739,7 @@ public final class XmlDataImporter extends ActionAbstract {
|
|||
ClientSession.AddressQuery addressQuery = session.addressQuery(new SimpleString(addressName));
|
||||
|
||||
if (!addressQuery.isExists()) {
|
||||
Set<RoutingType> set = new HashSet<>();
|
||||
EnumSet<RoutingType> set = EnumSet.noneOf(RoutingType.class);
|
||||
for (String routingType : ListUtil.toList(routingTypes)) {
|
||||
set.add(RoutingType.valueOf(routingType));
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.activemq.artemis.api.core.client;
|
||||
|
||||
import javax.transaction.xa.XAResource;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -216,6 +217,15 @@ public interface ClientSession extends XAResource, AutoCloseable {
|
|||
* @param autoCreated
|
||||
* @throws ActiveMQException
|
||||
*/
|
||||
void createAddress(SimpleString address, EnumSet<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException;
|
||||
|
||||
/**
|
||||
* Create Address with a single initial routing type
|
||||
* @param address
|
||||
* @param autoCreated
|
||||
* @throws ActiveMQException
|
||||
*/
|
||||
@Deprecated
|
||||
void createAddress(SimpleString address, Set<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.activemq.artemis.core.client.impl;
|
|||
import javax.transaction.xa.XAException;
|
||||
import javax.transaction.xa.XAResource;
|
||||
import javax.transaction.xa.Xid;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -276,6 +277,11 @@ public final class ClientSessionImpl implements ClientSessionInternal, FailureLi
|
|||
|
||||
@Override
|
||||
public void createAddress(final SimpleString address, Set<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException {
|
||||
createAddress(address, EnumSet.copyOf(routingTypes), autoCreated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAddress(final SimpleString address, EnumSet<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException {
|
||||
checkClosed();
|
||||
|
||||
startCall();
|
||||
|
@ -288,9 +294,7 @@ public final class ClientSessionImpl implements ClientSessionInternal, FailureLi
|
|||
|
||||
@Override
|
||||
public void createAddress(final SimpleString address, RoutingType routingType, boolean autoCreated) throws ActiveMQException {
|
||||
Set<RoutingType> routingTypes = new HashSet<>();
|
||||
routingTypes.add(routingType);
|
||||
createAddress(address, routingTypes, autoCreated);
|
||||
createAddress(address, EnumSet.of(routingType), autoCreated);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,7 @@ import javax.transaction.xa.XAResource;
|
|||
import javax.transaction.xa.Xid;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -613,6 +614,13 @@ public class ActiveMQSessionContext extends SessionContext {
|
|||
public void createAddress(SimpleString address,
|
||||
Set<RoutingType> routingTypes,
|
||||
final boolean autoCreated) throws ActiveMQException {
|
||||
createAddress(address, EnumSet.copyOf(routingTypes), autoCreated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAddress(SimpleString address,
|
||||
EnumSet<RoutingType> routingTypes,
|
||||
final boolean autoCreated) throws ActiveMQException {
|
||||
CreateAddressMessage request = new CreateAddressMessage(address, routingTypes, autoCreated, true);
|
||||
if (!sessionChannel.getConnection().isVersionBeforeAddressChange()) {
|
||||
sessionChannel.sendBlocking(request, PacketImpl.NULL_RESPONSE);
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.protocol.core.impl.wireformat;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
|
@ -28,14 +27,14 @@ public class CreateAddressMessage extends PacketImpl {
|
|||
|
||||
private SimpleString address;
|
||||
|
||||
private Set<RoutingType> routingTypes;
|
||||
private EnumSet<RoutingType> routingTypes;
|
||||
|
||||
private boolean autoCreated;
|
||||
|
||||
private boolean requiresResponse;
|
||||
|
||||
public CreateAddressMessage(final SimpleString address,
|
||||
Set<RoutingType> routingTypes,
|
||||
EnumSet<RoutingType> routingTypes,
|
||||
final boolean autoCreated,
|
||||
final boolean requiresResponse) {
|
||||
this();
|
||||
|
@ -78,11 +77,11 @@ public class CreateAddressMessage extends PacketImpl {
|
|||
this.address = address;
|
||||
}
|
||||
|
||||
public Set<RoutingType> getRoutingTypes() {
|
||||
public EnumSet<RoutingType> getRoutingTypes() {
|
||||
return routingTypes;
|
||||
}
|
||||
|
||||
public void setRoutingTypes(Set<RoutingType> routingTypes) {
|
||||
public void setRoutingTypes(EnumSet<RoutingType> routingTypes) {
|
||||
this.routingTypes = routingTypes;
|
||||
}
|
||||
|
||||
|
@ -101,7 +100,7 @@ public class CreateAddressMessage extends PacketImpl {
|
|||
public void decodeRest(final ActiveMQBuffer buffer) {
|
||||
address = buffer.readSimpleString();
|
||||
int routingTypeSetSize = buffer.readInt();
|
||||
routingTypes = new HashSet<>(routingTypeSetSize);
|
||||
routingTypes = EnumSet.noneOf(RoutingType.class);
|
||||
for (int i = 0; i < routingTypeSetSize; i++) {
|
||||
routingTypes.add(RoutingType.getType(buffer.readByte()));
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.activemq.artemis.spi.core.remoting;
|
|||
|
||||
import javax.transaction.xa.XAException;
|
||||
import javax.transaction.xa.Xid;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
|
@ -185,8 +186,10 @@ public abstract class SessionContext {
|
|||
|
||||
public abstract void deleteQueue(SimpleString queueName) throws ActiveMQException;
|
||||
|
||||
@Deprecated
|
||||
public abstract void createAddress(SimpleString address, Set<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException;
|
||||
|
||||
public abstract void createAddress(SimpleString address, EnumSet<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException;
|
||||
|
||||
@Deprecated
|
||||
public abstract void createQueue(SimpleString address,
|
||||
|
|
|
@ -16,9 +16,8 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.Pair;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
|
@ -26,14 +25,12 @@ import org.apache.activemq.artemis.api.core.RoutingType;
|
|||
|
||||
public class PrefixUtil {
|
||||
|
||||
public static Pair<SimpleString, Set<RoutingType>> getAddressAndRoutingTypes(SimpleString address,
|
||||
Set<RoutingType> defaultRoutingTypes,
|
||||
Map<SimpleString, RoutingType> prefixes) {
|
||||
public static Pair<SimpleString, EnumSet<RoutingType>> getAddressAndRoutingTypes(SimpleString address,
|
||||
EnumSet<RoutingType> defaultRoutingTypes,
|
||||
Map<SimpleString, RoutingType> prefixes) {
|
||||
for (Map.Entry<SimpleString, RoutingType> entry : prefixes.entrySet()) {
|
||||
if (address.startsWith(entry.getKey())) {
|
||||
Set routingTypes = new HashSet<>();
|
||||
routingTypes.add(entry.getValue());
|
||||
return new Pair<>(removePrefix(address, entry.getKey()), routingTypes);
|
||||
return new Pair<>(removePrefix(address, entry.getKey()), EnumSet.of(entry.getValue()));
|
||||
}
|
||||
}
|
||||
return new Pair<>(address, defaultRoutingTypes);
|
||||
|
|
|
@ -18,9 +18,8 @@ package org.apache.activemq.artemis.core.config;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
|
||||
|
@ -28,7 +27,7 @@ public class CoreAddressConfiguration implements Serializable {
|
|||
|
||||
private String name = null;
|
||||
|
||||
private Set<RoutingType> routingTypes = new HashSet<>();
|
||||
private EnumSet<RoutingType> routingTypes = EnumSet.noneOf(RoutingType.class);
|
||||
|
||||
private List<CoreQueueConfiguration> queueConfigurations = new ArrayList<>();
|
||||
|
||||
|
@ -44,7 +43,7 @@ public class CoreAddressConfiguration implements Serializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Set<RoutingType> getRoutingTypes() {
|
||||
public EnumSet<RoutingType> getRoutingTypes() {
|
||||
return routingTypes;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -630,7 +631,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
public StringBuilder format(AddressInfo addressInfo, StringBuilder output) {
|
||||
output.append("Address [name=").append(addressInfo.getName());
|
||||
output.append(", routingTypes={");
|
||||
final Set<RoutingType> routingTypes = addressInfo.getRoutingTypes();
|
||||
final EnumSet<RoutingType> routingTypes = addressInfo.getRoutingTypes();
|
||||
if (!routingTypes.isEmpty()) {
|
||||
for (RoutingType routingType : routingTypes) {
|
||||
output.append(routingType).append(',');
|
||||
|
@ -680,7 +681,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
|
||||
clearIO();
|
||||
try {
|
||||
Set<RoutingType> set = new HashSet<>();
|
||||
EnumSet<RoutingType> set = EnumSet.noneOf(RoutingType.class);
|
||||
for (String routingType : ListUtil.toList(routingTypes)) {
|
||||
set.add(RoutingType.valueOf(routingType));
|
||||
}
|
||||
|
@ -701,11 +702,11 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
|
||||
clearIO();
|
||||
try {
|
||||
final Set<RoutingType> routingTypeSet;
|
||||
final EnumSet<RoutingType> routingTypeSet;
|
||||
if (routingTypes == null) {
|
||||
routingTypeSet = null;
|
||||
} else {
|
||||
routingTypeSet = new HashSet<>();
|
||||
routingTypeSet = EnumSet.noneOf(RoutingType.class);
|
||||
final String[] routingTypeNames = routingTypes.split(",");
|
||||
for (String routingTypeName : routingTypeNames) {
|
||||
routingTypeSet.add(RoutingType.valueOf(routingTypeName));
|
||||
|
|
|
@ -21,6 +21,7 @@ import javax.management.MBeanAttributeInfo;
|
|||
import javax.management.MBeanOperationInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -100,7 +101,7 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
|
|||
|
||||
@Override
|
||||
public String[] getRoutingTypes() {
|
||||
Set<RoutingType> routingTypes = addressInfo.getRoutingTypes();
|
||||
EnumSet<RoutingType> routingTypes = addressInfo.getRoutingTypes();
|
||||
String[] result = new String[routingTypes.size()];
|
||||
int i = 0;
|
||||
for (RoutingType routingType : routingTypes) {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.persistence;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
|
@ -27,5 +27,5 @@ public interface AddressBindingInfo {
|
|||
|
||||
SimpleString getName();
|
||||
|
||||
Set<RoutingType> getRoutingTypes();
|
||||
EnumSet<RoutingType> getRoutingTypes();
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.persistence.impl.journal.codec;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
|
@ -34,10 +33,10 @@ public class PersistentAddressBindingEncoding implements EncodingSupport, Addres
|
|||
|
||||
public boolean autoCreated;
|
||||
|
||||
public Set<RoutingType> routingTypes;
|
||||
public EnumSet<RoutingType> routingTypes;
|
||||
|
||||
public PersistentAddressBindingEncoding() {
|
||||
routingTypes = new HashSet<>();
|
||||
routingTypes = EnumSet.noneOf(RoutingType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +56,7 @@ public class PersistentAddressBindingEncoding implements EncodingSupport, Addres
|
|||
}
|
||||
|
||||
public PersistentAddressBindingEncoding(final SimpleString name,
|
||||
final Set<RoutingType> routingTypes,
|
||||
final EnumSet<RoutingType> routingTypes,
|
||||
final boolean autoCreated) {
|
||||
this.name = name;
|
||||
this.routingTypes = routingTypes;
|
||||
|
@ -79,7 +78,7 @@ public class PersistentAddressBindingEncoding implements EncodingSupport, Addres
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<RoutingType> getRoutingTypes() {
|
||||
public EnumSet<RoutingType> getRoutingTypes() {
|
||||
return routingTypes;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.postoffice;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -68,7 +68,7 @@ public interface AddressManager {
|
|||
|
||||
/** it will return null if there are no updates.
|
||||
* it will throw an exception if the address doesn't exist */
|
||||
AddressInfo updateAddressInfo(SimpleString addressName, Collection<RoutingType> routingTypes) throws Exception;
|
||||
AddressInfo updateAddressInfo(SimpleString addressName, EnumSet<RoutingType> routingTypes) throws Exception;
|
||||
|
||||
AddressInfo removeAddressInfo(SimpleString address) throws Exception;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.core.postoffice;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -59,7 +59,7 @@ public interface PostOffice extends ActiveMQComponent {
|
|||
|
||||
AddressInfo getAddressInfo(SimpleString address);
|
||||
|
||||
AddressInfo updateAddressInfo(SimpleString addressName, Collection<RoutingType> routingTypes) throws Exception;
|
||||
AddressInfo updateAddressInfo(SimpleString addressName, EnumSet<RoutingType> routingTypes) throws Exception;
|
||||
|
||||
QueueBinding updateQueue(SimpleString name,
|
||||
RoutingType routingType,
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
package org.apache.activemq.artemis.core.postoffice.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -478,7 +478,7 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding
|
|||
if (routingType != null) {
|
||||
final SimpleString address = queue.getAddress();
|
||||
final AddressInfo addressInfo = addressManager.getAddressInfo(address);
|
||||
final Set<RoutingType> addressRoutingTypes = addressInfo.getRoutingTypes();
|
||||
final EnumSet<RoutingType> addressRoutingTypes = addressInfo.getRoutingTypes();
|
||||
if (!addressRoutingTypes.contains(routingType)) {
|
||||
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeUpdate(name.toString(), routingType, address.toString(), addressRoutingTypes);
|
||||
}
|
||||
|
@ -516,7 +516,7 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding
|
|||
|
||||
@Override
|
||||
public AddressInfo updateAddressInfo(SimpleString addressName,
|
||||
Collection<RoutingType> routingTypes) throws Exception {
|
||||
EnumSet<RoutingType> routingTypes) throws Exception {
|
||||
|
||||
synchronized (addressLock) {
|
||||
return addressManager.updateAddressInfo(addressName, routingTypes);
|
||||
|
|
|
@ -258,7 +258,7 @@ public class SimpleAddressManager implements AddressManager {
|
|||
|
||||
@Override
|
||||
public AddressInfo updateAddressInfo(SimpleString addressName,
|
||||
Collection<RoutingType> routingTypes) throws Exception {
|
||||
EnumSet<RoutingType> routingTypes) throws Exception {
|
||||
|
||||
AddressInfo info = addressInfoMap.get(addressName);
|
||||
|
||||
|
@ -272,7 +272,7 @@ public class SimpleAddressManager implements AddressManager {
|
|||
}
|
||||
|
||||
validateRoutingTypes(addressName, routingTypes);
|
||||
final Set<RoutingType> updatedRoutingTypes = EnumSet.copyOf(routingTypes);
|
||||
final EnumSet<RoutingType> updatedRoutingTypes = EnumSet.copyOf(routingTypes);
|
||||
info.setRoutingTypes(updatedRoutingTypes);
|
||||
|
||||
|
||||
|
@ -294,7 +294,7 @@ public class SimpleAddressManager implements AddressManager {
|
|||
return info;
|
||||
}
|
||||
|
||||
private boolean isEquals(Collection<RoutingType> set1, Collection<RoutingType> set2) {
|
||||
private boolean isEquals(Collection<RoutingType> set1, EnumSet<RoutingType> set2) {
|
||||
Set<RoutingType> eset1 = set1 == null || set1.isEmpty() ? Collections.emptySet() : EnumSet.copyOf(set1);
|
||||
Set<RoutingType> eset2 = set2 == null || set2.isEmpty() ? Collections.emptySet() : EnumSet.copyOf(set2);
|
||||
|
||||
|
@ -309,7 +309,7 @@ public class SimpleAddressManager implements AddressManager {
|
|||
return eset2.containsAll(eset1);
|
||||
}
|
||||
|
||||
private void validateRoutingTypes(SimpleString addressName, Collection<RoutingType> routingTypes) {
|
||||
private void validateRoutingTypes(SimpleString addressName, EnumSet<RoutingType> routingTypes) {
|
||||
final Bindings bindings = this.mappings.get(addressName);
|
||||
if (bindings != null) {
|
||||
for (Binding binding : bindings.getBindings()) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.activemq.artemis.core.server;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -442,6 +443,9 @@ public interface ActiveMQServer extends ServiceComponent {
|
|||
* @return {@code true} if the {@code AddressInfo} was updated, {@code false} otherwise
|
||||
* @throws Exception
|
||||
*/
|
||||
boolean updateAddressInfo(SimpleString address, EnumSet<RoutingType> routingTypes) throws Exception;
|
||||
|
||||
@Deprecated
|
||||
boolean updateAddressInfo(SimpleString address, Collection<RoutingType> routingTypes) throws Exception;
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.server;
|
|||
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.transaction.xa.Xid;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -164,7 +165,7 @@ public interface ServerSession extends SecurityAuth {
|
|||
boolean autoCreated) throws Exception;
|
||||
|
||||
AddressInfo createAddress(SimpleString address,
|
||||
Set<RoutingType> routingTypes,
|
||||
EnumSet<RoutingType> routingTypes,
|
||||
boolean autoCreated) throws Exception;
|
||||
|
||||
AddressInfo createAddress(SimpleString address,
|
||||
|
@ -302,8 +303,8 @@ public interface ServerSession extends SecurityAuth {
|
|||
* name and the {@code java.util.Set} of {@code org.apache.activemq.artemis.api.core.RoutingType} objects
|
||||
* corresponding to the that prefix.
|
||||
*/
|
||||
Pair<SimpleString, Set<RoutingType>> getAddressAndRoutingTypes(SimpleString address,
|
||||
Set<RoutingType> defaultRoutingTypes);
|
||||
Pair<SimpleString, EnumSet<RoutingType>> getAddressAndRoutingTypes(SimpleString address,
|
||||
EnumSet<RoutingType> defaultRoutingTypes);
|
||||
|
||||
void addProducer(ServerProducer serverProducer);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.security.PrivilegedAction;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
|
@ -2618,7 +2619,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean updateAddressInfo(SimpleString address, Collection<RoutingType> routingTypes) throws Exception {
|
||||
public boolean updateAddressInfo(SimpleString address, EnumSet<RoutingType> routingTypes) throws Exception {
|
||||
if (getAddressInfo(address) == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2628,6 +2629,11 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateAddressInfo(SimpleString address, Collection<RoutingType> routingTypes) throws Exception {
|
||||
return updateAddressInfo(address, EnumSet.copyOf(routingTypes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAddressInfo(AddressInfo addressInfo) throws Exception {
|
||||
boolean result = postOffice.addAddressInfo(addressInfo);
|
||||
|
@ -2715,8 +2721,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
addressInfo.setInternal(addrInfo == null ? false : addrInfo.isInternal());
|
||||
addAddressInfo(addressInfo);
|
||||
} else if (!info.getRoutingTypes().contains(rt)) {
|
||||
Set<RoutingType> routingTypes = new HashSet<>();
|
||||
routingTypes.addAll(info.getRoutingTypes());
|
||||
EnumSet<RoutingType> routingTypes = EnumSet.copyOf(info.getRoutingTypes());
|
||||
routingTypes.add(rt);
|
||||
updateAddressInfo(info.getName(), routingTypes);
|
||||
}
|
||||
|
@ -2823,8 +2828,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
addressInfo.setAutoCreated(true);
|
||||
addAddressInfo(addressInfo);
|
||||
} else if (!info.getRoutingTypes().contains(routingType)) {
|
||||
Set<RoutingType> routingTypes = new HashSet<>();
|
||||
routingTypes.addAll(info.getRoutingTypes());
|
||||
EnumSet<RoutingType> routingTypes = EnumSet.copyOf(info.getRoutingTypes());
|
||||
routingTypes.add(routingType);
|
||||
updateAddressInfo(info.getName(), routingTypes);
|
||||
}
|
||||
|
|
|
@ -20,9 +20,8 @@ import org.apache.activemq.artemis.api.core.RoutingType;
|
|||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.utils.PrefixUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class AddressInfo {
|
||||
|
||||
|
@ -32,12 +31,13 @@ public class AddressInfo {
|
|||
|
||||
private boolean autoCreated = false;
|
||||
|
||||
private Set<RoutingType> routingTypes;
|
||||
private EnumSet<RoutingType> routingTypes;
|
||||
private RoutingType firstSeen;
|
||||
|
||||
private boolean internal = false;
|
||||
|
||||
public AddressInfo(SimpleString name) {
|
||||
this(name, new HashSet<>());
|
||||
this(name, EnumSet.noneOf(RoutingType.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,9 +45,9 @@ public class AddressInfo {
|
|||
* @param name
|
||||
* @param routingTypes
|
||||
*/
|
||||
public AddressInfo(SimpleString name, Set<RoutingType> routingTypes) {
|
||||
public AddressInfo(SimpleString name, EnumSet<RoutingType> routingTypes) {
|
||||
this.name = name;
|
||||
this.routingTypes = routingTypes;
|
||||
setRoutingTypes(routingTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,8 +57,7 @@ public class AddressInfo {
|
|||
*/
|
||||
public AddressInfo(SimpleString name, RoutingType routingType) {
|
||||
this.name = name;
|
||||
this.routingTypes = new HashSet<>();
|
||||
routingTypes.add(routingType);
|
||||
addRoutingType(routingType);
|
||||
}
|
||||
|
||||
public boolean isAutoCreated() {
|
||||
|
@ -82,33 +81,35 @@ public class AddressInfo {
|
|||
return id;
|
||||
}
|
||||
|
||||
public Set<RoutingType> getRoutingTypes() {
|
||||
public EnumSet<RoutingType> getRoutingTypes() {
|
||||
return routingTypes;
|
||||
}
|
||||
|
||||
public AddressInfo setRoutingTypes(Set<RoutingType> routingTypes) {
|
||||
public AddressInfo setRoutingTypes(EnumSet<RoutingType> routingTypes) {
|
||||
this.routingTypes = routingTypes;
|
||||
if (!routingTypes.isEmpty()) {
|
||||
this.firstSeen = this.routingTypes.iterator().next();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddressInfo addRoutingType(RoutingType routingType) {
|
||||
if (routingTypes == null) {
|
||||
routingTypes = new HashSet<>();
|
||||
if (routingType != null) {
|
||||
if (routingTypes == null) {
|
||||
routingTypes = EnumSet.of(routingType);
|
||||
firstSeen = routingType;
|
||||
} else {
|
||||
if (routingTypes.isEmpty()) {
|
||||
firstSeen = routingType;
|
||||
}
|
||||
routingTypes.add(routingType);
|
||||
}
|
||||
}
|
||||
routingTypes.add(routingType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RoutingType getRoutingType() {
|
||||
/* We want to use a Set to guarantee only a single entry for ANYCAST, MULTICAST can be added to routing types.
|
||||
There are cases where we also want to get any routing type (when a queue doesn't specifyc it's routing type for
|
||||
example. For this reason we return the first element in the Set.
|
||||
*/
|
||||
// TODO There must be a better way of doing this. This creates an iterator on each lookup.
|
||||
for (RoutingType routingType : routingTypes) {
|
||||
return routingType;
|
||||
}
|
||||
return null;
|
||||
return firstSeen;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,7 @@ import javax.transaction.xa.XAException;
|
|||
import javax.transaction.xa.Xid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -636,9 +637,9 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
|
|||
|
||||
@Override
|
||||
public AddressInfo createAddress(final SimpleString address,
|
||||
Set<RoutingType> routingTypes,
|
||||
EnumSet<RoutingType> routingTypes,
|
||||
final boolean autoCreated) throws Exception {
|
||||
Pair<SimpleString, Set<RoutingType>> art = getAddressAndRoutingTypes(address, routingTypes);
|
||||
Pair<SimpleString, EnumSet<RoutingType>> art = getAddressAndRoutingTypes(address, routingTypes);
|
||||
securityCheck(art.getA(), CheckType.CREATE_ADDRESS, this);
|
||||
server.addOrUpdateAddressInfo(new AddressInfo(art.getA(), art.getB()).setAutoCreated(autoCreated));
|
||||
return server.getAddressInfo(art.getA());
|
||||
|
@ -1773,8 +1774,8 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Pair<SimpleString, Set<RoutingType>> getAddressAndRoutingTypes(SimpleString address,
|
||||
Set<RoutingType> defaultRoutingTypes) {
|
||||
public Pair<SimpleString, EnumSet<RoutingType>> getAddressAndRoutingTypes(SimpleString address,
|
||||
EnumSet<RoutingType> defaultRoutingTypes) {
|
||||
if (prefixEnabled) {
|
||||
return PrefixUtil.getAddressAndRoutingTypes(address, defaultRoutingTypes, prefixes);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.tests.integration.client;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -62,8 +63,7 @@ public class CreateQueueTest extends ActiveMQTestBase {
|
|||
server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false));
|
||||
server.getAddressSettingsRepository().addMatch(addressB.toString(), new AddressSettings().setAutoCreateAddresses(false));
|
||||
|
||||
Set<RoutingType> routingTypes = new HashSet<>();
|
||||
routingTypes.add(RoutingType.ANYCAST);
|
||||
EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST);
|
||||
sendSession.createAddress(addressA, routingTypes, false);
|
||||
try {
|
||||
sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA);
|
||||
|
@ -74,8 +74,7 @@ public class CreateQueueTest extends ActiveMQTestBase {
|
|||
assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
|
||||
}
|
||||
|
||||
routingTypes = new HashSet<>();
|
||||
routingTypes.add(RoutingType.MULTICAST);
|
||||
routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
|
||||
sendSession.createAddress(addressB, routingTypes, false);
|
||||
try {
|
||||
sendSession.createQueue(addressB, RoutingType.ANYCAST, queueB);
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.tests.integration.client;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.client.ClientConsumer;
|
||||
|
@ -227,9 +226,7 @@ public class RoutingTest extends ActiveMQTestBase {
|
|||
@Test
|
||||
public void testAnycastMessageRoutingExclusivity() throws Exception {
|
||||
ClientSession sendSession = cf.createSession(false, true, true);
|
||||
Set<RoutingType> routingTypes = new HashSet<>();
|
||||
routingTypes.add(RoutingType.ANYCAST);
|
||||
routingTypes.add(RoutingType.MULTICAST);
|
||||
EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
|
||||
sendSession.createAddress(addressA, routingTypes, false);
|
||||
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
|
||||
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB);
|
||||
|
@ -246,9 +243,7 @@ public class RoutingTest extends ActiveMQTestBase {
|
|||
@Test
|
||||
public void testMulticastMessageRoutingExclusivity() throws Exception {
|
||||
ClientSession sendSession = cf.createSession(false, true, true);
|
||||
Set<RoutingType> routingTypes = new HashSet<>();
|
||||
routingTypes.add(RoutingType.ANYCAST);
|
||||
routingTypes.add(RoutingType.MULTICAST);
|
||||
EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
|
||||
sendSession.createAddress(addressA, routingTypes, false);
|
||||
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
|
||||
sendSession.createQueue(addressA, RoutingType.MULTICAST, queueB);
|
||||
|
@ -265,9 +260,7 @@ public class RoutingTest extends ActiveMQTestBase {
|
|||
@Test
|
||||
public void testAmbiguousMessageRouting() throws Exception {
|
||||
ClientSession sendSession = cf.createSession(false, true, true);
|
||||
Set<RoutingType> routingTypes = new HashSet<>();
|
||||
routingTypes.add(RoutingType.ANYCAST);
|
||||
routingTypes.add(RoutingType.MULTICAST);
|
||||
EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
|
||||
sendSession.createAddress(addressA, routingTypes, false);
|
||||
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
|
||||
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB);
|
||||
|
|
|
@ -22,9 +22,8 @@ import javax.jms.MessageConsumer;
|
|||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
|
@ -133,9 +132,7 @@ public class UpdateQueueTest extends ActiveMQTestBase {
|
|||
|
||||
Assert.assertEquals(infoAdded.getId(), infoAfterRestart.getId());
|
||||
|
||||
Set<RoutingType> completeSet = new HashSet<>();
|
||||
completeSet.add(RoutingType.ANYCAST);
|
||||
completeSet.add(RoutingType.MULTICAST);
|
||||
EnumSet<RoutingType> completeSet = EnumSet.allOf(RoutingType.class);
|
||||
|
||||
server.updateAddressInfo(ADDRESS, completeSet);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.activemq.artemis.tests.integration.management;
|
|||
import javax.json.JsonArray;
|
||||
import javax.json.JsonString;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -295,9 +296,7 @@ public class AddressControlTest extends ManagementTestBase {
|
|||
Assert.assertEquals(RoutingType.ANYCAST.toString(), routingTypes[0]);
|
||||
|
||||
address = RandomUtil.randomSimpleString();
|
||||
Set<RoutingType> types = new HashSet<>();
|
||||
types.add(RoutingType.ANYCAST);
|
||||
types.add(RoutingType.MULTICAST);
|
||||
EnumSet<RoutingType> types = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
|
||||
session.createAddress(address, types, false);
|
||||
|
||||
addressControl = createManagementControl(address);
|
||||
|
|
|
@ -28,11 +28,10 @@ import java.net.ProtocolException;
|
|||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -1805,9 +1804,7 @@ public class MQTTTest extends MQTTTestSupport {
|
|||
public void testAmbiguousRoutingWithMQTT() throws Exception {
|
||||
String anycastAddress = "foo/bar";
|
||||
|
||||
Set<RoutingType> routingTypeSet = new HashSet<>();
|
||||
routingTypeSet.add(RoutingType.ANYCAST);
|
||||
routingTypeSet.add(RoutingType.MULTICAST);
|
||||
EnumSet<RoutingType> routingTypeSet = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
|
||||
|
||||
getServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString("foo.bar"), routingTypeSet));
|
||||
String clientId = "testMqtt";
|
||||
|
|
|
@ -27,8 +27,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.activemq.artemis.api.core.Message;
|
||||
|
@ -1006,9 +1005,7 @@ public class XmlImportExportTest extends ActiveMQTestBase {
|
|||
SimpleString myAddress = SimpleString.toSimpleString("myAddress");
|
||||
ClientSession session = basicSetUp();
|
||||
|
||||
Set<RoutingType> routingTypes = new HashSet<>();
|
||||
routingTypes.add(RoutingType.ANYCAST);
|
||||
routingTypes.add(RoutingType.MULTICAST);
|
||||
EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
|
||||
|
||||
session.createAddress(myAddress, routingTypes, false);
|
||||
|
||||
|
|
|
@ -30,8 +30,7 @@ import javax.jms.Session;
|
|||
import javax.jms.TextMessage;
|
||||
import javax.jms.Topic;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -710,9 +709,7 @@ public class MessageProducerTest extends JMSTestCase {
|
|||
public void testSendToQueueOnlyWhenTopicWithSameAddress() throws Exception {
|
||||
SimpleString addr = SimpleString.toSimpleString("testAddr");
|
||||
|
||||
Set<RoutingType> supportedRoutingTypes = new HashSet<>();
|
||||
supportedRoutingTypes.add(RoutingType.ANYCAST);
|
||||
supportedRoutingTypes.add(RoutingType.MULTICAST);
|
||||
EnumSet<RoutingType> supportedRoutingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
|
||||
|
||||
servers.get(0).getActiveMQServer().addAddressInfo(new AddressInfo(addr, supportedRoutingTypes));
|
||||
servers.get(0).getActiveMQServer().createQueue(addr, RoutingType.ANYCAST, addr, null, false, false);
|
||||
|
|
|
@ -32,6 +32,7 @@ import javax.transaction.xa.XAResource;
|
|||
import javax.transaction.xa.Xid;
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -1371,6 +1372,10 @@ public class MessageHeaderTest extends MessageHeaderTestBase {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAddress(SimpleString address, EnumSet<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Address with a single initial routing type
|
||||
*
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.artemis.tests.unit.core.server.impl.fakes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -52,7 +52,7 @@ public class FakePostOffice implements PostOffice {
|
|||
|
||||
@Override
|
||||
public AddressInfo updateAddressInfo(SimpleString addressName,
|
||||
Collection<RoutingType> routingTypes) throws Exception {
|
||||
EnumSet<RoutingType> routingTypes) throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue