public abstract class AbstractChannel extends AbstractInnerCloseable implements Channel, ExecutorServiceCarrier
| Modifier and Type | Class and Description |
|---|---|
class |
AbstractChannel.GracefulChannelCloseable |
protected static class |
AbstractChannel.GracefulState |
AbstractCloseable.StateAttributeRepository.AttributeKey<T>| Modifier and Type | Field and Description |
|---|---|
protected ChannelListener |
channelListenerProxy |
protected Collection<ChannelListener> |
channelListeners
Channel events listener
|
protected AtomicBoolean |
eofReceived |
protected AtomicBoolean |
eofSent |
protected DefaultCloseFuture |
gracefulFuture |
protected AtomicReference<AbstractChannel.GracefulState> |
gracefulState |
protected AtomicBoolean |
initialized |
static IntUnaryOperator |
RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers
|
protected ConnectionService |
service |
closeFuture, futureLock, statelogCHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMEMPTYNONECLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUT| Modifier | Constructor 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) |
| Modifier and Type | Method and Description |
|---|---|
void |
addChannelListener(ChannelListener listener)
Add a channel listener
|
protected Date |
addPendingRequest(String request,
boolean wantReply)
Add a channel request to the tracked pending ones if reply is expected
|
void |
addRequestHandler(RequestHandler<Channel> handler) |
Collection<AttributeRepository.AttributeKey<?>> |
attributeKeys() |
void |
clearAttributes() |
<T> T |
computeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key,
Function<? super AttributeRepository.AttributeKey<T>,? extends T> resolver) |
protected void |
configureWindow() |
protected abstract void |
doWriteData(byte[] data,
int off,
long len) |
protected abstract void |
doWriteExtendedData(byte[] data,
int off,
long len) |
<T> T |
getAttribute(AttributeRepository.AttributeKey<T> key) |
int |
getAttributesCount() |
ChannelListener |
getChannelListenerProxy() |
ChannelStreamPacketWriterResolver |
getChannelStreamPacketWriterResolver() |
CloseableExecutorService |
getExecutorService() |
int |
getId() |
protected Closeable |
getInnerCloseable() |
Window |
getLocalWindow() |
PropertyResolver |
getParentPropertyResolver() |
Map<String,Object> |
getProperties() |
int |
getRecipient() |
Window |
getRemoteWindow() |
List<RequestHandler<Channel>> |
getRequestHandlers() |
Session |
getSession() |
protected void |
handleChannelRequest(String req,
boolean wantReply,
Buffer buffer) |
void |
handleClose()
Invoked when
SSH_MSG_CHANNEL_CLOSE received |
void |
handleData(Buffer buffer)
Invoked when
SSH_MSG_CHANNEL_DATA received |
void |
handleEof()
Invoked when
SSH_MSG_CHANNEL_EOF received |
void |
handleExtendedData(Buffer buffer)
Invoked when
SSH_MSG_CHANNEL_EXTENDED_DATA received |
void |
handleFailure()
Invoked when
SSH_MSG_CHANNEL_FAILURE received |
protected RequestHandler.Result |
handleInternalRequest(String req,
boolean wantReply,
Buffer 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. |
void |
handleRequest(Buffer buffer)
Invoked when
SSH_MSG_CHANNEL_REQUEST received |
void |
handleSuccess()
Invoked when
SSH_MSG_CHANNEL_SUCCESS received |
protected void |
handleUnknownChannelRequest(String req,
boolean wantReply,
Buffer buffer)
Called when none of the register request handlers reported handling the request
|
void |
handleWindowAdjust(Buffer buffer)
Invoked when
SSH_MSG_CHANNEL_WINDOW_ADJUST received |
void |
init(ConnectionService service,
Session session,
int id)
Invoked when the local channel is initial created
|
protected void |
invokeChannelSignaller(Invoker<ChannelListener,Void> invoker) |
boolean |
isEofSent() |
boolean |
isEofSignalled() |
boolean |
isInitialized() |
protected void |
notifyStateChanged(ChannelListener listener,
String hint) |
protected void |
notifyStateChanged(String hint) |
protected void |
preClose() |
<T> T |
removeAttribute(AttributeRepository.AttributeKey<T> key) |
void |
removeChannelListener(ChannelListener listener)
Remove a channel listener
|
protected Date |
removePendingRequest(String request)
Removes a channel request from the tracked ones
|
void |
removeRequestHandler(RequestHandler<Channel> handler) |
ChannelStreamPacketWriterResolver |
resolveChannelStreamPacketWriterResolver() |
protected void |
sendEof() |
protected IoWriteFuture |
sendResponse(Buffer buffer,
String req,
RequestHandler.Result result,
boolean wantReply) |
protected void |
sendWindowAdjust(long len) |
<T> T |
setAttribute(AttributeRepository.AttributeKey<T> key,
T value) |
void |
setChannelStreamPacketWriterResolver(ChannelStreamPacketWriterResolver resolver) |
protected void |
setRecipient(int recipient) |
protected void |
signalChannelClosed(ChannelListener listener,
Throwable reason) |
void |
signalChannelClosed(Throwable reason) |
protected void |
signalChannelInitialized() |
protected void |
signalChannelInitialized(ChannelListener listener) |
protected void |
signalChannelOpenFailure(ChannelListener listener,
Throwable reason) |
protected void |
signalChannelOpenFailure(Throwable reason) |
protected void |
signalChannelOpenSuccess() |
protected void |
signalChannelOpenSuccess(ChannelListener listener) |
String |
toString() |
protected long |
validateIncomingDataSize(int cmd,
long len) |
IoWriteFuture |
writePacket(Buffer buffer) |
doCloseGracefully, doCloseImmediatelyaddCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenergetSimplifiedLoggerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddRequestHandlers, handleOpenFailure, handleOpenSuccess, open, removeRequestHandlers, resolveAttribute, resolveAttributegetSessionContextgetBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringPropertyofAttributesMap, ofKeyValuePaircalculatePadLengthresolveChannelStreamPacketWriteraddCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListenerpublic static final IntUnaryOperator RESPONSE_BUFFER_GROWTH_FACTOR
protected ConnectionService service
protected final AtomicBoolean initialized
protected final AtomicBoolean eofReceived
protected final AtomicBoolean eofSent
protected AtomicReference<AbstractChannel.GracefulState> gracefulState
protected final DefaultCloseFuture gracefulFuture
protected final Collection<ChannelListener> channelListeners
protected final ChannelListener channelListenerProxy
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)
public List<RequestHandler<Channel>> getRequestHandlers()
public void addRequestHandler(RequestHandler<Channel> handler)
public void removeRequestHandler(RequestHandler<Channel> handler)
public int getId()
public int getRecipient()
protected void setRecipient(int recipient)
public Window getLocalWindow()
public Window getRemoteWindow()
public Session getSession()
getSession in interface SessionHolder<Session>public PropertyResolver getParentPropertyResolver()
getParentPropertyResolver in interface PropertyResolverpublic CloseableExecutorService getExecutorService()
getExecutorService in interface ExecutorServiceCarrierpublic ChannelStreamPacketWriterResolver getChannelStreamPacketWriterResolver()
getChannelStreamPacketWriterResolver in interface ChannelStreamPacketWriterResolverManagerpublic void setChannelStreamPacketWriterResolver(ChannelStreamPacketWriterResolver resolver)
setChannelStreamPacketWriterResolver in interface ChannelStreamPacketWriterResolverManagerpublic ChannelStreamPacketWriterResolver resolveChannelStreamPacketWriterResolver()
resolveChannelStreamPacketWriterResolver in interface ChannelStreamPacketWriterResolverManagerprotected Date addPendingRequest(String request, boolean wantReply)
request - The request typewantReply - true if reply is expectedDate timestamp - null if no reply
is expected (in which case the request is not tracked)IllegalArgumentException - If the request is already being trackedremovePendingRequest(String)protected Date removePendingRequest(String request)
request - The request typeDate timestamp - null if the
specified request type is not being tracked or has not been added to
the tracked ones to begin withaddPendingRequest(String, boolean)public void handleRequest(Buffer buffer) throws IOException
ChannelSSH_MSG_CHANNEL_REQUEST receivedbuffer - The rest of the message data Buffer after
decoding the channel identifiersIOException - If failed to handle the messageprotected void handleChannelRequest(String req, boolean wantReply, Buffer buffer) throws IOException
IOExceptionprotected void handleUnknownChannelRequest(String req, boolean wantReply, Buffer buffer) throws IOException
req - The request typewantReply - Whether reply is requestedbuffer - The Buffer containing extra request-specific dataIOException - If failed to send the response (if needed)handleInternalRequest(String, boolean, Buffer)protected RequestHandler.Result handleInternalRequest(String req, boolean wantReply, Buffer buffer) throws IOException
handleUnknownChannelRequest(String, boolean, Buffer)
in order to allow channel request handling if none of the registered handlers
processed the request - last chance.req - The request typewantReply - Whether reply is requestedbuffer - The Buffer containing extra request-specific datanull or Unsupported
and reply is required then a failure message will be sentIOException - If failed to process the request internallyprotected IoWriteFuture sendResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException
IOExceptionpublic void init(ConnectionService service, Session session, int id) throws IOException
Channelservice - The ConnectionService through which the channel is initializedsession - The Session associated with the channelid - The locally assigned channel identifierIOException - If failed to process the initializationprotected void signalChannelInitialized()
throws IOException
IOExceptionprotected void signalChannelInitialized(ChannelListener listener)
protected void signalChannelOpenSuccess()
protected void signalChannelOpenSuccess(ChannelListener listener)
public boolean isInitialized()
true if call to Channel.init(ConnectionService, Session, int) was
successfully completedprotected void signalChannelOpenFailure(Throwable reason)
protected void signalChannelOpenFailure(ChannelListener listener, Throwable reason)
protected void notifyStateChanged(String hint)
protected void notifyStateChanged(ChannelListener listener, String hint)
public void addChannelListener(ChannelListener listener)
ChannelListenerManageraddChannelListener in interface ChannelListenerManagerlistener - The ChannelListener to add - not nullpublic void removeChannelListener(ChannelListener listener)
ChannelListenerManagerremoveChannelListener in interface ChannelListenerManagerlistener - The ChannelListener to removepublic ChannelListener getChannelListenerProxy()
getChannelListenerProxy in interface ChannelListenerManagernull proxy ChannelListener that represents
all the currently registered listeners. Any method invocation on the proxy
is replicated to the currently registered listenerspublic void handleClose()
throws IOException
ChannelSSH_MSG_CHANNEL_CLOSE receivedIOException - If failed to handle the messageprotected Closeable getInnerCloseable()
getInnerCloseable in class AbstractInnerCloseableprotected void preClose()
preClose in class AbstractCloseablepublic void signalChannelClosed(Throwable reason)
protected void signalChannelClosed(ChannelListener listener, Throwable reason)
protected void invokeChannelSignaller(Invoker<ChannelListener,Void> invoker) throws Throwable
Throwablepublic IoWriteFuture writePacket(Buffer buffer) throws IOException
writePacket in interface PacketWriterIOExceptionpublic void handleData(Buffer buffer) throws IOException
ChannelSSH_MSG_CHANNEL_DATA receivedbuffer - The rest of the message data Buffer after
decoding the channel identifiersIOException - If failed to handle the messagepublic void handleExtendedData(Buffer buffer) throws IOException
ChannelSSH_MSG_CHANNEL_EXTENDED_DATA receivedbuffer - The rest of the message data Buffer after
decoding the channel identifiersIOException - If failed to handle the messageprotected long validateIncomingDataSize(int cmd,
long len)
public void handleEof()
throws IOException
ChannelSSH_MSG_CHANNEL_EOF receivedIOException - If failed to handle the messagepublic boolean isEofSignalled()
true if the peer signaled that it will not send any
more datapublic void handleWindowAdjust(Buffer buffer) throws IOException
ChannelSSH_MSG_CHANNEL_WINDOW_ADJUST receivedbuffer - The rest of the message data Buffer after
decoding the channel identifiersIOException - If failed to handle the messagepublic void handleSuccess()
throws IOException
ChannelSSH_MSG_CHANNEL_SUCCESS receivedIOException - If failed to handle the messagepublic void handleFailure()
throws IOException
ChannelSSH_MSG_CHANNEL_FAILURE receivedIOException - If failed to handle the messageprotected abstract void doWriteData(byte[] data,
int off,
long len)
throws IOException
IOExceptionprotected abstract void doWriteExtendedData(byte[] data,
int off,
long len)
throws IOException
IOExceptionprotected void sendEof()
throws IOException
IOExceptionpublic boolean isEofSent()
public Map<String,Object> getProperties()
getProperties in interface PropertyResolverpublic int getAttributesCount()
getAttributesCount in interface AttributeRepositorypublic <T> T getAttribute(AttributeRepository.AttributeKey<T> key)
getAttribute in interface AttributeRepositorypublic Collection<AttributeRepository.AttributeKey<?>> attributeKeys()
attributeKeys in interface AttributeRepositorypublic <T> T computeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key, Function<? super AttributeRepository.AttributeKey<T>,? extends T> resolver)
computeAttributeIfAbsent in interface AttributeStorepublic <T> T setAttribute(AttributeRepository.AttributeKey<T> key, T value)
setAttribute in interface AttributeStorepublic <T> T removeAttribute(AttributeRepository.AttributeKey<T> key)
removeAttribute in interface AttributeStorepublic void clearAttributes()
clearAttributes in interface AttributeStoreprotected void configureWindow()
protected void sendWindowAdjust(long len)
throws IOException
IOExceptionCopyright © 2008–2020 The Apache Software Foundation. All rights reserved.