/** * 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); } }
/** * 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); } }