org.apache.camel.model
Class ProcessorDefinitionHelper

java.lang.Object
  extended by org.apache.camel.model.ProcessorDefinitionHelper

public final class ProcessorDefinitionHelper
extends Object

Helper class for ProcessorDefinition and the other model classes.


Method Summary
static
<T> Iterator<T>
filterTypeInOutputs(List<ProcessorDefinition<?>> outputs, Class<T> type)
          Looks for the given type in the list of outputs and recurring all the children as well.
static
<T> T
findFirstTypeInOutputs(List<ProcessorDefinition<?>> outputs, Class<T> type)
          Looks for the given type in the list of outputs and recurring all the children as well.
static ExecutorService getConfiguredExecutorService(RouteContext routeContext, String name, ExecutorServiceAwareDefinition<?> definition, boolean useDefault)
          Will lookup and get the configured ExecutorService from the given definition.
static ScheduledExecutorService getConfiguredScheduledExecutorService(RouteContext routeContext, String name, ExecutorServiceAwareDefinition<?> definition, boolean useDefault)
          Will lookup and get the configured ScheduledExecutorService from the given definition.
static RouteDefinition getRoute(ProcessorDefinition<?> node)
          Gets the route definition the given node belongs to.
static boolean hasOutputs(List<ProcessorDefinition<?>> outputs, boolean excludeAbstract)
          Is there any outputs in the given list.
static boolean isFirstChildOfType(Class<?> parentType, ProcessorDefinition<?> node)
          Is the given child the first in the outputs from the parent?
static boolean isParentOfType(Class<?> parentType, ProcessorDefinition<?> node, boolean recursive)
          Is the given node parent(s) of the given type
static ExecutorService lookupExecutorServiceRef(RouteContext routeContext, String name, Object source, String executorServiceRef)
          Will lookup in Registry for a ExecutorService registered with the given executorServiceRef name.
static ScheduledExecutorService lookupScheduledExecutorServiceRef(RouteContext routeContext, String name, Object source, String executorServiceRef)
          Will lookup in Registry for a ScheduledExecutorService registered with the given executorServiceRef name.
static boolean willCreateNewThreadPool(RouteContext routeContext, ExecutorServiceAwareDefinition<?> definition, boolean useDefault)
          Determines whether a new thread pool will be created or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

filterTypeInOutputs

public static <T> Iterator<T> filterTypeInOutputs(List<ProcessorDefinition<?>> outputs,
                                                  Class<T> type)
Looks for the given type in the list of outputs and recurring all the children as well.

Parameters:
outputs - list of outputs, can be null or empty.
type - the type to look for
Returns:
the found definitions, or null if not found

findFirstTypeInOutputs

public static <T> T findFirstTypeInOutputs(List<ProcessorDefinition<?>> outputs,
                                           Class<T> type)
Looks for the given type in the list of outputs and recurring all the children as well. Will stop at first found and return it.

Parameters:
outputs - list of outputs, can be null or empty.
type - the type to look for
Returns:
the first found type, or null if not found

isFirstChildOfType

public static boolean isFirstChildOfType(Class<?> parentType,
                                         ProcessorDefinition<?> node)
Is the given child the first in the outputs from the parent?

Parameters:
parentType - the type the parent must be
node - the node
Returns:
true if first child, false otherwise

isParentOfType

public static boolean isParentOfType(Class<?> parentType,
                                     ProcessorDefinition<?> node,
                                     boolean recursive)
Is the given node parent(s) of the given type

Parameters:
parentType - the parent type
node - the current node
recursive - whether or not to check grand parent(s) as well
Returns:
true if parent(s) is of given type, false otherwise

getRoute

public static RouteDefinition getRoute(ProcessorDefinition<?> node)
Gets the route definition the given node belongs to.

Parameters:
node - the node
Returns:
the route, or null if not possible to find

hasOutputs

public static boolean hasOutputs(List<ProcessorDefinition<?>> outputs,
                                 boolean excludeAbstract)
Is there any outputs in the given list.

Is used for check if the route output has any real outputs (non abstracts)

Parameters:
outputs - the outputs
excludeAbstract - whether or not to exclude abstract outputs (e.g. skip onException etc.)
Returns:
true if has outputs, otherwise false is returned

willCreateNewThreadPool

public static boolean willCreateNewThreadPool(RouteContext routeContext,
                                              ExecutorServiceAwareDefinition<?> definition,
                                              boolean useDefault)
Determines whether a new thread pool will be created or not.

This is used to know if a new thread pool will be created, and therefore is not shared by others, and therefore exclusive to the definition.

Parameters:
routeContext - the route context
definition - the node definition which may leverage executor service.
useDefault - whether to fallback and use a default thread pool, if no explicit configured
Returns:
true if a new thread pool will be created, false if not
See Also:
getConfiguredExecutorService(org.apache.camel.spi.RouteContext, String, ExecutorServiceAwareDefinition, boolean)

lookupExecutorServiceRef

public static ExecutorService lookupExecutorServiceRef(RouteContext routeContext,
                                                       String name,
                                                       Object source,
                                                       String executorServiceRef)
Will lookup in Registry for a ExecutorService registered with the given executorServiceRef name.

This method will lookup for configured thread pool in the following order

Parameters:
routeContext - the route context
name - name which is appended to the thread name, when the ExecutorService is created based on a ThreadPoolProfile.
source - the source to use the thread pool
executorServiceRef - reference name of the thread pool
Returns:
the executor service, or null if none was found.

getConfiguredExecutorService

public static ExecutorService getConfiguredExecutorService(RouteContext routeContext,
                                                           String name,
                                                           ExecutorServiceAwareDefinition<?> definition,
                                                           boolean useDefault)
                                                    throws IllegalArgumentException
Will lookup and get the configured ExecutorService from the given definition.

This method will lookup for configured thread pool in the following order

The various ExecutorServiceAwareDefinition should use this helper method to ensure they support configured executor services in the same coherent way.

Parameters:
routeContext - the route context
name - name which is appended to the thread name, when the ExecutorService is created based on a ThreadPoolProfile.
definition - the node definition which may leverage executor service.
useDefault - whether to fallback and use a default thread pool, if no explicit configured
Returns:
the configured executor service, or null if none was configured.
Throws:
IllegalArgumentException - is thrown if lookup of executor service in Registry was not found

lookupScheduledExecutorServiceRef

public static ScheduledExecutorService lookupScheduledExecutorServiceRef(RouteContext routeContext,
                                                                         String name,
                                                                         Object source,
                                                                         String executorServiceRef)
Will lookup in Registry for a ScheduledExecutorService registered with the given executorServiceRef name.

This method will lookup for configured thread pool in the following order

Parameters:
routeContext - the route context
name - name which is appended to the thread name, when the ExecutorService is created based on a ThreadPoolProfile.
source - the source to use the thread pool
executorServiceRef - reference name of the thread pool
Returns:
the executor service, or null if none was found.

getConfiguredScheduledExecutorService

public static ScheduledExecutorService getConfiguredScheduledExecutorService(RouteContext routeContext,
                                                                             String name,
                                                                             ExecutorServiceAwareDefinition<?> definition,
                                                                             boolean useDefault)
                                                                      throws IllegalArgumentException
Will lookup and get the configured ScheduledExecutorService from the given definition.

This method will lookup for configured thread pool in the following order

The various ExecutorServiceAwareDefinition should use this helper method to ensure they support configured executor services in the same coherent way.

Parameters:
routeContext - the rout context
name - name which is appended to the thread name, when the ExecutorService is created based on a ThreadPoolProfile.
definition - the node definition which may leverage executor service.
useDefault - whether to fallback and use a default thread pool, if no explicit configured
Returns:
the configured executor service, or null if none was configured.
Throws:
IllegalArgumentException - is thrown if the found instance is not a ScheduledExecutorService type, or lookup of executor service in Registry was not found


Apache CAMEL