Class AbstractMaintenanceTask
java.lang.Object
org.ametys.workspaces.repository.maintenance.AbstractMaintenanceTask
- All Implemented Interfaces:
LogEnabled
- Direct Known Subclasses:
CleanReferenceTask
,ConsistencyCheckTask
,DataStoreGarbageCollectorTask
,ReclaimUnusedSpaceTask
,ReindexingTask
,RemoveUnusedHistoryTask
Jackrabbit maintenance tasks implementations should extends this class.
-
Field Summary
Modifier and TypeFieldDescriptionprotected Logger
Logger for tracesprotected TaskProgress
TaskProgress -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
_getFormattedDuration
(long elapsedTime) Transforms millisecond to a formatted string representing a duration.protected abstract void
apply()
Apply the tasks (within the execute method()).protected void
close()
Close the tasksprotected RepositoryImpl
Create a repository.protected RepositoryContext
Create a repository context.void
execute
(Pair<RepositoryConfig, RepositoryContext> repositoryInfo) Execute the taskprotected static List<IterablePersistenceManager>
Get the persistence manager from all workspace and the version manager from the repository context If any of those persistence manager is not anIterablePersistenceManager
null will be returnedprotected RepositoryImpl
Get the repository from a provided context.protected RepositoryContext
Get the current repository context if one was provided or already created.Get progress information.protected RepositoryImpl
Get the repository.protected RepositoryConfig
Get the repository configprotected void
Initialize the tasks.boolean
Is the execution of the task finished?boolean
Indicate if the task need to be executed with an offline repositoryprotected abstract void
Set the tasks logger.void
Called at creation time to provide aLogger
.
-
Field Details
-
_progress
TaskProgress -
_logger
Logger for traces
-
-
Constructor Details
-
AbstractMaintenanceTask
public AbstractMaintenanceTask()
-
-
Method Details
-
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.RepositoryExceptionExecute 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
Initialize the tasks. This method can also create theTaskProgress
object bounded to the task.- Throws:
javax.jcr.RepositoryException
- If a repository exception
-
apply
Apply the tasks (within the execute method()).- Throws:
javax.jcr.RepositoryException
- If a repository exception
-
close
Close the tasks -
setLogger
Set the tasks logger. -
setLogger
Description copied from interface:LogEnabled
Called at creation time to provide aLogger
.- Specified by:
setLogger
in interfaceLogEnabled
- Parameters:
logger
- aLogger
for messages.
-
getProgressInfo
Get progress information.- Returns:
- a map containing information on the progress status.
-
isFinished
Is the execution of the task finished?- Returns:
- true if finished
-
_getFormattedDuration
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
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
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 providedRepositoryContext
or from a context created bycreateRepositoryContext()
,createRepository()
orgetOrCreateRepository()
.- Returns:
- the repository
-
createRepository
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
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 anIterablePersistenceManager
null will be returned- Parameters:
context
- the repository context- Returns:
- the persistence managers
- Throws:
javax.jcr.RepositoryException
- if an error occurred
-