Top Inners Fields Constructors Methods
org.apache.sshd.common.channel

public Class ChannelAsyncOutputStream

extends AbstractCloseable
implements IoOutputStream, ChannelHolder
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.channel.ChannelHolder, org.apache.sshd.common.io.IoOutputStream, org.apache.sshd.common.Closeable, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.EOFException, .IOException, java.util.Objects, java.util.concurrent.atomic.AtomicReference, org.apache.sshd.common.SshConstants, org.apache.sshd.common.channel.throttle.ChannelStreamWriter, org.apache.sshd.common.future.CloseFuture, org.apache.sshd.common.io.IoOutputStream, .IoWriteFuture, .WritePendingException, org.apache.sshd.common.session.Session, .SessionContext, org.apache.sshd.common.session.helpers.PacketBuffer, org.apache.sshd.common.util.buffer.Buffer, .ByteArrayBuffer, org.apache.sshd.common.util.closeable.AbstractCloseable

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
protected static class
ChannelAsyncOutputStream.WriteState

Collects state variables; access is always synchronized on the single instance per stream.

Field Summary

Modifier and TypeField and Description
private final Channel
private final byte
protected final AtomicReference<IoWriteFuture>
lastWrite

The future describing the last executed *buffer* write ChannelAsyncOutputStream#writeBuffer(Buffer).

private final Object
private final ChannelStreamWriter
protected final ChannelAsyncOutputStream.WriteState
writeState

Encapsulates the state of the current write operation.

Inherited from org.apache.sshd.common.util.closeable.AbstractCloseable:
closeFuturefutureLockstate

Constructor Summary

AccessConstructor and Description
public
ChannelAsyncOutputStream(Channel
The Channel through which the stream is communicating
channel
,
byte
Either SSH_MSG_CHANNEL_DATA or SSH_MSG_CHANNEL_EXTENDED_DATA indicating the output stream type
cmd
)

Method Summary

Modifier and TypeMethod and Description
private boolean
protected Buffer
createSendBuffer(Buffer buffer, Channel channel, int length)

protected CloseFuture
protected void
doCloseImmediately()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.doCloseImmediately.

doCloseImmediately is called once and only once with state == Immediate Overriding methods should always call the base implementation.

protected void
doWriteIfPossible(boolean resume)

public Channel
public byte

Returns:

Either SSH_MSG_CHANNEL_DATA or SSH_MSG_CHANNEL_EXTENDED_DATA indicating the output stream type
getCommandType
()

public void
protected void
onWritten(IoWriteFutureImpl future, int total, int length, IoWriteFuture f)

protected void
preClose()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.preClose.

preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.

protected void
protected void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public IoWriteFuture
writeBuffer(Buffer
the data to write

Note

the buffer must not be touched until the returned write future is completed.

buffer
)

Implements org.apache.sshd.common.io.IoOutputStream.writeBuffer.

Write the given buffer.

protected IoWriteFutureImpl

Returns:

null if all written, or if the rest will be written via a future listener. Otherwise a future for the remaining writes.
writePacket
(IoWriteFutureImpl
IoWriteFutureImpl for the current write
future
,
boolean
whether being called in response to a remote window adjustment
resume
)

Try to write as much of the current buffer as possible.

Inherited from org.apache.sshd.common.util.closeable.AbstractCloseable:
addCloseFutureListenerbuilderclosegetFutureLockisClosedisClosingremoveCloseFutureListener

Field Detail

channelInstanceback to summary
private final Channel channelInstance
cmdback to summary
private final byte cmd
lastWriteback to summary
protected final AtomicReference<IoWriteFuture> lastWrite

The future describing the last executed *buffer* write ChannelAsyncOutputStream#writeBuffer(Buffer). Used for graceful closing.

packetWriteIdback to summary
private final Object packetWriteId
packetWriterback to summary
private final ChannelStreamWriter packetWriter
writeStateback to summary
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

ChannelAsyncOutputStreamback to summary
public ChannelAsyncOutputStream(Channel channel, byte cmd)
Parameters
channel:Channel

The Channel through which the stream is communicating

cmd:byte

Either SSH_MSG_CHANNEL_DATA or SSH_MSG_CHANNEL_EXTENDED_DATA indicating the output stream type

Method Detail

abortWriteback to summary
private boolean abortWrite(AbstractCloseable.State openState)
createSendBufferback to summary
protected Buffer createSendBuffer(Buffer buffer, Channel channel, int length)
doCloseGracefullyback to summary
protected CloseFuture doCloseGracefully()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.doCloseGracefully.

Annotations
@Override
doCloseImmediatelyback to summary
protected void doCloseImmediately()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.doCloseImmediately.

Doc from org.apache.sshd.common.util.closeable.AbstractCloseable.doCloseImmediately.

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

Annotations
@Override
doWriteIfPossibleback to summary
protected void doWriteIfPossible(boolean resume)
getChannelback to summary
public Channel getChannel()

Implements org.apache.sshd.common.channel.ChannelHolder.getChannel.

Returns:Channel

Doc from org.apache.sshd.common.channel.ChannelHolder.getChannel.

The associated Channel instance

Annotations
@Override
getCommandTypeback to summary
public byte getCommandType()
Returns:byte

Either SSH_MSG_CHANNEL_DATA or SSH_MSG_CHANNEL_EXTENDED_DATA indicating the output stream type

onWindowExpandedback to summary
public void onWindowExpanded() throws IOException
onWrittenback to summary
protected void onWritten(IoWriteFutureImpl future, int total, int length, IoWriteFuture f)
preCloseback to summary
protected void preClose()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.preClose.

Doc from org.apache.sshd.common.util.closeable.AbstractCloseable.preClose.

preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately. When preClose() is called, isClosing() == true

Annotations
@Override
shutdownback to summary
protected void shutdown()
terminateFutureback to summary
protected void terminateFuture(IoWriteFutureImpl future)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
writeBufferback to summary
public IoWriteFuture writeBuffer(Buffer buffer) throws IOException

Implements org.apache.sshd.common.io.IoOutputStream.writeBuffer.

Doc from org.apache.sshd.common.io.IoOutputStream.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 a 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.

Parameters
buffer:Buffer

the data to write

Note

the buffer must not be touched until the returned write future is completed.

Returns:IoWriteFuture

An IoWriteFuture that can be used to check when the data has actually been written.

Annotations
@Override
Exceptions
IOException:
if an error occurred when writing the data
WritePendingException:
if a concurrent write is attempted
writePacketback to summary
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

IoWriteFutureImpl for the current write

resume:boolean

whether being called in response to a remote window adjustment

Returns:IoWriteFutureImpl

null if all written, or if the rest will be written via a future listener. Otherwise a future for the remaining writes.

org.apache.sshd.common.channel back to summary

protected Class ChannelAsyncOutputStream.BufferedFuture

extends IoWriteFutureImpl
Class Inheritance

Marker type to avoid repeated buffering in ChannelAsyncOutputStream#writePacket(IoWriteFutureImpl, boolean).

Field Summary

Modifier and TypeField and Description
protected boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from org.apache.sshd.common.channel.IoWriteFutureImpl:
getBuffer

Field Detail

waitOnWindowback to summary
protected boolean waitOnWindow

Constructor Detail

BufferedFutureback to summary
pack-priv BufferedFuture(Object id, Buffer buffer)
org.apache.sshd.common.channel back to summary

protected Class ChannelAsyncOutputStream.WriteState

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.sshd.common.channel.ChannelAsyncOutputStream.WriteState

Collects state variables; access is always synchronized on the single instance per stream.

Field Summary

Modifier and TypeField and Description
protected AbstractCloseable.State
openState

A copy of this stream's state as set by the superclass.

protected IoWriteFutureImpl
pendingWrite

The future describing the current packet write; if null, there is nothing to write or ChannelAsyncOutputStream#writePacket(IoWriteFutureImpl, boolean) is running.

protected int
toSend

Number of bytes still to send.

protected int
totalLength

Number of bytes to send in total.

protected boolean
windowExpanded

Set to true when there was a remote window expansion while ChannelAsyncOutputStream#writePacket(IoWriteFutureImpl, boolean) was in progress.

protected boolean
writeInProgress

Flag to throw an exception if non-sequential ChannelAsyncOutputStream#writeBuffer(Buffer) calls should occur.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

openStateback to summary
protected AbstractCloseable.State openState

A copy of this stream's state as set by the superclass.

pendingWriteback to summary
protected IoWriteFutureImpl pendingWrite

The future describing the current packet write; if null, there is nothing to write or ChannelAsyncOutputStream#writePacket(IoWriteFutureImpl, boolean) is running.

toSendback to summary
protected int toSend

Number of bytes still to send.

totalLengthback to summary
protected int totalLength

Number of bytes to send in total.

windowExpandedback to summary
protected boolean windowExpanded

Set to true when there was a remote window expansion while ChannelAsyncOutputStream#writePacket(IoWriteFutureImpl, boolean) was in progress. If set, ChannelAsyncOutputStream#doWriteIfPossible(boolean) will run a ChannelAsyncOutputStream#writePacket(IoWriteFutureImpl, boolean) again.

writeInProgressback to summary
protected boolean writeInProgress

Flag to throw an exception if non-sequential ChannelAsyncOutputStream#writeBuffer(Buffer) calls should occur.

Constructor Detail

WriteStateback to summary
protected WriteState()