public abstract class AbstractConnectionService extends AbstractInnerCloseable implements ConnectionService
AbstractCloseable.State
SessionHeartbeatController.HeartbeatType
Modifier and Type | Field and Description |
---|---|
protected Map<Long,Channel> |
channels
Map of channels keyed by the identifier
|
static String |
DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
Used in
SSH_MSH_IGNORE messages for the keep-alive mechanism |
protected AtomicLong |
heartbeatCount |
protected AtomicLong |
nextChannelId
Next channel identifier - a UINT32 represented as a long
|
static IntUnaryOperator |
RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers
|
closeFuture, futureLock, state
log
EMPTY
Modifier | Constructor and Description |
---|---|
protected |
AbstractConnectionService(AbstractSession session) |
Modifier and Type | Method and Description |
---|---|
void |
addPortForwardingEventListener(PortForwardingEventListener listener)
Add a port forwarding listener
|
boolean |
addPortForwardingEventListenerManager(PortForwardingEventListenerManager manager) |
void |
channelClose(Buffer buffer)
Close a channel due to a close packet received
|
void |
channelData(Buffer buffer)
Process incoming data on a channel
|
void |
channelEof(Buffer buffer)
Process end of file on a channel
|
void |
channelExtendedData(Buffer buffer)
Process incoming extended data on a channel
|
void |
channelFailure(Buffer buffer)
Process a failure on a channel
|
protected void |
channelOpen(Buffer buffer) |
void |
channelOpenConfirmation(Buffer buffer) |
void |
channelOpenFailure(Buffer buffer) |
void |
channelRequest(Buffer buffer)
Service a request on a channel
|
void |
channelSuccess(Buffer buffer)
Process a success on a channel
|
void |
channelWindowAdjust(Buffer buffer)
Process a window adjust packet on a channel
|
protected AgentForwardSupport |
createAgentForwardSupport(Session session) |
protected Forwarder |
createForwardingFilter(Session session) |
protected X11ForwardSupport |
createX11ForwardSupport(Session session) |
protected void |
futureDone(IoWriteFuture future) |
AgentForwardSupport |
getAgentForwardSupport() |
protected Channel |
getChannel(byte cmd,
Buffer buffer)
Retrieve the channel designated by the given packet
|
protected Channel |
getChannel(byte cmd,
long recipient,
Buffer buffer) |
Collection<Channel> |
getChannels() |
Forwarder |
getForwarder()
Retrieve the forwarder instance
|
protected Closeable |
getInnerCloseable() |
protected long |
getNextChannelId() |
PortForwardingEventListener |
getPortForwardingEventListenerProxy() |
Map<String,Object> |
getProperties()
A map of properties that can be used to configure the SSH server or client.
|
Collection<PortForwardingEventListenerManager> |
getRegisteredManagers() |
AbstractSession |
getSession() |
UnknownChannelReferenceHandler |
getUnknownChannelReferenceHandler() |
X11ForwardSupport |
getX11ForwardSupport() |
protected IoWriteFuture |
globalRequest(Buffer buffer)
Process global requests
|
protected IoWriteFuture |
handleUnknownRequest(Buffer buffer,
String req,
boolean wantReply) |
boolean |
isAllowMoreSessions() |
protected void |
preClose()
preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.
|
void |
process(int cmd,
Buffer buffer)
Service the request.
|
long |
registerChannel(Channel channel)
Register a newly created channel with a new unique identifier
|
void |
removePortForwardingEventListener(PortForwardingEventListener listener)
Remove a port forwarding listener
|
boolean |
removePortForwardingEventListenerManager(PortForwardingEventListenerManager manager) |
protected void |
requestFailure(Buffer buffer) |
protected void |
requestSuccess(Buffer buffer) |
UnknownChannelReferenceHandler |
resolveUnknownChannelReferenceHandler()
Check if current manager has a specific handler set for it - if not, try and resolve one from the
"parent" container (if any)
|
protected IoWriteFuture |
sendChannelOpenFailure(Buffer buffer,
long sender,
int reasonCode,
String message,
String lang) |
protected IoWriteFuture |
sendGlobalResponse(Buffer buffer,
String req,
RequestHandler.Result result,
boolean wantReply) |
protected boolean |
sendHeartBeat()
Sends a heartbeat message/packet
|
void |
setAllowMoreSessions(boolean allow) |
void |
setUnknownChannelReferenceHandler(UnknownChannelReferenceHandler handler) |
void |
start() |
protected ScheduledFuture<?> |
startHeartBeat() |
protected void |
stopHeartBeat() |
String |
toString() |
void |
unregisterChannel(Channel channel)
Remove this channel from the list of managed channels
|
doCloseGracefully, doCloseImmediately
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getParentPropertyResolver
getSessionContext
addCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListener
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeat
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringProperty, isEmpty, isEmpty
public static final IntUnaryOperator RESPONSE_BUFFER_GROWTH_FACTOR
public static final String DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
SSH_MSH_IGNORE
messages for the keep-alive mechanismprotected final AtomicLong nextChannelId
protected final AtomicLong heartbeatCount
protected AbstractConnectionService(AbstractSession session)
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
. Note: may be
immutable.public PortForwardingEventListener getPortForwardingEventListenerProxy()
getPortForwardingEventListenerProxy
in interface PortForwardingEventListenerManager
public void addPortForwardingEventListener(PortForwardingEventListener listener)
PortForwardingEventListenerManager
addPortForwardingEventListener
in interface PortForwardingEventListenerManager
listener
- The PortForwardingEventListener
to add - never null
public void removePortForwardingEventListener(PortForwardingEventListener listener)
PortForwardingEventListenerManager
removePortForwardingEventListener
in interface PortForwardingEventListenerManager
listener
- The PortForwardingEventListener
to remove - ignored if null
public UnknownChannelReferenceHandler getUnknownChannelReferenceHandler()
getUnknownChannelReferenceHandler
in interface UnknownChannelReferenceHandlerManager
UnknownChannelReferenceHandlerManager
to use - if null
then any reference to unknown
channel causes an SshChannelNotFoundException
public void setUnknownChannelReferenceHandler(UnknownChannelReferenceHandler handler)
setUnknownChannelReferenceHandler
in interface UnknownChannelReferenceHandlerManager
handler
- The UnknownChannelReferenceHandlerManager
to use - if null
then any reference to
unknown channel causes an SshChannelNotFoundException
public Collection<PortForwardingEventListenerManager> getRegisteredManagers()
getRegisteredManagers
in interface PortForwardingEventListenerManagerHolder
public boolean addPortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
addPortForwardingEventListenerManager
in interface PortForwardingEventListenerManagerHolder
public boolean removePortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
removePortForwardingEventListenerManager
in interface PortForwardingEventListenerManagerHolder
public Collection<Channel> getChannels()
public AbstractSession getSession()
getSession
in interface SessionHolder<Session>
protected ScheduledFuture<?> startHeartBeat()
protected boolean sendHeartBeat()
true
if heartbeat successfully sentprotected void futureDone(IoWriteFuture future)
protected void stopHeartBeat()
public Forwarder getForwarder()
ConnectionService
getForwarder
in interface ConnectionService
Forwarder
protected void preClose()
AbstractCloseable
preClose
in class AbstractCloseable
public X11ForwardSupport getX11ForwardSupport()
getX11ForwardSupport
in interface ConnectionService
protected X11ForwardSupport createX11ForwardSupport(Session session)
public AgentForwardSupport getAgentForwardSupport()
getAgentForwardSupport
in interface ConnectionService
protected AgentForwardSupport createAgentForwardSupport(Session session)
protected Closeable getInnerCloseable()
getInnerCloseable
in class AbstractInnerCloseable
protected long getNextChannelId()
public long registerChannel(Channel channel) throws IOException
ConnectionService
registerChannel
in interface ConnectionService
channel
- The Channel
to registerlong
IOException
- If failed to initialize and register the channelpublic void unregisterChannel(Channel channel)
unregisterChannel
in interface ConnectionService
channel
- the channelpublic void process(int cmd, Buffer buffer) throws Exception
Service
public boolean isAllowMoreSessions()
isAllowMoreSessions
in interface ConnectionService
public void setAllowMoreSessions(boolean allow)
setAllowMoreSessions
in interface ConnectionService
public void channelOpenConfirmation(Buffer buffer) throws IOException
IOException
public void channelOpenFailure(Buffer buffer) throws IOException
IOException
public void channelData(Buffer buffer) throws IOException
buffer
- the buffer containing the dataIOException
- if an error occurspublic void channelExtendedData(Buffer buffer) throws IOException
buffer
- the buffer containing the dataIOException
- if an error occurspublic void channelWindowAdjust(Buffer buffer) throws IOException
buffer
- the buffer containing the window adjustment parametersIOException
- if an error occurspublic void channelEof(Buffer buffer) throws IOException
buffer
- the buffer containing the packetIOException
- if an error occurspublic void channelClose(Buffer buffer) throws IOException
buffer
- the buffer containing the packetIOException
- if an error occurspublic void channelRequest(Buffer buffer) throws IOException
buffer
- the buffer containing the requestIOException
- if an error occurspublic void channelFailure(Buffer buffer) throws IOException
buffer
- the buffer containing the packetIOException
- if an error occurspublic void channelSuccess(Buffer buffer) throws IOException
buffer
- the buffer containing the packetIOException
- if an error occursprotected Channel getChannel(byte cmd, Buffer buffer) throws IOException
cmd
- The command being processed for the channelbuffer
- the incoming packetIOException
- if the channel does not existsprotected Channel getChannel(byte cmd, long recipient, Buffer buffer) throws IOException
IOException
public UnknownChannelReferenceHandler resolveUnknownChannelReferenceHandler()
UnknownChannelReferenceHandlerManager
resolveUnknownChannelReferenceHandler
in interface UnknownChannelReferenceHandlerManager
protected IoWriteFuture sendChannelOpenFailure(Buffer buffer, long sender, int reasonCode, String message, String lang) throws IOException
IOException
protected IoWriteFuture globalRequest(Buffer buffer) throws Exception
buffer
- The request Buffer
IoWriteFuture
representing the sent packet - Note: if no reply sent then an
"empty" future is returned - i.e., any added listeners are triggered immediately with
a synthetic "success"Exception
- If failed to process the requestprotected IoWriteFuture handleUnknownRequest(Buffer buffer, String req, boolean wantReply) throws IOException
IOException
protected IoWriteFuture sendGlobalResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException
IOException
Copyright © 2008–2024 The Apache Software Foundation. All rights reserved.