/** * The work loop. Selects on the server transport and accepts. If there was * a server transport that had blocking accepts, and returned on blocking * client transports, that should be used instead */ public void run() { try { if (eventHandler_ != null) { eventHandler_.preServe(); } while (!stopped_) { select(); } } catch (Throwable t) { LOGGER.error("run() on AcceptThread exiting due to uncaught error", t); } finally { try { acceptSelector.close(); } catch (IOException e) { LOGGER.error("Got an IOException while closing accept selector!", e); } // This will wake up the selector threads TThreadedSelectorServer.this.stop(); } }
/** * The work loop. Handles selecting (read/write IO), dispatching, and * managing the selection preferences of all existing connections. */ public void run() { try { while (!stopped_) { select(); processAcceptedConnections(); processInterestChanges(); } for (SelectionKey selectionKey : selector.keys()) { cleanupSelectionKey(selectionKey); } } catch (Throwable t) { LOGGER.error("run() on SelectorThread exiting due to uncaught error", t); } finally { try { selector.close(); } catch (IOException e) { LOGGER.error("Got an IOException while closing selector!", e); } // This will wake up the accept thread and the other selector threads TThreadedSelectorServer.this.stop(); } }
private void stopServingData() { if (dataServer == null) { return; } LOG.info("Stopping data server thread."); dataServer.stop(); try { dataServerThread.join(); } catch (InterruptedException e) { LOG.error("Interrupted while waiting for data server thread to stop. Continuing.", e); } dataServer = null; dataServerThread = null; LOG.info("Data server thread stopped"); }