public abstract class AbstractChannel extends AbstractInnerCloseable implements Channel, ExecutorServiceConfigurer
Modifier and Type | Class and Description |
---|---|
class |
AbstractChannel.GracefulChannelCloseable |
protected static class |
AbstractChannel.GracefulState |
AbstractCloseable.State
Modifier and Type | Field and Description |
---|---|
protected ChannelListener |
channelListenerProxy |
protected Collection<ChannelListener> |
channelListeners
Channel events listener
|
protected AtomicBoolean |
eof |
protected ExecutorService |
executor |
protected DefaultCloseFuture |
gracefulFuture |
protected AtomicReference<AbstractChannel.GracefulState> |
gracefulState |
protected List<RequestHandler<Channel>> |
handlers |
protected Window |
localWindow |
protected Window |
remoteWindow |
static Int2IntFunction |
RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers
|
protected ConnectionService |
service |
protected boolean |
shutdownExecutor |
closeFuture, lock, state
log
CHANNEL_EXEC, CHANNEL_SHELL, CHANNEL_SUBSYSTEM
Modifier | Constructor and Description |
---|---|
protected |
AbstractChannel(boolean client) |
protected |
AbstractChannel(String discriminator,
boolean client) |
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) |
protected void |
configureWindow() |
protected void |
doCloseImmediately()
doCloseImmediately is called once and only once
with state == Immediate
|
protected abstract void |
doWriteData(byte[] data,
int off,
int len) |
protected abstract void |
doWriteExtendedData(byte[] data,
int off,
int len) |
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() |
Session |
getSession() |
protected void |
handleChannelRequest(String req,
boolean wantReply,
Buffer buffer) |
void |
handleClose() |
void |
handleData(Buffer buffer) |
void |
handleEof() |
void |
handleExtendedData(Buffer buffer) |
void |
handleFailure()
Handle channel request failure
|
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) |
void |
handleSuccess()
Handle channel request success
|
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) |
void |
init(ConnectionService service,
Session session,
int id) |
boolean |
isEofSignalled() |
boolean |
isShutdownOnExit() |
protected void |
notifyStateChanged() |
protected void |
preClose()
preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.
|
void |
removeChannelListener(ChannelListener listener)
Remove a channel listener
|
protected Date |
removePendingRequest(String request)
Removes a channel request from the tracked ones
|
protected void |
sendEof() |
protected void |
sendResponse(Buffer buffer,
String req,
RequestHandler.Result result,
boolean wantReply) |
protected void |
sendWindowAdjust(int len) |
void |
setEofSignalled(boolean on) |
void |
setExecutorService(ExecutorService service) |
protected void |
setRecipient(int recipient) |
void |
setShutdownOnExit(boolean shutdown) |
String |
toString() |
protected void |
writePacket(Buffer buffer) |
doCloseGracefully
builder, close, isClosed, isClosing
close, isOpen
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
handleOpenFailure, handleOpenSuccess, open
public static final Int2IntFunction RESPONSE_BUFFER_GROWTH_FACTOR
protected ExecutorService executor
protected boolean shutdownExecutor
protected final Window localWindow
protected final Window remoteWindow
protected ConnectionService service
protected final AtomicBoolean eof
protected AtomicReference<AbstractChannel.GracefulState> gracefulState
protected final DefaultCloseFuture gracefulFuture
protected final List<RequestHandler<Channel>> handlers
protected final Collection<ChannelListener> channelListeners
protected final ChannelListener channelListenerProxy
protected AbstractChannel(boolean client)
protected AbstractChannel(String discriminator, boolean client)
public void addRequestHandler(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 PropertyResolver
null
if no parentpublic ExecutorService getExecutorService()
getExecutorService
in interface ExecutorServiceCarrier
public void setExecutorService(ExecutorService service)
setExecutorService
in interface ExecutorServiceConfigurer
public boolean isShutdownOnExit()
isShutdownOnExit
in interface ExecutorServiceCarrier
true
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 ExecutorServiceConfigurer
protected 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
IOException
protected void handleChannelRequest(String req, boolean wantReply, Buffer buffer) throws IOException
IOException
protected 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 void sendResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException
IOException
public void init(ConnectionService service, Session session, int id) throws IOException
IOException
protected void notifyStateChanged()
public void addChannelListener(ChannelListener listener)
ChannelListenerManager
addChannelListener
in interface ChannelListenerManager
listener
- The ChannelListener
to add - not null
public void removeChannelListener(ChannelListener listener)
ChannelListenerManager
removeChannelListener
in interface ChannelListenerManager
listener
- The ChannelListener
to removepublic ChannelListener getChannelListenerProxy()
getChannelListenerProxy
in interface ChannelListenerManager
null
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
IOException
protected Closeable getInnerCloseable()
getInnerCloseable
in class AbstractInnerCloseable
protected void preClose()
AbstractCloseable
preClose
in class AbstractCloseable
protected void doCloseImmediately()
AbstractCloseable
doCloseImmediately 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 AbstractInnerCloseable
protected void writePacket(Buffer buffer) throws IOException
IOException
public void handleData(Buffer buffer) throws IOException
IOException
public void handleExtendedData(Buffer buffer) throws IOException
IOException
public boolean isEofSignalled()
public void setEofSignalled(boolean on)
public void handleEof() throws IOException
IOException
public void handleWindowAdjust(Buffer buffer) throws IOException
IOException
public void handleSuccess() throws IOException
Channel
IOException
- If failed to handlepublic void handleFailure() throws IOException
Channel
IOException
- If failed to handleprotected abstract void doWriteData(byte[] data, int off, int len) throws IOException
IOException
protected abstract void doWriteExtendedData(byte[] data, int off, int len) throws IOException
IOException
protected void sendEof() throws IOException
IOException
public Map<String,Object> getProperties()
PropertyResolver
A 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 PropertyResolver
Map
containing configuration values, never null
protected void configureWindow()
protected void sendWindowAdjust(int len) throws IOException
IOException
Copyright © 2008–2016 The Apache Software Foundation. All rights reserved.