/** * Constructor for the <code>SocketFlusher</code> object. This is * used to flush buffers to the underlying socket asynchronously. * When finished flushing all of the buffered data this signals * any threads that are blocking waiting for the write to finish. * * @param buffer this is used to write the buffered buffers * @param reactor this is used to perform asynchronous writes * @param socket this is the socket used to select with */ public SocketFlusher(SocketBuffer buffer, Socket socket, Reactor reactor) throws IOException { this.signaller = new FlushSignaller(this, socket); this.scheduler = new FlushScheduler(socket, reactor, signaller, this); this.buffer = buffer; }
/** * 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. */ public synchronized void abort() throws IOException { scheduler.close(); buffer.close(); }
/** * 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. */ public synchronized void execute() throws IOException { boolean ready = buffer.flush(); if(!ready) { boolean block = !buffer.ready(); if(!block && !closed) { scheduler.release(); } scheduler.repeat(); } else{ scheduler.ready(); } }
/** * 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 = buffer.flush(); if(!closed) { closed = true; } if(!ready) { scheduler.schedule(true); } } }
/** * This is used to schedule the task for execution. If this is * given a boolean true to indicate that it wishes to block * then this will block the calling thread until such time as * the <code>ready</code> method is invoked. * * @param block indicates whether the thread should block */ public void schedule(boolean block) throws IOException { if(closed) { throw new TransportException("Socket closed"); } if(!running) { trace.trace(WRITE_WAIT); reactor.process(task, OP_WRITE); running = true; } if(block) { listen(); } }
/** * 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 = buffer.flush(); if(!closed) { closed = true; } if(!ready) { scheduler.schedule(true); } } }
/** * This is used to schedule the task for execution. If this is * given a boolean true to indicate that it wishes to block * then this will block the calling thread until such time as * the <code>ready</code> method is invoked. * * @param block indicates whether the thread should block */ public void schedule(boolean block) throws IOException { if(closed) { throw new TransportException("Socket closed"); } if(!running) { trace.trace(WRITE_WAIT); reactor.process(task, OP_WRITE); running = true; } if(block) { listen(); } }
/** * 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. */ public synchronized void execute() throws IOException { boolean ready = buffer.flush(); if(!ready) { boolean block = !buffer.ready(); if(!block && !closed) { scheduler.release(); } scheduler.repeat(); } else{ scheduler.ready(); } }
/** * 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 = !buffer.ready(); if(!closed) { scheduler.schedule(block); } }
/** * 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. */ public synchronized void abort() throws IOException { scheduler.close(); buffer.close(); }
/** * Constructor for the <code>SocketFlusher</code> object. This is * used to flush buffers to the underlying socket asynchronously. * When finished flushing all of the buffered data this signals * any threads that are blocking waiting for the write to finish. * * @param buffer this is used to write the buffered buffers * @param reactor this is used to perform asynchronous writes * @param socket this is the socket used to select with */ public SocketFlusher(SocketBuffer buffer, Socket socket, Reactor reactor) throws IOException { this.signaller = new FlushSignaller(this, socket); this.scheduler = new FlushScheduler(socket, reactor, signaller, this); this.buffer = buffer; }
/** * 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 = !buffer.ready(); if(!closed) { scheduler.schedule(block); } }