Class Task
- java.lang.Object
-
- org.opends.guitools.controlpanel.task.Task
-
- Direct Known Subclasses:
AddToGroupTask,CancelTaskTask,DeleteBaseDNAndBackendTask,DeleteEntryTask,DeleteIndexTask,DeleteSchemaElementsTask,InclusionExclusionPanel.InclusionExclusionTask,IndexTask,ModifyAttributeTask,ModifyEntryTask,ModifyObjectClassTask,NewEntryTask,NewSchemaElementsTask,ResetUserPasswordTask,RestartServerTask,StartServerTask,StopServerTask
public abstract class Task extends Object
The class used to define a number of common methods and mechanisms for the tasks that are run in the Control Panel.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTask.StateThe state on which the task can be.static classTask.TypeThe different task types.
-
Field Summary
Fields Modifier and Type Field Description protected ApplicationPrintStreamerrorPrintStreamThe print stream for the error logs.protected ThrowablelastExceptionThe last exception encountered during the task execution.protected ApplicationPrintStreamoutPrintStreamThe print stream for the standard output logs.protected IntegerreturnCodeThe return code of the task.protected Task.StatestateThe current state of the task.
-
Constructor Summary
Constructors Modifier Constructor Description protectedTask(ControlPanelInfo info, ProgressDialog progressDialog)Constructor of the task.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddConfigurationElementCreatedListener(ConfigurationElementCreatedListener listener)Adds a configuration element created listener.abstract booleancanLaunch(Task taskToBeLaunched, Collection<org.forgerock.i18n.LocalizableMessage> incompatibilityReasons)Informs of whether the task to be launched can be launched or not.protected intexecuteCommandLine(String commandLineName, String[] args)Executes a command-line synchronously.abstract Set<String>getBackends()Returns the names of the backends that are affected by the task.protected abstract List<String>getCommandLineArguments()Returns the list of command-line arguments.protected abstract StringgetCommandLinePath()Returns the full path of the command-line associated with this task ornullif there is not a command-line (or a single command-line) associated with the task.protected StringgetCommandLinePath(String scriptBasicName)Returns the full path of the command-line for a given script name.StringgetCommandLineToDisplay()Returns the command-line to be displayed (when we display the equivalent command-line).protected List<String>getConfigCommandLineArguments()Returns the command-line arguments that correspond to the configuration.protected List<String>getConnectionCommandLineArguments()Returns the list of arguments related to the connection (host, port, bind DN, etc.).protected List<String>getConnectionCommandLineArguments(boolean useAdminConnector, boolean addConnectionTypeParameters)Returns the list of arguments related to the connection (host, port, bind DN, etc.).static StringgetEquivalentCommandLine(String cmdName, List<String> args)Returns the equivalent command line in HTML without font properties.StringgetErrorLogs()Returns the error logs of the task.ApplicationPrintStreamgetErrorPrintStream()Returns the print stream for the error logs.protected org.forgerock.i18n.LocalizableMessagegetIncompatibilityMessage(Task taskRunning, Task taskToBeLaunched)Returns the incompatible message between two tasks.ControlPanelInfogetInfo()Returns the ControlPanelInfo object.ThrowablegetLastException()Returns last exception encountered during the task execution.StringgetLogs()Returns the logs of the task.protected StringgetNoPropertiesFileArgument()Returns the noPropertiesFile argument.protected List<String>getObfuscatedCommandLineArguments(List<String> clearArgs)Returns the list of obfuscated command-line arguments.ApplicationPrintStreamgetOutPrintStream()Returns the print stream for the output logs.StringgetOutputLogs()Returns the output logs of the task.ProcessgetProcess()Returns the process that the task launched.protected ProgressDialoggetProgressDialog()Returns the progress dialog.IntegergetReturnCode()Returns the return code (this makes sense when the task launches a command-line, it will return the error code returned by the command-line).ServerDescriptorgetServer()Returns the server descriptor on which the task was launched.Task.StategetState()Returns the state of the task.abstract org.forgerock.i18n.LocalizableMessagegetTaskDescription()The description of the task.abstract Task.TypegetType()Returns the type of the task.protected booleanisServerRunning()Commodity method to know if the server is running or not.protected voidnotifyConfigurationElementCreated(Object configObject)Notifies the configuration element created listener that a new object has been created.protected StringobfuscateLDIFLine(String line)Obfuscates (if required) the attribute value in an LDIF line.voidpostOperation()Method that is called when everything is finished after updating the progress dialog.protected voidprintEquivalentCommandLine(String cmdName, List<String> args, org.forgerock.i18n.LocalizableMessage msg)Prints the equivalent command line.protected voidprintEquivalentCommandToModify(DN dn, Collection<Modification> mods, boolean useAdminCtx)Prints the equivalent modify command line in the progress dialog.protected voidprintEquivalentRenameCommand(DN oldDN, DN newDN, boolean useAdminCtx)Prints the equivalent rename command line in the progress dialog.booleanregenerateDescriptor()Tells whether a new server descriptor should be regenerated when the task is over.voidremoveConfigurationElementCreatedListener(ConfigurationElementCreatedListener listener)Removes a configuration element created listener.protected booleanrunningOnSameServer(Task task)Check whether the provided task and this task run on the same server.abstract voidrunTask()Execute the task.protected voidstartPoolingAndInitializeConfiguration()Initializes the configuration and starts the pooling.protected voidstopPoolingAndInitializeConfiguration()Stops the pooling and initializes the configuration.
-
-
-
Field Detail
-
state
protected Task.State state
The current state of the task.
-
returnCode
protected Integer returnCode
The return code of the task.
-
lastException
protected Throwable lastException
The last exception encountered during the task execution.
-
errorPrintStream
protected final ApplicationPrintStream errorPrintStream
The print stream for the error logs.
-
outPrintStream
protected final ApplicationPrintStream outPrintStream
The print stream for the standard output logs.
-
-
Constructor Detail
-
Task
protected Task(ControlPanelInfo info, ProgressDialog progressDialog)
Constructor of the task.- Parameters:
info- the control panel information.progressDialog- the progress dialog where the task progress will be displayed.
-
-
Method Detail
-
getBackends
public abstract Set<String> getBackends()
Returns the names of the backends that are affected by the task.- Returns:
- the names of the backends that are affected by the task.
-
getInfo
public ControlPanelInfo getInfo()
Returns the ControlPanelInfo object.- Returns:
- the ControlPanelInfo object.
-
stopPoolingAndInitializeConfiguration
protected void stopPoolingAndInitializeConfiguration() throws DirectoryException, InitializationExceptionStops the pooling and initializes the configuration.- Throws:
DirectoryException- if the configuration cannot be deregisteredInitializationException- if a problem occurs during configuration initialization
-
startPoolingAndInitializeConfiguration
protected void startPoolingAndInitializeConfiguration() throws InitializationExceptionInitializes the configuration and starts the pooling.- Throws:
InitializationException- if a problem occurs during configuration initialization
-
getLogs
public String getLogs()
Returns the logs of the task.- Returns:
- the logs of the task.
-
getErrorLogs
public String getErrorLogs()
Returns the error logs of the task.- Returns:
- the error logs of the task.
-
getOutputLogs
public String getOutputLogs()
Returns the output logs of the task.- Returns:
- the output logs of the task.
-
getState
public Task.State getState()
Returns the state of the task.- Returns:
- the state of the task.
-
getLastException
public Throwable getLastException()
Returns last exception encountered during the task execution. Returnsnullif no exception was found.- Returns:
- last exception encountered during the task execution.
-
getReturnCode
public Integer getReturnCode()
Returns the return code (this makes sense when the task launches a command-line, it will return the error code returned by the command-line).- Returns:
- the return code.
-
getProcess
public Process getProcess()
Returns the process that the task launched. Returnsnullif not process was launched.- Returns:
- the process that the task launched.
-
getProgressDialog
protected ProgressDialog getProgressDialog()
Returns the progress dialog.- Returns:
- the progress dialog.
-
regenerateDescriptor
public boolean regenerateDescriptor()
Tells whether a new server descriptor should be regenerated when the task is over. If the task has an influence in the configuration or state of the server (for instance the creation of a base DN) this method should returntrueso that the configuration will be re-read and all the ConfigChangeListeners will receive a notification with the new configuration.- Returns:
trueif a new server descriptor must be regenerated when the task is over andfalseotherwise.
-
postOperation
public void postOperation()
Method that is called when everything is finished after updating the progress dialog. It is called from the event thread.
-
getTaskDescription
public abstract org.forgerock.i18n.LocalizableMessage getTaskDescription()
The description of the task. It is used in both the incompatibility messages and in the warning message displayed when the user wants to quit and there are tasks running.- Returns:
- the description of the task.
-
addConfigurationElementCreatedListener
public void addConfigurationElementCreatedListener(ConfigurationElementCreatedListener listener)
Adds a configuration element created listener.- Parameters:
listener- the listener.
-
removeConfigurationElementCreatedListener
public void removeConfigurationElementCreatedListener(ConfigurationElementCreatedListener listener)
Removes a configuration element created listener.- Parameters:
listener- the listener.
-
notifyConfigurationElementCreated
protected void notifyConfigurationElementCreated(Object configObject)
Notifies the configuration element created listener that a new object has been created.- Parameters:
configObject- the created object.
-
obfuscateLDIFLine
protected String obfuscateLDIFLine(String line)
Obfuscates (if required) the attribute value in an LDIF line.- Parameters:
line- the line of the LDIF file that must be treated.- Returns:
- the line obfuscated.
-
executeCommandLine
protected int executeCommandLine(String commandLineName, String[] args)
Executes a command-line synchronously.- Parameters:
commandLineName- the command line full path.args- the arguments for the command-line.- Returns:
- the error code returned by the command-line.
-
canLaunch
public abstract boolean canLaunch(Task taskToBeLaunched, Collection<org.forgerock.i18n.LocalizableMessage> incompatibilityReasons)
Informs of whether the task to be launched can be launched or not. Every task must implement this method so that we avoid launching in paralel two tasks that are not compatible. Note that in general if the current task is not running this method will returntrue.- Parameters:
taskToBeLaunched- the Task that we are trying to launch.incompatibilityReasons- the list of incompatibility reasons that must be updated.- Returns:
trueif the task that we are trying to launch can be launched in parallel with this task andfalseotherwise.
-
runTask
public abstract void runTask()
Execute the task. This method is synchronous.
-
getType
public abstract Task.Type getType()
Returns the type of the task.- Returns:
- the type of the task.
-
runningOnSameServer
protected boolean runningOnSameServer(Task task)
Check whether the provided task and this task run on the same server.- Parameters:
task- the task the task to be analyzed.- Returns:
trueif both tasks run on the same server andfalseotherwise.
-
getServer
public ServerDescriptor getServer()
Returns the server descriptor on which the task was launched.- Returns:
- the server descriptor on which the task was launched.
-
getCommandLinePath
protected abstract String getCommandLinePath()
Returns the full path of the command-line associated with this task ornullif there is not a command-line (or a single command-line) associated with the task.- Returns:
- the full path of the command-line associated with this task.
-
getCommandLinePath
protected String getCommandLinePath(String scriptBasicName)
Returns the full path of the command-line for a given script name.- Parameters:
scriptBasicName- the script basic name (with no extension).- Returns:
- the full path of the command-line for a given script name.
-
getCommandLineArguments
protected abstract List<String> getCommandLineArguments()
Returns the list of command-line arguments.- Returns:
- the list of command-line arguments.
-
getObfuscatedCommandLineArguments
protected List<String> getObfuscatedCommandLineArguments(List<String> clearArgs)
Returns the list of obfuscated command-line arguments. This is called basically to display the equivalent command-line to the user.- Parameters:
clearArgs- the arguments in clear.- Returns:
- the list of obfuscated command-line arguments.
-
getConfigCommandLineArguments
protected List<String> getConfigCommandLineArguments()
Returns the command-line arguments that correspond to the configuration. This method is called to remove them when we display the equivalent command-line. In some cases we run the methods of the command-line directly (on this JVM) instead of launching the script in another process. When we call this methods we must add these arguments, but they are not to be included as arguments of the command-line (when is launched as a script).- Returns:
- the command-line arguments that correspond to the configuration.
-
getConnectionCommandLineArguments
protected List<String> getConnectionCommandLineArguments()
Returns the list of arguments related to the connection (host, port, bind DN, etc.).- Returns:
- the list of arguments related to the connection.
-
getConnectionCommandLineArguments
protected List<String> getConnectionCommandLineArguments(boolean useAdminConnector, boolean addConnectionTypeParameters)
Returns the list of arguments related to the connection (host, port, bind DN, etc.).- Parameters:
useAdminConnector- use the administration connector to generate the command line.addConnectionTypeParameters- add the connection type parameters (--useSSL or --useStartTLS parameters: for ldapadd, ldapdelete, etc.).- Returns:
- the list of arguments related to the connection.
-
getNoPropertiesFileArgument
protected String getNoPropertiesFileArgument()
Returns the noPropertiesFile argument.- Returns:
- the noPropertiesFile argument.
-
getCommandLineToDisplay
public String getCommandLineToDisplay()
Returns the command-line to be displayed (when we display the equivalent command-line).- Returns:
- the command-line to be displayed.
-
isServerRunning
protected boolean isServerRunning()
Commodity method to know if the server is running or not.- Returns:
trueif the server is running andfalseotherwise.
-
getErrorPrintStream
public ApplicationPrintStream getErrorPrintStream()
Returns the print stream for the error logs.- Returns:
- the print stream for the error logs.
-
getOutPrintStream
public ApplicationPrintStream getOutPrintStream()
Returns the print stream for the output logs.- Returns:
- the print stream for the output logs.
-
printEquivalentCommandToModify
protected void printEquivalentCommandToModify(DN dn, Collection<Modification> mods, boolean useAdminCtx)
Prints the equivalent modify command line in the progress dialog.- Parameters:
dn- the dn of the modified entry.mods- the modifications.useAdminCtx- use the administration connector.
-
getEquivalentCommandLine
public static String getEquivalentCommandLine(String cmdName, List<String> args)
Returns the equivalent command line in HTML without font properties.- Parameters:
cmdName- the command name.args- the arguments for the command line.- Returns:
- the equivalent command-line in HTML.
-
printEquivalentCommandLine
protected void printEquivalentCommandLine(String cmdName, List<String> args, org.forgerock.i18n.LocalizableMessage msg)
Prints the equivalent command line.- Parameters:
cmdName- the command name.args- the arguments for the command line.msg- the message associated with the command line.
-
printEquivalentRenameCommand
protected void printEquivalentRenameCommand(DN oldDN, DN newDN, boolean useAdminCtx)
Prints the equivalent rename command line in the progress dialog.- Parameters:
oldDN- the old DN of the entry.newDN- the new DN of the entry.useAdminCtx- use the administration connector.
-
getIncompatibilityMessage
protected org.forgerock.i18n.LocalizableMessage getIncompatibilityMessage(Task taskRunning, Task taskToBeLaunched)
Returns the incompatible message between two tasks.- Parameters:
taskRunning- the task that is running.taskToBeLaunched- the task that we are trying to launch.- Returns:
- the incompatible message between two tasks.
-
-