/** * This method is used to flush all of the queued packets to * the client. This method will block not block but will simply * flush any data to the underlying transport. Internally the * data will be queued for delivery to the connected entity. */ public void flush() throws IOException { boolean done = writer.flush(); if(!done) { flusher.flush(); } }
/** * This returns the socket channel for the connected pipeline. It * is this channel that is used to determine if there are bytes * that can be written. When closed this is no longer selectable. * * @return this returns the connected channel for the pipeline */ public SocketChannel getChannel() { return writer.getChannel(); }
/** * This is executed when the flusher is to write all of the data to * the underlying socket. In this situation the writes are attempted * in a non blocking way, if the task does not complete then this * will simply enqueue the writing task for OP_WRITE and leave the * method. This returns true if all the buffers are written. */ private synchronized void execute() throws IOException { boolean ready = writer.flush(); if(!ready) { boolean block = writer.isBlocking(); if(!block && !closed) { scheduler.release(); } scheduler.repeat(); } else{ scheduler.ready(); } }
/** * This is used to abort the flushing process when the reactor has * been stopped. An abort to the flusher typically happens when the * server has been shutdown. It prevents threads lingering waiting * for a I/O operation which prevents the server from shutting down. */ private synchronized void abort() throws IOException { scheduler.close(); writer.close(); }
/** * This method is used to deliver the provided packet of bytes to * the underlying transport. This will not modify the data that * is to be written, this will simply queue the packets in the * order that they are provided. * * @param packet this is the array of bytes to send to the client */ public void write(Packet packet) throws IOException { boolean done = writer.write(packet); if(!done) { flusher.flush(); } }
/** * Here in this method we schedule a flush when the underlying * writer is write ready. This allows the writer thread to return * without having to fully flush the content to the underlying * transport. If there are references queued this will block. */ public synchronized void flush() throws IOException { if(closed) { throw new TransportException("Flusher is closed"); } boolean block = writer.isBlocking(); if(!closed) { scheduler.schedule(block); } }
/** * This is used to close the writer and the underlying socket. * If a close is performed on the writer then no more bytes * can be read from or written to the writer and the client * will receive a connection close on their side. */ public void close() throws IOException { flusher.close(); writer.close(); } }
/** * This is used to close the flusher ensuring that all of the * data within the writer will be flushed regardless of the * amount of data within the writer that needs to be written. If * the writer does not block then this waits to be finished. */ public synchronized void close() throws IOException { boolean ready = writer.flush(); if(!closed) { closed = true; } if(!ready) { scheduler.schedule(true); } }