Package org.nuxeo.ecm.core.work
Class SleepWork
- java.lang.Object
-
- org.nuxeo.ecm.core.work.AbstractWork
-
- org.nuxeo.ecm.core.work.SleepWork
-
- All Implemented Interfaces:
Serializable
,Work
public class SleepWork extends AbstractWork
Simple work that just sleeps, mostly used for tests.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.work.api.Work
Work.Progress, Work.State
-
-
Field Summary
Fields Modifier and Type Field Description protected String
category
static String
CATEGORY
protected boolean
coalescing
protected AtomicInteger
count
protected long
durationMillis
protected boolean
idempotent
protected String
partitionKey
-
Fields inherited from class org.nuxeo.ecm.core.work.AbstractWork
callerThread, completionTime, docId, docIds, FAILURE_EXCEPTION, FAILURE_MSG, GLOBAL_DLQ_COUNT_REGISTRY_NAME, id, isTree, loginContext, originatingUsername, progress, RANDOM, repositoryName, schedulePath, schedulingTime, session, startTime, state, status, suspended, suspending, traceContext, WORK_FAILED_EVENT, WORK_INSTANCE
-
-
Constructor Summary
Constructors Constructor Description SleepWork(long durationMillis)
SleepWork(long durationMillis, boolean debug)
Deprecated.since 10.2 debug flag is unusedSleepWork(long durationMillis, boolean debug, String id)
Deprecated.since 10.2 debug flag is unusedSleepWork(long durationMillis, String id)
SleepWork(long durationMillis, String category, boolean debug)
Deprecated.since 10.2 debug flag is unusedSleepWork(long durationMillis, String category, boolean debug, String id)
Deprecated.since 10.2 debug flag is unusedSleepWork(long durationMillis, String category, String id)
Creates a work instance that does nothing but sleep.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doWork()
String
getCategory()
Gets the category for this work.String
getPartitionKey()
Returns a key that can be used by the WorkManager implementation to guarantee that works with the same partition key will be executed in the order they are submitted.String
getTitle()
Gets a human-readable name for this work instance.boolean
isCoalescing()
When setting the coalescing flag to true you indicate to the work manager that if multiple works with the same id are scheduled you only care about the lastest execution.boolean
isIdempotent()
Returns true if a work with a givenWork.getId()
should always produce the same result.void
setCoalescing(boolean coalescing)
void
setIdempotent(boolean idempotent)
String
toString()
void
work()
This method should implement the actual work done by theWork
instance.-
Methods inherited from class org.nuxeo.ecm.core.work.AbstractWork
appendWorkToDeadLetterQueue, buildWorkFailureEventProps, cleanUp, closeSession, commitOrRollbackTransaction, equals, getCompletionTime, getDocument, getDocuments, getId, getOriginatingUsername, getProgress, getRetryCount, getSchedulePath, getSchedulingTime, getSpanFromContext, getStartTime, getStatus, getWorkInstanceState, hashCode, initSession, initSession, isDocumentTree, isSuspending, isWorkInstanceSuspended, newDocumentLocation, openSystemSession, openUserSession, run, runWorkWithTransaction, setCompletionTime, setDocument, setDocument, setDocuments, setOriginatingUsername, setProgress, setSchedulePath, setStartTime, setStatus, setWorkInstanceState, setWorkInstanceSuspending, startTransaction, suspended, workFailed
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.nuxeo.ecm.core.work.api.Work
isGroupJoin, onGroupJoinCompletion
-
-
-
-
Field Detail
-
CATEGORY
public static final String CATEGORY
- See Also:
- Constant Field Values
-
durationMillis
protected long durationMillis
-
category
protected String category
-
count
protected AtomicInteger count
-
partitionKey
protected String partitionKey
-
idempotent
protected boolean idempotent
-
coalescing
protected boolean coalescing
-
-
Constructor Detail
-
SleepWork
public SleepWork(long durationMillis, String category, String id)
Creates a work instance that does nothing but sleep.- Parameters:
durationMillis
- the sleep duration- Since:
- 10.2
-
SleepWork
public SleepWork(long durationMillis, String id)
- Since:
- 10.2
-
SleepWork
public SleepWork(long durationMillis)
- Since:
- 10.2
-
SleepWork
@Deprecated public SleepWork(long durationMillis, boolean debug)
Deprecated.since 10.2 debug flag is unusedIf debug is true, then the various debug* methods must be called in the proper order for the work to start and stop.- Parameters:
durationMillis
- the sleep durationdebug
-true
for debug
-
SleepWork
@Deprecated public SleepWork(long durationMillis, boolean debug, String id)
Deprecated.since 10.2 debug flag is unused
-
SleepWork
@Deprecated public SleepWork(long durationMillis, String category, boolean debug)
Deprecated.since 10.2 debug flag is unused
-
SleepWork
@Deprecated public SleepWork(long durationMillis, String category, boolean debug, String id)
Deprecated.since 10.2 debug flag is unused
-
-
Method Detail
-
getCategory
public String getCategory()
Description copied from interface:Work
Gets the category for this work.Used to choose an execution queue.
- Specified by:
getCategory
in interfaceWork
- Overrides:
getCategory
in classAbstractWork
- Returns:
- the category, or
null
for the default
-
getTitle
public String getTitle()
Description copied from interface:Work
Gets a human-readable name for this work instance.- Returns:
- a human-readable name
-
work
public void work()
Description copied from interface:Work
This method should implement the actual work done by theWork
instance.It should periodically update its progress through
Work.setProgress(org.nuxeo.ecm.core.work.api.Work.Progress)
.To allow for suspension by the
WorkManager
, it should periodically callWork.isSuspending()
, and iftrue
callWork.suspended()
return early with saved state data.Clean up can by implemented by
Work.cleanUp(boolean, Exception)
.- Specified by:
work
in interfaceWork
- Specified by:
work
in classAbstractWork
- See Also:
Work.isSuspending()
,Work.suspended()
,Work.cleanUp(boolean, java.lang.Exception)
-
doWork
protected void doWork() throws InterruptedException
- Throws:
InterruptedException
-
getPartitionKey
public String getPartitionKey()
Description copied from interface:Work
Returns a key that can be used by the WorkManager implementation to guarantee that works with the same partition key will be executed in the order they are submitted.- Specified by:
getPartitionKey
in interfaceWork
- Overrides:
getPartitionKey
in classAbstractWork
-
isIdempotent
public boolean isIdempotent()
Description copied from interface:Work
Returns true if a work with a givenWork.getId()
should always produce the same result. The WorkManager implementation can safely skip duplicate executions of idempotent work.
-
setIdempotent
public void setIdempotent(boolean idempotent)
-
isCoalescing
public boolean isCoalescing()
Description copied from interface:Work
When setting the coalescing flag to true you indicate to the work manager that if multiple works with the same id are scheduled you only care about the lastest execution. The goal is to skip useless executions to save resources, It is up to the work manager implementation to support or not this optimization.
-
setCoalescing
public void setCoalescing(boolean coalescing)
-
toString
public String toString()
- Overrides:
toString
in classAbstractWork
-
-