public static void shutdown() { logger_.info("Shutting down ..."); synchronized (MessagingService.class) { /* Stop listening on any socket */ for (SelectionKey skey : listenSockets_.values()) { SelectorManager.getSelectorManager().cancel(skey); } listenSockets_.clear(); /* Shutdown the threads in the EventQueue's */ messageDeserializationExecutor_.shutdownNow(); messageSerializerExecutor_.shutdownNow(); messageDeserializerExecutor_.shutdownNow(); streamExecutor_.shutdownNow(); /* shut down the cachetables */ taskCompletionMap_.shutdown(); callbackMap_.shutdown(); /* Interrupt the selector manager thread */ SelectorManager.getSelectorManager().interrupt(); poolTable_.clear(); verbHandlers_.clear(); bShutdown_ = true; } logger_.debug("Shutdown invocation complete."); }
public static void stop() { try { if (port[0] != -1) { for (Entry<String, SocketChannel> client : clients.entrySet()) { if (client.getValue().isConnected()) { sendMessage(client.getValue(), MessageUtils.bye()); Utils.tryClose(client.getValue()); } } Utils.tryClose(serverSocket); clients.clear(); port[0] = -1; } else { System.err.println("stop: already stopped"); } } catch (Exception expt) { Utils.printErrorAndExit(expt.getMessage()); } }