juife
v0.1a

net.sf.juife
Class AbstractTask<R>

java.lang.Object
  extended by net.sf.juife.AbstractTask<R>
All Implemented Interfaces:
java.lang.Runnable, Task<R>

public abstract class AbstractTask<R>
extends java.lang.Object
implements Task<R>, java.lang.Runnable

Provides default implementation of the Task interface. This class can be used to facilitate the monitoring of time-consuming task. Note that all event notifications are done on the event dispatching thread. This means that the event handlers can safely perform operations on Swing components.


Field Summary
static int UNKNOWN_ERROR
           
 
Constructor Summary
AbstractTask()
           
 
Method Summary
 void addTaskListener(TaskListener l)
          Registers the specified TaskListener to be notified when task is done.
 boolean done()
          Determines whether the task has finished execution.
 boolean doneWithErrors()
          Determines whether the task has finished its execution successfully.
 java.lang.String getDescription()
          Gets a short description about this task.
 int getErrorCode()
          Gets an appropriate error code identifying the failure of the task.
 java.lang.String getErrorMessage()
          Gets an appropriate error message when the task fails.
 R getResult()
          Gets the result of the task execution.
 java.lang.String getTitle()
          Gets the title of this task.
 void invoke()
          Starts the execution of this task.
 void invokeAndWait()
          Starts the execution of this task.
 boolean isStarted()
          Determines whether the task has been started.
 void removeTaskListener(TaskListener l)
          Removes the specified listener.
 void setDescription(java.lang.String desc)
          Sets the description of this task.
 void setDone(boolean b)
          Sets whether the task has finished execution.
 void setDoneWithErrors(boolean b)
          Sets whether the execution of the task fails.
 void setErrorCode(int code)
          Sets an error code identifying the failure of the task.
 void setErrorMessage(java.lang.String msg)
          Set the error message of this task.
 void setResult(R result)
          Sets the result of the task execution.
 void setTitle(java.lang.String title)
          Sets the title of this task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.juife.Task
stop
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

UNKNOWN_ERROR

public static int UNKNOWN_ERROR
Constructor Detail

AbstractTask

public AbstractTask()
Method Detail

done

public boolean done()
Determines whether the task has finished execution.

Specified by:
done in interface Task<R>
Returns:
true if the task has finished execution, false otherwise.

setDone

public void setDone(boolean b)
Sets whether the task has finished execution.

Parameters:
b - Specify true to indicate that the task has finished execution and false otherwise.

doneWithErrors

public boolean doneWithErrors()
Determines whether the task has finished its execution successfully.

Specified by:
doneWithErrors in interface Task<R>
Returns:
true if the task has not finished its execution successfully; false otherwise

setDoneWithErrors

public void setDoneWithErrors(boolean b)
Sets whether the execution of the task fails.

Parameters:
b - Specify true to indicate that the execution of the task fails.

getErrorCode

public int getErrorCode()
Gets an appropriate error code identifying the failure of the task.

Specified by:
getErrorCode in interface Task<R>
Returns:
An appropriate error code identifying the error.
See Also:
doneWithErrors

setErrorCode

public void setErrorCode(int code)
Sets an error code identifying the failure of the task.

Parameters:
code - Specifies the error code identifying the failure of the task.

getErrorMessage

public java.lang.String getErrorMessage()
Gets an appropriate error message when the task fails.

Specified by:
getErrorMessage in interface Task<R>
Returns:
An appropriate error message describing the failure of the task.
See Also:
doneWithErrors

setErrorMessage

public void setErrorMessage(java.lang.String msg)
Set the error message of this task.

Parameters:
msg - Specifies the error message describing the failure of the task.

getTitle

public java.lang.String getTitle()
Gets the title of this task.

Specified by:
getTitle in interface Task<R>
Returns:
The title of this task.

setTitle

public void setTitle(java.lang.String title)
Sets the title of this task.

Specified by:
setTitle in interface Task<R>
Parameters:
title - Specifies the title text of this task.

getDescription

public java.lang.String getDescription()
Gets a short description about this task.

Specified by:
getDescription in interface Task<R>
Returns:
An arbitrary text describing this task.

setDescription

public void setDescription(java.lang.String desc)
Sets the description of this task.

Parameters:
desc - An arbitrary text describing the task.

invoke

public void invoke()
Starts the execution of this task. This method returns immediately after the the task is started. If you want to wait until the end of execution consider using invokeAndWait(). Notice that every task can be started only once.

Specified by:
invoke in interface Task<R>
Throws:
java.lang.IllegalStateException - if the task has been started already.
See Also:
invokeAndWait()

invokeAndWait

public void invokeAndWait()
Starts the execution of this task. This method blocks until the task finishes its execution. Consider using invoke() if you don't want this method to wait until the end of the task execution. Notice that every task can be started only once.

Specified by:
invokeAndWait in interface Task<R>
Throws:
java.lang.IllegalStateException - if the task has been started already.
See Also:
invoke()

isStarted

public boolean isStarted()
Determines whether the task has been started.

Specified by:
isStarted in interface Task<R>
Returns:
true if the task is already started and false if the task is not started yet.

getResult

public R getResult()
Gets the result of the task execution.

Specified by:
getResult in interface Task<R>
Returns:
R instance providing the result of the task execution.

setResult

public void setResult(R result)
Sets the result of the task execution.

Parameters:
result - R instance providing the result of the task execution.

addTaskListener

public void addTaskListener(TaskListener l)
Registers the specified TaskListener to be notified when task is done.

Specified by:
addTaskListener in interface Task<R>
Parameters:
l - The TaskListener to register.

removeTaskListener

public void removeTaskListener(TaskListener l)
Removes the specified listener.

Specified by:
removeTaskListener in interface Task<R>
Parameters:
l - The TaskListener to remove.

juife
v0.1a

Copyright © 2005 Grigor Iliev. All rights reserved. SourceForge.net Logo