From b5f14638647e2ef6cc546bf3eb22f44b7af37034 Mon Sep 17 00:00:00 2001 From: Emmanuel Bigeon Date: Sat, 19 Aug 2017 16:17:55 -0400 Subject: [PATCH] Extract nested trys Signed-off-by: Emmanuel Bigeon --- .../socket/SocketConsoleApplicationShell.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java b/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java index 834c45f..bcf2ad6 100644 --- a/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java +++ b/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java @@ -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();