org.apache.felix.eventadmin.impl.tasks
Class AsyncDeliverTasks

java.lang.Object
  extended by org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks
All Implemented Interfaces:
DeliverTask, DeliverTasks, HandoverTask

public class AsyncDeliverTasks
extends java.lang.Object
implements DeliverTasks, HandoverTask, DeliverTask

This class does the actual work of the asynchronous event dispatch.

It serves two purposes: first, it will append tasks to its queue hence, asynchronous event delivery is executed - second, it will set up a given dispatch task with its ThreadPool in a way that it is associated with a DeliverTask that will block in case the thread hits the SyncDeliverTasks.

In other words, if the asynchronous event dispatching thread is used to send a synchronous event then it will spin-off a new asynchronous dispatching thread while the former waits for the synchronous event to be delivered and then return to its ThreadPool.

Author:
Felix Project Team

Constructor Summary
AsyncDeliverTasks(TaskQueue queue, TaskQueue handoverQueue, ThreadPool pool)
          The constructor of the class that will use the asynchronous queue to append event dispatch handlers.
 
Method Summary
 DeliverTask createTask()
          Return a DeliverTask that can be used to execute asynchronous event dispatch.
 void execute(DispatchTask task)
          Execute the handover in case of timeout or that the asynchronous event dispatching thread is used to send a synchronous event.
 void execute(HandlerTask[] tasks)
          Execute asynchronous event dispatch.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncDeliverTasks

public AsyncDeliverTasks(TaskQueue queue,
                         TaskQueue handoverQueue,
                         ThreadPool pool)
The constructor of the class that will use the asynchronous queue to append event dispatch handlers. Furthermore, a second queue is used to append the events in case that the asynchronous event dispatching thread is used to send a synchronous event - in this case the given ThreadPool is used to spin-off a new asynchronous event dispatching thread while the former waits for the synchronous event to be delivered.

Parameters:
queue - The asynchronous event queue
handoverQueue - The synchronous event queue, to be used in case that the asynchronous event dispatching thread is used to send a synchronous event
pool - The thread pool used to spin-off new asynchronous event dispatching threads in case of timeout or that the asynchronous event dispatching thread is used to send a synchronous event
Method Detail

createTask

public DeliverTask createTask()
Return a DeliverTask that can be used to execute asynchronous event dispatch.

Specified by:
createTask in interface DeliverTasks
Returns:
A task that can be used to execute asynchronous event dispatch
See Also:
DeliverTasks.createTask()

execute

public void execute(HandlerTask[] tasks)
Execute asynchronous event dispatch.

Specified by:
execute in interface DeliverTask
Parameters:
tasks - The event dispatch tasks to execute
See Also:
DeliverTask.execute(org.apache.felix.eventadmin.impl.tasks.HandlerTask[])

execute

public void execute(DispatchTask task)
Execute the handover in case of timeout or that the asynchronous event dispatching thread is used to send a synchronous event.

Specified by:
execute in interface HandoverTask
Parameters:
task - The task to set-up in a new thread
See Also:
HandoverTask.execute(org.apache.felix.eventadmin.impl.tasks.DispatchTask)