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

public abstract Class AbstractChannel

extends AbstractInnerCloseable
implements Channel, ExecutorServiceCarrier
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.util.threads.ExecutorServiceCarrier, org.apache.sshd.common.channel.Channel, org.apache.sshd.common.Closeable, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager, org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver, org.apache.sshd.common.AttributeStore, org.apache.sshd.common.AttributeRepository, org.apache.sshd.common.PropertyResolver, org.apache.sshd.common.channel.ChannelListenerManager, org.apache.sshd.common.channel.ChannelIdentifier, org.apache.sshd.common.session.SessionHolder, org.apache.sshd.common.session.SessionContextHolder
Known Direct Subclasses
org.apache.sshd.server.channel.AbstractServerChannel, org.apache.sshd.client.channel.AbstractClientChannel
Imports
java.io.EOFException, .IOException, java.time.Duration, java.util.Collection, .Collections, .Date, .HashSet, .List, .Map, .Objects, java.util.concurrent.ConcurrentHashMap, .CopyOnWriteArrayList, .CopyOnWriteArraySet, java.util.concurrent.atomic.AtomicBoolean, .AtomicReference, java.util.function.Function, .IntUnaryOperator, org.apache.sshd.common.AttributeRepository, .Closeable, .FactoryManager, .PropertyResolver, .SshConstants, org.apache.sshd.common.channel.exception.SshChannelInvalidPacketException, org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver, .ChannelStreamWriterResolverManager, org.apache.sshd.common.future.CloseFuture, .DefaultCloseFuture, .SshFutureListener, org.apache.sshd.common.io.AbstractIoWriteFuture, .IoWriteFuture, org.apache.sshd.common.session.ConnectionService, .Session, org.apache.sshd.common.util.EventListenerUtils, .ExceptionUtils, .GenericUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.Buffer, .BufferUtils, org.apache.sshd.common.util.closeable.AbstractInnerCloseable, .IoBaseCloseable, .SimpleCloseable, org.apache.sshd.common.util.functors.Int2IntFunction, org.apache.sshd.common.util.io.IoUtils, org.apache.sshd.common.util.io.functors.Invoker, org.apache.sshd.common.util.threads.CloseableExecutorService, .ExecutorServiceCarrier, org.apache.sshd.core.CoreModuleProperties

Provides common client/server channel functionality
Author
Apache MINA SSHD Project

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
protected static enum
public static interface
AbstractChannel.PacketValidator

A PacketValidator can validate packet lengths.

Field Summary

Modifier and TypeField and Description
private final Map<AttributeRepository.AttributeKey<?>, Object>
protected final ChannelListener
protected final Collection<ChannelListener>
channelListeners

Channel events listener

private ChannelStreamWriterResolver
protected final AtomicBoolean
public static final AbstractChannel.PacketValidator
DEFAULT_PACKET_VALIDATOR

A default PacketValidator that enforces that the packet size is not greater than the maximum packet size of the channel's local window.

private AtomicReference<IoWriteFuture>
protected final AtomicBoolean
protected final AtomicBoolean
eofSent

Deprecated since 2.10.1
Obsolete and unused; present only for API backwards compatibility.
private CloseableExecutorService
protected final DefaultCloseFuture
protected AtomicReference<AbstractChannel.GracefulState>
private long
protected final AtomicBoolean
private final LocalWindow
private AbstractChannel.PacketValidator
private final Map<String, Date>
pendingRequests

A Map of sent requests - key = request name, value = timestamp when request was sent.

private final Map<String, Object>
private long
private final RemoteWindow
private final List<RequestHandler<Channel>>
public static final IntUnaryOperator
RESPONSE_BUFFER_GROWTH_FACTOR

Default growth factor function used to resize response buffers

protected ConnectionService
private Session
protected final AtomicBoolean

Constructor Summary

AccessConstructor and Description
protected
AbstractChannel(boolean client)

protected
AbstractChannel(boolean client, Collection<? extends RequestHandler<Channel>> handlers)

protected
AbstractChannel(String discriminator, boolean client)

protected
AbstractChannel(String discriminator, boolean client, Collection<? extends RequestHandler<Channel>> handlers, CloseableExecutorService executorService)

Method Summary

Modifier and TypeMethod and Description
public void
protected Date

Returns:

The allocated Date timestamp - null if no reply is expected (in which case the request is not tracked)
addPendingRequest
(String
The request type
request
,
boolean
true if reply is expected
wantReply
)

Add a channel request to the tracked pending ones if reply is expected

public void
public Collection<AttributeRepository.AttributeKey<?>>
public void
clearAttributes()

Implements org.apache.sshd.common.AttributeStore.clearAttributes.

Removes all currently stored user-defined attributes

public <T> T
computeAttributeIfAbsent(AttributeRepository.AttributeKey<T>
The key of the attribute; must not be null.
key
,
Function<? super AttributeRepository.AttributeKey<T>, ? extends T>
The (never null) mapping function to use if value not already mapped. If returns null then value is not mapped to the provided key.
resolver
)

Overrides default org.apache.sshd.common.AttributeStore.computeAttributeIfAbsent.

If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.

protected void
protected abstract void
doWriteData(byte[] data, int off, long len)

protected abstract void
doWriteExtendedData(byte[] data, int off, long len)

public <T> T
getAttribute(AttributeRepository.AttributeKey<T>
The key of the attribute; must not be null.
key
)

Implements org.apache.sshd.common.AttributeRepository.getAttribute.

Returns the value of the user-defined attribute.

public int
public long
public ChannelListener
public ChannelStreamWriterResolver
public CloseableExecutorService
protected Closeable
public LocalWindow
public AbstractChannel.PacketValidator

Returns:

the validator, never null
getPacketValidator
()

Retrieves the currently set PacketValidator.

public PropertyResolver
public Map<String, Object>
getProperties()

Implements org.apache.sshd.common.PropertyResolver.getProperties.

A map of properties that can be used to configure the SSH server or client.

public long
public RemoteWindow
public List<RequestHandler<Channel>>
public Session
public void
handleChannelRegistrationResult(ConnectionService
The ConnectionService through which the channel is registered
service
,
Session
The Session associated with the channel
session
,
long
The locally assigned channel identifier (UINT32 represented as a long)
channelId
,
boolean
Whether registration was successful or not
registered
)

Implements org.apache.sshd.common.channel.Channel.handleChannelRegistrationResult.

Invoked after being successfully registered by the connection service - should throw a RuntimeException if not registered

protected void
handleChannelRequest(String req, boolean wantReply, Buffer buffer)

public void
handleChannelUnregistration(ConnectionService
The ConnectionService through which the channel is unregistered
service
)

Implements org.apache.sshd.common.channel.Channel.handleChannelUnregistration.

Called by the connection service to inform the channel that it has bee unregistered.

public void
handleClose()

Implements org.apache.sshd.common.channel.Channel.handleClose.

Invoked when SSH_MSG_CHANNEL_CLOSE received

public void
handleData(Buffer
The rest of the message data Buffer after decoding the channel identifiers
buffer
)

Implements org.apache.sshd.common.channel.Channel.handleData.

Invoked when SSH_MSG_CHANNEL_DATA received

public void
handleEof()

Implements org.apache.sshd.common.channel.Channel.handleEof.

Invoked when SSH_MSG_CHANNEL_EOF received

public void
handleExtendedData(Buffer
The rest of the message data Buffer after decoding the channel identifiers
buffer
)

Implements org.apache.sshd.common.channel.Channel.handleExtendedData.

Invoked when SSH_MSG_CHANNEL_EXTENDED_DATA received

public void
handleFailure()

Implements org.apache.sshd.common.channel.Channel.handleFailure.

Invoked when SSH_MSG_CHANNEL_FAILURE received

protected RequestHandler.Result

Returns:

The handling result - if null or Unsupported and reply is required then a failure message will be sent
handleInternalRequest
(String
The request type
req
,
boolean
Whether reply is requested
wantReply
,
Buffer
The Buffer containing extra request-specific data
buffer
)

Called by handleUnknownChannelRequest(String, boolean, Buffer) in order to allow channel request handling if none of the registered handlers processed the request - last chance.

public void
handleRequest(Buffer
The rest of the message data Buffer after decoding the channel identifiers
buffer
)

Implements org.apache.sshd.common.channel.Channel.handleRequest.

Invoked when SSH_MSG_CHANNEL_REQUEST received

public void
handleSuccess()

Implements org.apache.sshd.common.channel.Channel.handleSuccess.

Invoked when SSH_MSG_CHANNEL_SUCCESS received

protected void
handleUnknownChannelRequest(String
The request type
req
,
boolean
Whether reply is requested
wantReply
,
Buffer
The Buffer containing extra request-specific data
buffer
)

Called when none of the register request handlers reported handling the request

public void
handleWindowAdjust(Buffer
The rest of the message data Buffer after decoding the channel identifiers
buffer
)

Implements org.apache.sshd.common.channel.Channel.handleWindowAdjust.

Invoked when SSH_MSG_CHANNEL_WINDOW_ADJUST received

public void
init(ConnectionService
The ConnectionService through which the channel is initialized
service
,
Session
The Session associated with the channel
session
,
long
The locally assigned channel identifier (UINT32 represented as a long)
id
)

Implements org.apache.sshd.common.channel.Channel.init.

Invoked when the local channel is initial created

protected void
public boolean
public boolean
public boolean
protected boolean
protected void
protected void
protected void
preClose()

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

preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.

public <T> T
removeAttribute(AttributeRepository.AttributeKey<T>
The key of the attribute; must not be null.
key
)

Implements org.apache.sshd.common.AttributeStore.removeAttribute.

Removes the user-defined attribute

public void
protected Date

Returns:

The allocated Date timestamp - null if the specified request type is not being tracked or has not been added to the tracked ones to begin with
removePendingRequest
(String
The request type
request
)

Removes a channel request from the tracked ones

public void
public ChannelStreamWriterResolver
protected IoWriteFuture

Returns:

The IoWriteFuture of the sent packet - null if message not sent due to channel state (or already sent)
sendEof
()

Sends SSH_MSG_CHANNEL_EOF provided not already sent and current channel state allows it.

protected IoWriteFuture
sendResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply)

protected void
sendWindowAdjust(long len)

public <T> T
setAttribute(AttributeRepository.AttributeKey<T>
The key of the attribute; must not be null.
key
,
T
The value of the attribute; must not be null.
value
)

Implements org.apache.sshd.common.AttributeStore.setAttribute.

Sets a user-defined attribute.

public void
public void
setPacketValidator(AbstractChannel.PacketValidator
the validator to set, if null the DEFAULT_PACKET_VALIDATOR is set
validator
)

Sets a PacketValidator.

protected void
setRecipient(long recipient)

public void
protected void
protected void
protected void
protected void
protected void
protected void
protected void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

protected long
validateIncomingDataSize(int cmd, long len)

public IoWriteFuture
writePacket(Buffer
the buffer to encode and send

Note

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

buffer
)

Implements org.apache.sshd.common.channel.Channel.writePacket.

Encode and send the given buffer

Note

for session packets the buffer has to have 5 bytes free at the beginning to allow the encoding to take place.

Inherited from org.apache.sshd.common.util.closeable.AbstractInnerCloseable:
doCloseGracefullydoCloseImmediately