Class BackgroundProcess
- java.lang.Object
-
- com.jalios.jcms.backgroundprocess.BackgroundProcess
-
- All Implemented Interfaces:
JcmsConstants,JaliosConstants
- Direct Known Subclasses:
AbstractCaddyProcess,AdminSearchEngineProcess,ApplicationDeployProcess,ApplicationResetProcess,CheckIntegrityProcess,LoggingInitPackagesProcess,MemberImportProcess,PublicationClassificationLevelUpdaterProcess,SilentProcess,SilentProgressingProcess,StoreAnonymizerProcess,TrashBulkProcess,UpdatePropertiesProcess,UpdateSiteLanguageProcess
public abstract class BackgroundProcess extends java.lang.Object implements JcmsConstants
Domain Nomenclature: depending on whether the processes are performed by- plugin, use a prefix following the same nomenclature as the plugin properties: examples:
- plugin.collaborativespace.create-space
- plugin.newsletter.send-newsletter
- plugin.jnlp.summarize
- the JPlatform core, no prefix.
- core.properties
- Since:
- jcms-10.0.8 / JCMS-9179
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBackgroundProcess.ScopeDefines the visibility of a process.static classBackgroundProcess.Status
-
Field Summary
Fields Modifier and Type Field Description static intCOMPLETED_PROGRESSstatic java.lang.StringDEFAULT_LABEL_PROPprotected static BackgroundProcessManagerMGR-
Fields inherited from interface com.jalios.util.JaliosConstants
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR
-
Fields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, ADMIN_NOTES_PROP, ADVANCED_TAB, AJAX_MODE_ATTR, ARCHIVES_DIR, ASCII_WIDTH, CATEGORY_TAB, CDATE_SEARCH, CLASS_PROPERTY, COMMON_ALARM, CONTENT_TAB, COOKIE_MAX_AGE, COUNTRY_SPRITE, CS_TYPOLOGY_ROOT_CAT_VID, CTRL_TOPIC_INTERNAL, CTRL_TOPIC_REF, CTRL_TOPIC_VALUE, CTRL_TOPIC_WRITE, CUSTOM_PROP, DATA_DIRECTORY, DEFAULT_PHOTO_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, GLYPH_ICON_PREFIX, ICON_ARCHIVE, ICON_ICON_PREFIX, ICON_LOCK, ICON_LOCK_STRONG, ICON_PREFIX_PROP, ICON_WARN, ICON_WH_BOOK_CLOSED, ICON_WH_BOOK_OPEN, INFORMATION_MSG, IS_IN_FRONT_OFFICE, JALIOS_JUNIT_PROP, JCMS_CADDY, JCMS_MSG_LIST, JCMS_TOASTR_COLLECTION, JSYNC_DOWNLOAD_DIR, JSYNC_SYNC_ALARM, LANG_SPRITE, LOG_FILE, LOG_TOPIC_SECURITY, LOGGER_PROP, LOGGER_XMLPROP, MBR_PHOTO_DIR, MDATE_SEARCH, MONITOR_XML, OP_CREATE, OP_CREATE_STR, OP_DEEP_COPY, OP_DEEP_COPY_STR, OP_DEEP_DELETE, OP_DEEP_DELETE_STR, OP_DELETE, OP_DELETE_STR, OP_MERGE, OP_MERGE_STR, OP_UPDATE, OP_UPDATE_STR, ORGANIZATION_ROOT_GROUP_PROP, PDATE_SEARCH, PHOTO_DIR, PHOTO_ICON, PHOTO_ICON_HEIGHT, PHOTO_ICON_PROP_PREFIX, PHOTO_ICON_WIDTH, PHOTO_LARGE, PHOTO_LARGE_HEIGHT, PHOTO_LARGE_PROP_PREFIX, PHOTO_LARGE_WIDTH, PHOTO_MINI, PHOTO_MINI_HEIGHT, PHOTO_MINI_PROP_PREFIX, PHOTO_MINI_WIDTH, PHOTO_NORMAL, PHOTO_NORMAL_HEIGHT, PHOTO_NORMAL_PROP_PREFIX, PHOTO_NORMAL_WIDTH, PHOTO_SMALL, PHOTO_SMALL_HEIGHT, PHOTO_SMALL_PROP_PREFIX, PHOTO_SMALL_WIDTH, PHOTO_TINY, PHOTO_TINY_HEIGHT, PHOTO_TINY_PROP_PREFIX, PHOTO_TINY_WIDTH, PREVIOUS_TAB, PRINT_VIEW, PRIVATE_FILE_ACCESS, PUBLIC_FILE_ACCESS, RAW_CONTENT_ICON_PREFIX, READ_RIGHT_TAB, SDATE_SEARCH, SEARCHENGINE_ALARM, SECURITY_LOG_FILE, SESSION_AUTHORIZED_FILENAMES_SET, SPRITE_ICON_PREFIX, STATS_REPORT_DIR, STATUS_PROP, STORE_DIR, STORE_XML, SUCCESS_MSG, SVG_ICON_PREFIX, SVGINLINE_ICON_PREFIX, TEMPLATE_TAB, THUMBNAIL_LARGE_HEIGHT, THUMBNAIL_LARGE_WIDTH, THUMBNAIL_SMALL_HEIGHT, THUMBNAIL_SMALL_WIDTH, TTCARD_MEDIA_HEIGHT, TTCARD_MEDIA_WIDTH, TYPES_ICON_ALT_PROP, TYPES_ICON_SUFFIX_PROP, TYPES_ICON_TITLE_PROP, TYPES_PREFIX_PROP, TYPES_THUMB_SUFFIX_PROP, UDATE_SEARCH, UPDATE_RIGHT_TAB, UPLOAD_DIR, UPLOAD_PERMISSION_COUNT_PROP_PREFIX, UPLOAD_PERMISSION_SIZE_PROP_PREFIX, URL_REGEXP, VID_LOGGED_MEMBER, WARNING_MSG, WEBAPP_PROP, WFEXPRESS_ALARM, WFREMINDER_ALARM, WORKFLOW_TAB, WORKFLOW_XML
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBackgroundProcess(java.lang.String domain)Default scope onBackgroundProcess.Scope.USERprotectedBackgroundProcess(java.lang.String domain, BackgroundProcess.Scope scope)Default unique is false.protectedBackgroundProcess(java.lang.String domain, BackgroundProcess.Scope scope, boolean unique)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanallowNulLAuthor()Override to allow a process to be run with no author.booleancanBeNotified(Member member)ControllerStatuscanStart(Member author)protected static Channelchannel()protected static voiddebugSleep(java.lang.String sleepProperty)MembergetAuthor()Retrieve the member who started this BackgroundProcessjava.lang.StringgetCompletedMessage()Retrieve the Message that was set at end of BackgroundProcessjava.lang.StringgetCompletedMessage(java.lang.String lang)Retrieve the Message that was set at end of BackgroundProcessjava.lang.StringgetCompletedMessage(java.lang.String lang, boolean useDefault)Retrieve a Message indicating BackgroundProcess completionBackgroundProcess.StatusgetCompletedStatus()Retrieve the completion status of this BackgroundProcessintgetCurrentStep()Retrieve the current step of this processing (from 0 to totalStep).java.lang.StringgetDetailsMessage()java.lang.StringgetDomain()BackgroundProcessInfogetInfo()Retrieve the BackgroundProcessInfo tracking this BackgroundProcess progression in database.java.lang.StringgetInfoId()Retrieve the id of the BackgroundProcessInfo used to track this BackgroundProcess progression in database.java.lang.StringgetLabel(java.lang.String lang)Retrieve an I18Ned label of this BackgroundProcess, in the specified language.java.lang.StringgetLabelProp()Retrieve the I18N property key to use to provide the I18Ned label of this BackgroundProcess to the user.intgetProgress()Retrieve the current progress percentage of this BackgroundProcessjava.lang.StringgetRunningMessage()protected longgetStartTime()intgetTotalStep()Retrieve total number of step that this BackgroundProcess will do before reaching completion.java.lang.StringgetUserLang()Retrieve the lang to use for localizationjava.lang.StringgetUserLocale()Retrieve the lang to use for localizationprotected java.lang.Stringglp(java.lang.String prop, java.lang.Object... params)protected voidhandleComplete()Called after completed.booleanhasProgression()Check if this BackgroundProcess has a known total number of steps, allowing precise progression to be provided to end user.voidincrementStep()Increment the step number of this processing by one.booleanisAuthor(Member member)Check if given member is the process authorbooleanisCompleted()booleanisCompletedFailed()Returns true if completedStatus isBackgroundProcess.Status.FAILED.booleanisCompletedSuccess()Returns true if completedStatus isBackgroundProcess.Status.OK.booleanisCompletedWarn()Returns true if completedStatus isBackgroundProcess.Status.WARN.protected abstract voidrunProcess()Override to implement the process.protected voidsave(boolean forceSave)SaveBackgroundProcessInfoof current processprotected voidsetCompletedMessage(java.lang.String completedMessage)Set the message property to display to indicate the process has completedprotected voidsetCompletedStatus(BackgroundProcess.Status status)Set the completion status of this BackgroundProcess.voidsetCurrentStep(int stepNbr)Set the current step number of this processing.protected voidsetDetailsMessage(java.lang.String detailsMessage)Sets the message that will detail the process at the end.voidsetLabelProp(java.lang.String prop)Set the I18N property key to use to provide the I18Ned label of this BackgroundProcess to the user.voidsetProgress(int progress)Set process progression.protected voidsetRunningMessage(java.lang.String runningMessage)Sets the message that will detail the process at the current step.protected voidsetStartTime(long startTime)voidsetTotalStep(int totalStepNbr)Set the total number of step that this BackgroundProcess will do before reaching completion.java.util.concurrent.CompletableFuture<java.lang.Void>start(Member author)Start this BackgroundProcess in a new thread.java.lang.StringtoString()
-
-
-
Field Detail
-
MGR
protected static final BackgroundProcessManager MGR
-
DEFAULT_LABEL_PROP
public static final java.lang.String DEFAULT_LABEL_PROP
- See Also:
- Constant Field Values
-
COMPLETED_PROGRESS
public static final int COMPLETED_PROGRESS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BackgroundProcess
protected BackgroundProcess(java.lang.String domain)
Default scope onBackgroundProcess.Scope.USER- Parameters:
domain- domain to set- Since:
- jcms-10.0.8
- See Also:
BackgroundProcess(String, Scope)
-
BackgroundProcess
protected BackgroundProcess(java.lang.String domain, BackgroundProcess.Scope scope)Default unique is false.- Parameters:
domain- domain to setscope- scope filter to set- Since:
- jcms-10.0.8
- See Also:
BackgroundProcess(String, Scope, boolean)
-
BackgroundProcess
protected BackgroundProcess(java.lang.String domain, BackgroundProcess.Scope scope, boolean unique)- Parameters:
domain- domain to setscope- scope filter to setunique- true if no new other process can be started while one running- Since:
- jcms-10.0.8
-
-
Method Detail
-
start
public final java.util.concurrent.CompletableFuture<java.lang.Void> start(Member author)
Start this BackgroundProcess in a new thread.- Parameters:
author- author of the process- Returns:
- a CompletableFuture (never return null)
- Since:
- jcms-10.0.8
-
canStart
public ControllerStatus canStart(Member author)
- Parameters:
author- author of the process- Returns:
- a ControllerStatus
- Since:
- jcms-10.0.8
- See Also:
BackgroundProcessManager.canStart(Member, BackgroundProcess, Scope, boolean)
-
save
protected final void save(boolean forceSave)
SaveBackgroundProcessInfoof current process- Parameters:
forceSave- to skip the check of delay between commits- Since:
- jcms-10.0.8
-
handleComplete
protected void handleComplete()
Called after completed.Check completedStatus to do custom job.
Does nothing by default.
- Since:
- jcms-10.0.8
-
canBeNotified
public boolean canBeNotified(Member member)
- Parameters:
member- member to be notified- Returns:
- true if member asked for notification
- Since:
- jcms-10.0.8
-
runProcess
protected abstract void runProcess() throws BackgroundProcessExceptionOverride to implement the process.- Throws:
BackgroundProcessException- if an error occurs- Since:
- jcms-10.0.8
-
setCompletedStatus
protected final void setCompletedStatus(BackgroundProcess.Status status)
Set the completion status of this BackgroundProcess. You should invoke this method at the end of your process.- Parameters:
status- status to set- Since:
- jcms-10.0.8
-
getCompletedStatus
public final BackgroundProcess.Status getCompletedStatus()
Retrieve the completion status of this BackgroundProcess- Returns:
- the BackgroundProcess status, may return null when BackgroundProcess not yet completed
- Since:
- jcms-10.0.8
-
isCompleted
public final boolean isCompleted()
- Returns:
- true if process is completed
- Since:
- jcms-10.0.8
-
isCompletedSuccess
public final boolean isCompletedSuccess()
Returns true if completedStatus isBackgroundProcess.Status.OK.Only test
getCompletedStatus(), does not check if completed step was reached.- Returns:
- true if completedStatus was set to
BackgroundProcess.Status.OK - Since:
- jcms-10.0.8
-
isCompletedWarn
public final boolean isCompletedWarn()
Returns true if completedStatus isBackgroundProcess.Status.WARN.Only test
getCompletedStatus(), does not check if completed step was reached.- Returns:
- true if completedStatus was set to
BackgroundProcess.Status.WARN - Since:
- jcms-10.0.8
-
isCompletedFailed
public final boolean isCompletedFailed()
Returns true if completedStatus isBackgroundProcess.Status.FAILED.Only test
getCompletedStatus(), does not check if completed step was reached.- Returns:
- true if completedStatus was set to
BackgroundProcess.Status.FAILED - Since:
- jcms-10.0.8
-
getCompletedMessage
public final java.lang.String getCompletedMessage()
Retrieve the Message that was set at end of BackgroundProcess- Returns:
- a message localized in default site language
- Since:
- jcms-10.0.8
-
getCompletedMessage
public final java.lang.String getCompletedMessage(java.lang.String lang)
Retrieve the Message that was set at end of BackgroundProcess- Parameters:
lang- an ISO-639 code used to localize the message- Returns:
- a message localized in default site language
- Since:
- jcms-10.0.8
-
getCompletedMessage
public final java.lang.String getCompletedMessage(java.lang.String lang, boolean useDefault)Retrieve a Message indicating BackgroundProcess completion- Parameters:
lang- an ISO-639 code used to localize the messageuseDefault- set to true to use a generic completion message if completed message was not set, if false and no message was set, return null- Returns:
- a message or null
- Since:
- jcms-10.0.8
-
setCompletedMessage
protected final void setCompletedMessage(java.lang.String completedMessage)
Set the message property to display to indicate the process has completed- Parameters:
completedMessage- an I18N property- Since:
- jcms-10.0.8
-
getAuthor
public Member getAuthor()
Retrieve the member who started this BackgroundProcess- Returns:
- a Member or null if none specified
- Since:
- jcms-10.0.8
-
isAuthor
public boolean isAuthor(Member member)
Check if given member is the process author- Parameters:
member- member to check- Returns:
- true if member is author of the process
- Since:
- jcms-10.0.8
-
allowNulLAuthor
public boolean allowNulLAuthor()
Override to allow a process to be run with no author.- Returns:
- if process can be run without author
- Since:
- jcms-10.0.8
-
getUserLang
public java.lang.String getUserLang()
Retrieve the lang to use for localization- Returns:
- current userLang if specified, else if process has an author, its language, else channel language
- Since:
- jcms-10.0.8
-
getUserLocale
public java.lang.String getUserLocale()
Retrieve the lang to use for localization- Returns:
- current userLang if specified, else if process has an author, its language, else channel language
- Since:
- jcms-10.0.8
-
getRunningMessage
public final java.lang.String getRunningMessage()
- Returns:
- the runningMessage or null
- Since:
- jcms-10.0.8
-
setRunningMessage
protected final void setRunningMessage(java.lang.String runningMessage)
Sets the message that will detail the process at the current step.- Parameters:
runningMessage- the runningMessage to set- Since:
- jcms-10.0.8
-
getDetailsMessage
public final java.lang.String getDetailsMessage()
- Returns:
- the detailsMessage or null
- Since:
- jcms-10.0.8
-
setDetailsMessage
protected final void setDetailsMessage(java.lang.String detailsMessage)
Sets the message that will detail the process at the end.- Parameters:
detailsMessage- the detailsMessage to set- Since:
- jcms-10.0.8
-
getTotalStep
public final int getTotalStep()
Retrieve total number of step that this BackgroundProcess will do before reaching completion.- Returns:
- a number of step, or 0 if total number of steps is unknown.
-
setTotalStep
public void setTotalStep(int totalStepNbr)
Set the total number of step that this BackgroundProcess will do before reaching completion.Implementation detail : If this call changes the progress percentage, it triggers an update in database of the BackgroundProcessInfo used to track the process progress
- Parameters:
totalStepNbr- a number of steps
-
getCurrentStep
public final int getCurrentStep()
Retrieve the current step of this processing (from 0 to totalStep).- Returns:
- the current step number
-
setCurrentStep
public void setCurrentStep(int stepNbr)
Set the current step number of this processing.Implementation detail : If this step changes the progress percentage, it triggers an update in database of the BackgroundProcessInfo used to track the process progress
- Parameters:
stepNbr- the step number to set- Since:
- jcms-10.0.8
-
getStartTime
protected long getStartTime()
- Returns:
- time when process has started
- Since:
- jcms-10.0.8
-
setStartTime
protected void setStartTime(long startTime)
- Parameters:
startTime- time when process has started- Since:
- jcms-10.0.8
-
incrementStep
public void incrementStep()
Increment the step number of this processing by one.Implementation detail : If this step changes the progress percentage, it triggers an update in database of the BackgroundProcessInfo used to track the process progress
- Since:
- jcms-10.0.8
-
hasProgression
public boolean hasProgression()
Check if this BackgroundProcess has a known total number of steps, allowing precise progression to be provided to end user.- Returns:
- true if this BackgroundProcess can have a progression status, false if this process is either started or done.
- Since:
- jcms-10.0.8
-
getProgress
public final int getProgress()
Retrieve the current progress percentage of this BackgroundProcess- Returns:
- a percentage (value is updated when current step or total step number are modified)
- Since:
- jcms-10.0.8
-
setProgress
public void setProgress(int progress)
Set process progression.Progress is limited to max = 100
- Parameters:
progress- the new progress percentage to set- Since:
- jcms-10.0.8
-
getLabelProp
public java.lang.String getLabelProp()
Retrieve the I18N property key to use to provide the I18Ned label of this BackgroundProcess to the user.- Returns:
- a property
- Since:
- jcms-10.0.8
-
setLabelProp
public void setLabelProp(java.lang.String prop)
Set the I18N property key to use to provide the I18Ned label of this BackgroundProcess to the user.- Parameters:
prop- a property key- Since:
- jcms-10.0.8
-
getLabel
public java.lang.String getLabel(java.lang.String lang)
Retrieve an I18Ned label of this BackgroundProcess, in the specified language.- Parameters:
lang- an ISO-639 code- Returns:
- a label suitable for prestation to the user
- Since:
- jcms-10.0.8
-
getInfoId
public final java.lang.String getInfoId()
Retrieve the id of the BackgroundProcessInfo used to track this BackgroundProcess progression in database.- Returns:
- a BackgroundProcessInfo id, or null if none was set
- Since:
- jcms-10.0.8
-
getInfo
public final BackgroundProcessInfo getInfo()
Retrieve the BackgroundProcessInfo tracking this BackgroundProcess progression in database.- Returns:
- a BackgroundProcessInfo, loaded from database using current hibernate session/transaction. May return null if none was set or info has already been deleted from database.
- Since:
- jcms-10.0.8
-
getDomain
public final java.lang.String getDomain()
- Returns:
- domain of the process
- Since:
- jcms-10.0.8
-
glp
protected java.lang.String glp(java.lang.String prop, java.lang.Object... params)
-
debugSleep
protected static void debugSleep(java.lang.String sleepProperty)
- Parameters:
sleepProperty- property of a long value to sleep in ms- Since:
- jcms-10.0.8
-
channel
protected static Channel channel()
- Returns:
- the channel
- Since:
- jcms-10.0.8
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Since:
- jcms-10.0.8
-
-