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

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

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

This class does the actual work of the synchronous event delivery.

It serves two purposes, first it is used to select the appropriate action depending on whether the sending thread is the asynchronous, the synchronous, or an unrelated thread. Second, it will set up a given dispatch task with its ThreadPool in a way that it is associated with a DeliverTask that will push given handler tasks to the queue and then wait for the tasks to be completed.

In other words if an unrelated thread is used to send a synchronous event it is blocked until the event is send (or a timeout occurs), if an asynchronous thread is used its handover callback is called in order to spin-off a new asynchronous delivery thread and the former is blocked until the events are delivered and then released (or returned to its thread pool), if a synchronous thread is used its task is disabled, the events are pushed to the queue and the threads continuous with the delivery of the new events (as per spec). Once the new events are done the thread wakes-up the disabled task and resumes to execute it.

Note that in case of a timeout while a task is disabled the thread is released and we spin-off a new thread that resumes the disabled task hence, this is the only place were we break the semantics of the synchronous delivery. While the only one to notice this is the timed-out handler - it is the fault of this handler too (i.e., it blocked the dispatch for to long) but since it will not receive events anymore it will not notice this semantic difference except that it might not see events it already sent before.

Author:
Felix Project Team

Constructor Summary
SyncDeliverTasks(TaskQueue queue, ThreadPool pool)
           
 
Method Summary
 DeliverTask createTask()
          This will select the appropriate action depending on whether the sending thread is the asynchronous, the synchronous, or an unrelated thread.
 void execute(DispatchTask task)
          Set up a given dispatch task with its ThreadPool in a way that it is associated with a DeliverTask that will push given handler tasks to the queue and then wait for the tasks to be completed.
 void execute(HandlerTask[] tasks)
          This blocks an unrelated thread used to send a synchronous event until the event is send (or a timeout occurs).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyncDeliverTasks

public SyncDeliverTasks(TaskQueue queue,
                        ThreadPool pool)
Parameters:
queue - The synchronous event queue
pool - The thread pool used to spin-off new threads and associate callbacks with tasks
Method Detail

createTask

public DeliverTask createTask()
This will select the appropriate action depending on whether the sending thread is the asynchronous, the synchronous, or an unrelated thread.

Specified by:
createTask in interface DeliverTasks
Returns:
The appropriate action
See Also:
DeliverTasks.createTask()

execute

public void execute(HandlerTask[] tasks)
This blocks an unrelated thread used to send a synchronous event until the event is send (or a timeout occurs).

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

execute

public void execute(DispatchTask task)
Set up a given dispatch task with its ThreadPool in a way that it is associated with a DeliverTask that will push given handler tasks to the queue and then wait for the tasks to be completed.

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