org.apache.felix.eventadmin.impl.dispatch
Interface ThreadPool

All Known Implementing Classes:
CacheThreadPool

public interface ThreadPool

A ThreadPool interface that allows to execute tasks using pooled threads in order to ease the thread creation overhead and additionally, to associate a callback with the thread that executes the task. Subsequently, the callback for a given thread can be asked from instances of this class. Finally, the currently executed task of a thread created by this pool can be retrieved as well. The look-up methods accept plain thread objects and will return given default values in case that the specific threads have not been created by this pool. Note that a closed pool should still execute new tasks but stop pooling threads.

Author:
Felix Project Team

Method Summary
 void close()
          Close the pool i.e, stop pooling threads.
 void execute(DispatchTask task, DeliverTask callback)
          Execute the task in a free thread or create a new one.
 DeliverTask getCallback(java.lang.Thread thread, DeliverTask defaultCallback)
          Look-up the callback associated with the task that the given thread is currently executing or return the default value that may be null.
 DispatchTask getTask(java.lang.Thread thread, DispatchTask defaultTask)
          Look-up the task that the given thread is currently executing or return the default value that may be null in case that the thread has not been created by an instance of this class.
 

Method Detail

execute

void execute(DispatchTask task,
             DeliverTask callback)
Execute the task in a free thread or create a new one. The given callback will be associated with the executing thread as long as it is executed.

Parameters:
task - The task to execute
callback - The callback that will be associated with the executing thread or null if none.

getCallback

DeliverTask getCallback(java.lang.Thread thread,
                        DeliverTask defaultCallback)
Look-up the callback associated with the task that the given thread is currently executing or return the default value that may be null.

Parameters:
thread - The thread that is currently executing the task for which to return the callback. In case the thread is not created by an instance of this class the default value will be returned.
defaultCallback - The value to return in case that the thread was not created by an instance of this class. May be null
Returns:
The callback associated with the given thread or the default value.

getTask

DispatchTask getTask(java.lang.Thread thread,
                     DispatchTask defaultTask)
Look-up the task that the given thread is currently executing or return the default value that may be null in case that the thread has not been created by an instance of this class.

Parameters:
thread - The thread whose currently executed task should be returned.
defaultTask - The default value to be returned in case that the thread was not created by this instance or doesn't currently has a task. May be null
Returns:
The task the given thread is currently executing or the defaultTask

close

void close()
Close the pool i.e, stop pooling threads. Note that subsequently, task will still be executed but no pooling is taking place anymore.