fulmine.util.concurrent
Class TaskExecutor

java.lang.Object
  extended by fulmine.util.concurrent.TaskExecutor
All Implemented Interfaces:
IDestroyable, ILifeCycle, ITaskExecutor, Executor

public final class TaskExecutor
extends Object
implements ITaskExecutor, ILifeCycle

A single threaded Executor for tasks. This has an unbounded task queue. There are 2 modes of operation for this;

These 2 modes provide the necessary behaviour to meet different application processing requirements. A polling behaviour is suitable for high volume non-critical task submission; the threads submitting the tasks do not wake up the executing thread. The executing thread will periodically poll the task queue and consume all tasks. The trade-off for the submitting thread not having to notify the executing thread is greater context switching regardless of whether there are any tasks to process for the executing thread.

There is a single global Timer used by all executors for handling the scheduling of tasks via the schedule(TimerTask, long, long) method. The actual task will be run by the TaskExecutor - the timer is merely used to schedule a call to execute(Runnable) when the task is due for (re)execution.

Author:
Ramon Servadei

Constructor Summary
TaskExecutor(String identity, IFulmineContext context)
          Construct the executor in event driven mode in the same thread group as the calling thread.
TaskExecutor(String identity, long pollingPeriod, IFulmineContext context)
          Construct the executor in polling or event driven mode in the same thread group as the calling thread.
TaskExecutor(ThreadGroup threadGroup, String identity, IFulmineContext context)
          Construct the executor in event driven mode with a specific priority
 
Method Summary
 void destroy()
          This is called when the object is being removed from application use.
 void execute(Runnable command)
          Add the task to a queue for processing by a single thread
 StackTraceElement[] getStackTrace()
          Get the current stack of the executor
 boolean isActive()
          Determine if this life-cycle object is active.
 void schedule(TimerTask task, long delay, long period)
          Schedule a timer task to be executed by a single worker thread.
 void start()
          Activate (start) this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskExecutor

public TaskExecutor(String identity,
                    IFulmineContext context)
Construct the executor in event driven mode in the same thread group as the calling thread.

Parameters:
identity - the identity of the executor
context - required to construct the information container record, this is done lazily

TaskExecutor

public TaskExecutor(String identity,
                    long pollingPeriod,
                    IFulmineContext context)
Construct the executor in polling or event driven mode in the same thread group as the calling thread.

Parameters:
identity - the identity of the executor
pollingPeriod - the polling period, in milliseconds or 0 or less for event driven mode
context - required to construct the information container record, this is done lazily

TaskExecutor

public TaskExecutor(ThreadGroup threadGroup,
                    String identity,
                    IFulmineContext context)
Construct the executor in event driven mode with a specific priority

Parameters:
threadGroup - the thread group and priority
identity - the identity of the executor
context - required to construct the information container record, this is done lazily
Method Detail

execute

public void execute(Runnable command)
Description copied from interface: ITaskExecutor
Add the task to a queue for processing by a single thread

Specified by:
execute in interface ITaskExecutor
Specified by:
execute in interface Executor
Parameters:
command - the task to add to a queue that is processed by a single thread

isActive

public boolean isActive()
Description copied from interface: ILifeCycle
Determine if this life-cycle object is active.

Specified by:
isActive in interface ILifeCycle
Returns:
true if the object is active

start

public void start()
Description copied from interface: ILifeCycle
Activate (start) this object. This allocates system resources required for the object to operate. This operation is idempotent.

This method may throw a RuntimeException if it fails to activate the object.

Specified by:
start in interface ILifeCycle

destroy

public void destroy()
Description copied from interface: IDestroyable
This is called when the object is being removed from application use. This releases all system resources and performs clean up prior to the object becoming redundant. This operation is idempotent.

This method must not throw a RuntimeException.

Specified by:
destroy in interface IDestroyable

getStackTrace

public StackTraceElement[] getStackTrace()
Description copied from interface: ITaskExecutor
Get the current stack of the executor

Specified by:
getStackTrace in interface ITaskExecutor
Returns:
the current stack of the executor
See Also:
Thread.getStackTrace()

schedule

public void schedule(TimerTask task,
                     long delay,
                     long period)
Description copied from interface: ITaskExecutor
Schedule a timer task to be executed by a single worker thread.

Specified by:
schedule in interface ITaskExecutor
Parameters:
task - task to be scheduled.
delay - delay in milliseconds before task is to be executed.
period - time in milliseconds between successive task executions.


Copyright © 2007-2009. All Rights Reserved.