Class BackgroundProcess

    • Constructor Detail

      • BackgroundProcess

        protected BackgroundProcess​(java.lang.String domain,
                                    BackgroundProcess.Scope scope,
                                    boolean unique)
        Parameters:
        domain - domain to set
        scope - scope filter to set
        unique - 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
      • save

        protected final void save​(boolean forceSave)
        Save BackgroundProcessInfo of 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
      • 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
      • 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 message
        useDefault - 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:
        toString in class java.lang.Object
        Since:
        jcms-10.0.8