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 Classes Modifier and Type Class Description protected static class
ChannelAsyncOutputStream.BufferedFuture
Marker type to avoid repeated buffering inwritePacket(IoWriteFutureImpl, boolean)
.protected static class
ChannelAsyncOutputStream.WriteState
Collects 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
Fields Modifier and Type Field Description protected ChannelAsyncOutputStream.WriteState
writeState
Encapsulates the state of the current write operation.-
Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, state
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
-
Constructor Summary
Constructors Constructor Description ChannelAsyncOutputStream(Channel channel, byte cmd)
ChannelAsyncOutputStream(Channel channel, byte cmd, boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Buffer
createSendBuffer(Buffer buffer, Channel channel, long length)
protected CloseFuture
doCloseGracefully()
protected void
doCloseImmediately()
protected void
doWriteIfPossible(boolean resume)
Channel
getChannel()
byte
getCommandType()
boolean
isSendChunkIfRemoteWindowIsSmallerThanPacketSize()
void
onWindowExpanded()
protected void
onWritten(IoWriteFutureImpl future, int total, long length, IoWriteFuture f)
protected void
preClose()
void
setSendChunkIfRemoteWindowIsSmallerThanPacketSize(boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize)
protected void
shutdown()
protected void
terminateFuture(IoWriteFutureImpl future)
String
toString()
IoWriteFuture
writeBuffer(Buffer 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.protected IoWriteFutureImpl
writePacket(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, removeCloseFutureListener
-
Methods 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, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
-
-
-
Field Detail
-
writeState
protected final ChannelAsyncOutputStream.WriteState 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.
-
-
Constructor Detail
-
ChannelAsyncOutputStream
public ChannelAsyncOutputStream(Channel channel, byte cmd)
- Parameters:
channel
- TheChannel
through which the stream is communicatingcmd
- EitherSSH_MSG_CHANNEL_DATA
orSSH_MSG_CHANNEL_EXTENDED_DATA
indicating the output stream type
-
ChannelAsyncOutputStream
public ChannelAsyncOutputStream(Channel channel, byte cmd, boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize)
- Parameters:
channel
- TheChannel
through which the stream is communicatingcmd
- EitherSSH_MSG_CHANNEL_DATA
orSSH_MSG_CHANNEL_EXTENDED_DATA
indicating the output stream typesendChunkIfRemoteWindowIsSmallerThanPacketSize
- Determines the chunking behaviour, if the remote window size is smaller than the packet size. Can be used to establish compatibility with certain clients, that wait until the window size is 0 before adjusting it.- See Also:
- SSHD-1123
-
-
Method Detail
-
getChannel
public Channel getChannel()
- Specified by:
getChannel
in interfaceChannelHolder
- Returns:
- The associated
Channel
instance
-
getCommandType
public byte getCommandType()
- Returns:
- Either
SSH_MSG_CHANNEL_DATA
orSSH_MSG_CHANNEL_EXTENDED_DATA
indicating the output stream type
-
writeBuffer
public IoWriteFuture writeBuffer(Buffer buffer) throws IOException
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:
writeBuffer
in interfaceIoOutputStream
- Throws:
WritePendingException
- if a concurrent write is attemptedIOException
-
preClose
protected void preClose()
- Overrides:
preClose
in classAbstractCloseable
-
doCloseImmediately
protected void doCloseImmediately()
- Overrides:
doCloseImmediately
in classAbstractCloseable
-
shutdown
protected void shutdown()
-
terminateFuture
protected void terminateFuture(IoWriteFutureImpl future)
-
doCloseGracefully
protected CloseFuture doCloseGracefully()
- Overrides:
doCloseGracefully
in classAbstractCloseable
-
onWindowExpanded
public void onWindowExpanded() throws IOException
- Throws:
IOException
-
doWriteIfPossible
protected void doWriteIfPossible(boolean resume)
-
writePacket
protected IoWriteFutureImpl writePacket(IoWriteFutureImpl future, boolean resume)
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
-IoWriteFutureImpl
for the current writeresume
- whether being called in response to a remote window adjustment- Returns:
null
if all written, or if the rest will be written via a future listener. Otherwise a future for the remaining writes.
-
onWritten
protected void onWritten(IoWriteFutureImpl future, int total, long length, IoWriteFuture f)
-
isSendChunkIfRemoteWindowIsSmallerThanPacketSize
public boolean isSendChunkIfRemoteWindowIsSmallerThanPacketSize()
-
setSendChunkIfRemoteWindowIsSmallerThanPacketSize
public void setSendChunkIfRemoteWindowIsSmallerThanPacketSize(boolean sendChunkIfRemoteWindowIsSmallerThanPacketSize)
-
-