org.apache.camel.impl
Class DefaultExecutorServiceStrategy

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.impl.DefaultExecutorServiceStrategy
All Implemented Interfaces:
Service, ShutdownableService, ExecutorServiceStrategy

public class DefaultExecutorServiceStrategy
extends ServiceSupport
implements ExecutorServiceStrategy

Version:

Constructor Summary
DefaultExecutorServiceStrategy(CamelContext camelContext)
           
 
Method Summary
protected  void doShutdown()
          Implementations override this method to perform customized shutdown
protected  void doStart()
           
protected  void doStop()
           
 ThreadPoolProfile getDefaultThreadPoolProfile()
          Gets the default thread pool profile
 String getThreadName(String name)
          Creates a full thread name
 String getThreadNamePattern()
          Gets the thread name pattern used for creating the full thread name.
 ThreadPoolProfile getThreadPoolProfile(String id)
          Gets the thread pool profile by the given id
 ExecutorService lookup(Object source, String name, String executorServiceRef)
          Lookup a ExecutorService from the Registry and from known list of ThreadPoolProfile(s).
 ScheduledExecutorService lookupScheduled(Object source, String name, String executorServiceRef)
          Lookup a ScheduledExecutorService from the Registry and from known list of ThreadPoolProfile(s).
 ExecutorService newCachedThreadPool(Object source, String name)
          Creates a new cached thread pool.
 ExecutorService newDefaultThreadPool(Object source, String name)
          Creates a new thread pool using the default thread pool profile.
 ExecutorService newFixedThreadPool(Object source, String name, int poolSize)
          Creates a new fixed thread pool.
 ScheduledExecutorService newScheduledThreadPool(Object source, String name)
          Creates a new scheduled thread pool.
 ScheduledExecutorService newScheduledThreadPool(Object source, String name, int poolSize)
          Creates a new scheduled thread pool.
 ExecutorService newSingleThreadExecutor(Object source, String name)
          Creates a new single-threaded thread pool.
 ExecutorService newSynchronousThreadPool(Object source, String name)
          Creates a new synchronous thread pool, which executes the task in the caller thread (no task queue).
 ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize)
          Creates a new custom thread pool.
 ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize, int maxQueueSize)
          Creates a new custom thread pool.
 ExecutorService newThreadPool(Object source, String name, int corePoolSize, int maxPoolSize, long keepAliveTime, TimeUnit timeUnit, int maxQueueSize, RejectedExecutionHandler rejectedExecutionHandler, boolean daemon)
          Creates a new custom thread pool.
 ExecutorService newThreadPool(Object source, String name, String threadPoolProfileId)
          Creates a new thread pool using based on the given profile id.
protected  void onNewExecutorService(ExecutorService executorService)
          Strategy callback when a new ExecutorService have been created.
protected  void onThreadPoolCreated(ExecutorService executorService, Object source, String threadPoolProfileId)
          Invoked when a new thread pool is created.
 void registerThreadPoolProfile(ThreadPoolProfile profile)
          Registers the given thread pool profile
 void setDefaultThreadPoolProfile(ThreadPoolProfile defaultThreadPoolProfile)
          Sets the default thread pool profile
 void setThreadNamePattern(String threadNamePattern)
          Sets the thread name pattern used for creating the full thread name.
 void shutdown(ExecutorService executorService)
          Shutdown the given executor service.
 List<Runnable> shutdownNow(ExecutorService executorService)
          Shutdown now the given executor service.
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, doResume, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, removeChildService, resume, shutdown, start, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.camel.ShutdownableService
shutdown
 
Methods inherited from interface org.apache.camel.Service
start, stop
 

Constructor Detail

DefaultExecutorServiceStrategy

public DefaultExecutorServiceStrategy(CamelContext camelContext)
Method Detail

registerThreadPoolProfile

public void registerThreadPoolProfile(ThreadPoolProfile profile)
Description copied from interface: ExecutorServiceStrategy
Registers the given thread pool profile

Specified by:
registerThreadPoolProfile in interface ExecutorServiceStrategy
Parameters:
profile - the profile

getThreadPoolProfile

public ThreadPoolProfile getThreadPoolProfile(String id)
Description copied from interface: ExecutorServiceStrategy
Gets the thread pool profile by the given id

Specified by:
getThreadPoolProfile in interface ExecutorServiceStrategy
Parameters:
id - id of the thread pool profile to get
Returns:
the found profile, or null if not found

getDefaultThreadPoolProfile

public ThreadPoolProfile getDefaultThreadPoolProfile()
Description copied from interface: ExecutorServiceStrategy
Gets the default thread pool profile

Specified by:
getDefaultThreadPoolProfile in interface ExecutorServiceStrategy
Returns:
the default profile which are newer null

setDefaultThreadPoolProfile

public void setDefaultThreadPoolProfile(ThreadPoolProfile defaultThreadPoolProfile)
Description copied from interface: ExecutorServiceStrategy
Sets the default thread pool profile

Specified by:
setDefaultThreadPoolProfile in interface ExecutorServiceStrategy
Parameters:
defaultThreadPoolProfile - the new default thread pool profile

getThreadName

public String getThreadName(String name)
Description copied from interface: ExecutorServiceStrategy
Creates a full thread name

Specified by:
getThreadName in interface ExecutorServiceStrategy
Parameters:
name - name which is appended to the full thread name
Returns:
the full thread name

getThreadNamePattern

public String getThreadNamePattern()
Description copied from interface: ExecutorServiceStrategy
Gets the thread name pattern used for creating the full thread name.

Specified by:
getThreadNamePattern in interface ExecutorServiceStrategy
Returns:
the pattern

setThreadNamePattern

public void setThreadNamePattern(String threadNamePattern)
Description copied from interface: ExecutorServiceStrategy
Sets the thread name pattern used for creating the full thread name.

The default pattern is: Camel (${camelId}) thread #${counter} - ${name}

Where ${camelId} is the name of the CamelContext
and ${counter} is a unique incrementing counter.
and ${name} is the regular thread name.
You can also use ${longName} is the long thread name which can includes endpoint parameters etc.

Specified by:
setThreadNamePattern in interface ExecutorServiceStrategy
Parameters:
threadNamePattern - the pattern

lookup

public ExecutorService lookup(Object source,
                              String name,
                              String executorServiceRef)
Description copied from interface: ExecutorServiceStrategy
Lookup a ExecutorService from the Registry and from known list of ThreadPoolProfile(s).

Specified by:
lookup in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
executorServiceRef - reference to lookup
Returns:
the ExecutorService or null if not found

lookupScheduled

public ScheduledExecutorService lookupScheduled(Object source,
                                                String name,
                                                String executorServiceRef)
Description copied from interface: ExecutorServiceStrategy
Lookup a ScheduledExecutorService from the Registry and from known list of ThreadPoolProfile(s).

Specified by:
lookupScheduled in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
executorServiceRef - reference to lookup
Returns:
the ScheduledExecutorService or null if not found

newDefaultThreadPool

public ExecutorService newDefaultThreadPool(Object source,
                                            String name)
Description copied from interface: ExecutorServiceStrategy
Creates a new thread pool using the default thread pool profile.

Specified by:
newDefaultThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newThreadPool

public ExecutorService newThreadPool(Object source,
                                     String name,
                                     String threadPoolProfileId)
Description copied from interface: ExecutorServiceStrategy
Creates a new thread pool using based on the given profile id.

Specified by:
newThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
threadPoolProfileId - id of the thread pool profile to use for creating the thread pool
Returns:
the created thread pool, or null if the was no thread pool profile with that given id.

newCachedThreadPool

public ExecutorService newCachedThreadPool(Object source,
                                           String name)
Description copied from interface: ExecutorServiceStrategy
Creates a new cached thread pool.

Important: Using cached thread pool is discouraged as they have no upper bound and can overload the JVM.

Specified by:
newCachedThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newScheduledThreadPool

public ScheduledExecutorService newScheduledThreadPool(Object source,
                                                       String name)
Description copied from interface: ExecutorServiceStrategy
Creates a new scheduled thread pool.

Specified by:
newScheduledThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newScheduledThreadPool

public ScheduledExecutorService newScheduledThreadPool(Object source,
                                                       String name,
                                                       int poolSize)
Description copied from interface: ExecutorServiceStrategy
Creates a new scheduled thread pool.

Will use the pool size from the default thread pool profile

Specified by:
newScheduledThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
poolSize - the core pool size
Returns:
the created thread pool

newFixedThreadPool

public ExecutorService newFixedThreadPool(Object source,
                                          String name,
                                          int poolSize)
Description copied from interface: ExecutorServiceStrategy
Creates a new fixed thread pool.

Specified by:
newFixedThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
poolSize - the core pool size
Returns:
the created thread pool

newSingleThreadExecutor

public ExecutorService newSingleThreadExecutor(Object source,
                                               String name)
Description copied from interface: ExecutorServiceStrategy
Creates a new single-threaded thread pool. This is often used for background threads.

Specified by:
newSingleThreadExecutor in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newSynchronousThreadPool

public ExecutorService newSynchronousThreadPool(Object source,
                                                String name)
Description copied from interface: ExecutorServiceStrategy
Creates a new synchronous thread pool, which executes the task in the caller thread (no task queue).

Specified by:
newSynchronousThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
Returns:
the created thread pool

newThreadPool

public ExecutorService newThreadPool(Object source,
                                     String name,
                                     int corePoolSize,
                                     int maxPoolSize)
Description copied from interface: ExecutorServiceStrategy
Creates a new custom thread pool.

Will by default use 60 seconds for keep alive time for idle threads. And use CallerRunsPolicy as rejection handler

Specified by:
newThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
corePoolSize - the core pool size
maxPoolSize - the maximum pool size
Returns:
the created thread pool

newThreadPool

public ExecutorService newThreadPool(Object source,
                                     String name,
                                     int corePoolSize,
                                     int maxPoolSize,
                                     int maxQueueSize)
Description copied from interface: ExecutorServiceStrategy
Creates a new custom thread pool.

Will by default use 60 seconds for keep alive time for idle threads. And use CallerRunsPolicy as rejection handler

Specified by:
newThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
corePoolSize - the core pool size
maxPoolSize - the maximum pool size
maxQueueSize - the maximum number of tasks in the queue, use Integer.MAX_INT or -1 to indicate unbounded
Returns:
the created thread pool

newThreadPool

public ExecutorService newThreadPool(Object source,
                                     String name,
                                     int corePoolSize,
                                     int maxPoolSize,
                                     long keepAliveTime,
                                     TimeUnit timeUnit,
                                     int maxQueueSize,
                                     RejectedExecutionHandler rejectedExecutionHandler,
                                     boolean daemon)
Description copied from interface: ExecutorServiceStrategy
Creates a new custom thread pool.

Specified by:
newThreadPool in interface ExecutorServiceStrategy
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
corePoolSize - the core pool size
maxPoolSize - the maximum pool size
keepAliveTime - keep alive time for idle threads
timeUnit - time unit for keep alive time
maxQueueSize - the maximum number of tasks in the queue, use Integer.MAX_INT or -1 to indicate unbounded
rejectedExecutionHandler - the handler for tasks which cannot be executed by the thread pool. If null is provided then CallerRunsPolicy is used.
daemon - whether or not the created threads is daemon or not
Returns:
the created thread pool

shutdown

public void shutdown(ExecutorService executorService)
Description copied from interface: ExecutorServiceStrategy
Shutdown the given executor service.

Specified by:
shutdown in interface ExecutorServiceStrategy
Parameters:
executorService - the executor service to shutdown
See Also:
ExecutorService.shutdown()

shutdownNow

public List<Runnable> shutdownNow(ExecutorService executorService)
Description copied from interface: ExecutorServiceStrategy
Shutdown now the given executor service.

Specified by:
shutdownNow in interface ExecutorServiceStrategy
Parameters:
executorService - the executor service to shutdown now
Returns:
list of tasks that never commenced execution
See Also:
ExecutorService.shutdownNow()

onThreadPoolCreated

protected void onThreadPoolCreated(ExecutorService executorService,
                                   Object source,
                                   String threadPoolProfileId)
Invoked when a new thread pool is created. This implementation will invoke the LifecycleStrategy.onThreadPoolAdd method, which for example will enlist the thread pool in JMX management.

Parameters:
executorService - the thread pool
source - the source to use the thread pool
threadPoolProfileId - profile id, if the thread pool was created from a thread pool profile

onNewExecutorService

protected void onNewExecutorService(ExecutorService executorService)
Strategy callback when a new ExecutorService have been created.

Parameters:
executorService - the created ExecutorService

doStart

protected void doStart()
                throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception

doShutdown

protected void doShutdown()
                   throws Exception
Description copied from class: ServiceSupport
Implementations override this method to perform customized shutdown

Overrides:
doShutdown in class ServiceSupport
Throws:
Exception


Apache CAMEL