CAMEL-8527: Processor in routes should be IdAware
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7973ac5f Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7973ac5f Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7973ac5f Branch: refs/heads/master Commit: 7973ac5f1baba82c4a8b5340d441bf6881a772c6 Parents: 0c7b6d2 Author: Claus Ibsen <[email protected]> Authored: Mon Mar 23 08:23:09 2015 +0100 Committer: Claus Ibsen <[email protected]> Committed: Mon Mar 23 11:56:00 2015 +0100 ---------------------------------------------------------------------- .../java/org/apache/camel/CamelContext.java | 20 ++++++++++++++++++++ .../apache/camel/impl/DefaultCamelContext.java | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/7973ac5f/camel-core/src/main/java/org/apache/camel/CamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java index b92349e..0b7d8b6 100644 --- a/camel-core/src/main/java/org/apache/camel/CamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java @@ -522,6 +522,16 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration { Processor getProcessor(String id); /** + * Gets the processor from any of the routes which with the given id + * + * @param id id of the processor + * @param type the processor type + * @return the processor or <tt>null</tt> if not found + * @throws java.lang.ClassCastException is thrown if the type is not correct type + */ + <T extends Processor> T getProcessor(String id, Class<T> type); + + /** * Gets the processor definition from any of the routes which with the given id * * @param id id of the processor definition @@ -530,6 +540,16 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration { ProcessorDefinition getProcessorDefinition(String id); /** + * Gets the processor definition from any of the routes which with the given id + * + * @param id id of the processor definition + * @param type the processor definition type + * @return the processor definition or <tt>null</tt> if not found + * @throws java.lang.ClassCastException is thrown if the type is not correct type + */ + <T extends ProcessorDefinition> T getProcessorDefinition(String id, Class<T> type); + + /** * Adds a collection of routes to this context using the given builder * to build them. * <p/> http://git-wip-us.apache.org/repos/asf/camel/blob/7973ac5f/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index 9ac8692..b0874a5 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -719,6 +719,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon return null; } + public <T extends Processor> T getProcessor(String id, Class<T> type) { + Processor answer = getProcessor(id); + if (answer != null) { + return type.cast(answer); + } + return null; + } + public ProcessorDefinition getProcessorDefinition(String id) { for (RouteDefinition route : getRouteDefinitions()) { Iterator<ProcessorDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), ProcessorDefinition.class); @@ -732,6 +740,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon return null; } + public <T extends ProcessorDefinition> T getProcessorDefinition(String id, Class<T> type) { + ProcessorDefinition answer = getProcessorDefinition(id); + if (answer != null) { + return type.cast(answer); + } + return null; + } + @Deprecated public void setRoutes(List<Route> routes) { throw new UnsupportedOperationException("Overriding existing routes is not supported yet, use addRouteCollection instead");
