public abstract class AbstractConnectionService extends AbstractInnerCloseable implements ConnectionService
AbstractCloseable.StateSessionHeartbeatController.HeartbeatType| Modifier and Type | Field and Description |
|---|---|
private java.util.concurrent.atomic.AtomicReference<AgentForwardSupport> |
agentForwardHolder |
private java.util.concurrent.atomic.AtomicBoolean |
allowMoreSessions |
protected java.util.Map<java.lang.Integer,Channel> |
channels
Map of channels keyed by the identifier
|
static int |
DEFAULT_MAX_CHANNELS
Default value for
MAX_CONCURRENT_CHANNELS_PROP is none specified |
static java.lang.String |
DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
Used in
SSH_MSH_IGNORE messages for the keep-alive mechanism |
private java.util.concurrent.atomic.AtomicReference<ForwardingFilter> |
forwarderHolder |
private java.util.concurrent.ScheduledFuture<?> |
heartBeat |
protected java.util.concurrent.atomic.AtomicLong |
heartbeatCount |
private PortForwardingEventListener |
listenerProxy |
private java.util.Collection<PortForwardingEventListener> |
listeners |
private java.util.Collection<PortForwardingEventListenerManager> |
managersHolder |
static java.lang.String |
MAX_CONCURRENT_CHANNELS_PROP
Property that can be used to configure max.
|
protected java.util.concurrent.atomic.AtomicInteger |
nextChannelId
Next channel identifier
|
private java.util.Map<java.lang.String,java.lang.Object> |
properties |
static java.util.function.IntUnaryOperator |
RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers
|
private AbstractSession |
sessionInstance |
private UnknownChannelReferenceHandler |
unknownChannelReferenceHandler |
private java.util.concurrent.atomic.AtomicReference<X11ForwardSupport> |
x11ForwardHolder |
closeFuture, futureLock, statelogCLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUTDEFAULT_CONNECTION_HEARTBEAT_INTERVAL, SESSION_HEARTBEAT_INTERVAL, SESSION_HEARTBEAT_TYPEEMPTY| 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 ForwardingFilter |
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,
int recipient,
Buffer buffer) |
java.util.Collection<Channel> |
getChannels() |
ForwardingFilter |
getForwardingFilter()
Retrieve the forwarder instance
|
protected Closeable |
getInnerCloseable() |
protected int |
getNextChannelId() |
PortForwardingEventListener |
getPortForwardingEventListenerProxy() |
java.util.Map<java.lang.String,java.lang.Object> |
getProperties()
A map of properties that can be used to configure the SSH server or client.
|
java.util.Collection<PortForwardingEventListenerManager> |
getRegisteredManagers() |
AbstractSession |
getSession() |
UnknownChannelReferenceHandler |
getUnknownChannelReferenceHandler() |
X11ForwardSupport |
getX11ForwardSupport() |
protected IoWriteFuture |
globalRequest(Buffer buffer)
Process global requests
|
protected void |
handleChannelRegistrationFailure(Channel channel,
int channelId) |
protected IoWriteFuture |
handleUnknownRequest(Buffer buffer,
java.lang.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.
|
int |
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,
int sender,
int reasonCode,
java.lang.String message,
java.lang.String lang) |
protected IoWriteFuture |
sendGlobalResponse(Buffer buffer,
java.lang.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 java.util.concurrent.ScheduledFuture<?> |
startHeartBeat() |
protected void |
stopHeartBeat() |
java.lang.String |
toString() |
void |
unregisterChannel(Channel channel)
Remove this channel from the list of managed channels
|
doCloseGracefully, doCloseImmediatelyaddCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenergetSimplifiedLoggerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetParentPropertyResolvergetSessionContextaddCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListenerdisableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatgetBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringPropertypublic static final java.lang.String MAX_CONCURRENT_CHANNELS_PROP
registerChannel(Channel),
Constant Field Valuespublic static final int DEFAULT_MAX_CHANNELS
MAX_CONCURRENT_CHANNELS_PROP is none specifiedpublic static final java.util.function.IntUnaryOperator RESPONSE_BUFFER_GROWTH_FACTOR
public static final java.lang.String DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
SSH_MSH_IGNORE messages for the keep-alive mechanismprotected final java.util.Map<java.lang.Integer,Channel> channels
protected final java.util.concurrent.atomic.AtomicInteger nextChannelId
protected final java.util.concurrent.atomic.AtomicLong heartbeatCount
private java.util.concurrent.ScheduledFuture<?> heartBeat
private final java.util.concurrent.atomic.AtomicReference<AgentForwardSupport> agentForwardHolder
private final java.util.concurrent.atomic.AtomicReference<X11ForwardSupport> x11ForwardHolder
private final java.util.concurrent.atomic.AtomicReference<ForwardingFilter> forwarderHolder
private final java.util.concurrent.atomic.AtomicBoolean allowMoreSessions
private final java.util.Collection<PortForwardingEventListener> listeners
private final java.util.Collection<PortForwardingEventListenerManager> managersHolder
private final java.util.Map<java.lang.String,java.lang.Object> properties
private final PortForwardingEventListener listenerProxy
private final AbstractSession sessionInstance
private UnknownChannelReferenceHandler unknownChannelReferenceHandler
protected AbstractConnectionService(AbstractSession session)
public java.util.Map<java.lang.String,java.lang.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 null. Note: may be
immutable.public PortForwardingEventListener getPortForwardingEventListenerProxy()
getPortForwardingEventListenerProxy in interface PortForwardingEventListenerManagerpublic void addPortForwardingEventListener(PortForwardingEventListener listener)
PortForwardingEventListenerManageraddPortForwardingEventListener in interface PortForwardingEventListenerManagerlistener - The PortForwardingEventListener to add - never nullpublic void removePortForwardingEventListener(PortForwardingEventListener listener)
PortForwardingEventListenerManagerremovePortForwardingEventListener in interface PortForwardingEventListenerManagerlistener - The PortForwardingEventListener to remove - ignored if nullpublic UnknownChannelReferenceHandler getUnknownChannelReferenceHandler()
getUnknownChannelReferenceHandler in interface UnknownChannelReferenceHandlerManagerUnknownChannelReferenceHandlerManager to use - if null then any reference to unknown
channel causes an SshChannelNotFoundExceptionpublic void setUnknownChannelReferenceHandler(UnknownChannelReferenceHandler handler)
setUnknownChannelReferenceHandler in interface UnknownChannelReferenceHandlerManagerhandler - The UnknownChannelReferenceHandlerManager to use - if null then any reference to
unknown channel causes an SshChannelNotFoundExceptionpublic java.util.Collection<PortForwardingEventListenerManager> getRegisteredManagers()
getRegisteredManagers in interface PortForwardingEventListenerManagerHolderpublic boolean addPortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
addPortForwardingEventListenerManager in interface PortForwardingEventListenerManagerHolderpublic boolean removePortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
removePortForwardingEventListenerManager in interface PortForwardingEventListenerManagerHolderpublic java.util.Collection<Channel> getChannels()
public AbstractSession getSession()
getSession in interface SessionHolder<Session>protected java.util.concurrent.ScheduledFuture<?> startHeartBeat()
protected boolean sendHeartBeat()
true if heartbeat successfully sentprotected void futureDone(IoWriteFuture future)
protected void stopHeartBeat()
public ForwardingFilter getForwardingFilter()
ConnectionServicegetForwardingFilter in interface ConnectionServiceForwardingFilterprotected void preClose()
AbstractCloseablepreClose in class AbstractCloseableprotected ForwardingFilter createForwardingFilter(Session session)
public X11ForwardSupport getX11ForwardSupport()
getX11ForwardSupport in interface ConnectionServiceprotected X11ForwardSupport createX11ForwardSupport(Session session)
public AgentForwardSupport getAgentForwardSupport()
getAgentForwardSupport in interface ConnectionServiceprotected AgentForwardSupport createAgentForwardSupport(Session session)
protected Closeable getInnerCloseable()
getInnerCloseable in class AbstractInnerCloseableprotected int getNextChannelId()
public int registerChannel(Channel channel) throws java.io.IOException
ConnectionServiceregisterChannel in interface ConnectionServicechannel - The Channel to registerjava.io.IOException - If failed to initialize and register the channelprotected void handleChannelRegistrationFailure(Channel channel, int channelId) throws java.io.IOException
java.io.IOExceptionpublic void unregisterChannel(Channel channel)
unregisterChannel in interface ConnectionServicechannel - the channelpublic void process(int cmd,
Buffer buffer)
throws java.lang.Exception
Servicepublic boolean isAllowMoreSessions()
isAllowMoreSessions in interface ConnectionServicepublic void setAllowMoreSessions(boolean allow)
setAllowMoreSessions in interface ConnectionServicepublic void channelOpenConfirmation(Buffer buffer) throws java.io.IOException
java.io.IOExceptionpublic void channelOpenFailure(Buffer buffer) throws java.io.IOException
java.io.IOExceptionpublic void channelData(Buffer buffer) throws java.io.IOException
buffer - the buffer containing the datajava.io.IOException - if an error occurspublic void channelExtendedData(Buffer buffer) throws java.io.IOException
buffer - the buffer containing the datajava.io.IOException - if an error occurspublic void channelWindowAdjust(Buffer buffer) throws java.io.IOException
buffer - the buffer containing the window adjustment parametersjava.io.IOException - if an error occurspublic void channelEof(Buffer buffer) throws java.io.IOException
buffer - the buffer containing the packetjava.io.IOException - if an error occurspublic void channelClose(Buffer buffer) throws java.io.IOException
buffer - the buffer containing the packetjava.io.IOException - if an error occurspublic void channelRequest(Buffer buffer) throws java.io.IOException
buffer - the buffer containing the requestjava.io.IOException - if an error occurspublic void channelFailure(Buffer buffer) throws java.io.IOException
buffer - the buffer containing the packetjava.io.IOException - if an error occurspublic void channelSuccess(Buffer buffer) throws java.io.IOException
buffer - the buffer containing the packetjava.io.IOException - if an error occursprotected Channel getChannel(byte cmd, Buffer buffer) throws java.io.IOException
cmd - The command being processed for the channelbuffer - the incoming packetjava.io.IOException - if the channel does not existsprotected Channel getChannel(byte cmd, int recipient, Buffer buffer) throws java.io.IOException
java.io.IOExceptionpublic UnknownChannelReferenceHandler resolveUnknownChannelReferenceHandler()
UnknownChannelReferenceHandlerManagerresolveUnknownChannelReferenceHandler in interface UnknownChannelReferenceHandlerManagerprotected void channelOpen(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionprotected IoWriteFuture sendChannelOpenFailure(Buffer buffer, int sender, int reasonCode, java.lang.String message, java.lang.String lang) throws java.io.IOException
java.io.IOExceptionprotected IoWriteFuture globalRequest(Buffer buffer) throws java.lang.Exception
buffer - The request BufferIoWriteFuture 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"java.lang.Exception - If failed to process the requestprotected IoWriteFuture handleUnknownRequest(Buffer buffer, java.lang.String req, boolean wantReply) throws java.io.IOException
java.io.IOExceptionprotected IoWriteFuture sendGlobalResponse(Buffer buffer, java.lang.String req, RequestHandler.Result result, boolean wantReply) throws java.io.IOException
java.io.IOExceptionprotected void requestSuccess(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionprotected void requestFailure(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionpublic java.lang.String toString()
toString in class java.lang.Object