ARTEMIS-3219 Save allocating map entries during bindings iteration

This commit is contained in:
franz1981 2021-04-07 09:26:43 +02:00
parent c576db9013
commit f4d7c8ae69
2 changed files with 30 additions and 2 deletions

View File

@ -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);

View File

@ -151,6 +151,34 @@ final class CopyOnWriteBindings {
@FunctionalInterface
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.
@ -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;