public void shutdown() { try { socket.close(); workers.remove(this); } catch (Exception e) { log.warn("Can't close worker ::: " + e.getMessage()); } }
/** * close socket,remove socket from array * * @param socket */ public static void closeConnection(AsynchronousSocketChannel socket) { try { logger.info("close client socket:" + socket.getRemoteAddress().toString()); socket.close(); } catch (IOException e) { logger.error("socket close error", e); } removeClientConnection(socket); }
@Override public void failed(Throwable exc, AsyncTimeClientHandler attachment) { exc.printStackTrace(); try { client.close(); latch.countDown(); } catch (IOException e) { e.printStackTrace(); } }
/** 关闭全部Socket */ public static void closeAllConnections() { Enumeration<AsynchronousSocketChannel> it = allClientSocket.keys(); while (it.hasMoreElements()) { AsynchronousSocketChannel so = it.nextElement(); try { logger.info("close client socket:" + so.getRemoteAddress().toString()); so.close(); } catch (IOException e) { logger.error("SocketQueue.closeAllSocket IOException:", e); } } allClientSocket.clear(); }
@Override public void run() { latch = new CountDownLatch(1); client.connect(new InetSocketAddress(host, port), this, this); try { latch.await(); } catch (InterruptedException e1) { e1.printStackTrace(); } try { client.close(); } catch (IOException e) { e.printStackTrace(); } }
public void dispose() { if (!isDispose) { isDispose = true; } if (player != null) { if (player.getCurrentHall() != null) { player.getCurrentHall().kickPlayer(this); } player = null; } if (readBuffer != null) { BufferPool.getInstance().releaseBuffer(readBuffer); readBuffer = null; } if (channel != null) { try { channel.close(); } catch (IOException e) { e.printStackTrace(); } finally { channel = null; } } }