Extract nested trys

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2017-08-19 16:17:55 -04:00
parent 0bbe9d321d
commit b5f1463864

View File

@ -236,16 +236,7 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
}
runnable.setRunning(false);
try {
consoleManager.type(applicationShutdown);
try {
appThNext.join(ONE_TENTH_OF_SECOND);
} catch (InterruptedException e) {
LOGGER.warning("Application thread was interrupted!"); //$NON-NLS-1$
LOGGER.log(Level.FINE,
"Application thread was interrupted while closing", //$NON-NLS-1$
e);
}
consoleManager.close();
closeManager(appThNext);
} catch (IOException e) {
LOGGER.warning("Unable to close application correctly"); //$NON-NLS-1$
LOGGER.log(Level.FINE, "Application closing caused an exception", //$NON-NLS-1$
@ -254,6 +245,24 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
LOGGER.info("Closing Server"); //$NON-NLS-1$
}
/** Close the console manager after writing the application shutdown
* command.
*
* @param appThNext the thread containing the application
* @throws IOException if the typyng or closing failed */
private void closeManager(Thread appThNext) throws IOException {
consoleManager.type(applicationShutdown);
try {
appThNext.join(ONE_TENTH_OF_SECOND);
} catch (InterruptedException e) {
LOGGER.warning("Application thread was interrupted!"); //$NON-NLS-1$
LOGGER.log(Level.FINE,
"Application thread was interrupted while closing", //$NON-NLS-1$
e);
}
consoleManager.close();
}
/** @param runnable the runnable */
private void startApplication(ConsoleRunnable runnable) {
runnable.restart();