org.apache.cocoon.thread.impl
Class DefaultRunnableManager

java.lang.Object
  extended byorg.apache.cocoon.thread.impl.DefaultRunnableManager
All Implemented Interfaces:
Runnable, org.apache.cocoon.thread.RunnableManager

public class DefaultRunnableManager
extends Object
implements org.apache.cocoon.thread.RunnableManager, Runnable

The DefaultRunnableManager implements the RunnableManager interface and is responsible to create ThreadPools and run Runnables in them as background commands.

The configuration of the DefaultRunnableManager:

     <property name="workerThreadPools">
       <configurator:bean-map type="org.apache.cocoon.thread.ThreadPool" strip-prefix="true"/>
     </property>
 

Version:
$Id: DefaultRunnableManager.java 498489 2007-01-21 23:19:09Z jjohnston $

Field Summary
protected  SortedSet commandStack
          Sorted set of ExecutionInfo instances, based on their next execution time.
 
Fields inherited from interface org.apache.cocoon.thread.RunnableManager
ROLE
 
Constructor Summary
DefaultRunnableManager()
           
 
Method Summary
 org.apache.cocoon.thread.ThreadPool createPool(int queueSize, int maxPoolSize, int minPoolSize, int priority, boolean isDaemon, long keepAliveTime, String blockPolicy, boolean shutdownGraceful, int shutdownWaitTime)
          Create a private ThreadPool
 org.apache.cocoon.thread.ThreadPool createPool(String name, int queueSize, int maxPoolSize, int minPoolSize, int priority, boolean isDaemon, long keepAliveTime, String blockPolicy, boolean shutdownGraceful, int shutdownWaitTimeMs)
          Create a shared ThreadPool
 void destroy()
          Destroy
 void execute(Runnable command)
          Run a Runnable in the background using a ThreadPool
 void execute(Runnable command, long delay)
          Run a Runnable in the background using a ThreadPool
 void execute(Runnable command, long delay, long interval)
          Run a Runnable in the background using a ThreadPool
 void execute(String threadPoolName, Runnable command)
          Run a Runnable in the background using a ThreadPool
 void execute(String threadPoolName, Runnable command, long delay)
          Run a Runnable in the background using a ThreadPool
 void execute(String threadPoolName, Runnable command, long delay, long interval)
          Run a Runnable in the background using a ThreadPool
 Log getLogger()
           
 org.apache.cocoon.thread.ThreadPool getPool(String name)
           
 void init()
          Initialize
 void remove(Runnable command)
          Remove a Runnable from the command stack
 void run()
          The heart of the command manager
 void setLogger(Log l)
           
 void setWorkerThreadPools(Map workerThreadPools)
           
protected  void start()
          Start the managing thread
protected  void stop()
          Stop the managing thread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commandStack

protected SortedSet commandStack
Sorted set of ExecutionInfo instances, based on their next execution time.

Constructor Detail

DefaultRunnableManager

public DefaultRunnableManager()
Method Detail

getLogger

public Log getLogger()

setLogger

public void setLogger(Log l)

init

public void init()
          throws Exception
Initialize

Throws:
Exception

createPool

public org.apache.cocoon.thread.ThreadPool createPool(String name,
                                                      int queueSize,
                                                      int maxPoolSize,
                                                      int minPoolSize,
                                                      int priority,
                                                      boolean isDaemon,
                                                      long keepAliveTime,
                                                      String blockPolicy,
                                                      boolean shutdownGraceful,
                                                      int shutdownWaitTimeMs)
Create a shared ThreadPool

Specified by:
createPool in interface org.apache.cocoon.thread.RunnableManager
Parameters:
name - The name of the thread pool
queueSize - The size of the queue
maxPoolSize - The maximum number of threads
minPoolSize - The maximum number of threads
priority - The priority of threads created by this pool. This is one of Thread.MIN_PRIORITY, Thread.NORM_PRIORITY, or Thread.MAX_PRIORITY
isDaemon - Whether or not thread from the pool should run in daemon mode
keepAliveTime - How long should a thread be alive for new work to be done before it is GCed
blockPolicy - What's the blocking policy is resources are exhausted
shutdownGraceful - Should we wait for the queue to finish all pending commands?
Throws:
IllegalArgumentException - If the pool already exists

createPool

public org.apache.cocoon.thread.ThreadPool createPool(int queueSize,
                                                      int maxPoolSize,
                                                      int minPoolSize,
                                                      int priority,
                                                      boolean isDaemon,
                                                      long keepAliveTime,
                                                      String blockPolicy,
                                                      boolean shutdownGraceful,
                                                      int shutdownWaitTime)
Create a private ThreadPool

Specified by:
createPool in interface org.apache.cocoon.thread.RunnableManager
Parameters:
queueSize - The size of the queue
maxPoolSize - The maximum number of threads
minPoolSize - The maximum number of threads
priority - The priority of threads created by this pool. This is one of Thread.MIN_PRIORITY, Thread.NORM_PRIORITY, or Thread.MAX_PRIORITY
isDaemon - Whether or not thread from the pool should run in daemon mode
keepAliveTime - How long should a thread be alive for new work to be done before it is GCed
blockPolicy - What's the blocking policy is resources are exhausted
shutdownGraceful - Should we wait for the queue to finish all pending commands?
shutdownWaitTime - After what time a normal shutdown should take into account if a graceful shutdown has not come to an end
Returns:
A newly created ThreadPool

getPool

public org.apache.cocoon.thread.ThreadPool getPool(String name)
Specified by:
getPool in interface org.apache.cocoon.thread.RunnableManager
See Also:
RunnableManager.getPool(java.lang.String)

destroy

public void destroy()
             throws Exception
Destroy

Throws:
Exception

execute

public void execute(String threadPoolName,
                    Runnable command,
                    long delay,
                    long interval)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface org.apache.cocoon.thread.RunnableManager
Parameters:
threadPoolName - The thread pool name to be used
command - The Runnable to execute
delay - the delay befor first run
interval - The interval for repeated runs
Throws:
IllegalArgumentException - DOCUMENT ME!

execute

public void execute(Runnable command,
                    long delay,
                    long interval)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface org.apache.cocoon.thread.RunnableManager
Parameters:
command - The Runnable to execute
delay - the delay befor first run
interval - The interval for repeated runs

execute

public void execute(Runnable command,
                    long delay)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface org.apache.cocoon.thread.RunnableManager
Parameters:
command - The Runnable to execute
delay - the delay befor first run

execute

public void execute(Runnable command)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface org.apache.cocoon.thread.RunnableManager
Parameters:
command - The Runnable to execute

execute

public void execute(String threadPoolName,
                    Runnable command,
                    long delay)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface org.apache.cocoon.thread.RunnableManager
Parameters:
threadPoolName - The thread pool name to be used
command - The Runnable to execute
delay - the delay befor first run

execute

public void execute(String threadPoolName,
                    Runnable command)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface org.apache.cocoon.thread.RunnableManager
Parameters:
threadPoolName - The thread pool name to be used
command - The Runnable to execute

remove

public void remove(Runnable command)
Remove a Runnable from the command stack

Specified by:
remove in interface org.apache.cocoon.thread.RunnableManager
Parameters:
command - The Runnable to be removed

run

public void run()
The heart of the command manager

Specified by:
run in interface Runnable

start

protected void start()
              throws Exception
Start the managing thread

Throws:
Exception - DOCUMENT ME!

stop

protected void stop()
Stop the managing thread


setWorkerThreadPools

public void setWorkerThreadPools(Map workerThreadPools)
Parameters:
workerThreadPools - the workerThreadPools to set


Copyright © 1999-2008 The Apache Software Foundation. All Rights Reserved.