Class AbstractConnectionService
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.common.util.closeable.IoBaseCloseable
-
- org.apache.sshd.common.util.closeable.AbstractCloseable
-
- org.apache.sshd.common.util.closeable.AbstractInnerCloseable
-
- org.apache.sshd.common.session.helpers.AbstractConnectionService
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Channel
,Closeable
,PortForwardingEventListenerManager
,PortForwardingEventListenerManagerHolder
,PropertyResolver
,Service
,ConnectionService
,SessionContextHolder
,SessionHeartbeatController
,SessionHolder<Session>
,UnknownChannelReferenceHandlerManager
- Direct Known Subclasses:
ClientConnectionService
,ServerConnectionService
public abstract class AbstractConnectionService extends AbstractInnerCloseable implements ConnectionService
Base implementation of ConnectionService.- Author:
- Apache MINA SSHD Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
SessionHeartbeatController.HeartbeatType
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Integer,Channel>
channels
Map of channels keyed by the identifierstatic int
DEFAULT_MAX_CHANNELS
Default value forMAX_CONCURRENT_CHANNELS_PROP
is none specifiedstatic String
DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
Used inSSH_MSH_IGNORE
messages for the keep-alive mechanismprotected AtomicLong
heartbeatCount
static String
MAX_CONCURRENT_CHANNELS_PROP
Property that can be used to configure max.protected AtomicInteger
nextChannelId
Next channel identifierstatic IntUnaryOperator
RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers-
Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, state
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields inherited from interface org.apache.sshd.common.Closeable
CLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUT
-
Fields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY
-
Fields inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
DEFAULT_CONNECTION_HEARTBEAT_INTERVAL, SESSION_HEARTBEAT_INTERVAL, SESSION_HEARTBEAT_TYPE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConnectionService(AbstractSession session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPortForwardingEventListener(PortForwardingEventListener listener)
Add a port forwarding listenerboolean
addPortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
void
channelClose(Buffer buffer)
Close a channel due to a close packet receivedvoid
channelData(Buffer buffer)
Process incoming data on a channelvoid
channelEof(Buffer buffer)
Process end of file on a channelvoid
channelExtendedData(Buffer buffer)
Process incoming extended data on a channelvoid
channelFailure(Buffer buffer)
Process a failure on a channelprotected void
channelOpen(Buffer buffer)
void
channelOpenConfirmation(Buffer buffer)
void
channelOpenFailure(Buffer buffer)
void
channelRequest(Buffer buffer)
Service a request on a channelvoid
channelSuccess(Buffer buffer)
Process a success on a channelvoid
channelWindowAdjust(Buffer buffer)
Process a window adjust packet on a channelprotected 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, int recipient, Buffer buffer)
protected Channel
getChannel(byte cmd, Buffer buffer)
Retrieve the channel designated by the given packetCollection<Channel>
getChannels()
ForwardingFilter
getForwardingFilter()
Retrieve the forwarder instanceprotected Closeable
getInnerCloseable()
protected int
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 requestsprotected void
handleChannelRegistrationFailure(Channel channel, int channelId)
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.int
registerChannel(Channel channel)
Register a newly created channel with a new unique identifiervoid
removePortForwardingEventListener(PortForwardingEventListener listener)
Remove a port forwarding listenerboolean
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, String message, String lang)
protected IoWriteFuture
sendGlobalResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply)
protected boolean
sendHeartBeat()
Sends a heartbeat message/packetvoid
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-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediately
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListener
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
getSimplifiedLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
Methods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringProperty
-
Methods inherited from interface org.apache.sshd.common.Service
getParentPropertyResolver
-
Methods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
-
-
-
Field Detail
-
MAX_CONCURRENT_CHANNELS_PROP
public static final String MAX_CONCURRENT_CHANNELS_PROP
Property that can be used to configure max. allowed concurrent active channels- See Also:
registerChannel(Channel)
, Constant Field Values
-
DEFAULT_MAX_CHANNELS
public static final int DEFAULT_MAX_CHANNELS
Default value forMAX_CONCURRENT_CHANNELS_PROP
is none specified- See Also:
- Constant Field Values
-
RESPONSE_BUFFER_GROWTH_FACTOR
public static final IntUnaryOperator RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers
-
DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
public static final String DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
Used inSSH_MSH_IGNORE
messages for the keep-alive mechanism- See Also:
- Constant Field Values
-
nextChannelId
protected final AtomicInteger nextChannelId
Next channel identifier
-
heartbeatCount
protected final AtomicLong heartbeatCount
-
-
Constructor Detail
-
AbstractConnectionService
protected AbstractConnectionService(AbstractSession session)
-
-
Method Detail
-
getProperties
public Map<String,Object> getProperties()
Description copied from interface: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, thetoString()
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 along
then it will be parsed into one. Also, if the mapped value is anInteger
but along
is expected, then it will be converted into one.- Specified by:
getProperties
in interfacePropertyResolver
- Returns:
- a valid
Map
containing configuration values, nevernull
. Note: may be immutable.
-
getPortForwardingEventListenerProxy
public PortForwardingEventListener getPortForwardingEventListenerProxy()
- Specified by:
getPortForwardingEventListenerProxy
in interfacePortForwardingEventListenerManager
- Returns:
- A proxy listener representing all the currently registered listener through this manager
-
addPortForwardingEventListener
public void addPortForwardingEventListener(PortForwardingEventListener listener)
Description copied from interface:PortForwardingEventListenerManager
Add a port forwarding listener- Specified by:
addPortForwardingEventListener
in interfacePortForwardingEventListenerManager
- Parameters:
listener
- ThePortForwardingEventListener
to add - nevernull
-
removePortForwardingEventListener
public void removePortForwardingEventListener(PortForwardingEventListener listener)
Description copied from interface:PortForwardingEventListenerManager
Remove a port forwarding listener- Specified by:
removePortForwardingEventListener
in interfacePortForwardingEventListenerManager
- Parameters:
listener
- ThePortForwardingEventListener
to remove - ignored ifnull
-
getUnknownChannelReferenceHandler
public UnknownChannelReferenceHandler getUnknownChannelReferenceHandler()
- Specified by:
getUnknownChannelReferenceHandler
in interfaceUnknownChannelReferenceHandlerManager
- Returns:
- The
UnknownChannelReferenceHandlerManager
to use - ifnull
then any reference to unknown channel causes anSshChannelNotFoundException
-
setUnknownChannelReferenceHandler
public void setUnknownChannelReferenceHandler(UnknownChannelReferenceHandler handler)
- Specified by:
setUnknownChannelReferenceHandler
in interfaceUnknownChannelReferenceHandlerManager
- Parameters:
handler
- TheUnknownChannelReferenceHandlerManager
to use - ifnull
then any reference to unknown channel causes anSshChannelNotFoundException
-
getRegisteredManagers
public Collection<PortForwardingEventListenerManager> getRegisteredManagers()
- Specified by:
getRegisteredManagers
in interfacePortForwardingEventListenerManagerHolder
- Returns:
- The currently registered managers. Note: it is highly recommended that implementors return either an un-modifiable collection or a copy of the current one. Callers, should avoid modifying the retrieved value.
-
addPortForwardingEventListenerManager
public boolean addPortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
- Specified by:
addPortForwardingEventListenerManager
in interfacePortForwardingEventListenerManagerHolder
-
removePortForwardingEventListenerManager
public boolean removePortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
- Specified by:
removePortForwardingEventListenerManager
in interfacePortForwardingEventListenerManagerHolder
-
getChannels
public Collection<Channel> getChannels()
-
getSession
public AbstractSession getSession()
- Specified by:
getSession
in interfaceSessionHolder<Session>
-
startHeartBeat
protected ScheduledFuture<?> startHeartBeat()
-
sendHeartBeat
protected boolean sendHeartBeat()
Sends a heartbeat message/packet- Returns:
true
if heartbeat successfully sent
-
futureDone
protected void futureDone(IoWriteFuture future)
-
stopHeartBeat
protected void stopHeartBeat()
-
getForwardingFilter
public ForwardingFilter getForwardingFilter()
Description copied from interface:ConnectionService
Retrieve the forwarder instance- Specified by:
getForwardingFilter
in interfaceConnectionService
- Returns:
- The
ForwardingFilter
-
preClose
protected void preClose()
Description copied from class:AbstractCloseable
preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately. When preClose() is called, isClosing() == true- Overrides:
preClose
in classAbstractCloseable
-
createForwardingFilter
protected ForwardingFilter createForwardingFilter(Session session)
-
getX11ForwardSupport
public X11ForwardSupport getX11ForwardSupport()
- Specified by:
getX11ForwardSupport
in interfaceConnectionService
-
createX11ForwardSupport
protected X11ForwardSupport createX11ForwardSupport(Session session)
-
getAgentForwardSupport
public AgentForwardSupport getAgentForwardSupport()
- Specified by:
getAgentForwardSupport
in interfaceConnectionService
-
createAgentForwardSupport
protected AgentForwardSupport createAgentForwardSupport(Session session)
-
getInnerCloseable
protected Closeable getInnerCloseable()
- Specified by:
getInnerCloseable
in classAbstractInnerCloseable
-
getNextChannelId
protected int getNextChannelId()
-
registerChannel
public int registerChannel(Channel channel) throws IOException
Description copied from interface:ConnectionService
Register a newly created channel with a new unique identifier- Specified by:
registerChannel
in interfaceConnectionService
- Parameters:
channel
- TheChannel
to register- Returns:
- The assigned id of this channel
- Throws:
IOException
- If failed to initialize and register the channel
-
handleChannelRegistrationFailure
protected void handleChannelRegistrationFailure(Channel channel, int channelId) throws IOException
- Throws:
IOException
-
unregisterChannel
public void unregisterChannel(Channel channel)
Remove this channel from the list of managed channels- Specified by:
unregisterChannel
in interfaceConnectionService
- Parameters:
channel
- the channel
-
process
public void process(int cmd, Buffer buffer) throws Exception
Description copied from interface:Service
Service the request.
-
isAllowMoreSessions
public boolean isAllowMoreSessions()
- Specified by:
isAllowMoreSessions
in interfaceConnectionService
-
setAllowMoreSessions
public void setAllowMoreSessions(boolean allow)
- Specified by:
setAllowMoreSessions
in interfaceConnectionService
-
channelOpenConfirmation
public void channelOpenConfirmation(Buffer buffer) throws IOException
- Throws:
IOException
-
channelOpenFailure
public void channelOpenFailure(Buffer buffer) throws IOException
- Throws:
IOException
-
channelData
public void channelData(Buffer buffer) throws IOException
Process incoming data on a channel- Parameters:
buffer
- the buffer containing the data- Throws:
IOException
- if an error occurs
-
channelExtendedData
public void channelExtendedData(Buffer buffer) throws IOException
Process incoming extended data on a channel- Parameters:
buffer
- the buffer containing the data- Throws:
IOException
- if an error occurs
-
channelWindowAdjust
public void channelWindowAdjust(Buffer buffer) throws IOException
Process a window adjust packet on a channel- Parameters:
buffer
- the buffer containing the window adjustment parameters- Throws:
IOException
- if an error occurs
-
channelEof
public void channelEof(Buffer buffer) throws IOException
Process end of file on a channel- Parameters:
buffer
- the buffer containing the packet- Throws:
IOException
- if an error occurs
-
channelClose
public void channelClose(Buffer buffer) throws IOException
Close a channel due to a close packet received- Parameters:
buffer
- the buffer containing the packet- Throws:
IOException
- if an error occurs
-
channelRequest
public void channelRequest(Buffer buffer) throws IOException
Service a request on a channel- Parameters:
buffer
- the buffer containing the request- Throws:
IOException
- if an error occurs
-
channelFailure
public void channelFailure(Buffer buffer) throws IOException
Process a failure on a channel- Parameters:
buffer
- the buffer containing the packet- Throws:
IOException
- if an error occurs
-
channelSuccess
public void channelSuccess(Buffer buffer) throws IOException
Process a success on a channel- Parameters:
buffer
- the buffer containing the packet- Throws:
IOException
- if an error occurs
-
getChannel
protected Channel getChannel(byte cmd, Buffer buffer) throws IOException
Retrieve the channel designated by the given packet- Parameters:
cmd
- The command being processed for the channelbuffer
- the incoming packet- Returns:
- the target channel
- Throws:
IOException
- if the channel does not exists
-
getChannel
protected Channel getChannel(byte cmd, int recipient, Buffer buffer) throws IOException
- Throws:
IOException
-
resolveUnknownChannelReferenceHandler
public UnknownChannelReferenceHandler resolveUnknownChannelReferenceHandler()
Description copied from interface:UnknownChannelReferenceHandlerManager
Check if current manager has a specific handler set for it - if not, try and resolve one from the "parent" container (if any)- Specified by:
resolveUnknownChannelReferenceHandler
in interfaceUnknownChannelReferenceHandlerManager
- Returns:
- The resolved handler instance
-
sendChannelOpenFailure
protected IoWriteFuture sendChannelOpenFailure(Buffer buffer, int sender, int reasonCode, String message, String lang) throws IOException
- Throws:
IOException
-
globalRequest
protected IoWriteFuture globalRequest(Buffer buffer) throws Exception
Process global requests- Parameters:
buffer
- The requestBuffer
- Returns:
- An
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" - Throws:
Exception
- If failed to process the request
-
handleUnknownRequest
protected IoWriteFuture handleUnknownRequest(Buffer buffer, String req, boolean wantReply) throws IOException
- Throws:
IOException
-
sendGlobalResponse
protected IoWriteFuture sendGlobalResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException
- Throws:
IOException
-
-