final SyncThread syncThread = sleepingThread instanceof SyncThread ? (SyncThread)sleepingThread : null;
final Iterator<EventHandlerProxy> i = tasks.iterator();
while ( i.hasNext() )
{
final EventHandlerProxy task = i.next();
// if ( !filterAsyncUnordered || task.isAsyncOrderedDelivery() )
// {
if ( !useTimeout(task) )
{
// no timeout, we can directly execute
task.sendEvent(event);
}
else if ( syncThread != null )
{
// if this is a cascaded event, we directly use this thread
// otherwise we could end up in a starvation
final long startTime = System.currentTimeMillis();
task.sendEvent(event);
if ( System.currentTimeMillis() - startTime > this.timeout )
{
task.blackListHandler();
}
}
else
{
final Rendezvous startBarrier = new Rendezvous();
final Rendezvous timerBarrier = new Rendezvous();
this.pool.executeTask(new Runnable()
{
@Override
public void run()
{
try
{
// notify the outer thread to start the timer
startBarrier.waitForRendezvous();
// execute the task
task.sendEvent(event);
// stop the timer
timerBarrier.waitForRendezvous();
}
catch (final IllegalStateException ise)
{
// this can happen on shutdown, so we ignore it
}
}
});
// we wait for the inner thread to start
startBarrier.waitForRendezvous();
// timeout handling
// we sleep for the sleep time
// if someone wakes us up it's the finished inner task
try
{
timerBarrier.waitAttemptForRendezvous(this.timeout);
}
catch (final TimeoutException ie)
{
// if we timed out, we have to blacklist the handler
task.blackListHandler();
}
}
// }
}