diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/BindingsImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/BindingsImpl.java index 78c2896863..d7420d32bd 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/BindingsImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/BindingsImpl.java @@ -330,7 +330,7 @@ public final class BindingsImpl implements Bindings { logger.tracef("Routing message %s on binding=%s current context::$s", message, this, context); } - routingNameBindingMap.forEach((routingName, bindings, nextPosition) -> { + routingNameBindingMap.forEachBindings((bindings, nextPosition) -> { final Binding nextBinding = getNextBinding(message, bindings, nextPosition); if (nextBinding != null && nextBinding.getFilter() == null && nextBinding.isLocal() && bindings.length == 1) { context.setReusable(true, currentVersion); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/CopyOnWriteBindings.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/CopyOnWriteBindings.java index fc79da45c1..90eade2d18 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/CopyOnWriteBindings.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/CopyOnWriteBindings.java @@ -151,6 +151,34 @@ final class CopyOnWriteBindings { @FunctionalInterface public interface BindingsConsumer { + /** + * {@code bindings} cannot be {@code null} or empty. + * {@code nextPosition} cannot be null. + */ + void accept(Binding[] bindings, BindingIndex nextPosition) throws T; + } + + /** + * Iterates through the bindings and its related indexes.
+ */ + public void forEachBindings(BindingsConsumer bindingsConsumer) throws T { + Objects.requireNonNull(bindingsConsumer); + if (map.isEmpty()) { + return; + } + for (BindingsAndPosition bindingsAndPosition : map.values()) { + final Binding[] bindings = bindingsAndPosition.get(); + if (bindings == TOMBSTONE_BINDINGS) { + continue; + } + assert bindings != null && bindings.length > 0; + bindingsConsumer.accept(bindings, bindingsAndPosition); + } + } + + @FunctionalInterface + public interface RoutingNameBindingsConsumer { + /** * {@code routingName} cannot be {@code null}. * {@code bindings} cannot be {@code null} or empty. @@ -162,7 +190,7 @@ final class CopyOnWriteBindings { /** * Iterates through the bindings and its related indexes.
*/ - public void forEach(BindingsConsumer bindingsConsumer) throws T { + public void forEach(RoutingNameBindingsConsumer bindingsConsumer) throws T { Objects.requireNonNull(bindingsConsumer); if (map.isEmpty()) { return;