This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9e6ddcbe8584abe83ef088337354687f34233c2f Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Mon May 20 16:24:18 2019 +0200 [CAMEL-13371] Rename ErrorHandlerBuilder to ErrorHandlerFactory in some places --- .../cdi/transaction/JtaTransactionPolicy.java | 9 ++++--- .../camel/spring/spi/SpringTransactionPolicy.java | 8 +++---- .../camel/builder/ErrorHandlerBuilderRef.java | 28 ++++++++++------------ .../camel/builder/ErrorHandlerBuilderSupport.java | 6 +---- .../org/apache/camel/impl/DefaultRouteContext.java | 2 +- .../org/apache/camel/model/RouteDefinition.java | 24 +++++++++---------- .../apache/camel/model/RouteDefinitionHelper.java | 17 +++---------- .../org/apache/camel/model/RoutesDefinition.java | 2 +- .../DefaultManagementObjectNameStrategy.java | 4 ++-- 9 files changed, 40 insertions(+), 60 deletions(-) diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/transaction/JtaTransactionPolicy.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/transaction/JtaTransactionPolicy.java index b237b8c..e674b3d 100644 --- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/transaction/JtaTransactionPolicy.java +++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/transaction/JtaTransactionPolicy.java @@ -19,7 +19,6 @@ package org.apache.camel.cdi.transaction; import javax.annotation.Resource; import javax.transaction.TransactionManager; -import org.apache.camel.ErrorHandlerFactory; import org.apache.camel.NamedNode; import org.apache.camel.Processor; import org.apache.camel.RuntimeCamelException; @@ -77,7 +76,7 @@ public abstract class JtaTransactionPolicy implements TransactedPolicy { // find the existing error handler builder RouteDefinition route = (RouteDefinition) routeContext.getRoute(); - ErrorHandlerBuilder builder = (ErrorHandlerBuilder) route.getErrorHandlerBuilder(); + ErrorHandlerBuilder builder = (ErrorHandlerBuilder) route.getErrorHandlerFactory(); // check if its a ref if so then do a lookup if (builder instanceof ErrorHandlerBuilderRef) { @@ -87,9 +86,9 @@ public abstract class JtaTransactionPolicy implements TransactedPolicy { // only lookup if there was explicit an error handler builder configured // otherwise its just the "default" that has not explicit been configured // and if so then we can safely replace that with our transacted error handler - if (ErrorHandlerBuilderRef.isErrorHandlerBuilderConfigured(ref)) { + if (ErrorHandlerBuilderRef.isErrorHandlerFactoryConfigured(ref)) { LOG.debug("Looking up ErrorHandlerBuilder with ref: {}", ref); - builder = (ErrorHandlerBuilder) ErrorHandlerBuilderRef.lookupErrorHandlerBuilder(routeContext, ref); + builder = (ErrorHandlerBuilder) ErrorHandlerBuilderRef.lookupErrorHandlerFactory(routeContext, ref); } } @@ -121,7 +120,7 @@ public abstract class JtaTransactionPolicy implements TransactedPolicy { txBuilder.configure(routeContext, answer); // set the route to use our transacted error handler builder - route.setErrorHandlerBuilder(txBuilder); + route.setErrorHandlerFactory(txBuilder); // return with wrapped transacted error handler return answer; diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java index 8161fdc..362160e 100644 --- a/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java +++ b/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringTransactionPolicy.java @@ -69,7 +69,7 @@ public class SpringTransactionPolicy implements TransactedPolicy { // find the existing error handler builder RouteDefinition route = (RouteDefinition) routeContext.getRoute(); - ErrorHandlerBuilder builder = (ErrorHandlerBuilder) route.getErrorHandlerBuilder(); + ErrorHandlerBuilder builder = (ErrorHandlerBuilder) route.getErrorHandlerFactory(); // check if its a ref if so then do a lookup if (builder instanceof ErrorHandlerBuilderRef) { @@ -79,9 +79,9 @@ public class SpringTransactionPolicy implements TransactedPolicy { // only lookup if there was explicit an error handler builder configured // otherwise its just the "default" that has not explicit been configured // and if so then we can safely replace that with our transacted error handler - if (ErrorHandlerBuilderRef.isErrorHandlerBuilderConfigured(ref)) { + if (ErrorHandlerBuilderRef.isErrorHandlerFactoryConfigured(ref)) { LOG.debug("Looking up ErrorHandlerBuilder with ref: {}", ref); - builder = (ErrorHandlerBuilder)ErrorHandlerBuilderRef.lookupErrorHandlerBuilder(routeContext, ref); + builder = (ErrorHandlerBuilder)ErrorHandlerBuilderRef.lookupErrorHandlerFactory(routeContext, ref); } } @@ -114,7 +114,7 @@ public class SpringTransactionPolicy implements TransactedPolicy { txBuilder.configure(routeContext, answer); // set the route to use our transacted error handler builder - route.setErrorHandlerBuilder(txBuilder); + route.setErrorHandlerFactory(txBuilder); } // return with wrapped transacted error handler diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java b/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java index 8cfcec2..d292f0e 100644 --- a/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java +++ b/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderRef.java @@ -64,11 +64,7 @@ public class ErrorHandlerBuilderRef extends ErrorHandlerBuilderSupport { public Processor createErrorHandler(RouteContext routeContext, Processor processor) throws Exception { - ErrorHandlerBuilder handler = handlers.get(routeContext); - if (handler == null) { - handler = createErrorHandler(routeContext); - handlers.put(routeContext, handler); - } + ErrorHandlerFactory handler = handlers.computeIfAbsent(routeContext, this::createErrorHandler); return handler.createErrorHandler(routeContext, processor); } @@ -98,8 +94,8 @@ public class ErrorHandlerBuilderRef extends ErrorHandlerBuilderSupport { * @param ref reference id for the error handler * @return the error handler */ - public static ErrorHandlerFactory lookupErrorHandlerBuilder(RouteContext routeContext, String ref) { - return lookupErrorHandlerBuilder(routeContext, ref, true); + public static ErrorHandlerFactory lookupErrorHandlerFactory(RouteContext routeContext, String ref) { + return lookupErrorHandlerFactory(routeContext, ref, true); } /** @@ -110,16 +106,16 @@ public class ErrorHandlerBuilderRef extends ErrorHandlerBuilderSupport { * @param mandatory whether the error handler must exists, if not a {@link org.apache.camel.NoSuchBeanException} is thrown * @return the error handler */ - public static ErrorHandlerFactory lookupErrorHandlerBuilder(RouteContext routeContext, String ref, boolean mandatory) { + public static ErrorHandlerFactory lookupErrorHandlerFactory(RouteContext routeContext, String ref, boolean mandatory) { ErrorHandlerFactory answer; // if the ref is the default then we do not have any explicit error handler configured // if that is the case then use error handlers configured on the route, as for instance // the transacted error handler could have been configured on the route so we should use that one - if (!isErrorHandlerBuilderConfigured(ref)) { + if (!isErrorHandlerFactoryConfigured(ref)) { // see if there has been configured a route builder on the route RouteDefinition route = (RouteDefinition) routeContext.getRoute(); - answer = route.getErrorHandlerBuilder(); + answer = route.getErrorHandlerFactory(); if (answer == null && route.getErrorHandlerRef() != null) { answer = routeContext.lookup(route.getErrorHandlerRef(), ErrorHandlerBuilder.class); } @@ -131,10 +127,10 @@ public class ErrorHandlerBuilderRef extends ErrorHandlerBuilderSupport { if (answer instanceof ErrorHandlerBuilderRef) { ErrorHandlerBuilderRef other = (ErrorHandlerBuilderRef) answer; String otherRef = other.getRef(); - if (!isErrorHandlerBuilderConfigured(otherRef)) { + if (!isErrorHandlerFactoryConfigured(otherRef)) { // the other has also no explicit error handler configured then fallback to the handler // configured on the parent camel context - answer = lookupErrorHandlerBuilder(routeContext.getCamelContext()); + answer = lookupErrorHandlerFactory(routeContext.getCamelContext()); } if (answer == null) { // the other has also no explicit error handler configured then fallback to the default error handler @@ -157,12 +153,12 @@ public class ErrorHandlerBuilderRef extends ErrorHandlerBuilderSupport { return answer; } - protected static ErrorHandlerFactory lookupErrorHandlerBuilder(CamelContext camelContext) { + protected static ErrorHandlerFactory lookupErrorHandlerFactory(CamelContext camelContext) { ErrorHandlerFactory answer = camelContext.adapt(ExtendedCamelContext.class).getErrorHandlerFactory(); if (answer instanceof ErrorHandlerBuilderRef) { ErrorHandlerBuilderRef other = (ErrorHandlerBuilderRef) answer; String otherRef = other.getRef(); - if (isErrorHandlerBuilderConfigured(otherRef)) { + if (isErrorHandlerFactoryConfigured(otherRef)) { answer = camelContext.getRegistry().lookupByNameAndType(otherRef, ErrorHandlerBuilder.class); if (answer == null) { throw new IllegalArgumentException("ErrorHandlerBuilder with id " + otherRef + " not found in registry."); @@ -182,7 +178,7 @@ public class ErrorHandlerBuilderRef extends ErrorHandlerBuilderSupport { * This is for instance used by the transacted policy to setup a TransactedErrorHandlerBuilder * in camel-spring. */ - public static boolean isErrorHandlerBuilderConfigured(String ref) { + public static boolean isErrorHandlerFactoryConfigured(String ref) { return !DEFAULT_ERROR_HANDLER_BUILDER.equals(ref); } @@ -191,7 +187,7 @@ public class ErrorHandlerBuilderRef extends ErrorHandlerBuilderSupport { } private ErrorHandlerBuilder createErrorHandler(RouteContext routeContext) { - ErrorHandlerBuilder handler = (ErrorHandlerBuilder)lookupErrorHandlerBuilder(routeContext, getRef()); + ErrorHandlerBuilder handler = (ErrorHandlerBuilder) lookupErrorHandlerFactory(routeContext, getRef()); ObjectHelper.notNull(handler, "error handler '" + ref + "'"); // configure if the handler support transacted diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderSupport.java b/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderSupport.java index 0f46713..bd951a8 100644 --- a/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderSupport.java +++ b/core/camel-core/src/main/java/org/apache/camel/builder/ErrorHandlerBuilderSupport.java @@ -38,11 +38,7 @@ public abstract class ErrorHandlerBuilderSupport implements ErrorHandlerBuilder public void addErrorHandlers(RouteContext routeContext, OnExceptionDefinition exception) { // only add if we not already have it - List<OnExceptionDefinition> list = onExceptions.get(routeContext); - if (list == null) { - list = new ArrayList<>(); - onExceptions.put(routeContext, list); - } + List<OnExceptionDefinition> list = onExceptions.computeIfAbsent(routeContext, rc -> new ArrayList<>()); if (!list.contains(exception)) { list.add(exception); } diff --git a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java index f56465c..6df3b2a 100644 --- a/core/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java +++ b/core/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java @@ -426,7 +426,7 @@ public class DefaultRouteContext implements RouteContext { @Override public ErrorHandlerFactory getErrorHandlerFactory() { - return route.getErrorHandlerBuilder(); + return route.getErrorHandlerFactory(); } public void setShutdownRoute(ShutdownRoute shutdownRoute) { diff --git a/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java index 8c6cbbb..dcc96ac 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java @@ -66,7 +66,7 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> { private ShutdownRoute shutdownRoute; private ShutdownRunningTask shutdownRunningTask; private String errorHandlerRef; - private ErrorHandlerFactory errorHandlerBuilder; + private ErrorHandlerFactory errorHandlerFactory; // keep state whether the error handler is context scoped or not // (will by default be context scoped of no explicit error handler configured) private boolean contextScopedErrorHandler = true; @@ -375,7 +375,7 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> { * @return the current builder with the error handler configured */ public RouteDefinition errorHandler(ErrorHandlerFactory errorHandlerBuilder) { - setErrorHandlerBuilder(errorHandlerBuilder); + setErrorHandlerFactory(errorHandlerBuilder); // we are now using a route scoped error handler contextScopedErrorHandler = false; return this; @@ -831,7 +831,7 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> { this.errorHandlerRef = errorHandlerRef; // we use an specific error handler ref (from Spring DSL) then wrap that // with a error handler build ref so Camel knows its not just the default one - setErrorHandlerBuilder(new ErrorHandlerBuilderRef(errorHandlerRef)); + setErrorHandlerFactory(new ErrorHandlerBuilderRef(errorHandlerRef)); } /** @@ -844,9 +844,9 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> { /** * Sets the error handler if one is not already set */ - public void setErrorHandlerBuilderIfNull(ErrorHandlerFactory errorHandlerBuilder) { - if (this.errorHandlerBuilder == null) { - setErrorHandlerBuilder(errorHandlerBuilder); + public void setErrorHandlerFactoryIfNull(ErrorHandlerFactory errorHandlerFactory) { + if (this.errorHandlerFactory == null) { + setErrorHandlerFactory(errorHandlerFactory); } } @@ -913,18 +913,18 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> { } @XmlTransient - public ErrorHandlerFactory getErrorHandlerBuilder() { - if (errorHandlerBuilder == null) { - errorHandlerBuilder = createErrorHandlerBuilder(); + public ErrorHandlerFactory getErrorHandlerFactory() { + if (errorHandlerFactory == null) { + errorHandlerFactory = createErrorHandlerBuilder(); } - return errorHandlerBuilder; + return errorHandlerFactory; } /** * Sets the error handler to use with processors created by this builder */ - public void setErrorHandlerBuilder(ErrorHandlerFactory errorHandlerBuilder) { - this.errorHandlerBuilder = errorHandlerBuilder; + public void setErrorHandlerFactory(ErrorHandlerFactory errorHandlerFactory) { + this.errorHandlerFactory = errorHandlerFactory; } @XmlAttribute diff --git a/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java b/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java index 62cc273..9b1c7d4 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java @@ -268,17 +268,6 @@ public final class RouteDefinitionHelper { } } - private static void initParentAndErrorHandlerBuilder(ProcessorDefinition parent) { - List<ProcessorDefinition<?>> children = parent.getOutputs(); - for (ProcessorDefinition child : children) { - child.setParent(parent); - if (child.getOutputs() != null && !child.getOutputs().isEmpty()) { - // recursive the children - initParentAndErrorHandlerBuilder(child); - } - } - } - public static void prepareRouteForInit(RouteDefinition route, List<ProcessorDefinition<?>> abstracts, List<ProcessorDefinition<?>> lower) { // filter the route into abstracts and lower @@ -453,7 +442,7 @@ public final class RouteDefinitionHelper { if (builder != null) { if (builder instanceof ErrorHandlerBuilder) { builder = ((ErrorHandlerBuilder) builder).cloneBuilder(); - route.setErrorHandlerBuilderIfNull(builder); + route.setErrorHandlerFactoryIfNull(builder); } else { throw new UnsupportedOperationException("The ErrorHandlerFactory must implement ErrorHandlerBuilder"); } @@ -461,12 +450,12 @@ public final class RouteDefinitionHelper { } // init parent and error handler builder on the route - initParentAndErrorHandlerBuilder(route); + initParent(route); // set the parent and error handler builder on the global on exceptions if (onExceptions != null) { for (OnExceptionDefinition global : onExceptions) { - initParentAndErrorHandlerBuilder(global); + initParent(global); } } } diff --git a/core/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java index b857e54..2e8aac2 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java @@ -271,7 +271,7 @@ public class RoutesDefinition extends OptionalIdentifiedDefinition<RoutesDefinit RouteDefinition route = new RouteDefinition(); ErrorHandlerFactory handler = getErrorHandlerFactory(); if (handler != null) { - route.setErrorHandlerBuilderIfNull(handler); + route.setErrorHandlerFactoryIfNull(handler); } return route; } diff --git a/core/camel-management-impl/src/main/java/org/apache/camel/management/DefaultManagementObjectNameStrategy.java b/core/camel-management-impl/src/main/java/org/apache/camel/management/DefaultManagementObjectNameStrategy.java index a34c74a..ad49c11 100644 --- a/core/camel-management-impl/src/main/java/org/apache/camel/management/DefaultManagementObjectNameStrategy.java +++ b/core/camel-management-impl/src/main/java/org/apache/camel/management/DefaultManagementObjectNameStrategy.java @@ -300,7 +300,7 @@ public class DefaultManagementObjectNameStrategy implements ManagementObjectName // it has not then its an indirection and we should do some work to lookup the real builder ref = builderRef.getRef(); - ErrorHandlerFactory refBuilder = ErrorHandlerBuilderRef.lookupErrorHandlerBuilder(routeContext, builderRef.getRef(), false); + ErrorHandlerFactory refBuilder = ErrorHandlerBuilderRef.lookupErrorHandlerFactory(routeContext, builderRef.getRef(), false); if (refBuilder != null) { builder = refBuilder; } @@ -312,7 +312,7 @@ public class DefaultManagementObjectNameStrategy implements ManagementObjectName builderRef = (ErrorHandlerBuilderRef) builder; // does it refer to a non default error handler then do a 2nd lookup if (!builderRef.getRef().equals(ErrorHandlerBuilderRef.DEFAULT_ERROR_HANDLER_BUILDER)) { - refBuilder = ErrorHandlerBuilderRef.lookupErrorHandlerBuilder(routeContext, builderRef.getRef(), false); + refBuilder = ErrorHandlerBuilderRef.lookupErrorHandlerFactory(routeContext, builderRef.getRef(), false); if (refBuilder != null) { ref = builderRef.getRef(); builder = refBuilder;