Class AbstractMaintenanceTask

java.lang.Object
org.ametys.workspaces.repository.maintenance.AbstractMaintenanceTask
All Implemented Interfaces:
LogEnabled
Direct Known Subclasses:
CleanReferenceTask, ConsistencyCheckTask, DataStoreGarbageCollectorTask, ReclaimUnusedSpaceTask, ReindexingTask, RemoveUnusedHistoryTask

public abstract class AbstractMaintenanceTask extends Object implements LogEnabled
Jackrabbit maintenance tasks implementations should extends this class.
  • Field Details

  • Constructor Details

  • Method Details

    • requiresOffline

      public boolean requiresOffline()
      Indicate if the task need to be executed with an offline repository
      Returns:
      true if the repository need to be offline
    • execute

      public void execute(Pair<RepositoryConfig,RepositoryContext> repositoryInfo) throws javax.jcr.RepositoryException
      Execute the task
      Parameters:
      repositoryInfo - a pair providing either the repository config (left) or the repository context (right). Only one will be valued. The other one is null.
      Throws:
      javax.jcr.RepositoryException - If an error with the repository occurs while the task is executed.
    • initialize

      protected void initialize() throws javax.jcr.RepositoryException
      Initialize the tasks. This method can also create the ProgressionTracker object bounded to the task.
      Throws:
      javax.jcr.RepositoryException - If a repository exception
    • apply

      protected abstract void apply() throws javax.jcr.RepositoryException
      Apply the tasks (within the execute method()).
      Throws:
      javax.jcr.RepositoryException - If a repository exception
    • close

      protected void close()
      Close the tasks
    • setLogger

      protected abstract void setLogger()
      Set the tasks logger.
    • setLogger

      public void setLogger(Logger logger)
      Description copied from interface: LogEnabled
      Called at creation time to provide a Logger.
      Specified by:
      setLogger in interface LogEnabled
      Parameters:
      logger - a Logger for messages.
    • getProgressInfo

      Get progress information.
      Returns:
      a map containing information on the progress status.
    • isFinished

      public boolean isFinished()
      Is the execution of the task finished?
      Returns:
      true if finished
    • _getFormattedDuration

      protected String _getFormattedDuration(long elapsedTime)
      Transforms millisecond to a formatted string representing a duration.
      Parameters:
      elapsedTime - milleseconds corresponding to the duration.
      Returns:
      Pretty formatted string.
    • getRepositoryConfig

      Get the repository config
      Returns:
      the repository config
    • createRepositoryContext

      protected RepositoryContext createRepositoryContext() throws javax.jcr.RepositoryException
      Create a repository context. If a repository context was provided, or a repository was already created, then an error will be thrown
      Returns:
      the repository context
      Throws:
      javax.jcr.RepositoryException - if an error occurred
    • getOrCreateRepositoryContext

      protected RepositoryContext getOrCreateRepositoryContext() throws javax.jcr.RepositoryException
      Get the current repository context if one was provided or already created. Or instantiate a new one from the provided config.
      Returns:
      a repository context
      Throws:
      javax.jcr.RepositoryException - when an error occurred
    • getRepository

      Get the repository. The repository can either be retrieved from a provided RepositoryContext or from a context created by createRepositoryContext(), createRepository() or getOrCreateRepository().
      Returns:
      the repository
    • createRepository

      protected RepositoryImpl createRepository() throws javax.jcr.RepositoryException
      Create a repository. If there is already an existing repository or repository context, a error will be thrown
      Returns:
      a repository
      Throws:
      javax.jcr.RepositoryException - when an error occurred
    • getOrCreateRepository

      protected RepositoryImpl getOrCreateRepository() throws javax.jcr.RepositoryException
      Get the repository from a provided context. Or instantiate a new repository from the provided config
      Returns:
      a repository
      Throws:
      javax.jcr.RepositoryException - when an error occurred
    • getAllPersistenceManager

      protected static List<IterablePersistenceManager> getAllPersistenceManager(RepositoryContext context) throws javax.jcr.RepositoryException
      Get the persistence manager from all workspace and the version manager from the repository context If any of those persistence manager is not an IterablePersistenceManager null will be returned
      Parameters:
      context - the repository context
      Returns:
      the persistence managers
      Throws:
      javax.jcr.RepositoryException - if an error occurred