Class BackgroundProcess
- All Implemented Interfaces:
JcmsConstants,JaliosConstants
- Direct Known Subclasses:
AbstractCaddyProcess,AdminSearchEngineProcess,ApplicationDeployProcess,ApplicationResetProcess,CheckIntegrityProcess,LoggingInitPackagesProcess,MemberImportProcess,PublicationClassificationLevelUpdaterProcess,SilentProcess,SilentProgressingProcess,StoreAnonymizerProcess,TrashBulkProcess,UpdatePropertiesProcess,UpdateSiteLanguageProcess
- 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 ClassesModifier and TypeClassDescriptionclassStores details about the original context at the time the process was started.static enumDefines the visibility of a process.static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final Stringprotected static final BackgroundProcessManagerFields 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_YEARFields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, 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, GENERATIONAL_STORE_DIRECTORY, 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, PHOTO_XLARGE, PHOTO_XLARGE_HEIGHT, PHOTO_XLARGE_PROP_PREFIX, PHOTO_XLARGE_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_XML, SUCCESS_MSG, SVG_ICON_PREFIX, SVGINLINE_ICON_PREFIX, SVGSPRITE_ICON_PREFIX, TEMPLATE_TAB, THEME_DIR, 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, TYPES_UNKNOWN_CLASS_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
ConstructorsModifierConstructorDescriptionprotectedBackgroundProcess(String domain) Default scope onBackgroundProcess.Scope.USERprotectedBackgroundProcess(String domain, BackgroundProcess.Scope scope) Default unique is false.protectedBackgroundProcess(String domain, BackgroundProcess.Scope scope, boolean unique) -
Method Summary
Modifier and TypeMethodDescriptionbooleanOverride to allow a process to be run with no author.booleancanBeNotified(Member member) Checks if this process can be started by returning a controller status.protected static Channelchannel()protected static voiddebugSleep(String sleepProperty) Retrieve the member who started this BackgroundProcessfinal StringRetrieve the Message that was set at end of BackgroundProcessfinal StringgetCompletedMessage(String lang) Retrieve the Message that was set at end of BackgroundProcessfinal StringgetCompletedMessage(String lang, boolean useDefault) Retrieve a Message indicating BackgroundProcess completionfinal BackgroundProcess.StatusRetrieve the completion status of this BackgroundProcessfinal intRetrieve the current step of this processing (from 0 to totalStep).final Stringfinal Stringfinal BackgroundProcessInfogetInfo()Retrieve the BackgroundProcessInfo tracking this BackgroundProcess progression in database.final StringRetrieve the id of the BackgroundProcessInfo used to track this BackgroundProcess progression in database.Retrieve an I18Ned label of this BackgroundProcess, in the specified language.Retrieve the I18N property key to use to provide the I18Ned label of this BackgroundProcess to the user.Retrieves information about the original context of execution when the process was started.final intRetrieve the current progress percentage of this BackgroundProcessfinal Stringprotected longfinal intRetrieve total number of step that this BackgroundProcess will do before reaching completion.Retrieve the lang to use for localizationprotected Stringprotected voidCalled after completed.booleanCheck if this BackgroundProcess has a known total number of steps, allowing precise progression to be provided to end user.voidIncrement the step number of this processing by one.booleanCheck if given member is the process authorfinal booleanfinal booleanReturns true if completedStatus isBackgroundProcess.Status.FAILED.final booleanReturns true if completedStatus isBackgroundProcess.Status.OK.final booleanReturns true if completedStatus isBackgroundProcess.Status.WARN.protected abstract voidOverride to implement the process.protected final voidsave(boolean forceSave) SaveBackgroundProcessInfoof current processfinal voidsetCompletedMessage(String completedMessage) Set the message property to display to indicate the process has completedprotected final voidSet the completion status of this BackgroundProcess.voidsetCurrentStep(int stepNbr) Set the current step number of this processing.final voidsetDetailsMessage(String detailsMessage) Sets the message that will detail the process at the end.voidsetLabelProp(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.final voidsetRunningMessage(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.final CompletableFuture<Void> Start this BackgroundProcess in a new thread.toString()
-
Field Details
-
MGR
-
DEFAULT_LABEL_PROP
- See Also:
-
COMPLETED_PROGRESS
public static final int COMPLETED_PROGRESS- See Also:
-
-
Constructor Details
-
BackgroundProcess
Default scope onBackgroundProcess.Scope.USER- Parameters:
domain- domain to set- Since:
- jcms-10.0.8
- See Also:
-
BackgroundProcess
Default unique is false.- Parameters:
domain- domain to setscope- scope filter to set- Since:
- jcms-10.0.8
- See Also:
-
BackgroundProcess
- 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 Details
-
start
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
Checks if this process can be started by returning a controller status.Prevents unique process to be run simultaneously, depending on author, domain and scope.
Prevents null-author process to be run, unless it is explicitely allowed usingallowNullAuthor();- Parameters:
author- author of the process- Returns:
- a ControllerStatus
- Since:
- jcms-10.0.8
- See Also:
-
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
- Parameters:
member- member to be notified- Returns:
- true if member asked for notification
- Since:
- jcms-10.0.8
-
runProcess
Override to implement the process.- Throws:
BackgroundProcessException- if an error occurs- Since:
- jcms-10.0.8
-
setCompletedStatus
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
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
Retrieve the Message that was set at end of BackgroundProcess- Returns:
- a message localized in default site language
- Since:
- jcms-10.0.8
-
getCompletedMessage
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
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
Set the message property to display to indicate the process has completed- Parameters:
completedMessage- an I18N property- Since:
- jcms-10.0.8
-
getAuthor
Retrieve the member who started this BackgroundProcess- Returns:
- a Member or null if none specified
- Since:
- jcms-10.0.8
-
isAuthor
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
-
getOriginalContext
Retrieves information about the original context of execution when the process was started.- Returns:
- an OriginalContext instance if the process was started via an HTTP request, or null otherwise.
- Since:
- jcms-10.0.9 / JCMS-11194
-
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
-
getRunningMessage
- Returns:
- the runningMessage or null
- Since:
- jcms-10.0.8
-
setRunningMessage
Sets the message that will detail the process at the current step.- Parameters:
runningMessage- the runningMessage to set- Since:
- jcms-10.0.8
-
getDetailsMessage
- Returns:
- the detailsMessage or null
- Since:
- jcms-10.0.8
-
setDetailsMessage
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
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
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
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
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
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
- Returns:
- domain of the process
- Since:
- jcms-10.0.8
-
glp
-
debugSleep
- Parameters:
sleepProperty- property of a long value to sleep in ms- Since:
- jcms-10.0.8
-
channel
- Returns:
- the channel
- Since:
- jcms-10.0.8
-
toString
-