|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object nl.coderight.jazz.Task<V>
public abstract class Task<V>
Use Task
for (long running) background processes.
Example: public class LoadContactsTask extends Task>{ public List
process() throws Exception { return DatabaseService.getInstance().getContacts(); } protected void onStart() { ProgressEvent progressEvent = new ProgressEvent(ProgressEventType.START); progressEvent.setMessage("Loading contacts..."); progressEvent.setIndeterminate(true); postEvent(progressEvent); } protected void onFinish() { postEvent(new ProgressEvent(ProgressEventType.STOP)); ContactEvent contactEvent = new ContactEvent(ContactEventType.LOAD_SUCCESS); contactEvent.setContacts(getResult()); postEvent(contactEvent); } protected void onError() { MessageEvent error = new MessageEvent(MessageEventType.ERROR); error.setMessage(getError().getMessage()); postEvent(error); } }
Controller.executeTask(Task)
,
Controller.scheduleTask(Task, nl.coderight.jazz.Task.Schedule)
Nested Class Summary | |
---|---|
static class |
Task.FixedDelaySchedule
|
static class |
Task.FixedRateSchedule
|
static class |
Task.TaskState
Enumeration of the possible Task states. |
Constructor Summary | |
---|---|
Task()
|
Method Summary | |
---|---|
void |
cancel()
Cancels running task. |
ProgressMonitor |
createProgressMonitor(String message,
InputStream inputStream)
Creates a ProgressMonitor. |
ProgressMonitor |
createProgressMonitor(String message,
String note,
int min,
int max)
Creates a standard ProgressMonitor. |
Exception |
getError()
Returns the error (if set). |
V |
getResult()
Returns the result from process. |
Task.TaskState |
getState()
Returns current state. |
boolean |
hasError()
Returns true if an error is set. |
boolean |
isCanceled()
Returns true if task was canceled. |
protected void |
onCanceled()
Invoked when task is canceled. |
protected void |
onError()
Invoked when an error occurred. |
protected void |
onFinish()
Invoked when task is finished. |
protected void |
onStart()
Invoked when task starts running. |
void |
postEvent(Event event)
Use to post events like ProgressEvents and message events. |
abstract V |
process()
Performs a (long running) operation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Task()
Method Detail |
---|
public final Task.TaskState getState()
Task.TaskState
public final Exception getError()
public final boolean hasError()
public final V getResult()
public final void cancel()
public final boolean isCanceled()
public final void postEvent(Event event)
public final ProgressMonitor createProgressMonitor(String message, String note, int min, int max)
ProgressMonitor
public final ProgressMonitor createProgressMonitor(String message, InputStream inputStream)
ProgressMonitor
public abstract V process() throws Exception
Exception
protected void onStart()
protected void onFinish()
protected void onError()
protected void onCanceled()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |