guarana.toolkit.engine
Class WorkUnit

java.lang.Object
  extended by guarana.toolkit.engine.WorkUnit
All Implemented Interfaces:
Comparable<WorkUnit>

public class WorkUnit
extends Object
implements Comparable<WorkUnit>

Represents a wrapper for tasks that can be executed. Work units have, apart of the task to be execute, the date and time it must be executed.

Since:
Guaranį SDK 1.0.0
Author:
Rafael Z. Frantz

Constructor Summary
WorkUnit(Task task)
          Creates a work unit for a given Task which can be processed instantaneously.
WorkUnit(Task task, long notBefore)
          Creates a work unit for a given Task which must be processed on the specified date or latter.
 
Method Summary
 int compareTo(WorkUnit workUnit)
          Compares the current work unit with another one.
 void execute()
          Executes the wrapped task by this object and if the task is a trigger task, computes the next execution time.
 long getDateToExecute()
          Return the date on which this work unit can be processed.
 Task getTask()
          Returns the task assigned to be processed by this work unit.
 boolean isTrigger()
          Checks if this object contains a trigger task.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkUnit

public WorkUnit(Task task,
                long notBefore)
Creates a work unit for a given Task which must be processed on the specified date or latter.

Parameters:
task - The Task which can be processed.
notBefore - The date on which this work unit can be processed.

WorkUnit

public WorkUnit(Task task)
Creates a work unit for a given Task which can be processed instantaneously.

Parameters:
task - the Task which can be processed.
Method Detail

compareTo

public int compareTo(WorkUnit workUnit)
Compares the current work unit with another one. Each work unit has its own date to be processed, which is used to establish priority on processing.

Specified by:
compareTo in interface Comparable<WorkUnit>
Parameters:
workUnit - The work unit to compare with this one.
Returns:
-1 if the current work unit must be processed first;
0 if both work units have the same processed date defined;
+1 if the current work unit must be processed after.

isTrigger

public boolean isTrigger()
Checks if this object contains a trigger task.

Returns:
True if this object is a trigger task; otherwise, False.

execute

public void execute()
             throws TaskExecutionException
Executes the wrapped task by this object and if the task is a trigger task, computes the next execution time.

Throws:
TaskExecutionException - throws any exception caused by the task execute() method.
See Also:
Task, TaskExecutionException

getTask

public Task getTask()
Returns the task assigned to be processed by this work unit.

Returns:
the task.

getDateToExecute

public long getDateToExecute()
Return the date on which this work unit can be processed. This date is returned in milliseconds.

Returns:
the date.


Guaranį DSL Home