/** * Initializes and starts the network thread. * * @throws IOException * - if network thread initialization fails */ public void start() throws IOException { if (!isNetworkThreadRunning()) { socketServerThread = new Thread(connectionHandler); socketServerThread.start(); LOGGER.info("Started network thread."); } else { LOGGER.error("Network thread start requested, but it's already running."); } }
/** * Terminates the work of the socket server. */ public void terminate() { if (!isNetworkThreadRunning()) { LOGGER.warn("Could not terminate network thread. Network thread is not running."); return; } LOGGER.info("Stopping socket server..."); connectionHandler.terminate(); try { socketServerThread.join(SOCKET_THREAD_KILL_TIMEOUT); LOGGER.debug("Network thread should be stopped now..."); } catch (InterruptedException e) { LOGGER.debug("Error stopping network thread...", e); } try { connectionHandler.terminateSocketServer(); LOGGER.info("Socket connection stopped successfully!"); } catch (IOException e) { LOGGER.error("Could not close opened connection.", e); } } }