This commit is contained in:
Michael Pearce 2018-01-18 13:36:10 +01:00
commit 1d31227cdb
30 changed files with 138 additions and 123 deletions

View File

@ -38,11 +38,10 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.UUID; import java.util.UUID;
@ -740,7 +739,7 @@ public final class XmlDataImporter extends ActionAbstract {
ClientSession.AddressQuery addressQuery = session.addressQuery(new SimpleString(addressName)); ClientSession.AddressQuery addressQuery = session.addressQuery(new SimpleString(addressName));
if (!addressQuery.isExists()) { if (!addressQuery.isExists()) {
Set<RoutingType> set = new HashSet<>(); EnumSet<RoutingType> set = EnumSet.noneOf(RoutingType.class);
for (String routingType : ListUtil.toList(routingTypes)) { for (String routingType : ListUtil.toList(routingTypes)) {
set.add(RoutingType.valueOf(routingType)); set.add(RoutingType.valueOf(routingType));
} }

View File

@ -17,6 +17,7 @@
package org.apache.activemq.artemis.api.core.client; package org.apache.activemq.artemis.api.core.client;
import javax.transaction.xa.XAResource; import javax.transaction.xa.XAResource;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -216,6 +217,15 @@ public interface ClientSession extends XAResource, AutoCloseable {
* @param autoCreated * @param autoCreated
* @throws ActiveMQException * @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; void createAddress(SimpleString address, Set<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException;
/** /**

View File

@ -19,6 +19,7 @@ package org.apache.activemq.artemis.core.client.impl;
import javax.transaction.xa.XAException; import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource; import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid; import javax.transaction.xa.Xid;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -276,6 +277,11 @@ public final class ClientSessionImpl implements ClientSessionInternal, FailureLi
@Override @Override
public void createAddress(final SimpleString address, Set<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException { 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(); checkClosed();
startCall(); startCall();
@ -288,9 +294,7 @@ public final class ClientSessionImpl implements ClientSessionInternal, FailureLi
@Override @Override
public void createAddress(final SimpleString address, RoutingType routingType, boolean autoCreated) throws ActiveMQException { public void createAddress(final SimpleString address, RoutingType routingType, boolean autoCreated) throws ActiveMQException {
Set<RoutingType> routingTypes = new HashSet<>(); createAddress(address, EnumSet.of(routingType), autoCreated);
routingTypes.add(routingType);
createAddress(address, routingTypes, autoCreated);
} }
@Override @Override

View File

@ -21,6 +21,7 @@ import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid; import javax.transaction.xa.Xid;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -613,6 +614,13 @@ public class ActiveMQSessionContext extends SessionContext {
public void createAddress(SimpleString address, public void createAddress(SimpleString address,
Set<RoutingType> routingTypes, Set<RoutingType> routingTypes,
final boolean autoCreated) throws ActiveMQException { 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); CreateAddressMessage request = new CreateAddressMessage(address, routingTypes, autoCreated, true);
if (!sessionChannel.getConnection().isVersionBeforeAddressChange()) { if (!sessionChannel.getConnection().isVersionBeforeAddressChange()) {
sessionChannel.sendBlocking(request, PacketImpl.NULL_RESPONSE); sessionChannel.sendBlocking(request, PacketImpl.NULL_RESPONSE);

View File

@ -16,8 +16,7 @@
*/ */
package org.apache.activemq.artemis.core.protocol.core.impl.wireformat; package org.apache.activemq.artemis.core.protocol.core.impl.wireformat;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Set;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
@ -28,14 +27,14 @@ public class CreateAddressMessage extends PacketImpl {
private SimpleString address; private SimpleString address;
private Set<RoutingType> routingTypes; private EnumSet<RoutingType> routingTypes;
private boolean autoCreated; private boolean autoCreated;
private boolean requiresResponse; private boolean requiresResponse;
public CreateAddressMessage(final SimpleString address, public CreateAddressMessage(final SimpleString address,
Set<RoutingType> routingTypes, EnumSet<RoutingType> routingTypes,
final boolean autoCreated, final boolean autoCreated,
final boolean requiresResponse) { final boolean requiresResponse) {
this(); this();
@ -78,11 +77,11 @@ public class CreateAddressMessage extends PacketImpl {
this.address = address; this.address = address;
} }
public Set<RoutingType> getRoutingTypes() { public EnumSet<RoutingType> getRoutingTypes() {
return routingTypes; return routingTypes;
} }
public void setRoutingTypes(Set<RoutingType> routingTypes) { public void setRoutingTypes(EnumSet<RoutingType> routingTypes) {
this.routingTypes = routingTypes; this.routingTypes = routingTypes;
} }
@ -101,7 +100,7 @@ public class CreateAddressMessage extends PacketImpl {
public void decodeRest(final ActiveMQBuffer buffer) { public void decodeRest(final ActiveMQBuffer buffer) {
address = buffer.readSimpleString(); address = buffer.readSimpleString();
int routingTypeSetSize = buffer.readInt(); int routingTypeSetSize = buffer.readInt();
routingTypes = new HashSet<>(routingTypeSetSize); routingTypes = EnumSet.noneOf(RoutingType.class);
for (int i = 0; i < routingTypeSetSize; i++) { for (int i = 0; i < routingTypeSetSize; i++) {
routingTypes.add(RoutingType.getType(buffer.readByte())); routingTypes.add(RoutingType.getType(buffer.readByte()));
} }

View File

@ -18,6 +18,7 @@ package org.apache.activemq.artemis.spi.core.remoting;
import javax.transaction.xa.XAException; import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid; import javax.transaction.xa.Xid;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -185,8 +186,10 @@ public abstract class SessionContext {
public abstract void deleteQueue(SimpleString queueName) throws ActiveMQException; 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, Set<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException;
public abstract void createAddress(SimpleString address, EnumSet<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException;
@Deprecated @Deprecated
public abstract void createQueue(SimpleString address, public abstract void createQueue(SimpleString address,

View File

@ -16,9 +16,8 @@
*/ */
package org.apache.activemq.artemis.utils; package org.apache.activemq.artemis.utils;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.activemq.artemis.api.core.Pair; import org.apache.activemq.artemis.api.core.Pair;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
@ -26,14 +25,12 @@ import org.apache.activemq.artemis.api.core.RoutingType;
public class PrefixUtil { public class PrefixUtil {
public static Pair<SimpleString, Set<RoutingType>> getAddressAndRoutingTypes(SimpleString address, public static Pair<SimpleString, EnumSet<RoutingType>> getAddressAndRoutingTypes(SimpleString address,
Set<RoutingType> defaultRoutingTypes, EnumSet<RoutingType> defaultRoutingTypes,
Map<SimpleString, RoutingType> prefixes) { Map<SimpleString, RoutingType> prefixes) {
for (Map.Entry<SimpleString, RoutingType> entry : prefixes.entrySet()) { for (Map.Entry<SimpleString, RoutingType> entry : prefixes.entrySet()) {
if (address.startsWith(entry.getKey())) { if (address.startsWith(entry.getKey())) {
Set routingTypes = new HashSet<>(); return new Pair<>(removePrefix(address, entry.getKey()), EnumSet.of(entry.getValue()));
routingTypes.add(entry.getValue());
return new Pair<>(removePrefix(address, entry.getKey()), routingTypes);
} }
} }
return new Pair<>(address, defaultRoutingTypes); return new Pair<>(address, defaultRoutingTypes);

View File

@ -18,9 +18,8 @@ package org.apache.activemq.artemis.core.config;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.RoutingType;
@ -28,7 +27,7 @@ public class CoreAddressConfiguration implements Serializable {
private String name = null; private String name = null;
private Set<RoutingType> routingTypes = new HashSet<>(); private EnumSet<RoutingType> routingTypes = EnumSet.noneOf(RoutingType.class);
private List<CoreQueueConfiguration> queueConfigurations = new ArrayList<>(); private List<CoreQueueConfiguration> queueConfigurations = new ArrayList<>();
@ -44,7 +43,7 @@ public class CoreAddressConfiguration implements Serializable {
return this; return this;
} }
public Set<RoutingType> getRoutingTypes() { public EnumSet<RoutingType> getRoutingTypes() {
return routingTypes; return routingTypes;
} }

View File

@ -36,6 +36,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -630,7 +631,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
public StringBuilder format(AddressInfo addressInfo, StringBuilder output) { public StringBuilder format(AddressInfo addressInfo, StringBuilder output) {
output.append("Address [name=").append(addressInfo.getName()); output.append("Address [name=").append(addressInfo.getName());
output.append(", routingTypes={"); output.append(", routingTypes={");
final Set<RoutingType> routingTypes = addressInfo.getRoutingTypes(); final EnumSet<RoutingType> routingTypes = addressInfo.getRoutingTypes();
if (!routingTypes.isEmpty()) { if (!routingTypes.isEmpty()) {
for (RoutingType routingType : routingTypes) { for (RoutingType routingType : routingTypes) {
output.append(routingType).append(','); output.append(routingType).append(',');
@ -680,7 +681,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
clearIO(); clearIO();
try { try {
Set<RoutingType> set = new HashSet<>(); EnumSet<RoutingType> set = EnumSet.noneOf(RoutingType.class);
for (String routingType : ListUtil.toList(routingTypes)) { for (String routingType : ListUtil.toList(routingTypes)) {
set.add(RoutingType.valueOf(routingType)); set.add(RoutingType.valueOf(routingType));
} }
@ -701,11 +702,11 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
clearIO(); clearIO();
try { try {
final Set<RoutingType> routingTypeSet; final EnumSet<RoutingType> routingTypeSet;
if (routingTypes == null) { if (routingTypes == null) {
routingTypeSet = null; routingTypeSet = null;
} else { } else {
routingTypeSet = new HashSet<>(); routingTypeSet = EnumSet.noneOf(RoutingType.class);
final String[] routingTypeNames = routingTypes.split(","); final String[] routingTypeNames = routingTypes.split(",");
for (String routingTypeName : routingTypeNames) { for (String routingTypeName : routingTypeNames) {
routingTypeSet.add(RoutingType.valueOf(routingTypeName)); routingTypeSet.add(RoutingType.valueOf(routingTypeName));

View File

@ -21,6 +21,7 @@ import javax.management.MBeanAttributeInfo;
import javax.management.MBeanOperationInfo; import javax.management.MBeanOperationInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -100,7 +101,7 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
@Override @Override
public String[] getRoutingTypes() { public String[] getRoutingTypes() {
Set<RoutingType> routingTypes = addressInfo.getRoutingTypes(); EnumSet<RoutingType> routingTypes = addressInfo.getRoutingTypes();
String[] result = new String[routingTypes.size()]; String[] result = new String[routingTypes.size()];
int i = 0; int i = 0;
for (RoutingType routingType : routingTypes) { for (RoutingType routingType : routingTypes) {

View File

@ -16,7 +16,7 @@
*/ */
package org.apache.activemq.artemis.core.persistence; 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.SimpleString;
import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.RoutingType;
@ -27,5 +27,5 @@ public interface AddressBindingInfo {
SimpleString getName(); SimpleString getName();
Set<RoutingType> getRoutingTypes(); EnumSet<RoutingType> getRoutingTypes();
} }

View File

@ -16,8 +16,7 @@
*/ */
package org.apache.activemq.artemis.core.persistence.impl.journal.codec; package org.apache.activemq.artemis.core.persistence.impl.journal.codec;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Set;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
@ -34,10 +33,10 @@ public class PersistentAddressBindingEncoding implements EncodingSupport, Addres
public boolean autoCreated; public boolean autoCreated;
public Set<RoutingType> routingTypes; public EnumSet<RoutingType> routingTypes;
public PersistentAddressBindingEncoding() { public PersistentAddressBindingEncoding() {
routingTypes = new HashSet<>(); routingTypes = EnumSet.noneOf(RoutingType.class);
} }
@Override @Override
@ -57,7 +56,7 @@ public class PersistentAddressBindingEncoding implements EncodingSupport, Addres
} }
public PersistentAddressBindingEncoding(final SimpleString name, public PersistentAddressBindingEncoding(final SimpleString name,
final Set<RoutingType> routingTypes, final EnumSet<RoutingType> routingTypes,
final boolean autoCreated) { final boolean autoCreated) {
this.name = name; this.name = name;
this.routingTypes = routingTypes; this.routingTypes = routingTypes;
@ -79,7 +78,7 @@ public class PersistentAddressBindingEncoding implements EncodingSupport, Addres
} }
@Override @Override
public Set<RoutingType> getRoutingTypes() { public EnumSet<RoutingType> getRoutingTypes() {
return routingTypes; return routingTypes;
} }

View File

@ -16,7 +16,7 @@
*/ */
package org.apache.activemq.artemis.core.postoffice; package org.apache.activemq.artemis.core.postoffice;
import java.util.Collection; import java.util.EnumSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -68,7 +68,7 @@ public interface AddressManager {
/** it will return null if there are no updates. /** it will return null if there are no updates.
* it will throw an exception if the address doesn't exist */ * 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; AddressInfo removeAddressInfo(SimpleString address) throws Exception;

View File

@ -16,7 +16,7 @@
*/ */
package org.apache.activemq.artemis.core.postoffice; package org.apache.activemq.artemis.core.postoffice;
import java.util.Collection; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -59,7 +59,7 @@ public interface PostOffice extends ActiveMQComponent {
AddressInfo getAddressInfo(SimpleString address); 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, QueueBinding updateQueue(SimpleString name,
RoutingType routingType, RoutingType routingType,

View File

@ -17,8 +17,8 @@
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.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -478,7 +478,7 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding
if (routingType != null) { if (routingType != null) {
final SimpleString address = queue.getAddress(); final SimpleString address = queue.getAddress();
final AddressInfo addressInfo = addressManager.getAddressInfo(address); final AddressInfo addressInfo = addressManager.getAddressInfo(address);
final Set<RoutingType> addressRoutingTypes = addressInfo.getRoutingTypes(); final EnumSet<RoutingType> addressRoutingTypes = addressInfo.getRoutingTypes();
if (!addressRoutingTypes.contains(routingType)) { if (!addressRoutingTypes.contains(routingType)) {
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeUpdate(name.toString(), routingType, address.toString(), addressRoutingTypes); throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeUpdate(name.toString(), routingType, address.toString(), addressRoutingTypes);
} }
@ -516,7 +516,7 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding
@Override @Override
public AddressInfo updateAddressInfo(SimpleString addressName, public AddressInfo updateAddressInfo(SimpleString addressName,
Collection<RoutingType> routingTypes) throws Exception { EnumSet<RoutingType> routingTypes) throws Exception {
synchronized (addressLock) { synchronized (addressLock) {
return addressManager.updateAddressInfo(addressName, routingTypes); return addressManager.updateAddressInfo(addressName, routingTypes);

View File

@ -258,7 +258,7 @@ public class SimpleAddressManager implements AddressManager {
@Override @Override
public AddressInfo updateAddressInfo(SimpleString addressName, public AddressInfo updateAddressInfo(SimpleString addressName,
Collection<RoutingType> routingTypes) throws Exception { EnumSet<RoutingType> routingTypes) throws Exception {
AddressInfo info = addressInfoMap.get(addressName); AddressInfo info = addressInfoMap.get(addressName);
@ -272,7 +272,7 @@ public class SimpleAddressManager implements AddressManager {
} }
validateRoutingTypes(addressName, routingTypes); validateRoutingTypes(addressName, routingTypes);
final Set<RoutingType> updatedRoutingTypes = EnumSet.copyOf(routingTypes); final EnumSet<RoutingType> updatedRoutingTypes = EnumSet.copyOf(routingTypes);
info.setRoutingTypes(updatedRoutingTypes); info.setRoutingTypes(updatedRoutingTypes);
@ -294,7 +294,7 @@ public class SimpleAddressManager implements AddressManager {
return info; 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> eset1 = set1 == null || set1.isEmpty() ? Collections.emptySet() : EnumSet.copyOf(set1);
Set<RoutingType> eset2 = set2 == null || set2.isEmpty() ? Collections.emptySet() : EnumSet.copyOf(set2); 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); 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); final Bindings bindings = this.mappings.get(addressName);
if (bindings != null) { if (bindings != null) {
for (Binding binding : bindings.getBindings()) { for (Binding binding : bindings.getBindings()) {

View File

@ -17,6 +17,7 @@
package org.apache.activemq.artemis.core.server; package org.apache.activemq.artemis.core.server;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; 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 * @return {@code true} if the {@code AddressInfo} was updated, {@code false} otherwise
* @throws Exception * @throws Exception
*/ */
boolean updateAddressInfo(SimpleString address, EnumSet<RoutingType> routingTypes) throws Exception;
@Deprecated
boolean updateAddressInfo(SimpleString address, Collection<RoutingType> routingTypes) throws Exception; boolean updateAddressInfo(SimpleString address, Collection<RoutingType> routingTypes) throws Exception;
/** /**

View File

@ -18,6 +18,7 @@ package org.apache.activemq.artemis.core.server;
import javax.json.JsonArrayBuilder; import javax.json.JsonArrayBuilder;
import javax.transaction.xa.Xid; import javax.transaction.xa.Xid;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -164,7 +165,7 @@ public interface ServerSession extends SecurityAuth {
boolean autoCreated) throws Exception; boolean autoCreated) throws Exception;
AddressInfo createAddress(SimpleString address, AddressInfo createAddress(SimpleString address,
Set<RoutingType> routingTypes, EnumSet<RoutingType> routingTypes,
boolean autoCreated) throws Exception; boolean autoCreated) throws Exception;
AddressInfo createAddress(SimpleString address, 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 * name and the {@code java.util.Set} of {@code org.apache.activemq.artemis.api.core.RoutingType} objects
* corresponding to the that prefix. * corresponding to the that prefix.
*/ */
Pair<SimpleString, Set<RoutingType>> getAddressAndRoutingTypes(SimpleString address, Pair<SimpleString, EnumSet<RoutingType>> getAddressAndRoutingTypes(SimpleString address,
Set<RoutingType> defaultRoutingTypes); EnumSet<RoutingType> defaultRoutingTypes);
void addProducer(ServerProducer serverProducer); void addProducer(ServerProducer serverProducer);

View File

@ -28,6 +28,7 @@ import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
@ -2618,7 +2619,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
} }
@Override @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) { if (getAddressInfo(address) == null) {
return false; return false;
} }
@ -2628,6 +2629,11 @@ public class ActiveMQServerImpl implements ActiveMQServer {
return true; return true;
} }
@Override
public boolean updateAddressInfo(SimpleString address, Collection<RoutingType> routingTypes) throws Exception {
return updateAddressInfo(address, EnumSet.copyOf(routingTypes));
}
@Override @Override
public boolean addAddressInfo(AddressInfo addressInfo) throws Exception { public boolean addAddressInfo(AddressInfo addressInfo) throws Exception {
boolean result = postOffice.addAddressInfo(addressInfo); boolean result = postOffice.addAddressInfo(addressInfo);
@ -2715,8 +2721,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
addressInfo.setInternal(addrInfo == null ? false : addrInfo.isInternal()); addressInfo.setInternal(addrInfo == null ? false : addrInfo.isInternal());
addAddressInfo(addressInfo); addAddressInfo(addressInfo);
} else if (!info.getRoutingTypes().contains(rt)) { } else if (!info.getRoutingTypes().contains(rt)) {
Set<RoutingType> routingTypes = new HashSet<>(); EnumSet<RoutingType> routingTypes = EnumSet.copyOf(info.getRoutingTypes());
routingTypes.addAll(info.getRoutingTypes());
routingTypes.add(rt); routingTypes.add(rt);
updateAddressInfo(info.getName(), routingTypes); updateAddressInfo(info.getName(), routingTypes);
} }
@ -2823,8 +2828,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
addressInfo.setAutoCreated(true); addressInfo.setAutoCreated(true);
addAddressInfo(addressInfo); addAddressInfo(addressInfo);
} else if (!info.getRoutingTypes().contains(routingType)) { } else if (!info.getRoutingTypes().contains(routingType)) {
Set<RoutingType> routingTypes = new HashSet<>(); EnumSet<RoutingType> routingTypes = EnumSet.copyOf(info.getRoutingTypes());
routingTypes.addAll(info.getRoutingTypes());
routingTypes.add(routingType); routingTypes.add(routingType);
updateAddressInfo(info.getName(), routingTypes); updateAddressInfo(info.getName(), routingTypes);
} }

View File

@ -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.api.core.SimpleString;
import org.apache.activemq.artemis.utils.PrefixUtil; import org.apache.activemq.artemis.utils.PrefixUtil;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
public class AddressInfo { public class AddressInfo {
@ -32,12 +31,13 @@ public class AddressInfo {
private boolean autoCreated = false; private boolean autoCreated = false;
private Set<RoutingType> routingTypes; private EnumSet<RoutingType> routingTypes;
private RoutingType firstSeen;
private boolean internal = false; private boolean internal = false;
public AddressInfo(SimpleString name) { public AddressInfo(SimpleString name) {
this(name, new HashSet<>()); this(name, EnumSet.noneOf(RoutingType.class));
} }
/** /**
@ -45,9 +45,9 @@ public class AddressInfo {
* @param name * @param name
* @param routingTypes * @param routingTypes
*/ */
public AddressInfo(SimpleString name, Set<RoutingType> routingTypes) { public AddressInfo(SimpleString name, EnumSet<RoutingType> routingTypes) {
this.name = name; this.name = name;
this.routingTypes = routingTypes; setRoutingTypes(routingTypes);
} }
/** /**
@ -57,8 +57,7 @@ public class AddressInfo {
*/ */
public AddressInfo(SimpleString name, RoutingType routingType) { public AddressInfo(SimpleString name, RoutingType routingType) {
this.name = name; this.name = name;
this.routingTypes = new HashSet<>(); addRoutingType(routingType);
routingTypes.add(routingType);
} }
public boolean isAutoCreated() { public boolean isAutoCreated() {
@ -82,33 +81,35 @@ public class AddressInfo {
return id; return id;
} }
public Set<RoutingType> getRoutingTypes() { public EnumSet<RoutingType> getRoutingTypes() {
return routingTypes; return routingTypes;
} }
public AddressInfo setRoutingTypes(Set<RoutingType> routingTypes) { public AddressInfo setRoutingTypes(EnumSet<RoutingType> routingTypes) {
this.routingTypes = routingTypes; this.routingTypes = routingTypes;
if (!routingTypes.isEmpty()) {
this.firstSeen = this.routingTypes.iterator().next();
}
return this; return this;
} }
public AddressInfo addRoutingType(RoutingType routingType) { public AddressInfo addRoutingType(RoutingType routingType) {
if (routingTypes == null) { if (routingType != null) {
routingTypes = new HashSet<>(); if (routingTypes == null) {
routingTypes = EnumSet.of(routingType);
firstSeen = routingType;
} else {
if (routingTypes.isEmpty()) {
firstSeen = routingType;
}
routingTypes.add(routingType);
}
} }
routingTypes.add(routingType);
return this; return this;
} }
public RoutingType getRoutingType() { public RoutingType getRoutingType() {
/* We want to use a Set to guarantee only a single entry for ANYCAST, MULTICAST can be added to routing types. return firstSeen;
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;
} }
@Override @Override

View File

@ -22,6 +22,7 @@ import javax.transaction.xa.XAException;
import javax.transaction.xa.Xid; import javax.transaction.xa.Xid;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -636,9 +637,9 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
@Override @Override
public AddressInfo createAddress(final SimpleString address, public AddressInfo createAddress(final SimpleString address,
Set<RoutingType> routingTypes, EnumSet<RoutingType> routingTypes,
final boolean autoCreated) throws Exception { 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); securityCheck(art.getA(), CheckType.CREATE_ADDRESS, this);
server.addOrUpdateAddressInfo(new AddressInfo(art.getA(), art.getB()).setAutoCreated(autoCreated)); server.addOrUpdateAddressInfo(new AddressInfo(art.getA(), art.getB()).setAutoCreated(autoCreated));
return server.getAddressInfo(art.getA()); return server.getAddressInfo(art.getA());
@ -1773,8 +1774,8 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
} }
@Override @Override
public Pair<SimpleString, Set<RoutingType>> getAddressAndRoutingTypes(SimpleString address, public Pair<SimpleString, EnumSet<RoutingType>> getAddressAndRoutingTypes(SimpleString address,
Set<RoutingType> defaultRoutingTypes) { EnumSet<RoutingType> defaultRoutingTypes) {
if (prefixEnabled) { if (prefixEnabled) {
return PrefixUtil.getAddressAndRoutingTypes(address, defaultRoutingTypes, prefixes); return PrefixUtil.getAddressAndRoutingTypes(address, defaultRoutingTypes, prefixes);
} }

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.activemq.artemis.tests.integration.client; package org.apache.activemq.artemis.tests.integration.client;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; 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(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false));
server.getAddressSettingsRepository().addMatch(addressB.toString(), new AddressSettings().setAutoCreateAddresses(false)); server.getAddressSettingsRepository().addMatch(addressB.toString(), new AddressSettings().setAutoCreateAddresses(false));
Set<RoutingType> routingTypes = new HashSet<>(); EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST);
routingTypes.add(RoutingType.ANYCAST);
sendSession.createAddress(addressA, routingTypes, false); sendSession.createAddress(addressA, routingTypes, false);
try { try {
sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA); sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA);
@ -74,8 +74,7 @@ public class CreateQueueTest extends ActiveMQTestBase {
assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType()); assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
} }
routingTypes = new HashSet<>(); routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
routingTypes.add(RoutingType.MULTICAST);
sendSession.createAddress(addressB, routingTypes, false); sendSession.createAddress(addressB, routingTypes, false);
try { try {
sendSession.createQueue(addressB, RoutingType.ANYCAST, queueB); sendSession.createQueue(addressB, RoutingType.ANYCAST, queueB);

View File

@ -16,8 +16,7 @@
*/ */
package org.apache.activemq.artemis.tests.integration.client; package org.apache.activemq.artemis.tests.integration.client;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Set;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.client.ClientConsumer; import org.apache.activemq.artemis.api.core.client.ClientConsumer;
@ -227,9 +226,7 @@ public class RoutingTest extends ActiveMQTestBase {
@Test @Test
public void testAnycastMessageRoutingExclusivity() throws Exception { public void testAnycastMessageRoutingExclusivity() throws Exception {
ClientSession sendSession = cf.createSession(false, true, true); ClientSession sendSession = cf.createSession(false, true, true);
Set<RoutingType> routingTypes = new HashSet<>(); EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
routingTypes.add(RoutingType.ANYCAST);
routingTypes.add(RoutingType.MULTICAST);
sendSession.createAddress(addressA, routingTypes, false); sendSession.createAddress(addressA, routingTypes, false);
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB);
@ -246,9 +243,7 @@ public class RoutingTest extends ActiveMQTestBase {
@Test @Test
public void testMulticastMessageRoutingExclusivity() throws Exception { public void testMulticastMessageRoutingExclusivity() throws Exception {
ClientSession sendSession = cf.createSession(false, true, true); ClientSession sendSession = cf.createSession(false, true, true);
Set<RoutingType> routingTypes = new HashSet<>(); EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
routingTypes.add(RoutingType.ANYCAST);
routingTypes.add(RoutingType.MULTICAST);
sendSession.createAddress(addressA, routingTypes, false); sendSession.createAddress(addressA, routingTypes, false);
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
sendSession.createQueue(addressA, RoutingType.MULTICAST, queueB); sendSession.createQueue(addressA, RoutingType.MULTICAST, queueB);
@ -265,9 +260,7 @@ public class RoutingTest extends ActiveMQTestBase {
@Test @Test
public void testAmbiguousMessageRouting() throws Exception { public void testAmbiguousMessageRouting() throws Exception {
ClientSession sendSession = cf.createSession(false, true, true); ClientSession sendSession = cf.createSession(false, true, true);
Set<RoutingType> routingTypes = new HashSet<>(); EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
routingTypes.add(RoutingType.ANYCAST);
routingTypes.add(RoutingType.MULTICAST);
sendSession.createAddress(addressA, routingTypes, false); sendSession.createAddress(addressA, routingTypes, false);
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB);

View File

@ -22,9 +22,8 @@ import javax.jms.MessageConsumer;
import javax.jms.MessageProducer; import javax.jms.MessageProducer;
import javax.jms.Session; import javax.jms.Session;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.RoutingType;
@ -133,9 +132,7 @@ public class UpdateQueueTest extends ActiveMQTestBase {
Assert.assertEquals(infoAdded.getId(), infoAfterRestart.getId()); Assert.assertEquals(infoAdded.getId(), infoAfterRestart.getId());
Set<RoutingType> completeSet = new HashSet<>(); EnumSet<RoutingType> completeSet = EnumSet.allOf(RoutingType.class);
completeSet.add(RoutingType.ANYCAST);
completeSet.add(RoutingType.MULTICAST);
server.updateAddressInfo(ADDRESS, completeSet); server.updateAddressInfo(ADDRESS, completeSet);

View File

@ -19,6 +19,7 @@ package org.apache.activemq.artemis.tests.integration.management;
import javax.json.JsonArray; import javax.json.JsonArray;
import javax.json.JsonString; import javax.json.JsonString;
import java.util.Arrays; import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -295,9 +296,7 @@ public class AddressControlTest extends ManagementTestBase {
Assert.assertEquals(RoutingType.ANYCAST.toString(), routingTypes[0]); Assert.assertEquals(RoutingType.ANYCAST.toString(), routingTypes[0]);
address = RandomUtil.randomSimpleString(); address = RandomUtil.randomSimpleString();
Set<RoutingType> types = new HashSet<>(); EnumSet<RoutingType> types = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
types.add(RoutingType.ANYCAST);
types.add(RoutingType.MULTICAST);
session.createAddress(address, types, false); session.createAddress(address, types, false);
addressControl = createManagementControl(address); addressControl = createManagementControl(address);

View File

@ -28,11 +28,10 @@ import java.net.ProtocolException;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -1805,9 +1804,7 @@ public class MQTTTest extends MQTTTestSupport {
public void testAmbiguousRoutingWithMQTT() throws Exception { public void testAmbiguousRoutingWithMQTT() throws Exception {
String anycastAddress = "foo/bar"; String anycastAddress = "foo/bar";
Set<RoutingType> routingTypeSet = new HashSet<>(); EnumSet<RoutingType> routingTypeSet = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
routingTypeSet.add(RoutingType.ANYCAST);
routingTypeSet.add(RoutingType.MULTICAST);
getServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString("foo.bar"), routingTypeSet)); getServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString("foo.bar"), routingTypeSet));
String clientId = "testMqtt"; String clientId = "testMqtt";

View File

@ -27,8 +27,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.Message;
@ -1006,9 +1005,7 @@ public class XmlImportExportTest extends ActiveMQTestBase {
SimpleString myAddress = SimpleString.toSimpleString("myAddress"); SimpleString myAddress = SimpleString.toSimpleString("myAddress");
ClientSession session = basicSetUp(); ClientSession session = basicSetUp();
Set<RoutingType> routingTypes = new HashSet<>(); EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
routingTypes.add(RoutingType.ANYCAST);
routingTypes.add(RoutingType.MULTICAST);
session.createAddress(myAddress, routingTypes, false); session.createAddress(myAddress, routingTypes, false);

View File

@ -30,8 +30,7 @@ import javax.jms.Session;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import javax.jms.Topic; import javax.jms.Topic;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashSet; import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -710,9 +709,7 @@ public class MessageProducerTest extends JMSTestCase {
public void testSendToQueueOnlyWhenTopicWithSameAddress() throws Exception { public void testSendToQueueOnlyWhenTopicWithSameAddress() throws Exception {
SimpleString addr = SimpleString.toSimpleString("testAddr"); SimpleString addr = SimpleString.toSimpleString("testAddr");
Set<RoutingType> supportedRoutingTypes = new HashSet<>(); EnumSet<RoutingType> supportedRoutingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
supportedRoutingTypes.add(RoutingType.ANYCAST);
supportedRoutingTypes.add(RoutingType.MULTICAST);
servers.get(0).getActiveMQServer().addAddressInfo(new AddressInfo(addr, supportedRoutingTypes)); servers.get(0).getActiveMQServer().addAddressInfo(new AddressInfo(addr, supportedRoutingTypes));
servers.get(0).getActiveMQServer().createQueue(addr, RoutingType.ANYCAST, addr, null, false, false); servers.get(0).getActiveMQServer().createQueue(addr, RoutingType.ANYCAST, addr, null, false, false);

View File

@ -32,6 +32,7 @@ import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid; import javax.transaction.xa.Xid;
import java.io.File; import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.EnumSet;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -1371,6 +1372,10 @@ public class MessageHeaderTest extends MessageHeaderTestBase {
return 0; return 0;
} }
@Override
public void createAddress(SimpleString address, EnumSet<RoutingType> routingTypes, boolean autoCreated) throws ActiveMQException {
}
/** /**
* Create Address with a single initial routing type * Create Address with a single initial routing type
* *

View File

@ -16,7 +16,7 @@
*/ */
package org.apache.activemq.artemis.tests.unit.core.server.impl.fakes; 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.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -52,7 +52,7 @@ public class FakePostOffice implements PostOffice {
@Override @Override
public AddressInfo updateAddressInfo(SimpleString addressName, public AddressInfo updateAddressInfo(SimpleString addressName,
Collection<RoutingType> routingTypes) throws Exception { EnumSet<RoutingType> routingTypes) throws Exception {
return null; return null;
} }