public abstract class Task extends Object implements Comparable<Task>
Constructor and Description |
---|
Task() |
Modifier and Type | Method and Description |
---|---|
void |
addLogMessage(Severity severity,
LocalizableMessage message)
Adds a log message to the set of messages logged by this task.
|
void |
addLogMessage(Severity severity,
LocalizableMessage message,
Throwable exception)
Adds a log message to the set of messages logged by this task.
|
int |
compareTo(Task task)
Compares this task with the provided task for the purposes of ordering in a sorted list.
|
TaskState |
execute()
Begins execution for this task.
|
long |
getActualStartTime()
Retrieves the time that this task actually started running, if it has started.
|
LocalizableMessage |
getAttributeDisplayName(String name)
Given an attribute type name returns and locale sensitive representation.
|
long |
getCompletionTime()
Retrieves the time that this task completed all of its associated processing (regardless of whether it was
successful), if it has completed.
|
LinkedList<String> |
getDependencyIDs()
Retrieves the set of task IDs for any tasks on which this task is dependent.
|
LocalizableMessage |
getDisplayName()
Gets a message that identifies this type of task suitable for presentation to humans in monitoring tools.
|
FailedDependencyAction |
getFailedDependencyAction()
Retrieves the action that should be taken if any of the dependencies for this task do not complete successfully.
|
protected TaskState |
getFinalTaskState()
Returns a state for this task after processing has completed.
|
List<LocalizableMessage> |
getLogMessages()
Retrieves the set of messages that were logged by this task.
|
LinkedList<String> |
getNotifyOnCompletionAddresses()
Retrieves the set of e-mail addresses for the users that should receive a notification message when processing
for this task has completed.
|
LinkedList<String> |
getNotifyOnErrorAddresses()
Retrieves the set of e-mail addresses for the users that should receive a notification message if processing for
this task does not complete successfully.
|
Operation |
getOperation()
Retrieves the operation used to create this task in the server.
|
String |
getRecurringTaskID()
Retrieves the unique identifier assigned to the recurring task that is associated with this task, if there is
one.
|
long |
getScheduledStartTime()
Retrieves the scheduled start time for this task, if there is one.
|
protected ServerContext |
getServerContext()
Returns the server context.
|
Entry |
getTaskEntry()
Retrieves the entry containing the definition for this task.
|
Dn |
getTaskEntryDN()
Retrieves the DN of the entry containing the definition for this task.
|
String |
getTaskID()
Retrieves the unique identifier assigned to this task.
|
protected TaskState |
getTaskInterruptState()
Gets the interrupt state for this task that was set as a result of a call to
interruptTask(TaskState, LocalizableMessage) . |
TaskState |
getTaskState()
Retrieves the current state for this task.
|
void |
initializeTask()
Performs any task-specific initialization that may be required before processing can start.
|
void |
initializeTaskInternal(ServerContext serverContext,
TaskScheduler taskScheduler,
Entry taskEntry)
Performs generic initialization for this task based on the information in the provided task entry.
|
void |
interruptTask(TaskState interruptState,
LocalizableMessage interruptReason)
Performs any necessary processing to prematurely interrupt the execution of this task.
|
boolean |
isCancelled()
Indicates whether this task has been cancelled.
|
boolean |
isInterruptable()
Indicates whether this task is interruptible or not.
|
boolean |
isRecurring()
Indicates whether this task is an iteration of some recurring task.
|
protected void |
replaceAttributeValue(String name,
Object value)
Replaces an attribute values of the task entry.
|
protected abstract TaskState |
runTask()
Performs the actual core processing for this task.
|
protected void |
sendNotificationEMailMessage()
If appropriate, send an e-mail message with information about the completed task.
|
protected void |
setCompletionTime(long completionTime)
Sets the completion time for this task and updates the associated task entry as necessary.
|
void |
setOperation(Operation operation)
Specifies the operation used to create this task in the server.
|
protected void |
setTaskInterruptState(TaskState state)
Sets a state for this task that is the result of a call to
interruptTask(TaskState, LocalizableMessage) . |
protected ServerContext getServerContext()
public LocalizableMessage getDisplayName()
public LocalizableMessage getAttributeDisplayName(String name)
name
- of an attribute type associated with the object class that represents this entry in the directorypublic final void initializeTaskInternal(ServerContext serverContext, TaskScheduler taskScheduler, Entry taskEntry) throws InitializationException
serverContext
- The server context.taskScheduler
- The scheduler with which this task is associated.taskEntry
- The entry containing the task configuration.InitializationException
- If a problem occurs while performing the initialization.public final Dn getTaskEntryDN()
public final Entry getTaskEntry()
public final Operation getOperation()
initializeTask
method (and even that method should not depend on it always being available, since it will not be available if
the server is restarted and the task needs to be reinitialized).null
if it is not available.public final void setOperation(Operation operation)
operation
- The operation used to create this task in the server.public final String getTaskID()
public final String getRecurringTaskID()
null
if it is not associated with any recurring task.public final TaskState getTaskState()
public boolean isRecurring()
public boolean isCancelled()
protected void setTaskInterruptState(TaskState state)
interruptTask(TaskState, LocalizableMessage)
.
It may take this task some time to actually cancel to that actual state may differ until quiescence.state
- for this task once it has canceled whatever it is doingprotected TaskState getTaskInterruptState()
interruptTask(TaskState, LocalizableMessage)
.protected TaskState getFinalTaskState()
interruptTask(TaskState, LocalizableMessage)
then that method's interruptState is returned here.
Otherwise this method returns TaskState.COMPLETED_SUCCESSFULLY. It is assumed that if there were errors during
task processing that task state will have been derived in some other way.protected void replaceAttributeValue(String name, Object value)
name
- The name of the attribute that must be replaced.value
- The value that must replace the previous values of the attribute.public final long getScheduledStartTime()
System.currentTimeMillis()
. Any value representing a time in the past, or
any negative value, should be taken to mean that the task should be considered eligible for immediate execution.public final long getActualStartTime()
System.currentTimeMillis()
.public final long getCompletionTime()
System.currentTimeMillis()
.protected void setCompletionTime(long completionTime)
completionTime
- The completion time to use for this task.public final LinkedList<String> getDependencyIDs()
public final FailedDependencyAction getFailedDependencyAction()
public final LinkedList<String> getNotifyOnCompletionAddresses()
public final LinkedList<String> getNotifyOnErrorAddresses()
public final List<LocalizableMessage> getLogMessages()
public void addLogMessage(Severity severity, LocalizableMessage message)
ErrorLog.logError
methods. It does not
automatically persist the updated task information to disk.severity
- the severity of message.message
- the log message.public void addLogMessage(Severity severity, LocalizableMessage message, Throwable exception)
ErrorLog.logError
methods. It does not
automatically persist the updated task information to disk.severity
- the severity of message.message
- the log message.exception
- the exception to log. May be null
.public final int compareTo(Task task)
compareTo
in interface Comparable<Task>
task
- The task to compare with this task.public final TaskState execute()
runTask
method that performs the
appropriate set-up and tear-down. It should only be invoked by a task thread.protected void sendNotificationEMailMessage() throws javax.mail.MessagingException
javax.mail.MessagingException
- If a problem occurs while attempting to send the message.public void initializeTask() throws LdapException
LdapException
- If a problem occurs during initialization that should be returned to the client.protected abstract TaskState runTask()
public void interruptTask(TaskState interruptState, LocalizableMessage interruptReason)
setTaskInterruptState(TaskState)
if the
interruption is accepted by this task.interruptState
- The state to use for the task if it is successfully interrupted.interruptReason
- A human-readable explanation for the cancellation.public boolean isInterruptable()
Copyright 2010-2022 ForgeRock AS.