public abstract class WriteFlusher extends Object
EndPoint.write(Callback, ByteBuffer...)
by calling
EndPoint.flush(ByteBuffer...)
until all content is written.
The abstract method onIncompleteFlushed()
is called when not all content has been written after a call to
flush and should organise for the completeWrite()
method to be called when a subsequent call to flush
should be able to make more progress.
Modifier | Constructor and Description |
---|---|
protected |
WriteFlusher(EndPoint endPoint) |
Modifier and Type | Method and Description |
---|---|
void |
completeWrite()
Complete a write that has not completed and that called
onIncompleteFlushed() to request a call to this
method when a call to EndPoint.flush(ByteBuffer...) is likely to be able to progress. |
protected ByteBuffer[] |
flush(ByteBuffer[] buffers)
Flush the buffers iteratively until no progress is made
|
boolean |
isInProgress() |
void |
onClose() |
boolean |
onFail(Throwable cause)
Notify the flusher of a failure
|
protected abstract void |
onIncompleteFlushed()
Abstract call to be implemented by specific WriteFlushers.
|
String |
toString() |
void |
write(Callback callback,
ByteBuffer... buffers)
Tries to switch state to WRITING.
|
protected WriteFlusher(EndPoint endPoint)
protected abstract void onIncompleteFlushed()
completeWrite()
or onFail(Throwable)
when appropriate.public void write(Callback callback, ByteBuffer... buffers) throws WritePendingException
PendingState
object to preserve the state
and then calls onIncompleteFlushed()
. 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 completebuffers
- the buffers to flush to the endpointWritePendingException
public void completeWrite()
onIncompleteFlushed()
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
onFail(Throwable)
or onClose()
protected ByteBuffer[] flush(ByteBuffer[] buffers) throws IOException
buffers
- The buffers to flushIOException
public boolean onFail(Throwable cause)
cause
- The cause of the failureCallback
instancepublic void onClose()
public boolean isInProgress()
Copyright © 1995-2015 Webtide. All Rights Reserved.