public class ChannelAsyncOutputStream extends AbstractCloseable implements IoOutputStream, ChannelHolder
Modifier and Type | Class and Description |
---|---|
protected static class |
ChannelAsyncOutputStream.BufferedFuture
Marker type to avoid repeated buffering in
writePacket(IoWriteFutureImpl, boolean) . |
protected static class |
ChannelAsyncOutputStream.WriteState
Collects state variables; access is always synchronized on the single instance per stream.
|
AbstractCloseable.State
Modifier and Type | Field and Description |
---|---|
protected ChannelAsyncOutputStream.WriteState |
writeState
Encapsulates the state of the current write operation.
|
closeFuture, futureLock, state
log
Constructor and Description |
---|
ChannelAsyncOutputStream(Channel channel,
byte cmd) |
Modifier and Type | Method and Description |
---|---|
protected Buffer |
createSendBuffer(Buffer buffer,
Channel channel,
int length) |
protected CloseFuture |
doCloseGracefully() |
protected void |
doCloseImmediately()
doCloseImmediately is called once and only once with state == Immediate
|
protected void |
doWriteIfPossible(boolean resume) |
Channel |
getChannel() |
byte |
getCommandType() |
void |
onWindowExpanded() |
protected void |
onWritten(IoWriteFutureImpl future,
int total,
int length,
IoWriteFuture f) |
protected void |
preClose()
preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.
|
protected void |
shutdown() |
protected void |
terminateFuture(IoWriteFutureImpl future) |
String |
toString() |
IoWriteFuture |
writeBuffer(Buffer buffer)
Write the given buffer.
|
protected IoWriteFutureImpl |
writePacket(IoWriteFutureImpl future,
boolean resume)
Try to write as much of the current buffer as possible.
|
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListener
protected final ChannelAsyncOutputStream.WriteState writeState
public ChannelAsyncOutputStream(Channel channel, byte cmd)
channel
- The Channel
through which the stream is communicatingcmd
- Either SSH_MSG_CHANNEL_DATA
or
SSH_MSG_CHANNEL_EXTENDED_DATA
indicating the
output stream typepublic Channel getChannel()
getChannel
in interface ChannelHolder
Channel
instancepublic byte getCommandType()
SSH_MSG_CHANNEL_DATA
or
SSH_MSG_CHANNEL_EXTENDED_DATA
indicating the output
stream typepublic IoWriteFuture writeBuffer(Buffer buffer) throws IOException
WritePendingException
. Any subsequent write must occur only once the returned future is
fulfilled; for instance triggered via a listener on the returned future. Try to avoid doing a subsequent write
directly in a future listener, though; doing so may lead to deep chains of nested listener calls with deep stack
traces, and may ultimately lead to a stack overflow.writeBuffer
in interface IoOutputStream
buffer
- the data to write. NOTE: the buffer must not be touched until the returned write
future is completed.IoWriteFuture
that can be used to check when the data has actually been written.WritePendingException
- if a concurrent write is attemptedIOException
- if an error occurred when writing the dataprotected void preClose()
AbstractCloseable
preClose
in class AbstractCloseable
protected void doCloseImmediately()
AbstractCloseable
doCloseImmediately is called once and only once with state == Immediate
Overriding methods should always call the base implementation. It may be called concurrently while preClose() or doCloseGracefully is executing
doCloseImmediately
in class AbstractCloseable
protected void shutdown()
protected void terminateFuture(IoWriteFutureImpl future)
protected CloseFuture doCloseGracefully()
doCloseGracefully
in class AbstractCloseable
public void onWindowExpanded() throws IOException
IOException
protected void doWriteIfPossible(boolean resume)
protected IoWriteFutureImpl writePacket(IoWriteFutureImpl future, boolean resume)
future
- IoWriteFutureImpl
for the current writeresume
- whether being called in response to a remote window adjustmentnull
if all written, or if the rest will be written via a future listener. Otherwise a
future for the remaining writes.protected void onWritten(IoWriteFutureImpl future, int total, int length, IoWriteFuture f)
Copyright © 2008–2024 The Apache Software Foundation. All rights reserved.