/** Closes this handler, removes it from the map of handlers by address and calls handleClose. */ @Override public void close() { try { server.getHandlerByAddress().remove(remoteAddress); super.close(); handleClose(); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Sets the SelectionKey of this handler. * * <p>Use EITHER this method or connect, not both. * * @param k the java.nio.channels#SelectionKey attaching this handler * @return this NetworkEventHandler, to call more methods on */ @SuppressWarnings("unchecked") @Override protected SocketServerEventHandler setSelectionKey(SelectionKey k) { try { super.setSelectionKey(k); Socket socket = ((SocketChannel) selectionKey.channel()).socket(); remoteAddress = socket.getRemoteSocketAddress(); socket.setKeepAlive(true); server .getHandlerByAddress() .put(((SocketChannel) selectionKey.channel()).socket().getRemoteSocketAddress(), this); return this; } catch (Exception e) { throw new RuntimeException(e); } }