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

public Interface Channel

extends SessionHolder<Session>, ChannelIdentifier, ChannelListenerManager, PropertyResolver, AttributeStore, ChannelStreamWriterResolverManager, Closeable
Known Direct Subinterfaces
org.apache.sshd.server.channel.ServerChannel, org.apache.sshd.client.channel.ClientChannel
Known Direct Implementers
org.apache.sshd.common.channel.AbstractChannel
Imports
java.io.IOException, java.util.Collection, .List, .Objects, org.apache.sshd.client.future.OpenFuture, org.apache.sshd.common.AttributeRepository, .AttributeStore, .Closeable, .PropertyResolver, org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager, org.apache.sshd.common.io.IoWriteFuture, org.apache.sshd.common.session.ConnectionService, .Session, .SessionHolder, org.apache.sshd.common.util.GenericUtils, org.apache.sshd.common.util.buffer.Buffer

Represents a channel opened over an SSH session - holds information that is common both to server and client channels.
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
Inherited from org.apache.sshd.common.PropertyResolver:
EMPTY

Method Summary

Modifier and TypeMethod and Description
public void
public default void
public LocalWindow
public long

Returns:

Remote channel UITN32 identifier
getRecipient
()

public RemoteWindow
public List<RequestHandler<Channel>>
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)
id
,
boolean
Whether registration was successful or not
registered
)

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

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

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

public void
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
)

Invoked when SSH_MSG_CHANNEL_DATA received

public void
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
)

Invoked when SSH_MSG_CHANNEL_EXTENDED_DATA received

public void
handleFailure()

Invoked when SSH_MSG_CHANNEL_FAILURE received

public void
handleOpenFailure(Buffer
Incoming Buffer that triggered the call

Note

the buffer's read position is exactly after the information that read to this call was decoded

buffer
)

For a client channel, this method will be called internally by the session when the server has rejected this channel opening.

public void
handleOpenSuccess(long
Recipient identifier (UINT32 represented as a long)
recipient
,
long
Read/Write window size (uint32)
rwSize
,
long
Preferred maximum packet size (uint32)
packetSize
,
Buffer
Incoming Buffer that triggered the call

Note

the buffer's read position is exactly after the information that read to this call was decoded

buffer
)

For a client channel, this method will be called internally by the session when the confirmation has been received.

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

Invoked when SSH_MSG_CHANNEL_REQUEST received

public void
handleSuccess()

Invoked when SSH_MSG_CHANNEL_SUCCESS received

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

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
)

Invoked when the local channel is initial created

public boolean

Returns:

true if the peer signaled that it will not send any more data
isEofSignalled
()

public boolean

Returns:

true if call to init(ConnectionService, Session, long) was successfully completed
isInitialized
()

public OpenFuture

Returns:

An OpenFuture for the channel open request
open
(long
Recipient identifier (UINT32 represented as a long)
recipient
,
long
Read/Write window size (uint32)
rwSize
,
long
Preferred maximum packet size (uint32)
packetSize
,
Buffer
Incoming Buffer that triggered the call

Note

the buffer's read position is exactly after the information that read to this call was decoded

buffer
)

For a server channel, this method will actually open the channel

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

Overrides default org.apache.sshd.common.AttributeRepository.resolveAttribute.

Attempts to resolve the associated value by going up the store's hierarchy (if any)

public static <
The generic attribute type
T
>
T

Returns:

Associated value - null if not found
resolveAttribute
(Channel
The Channel - ignored if null
channel
,
AttributeRepository.AttributeKey<T>
The attribute key - never null
key
)

Attempts to use the channel attribute, if not found then tries the session

public IoWriteFuture

Returns:

An IoWriteFuture that can be used to check when the packet has actually been sent
writePacket
(Buffer
the buffer to encode and send

Note

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

buffer
)

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.AttributeStore:
clearAttributescomputeAttributeIfAbsentremoveAttributesetAttribute
Inherited from org.apache.sshd.common.channel.ChannelIdentifier:
getChannelId
Inherited from org.apache.sshd.common.channel.ChannelListenerManager:
addChannelListenergetChannelListenerProxyremoveChannelListener
Inherited from org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager:
getChannelStreamWriterResolverresolveChannelStreamWriterresolveChannelStreamWriterResolversetChannelStreamWriterResolver
Inherited from org.apache.sshd.common.Closeable:
addCloseFutureListenerclosecloseclosegetMaxCloseWaitTimeisClosedisClosingisOpenremoveCloseFutureListener
Inherited from org.apache.sshd.common.PropertyResolver:
getBooleangetBooleanPropertygetCharsetgetIntegergetIntPropertygetLonggetLongPropertygetObjectgetParentPropertyResolvergetPropertiesgetStringgetStringPropertyisEmptyisEmpty
Inherited from org.apache.sshd.common.session.SessionHolder:
getSessiongetSessionContext

Field Detail

CHANNEL_EXECback to summary
public static final String CHANNEL_EXEC
CHANNEL_SHELLback to summary
public static final String CHANNEL_SHELL
CHANNEL_SUBSYSTEMback to summary
public static final String CHANNEL_SUBSYSTEM

Method Detail

addRequestHandlerback to summary
public void addRequestHandler(RequestHandler<Channel> handler)
addRequestHandlersback to summary
public default void addRequestHandlers(Collection<? extends RequestHandler<Channel>> handlers)
getLocalWindowback to summary
public LocalWindow getLocalWindow()
getRecipientback to summary
public long getRecipient()
Returns:long

Remote channel UITN32 identifier

getRemoteWindowback to summary
public RemoteWindow getRemoteWindow()
getRequestHandlersback to summary
public List<RequestHandler<Channel>> getRequestHandlers()
handleChannelRegistrationResultback to summary
public void handleChannelRegistrationResult(ConnectionService service, Session session, long id, boolean registered)

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

Parameters
service:ConnectionService

The ConnectionService through which the channel is registered

session:Session

The Session associated with the channel

id:long

The locally assigned channel identifier (UINT32 represented as a long)

registered:boolean

Whether registration was successful or not

handleChannelUnregistrationback to summary
public void handleChannelUnregistration(ConnectionService service)

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

Parameters
service:ConnectionService

The ConnectionService through which the channel is unregistered

handleCloseback to summary
public void handleClose() throws IOException

Invoked when SSH_MSG_CHANNEL_CLOSE received

Exceptions
IOException:
If failed to handle the message
handleDataback to summary
public void handleData(Buffer buffer) throws IOException

Invoked when SSH_MSG_CHANNEL_DATA received

Parameters
buffer:Buffer

The rest of the message data Buffer after decoding the channel identifiers

Exceptions
IOException:
If failed to handle the message
handleEofback to summary
public void handleEof() throws IOException

Invoked when SSH_MSG_CHANNEL_EOF received

Exceptions
IOException:
If failed to handle the message
handleExtendedDataback to summary
public void handleExtendedData(Buffer buffer) throws IOException

Invoked when SSH_MSG_CHANNEL_EXTENDED_DATA received

Parameters
buffer:Buffer

The rest of the message data Buffer after decoding the channel identifiers

Exceptions
IOException:
If failed to handle the message
handleFailureback to summary
public void handleFailure() throws IOException

Invoked when SSH_MSG_CHANNEL_FAILURE received

Exceptions
IOException:
If failed to handle the message
handleOpenFailureback to summary
public void handleOpenFailure(Buffer buffer) throws IOException

For a client channel, this method will be called internally by the session when the server has rejected this channel opening.

Parameters
buffer:Buffer

Incoming Buffer that triggered the call

Note

the buffer's read position is exactly after the information that read to this call was decoded

Exceptions
IOException:
If failed to handle the success
handleOpenSuccessback to summary
public void handleOpenSuccess(long recipient, long rwSize, long packetSize, Buffer buffer) throws IOException

For a client channel, this method will be called internally by the session when the confirmation has been received.

Parameters
recipient:long

Recipient identifier (UINT32 represented as a long)

rwSize:long

Read/Write window size (uint32)

packetSize:long

Preferred maximum packet size (uint32)

buffer:Buffer

Incoming Buffer that triggered the call

Note

the buffer's read position is exactly after the information that read to this call was decoded

Exceptions
IOException:
If failed to handle the success
handleRequestback to summary
public void handleRequest(Buffer buffer) throws IOException

Invoked when SSH_MSG_CHANNEL_REQUEST received

Parameters
buffer:Buffer

The rest of the message data Buffer after decoding the channel identifiers

Exceptions
IOException:
If failed to handle the message
handleSuccessback to summary
public void handleSuccess() throws IOException

Invoked when SSH_MSG_CHANNEL_SUCCESS received

Exceptions
IOException:
If failed to handle the message
handleWindowAdjustback to summary
public void handleWindowAdjust(Buffer buffer) throws IOException

Invoked when SSH_MSG_CHANNEL_WINDOW_ADJUST received

Parameters
buffer:Buffer

The rest of the message data Buffer after decoding the channel identifiers

Exceptions
IOException:
If failed to handle the message
initback to summary
public void init(ConnectionService service, Session session, long id) throws IOException

Invoked when the local channel is initial created

Parameters
service:ConnectionService

The ConnectionService through which the channel is initialized

session:Session

The Session associated with the channel

id:long

The locally assigned channel identifier (UINT32 represented as a long)

Exceptions
IOException:
If failed to process the initialization
isEofSignalledback to summary
public boolean isEofSignalled()
Returns:boolean

true if the peer signaled that it will not send any more data

See Also
RFC 4254 - section 5.3 - SSH_MSG_CHANNEL_EOF
isInitializedback to summary
public boolean isInitialized()
Returns:boolean

true if call to init(ConnectionService, Session, long) was successfully completed

openback to summary
public OpenFuture open(long recipient, long rwSize, long packetSize, Buffer buffer)

For a server channel, this method will actually open the channel

Parameters
recipient:long

Recipient identifier (UINT32 represented as a long)

rwSize:long

Read/Write window size (uint32)

packetSize:long

Preferred maximum packet size (uint32)

buffer:Buffer

Incoming Buffer that triggered the call

Note

the buffer's read position is exactly after the information that read to this call was decoded

Returns:OpenFuture

An OpenFuture for the channel open request

removeRequestHandlerback to summary
public void removeRequestHandler(RequestHandler<Channel> handler)
removeRequestHandlersback to summary
public default void removeRequestHandlers(Collection<? extends RequestHandler<Channel>> handlers)
resolveAttributeback to summary
public default <T> T resolveAttribute(AttributeRepository.AttributeKey<T> key)

Overrides default org.apache.sshd.common.AttributeRepository.resolveAttribute.

Doc from org.apache.sshd.common.AttributeRepository.resolveAttribute.

Attempts to resolve the associated value by going up the store's hierarchy (if any)

Parameters
<T>
The generic attribute type
key:AttributeRepository.AttributeKey<T>

The key of the attribute; must not be null.

Returns:T

null if there is no value associated with the specified key either in this repository or any of its ancestors (if any available)

Annotations
@Override
resolveAttributeback to summary
public static <T> T resolveAttribute(Channel channel, AttributeRepository.AttributeKey<T> key)

Attempts to use the channel attribute, if not found then tries the session

Parameters
<T>
The generic attribute type
channel:Channel

The Channel - ignored if null

key:AttributeRepository.AttributeKey<T>

The attribute key - never null

Returns:T

Associated value - null if not found

See Also
getSession(), Session#resolveAttribute(Session, AttributeRepository.AttributeKey)
writePacketback to summary
public IoWriteFuture writePacket(Buffer buffer) throws IOException

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. Also, the write position of the buffer has to be set to the position of the last byte to write.

Parameters
buffer:Buffer

the buffer to encode and send

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 packet has actually been sent

Exceptions
IOException:
if an error occurred when encoding or sending the packet