public abstract class WriteFlusher extends java.lang.ObjectA Utility class to help implement
EndPoint.write(Callback, ByteBuffer...)by calling
EndPoint.flush(ByteBuffer...)until all content is written. The abstract method
onIncompleteFlush()is called when not all content has been written after a call to flush and should organize for the
completeWrite()method to be called when a subsequent call to flush should be able to make more progress.
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description
flush(java.nio.ByteBuffer buffers)Flushes the buffers iteratively until no progress is made.
onFail(java.lang.Throwable cause)Notify the flusher of a failure
protected abstract void
onIncompleteFlush()Abstract call to be implemented by specific WriteFlushers.
write(Callback callback, java.nio.ByteBuffer... buffers)Tries to switch state to WRITING.
protected WriteFlusher(EndPoint endPoint)
public Invocable.InvocationType getCallbackInvocationType()
protected abstract void onIncompleteFlush()
public void write(Callback callback, java.nio.ByteBuffer... buffers) throws java.nio.channels.WritePendingExceptionTries to switch state to WRITING. If successful it writes the given buffers to the EndPoint. If state transition fails it will fail the callback and leave the WriteFlusher in a terminal FAILED state. If not all buffers can be written in one go it creates a new
PendingStateobject to preserve the state and then calls
onIncompleteFlush(). The remaining buffers will be written in
completeWrite(). If all buffers have been written it calls callback.complete().
callback- the callback to call on either failed or complete
buffers- the buffers to flush to the endpoint
java.nio.channels.WritePendingException- if unable to write due to prior pending write
public void completeWrite()Complete a write that has not completed and that called
onIncompleteFlush()to request a call to this method when a call to
EndPoint.flush(ByteBuffer...)is likely to be able to progress. It tries to switch from PENDING to COMPLETING. If state transition fails, then it does nothing as the callback should have been already failed. That's because the only way to switch from PENDING outside this method is
protected java.nio.ByteBuffer flush(java.nio.ByteBuffer buffers) throws java.io.IOExceptionFlushes the buffers iteratively until no progress is made.
buffers- The buffers to flush
- The unflushed buffers, or null if all flushed
java.io.IOException- if unable to flush
public boolean onFail(java.lang.Throwable cause)Notify the flusher of a failure
cause- The cause of the failure
- true if the flusher passed the failure to a
public void onClose()
public boolean isPending()
public java.lang.String toStateString()
public java.lang.String toString()