diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java index b68479994d..1f4062efd2 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/xml/XmlDataImporter.java @@ -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 set = new HashSet<>(); + EnumSet set = EnumSet.noneOf(RoutingType.class); for (String routingType : ListUtil.toList(routingTypes)) { set.add(RoutingType.valueOf(routingType)); } diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ClientSession.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ClientSession.java index ab59eb6651..ce56013ade 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ClientSession.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/client/ClientSession.java @@ -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 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 routingTypes, boolean autoCreated) throws ActiveMQException; /** diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientSessionImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientSessionImpl.java index b5f8a1b67d..e5e91dbd99 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientSessionImpl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientSessionImpl.java @@ -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 routingTypes, boolean autoCreated) throws ActiveMQException { + createAddress(address, EnumSet.copyOf(routingTypes), autoCreated); + } + + @Override + public void createAddress(final SimpleString address, EnumSet 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 routingTypes = new HashSet<>(); - routingTypes.add(routingType); - createAddress(address, routingTypes, autoCreated); + createAddress(address, EnumSet.of(routingType), autoCreated); } @Override diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQSessionContext.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQSessionContext.java index 1a81259960..3a4878b26d 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQSessionContext.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQSessionContext.java @@ -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 routingTypes, final boolean autoCreated) throws ActiveMQException { + createAddress(address, EnumSet.copyOf(routingTypes), autoCreated); + } + + @Override + public void createAddress(SimpleString address, + EnumSet routingTypes, + final boolean autoCreated) throws ActiveMQException { CreateAddressMessage request = new CreateAddressMessage(address, routingTypes, autoCreated, true); if (!sessionChannel.getConnection().isVersionBeforeAddressChange()) { sessionChannel.sendBlocking(request, PacketImpl.NULL_RESPONSE); diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/CreateAddressMessage.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/CreateAddressMessage.java index f592a4ca8b..a98f888979 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/CreateAddressMessage.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/wireformat/CreateAddressMessage.java @@ -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 routingTypes; + private EnumSet routingTypes; private boolean autoCreated; private boolean requiresResponse; public CreateAddressMessage(final SimpleString address, - Set routingTypes, + EnumSet routingTypes, final boolean autoCreated, final boolean requiresResponse) { this(); @@ -78,11 +77,11 @@ public class CreateAddressMessage extends PacketImpl { this.address = address; } - public Set getRoutingTypes() { + public EnumSet getRoutingTypes() { return routingTypes; } - public void setRoutingTypes(Set routingTypes) { + public void setRoutingTypes(EnumSet 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())); } diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/SessionContext.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/SessionContext.java index 78135a8bec..1c85f08c50 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/SessionContext.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/spi/core/remoting/SessionContext.java @@ -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 routingTypes, boolean autoCreated) throws ActiveMQException; + public abstract void createAddress(SimpleString address, EnumSet routingTypes, boolean autoCreated) throws ActiveMQException; @Deprecated public abstract void createQueue(SimpleString address, diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PrefixUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PrefixUtil.java index 5313a8af9c..9c6e92a099 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PrefixUtil.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/utils/PrefixUtil.java @@ -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> getAddressAndRoutingTypes(SimpleString address, - Set defaultRoutingTypes, - Map prefixes) { + public static Pair> getAddressAndRoutingTypes(SimpleString address, + EnumSet defaultRoutingTypes, + Map prefixes) { for (Map.Entry 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); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/CoreAddressConfiguration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/CoreAddressConfiguration.java index 86bbeab15c..290d48342b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/CoreAddressConfiguration.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/CoreAddressConfiguration.java @@ -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 routingTypes = new HashSet<>(); + private EnumSet routingTypes = EnumSet.noneOf(RoutingType.class); private List queueConfigurations = new ArrayList<>(); @@ -44,7 +43,7 @@ public class CoreAddressConfiguration implements Serializable { return this; } - public Set getRoutingTypes() { + public EnumSet getRoutingTypes() { return routingTypes; } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java index 6e12766605..4e80bb5527 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java @@ -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 routingTypes = addressInfo.getRoutingTypes(); + final EnumSet 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 set = new HashSet<>(); + EnumSet 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 routingTypeSet; + final EnumSet 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)); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java index 04b0e4bbe7..82c6a6c994 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java @@ -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 routingTypes = addressInfo.getRoutingTypes(); + EnumSet routingTypes = addressInfo.getRoutingTypes(); String[] result = new String[routingTypes.size()]; int i = 0; for (RoutingType routingType : routingTypes) { diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/AddressBindingInfo.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/AddressBindingInfo.java index 381d6274b4..902c16b6d1 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/AddressBindingInfo.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/AddressBindingInfo.java @@ -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 getRoutingTypes(); + EnumSet getRoutingTypes(); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java index 3e5012a99c..3ed3f96a36 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/codec/PersistentAddressBindingEncoding.java @@ -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 routingTypes; + public EnumSet 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 routingTypes, + final EnumSet routingTypes, final boolean autoCreated) { this.name = name; this.routingTypes = routingTypes; @@ -79,7 +78,7 @@ public class PersistentAddressBindingEncoding implements EncodingSupport, Addres } @Override - public Set getRoutingTypes() { + public EnumSet getRoutingTypes() { return routingTypes; } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/AddressManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/AddressManager.java index aa4af0e297..dbf1ef7d7f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/AddressManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/AddressManager.java @@ -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 routingTypes) throws Exception; + AddressInfo updateAddressInfo(SimpleString addressName, EnumSet routingTypes) throws Exception; AddressInfo removeAddressInfo(SimpleString address) throws Exception; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/PostOffice.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/PostOffice.java index b27d726278..9eee907f72 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/PostOffice.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/PostOffice.java @@ -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 routingTypes) throws Exception; + AddressInfo updateAddressInfo(SimpleString addressName, EnumSet routingTypes) throws Exception; QueueBinding updateQueue(SimpleString name, RoutingType routingType, diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java index d5af56b2cd..50f2b58d57 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java @@ -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 addressRoutingTypes = addressInfo.getRoutingTypes(); + final EnumSet 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 routingTypes) throws Exception { + EnumSet routingTypes) throws Exception { synchronized (addressLock) { return addressManager.updateAddressInfo(addressName, routingTypes); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java index f1ca5aef26..72f669257b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/SimpleAddressManager.java @@ -258,7 +258,7 @@ public class SimpleAddressManager implements AddressManager { @Override public AddressInfo updateAddressInfo(SimpleString addressName, - Collection routingTypes) throws Exception { + EnumSet routingTypes) throws Exception { AddressInfo info = addressInfoMap.get(addressName); @@ -272,7 +272,7 @@ public class SimpleAddressManager implements AddressManager { } validateRoutingTypes(addressName, routingTypes); - final Set updatedRoutingTypes = EnumSet.copyOf(routingTypes); + final EnumSet updatedRoutingTypes = EnumSet.copyOf(routingTypes); info.setRoutingTypes(updatedRoutingTypes); @@ -294,7 +294,7 @@ public class SimpleAddressManager implements AddressManager { return info; } - private boolean isEquals(Collection set1, Collection set2) { + private boolean isEquals(Collection set1, EnumSet set2) { Set eset1 = set1 == null || set1.isEmpty() ? Collections.emptySet() : EnumSet.copyOf(set1); Set 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 routingTypes) { + private void validateRoutingTypes(SimpleString addressName, EnumSet routingTypes) { final Bindings bindings = this.mappings.get(addressName); if (bindings != null) { for (Binding binding : bindings.getBindings()) { diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java index 5eeb3db5a1..d1d30297a8 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java @@ -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 routingTypes) throws Exception; + + @Deprecated boolean updateAddressInfo(SimpleString address, Collection routingTypes) throws Exception; /** diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java index 32e35c1f32..d7e1ad2f7d 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ServerSession.java @@ -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 routingTypes, + EnumSet 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> getAddressAndRoutingTypes(SimpleString address, - Set defaultRoutingTypes); + Pair> getAddressAndRoutingTypes(SimpleString address, + EnumSet defaultRoutingTypes); void addProducer(ServerProducer serverProducer); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index a89a43bb6f..d6230e36ad 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -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 routingTypes) throws Exception { + public boolean updateAddressInfo(SimpleString address, EnumSet 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 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 routingTypes = new HashSet<>(); - routingTypes.addAll(info.getRoutingTypes()); + EnumSet 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 routingTypes = new HashSet<>(); - routingTypes.addAll(info.getRoutingTypes()); + EnumSet routingTypes = EnumSet.copyOf(info.getRoutingTypes()); routingTypes.add(routingType); updateAddressInfo(info.getName(), routingTypes); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java index 8a7691e574..4bc540fa3d 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AddressInfo.java @@ -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 routingTypes; + private EnumSet 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 routingTypes) { + public AddressInfo(SimpleString name, EnumSet 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 getRoutingTypes() { + public EnumSet getRoutingTypes() { return routingTypes; } - public AddressInfo setRoutingTypes(Set routingTypes) { + public AddressInfo setRoutingTypes(EnumSet 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 diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java index ad59acb07c..a2fb9332f9 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java @@ -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 routingTypes, + EnumSet routingTypes, final boolean autoCreated) throws Exception { - Pair> art = getAddressAndRoutingTypes(address, routingTypes); + Pair> 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> getAddressAndRoutingTypes(SimpleString address, - Set defaultRoutingTypes) { + public Pair> getAddressAndRoutingTypes(SimpleString address, + EnumSet defaultRoutingTypes) { if (prefixEnabled) { return PrefixUtil.getAddressAndRoutingTypes(address, defaultRoutingTypes, prefixes); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/CreateQueueTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/CreateQueueTest.java index 5581d1877c..13d71b363e 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/CreateQueueTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/CreateQueueTest.java @@ -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 routingTypes = new HashSet<>(); - routingTypes.add(RoutingType.ANYCAST); + EnumSet 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); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RoutingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RoutingTest.java index 6e95620dc9..7e058d87f1 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RoutingTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RoutingTest.java @@ -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 routingTypes = new HashSet<>(); - routingTypes.add(RoutingType.ANYCAST); - routingTypes.add(RoutingType.MULTICAST); + EnumSet 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 routingTypes = new HashSet<>(); - routingTypes.add(RoutingType.ANYCAST); - routingTypes.add(RoutingType.MULTICAST); + EnumSet 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 routingTypes = new HashSet<>(); - routingTypes.add(RoutingType.ANYCAST); - routingTypes.add(RoutingType.MULTICAST); + EnumSet routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST); sendSession.createAddress(addressA, routingTypes, false); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA); sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/UpdateQueueTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/UpdateQueueTest.java index 73b352ae79..5d1763f5e6 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/UpdateQueueTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/UpdateQueueTest.java @@ -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 completeSet = new HashSet<>(); - completeSet.add(RoutingType.ANYCAST); - completeSet.add(RoutingType.MULTICAST); + EnumSet completeSet = EnumSet.allOf(RoutingType.class); server.updateAddressInfo(ADDRESS, completeSet); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java index d466341d16..9f66bcfb32 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java @@ -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 types = new HashSet<>(); - types.add(RoutingType.ANYCAST); - types.add(RoutingType.MULTICAST); + EnumSet types = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST); session.createAddress(address, types, false); addressControl = createManagementControl(address); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/imported/MQTTTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/imported/MQTTTest.java index 631105805f..d5978b0156 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/imported/MQTTTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/imported/MQTTTest.java @@ -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 routingTypeSet = new HashSet<>(); - routingTypeSet.add(RoutingType.ANYCAST); - routingTypeSet.add(RoutingType.MULTICAST); + EnumSet routingTypeSet = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST); getServer().addAddressInfo(new AddressInfo(SimpleString.toSimpleString("foo.bar"), routingTypeSet)); String clientId = "testMqtt"; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/persistence/XmlImportExportTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/persistence/XmlImportExportTest.java index aaf29b0a1a..a041619d84 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/persistence/XmlImportExportTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/persistence/XmlImportExportTest.java @@ -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 routingTypes = new HashSet<>(); - routingTypes.add(RoutingType.ANYCAST); - routingTypes.add(RoutingType.MULTICAST); + EnumSet routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST); session.createAddress(myAddress, routingTypes, false); diff --git a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/MessageProducerTest.java b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/MessageProducerTest.java index a674aef666..d0a87cfb97 100644 --- a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/MessageProducerTest.java +++ b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/MessageProducerTest.java @@ -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 supportedRoutingTypes = new HashSet<>(); - supportedRoutingTypes.add(RoutingType.ANYCAST); - supportedRoutingTypes.add(RoutingType.MULTICAST); + EnumSet 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); diff --git a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/MessageHeaderTest.java b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/MessageHeaderTest.java index 39ea0e36d5..6e1fff2767 100644 --- a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/MessageHeaderTest.java +++ b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/MessageHeaderTest.java @@ -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 routingTypes, boolean autoCreated) throws ActiveMQException { + } + /** * Create Address with a single initial routing type * diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/fakes/FakePostOffice.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/fakes/FakePostOffice.java index 109a336e74..f9e413a0b9 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/fakes/FakePostOffice.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/fakes/FakePostOffice.java @@ -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 routingTypes) throws Exception { + EnumSet routingTypes) throws Exception { return null; }