org.apache.camel.impl
Class DefaultExecutorServiceManager

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.impl.DefaultExecutorServiceManager
All Implemented Interfaces:
Service, ShutdownableService, ExecutorServiceManager, StatefulService, SuspendableService

public class DefaultExecutorServiceManager
extends ServiceSupport
implements ExecutorServiceManager

Version:

Field Summary
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
DefaultExecutorServiceManager(CamelContext camelContext)
           
 
Method Summary
protected  void doShutdown()
          Implementations override this method to perform customized shutdown.
protected  void doStart()
          Implementations override this method to support customized start/stop.
protected  void doStop()
          Implementations override this method to support customized start/stop.
 ThreadPoolProfile getDefaultThreadPoolProfile()
          Gets the default thread pool profile
 String getThreadNamePattern()
          Gets the thread name patter to use
 ThreadPoolFactory getThreadPoolFactory()
          Gets the ThreadPoolFactory to use for creating the thread pools.
 ThreadPoolProfile getThreadPoolProfile(String id)
          Gets the thread pool profile by the given id
 ExecutorService newCachedThreadPool(Object source, String name)
          Creates a new cached thread pool.
 ScheduledExecutorService newDefaultScheduledThreadPool(Object source, String name)
          Creates a new scheduled thread pool using the default thread pool profile.
 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, int poolSize)
          Creates a new scheduled thread pool.
 ScheduledExecutorService newScheduledThreadPool(Object source, String name, String profileId)
          Creates a new scheduled thread pool using a profile id
 ScheduledExecutorService newScheduledThreadPool(Object source, String name, ThreadPoolProfile profile)
          Creates a new scheduled thread pool using a profile
 ExecutorService newSingleThreadExecutor(Object source, String name)
          Creates a new single-threaded thread pool.
 ScheduledExecutorService newSingleThreadScheduledExecutor(Object source, String name)
          Creates a new single-threaded thread pool.
 ExecutorService newThreadPool(Object source, String name, int poolSize, int maxPoolSize)
          Creates a new thread pool.
 ExecutorService newThreadPool(Object source, String name, String profileId)
          Creates a new thread pool using using the given profile id
 ExecutorService newThreadPool(Object source, String name, ThreadPoolProfile profile)
          Creates a new thread pool using the given profile
protected  void onNewExecutorService(ExecutorService executorService)
          Strategy callback when a new ExecutorService have been created.
 void registerThreadPoolProfile(ThreadPoolProfile profile)
          Registers the given thread pool profile
 String resolveThreadName(String name)
          Creates a full thread name
 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 setThreadPoolFactory(ThreadPoolFactory threadPoolFactory)
          Sets a custom ThreadPoolFactory to use
 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.support.ServiceSupport
doResume, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, resume, shutdown, 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

DefaultExecutorServiceManager

public DefaultExecutorServiceManager(CamelContext camelContext)
Method Detail

getThreadPoolFactory

public ThreadPoolFactory getThreadPoolFactory()
Description copied from interface: ExecutorServiceManager
Gets the ThreadPoolFactory to use for creating the thread pools.

Specified by:
getThreadPoolFactory in interface ExecutorServiceManager
Returns:
the thread pool factory

setThreadPoolFactory

public void setThreadPoolFactory(ThreadPoolFactory threadPoolFactory)
Description copied from interface: ExecutorServiceManager
Sets a custom ThreadPoolFactory to use

Specified by:
setThreadPoolFactory in interface ExecutorServiceManager
Parameters:
threadPoolFactory - the thread pool factory

registerThreadPoolProfile

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

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

getThreadPoolProfile

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

Specified by:
getThreadPoolProfile in interface ExecutorServiceManager
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: ExecutorServiceManager
Gets the default thread pool profile

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

setDefaultThreadPoolProfile

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

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

getThreadNamePattern

public String getThreadNamePattern()
Description copied from interface: ExecutorServiceManager
Gets the thread name patter to use

Specified by:
getThreadNamePattern in interface ExecutorServiceManager
Returns:
the pattern

setThreadNamePattern

public void setThreadNamePattern(String threadNamePattern)
Description copied from interface: ExecutorServiceManager
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 ExecutorServiceManager
Parameters:
threadNamePattern - the pattern

resolveThreadName

public String resolveThreadName(String name)
Description copied from interface: ExecutorServiceManager
Creates a full thread name

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

newDefaultThreadPool

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

Specified by:
newDefaultThreadPool in interface ExecutorServiceManager
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

newDefaultScheduledThreadPool

public ScheduledExecutorService newDefaultScheduledThreadPool(Object source,
                                                              String name)
Description copied from interface: ExecutorServiceManager
Creates a new scheduled thread pool using the default thread pool profile.

Specified by:
newDefaultScheduledThreadPool in interface ExecutorServiceManager
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 profileId)
Description copied from interface: ExecutorServiceManager
Creates a new thread pool using using the given profile id

Specified by:
newThreadPool in interface ExecutorServiceManager
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
profileId - the id of the profile with the thread pool settings to use
Returns:
the created thread pool, or null if the thread pool profile could not be found

newThreadPool

public ExecutorService newThreadPool(Object source,
                                     String name,
                                     ThreadPoolProfile profile)
Description copied from interface: ExecutorServiceManager
Creates a new thread pool using the given profile

Specified by:
newThreadPool in interface ExecutorServiceManager
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
profile - the profile with the thread pool settings to use
Returns:
the created thread pool

newThreadPool

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

Will fallback and use values from the default thread pool profile for keep alive time, rejection policy and other parameters which cannot be specified.

Specified by:
newThreadPool in interface ExecutorServiceManager
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
maxPoolSize - the maximum pool size
Returns:
the created thread pool

newSingleThreadExecutor

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

Notice that there will always be a single thread in the pool. If you want the pool to be able to shrink to no threads, then use the newThreadPool method, and use 0 in core pool size, and 1 in max pool size.

Specified by:
newSingleThreadExecutor in interface ExecutorServiceManager
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

newCachedThreadPool

public ExecutorService newCachedThreadPool(Object source,
                                           String name)
Description copied from interface: ExecutorServiceManager
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 ExecutorServiceManager
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

newFixedThreadPool

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

Specified by:
newFixedThreadPool in interface ExecutorServiceManager
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

newSingleThreadScheduledExecutor

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

Specified by:
newSingleThreadScheduledExecutor in interface ExecutorServiceManager
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,
                                                       ThreadPoolProfile profile)
Description copied from interface: ExecutorServiceManager
Creates a new scheduled thread pool using a profile

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

newScheduledThreadPool

public ScheduledExecutorService newScheduledThreadPool(Object source,
                                                       String name,
                                                       String profileId)
Description copied from interface: ExecutorServiceManager
Creates a new scheduled thread pool using a profile id

Specified by:
newScheduledThreadPool in interface ExecutorServiceManager
Parameters:
source - the source object, usually it should be this passed in as parameter
name - name which is appended to the thread name
profileId - the id of the profile with the thread pool settings to use
Returns:
created thread pool

newScheduledThreadPool

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

Specified by:
newScheduledThreadPool in interface ExecutorServiceManager
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

shutdown

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

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

shutdownNow

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

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

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
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: See ServiceSupport.doStop() for more details.

Specified by:
doStart in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStop()

doStop

protected void doStop()
               throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: Camel will invoke this ServiceSupport.doStop() method when the service is being stopped. This method will also be invoked if the service is still in uninitialized state (eg has not been started). The method is always called to allow the service to do custom logic when the service is being stopped, such as when CamelContext is shutting down.

Specified by:
doStop in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStart()

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