Class AbstractChannel
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.util.closeable.AbstractInnerCloseable
org.apache.sshd.common.channel.AbstractChannel
- All Implemented Interfaces:
Closeable, AutoCloseable, Channel, org.apache.sshd.common.AttributeRepository, org.apache.sshd.common.AttributeStore, Channel, ChannelIdentifier, ChannelListenerManager, ChannelStreamWriterResolver, ChannelStreamWriterResolverManager, org.apache.sshd.common.Closeable, org.apache.sshd.common.PropertyResolver, org.apache.sshd.common.session.SessionContextHolder, SessionHolder<Session>, org.apache.sshd.common.util.threads.ExecutorServiceCarrier
- Direct Known Subclasses:
AbstractClientChannel, AbstractServerChannel
public abstract class AbstractChannel
extends org.apache.sshd.common.util.closeable.AbstractInnerCloseable
implements Channel, org.apache.sshd.common.util.threads.ExecutorServiceCarrier
Provides common client/server channel functionality
- Author:
- Apache MINA SSHD Project
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassprotected static enumstatic interfaceAAbstractChannel.PacketValidatorcan validate packet lengths.Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable.StateNested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
org.apache.sshd.common.AttributeRepository.AttributeKey<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ChannelListenerprotected final Collection<ChannelListener> Channel events listenerprotected final AtomicBooleanstatic final AbstractChannel.PacketValidatorA defaultAbstractChannel.PacketValidatorthat enforces that the packet size is not greater than the maximum packet size of the channel's local window.protected final AtomicBooleanprotected final org.apache.sshd.common.future.DefaultCloseFutureprotected AtomicReference<AbstractChannel.GracefulState> protected final AtomicBooleanstatic final IntUnaryOperatorDefault growth factor function used to resize response buffersprotected ConnectionServiceprotected final AtomicBooleanFields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, stateFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface Channel
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMFields inherited from interface ChannelStreamWriterResolver
NONEFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractChannel(boolean client) protectedAbstractChannel(boolean client, Collection<? extends RequestHandler<Channel>> handlers) protectedAbstractChannel(String discriminator, boolean client) protectedAbstractChannel(String discriminator, boolean client, Collection<? extends RequestHandler<Channel>> handlers, org.apache.sshd.common.util.threads.CloseableExecutorService executorService) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChannelListener(ChannelListener listener) Add a channel listenerprotected DateaddPendingRequest(String request, boolean wantReply) Add a channel request to the tracked pending ones if reply is expectedvoidaddRequestHandler(RequestHandler<Channel> handler) Collection<org.apache.sshd.common.AttributeRepository.AttributeKey<?>> void<T> TcomputeAttributeIfAbsent(org.apache.sshd.common.AttributeRepository.AttributeKey<T> key, Function<? super org.apache.sshd.common.AttributeRepository.AttributeKey<T>, ? extends T> resolver) protected voidprotected abstract voiddoWriteData(byte[] data, int off, long len) protected abstract voiddoWriteExtendedData(byte[] data, int off, long len) <T> TgetAttribute(org.apache.sshd.common.AttributeRepository.AttributeKey<T> key) intlongorg.apache.sshd.common.util.threads.CloseableExecutorServiceprotected org.apache.sshd.common.CloseableRetrieves the currently setAbstractChannel.PacketValidator.org.apache.sshd.common.PropertyResolverlongvoidhandleChannelRegistrationResult(ConnectionService service, Session session, long channelId, boolean registered) Invoked after being successfully registered by the connection service - should throw aRuntimeExceptionif not registeredprotected voidhandleChannelRequest(String req, boolean wantReply, org.apache.sshd.common.util.buffer.Buffer buffer) voidCalled by the connection service to inform the channel that it has bee unregistered.voidInvoked whenSSH_MSG_CHANNEL_CLOSEreceivedvoidhandleData(org.apache.sshd.common.util.buffer.Buffer buffer) Invoked whenSSH_MSG_CHANNEL_DATAreceivedvoidInvoked whenSSH_MSG_CHANNEL_EOFreceivedvoidhandleExtendedData(org.apache.sshd.common.util.buffer.Buffer buffer) Invoked whenSSH_MSG_CHANNEL_EXTENDED_DATAreceivedvoidInvoked whenSSH_MSG_CHANNEL_FAILUREreceivedprotected RequestHandler.ResulthandleInternalRequest(String req, boolean wantReply, org.apache.sshd.common.util.buffer.Buffer buffer) Called byhandleUnknownChannelRequest(String, boolean, Buffer)in order to allow channel request handling if none of the registered handlers processed the request - last chance.voidhandleRequest(org.apache.sshd.common.util.buffer.Buffer buffer) Invoked whenSSH_MSG_CHANNEL_REQUESTreceivedvoidInvoked whenSSH_MSG_CHANNEL_SUCCESSreceivedprotected voidhandleUnknownChannelRequest(String req, boolean wantReply, org.apache.sshd.common.util.buffer.Buffer buffer) Called when none of the register request handlers reported handling the requestvoidhandleWindowAdjust(org.apache.sshd.common.util.buffer.Buffer buffer) Invoked whenSSH_MSG_CHANNEL_WINDOW_ADJUSTreceivedvoidinit(ConnectionService service, Session session, long id) Invoked when the local channel is initial createdprotected voidinvokeChannelSignaller(Consumer<ChannelListener> invoker) booleanbooleanbooleanprotected booleanmayWrite()protected voidnotifyStateChanged(String hint) protected voidpreClose()<T> TremoveAttribute(org.apache.sshd.common.AttributeRepository.AttributeKey<T> key) voidremoveChannelListener(ChannelListener listener) Remove a channel listenerprotected DateremovePendingRequest(String request) Removes a channel request from the tracked onesvoidremoveRequestHandler(RequestHandler<Channel> handler) protected org.apache.sshd.common.io.IoWriteFuturesendEof()SendsSSH_MSG_CHANNEL_EOFprovided not already sent and current channel state allows it.protected org.apache.sshd.common.io.IoWriteFuturesendResponse(org.apache.sshd.common.util.buffer.Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) protected voidsendWindowAdjust(long len) <T> TsetAttribute(org.apache.sshd.common.AttributeRepository.AttributeKey<T> key, T value) voidvoidSets aAbstractChannel.PacketValidator.protected voidsetRecipient(long recipient) voidsignalChannelClosed(Throwable reason) protected voidprotected voidsignalChannelOpenFailure(Throwable reason) protected voidtoString()protected longvalidateIncomingDataSize(int cmd, long len) org.apache.sshd.common.io.IoWriteFuturewritePacket(org.apache.sshd.common.util.buffer.Buffer buffer) Encode and send the given buffer.Methods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediatelyMethods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenerMethods 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, warnMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Channel
addRequestHandlers, handleOpenFailure, handleOpenSuccess, open, removeRequestHandlers, resolveAttributeMethods inherited from interface ChannelStreamWriterResolverManager
resolveChannelStreamWriterMethods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListenerMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringProperty, isEmptyMethods inherited from interface SessionHolder
getSessionContext
-
Field Details
-
RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers -
DEFAULT_PACKET_VALIDATOR
A defaultAbstractChannel.PacketValidatorthat enforces that the packet size is not greater than the maximum packet size of the channel's local window. -
service
-
initialized
-
eofReceived
-
unregisterSignaled
-
closeSignaled
-
gracefulState
-
gracefulFuture
protected final org.apache.sshd.common.future.DefaultCloseFuture gracefulFuture -
channelListeners
Channel events listener -
channelListenerProxy
-
-
Constructor Details
-
AbstractChannel
protected AbstractChannel(boolean client) -
AbstractChannel
-
AbstractChannel
-
AbstractChannel
protected AbstractChannel(String discriminator, boolean client, Collection<? extends RequestHandler<Channel>> handlers, org.apache.sshd.common.util.threads.CloseableExecutorService executorService)
-
-
Method Details
-
getRequestHandlers
- Specified by:
getRequestHandlersin interfaceChannel
-
addRequestHandler
- Specified by:
addRequestHandlerin interfaceChannel
-
removeRequestHandler
- Specified by:
removeRequestHandlerin interfaceChannel
-
getChannelId
public long getChannelId()- Specified by:
getChannelIdin interfaceChannelIdentifier- Returns:
- Local channel UINT32 identifier
-
getRecipient
public long getRecipient()- Specified by:
getRecipientin interfaceChannel- Returns:
- Remote channel UITN32 identifier
-
setRecipient
protected void setRecipient(long recipient) -
getLocalWindow
- Specified by:
getLocalWindowin interfaceChannel
-
getRemoteWindow
- Specified by:
getRemoteWindowin interfaceChannel
-
getSession
- Specified by:
getSessionin interfaceSessionHolder<Session>
-
getParentPropertyResolver
public org.apache.sshd.common.PropertyResolver getParentPropertyResolver()- Specified by:
getParentPropertyResolverin interfaceorg.apache.sshd.common.PropertyResolver
-
getExecutorService
public org.apache.sshd.common.util.threads.CloseableExecutorService getExecutorService()- Specified by:
getExecutorServicein interfaceorg.apache.sshd.common.util.threads.ExecutorServiceCarrier
-
getChannelStreamWriterResolver
- Specified by:
getChannelStreamWriterResolverin interfaceChannelStreamWriterResolverManager
-
setChannelStreamWriterResolver
- Specified by:
setChannelStreamWriterResolverin interfaceChannelStreamWriterResolverManager
-
resolveChannelStreamWriterResolver
- Specified by:
resolveChannelStreamWriterResolverin interfaceChannelStreamWriterResolverManager
-
addPendingRequest
Add a channel request to the tracked pending ones if reply is expected- Parameters:
request- The request typewantReply-trueif reply is expected- Returns:
- The allocated
Datetimestamp -nullif no reply is expected (in which case the request is not tracked) - Throws:
IllegalArgumentException- If the request is already being tracked- See Also:
-
removePendingRequest
Removes a channel request from the tracked ones- Parameters:
request- The request type- Returns:
- The allocated
Datetimestamp -nullif the specified request type is not being tracked or has not been added to the tracked ones to begin with - See Also:
-
handleRequest
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_REQUESTreceived- Specified by:
handleRequestin interfaceChannel- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
IOException- If failed to handle the message
-
handleChannelRequest
protected void handleChannelRequest(String req, boolean wantReply, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException - Throws:
IOException
-
handleUnknownChannelRequest
protected void handleUnknownChannelRequest(String req, boolean wantReply, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException Called when none of the register request handlers reported handling the request- Parameters:
req- The request typewantReply- Whether reply is requestedbuffer- TheBuffercontaining extra request-specific data- Throws:
IOException- If failed to send the response (if needed)- See Also:
-
handleInternalRequest
protected RequestHandler.Result handleInternalRequest(String req, boolean wantReply, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException Called byhandleUnknownChannelRequest(String, boolean, Buffer)in order to allow channel request handling if none of the registered handlers processed the request - last chance.- Parameters:
req- The request typewantReply- Whether reply is requestedbuffer- TheBuffercontaining extra request-specific data- Returns:
- The handling result - if
nullorUnsupportedand reply is required then a failure message will be sent - Throws:
IOException- If failed to process the request internally
-
sendResponse
protected org.apache.sshd.common.io.IoWriteFuture sendResponse(org.apache.sshd.common.util.buffer.Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException - Throws:
IOException
-
init
Description copied from interface:ChannelInvoked when the local channel is initial created- Specified by:
initin interfaceChannel- Parameters:
service- TheConnectionServicethrough which the channel is initializedsession- TheSessionassociated with the channelid- The locally assigned channel identifier (UINT32 represented as along)- Throws:
IOException- If failed to process the initialization
-
signalChannelInitialized
- Throws:
IOException
-
signalChannelOpenSuccess
protected void signalChannelOpenSuccess() -
isInitialized
public boolean isInitialized()- Specified by:
isInitializedin interfaceChannel- Returns:
trueif call toChannel.init(ConnectionService, Session, long)was successfully completed
-
handleChannelRegistrationResult
public void handleChannelRegistrationResult(ConnectionService service, Session session, long channelId, boolean registered) Description copied from interface:ChannelInvoked after being successfully registered by the connection service - should throw aRuntimeExceptionif not registered- Specified by:
handleChannelRegistrationResultin interfaceChannel- Parameters:
service- TheConnectionServicethrough which the channel is registeredsession- TheSessionassociated with the channelchannelId- The locally assigned channel identifier (UINT32 represented as along)registered- Whether registration was successful or not
-
signalChannelOpenFailure
-
notifyStateChanged
-
addChannelListener
Description copied from interface:ChannelListenerManagerAdd a channel listener- Specified by:
addChannelListenerin interfaceChannelListenerManager- Parameters:
listener- TheChannelListenerto add - notnull
-
removeChannelListener
Description copied from interface:ChannelListenerManagerRemove a channel listener- Specified by:
removeChannelListenerin interfaceChannelListenerManager- Parameters:
listener- TheChannelListenerto remove
-
getChannelListenerProxy
- Specified by:
getChannelListenerProxyin interfaceChannelListenerManager- Returns:
- A (never
nullproxyChannelListenerthat represents all the currently registered listeners. Any method invocation on the proxy is replicated to the currently registered listeners
-
handleClose
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_CLOSEreceived- Specified by:
handleClosein interfaceChannel- Throws:
IOException- If failed to handle the message
-
getInnerCloseable
protected org.apache.sshd.common.Closeable getInnerCloseable()- Specified by:
getInnerCloseablein classorg.apache.sshd.common.util.closeable.AbstractInnerCloseable
-
preClose
protected void preClose()- Overrides:
preClosein classorg.apache.sshd.common.util.closeable.AbstractCloseable
-
handleChannelUnregistration
Description copied from interface:ChannelCalled by the connection service to inform the channel that it has bee unregistered.- Specified by:
handleChannelUnregistrationin interfaceChannel- Parameters:
service- TheConnectionServicethrough which the channel is unregistered
-
signalChannelClosed
-
invokeChannelSignaller
-
writePacket
public org.apache.sshd.common.io.IoWriteFuture writePacket(org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException Description copied from interface:ChannelEncode 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.- Specified by:
writePacketin interfaceChannel- 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:
IOException- if an error occurred when encoding or sending the packet
-
mayWrite
protected boolean mayWrite() -
handleData
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_DATAreceived- Specified by:
handleDatain interfaceChannel- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
IOException- If failed to handle the message
-
handleExtendedData
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_EXTENDED_DATAreceived- Specified by:
handleExtendedDatain interfaceChannel- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
IOException- If failed to handle the message
-
validateIncomingDataSize
- Throws:
IOException
-
getPacketValidator
Retrieves the currently setAbstractChannel.PacketValidator.- Returns:
- the validator, never
null
-
setPacketValidator
Sets aAbstractChannel.PacketValidator.- Parameters:
validator- the validator to set, ifnulltheDEFAULT_PACKET_VALIDATORis set
-
handleEof
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_EOFreceived- Specified by:
handleEofin interfaceChannel- Throws:
IOException- If failed to handle the message
-
isEofSignalled
public boolean isEofSignalled()- Specified by:
isEofSignalledin interfaceChannel- Returns:
trueif the peer signaled that it will not send any more data- See Also:
-
handleWindowAdjust
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_WINDOW_ADJUSTreceived- Specified by:
handleWindowAdjustin interfaceChannel- Parameters:
buffer- The rest of the message dataBufferafter decoding the channel identifiers- Throws:
IOException- If failed to handle the message
-
handleSuccess
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_SUCCESSreceived- Specified by:
handleSuccessin interfaceChannel- Throws:
IOException- If failed to handle the message
-
handleFailure
Description copied from interface:ChannelInvoked whenSSH_MSG_CHANNEL_FAILUREreceived- Specified by:
handleFailurein interfaceChannel- Throws:
IOException- If failed to handle the message
-
doWriteData
- Throws:
IOException
-
doWriteExtendedData
- Throws:
IOException
-
sendEof
SendsSSH_MSG_CHANNEL_EOFprovided not already sent and current channel state allows it.- Returns:
- The
IoWriteFutureof the sent packet -nullif message not sent due to channel state (or already sent) - Throws:
IOException- If failed to send the packet
-
isEofSent
public boolean isEofSent() -
getProperties
-
getAttributesCount
public int getAttributesCount()- Specified by:
getAttributesCountin interfaceorg.apache.sshd.common.AttributeRepository
-
getAttribute
public <T> T getAttribute(org.apache.sshd.common.AttributeRepository.AttributeKey<T> key) - Specified by:
getAttributein interfaceorg.apache.sshd.common.AttributeRepository
-
attributeKeys
- Specified by:
attributeKeysin interfaceorg.apache.sshd.common.AttributeRepository
-
computeAttributeIfAbsent
public <T> T computeAttributeIfAbsent(org.apache.sshd.common.AttributeRepository.AttributeKey<T> key, Function<? super org.apache.sshd.common.AttributeRepository.AttributeKey<T>, ? extends T> resolver) - Specified by:
computeAttributeIfAbsentin interfaceorg.apache.sshd.common.AttributeStore
-
setAttribute
public <T> T setAttribute(org.apache.sshd.common.AttributeRepository.AttributeKey<T> key, T value) - Specified by:
setAttributein interfaceorg.apache.sshd.common.AttributeStore
-
removeAttribute
public <T> T removeAttribute(org.apache.sshd.common.AttributeRepository.AttributeKey<T> key) - Specified by:
removeAttributein interfaceorg.apache.sshd.common.AttributeStore
-
clearAttributes
public void clearAttributes()- Specified by:
clearAttributesin interfaceorg.apache.sshd.common.AttributeStore
-
configureWindow
protected void configureWindow() -
sendWindowAdjust
- Throws:
IOException
-
toString
-