Trull

edu.luc.cs.trull.task
Class DefaultTaskWorker

java.lang.Object
  extended by edu.luc.cs.trull.EmptyComponent
      extended by edu.luc.cs.trull.TerminatingComponent
          extended by edu.luc.cs.trull.task.DefaultTaskWorker
All Implemented Interfaces:
Component, PropertyChangeSource, Startable, Suspendable, Terminating, java.beans.PropertyChangeListener, java.util.EventListener

public class DefaultTaskWorker
extends TerminatingComponent

A Worker for the step-by-step execution of a Task using Trull's default scheduling mechanism. If this Worker does not provide sufficient responsiveness, consider making the task finer-grained or using a Worker implementation that carries out the task in one or more separate threads.

See Also:
Task, QueuedTaskWorker, PooledTaskWorker

Field Summary
protected  boolean firstTime
          A flag indicating whether the task is being executed for the first time.
private static org.apache.log4j.Logger logger
           
protected  java.lang.Runnable repeat
          A Runnable that executes one step of the task and reschedules itself for execution as long as the worker has not been suspended.
protected static int RUNNING
          The running state.
protected  int state
          The variable holding the current state.
protected static int STOPPED
          The stopped state.
protected static int SUSPENDED
          The suspended state.
protected  Task task
          The task executed by this worker.
 
Constructor Summary
DefaultTaskWorker(Task task)
          Constructs a worker for the given task.
 
Method Summary
 void resume()
          Resumes this suspendable component.
 void setTask(Task task)
          Sets the task to be performed.
 void start(java.beans.PropertyChangeEvent incoming)
          Restarts the task if necessary and schedules the repeat Runnable for executing the task step-by-step.
 void stop()
          Stops this startable component.
 void suspend()
          Suspends this suspendable component.
 
Methods inherited from class edu.luc.cs.trull.TerminatingComponent
fireTermination, getParent, getTermEvent, scheduleTermination, setTerminationListener
 
Methods inherited from class edu.luc.cs.trull.EmptyComponent
addPropertyChangeListener, getPropertyChangeListeners, getTerminationListener, propertyChange, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

firstTime

protected boolean firstTime
A flag indicating whether the task is being executed for the first time.


logger

private static org.apache.log4j.Logger logger

repeat

protected final java.lang.Runnable repeat
A Runnable that executes one step of the task and reschedules itself for execution as long as the worker has not been suspended.


RUNNING

protected static final int RUNNING
The running state.

See Also:
Constant Field Values

state

protected int state
The variable holding the current state.


STOPPED

protected static final int STOPPED
The stopped state.

See Also:
Constant Field Values

SUSPENDED

protected static final int SUSPENDED
The suspended state.

See Also:
Constant Field Values

task

protected Task task
The task executed by this worker.

Constructor Detail

DefaultTaskWorker

public DefaultTaskWorker(Task task)
Constructs a worker for the given task.

Parameters:
task - the task to be performed.
Throws:
java.lang.IllegalArgumentException - if the task is null.
Method Detail

resume

public void resume()
Description copied from interface: Suspendable
Resumes this suspendable component.

Specified by:
resume in interface Suspendable
Overrides:
resume in class EmptyComponent

setTask

public void setTask(Task task)
Sets the task to be performed.

Parameters:
task - the task to be performed.
Throws:
java.lang.IllegalArgumentException - if the task is null.

start

public void start(java.beans.PropertyChangeEvent incoming)
Restarts the task if necessary and schedules the repeat Runnable for executing the task step-by-step.

Specified by:
start in interface Startable
Overrides:
start in class EmptyComponent
Parameters:
incoming - the event that triggered the invocation of this method. May be null.

stop

public void stop()
Description copied from interface: Startable
Stops this startable component.

Specified by:
stop in interface Startable
Overrides:
stop in class EmptyComponent

suspend

public void suspend()
Description copied from interface: Suspendable
Suspends this suspendable component.

Specified by:
suspend in interface Suspendable
Overrides:
suspend in class EmptyComponent

Trull

http://www.cs.luc.edu/trull/