application's
* installation.
* @param application to use for notifications
*/
public ServerController(Application application) {
this(application, application.getInstallation());
}
/**
* Creates a new instance that will operate on application's
* installation.
* @param installation representing the server instance to control
*/
public ServerController(Installation installation) {
this(null, installation);
}
/**
* Creates a new instance that will operate on installation
* and use application for notifications.
* @param application to use for notifications
* @param installation representing the server instance to control
*/
public ServerController(Application application, Installation installation) {
if (installation == null) {
throw new NullPointerException("installation cannot be null");
}
this.application = application;
this.installation = installation;
}
/**
* This methods stops the server.
*
* @throws org.opends.quicksetup.ApplicationException if something goes wrong.
*/
public void stopServer() throws ApplicationException {
stopServer(false);
}
/**
* This methods stops the server.
*
* @param suppressOutput boolean indicating that ouput to standard output
* streams from the server should be suppressed.
* @throws org.opends.quicksetup.ApplicationException
* if something goes wrong.
*/
public void stopServer(boolean suppressOutput) throws ApplicationException {
stopServer(suppressOutput,false);
}
/**
* This methods stops the server.
*
* @param suppressOutput boolean indicating that ouput to standard output
* streams from the server should be suppressed.
* @param noPropertiesFile boolean indicating if the stopServer should
* be called without taking into account the
* properties file.
* @throws org.opends.quicksetup.ApplicationException
* if something goes wrong.
*/
public void stopServer(boolean suppressOutput,boolean noPropertiesFile)
throws ApplicationException {
if (suppressOutput && !StandardOutputSuppressor.isSuppressed()) {
StandardOutputSuppressor.suppress();
}
if (suppressOutput && application != null)
{
application.setNotifyListeners(false);
}
try {
if (application != null) {
LocalizableMessageBuilder mb = new LocalizableMessageBuilder();
mb.append(application.getFormattedProgress(
INFO_PROGRESS_STOPPING.get()));
mb.append(application.getLineBreak());
application.notifyListeners(mb.toMessage());
}
logger.info(LocalizableMessage.raw("stopping server"));
ArrayList
* When a new log message is found notifies the
* UninstallProgressUpdateListeners of it. If an error occurs it also
* notifies the listeners.
*/
private class StopReader {
private boolean isFirstLine;
/**
* The protected constructor.
*
* @param reader the BufferedReader of the stop process.
* @param isError a boolean indicating whether the BufferedReader
* corresponds to the standard error or to the standard output.
*/
public StopReader(final BufferedReader reader,
final boolean isError) {
final LocalizableMessage errorTag =
isError ?
INFO_ERROR_READING_ERROROUTPUT.get() :
INFO_ERROR_READING_OUTPUT.get();
isFirstLine = true;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
String line = reader.readLine();
while (line != null) {
if (application != null) {
LocalizableMessageBuilder buf = new LocalizableMessageBuilder();
if (!isFirstLine) {
buf.append(application.getProgressMessageFormatter().
getLineBreak());
}
if (isError) {
buf.append(application.getFormattedLogError(
LocalizableMessage.raw(line)));
} else {
buf.append(application.getFormattedLog(
LocalizableMessage.raw(line)));
}
application.notifyListeners(buf.toMessage());
isFirstLine = false;
}
logger.info(LocalizableMessage.raw("server: " + line));
line = reader.readLine();
}
} catch (Throwable t) {
if (application != null) {
LocalizableMessage errorMsg = getThrowableMsg(errorTag, t);
application.notifyListeners(errorMsg);
}
logger.info(LocalizableMessage.raw("error reading server messages",t));
}
}
});
t.start();
}
}
/**
* Returns the LocalizableMessage ID indicating that the server has started.
* @return the LocalizableMessage ID indicating that the server has started.
*/
private String getStartedId()
{
InstallerHelper helper = new InstallerHelper();
return helper.getStartedId();
}
/**
* This class is used to read the standard error and standard output of the
* Start process.
*
* When a new log message is found notifies the ProgressUpdateListeners
* of it. If an error occurs it also notifies the listeners.
*/
private class StartReader
{
private ApplicationException ex;
private boolean isFinished;
private boolean startedIdFound;
private boolean isFirstLine;
/**
* The protected constructor.
* @param reader the BufferedReader of the start process.
* @param startedId the message ID that this class can use to know whether
* the start is over or not.
* @param isError a boolean indicating whether the BufferedReader
* corresponds to the standard error or to the standard output.
*/
public StartReader(final BufferedReader reader, final String startedId,
final boolean isError)
{
final LocalizableMessage errorTag =
isError ?
INFO_ERROR_READING_ERROROUTPUT.get() :
INFO_ERROR_READING_OUTPUT.get();
isFirstLine = true;
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
String line = reader.readLine();
while (line != null)
{
if (application != null) {
LocalizableMessageBuilder buf = new LocalizableMessageBuilder();
if (!isFirstLine)
{
buf.append(application.getProgressMessageFormatter().
getLineBreak());
}
if (isError)
{
buf.append(application.getFormattedLogError(
LocalizableMessage.raw(line)));
} else
{
buf.append(application.getFormattedLog(
LocalizableMessage.raw(line)));
}
application.notifyListeners(buf.toMessage());
isFirstLine = false;
}
logger.info(LocalizableMessage.raw("server: " + line));
if (line.toLowerCase().contains("=" + startedId))
{
isFinished = true;
startedIdFound = true;
}
line = reader.readLine();
}
} catch (Throwable t)
{
logger.warn(LocalizableMessage.raw("Error reading output: "+t, t));
ex = new ApplicationException(
ReturnCode.START_ERROR,
getThrowableMsg(errorTag, t), t);
}
isFinished = true;
}
});
t.start();
}
/**
* Returns the ApplicationException that occurred reading the Start error
* and output or null if no exception occurred.
* @return the exception that occurred reading or null if
* no exception occurred.
*/
public ApplicationException getException()
{
return ex;
}
/**
* Returns true if the server starting process finished
* (successfully or not) and false otherwise.
* @return true if the server starting process finished
* (successfully or not) and false otherwise.
*/
public boolean isFinished()
{
return isFinished;
}
/**
* Returns true if the server start Id was found and
* false otherwise.
* @return true if the server start Id was found and
* false otherwise.
*/
public boolean startedIdFound()
{
return startedIdFound;
}
}
}