com.myJava.util.taskmonitor
Class TaskMonitor

java.lang.Object
  extended by com.myJava.util.taskmonitor.TaskMonitor

public class TaskMonitor
extends java.lang.Object

This task allows to monitor a task completion. It also holds multiple listeners for event management.

Author:
Olivier PETRUCCI

Areca Build ID : 7299034069467778562

Field Summary
protected  boolean cancellable
          Boolean telling whether the current tack can be canceled or not
protected  boolean cancelRequested
          Tells whether a "cancel" has been requested by the user
protected  double currentCompletionRate
          Completion rate of the task : between 0 and 1
protected  TaskMonitor currentSubTask
          Current subtask
protected  double currentSubTaskShare
          Part of the subtask in the global task completion (between 0 and 1)
protected  java.util.List listeners
          Task's listeners
protected  java.lang.String name
          Task name
protected  TaskMonitor parentTask
          Parent task (null if no parent task)
static long PAUSE_CHECK_DELAY_MS
           
protected  boolean pauseRequested
          Tells whether a "pause" has been requested by the user
 
Constructor Summary
TaskMonitor(java.lang.String name)
           
 
Method Summary
 void addCompletion(double completionStep)
           
 void addListener(TaskMonitorListener listener)
          Add a new listener
 void addNewSubTask(double subTaskShare, java.lang.String name)
           
 void checkTaskState()
          Checks whether the task has been canceled or paused.
 void clearAllListeners()
          remove all listeners
protected  void completionChanged()
          Call all listeners
 void enforceCompletion()
          Enforces the task's completion.
 TaskMonitor getCurrentActiveSubTask()
          Returns the really active subtask of the current task.
 double getGlobalCompletionRate()
          Return the global completion rate of the task
Task completion rate + subtask share * subtask global completion rate
 boolean isCancellable()
           
 boolean isCancelRequested()
           
 boolean isPauseRequested()
           
 void resetCancellationState()
           
 void setCancellable(boolean cancellable)
           
 void setCancelRequested()
           
 void setCurrentCompletion(double completion)
          Enforce the task's global completion rate.
 void setCurrentCompletion(long numerator, long denominator)
           
 void setCurrentSubTask(TaskMonitor subTask, double subTaskShare)
          Set the current sub task.
 void setPauseRequested(boolean pauseRequested)
           
 java.lang.String toOldString()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PAUSE_CHECK_DELAY_MS

public static final long PAUSE_CHECK_DELAY_MS
See Also:
Constant Field Values

currentCompletionRate

protected double currentCompletionRate
Completion rate of the task : between 0 and 1


currentSubTask

protected TaskMonitor currentSubTask
Current subtask


currentSubTaskShare

protected double currentSubTaskShare
Part of the subtask in the global task completion (between 0 and 1)


parentTask

protected TaskMonitor parentTask
Parent task (null if no parent task)


listeners

protected java.util.List listeners
Task's listeners


pauseRequested

protected boolean pauseRequested
Tells whether a "pause" has been requested by the user


cancellable

protected boolean cancellable
Boolean telling whether the current tack can be canceled or not


cancelRequested

protected boolean cancelRequested
Tells whether a "cancel" has been requested by the user


name

protected java.lang.String name
Task name

Constructor Detail

TaskMonitor

public TaskMonitor(java.lang.String name)
Method Detail

addListener

public void addListener(TaskMonitorListener listener)
Add a new listener

Parameters:
listener -

clearAllListeners

public void clearAllListeners()
remove all listeners


getGlobalCompletionRate

public double getGlobalCompletionRate()
Return the global completion rate of the task
Task completion rate + subtask share * subtask global completion rate

Returns:

setCurrentSubTask

public void setCurrentSubTask(TaskMonitor subTask,
                              double subTaskShare)
Set the current sub task.

Parameters:
subTask -
subTaskShare - is the share of the subtask in the task's global completion (between 0 and 1)

addNewSubTask

public void addNewSubTask(double subTaskShare,
                          java.lang.String name)

setCurrentCompletion

public void setCurrentCompletion(double completion)
Enforce the task's global completion rate. It can be done only if the current sub task is completed

Parameters:
completion -

addCompletion

public void addCompletion(double completionStep)

setCurrentCompletion

public void setCurrentCompletion(long numerator,
                                 long denominator)

enforceCompletion

public void enforceCompletion()
Enforces the task's completion.
All subtasks are deleted.
Since no checks are made, it must be used VERY carefully.


getCurrentActiveSubTask

public TaskMonitor getCurrentActiveSubTask()
Returns the really active subtask of the current task.
It is the last subtask which has been added in the subtask tree.
It is the only task whose completion rate can be set (by calling setCurrentCompletion)

Returns:

completionChanged

protected void completionChanged()
Call all listeners


isCancellable

public boolean isCancellable()

isCancelRequested

public boolean isCancelRequested()

isPauseRequested

public boolean isPauseRequested()

setPauseRequested

public void setPauseRequested(boolean pauseRequested)

setCancelRequested

public void setCancelRequested()

resetCancellationState

public void resetCancellationState()

setCancellable

public void setCancellable(boolean cancellable)

checkTaskState

public void checkTaskState()
                    throws TaskCancelledException
Checks whether the task has been canceled or paused.

Throws:
TaskCancelledException

toOldString

public java.lang.String toOldString()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object