CAMEL-11347: Optimize AsyncCallback to use shared instance when its empty. Fixed CS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ee2cfe69 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ee2cfe69 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ee2cfe69 Branch: refs/heads/master Commit: ee2cfe69915c89e2290fabeb8b3d69b8a1527a47 Parents: a999d47 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri May 26 19:28:34 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sat May 27 09:03:47 2017 +0200 ---------------------------------------------------------------------- .../component/file/GenericFileConsumer.java | 11 ++---- .../camel/component/seda/SedaConsumer.java | 7 ++-- .../camel/management/mbean/Statistic.java | 6 ++-- .../camel/support/EmptyAsyncCallback.java | 37 ++++++++++++++++++++ 4 files changed, 44 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/ee2cfe69/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java index 9ee398c..aef1d98 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java @@ -24,12 +24,12 @@ import java.util.List; import java.util.Queue; import java.util.regex.Pattern; -import org.apache.camel.AsyncCallback; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.ShutdownRunningTask; import org.apache.camel.impl.ScheduledBatchPollingConsumer; +import org.apache.camel.support.EmptyAsyncCallback; import org.apache.camel.util.CastUtils; import org.apache.camel.util.StopWatch; import org.apache.camel.util.StringHelper; @@ -448,14 +448,7 @@ public abstract class GenericFileConsumer<T> extends ScheduledBatchPollingConsum // process the exchange using the async consumer to support async routing engine // which can be supported by this file consumer as all the done work is // provided in the GenericFileOnCompletion - getAsyncProcessor().process(exchange, new AsyncCallback() { - public void done(boolean doneSync) { - // noop - if (log.isTraceEnabled()) { - log.trace("Done processing file: {} {}", target, doneSync ? "synchronously" : "asynchronously"); - } - } - }); + getAsyncProcessor().process(exchange, EmptyAsyncCallback.get()); } } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/camel/blob/ee2cfe69/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java b/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java index ca0ddcb..07784d3 100644 --- a/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java +++ b/camel-core/src/main/java/org/apache/camel/component/seda/SedaConsumer.java @@ -35,6 +35,7 @@ import org.apache.camel.processor.MulticastProcessor; import org.apache.camel.spi.ExceptionHandler; import org.apache.camel.spi.ShutdownAware; import org.apache.camel.spi.Synchronization; +import org.apache.camel.support.EmptyAsyncCallback; import org.apache.camel.support.LoggingExceptionHandler; import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.AsyncProcessorConverterHelper; @@ -295,11 +296,7 @@ public class SedaConsumer extends ServiceSupport implements Consumer, Runnable, }); } else { // use the regular processor and use the asynchronous routing engine to support it - processor.process(exchange, new AsyncCallback() { - public void done(boolean doneSync) { - // noop - } - }); + processor.process(exchange, EmptyAsyncCallback.get()); } } http://git-wip-us.apache.org/repos/asf/camel/blob/ee2cfe69/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java b/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java index 92760e9..aa866e0 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. http://git-wip-us.apache.org/repos/asf/camel/blob/ee2cfe69/camel-core/src/main/java/org/apache/camel/support/EmptyAsyncCallback.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/support/EmptyAsyncCallback.java b/camel-core/src/main/java/org/apache/camel/support/EmptyAsyncCallback.java new file mode 100644 index 0000000..8b68b24 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/support/EmptyAsyncCallback.java @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.support; + +import org.apache.camel.AsyncCallback; + +/** + * An empty {@link AsyncCallback} which allows to share the same instance instead of creating a new instance for each message. + */ +public final class EmptyAsyncCallback implements AsyncCallback { + + private static final EmptyAsyncCallback INSTANCE = new EmptyAsyncCallback(); + + public static AsyncCallback get() { + return INSTANCE; + } + + @Override + public void done(boolean doneSync) { + // noop + } + +}