|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--edu.jhu.pha.ivoa.Task
Current Version =============== ID: $Id: Task.html,v 1.3 2003/08/18 18:05:02 carliles Exp $ Revision: $Revision: 1.3 $ Date/time: $Date: 2003/08/18 18:05:02 $An abstract ecapsulation of the concept of a Task, which is similar to a
Thread, but which keeps finer-grained status information,
and which isn't cluttered with a ridiculous number of deprecated methods.
It also has bean-like aspects, namely the ability to notify
PropertyChangeListeners
when its status or message has changed. Its primary use is as a controller
for code execution that you want to a) break out into its own thread, and b)
add to TaskManager to keep the user updated on its status and to
give the user the option of cancelling it. You must provide an
implementation for the execute() method, and it's recommended that you not
override the run() method, although you are free to do so. A simple way to
use the class looks like
Task t = new Task("Reading files", "0 lines read.")
{
public void execute()
{
try
{
int linesRead = 0;
BufferedReader in =
new BufferedReader(new FileReader("/etc/passwd"));
for(String line = in.readLine(); line != null; line = in.readLine())
{
if(line != null)
{
System.out.println(line);
setMessage((++linesRead) + " lines read.");
}
}
System.out.flush();
}
catch(IOException e)
{
e.printStackTrace();
}
}
};
| Field Summary | |
static int |
CANCELLED
|
static int |
COMPLETED
|
static int |
ERROR
|
static java.lang.String |
MESSAGE_PROPERTY
The value returned by PropertyChangeEvent.getPropertyName()
when the value of the message field of this Task changes. |
static int |
RUNNING
|
static java.lang.String |
STATUS_PROPERTY
The value returned by PropertyChangeEvent.getPropertyName()
when the value of the status field of this Task changes. |
static java.lang.String[] |
STATUS_STRINGS
|
static int |
WAITING
|
| Constructor Summary | |
Task(java.lang.String name)
|
|
Task(java.lang.String name,
java.lang.String message)
|
|
Task(java.lang.String name,
java.lang.String message,
java.beans.PropertyChangeListener listener)
|
|
| Method Summary | |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
|
void |
cancel()
Cancels this Task, and sets its status to CANCELLED. |
abstract void |
execute()
This abstract method, which must be implemented by any subclasses, is where the work done by this Task should take place. |
java.lang.String |
getMessage()
|
java.lang.String |
getName()
|
int |
getStatus()
|
java.lang.String |
getStatusAsString()
|
boolean |
isInterrupted()
|
void |
join()
Causes the thread calling this method to block until this Task has completed. |
static void |
main(java.lang.String[] args)
For testing purposes. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
|
static java.lang.String |
revision()
|
void |
run()
Sets the status to RUNNING, then calls the execute() method of this Task. |
void |
start()
Starts this Task. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int WAITING
public static final int RUNNING
public static final int COMPLETED
public static final int CANCELLED
public static final int ERROR
public static final java.lang.String[] STATUS_STRINGS
public static final java.lang.String MESSAGE_PROPERTY
PropertyChangeEvent.getPropertyName()
when the value of the message field of this Task changes.
public static final java.lang.String STATUS_PROPERTY
PropertyChangeEvent.getPropertyName()
when the value of the status field of this Task changes.
| Constructor Detail |
public Task(java.lang.String name)
name - The name of this Task.
public Task(java.lang.String name,
java.lang.String message)
name - The name of this Task.message - The initial value of the message field for this Task.
public Task(java.lang.String name,
java.lang.String message,
java.beans.PropertyChangeListener listener)
name - The name of this Task.message - The initial value of the message field for this Task.listener - A PropertyChangeListener to be added
to the list of PropertyChangeListeners of this Task.| Method Detail |
public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.String getName()
public int getStatus()
public java.lang.String getStatusAsString()
public java.lang.String getMessage()
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
public void start()
public void cancel()
public void join()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic boolean isInterrupted()
public void run()
run in interface java.lang.Runnablepublic abstract void execute()
public static java.lang.String revision()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||