Class AbstractWork
- java.lang.Object
- 
- org.nuxeo.ecm.core.work.AbstractWork
 
- 
- All Implemented Interfaces:
- Serializable,- Work
 - Direct Known Subclasses:
- AsyncEventExecutor.ListenerWork,- BaseIndexingWorker,- BatchFinderWork,- BatchProcessorWork,- BinaryMetadataUpdateWork,- BinaryMetadataWork,- BlobProviderDocumentsUpdateWork,- ComputeDigestWork,- DocumentRoutingEscalationServiceImpl.EscalationRuleWork,- DuplicateCollectionMemberWork,- ESAuditMigrationWork,- FulltextExtractorWork,- ImagingRecomputeWork,- PictureViewsGenerationWork,- PreviewWork,- QuotaMaxSizeSetterWork,- QuotaStatsInitialWork,- RemovedAbstractWork,- RemoveFromCollectionWork,- RenditionWork,- SleepWork,- ThreeDBatchUpdateWork,- ThumbnailRecomputeWork,- TransiantStorageGCWork,- TransientStoreWork,- UpdateACEStatusWork,- UserProfileImporterWork,- VideoConversionWork,- VideoInfoWork,- VideoStoryboardWork
 
 public abstract class AbstractWork extends Object implements Work A base implementation for aWorkinstance, dealing with most of the details around state change.It also deals with transaction management, and prevents running work instances that are suspending. Actual implementations must at a minimum implement the work()method. A methodcleanUp(boolean, java.lang.Exception)is available.To deal with suspension, work()should periodically check forisSuspending()and if true save its state and callsuspended().Specific information about the work can be returned by getDocument()orgetDocuments().- Since:
- 5.6
- See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.work.api.WorkWork.Progress, Work.State
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected StringcallerThreadprotected longcompletionTimeprotected StringdocIdDoc id for the Work instance, if relevant.protected List<String>docIdsDoc ids for the Work instance, if relevant.static StringFAILURE_EXCEPTIONstatic StringFAILURE_MSGstatic StringGLOBAL_DLQ_COUNT_REGISTRY_NAMEprotected Stringidprotected booleanisTreeIftrue, the docId is only the root of a set of documents on which this Work instance will act.protected NuxeoLoginContextloginContextprotected StringoriginatingUsernameThe originating username to use when opening theCoreSession.protected Work.Progressprogressprotected static RandomRANDOMprotected StringrepositoryNameRepository name for the Work instance, if relevant.protected WorkSchedulePathschedulePathprotected longschedulingTimeprotected CoreSessionsessionprotected longstartTimeprotected Work.Statestateprotected Stringstatusprotected booleansuspendedSuspend acknowledged by the work instance.protected booleansuspendingSuspend requested by the work manager.protected byte[]traceContextstatic StringWORK_FAILED_EVENTstatic StringWORK_INSTANCE
 - 
Constructor SummaryConstructors Constructor Description AbstractWork()Constructs aWorkinstance with a unique id.AbstractWork(String id)
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidappendWorkToDeadLetterQueue()Map<String,Serializable>buildWorkFailureEventProps(RuntimeException exception)Builds failure event properties.voidcleanUp(boolean ok, Exception e)This method is called afterwork()is done in a finally block, whether work completed normally or was in error or was interrupted.voidcloseSession()Closes the session that was opened byopenSystemSession()oropenUserSession().voidcommitOrRollbackTransaction()Releases the transaction resources by committing the existing transaction (if any).booleanequals(Object other)StringgetCategory()Gets the category for this work.longgetCompletionTime()Gets the time at which this work instance was completed, suspended or failed.DocumentLocationgetDocument()Gets the document impacted by the work.List<DocumentLocation>getDocuments()Gets the documents impacted by the work.StringgetId()The work id.StringgetOriginatingUsername()Gets the user on behalf of which this work is done.StringgetPartitionKey()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.Work.ProgressgetProgress()Gets a progress report for this work instance.intgetRetryCount()Gets the number of times that this Work instance can be retried in case of concurrent update exceptions.WorkSchedulePathgetSchedulePath()Returns the schedule pathlonggetSchedulingTime()Gets the time at which this work instance was first scheduled.protected io.opencensus.trace.SpangetSpanFromContext(byte[] traceContext)longgetStartTime()Gets the time at which this work instance was first started.StringgetStatus()Gets a human-readable status for this work instance.Work.StategetWorkInstanceState()CALLED BY THE WORK MANAGER (not user code) to get this work instance's state.inthashCode()CoreSessioninitSession()Deprecated.since 8.1.CoreSessioninitSession(String repositoryName)Deprecated.since 8.1.booleanisDocumentTree()ReturnstrueifWork.getDocument()is only the root of a set of documents on which this Work instance will act.booleanisSuspending()Checks if a suspend has been requested for this work instance by the work manager.booleanisWorkInstanceSuspended()CALLED BY THE WORK MANAGER (not user code) to check if this work instance really suspended.protected DocumentLocationnewDocumentLocation(String docId)voidopenSystemSession()May be called by implementing classes to open a System session on the repository.voidopenUserSession()May be called by implementing classes to open a Use session on the repository.voidrun()Runs the work instance and does all the transaction management and retry.protected voidrunWorkWithTransaction()Does work under a transaction.protected voidsetCompletionTime()voidsetDocument(String repositoryName, String docId)voidsetDocument(String repositoryName, String docId, boolean isTree)voidsetDocuments(String repositoryName, List<String> docIds)voidsetOriginatingUsername(String originatingUsername)voidsetProgress(Work.Progress progress)This method should be called periodically by the actual work method when it knows of its progress.voidsetSchedulePath(WorkSchedulePath path)Set the schedule path, internal usagevoidsetStartTime()CALLED BY THE WORK MANAGER (not user code) to set the start time on the work instance.voidsetStatus(String status)Sets a human-readable status for this work instance.voidsetWorkInstanceState(Work.State state)CALLED BY THE WORK MANAGER (not user code) to set this work instance's state.voidsetWorkInstanceSuspending()CALLED BY THE WORK MANAGER (not user code) when it requests that this work instance be suspended.booleanstartTransaction()Starts a new transaction.voidsuspended()Must be called byWorkimplementations to advertise that state saving is done, whenWork.isSuspending()returnedtrue.StringtoString()abstract voidwork()This method should implement the actual work done by theWorkinstance.voidworkFailed(RuntimeException exception)Called when the worker failed to run successfully even after retrying.- 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.nuxeo.ecm.core.work.api.WorkgetTitle, isCoalescing, isGroupJoin, isIdempotent, onGroupJoinCompletion
 
- 
 
- 
- 
- 
Field Detail- 
RANDOMprotected static final Random RANDOM 
 - 
WORK_FAILED_EVENTpublic static final String WORK_FAILED_EVENT - See Also:
- Constant Field Values
 
 - 
WORK_INSTANCEpublic static final String WORK_INSTANCE - See Also:
- Constant Field Values
 
 - 
FAILURE_MSGpublic static final String FAILURE_MSG - See Also:
- Constant Field Values
 
 - 
FAILURE_EXCEPTIONpublic static final String FAILURE_EXCEPTION - See Also:
- Constant Field Values
 
 - 
idprotected String id 
 - 
suspendingprotected transient volatile boolean suspending Suspend requested by the work manager.
 - 
suspendedprotected transient volatile boolean suspended Suspend acknowledged by the work instance.
 - 
stateprotected Work.State state 
 - 
progressprotected Work.Progress progress 
 - 
repositoryNameprotected String repositoryName Repository name for the Work instance, if relevant.
 - 
docIdprotected String docId Doc id for the Work instance, if relevant. This describes for the WorkManager a document on which this Work instance will act.Either docId or docIds is set. Not both. 
 - 
docIdsprotected List<String> docIds Doc ids for the Work instance, if relevant. This describes for the WorkManager the documents on which this Work instance will act.Either docId or docIds is set. Not both. 
 - 
isTreeprotected boolean isTree Iftrue, the docId is only the root of a set of documents on which this Work instance will act.
 - 
originatingUsernameprotected String originatingUsername The originating username to use when opening theCoreSession.- Since:
- 8.1
 
 - 
statusprotected String status 
 - 
schedulingTimeprotected long schedulingTime 
 - 
startTimeprotected long startTime 
 - 
completionTimeprotected long completionTime 
 - 
sessionprotected transient CoreSession session 
 - 
loginContextprotected transient NuxeoLoginContext loginContext 
 - 
schedulePathprotected WorkSchedulePath schedulePath 
 - 
callerThreadprotected String callerThread 
 - 
GLOBAL_DLQ_COUNT_REGISTRY_NAMEpublic static final String GLOBAL_DLQ_COUNT_REGISTRY_NAME 
 - 
traceContextprotected byte[] traceContext 
 
- 
 - 
Method Detail- 
getIdpublic String getId() Description copied from interface:WorkThe work id.The id is used for equality comparisons, and as a key in persistent queues. 
 - 
getSchedulePathpublic WorkSchedulePath getSchedulePath() Description copied from interface:WorkReturns the schedule path- Specified by:
- getSchedulePathin interface- Work
 
 - 
setSchedulePathpublic void setSchedulePath(WorkSchedulePath path) Description copied from interface:WorkSet the schedule path, internal usage- Specified by:
- setSchedulePathin interface- Work
 
 - 
setOriginatingUsernamepublic void setOriginatingUsername(String originatingUsername) - Since:
- 8.1
 
 - 
setWorkInstanceSuspendingpublic void setWorkInstanceSuspending() Description copied from interface:WorkCALLED BY THE WORK MANAGER (not user code) when it requests that this work instance be suspended.- Specified by:
- setWorkInstanceSuspendingin interface- Work
 
 - 
isSuspendingpublic boolean isSuspending() Description copied from interface:WorkChecks if a suspend has been requested for this work instance by the work manager.If true, then state should be saved,Work.suspended()should be called, and theWork.work()method should return.- Specified by:
- isSuspendingin interface- Work
 
 - 
suspendedpublic void suspended() Description copied from interface:WorkMust be called byWorkimplementations to advertise that state saving is done, whenWork.isSuspending()returnedtrue. After this is called, theWork.work()method should return.
 - 
isWorkInstanceSuspendedpublic boolean isWorkInstanceSuspended() Description copied from interface:WorkCALLED BY THE WORK MANAGER (not user code) to check if this work instance really suspended.- Specified by:
- isWorkInstanceSuspendedin interface- Work
 
 - 
setWorkInstanceStatepublic void setWorkInstanceState(Work.State state) Description copied from interface:WorkCALLED BY THE WORK MANAGER (not user code) to set this work instance's state.- Specified by:
- setWorkInstanceStatein interface- Work
 
 - 
getWorkInstanceStatepublic Work.State getWorkInstanceState() Description copied from interface:WorkCALLED BY THE WORK MANAGER (not user code) to get this work instance's state.Used only to get the final state of a completed instance. - Specified by:
- getWorkInstanceStatein interface- Work
 
 - 
setProgresspublic void setProgress(Work.Progress progress) Description copied from interface:WorkThis method should be called periodically by the actual work method when it knows of its progress.- Specified by:
- setProgressin interface- Work
- Parameters:
- progress- the progress
- See Also:
- Progress(float),- Progress(long, long)
 
 - 
getProgresspublic Work.Progress getProgress() Description copied from interface:WorkGets a progress report for this work instance.- Specified by:
- getProgressin interface- Work
- Returns:
- a progress report, not null
 
 - 
setStatuspublic void setStatus(String status) Sets a human-readable status for this work instance.- Parameters:
- status- the status
 
 - 
getStatuspublic String getStatus() Description copied from interface:WorkGets a human-readable status for this work instance.
 - 
initSession@Deprecated public CoreSession initSession() Deprecated.since 8.1. UseopenSystemSession().May be called by implementing classes to open a session on the repository.- Returns:
- the session (also available in sessionfield)
 
 - 
openSystemSessionpublic void openSystemSession() May be called by implementing classes to open a System session on the repository.- Since:
- 8.1
 
 - 
openUserSessionpublic void openUserSession() May be called by implementing classes to open a Use session on the repository.It uses the set originatingUsernameto open the session.- Since:
- 8.1
 
 - 
initSession@Deprecated public CoreSession initSession(String repositoryName) Deprecated.since 8.1. UseopenSystemSession()to open a session on the configured repository name, otherwise useCoreInstance.getCoreSessionSystem(String).May be called by implementing classes to open a session on the given repository.- Parameters:
- repositoryName- the repository name
- Returns:
- the session (also available in sessionfield)
 
 - 
closeSessionpublic void closeSession() Closes the session that was opened byopenSystemSession()oropenUserSession().- Since:
- 5.8
 
 - 
runpublic void run() Description copied from interface:WorkRuns the work instance and does all the transaction management and retry.
 - 
getSpanFromContextprotected io.opencensus.trace.Span getSpanFromContext(byte[] traceContext) 
 - 
buildWorkFailureEventPropspublic Map<String,Serializable> buildWorkFailureEventProps(RuntimeException exception) Builds failure event properties. Work implementations can override this method to inject more event properties than the default.- Since:
- 10.1
 
 - 
workFailedpublic void workFailed(RuntimeException exception) Called when the worker failed to run successfully even after retrying.- Parameters:
- exception- the exception that occurred
- Since:
- 10.1
 
 - 
appendWorkToDeadLetterQueueprotected void appendWorkToDeadLetterQueue() 
 - 
runWorkWithTransactionprotected void runWorkWithTransaction() Does work under a transaction.- Since:
- 5.9.4
 
 - 
workpublic abstract void work() Description copied from interface:WorkThis method should implement the actual work done by theWorkinstance.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 iftruecallWork.suspended()return early with saved state data.Clean up can by implemented by Work.cleanUp(boolean, Exception).- Specified by:
- workin interface- Work
- See Also:
- Work.isSuspending(),- Work.suspended(),- Work.cleanUp(boolean, java.lang.Exception)
 
 - 
getRetryCountpublic int getRetryCount() Gets the number of times that this Work instance can be retried in case of concurrent update exceptions.- Returns:
- 0 for no retry, or more if some retries are possible
- Since:
- 5.8
- See Also:
- work()
 
 - 
cleanUppublic void cleanUp(boolean ok, Exception e)This method is called afterwork()is done in a finally block, whether work completed normally or was in error or was interrupted.
 - 
getOriginatingUsernamepublic String getOriginatingUsername() Description copied from interface:WorkGets the user on behalf of which this work is done.- Specified by:
- getOriginatingUsernamein interface- Work
- Returns:
- the originating username, or null
 
 - 
getSchedulingTimepublic long getSchedulingTime() Description copied from interface:WorkGets the time at which this work instance was first scheduled.- Specified by:
- getSchedulingTimein interface- Work
- Returns:
- the scheduling time (milliseconds since epoch)
 
 - 
getStartTimepublic long getStartTime() Description copied from interface:WorkGets the time at which this work instance was first started.- Specified by:
- getStartTimein interface- Work
- Returns:
- the start time (milliseconds since epoch), or 0if not stated
 
 - 
getCompletionTimepublic long getCompletionTime() Description copied from interface:WorkGets the time at which this work instance was completed, suspended or failed.- Specified by:
- getCompletionTimein interface- Work
- Returns:
- the completion time (milliseconds since epoch), or 0if not completed
 
 - 
setStartTimepublic void setStartTime() Description copied from interface:WorkCALLED BY THE WORK MANAGER (not user code) to set the start time on the work instance.- Specified by:
- setStartTimein interface- Work
 
 - 
setCompletionTimeprotected void setCompletionTime() 
 - 
getCategorypublic String getCategory() Description copied from interface:WorkGets the category for this work.Used to choose an execution queue. - Specified by:
- getCategoryin interface- Work
- Returns:
- the category, or nullfor the default
 
 - 
getDocumentpublic DocumentLocation getDocument() Description copied from interface:WorkGets the document impacted by the work.Returns nullif the work isn't about a single document.- Specified by:
- getDocumentin interface- Work
- Returns:
- the document, or null. This is always aDocumentLocationwith anIdRef
 
 - 
getDocumentspublic List<DocumentLocation> getDocuments() Description copied from interface:WorkGets the documents impacted by the work.Returns nullif the work isn't about documents.- Specified by:
- getDocumentsin interface- Work
- Returns:
- the documents, or an empty list. List elements are always a DocumentLocationwith anIdRef
 
 - 
newDocumentLocationprotected DocumentLocation newDocumentLocation(String docId) 
 - 
isDocumentTreepublic boolean isDocumentTree() Description copied from interface:WorkReturnstrueifWork.getDocument()is only the root of a set of documents on which this Work instance will act.- Specified by:
- isDocumentTreein interface- Work
- Returns:
- trueif a whole tree is impacted
 
 - 
commitOrRollbackTransactionpublic void commitOrRollbackTransaction() Releases the transaction resources by committing the existing transaction (if any). This is recommended before running a long process.
 - 
startTransactionpublic boolean startTransaction() Starts a new transaction.Usually called after commitOrRollbackTransaction(), for instance for saving back the results of a long process.- Returns:
- true if a new transaction was started
 
 - 
getPartitionKeypublic String getPartitionKey() Description copied from interface:WorkReturns 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:
- getPartitionKeyin interface- Work
 
 
- 
 
-