public void close(boolean flushData) { if (flushData) { closing = true; // Enqueue a close marker message to let the server // know we should close send(CLOSE_MARKER, false, true); return; } try { // Note: even though we may be disconnected from the socket.isConnected() // standpoint, it's still safest to tell the kernel so that it can be sure // to stop managing us gracefully. kernel.closeEndpoint(this); } catch (IOException e) { throw new KernelException("Error closing endpoint for socket:" + socket, e); } }