Package org.apache.sshd.common.channel
Class ChannelAsyncOutputStream
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.util.closeable.IoBaseCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable
org.apache.sshd.common.channel.ChannelAsyncOutputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,ChannelHolder,Closeable,IoOutputStream
public class ChannelAsyncOutputStream
extends AbstractCloseable
implements IoOutputStream, ChannelHolder
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classMarker type to avoid repeated buffering inwritePacket(IoWriteFutureImpl, boolean).protected static classCollects state variables; access is always synchronized on the single instance per stream.Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Channelprivate final byteprotected final AtomicReference<IoWriteFuture> The future describing the last executed *buffer* writewriteBuffer(Buffer).private final Objectprivate final ChannelStreamWriterprotected final ChannelAsyncOutputStream.WriteStateEncapsulates the state of the current write operation.Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, stateFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanabortWrite(AbstractCloseable.State openState) protected BuffercreateSendBuffer(Buffer buffer, Channel channel, int length) protected CloseFutureprotected voiddoCloseImmediately is called once and only once with state == Immediateprotected voiddoWriteIfPossible(boolean resume) bytevoidprotected voidonWritten(IoWriteFutureImpl future, int total, int length, IoWriteFuture f) protected voidpreClose()preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.protected voidshutdown()protected voidterminateFuture(IoWriteFutureImpl future) toString()writeBuffer(Buffer buffer) Write the given buffer.protected IoWriteFutureImplwritePacket(IoWriteFutureImpl future, boolean resume) Try to write as much of the current buffer as possible.Methods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenerMethods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
Field Details
-
lastWrite
The future describing the last executed *buffer* writewriteBuffer(Buffer). Used for graceful closing. -
writeState
Encapsulates the state of the current write operation. Access is always under lock (on writeState's monitor), the lock is held only shortly and never while writing. -
channelInstance
-
packetWriter
-
cmd
private final byte cmd -
packetWriteId
-
-
Constructor Details
-
ChannelAsyncOutputStream
- Parameters:
channel- TheChannelthrough which the stream is communicatingcmd- EitherSSH_MSG_CHANNEL_DATAorSSH_MSG_CHANNEL_EXTENDED_DATAindicating the output stream type
-
-
Method Details
-
getChannel
- Specified by:
getChannelin interfaceChannelHolder- Returns:
- The associated
Channelinstance
-
getCommandType
public byte getCommandType()- Returns:
- Either
SSH_MSG_CHANNEL_DATAorSSH_MSG_CHANNEL_EXTENDED_DATAindicating the output stream type
-
writeBuffer
Write the given buffer. This write operation is asynchronous: if there is not enough window space, it may keep the write pending or write only part of the buffer and keep the rest pending. Concurrent writes are not allowed and will throw aWritePendingException. 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.- Specified by:
writeBufferin interfaceIoOutputStream- Parameters:
buffer- the data to write. NOTE: the buffer must not be touched until the returned write future is completed.- Returns:
- An
IoWriteFuturethat can be used to check when the data has actually been written. - Throws:
WritePendingException- if a concurrent write is attemptedIOException- if an error occurred when writing the data
-
preClose
protected void preClose()Description copied from class:AbstractCloseablepreClose is guaranteed to be called before doCloseGracefully or doCloseImmediately. When preClose() is called, isClosing() == true- Overrides:
preClosein classAbstractCloseable
-
doCloseImmediately
protected void doCloseImmediately()Description copied from class:AbstractCloseabledoCloseImmediately 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
- Overrides:
doCloseImmediatelyin classAbstractCloseable
-
shutdown
protected void shutdown() -
terminateFuture
-
doCloseGracefully
- Overrides:
doCloseGracefullyin classAbstractCloseable
-
onWindowExpanded
- Throws:
IOException
-
doWriteIfPossible
protected void doWriteIfPossible(boolean resume) -
abortWrite
-
writePacket
Try to write as much of the current buffer as possible. If the buffer is larger than the packet size split it in packets, writing one after the other by chaining futures. If there is not enough window space, stop writing. Writing will be resumed once the window has been enlarged again.- Parameters:
future-IoWriteFutureImplfor the current writeresume- whether being called in response to a remote window adjustment- Returns:
nullif all written, or if the rest will be written via a future listener. Otherwise a future for the remaining writes.
-
onWritten
-
createSendBuffer
-
toString
-