public abstract class AbstractChannel extends AbstractInnerCloseable implements Channel, ExecutorServiceConfigurer
| Modifier and Type | Class and Description |
|---|---|
class |
AbstractChannel.GracefulChannelCloseable |
protected static class |
AbstractChannel.GracefulState |
AbstractCloseable.StateAttributeStore.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, lock, statelogCHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEMEMPTYCLOSE_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) |
| 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) |
CloseFuture |
close(boolean immediately)
Close this resource asynchronously and return a future.
|
protected void |
configureWindow() |
protected void |
doCloseImmediately()
doCloseImmediately is called once and only once
with state == Immediate
Overriding methods should always call the base implementation.
|
protected abstract void |
doWriteData(byte[] data,
int off,
long len) |
protected abstract void |
doWriteExtendedData(byte[] data,
int off,
long len) |
<T> T |
getAttribute(AttributeStore.AttributeKey<T> key)
Returns the value of the user-defined attribute.
|
ChannelListener |
getChannelListenerProxy() |
ExecutorService |
getExecutorService() |
int |
getId() |
protected Closeable |
getInnerCloseable() |
Window |
getLocalWindow() |
PropertyResolver |
getParentPropertyResolver() |
Map<String,Object> |
getProperties()
A map of properties that can be used to configure the SSH server or
client.
|
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() |
boolean |
isShutdownOnExit() |
protected void |
notifyStateChanged(ChannelListener listener,
String hint) |
protected void |
notifyStateChanged(String hint) |
protected void |
preClose()
preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.
|
<T> T |
removeAttribute(AttributeStore.AttributeKey<T> key)
Removes the user-defined attribute
|
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) |
<T> T |
resolveAttribute(AttributeStore.AttributeKey<T> key)
Attempts to resolve the associated value by going up the store's
hierarchy (if any)
|
protected void |
sendEof() |
protected IoWriteFuture |
sendResponse(Buffer buffer,
String req,
RequestHandler.Result result,
boolean wantReply) |
protected void |
sendWindowAdjust(long len) |
<T> T |
setAttribute(AttributeStore.AttributeKey<T> key,
T value)
Sets a user-defined attribute.
|
void |
setExecutorService(ExecutorService service) |
protected void |
setRecipient(int recipient) |
void |
setShutdownOnExit(boolean shutdown) |
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) |
protected IoWriteFuture |
writePacket(Buffer buffer) |
doCloseGracefullyaddCloseFutureListener, builder, isClosed, isClosing, removeCloseFutureListenergetSimplifiedLoggerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddRequestHandlers, handleOpenFailure, handleOpenSuccess, open, removeRequestHandlersgetBoolean, getBooleanProperty, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringPropertyresolveAttribute, resolveAttribute, resolveAttributeaddCloseFutureListener, 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)
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 PropertyResolver getParentPropertyResolver()
getParentPropertyResolver in interface PropertyResolvernull if no parentpublic ExecutorService getExecutorService()
getExecutorService in interface ExecutorServiceCarrierExecutorService to usepublic void setExecutorService(ExecutorService service)
setExecutorService in interface ExecutorServiceConfigurerpublic boolean isShutdownOnExit()
isShutdownOnExit in interface ExecutorServiceCarriertrue then the ExecutorService.shutdownNow()
will be called (unless it is an internally allocated service which is always
closed)public void setShutdownOnExit(boolean shutdown)
setShutdownOnExit in interface ExecutorServiceConfigurerprotected 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 messagepublic CloseFuture close(boolean immediately)
Closeableclose in class AbstractCloseableimmediately - true if the resource should be shut down abruptly,
false for a graceful closeCloseFuture representing the close requestprotected Closeable getInnerCloseable()
getInnerCloseable in class AbstractInnerCloseableprotected void preClose()
AbstractCloseablepreClose in class AbstractCloseablepublic void signalChannelClosed(Throwable reason)
protected void signalChannelClosed(ChannelListener listener, Throwable reason)
protected void invokeChannelSignaller(Invoker<ChannelListener,Void> invoker) throws Throwable
Throwableprotected void doCloseImmediately()
AbstractCloseabledoCloseImmediately is called once and only once with state == Immediate
Overriding methods should always call the base implementation. It may be called concurrently while preClose() or doCloseGracefully is executing
doCloseImmediately in class AbstractInnerCloseableprotected IoWriteFuture writePacket(Buffer buffer) throws IOException
IOExceptionpublic 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()
PropertyResolverA map of properties that can be used to configure the SSH server or client. This map will never be changed by either the server or client and is not supposed to be changed at runtime (changes are not bound to have any effect on a running client or server), though it may affect the creation of sessions later as these values are usually not cached.
Note: the type of the mapped property should match the
expected configuration value type - Long, Integer, Boolean,
String, etc.... If it doesn't, the toString() result of the
mapped value is used to convert it to the required type. E.g., if the
mapped value is the string "1234" and the expected value
is a long then it will be parsed into one. Also, if the mapped
value is an Integer but a long is expected, then it will
be converted into one.
getProperties in interface PropertyResolverMap containing configuration values, never
nullpublic <T> T getAttribute(AttributeStore.AttributeKey<T> key)
AttributeStoregetAttribute in interface AttributeStoreT - The generic attribute typekey - The key of the attribute; must not be null.public <T> T setAttribute(AttributeStore.AttributeKey<T> key, T value)
AttributeStoresetAttribute in interface AttributeStoreT - The generic attribute typekey - The key of the attribute; must not be null.value - The value of the attribute; must not be null.null if it is new.public <T> T removeAttribute(AttributeStore.AttributeKey<T> key)
AttributeStoreremoveAttribute in interface AttributeStoreT - The generic attribute typekey - The key of the attribute; must not be null.null if no previous valuepublic <T> T resolveAttribute(AttributeStore.AttributeKey<T> key)
AttributeStoreresolveAttribute in interface AttributeStoreT - The generic attribute typekey - The key of the attribute; must not be null.protected void configureWindow()
protected void sendWindowAdjust(long len)
throws IOException
IOExceptionCopyright © 2008–2017 The Apache Software Foundation. All rights reserved.