Class Application
- java.lang.Object
-
- org.opends.quicksetup.Application
-
- All Implemented Interfaces:
Runnable,ProgressNotifier
- Direct Known Subclasses:
GuiApplication
public abstract class Application extends Object implements ProgressNotifier, Runnable
This class represents an application that can be run in the context of QuickSetup. Examples of applications might be 'installer' and 'uninstaller'.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classApplication.ErrorPrintStreamThis class is used to notify the ProgressUpdateListeners of events that are written to the standard error.classApplication.OutputPrintStreamThis class is used to notify the ProgressUpdateListeners of events that are written to the standard output.protected classApplication.PointAdderClass used to add points periodically to the end of the logs.
-
Field Summary
Fields Modifier and Type Field Description protected ProgressMessageFormatterformatterFormats progress messages.protected CurrentInstallStatusinstallStatusRepresents current install state.protected TempLogFiletempLogFileTemporary log file where messages will be logged, onceopenTempLogFile()has asked for it.
-
Constructor Summary
Constructors Constructor Description Application()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddProgressUpdateListener(ProgressUpdateListener l)Adds a ProgressUpdateListener that will be notified of updates in the install progress.protected voidapplicationPrintStreamReceived(String message)Method that is invoked by the printstreams with the messages received on operations such as start or import.abstract voidcancel()Signals that the application should cancel a currently running operation as soon as possible and return the environment to the state prior to running the operation.voidcheckAbort()Checks whether the operation has been aborted.static GuiApplicationcreate()Creates an application by instantiating the Application class denoted by the System propertyorg.opends.quicksetup.Application.class.UserDatacreateUserData()Creates a set of user data with default values.Application.ErrorPrintStreamgetApplicationErrorStream()Returns the error stream to be used by the application when launching command lines.Application.OutputPrintStreamgetApplicationOutputStream()Returns the output stream to be used by the application when launching command lines.abstract ProgressStepgetCurrentProgressStep()Gets the current step.org.forgerock.i18n.LocalizableMessagegetFormattedDone()Returns the formatted representation of the 'Done' text string.org.forgerock.i18n.LocalizableMessagegetFormattedDoneWithLineBreak()Returns the formatted representation of the 'Done' text string with a line break at the end.protected org.forgerock.i18n.LocalizableMessagegetFormattedError(Throwable t, boolean applyMargin)Returns the formatted representation of an error message for a given exception.protected org.forgerock.i18n.LocalizableMessagegetFormattedError(org.forgerock.i18n.LocalizableMessage text)Returns the formatted representation of an error for a given text.org.forgerock.i18n.LocalizableMessagegetFormattedLog(org.forgerock.i18n.LocalizableMessage text)Returns the formatted representation of a log message for a given text.org.forgerock.i18n.LocalizableMessagegetFormattedLogError(org.forgerock.i18n.LocalizableMessage text)Returns the formatted representation of a log error message for a given text.org.forgerock.i18n.LocalizableMessagegetFormattedProgress(org.forgerock.i18n.LocalizableMessage text)Returns the formatted representation of a progress message for a given text.org.forgerock.i18n.LocalizableMessagegetFormattedProgressWithLineBreak(org.forgerock.i18n.LocalizableMessage text)Returns the formatted representation of a progress message for a given text with a line break.protected org.forgerock.i18n.LocalizableMessagegetFormattedSuccess(org.forgerock.i18n.LocalizableMessage text)Returns the formatted representation of a success message for a given text.protected org.forgerock.i18n.LocalizableMessagegetFormattedSummary(org.forgerock.i18n.LocalizableMessage text)Returns the formatted representation of the text that is the summary of the installation process (the one that goes in the UI next to the progress bar).org.forgerock.i18n.LocalizableMessagegetFormattedWarning(org.forgerock.i18n.LocalizableMessage text)Returns the formatted representation of an warning for a given text.org.forgerock.i18n.LocalizableMessagegetFormattedWithPoints(org.forgerock.i18n.LocalizableMessage text)Returns the formatted representation of the argument text to which we add points.InstallationgetInstallation()Gets the OpenDJ installation associated with the execution of this command.abstract StringgetInstallationPath()Returns the installation path.abstract StringgetInstancePath()Returns the instance path.org.forgerock.i18n.LocalizableMessagegetLineBreak()Returns the line break formatted.protected org.forgerock.i18n.LocalizableMessagegetMessage(TopologyCacheException e)Returns a localized representation of a TopologyCacheException object.ProgressMessageFormattergetProgressMessageFormatter()Gets the formatter this instance is currently using.abstract IntegergetRatio(ProgressStep step)Gets an integer representing the amount of processing this application still needs to perform as a ratio out of 100.protected ConnectionWrappergetRemoteConnection(ServerDescriptor server, DN dn, String pwd, int timeout, Set<PreferredConnection> cnx)Gets a connection based on the information that appears on the provided ServerDescriptor object.abstract org.forgerock.i18n.LocalizableMessagegetSummary(ProgressStep step)Gets an i18n'd string representing the summary of a give ProgressStep.protected org.forgerock.i18n.LocalizableMessagegetTaskSeparator()Returns the task separator formatted.ApplicationTrustManagergetTrustManager()Returns the trust manager that can be used to establish secure connections.UserDatagetUserData()Returns the UserData object representing the parameters provided by the user to do the installation.abstract booleanisCancellable()Indicates whether this application is capable of cancelling the operation performed in the run method.abstract booleanisFinished()Returns whether the installer has finished or not.booleanisVerbose()Returnstrueif the application is running in verbose mode andfalseotherwise.voidnotifyListeners(Integer ratio, org.forgerock.i18n.LocalizableMessage currentPhaseSummary, org.forgerock.i18n.LocalizableMessage newLogDetail)This method notifies the ProgressUpdateListeners that there was an update in the installation progress.voidnotifyListeners(org.forgerock.i18n.LocalizableMessage newLogDetail)This method is called when a new log message has been received.voidnotifyListenersDone(Integer ratio)This method notifies the ProgressUpdateListeners that there was an update in the installation progress.voidnotifyListenersRatioChange(Integer ratio)This method notifies the ProgressUpdateListeners that there was an update in the installation progress.voidnotifyListenersWithPoints(Integer ratio, org.forgerock.i18n.LocalizableMessage newLogDetail)This method notifies the ProgressUpdateListeners that there was an update in the installation progress.protected TempLogFileopenTempLogFile()Creates the temporary log file of this application, unless it has one already.voidremoveProgressUpdateListener(ProgressUpdateListener l)Removes a ProgressUpdateListener.voidsetCurrentInstallStatus(CurrentInstallStatus installStatus)Sets the current install status for this application.voidsetInstallation(Installation installation)Sets the application's installation.voidsetNotifyListeners(boolean notifyListeners)Tells whether we must notify the listeners or not of the message received.voidsetProgressMessageFormatter(ProgressMessageFormatter formatter)Sets the formatter this instance should use to used to format progress messages.voidsetTempLogFile(Supplier<TempLogFile> tempLogFile)Sets where the temporary log file of this application comes from, without creating it.voidsetUserData(UserData userData)Sets this instances user data.
-
-
-
Field Detail
-
installStatus
protected CurrentInstallStatus installStatus
Represents current install state.
-
formatter
protected ProgressMessageFormatter formatter
Formats progress messages.
-
tempLogFile
protected TempLogFile tempLogFile
Temporary log file where messages will be logged, onceopenTempLogFile()has asked for it. It staysnulluntil then: creating it costs a file - and the directory it lives in - that nothing removes unless the operation succeeds, so the roads which attempt nothing must not create one (issue #1030).
-
-
Method Detail
-
create
public static GuiApplication create() throws RuntimeException
Creates an application by instantiating the Application class denoted by the System propertyorg.opends.quicksetup.Application.class.- Returns:
- Application object that was newly instantiated
- Throws:
RuntimeException- if there was a problem creating the new Application object
-
setUserData
public void setUserData(UserData userData)
Sets this instances user data.- Parameters:
userData- UserData this application will use when executing
-
createUserData
public UserData createUserData()
Creates a set of user data with default values.- Returns:
- UserData empty set of UserData
-
addProgressUpdateListener
public void addProgressUpdateListener(ProgressUpdateListener l)
Adds a ProgressUpdateListener that will be notified of updates in the install progress.- Specified by:
addProgressUpdateListenerin interfaceProgressNotifier- Parameters:
l- the ProgressUpdateListener to be added.
-
removeProgressUpdateListener
public void removeProgressUpdateListener(ProgressUpdateListener l)
Removes a ProgressUpdateListener.- Specified by:
removeProgressUpdateListenerin interfaceProgressNotifier- Parameters:
l- the ProgressUpdateListener to be removed.
-
getInstallation
public Installation getInstallation()
Gets the OpenDJ installation associated with the execution of this command.- Returns:
- Installation object representing the current OpenDS installation
-
setInstallation
public void setInstallation(Installation installation)
Sets the application's installation.- Parameters:
installation- describing the application's OpenDS installation
-
getUserData
public UserData getUserData()
Returns the UserData object representing the parameters provided by the user to do the installation.- Returns:
- the UserData object representing the parameters provided by the user to do the installation.
-
notifyListenersDone
public void notifyListenersDone(Integer ratio)
This method notifies the ProgressUpdateListeners that there was an update in the installation progress.- Parameters:
ratio- the integer that specifies which percentage of the whole installation has been completed.
-
notifyListenersRatioChange
public void notifyListenersRatioChange(Integer ratio)
This method notifies the ProgressUpdateListeners that there was an update in the installation progress.- Parameters:
ratio- the integer that specifies which percentage of the whole installation has been completed.
-
notifyListeners
public void notifyListeners(Integer ratio, org.forgerock.i18n.LocalizableMessage currentPhaseSummary, org.forgerock.i18n.LocalizableMessage newLogDetail)
This method notifies the ProgressUpdateListeners that there was an update in the installation progress.- Specified by:
notifyListenersin interfaceProgressNotifier- Parameters:
ratio- the integer that specifies which percentage of the whole installation has been completed.currentPhaseSummary- the localized summary message for the current installation progress in formatted form.newLogDetail- the new log messages that we have for the installation in formatted form.
-
notifyListenersWithPoints
public void notifyListenersWithPoints(Integer ratio, org.forgerock.i18n.LocalizableMessage newLogDetail)
This method notifies the ProgressUpdateListeners that there was an update in the installation progress.- Parameters:
ratio- the integer that specifies which percentage of the whole installation has been completed.newLogDetail- the localized additional log message.
-
setProgressMessageFormatter
public void setProgressMessageFormatter(ProgressMessageFormatter formatter)
Sets the formatter this instance should use to used to format progress messages.- Parameters:
formatter- ProgressMessageFormatter for formatting progress messages
-
getProgressMessageFormatter
public ProgressMessageFormatter getProgressMessageFormatter()
Gets the formatter this instance is currently using.- Returns:
- the progress message formatter currently used by this application
-
getFormattedSummary
protected org.forgerock.i18n.LocalizableMessage getFormattedSummary(org.forgerock.i18n.LocalizableMessage text)
Returns the formatted representation of the text that is the summary of the installation process (the one that goes in the UI next to the progress bar).- Parameters:
text- the source text from which we want to get the formatted representation- Returns:
- the formatted representation of an error for the given text.
-
getFormattedError
protected org.forgerock.i18n.LocalizableMessage getFormattedError(org.forgerock.i18n.LocalizableMessage text)
Returns the formatted representation of an error for a given text.- Parameters:
text- the source text from which we want to get the formatted representation- Returns:
- the formatted representation of an error for the given text.
-
getFormattedWarning
public org.forgerock.i18n.LocalizableMessage getFormattedWarning(org.forgerock.i18n.LocalizableMessage text)
Returns the formatted representation of an warning for a given text.- Parameters:
text- the source text from which we want to get the formatted representation- Returns:
- the formatted representation of an warning for the given text.
-
getFormattedSuccess
protected org.forgerock.i18n.LocalizableMessage getFormattedSuccess(org.forgerock.i18n.LocalizableMessage text)
Returns the formatted representation of a success message for a given text.- Parameters:
text- the source text from which we want to get the formatted representation- Returns:
- the formatted representation of an success message for the given text.
-
getFormattedLogError
public org.forgerock.i18n.LocalizableMessage getFormattedLogError(org.forgerock.i18n.LocalizableMessage text)
Returns the formatted representation of a log error message for a given text.- Parameters:
text- the source text from which we want to get the formatted representation- Returns:
- the formatted representation of a log error message for the given text.
-
getFormattedLog
public org.forgerock.i18n.LocalizableMessage getFormattedLog(org.forgerock.i18n.LocalizableMessage text)
Returns the formatted representation of a log message for a given text.- Parameters:
text- the source text from which we want to get the formatted representation- Returns:
- the formatted representation of a log message for the given text.
-
getFormattedDone
public org.forgerock.i18n.LocalizableMessage getFormattedDone()
Returns the formatted representation of the 'Done' text string.- Returns:
- the formatted representation of the 'Done' text string.
-
getFormattedDoneWithLineBreak
public org.forgerock.i18n.LocalizableMessage getFormattedDoneWithLineBreak()
Returns the formatted representation of the 'Done' text string with a line break at the end.- Returns:
- the formatted representation of the 'Done' text string.
-
getFormattedWithPoints
public org.forgerock.i18n.LocalizableMessage getFormattedWithPoints(org.forgerock.i18n.LocalizableMessage text)
Returns the formatted representation of the argument text to which we add points. For instance if we pass as argument 'Configuring Server' the return value will be 'Configuring Server .....'.- Parameters:
text- the String to which add points.- Returns:
- the formatted representation of the '.....' text string.
-
getFormattedProgress
public org.forgerock.i18n.LocalizableMessage getFormattedProgress(org.forgerock.i18n.LocalizableMessage text)
Returns the formatted representation of a progress message for a given text.- Parameters:
text- the source text from which we want to get the formatted representation- Returns:
- the formatted representation of a progress message for the given text.
-
getFormattedProgressWithLineBreak
public org.forgerock.i18n.LocalizableMessage getFormattedProgressWithLineBreak(org.forgerock.i18n.LocalizableMessage text)
Returns the formatted representation of a progress message for a given text with a line break.- Parameters:
text- the source text from which we want to get the formatted representation- Returns:
- the formatted representation of a progress message for the given text.
-
getFormattedError
protected org.forgerock.i18n.LocalizableMessage getFormattedError(Throwable t, boolean applyMargin)
Returns the formatted representation of an error message for a given exception. This method applies a margin if the applyMargin parameter istrue.- Parameters:
t- the exception.applyMargin- specifies whether we apply a margin or not to the resulting formatted text.- Returns:
- the formatted representation of an error message for the given exception.
-
getLineBreak
public org.forgerock.i18n.LocalizableMessage getLineBreak()
Returns the line break formatted.- Returns:
- the line break formatted.
-
getTaskSeparator
protected org.forgerock.i18n.LocalizableMessage getTaskSeparator()
Returns the task separator formatted.- Returns:
- the task separator formatted.
-
notifyListeners
public void notifyListeners(org.forgerock.i18n.LocalizableMessage newLogDetail)
This method is called when a new log message has been received. It will notify the ProgressUpdateListeners of this fact.- Parameters:
newLogDetail- the new log detail.
-
getInstallationPath
public abstract String getInstallationPath()
Returns the installation path.- Returns:
- the installation path.
-
getInstancePath
public abstract String getInstancePath()
Returns the instance path.- Returns:
- the instance path.
-
getCurrentProgressStep
public abstract ProgressStep getCurrentProgressStep()
Gets the current step.- Returns:
- ProgressStep representing the current step
-
getRatio
public abstract Integer getRatio(ProgressStep step)
Gets an integer representing the amount of processing this application still needs to perform as a ratio out of 100.- Parameters:
step- ProgressStop for which a summary is needed- Returns:
- ProgressStep representing the current step
-
getSummary
public abstract org.forgerock.i18n.LocalizableMessage getSummary(ProgressStep step)
Gets an i18n'd string representing the summary of a give ProgressStep.- Parameters:
step- ProgressStop for which a summary is needed- Returns:
- String representing the summary
-
setCurrentInstallStatus
public void setCurrentInstallStatus(CurrentInstallStatus installStatus)
Sets the current install status for this application.- Parameters:
installStatus- for the current installation.
-
isFinished
public abstract boolean isFinished()
Returns whether the installer has finished or not.- Returns:
trueif the install is finished orfalseif not.
-
getTrustManager
public ApplicationTrustManager getTrustManager()
Returns the trust manager that can be used to establish secure connections.- Returns:
- the trust manager that can be used to establish secure connections.
-
isCancellable
public abstract boolean isCancellable()
Indicates whether this application is capable of cancelling the operation performed in the run method. A cancellable operation should leave its environment in the same state as it was prior to running the operation (files deleted, changes backed out etc.). Marking anApplicationas cancellable may control UI elements like the presense of a cancel button while the operation is being performed. Applications marked as cancellable should override thecancelmethod in such a way as to undo whatever actions have taken place in the run method up to that point.- Returns:
- boolean where true inidcates that the operation is cancellable
-
cancel
public abstract void cancel()
Signals that the application should cancel a currently running operation as soon as possible and return the environment to the state prior to running the operation. When finished backing out changes the application should make sure thatisFinishedreturns true so that the application can complete.
-
checkAbort
public void checkAbort() throws ApplicationExceptionChecks whether the operation has been aborted. If it has throws an ApplicationException. All the applications that support abort must provide their implementation as the default implementation is empty.- Throws:
ApplicationException- thrown if the application was aborted.
-
getMessage
protected org.forgerock.i18n.LocalizableMessage getMessage(TopologyCacheException e)
Returns a localized representation of a TopologyCacheException object.- Parameters:
e- the exception we want to obtain the representation from.- Returns:
- a localized representation of a TopologyCacheException object.
-
getRemoteConnection
protected ConnectionWrapper getRemoteConnection(ServerDescriptor server, DN dn, String pwd, int timeout, Set<PreferredConnection> cnx) throws ApplicationException
Gets a connection based on the information that appears on the provided ServerDescriptor object. Note that the server is assumed to be registered and that contains a Map with ADSContext.ServerProperty keys.- Parameters:
server- the object describing the server.dn- the dn to be used to authenticate.pwd- the pwd to be used to authenticate.timeout- the timeout to establish the connection in milliseconds. Use0to express no timeout.cnx- the ordered list of preferred connections to connect to the server.- Returns:
- the connection to the remote server.
- Throws:
ApplicationException- if something goes wrong.
-
isVerbose
public boolean isVerbose()
Returnstrueif the application is running in verbose mode andfalseotherwise.- Returns:
trueif the application is running in verbose mode andfalseotherwise.
-
getApplicationErrorStream
public Application.ErrorPrintStream getApplicationErrorStream()
Returns the error stream to be used by the application when launching command lines.- Returns:
- the error stream to be used by the application when launching command lines.
-
getApplicationOutputStream
public Application.OutputPrintStream getApplicationOutputStream()
Returns the output stream to be used by the application when launching command lines.- Returns:
- the output stream to be used by the application when launching command lines.
-
setNotifyListeners
public void setNotifyListeners(boolean notifyListeners)
Tells whether we must notify the listeners or not of the message received.- Parameters:
notifyListeners- the boolean that informs of whether we have to notify the listeners or not.
-
applicationPrintStreamReceived
protected void applicationPrintStreamReceived(String message)
Method that is invoked by the printstreams with the messages received on operations such as start or import. This is done so that the application can parse this messages and display them.- Parameters:
message- the message that has been received
-
setTempLogFile
public void setTempLogFile(Supplier<TempLogFile> tempLogFile)
Sets where the temporary log file of this application comes from, without creating it.The wizard and the CLI hand the supplier over as they start: the file itself is created by
openTempLogFile(), on the road that runs the operation, so that a run which does nothing - a quit at any step of the wizard, a server which turns out to be installed already - leaves no log behind (issue #1030).There is deliberately no setter taking the file itself: a caller holding a supplier could then resolve it on the spot, and the log would be created before anything is attempted again.
- Parameters:
tempLogFile- supplies the temporary log file where messages will be logged.
-
openTempLogFile
protected TempLogFile openTempLogFile()
Creates the temporary log file of this application, unless it has one already.Called where the operation begins and not before: from that point on the log is worth keeping, because there is something which can fail and be reported.
An application nobody handed a supplier to has no log of its own: the command line uninstaller is built that way, and its launcher creates the log before running it.
- Returns:
- the temporary log file of this application, or
nullif it was given none.
-
-