Package org.apache.sshd.common.channel
Interface Channel
-
- All Superinterfaces:
AttributeRepository,AttributeStore,java.lang.AutoCloseable,java.nio.channels.Channel,ChannelIdentifier,ChannelListenerManager,ChannelStreamWriterResolver,ChannelStreamWriterResolverManager,java.io.Closeable,Closeable,PropertyResolver,SessionContextHolder,SessionHolder<Session>
- All Known Subinterfaces:
ClientChannel,ServerChannel
- All Known Implementing Classes:
AbstractChannel,AbstractClientChannel,AbstractServerChannel,AgentForwardedChannel,AgentForwardedChannel,AsyncCapableClientChannel,ChannelAgentForwarding,ChannelAgentForwarding,ChannelDirectTcpip,ChannelExec,ChannelForwardedX11,ChannelSession,ChannelSession,ChannelShell,ChannelSubsystem,DefaultSftpClient.SftpChannelSubsystem,PtyCapableChannelSession,TcpipClientChannel,TcpipServerChannel
public interface Channel extends SessionHolder<Session>, ChannelIdentifier, ChannelListenerManager, PropertyResolver, AttributeStore, ChannelStreamWriterResolverManager, Closeable
Represents a channel opened over an SSH session - holds information that is common both to server and client channels.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCHANNEL_EXECstatic java.lang.StringCHANNEL_SHELLstatic java.lang.StringCHANNEL_SUBSYSTEM-
Fields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONE
-
Fields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddRequestHandler(RequestHandler<Channel> handler)default voidaddRequestHandlers(java.util.Collection<? extends RequestHandler<Channel>> handlers)LocalWindowgetLocalWindow()longgetRecipient()RemoteWindowgetRemoteWindow()java.util.List<RequestHandler<Channel>>getRequestHandlers()voidhandleChannelRegistrationResult(ConnectionService service, Session session, long id, boolean registered)Invoked after being successfully registered by the connection service - should throw aRuntimeExceptionif not registeredvoidhandleChannelUnregistration(ConnectionService service)Called by the connection service to inform the channel that it has bee unregistered.voidhandleClose()Invoked whenSSH_MSG_CHANNEL_CLOSEreceivedvoidhandleData(Buffer buffer)Invoked whenSSH_MSG_CHANNEL_DATAreceivedvoidhandleEof()Invoked whenSSH_MSG_CHANNEL_EOFreceivedvoidhandleExtendedData(Buffer buffer)Invoked whenSSH_MSG_CHANNEL_EXTENDED_DATAreceivedvoidhandleFailure()Invoked whenSSH_MSG_CHANNEL_FAILUREreceivedvoidhandleOpenFailure(Buffer buffer)For a client channel, this method will be called internally by the session when the server has rejected this channel opening.voidhandleOpenSuccess(long recipient, long rwSize, long packetSize, Buffer buffer)For a client channel, this method will be called internally by the session when the confirmation has been received.voidhandleRequest(Buffer buffer)Invoked whenSSH_MSG_CHANNEL_REQUESTreceivedvoidhandleSuccess()Invoked whenSSH_MSG_CHANNEL_SUCCESSreceivedvoidhandleWindowAdjust(Buffer buffer)Invoked whenSSH_MSG_CHANNEL_WINDOW_ADJUSTreceivedvoidinit(ConnectionService service, Session session, long id)Invoked when the local channel is initial createdbooleanisEofSignalled()booleanisInitialized()OpenFutureopen(long recipient, long rwSize, long packetSize, Buffer buffer)For a server channel, this method will actually open the channelvoidremoveRequestHandler(RequestHandler<Channel> handler)default voidremoveRequestHandlers(java.util.Collection<? extends RequestHandler<Channel>> handlers)default <T> TresolveAttribute(AttributeRepository.AttributeKey<T> key)Attempts to resolve the associated value by going up the store's hierarchy (if any)static <T> TresolveAttribute(Channel channel, AttributeRepository.AttributeKey<T> key)Attempts to use the channel attribute, if not found then tries the sessionIoWriteFuturewritePacket(Buffer buffer)Encode and send the given buffer.-
Methods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCount
-
Methods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttribute
-
Methods inherited from interface org.apache.sshd.common.channel.ChannelIdentifier
getChannelId
-
Methods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListener
-
Methods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolver
-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
Methods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmpty
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSession, getSessionContext
-
-
-
-
Field Detail
-
CHANNEL_EXEC
static final java.lang.String CHANNEL_EXEC
- See Also:
- Constant Field Values
-
CHANNEL_SHELL
static final java.lang.String CHANNEL_SHELL
- See Also:
- Constant Field Values
-
CHANNEL_SUBSYSTEM
static final java.lang.String CHANNEL_SUBSYSTEM
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRecipient
long getRecipient()
- Returns:
- Remote channel UITN32 identifier
-
getLocalWindow
LocalWindow getLocalWindow()
-
getRemoteWindow
RemoteWindow getRemoteWindow()
-
getRequestHandlers
java.util.List<RequestHandler<Channel>> getRequestHandlers()
-
addRequestHandler
void addRequestHandler(RequestHandler<Channel> handler)
-
addRequestHandlers
default void addRequestHandlers(java.util.Collection<? extends RequestHandler<Channel>> handlers)
-
removeRequestHandler
void removeRequestHandler(RequestHandler<Channel> handler)
-
removeRequestHandlers
default void removeRequestHandlers(java.util.Collection<? extends RequestHandler<Channel>> handlers)
-
handleClose
void handleClose() throws java.io.IOExceptionInvoked whenSSH_MSG_CHANNEL_CLOSEreceived- Throws:
java.io.IOException- If failed to handle the message
-
handleWindowAdjust
void handleWindowAdjust(Buffer buffer) throws java.io.IOException
Invoked whenSSH_MSG_CHANNEL_WINDOW_ADJUSTreceived- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
java.io.IOException- If failed to handle the message
-
handleRequest
void handleRequest(Buffer buffer) throws java.io.IOException
Invoked whenSSH_MSG_CHANNEL_REQUESTreceived- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
java.io.IOException- If failed to handle the message
-
handleData
void handleData(Buffer buffer) throws java.io.IOException
Invoked whenSSH_MSG_CHANNEL_DATAreceived- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
java.io.IOException- If failed to handle the message
-
handleExtendedData
void handleExtendedData(Buffer buffer) throws java.io.IOException
Invoked whenSSH_MSG_CHANNEL_EXTENDED_DATAreceived- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
java.io.IOException- If failed to handle the message
-
handleEof
void handleEof() throws java.io.IOExceptionInvoked whenSSH_MSG_CHANNEL_EOFreceived- Throws:
java.io.IOException- If failed to handle the message
-
handleSuccess
void handleSuccess() throws java.io.IOExceptionInvoked whenSSH_MSG_CHANNEL_SUCCESSreceived- Throws:
java.io.IOException- If failed to handle the message
-
handleFailure
void handleFailure() throws java.io.IOExceptionInvoked whenSSH_MSG_CHANNEL_FAILUREreceived- Throws:
java.io.IOException- If failed to handle the message
-
init
void init(ConnectionService service, Session session, long id) throws java.io.IOException
Invoked when the local channel is initial created- Parameters:
service- TheConnectionServicethrough which the channel is initializedsession- TheSessionassociated with the channelid- The locally assigned channel identifier (UINT32 represented as along)- Throws:
java.io.IOException- If failed to process the initialization
-
handleChannelRegistrationResult
void handleChannelRegistrationResult(ConnectionService service, Session session, long id, boolean registered)
Invoked after being successfully registered by the connection service - should throw aRuntimeExceptionif not registered- Parameters:
service- TheConnectionServicethrough which the channel is registeredsession- TheSessionassociated with the channelid- The locally assigned channel identifier (UINT32 represented as along)registered- Whether registration was successful or not
-
handleChannelUnregistration
void handleChannelUnregistration(ConnectionService service)
Called by the connection service to inform the channel that it has bee unregistered.- Parameters:
service- TheConnectionServicethrough which the channel is unregistered
-
isInitialized
boolean isInitialized()
- Returns:
trueif call toinit(ConnectionService, Session, long)was successfully completed
-
isEofSignalled
boolean isEofSignalled()
- Returns:
trueif the peer signaled that it will not send any more data- See Also:
- RFC 4254 - section 5.3 - SSH_MSG_CHANNEL_EOF
-
open
OpenFuture open(long recipient, long rwSize, long packetSize, Buffer buffer)
For a server channel, this method will actually open the channel- Parameters:
recipient- Recipient identifier (UINT32 represented as along)rwSize- Read/Write window size (uint32)packetSize- Preferred maximum packet size (uint32)buffer- IncomingBufferthat triggered the call. Note: the buffer's read position is exactly after the information that read to this call was decoded- Returns:
- An
OpenFuturefor the channel open request
-
handleOpenSuccess
void handleOpenSuccess(long recipient, long rwSize, long packetSize, Buffer buffer) throws java.io.IOExceptionFor a client channel, this method will be called internally by the session when the confirmation has been received.- Parameters:
recipient- Recipient identifier (UINT32 represented as along)rwSize- Read/Write window size (uint32)packetSize- Preferred maximum packet size (uint32)buffer- IncomingBufferthat triggered the call. Note: the buffer's read position is exactly after the information that read to this call was decoded- Throws:
java.io.IOException- If failed to handle the success
-
handleOpenFailure
void handleOpenFailure(Buffer buffer) throws java.io.IOException
For a client channel, this method will be called internally by the session when the server has rejected this channel opening.- Parameters:
buffer- IncomingBufferthat triggered the call. Note: the buffer's read position is exactly after the information that read to this call was decoded- Throws:
java.io.IOException- If failed to handle the success
-
resolveAttribute
default <T> T resolveAttribute(AttributeRepository.AttributeKey<T> key)
Description copied from interface:AttributeRepositoryAttempts to resolve the associated value by going up the store's hierarchy (if any)- Specified by:
resolveAttributein interfaceAttributeRepository- Type Parameters:
T- The generic attribute type- Parameters:
key- The key of the attribute; must not benull.- Returns:
nullif there is no value associated with the specified key either in this repository or any of its ancestors (if any available)
-
resolveAttribute
static <T> T resolveAttribute(Channel channel, AttributeRepository.AttributeKey<T> key)
Attempts to use the channel attribute, if not found then tries the session- Type Parameters:
T- The generic attribute type- Parameters:
channel- TheChannel- ignored ifnullkey- The attribute key - nevernull- Returns:
- Associated value -
nullif not found - See Also:
SessionHolder.getSession(),Session.resolveAttribute(Session, AttributeRepository.AttributeKey)
-
writePacket
IoWriteFuture writePacket(Buffer buffer) throws java.io.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- the buffer to encode and send. NOTE: the buffer must not be touched until the returned write future is completed.- Returns:
- An
IoWriteFuturethat can be used to check when the packet has actually been sent - Throws:
java.io.IOException- if an error occurred when encoding or sending the packet
-
-