public interface Work extends Runnable
Work
instance gets executed by a WorkManager
.
It's a runnable that can be suspended and can report its status and progress.
Implementors must take care to implement correctly beforeRun()
and
afterRun(boolean)
to change the state.
AbstractWork
Modifier and Type | Interface and Description |
---|---|
static class |
Work.Progress
A progress report about a work instance.
|
static class |
Work.State
The running state of a
Work instance. |
Modifier and Type | Method and Description |
---|---|
void |
afterRun(boolean ok)
Called by the thread pool executor after the work is run.
|
boolean |
awaitTermination(long timeout,
TimeUnit unit)
Wait for the work to be completed or suspension finished.
|
void |
beforeRun()
Called by the thread pool executor before the work is run.
|
String |
getCategory()
Gets the category for this work.
|
long |
getCompletionTime()
Gets the time at which this work instance was completed, suspended or
failed.
|
Map<String,Serializable> |
getData()
Gets the state data for this suspended work instance.
|
Collection<DocumentLocation> |
getDocuments()
Gets the documents impacted by the work.
|
Principal |
getPrincipal()
Gets the principal on behalf of which this work is done.
|
Work.Progress |
getProgress()
Gets a progress report for this work instance.
|
long |
getSchedulingTime()
Gets the time at which this work instance was scheduled.
|
long |
getStartTime()
Gets the time at which this work instance was started.
|
Work.State |
getState()
Gets the running state for this work instance.
|
String |
getStatus()
Gets a human-readable status for this work instance.
|
String |
getTitle()
Gets a human-readable name for this work instance.
|
void |
run()
The actual work.
|
void |
setCanceled()
Sets the state of this queued work instance to
CANCELED . |
void |
setData(Map<String,Serializable> data)
Restores a saved state data for this work instance.
|
boolean |
suspend()
Requests that this work instance suspend its state in memory.
|
String getCategory()
Used to choose a thread pool queue.
null
for the defaultvoid beforeRun()
void afterRun(boolean ok)
ok
- false
if there was an exception during task run and the
state should be FAILEDWork.State getState()
String getTitle()
String getStatus()
long getSchedulingTime()
long getStartTime()
0
if not
statedlong getCompletionTime()
0
if
not completedWork.Progress getProgress()
null
boolean suspend()
Does not block. Use awaitTermination(long, java.util.concurrent.TimeUnit)
to wait for actual
suspension and then getData()
to get the data.
A QUEUED work instance must immediately suspend.
true
if suspend was started, or false
if the job
was already completedboolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
timeout
- how long to waitunit
- the timeout unittrue
if the work is completed or suspended, or
false
for a timeoutInterruptedException
void setCanceled()
CANCELED
. Called by the work manager implementation.Map<String,Serializable> getData()
null
if no data is availablevoid setData(Map<String,Serializable> data)
data
- the saved state dataPrincipal getPrincipal()
This is informative only.
null
Collection<DocumentLocation> getDocuments()
This is informative only.
Copyright © 2013 Nuxeo SA. All Rights Reserved.