This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 1e5957c1212 (chores) camel-netty-http: use computeIfAbsent for cleaner map handling 1e5957c1212 is described below commit 1e5957c1212150f22a2241b56f96be15a92c9f03 Author: Otavio Rodolfo Piske <angusyo...@gmail.com> AuthorDate: Fri Apr 14 16:41:15 2023 +0200 (chores) camel-netty-http: use computeIfAbsent for cleaner map handling --- .../component/netty/http/NettyHttpComponent.java | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java index ff3bfbd74d7..2f79d383772 100644 --- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java +++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java @@ -330,24 +330,25 @@ public class NettyHttpComponent extends NettyComponent } public synchronized HttpServerConsumerChannelFactory getMultiplexChannelHandler(int port) { - HttpServerConsumerChannelFactory answer = multiplexChannelHandlers.get(port); - if (answer == null) { - answer = new HttpServerMultiplexChannelHandler(); - answer.init(port); - multiplexChannelHandlers.put(port, answer); - } + return multiplexChannelHandlers.computeIfAbsent(port, s -> newHttpServerConsumerChannelFactory(port)); + } + + private static HttpServerConsumerChannelFactory newHttpServerConsumerChannelFactory(int port) { + final HttpServerConsumerChannelFactory answer = new HttpServerMultiplexChannelHandler(); + answer.init(port); return answer; } protected synchronized HttpServerBootstrapFactory getOrCreateHttpNettyServerBootstrapFactory(NettyHttpConsumer consumer) { String key = consumer.getConfiguration().getAddress(); - HttpServerBootstrapFactory answer = bootstrapFactories.get(key); - if (answer == null) { - HttpServerConsumerChannelFactory channelFactory = getMultiplexChannelHandler(consumer.getConfiguration().getPort()); - answer = new HttpServerBootstrapFactory(channelFactory); - answer.init(getCamelContext(), consumer.getConfiguration(), new HttpServerInitializerFactory(consumer)); - bootstrapFactories.put(key, answer); - } + return bootstrapFactories.computeIfAbsent(key, s -> newHttpServerBootstrapFactory(consumer)); + } + + private HttpServerBootstrapFactory newHttpServerBootstrapFactory(NettyHttpConsumer consumer) { + final HttpServerConsumerChannelFactory channelFactory = getMultiplexChannelHandler(consumer.getConfiguration().getPort()); + final HttpServerBootstrapFactory answer = new HttpServerBootstrapFactory(channelFactory); + + answer.init(getCamelContext(), consumer.getConfiguration(), new HttpServerInitializerFactory(consumer)); return answer; }