Class Task

    • 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.
      • startPoolingAndInitializeConfiguration

        protected void startPoolingAndInitializeConfiguration()
                                                       throws InitializationException
        Initializes 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. Returns null if 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. Returns null if 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 return true so that the configuration will be re-read and all the ConfigChangeListeners will receive a notification with the new configuration.
        Returns:
        true if a new server descriptor must be regenerated when the task is over and false otherwise.
      • 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 return true.
        Parameters:
        taskToBeLaunched - the Task that we are trying to launch.
        incompatibilityReasons - the list of incompatibility reasons that must be updated.
        Returns:
        true if the task that we are trying to launch can be launched in parallel with this task and false otherwise.
      • 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:
        true if both tasks run on the same server and false otherwise.
      • 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 or null if 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:
        true if the server is running and false otherwise.
      • 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.