This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6a1d982212725e7e3bb6baa43c579b6d3779f14e Author: Claus Ibsen <[email protected]> AuthorDate: Wed Apr 7 11:53:32 2021 +0200 CAMEL-16462: camel-core - Optimize RecipientList EIP to reduce object allocations. --- .../camel/processor/RecipientListProcessor.java | 6 ++++- .../apache/camel/support/cache/ServicePool.java | 29 ++++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java index f72eede..c5927fc 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/RecipientListProcessor.java @@ -246,7 +246,7 @@ public class RecipientListProcessor extends MulticastProcessor { } // set property which endpoint we send to - setToEndpoint(copy, producer); + setToEndpoint(copy, endpoint); // rework error handling to support fine grained error handling Route route = ExchangeHelper.getRoute(exchange); @@ -327,6 +327,10 @@ public class RecipientListProcessor extends MulticastProcessor { return null; } + protected static void setToEndpoint(Exchange exchange, Endpoint endpoint) { + exchange.setProperty(ExchangePropertyKey.TO_ENDPOINT, endpoint.getEndpointUri()); + } + @Override protected void doBuild() throws Exception { super.doBuild(); diff --git a/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java b/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java index 28e9ff2..0dc1931 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java @@ -127,12 +127,17 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements } private Pool<S> getOrCreatePool(Endpoint endpoint) { - boolean singleton = endpoint.isSingletonProducer(); - if (singleton) { - return pool.computeIfAbsent(endpoint, SinglePool::new); - } else { - return pool.computeIfAbsent(endpoint, MultiplePool::new); + // its a pool so we have a lot more hits, so use regular get, and then fallback to computeIfAbsent + Pool<S> answer = pool.get(endpoint); + if (answer == null) { + boolean singleton = endpoint.isSingletonProducer(); + if (singleton) { + answer = pool.computeIfAbsent(endpoint, SinglePool::new); + } else { + answer = pool.computeIfAbsent(endpoint, MultiplePool::new); + } } + return answer; } /** @@ -261,12 +266,14 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements } private void cleanupEvicts() { - for (Map.Entry<Endpoint, Pool<S>> entry : singlePoolEvicted.entrySet()) { - Endpoint e = entry.getKey(); - Pool<S> p = entry.getValue(); - doStop(e); - p.stop(); - singlePoolEvicted.remove(e); + if (!singlePoolEvicted.isEmpty()) { + for (Map.Entry<Endpoint, Pool<S>> entry : singlePoolEvicted.entrySet()) { + Endpoint e = entry.getKey(); + Pool<S> p = entry.getValue(); + doStop(e); + p.stop(); + singlePoolEvicted.remove(e); + } } }
