You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ni...@apache.org on 2021/09/07 07:18:24 UTC
[activemq-artemis] branch main updated: ARTEMIS-3219 Save
allocating map entries during bindings iteration
This is an automated email from the ASF dual-hosted git repository.
nigrofranz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/main by this push:
new f4d7c8a ARTEMIS-3219 Save allocating map entries during bindings iteration
new 94f63df This closes #3528
f4d7c8a is described below
commit f4d7c8ae692850edd58b12a2b36a0c8e13ff3a2b
Author: franz1981 <ni...@gmail.com>
AuthorDate: Wed Apr 7 09:26:43 2021 +0200
ARTEMIS-3219 Save allocating map entries during bindings iteration
---
.../artemis/core/postoffice/impl/BindingsImpl.java | 2 +-
.../core/postoffice/impl/CopyOnWriteBindings.java | 30 +++++++++++++++++++++-
2 files changed, 30 insertions(+), 2 deletions(-)
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 78c2896..d7420d3 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 fc79da4..90eade2 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
@@ -152,6 +152,34 @@ final class CopyOnWriteBindings {
public interface BindingsConsumer<T extends Throwable> {
/**
+ * {@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.<br>
+ */
+ public <T extends Throwable> void forEachBindings(BindingsConsumer<T> 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<T extends Throwable> {
+
+ /**
* {@code routingName} cannot be {@code null}.
* {@code bindings} cannot be {@code null} or empty.
* {@code nextPosition} cannot be null.
@@ -162,7 +190,7 @@ final class CopyOnWriteBindings {
/**
* Iterates through the bindings and its related indexes.<br>
*/
- public <T extends Throwable> void forEach(BindingsConsumer<T> bindingsConsumer) throws T {
+ public <T extends Throwable> void forEach(RoutingNameBindingsConsumer<T> bindingsConsumer) throws T {
Objects.requireNonNull(bindingsConsumer);
if (map.isEmpty()) {
return;