Class AbstractConnectionService
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,Closeable,PortForwardingEventListenerManager,PortForwardingEventListenerManagerHolder,PropertyResolver,Service,ConnectionService,SessionContextHolder,SessionHeartbeatController,SessionHolder<Session>,UnknownChannelReferenceHandlerManager
- Direct Known Subclasses:
ClientConnectionService,ServerConnectionService
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.StateNested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
SessionHeartbeatController.HeartbeatType -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicReference<AgentForwardSupport> private final AtomicBooleanMap of channels keyed by the identifierstatic final StringUsed inSSH_MSH_IGNOREmessages for the keep-alive mechanismprivate final AtomicReference<Forwarder> private ScheduledFuture<?> protected final AtomicLongprivate final PortForwardingEventListenerprivate final Collection<PortForwardingEventListener> private final Collection<PortForwardingEventListenerManager> protected final AtomicLongNext channel identifier - a UINT32 represented as a longstatic final IntUnaryOperatorDefault growth factor function used to resize response buffersprivate final AbstractSessionprivate UnknownChannelReferenceHandlerprivate final AtomicReference<X11ForwardSupport> Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, stateFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a port forwarding listenerbooleanvoidchannelClose(Buffer buffer) Close a channel due to a close packet receivedvoidchannelData(Buffer buffer) Process incoming data on a channelvoidchannelEof(Buffer buffer) Process end of file on a channelvoidchannelExtendedData(Buffer buffer) Process incoming extended data on a channelvoidchannelFailure(Buffer buffer) Process a failure on a channelprotected voidchannelOpen(Buffer buffer) voidchannelOpenConfirmation(Buffer buffer) voidchannelOpenFailure(Buffer buffer) voidchannelRequest(Buffer buffer) Service a request on a channelvoidchannelSuccess(Buffer buffer) Process a success on a channelvoidchannelWindowAdjust(Buffer buffer) Process a window adjust packet on a channelprotected AgentForwardSupportcreateAgentForwardSupport(Session session) protected ForwardercreateForwardingFilter(Session session) protected X11ForwardSupportcreateX11ForwardSupport(Session session) protected voidfutureDone(IoWriteFuture future) protected ChannelgetChannel(byte cmd, long recipient, Buffer buffer) protected ChannelgetChannel(byte cmd, Buffer buffer) Retrieve the channel designated by the given packetRetrieve the forwarder instanceprotected Closeableprotected longA map of properties that can be used to configure the SSH server or client.protected IoWriteFutureglobalRequest(Buffer buffer) Process global requestsprotected IoWriteFuturehandleUnknownRequest(Buffer buffer, String req, boolean wantReply) booleanprotected voidpreClose()preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.voidService the request.longregisterChannel(Channel channel) Register a newly created channel with a new unique identifiervoidRemove a port forwarding listenerbooleanprotected voidrequestFailure(Buffer buffer) protected voidrequestSuccess(Buffer buffer) Check if current manager has a specific handler set for it - if not, try and resolve one from the "parent" container (if any)protected IoWriteFuturesendChannelOpenFailure(Buffer buffer, long sender, int reasonCode, String message, String lang) protected IoWriteFuturesendGlobalResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) protected booleanSends a heartbeat message/packetvoidsetAllowMoreSessions(boolean allow) voidvoidstart()protected ScheduledFuture<?> protected voidtoString()voidunregisterChannel(Channel channel) Remove this channel from the list of managed channelsMethods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediatelyMethods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, removeCloseFutureListenerMethods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListenerMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringProperty, isEmptyMethods inherited from interface org.apache.sshd.common.Service
getParentPropertyResolverMethods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatMethods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
Field Details
-
RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers -
DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
Used inSSH_MSH_IGNOREmessages for the keep-alive mechanism- See Also:
-
channels
Map of channels keyed by the identifier -
nextChannelId
Next channel identifier - a UINT32 represented as a long -
heartbeatCount
-
heartBeat
-
agentForwardHolder
-
x11ForwardHolder
-
forwarderHolder
-
allowMoreSessions
-
listeners
-
managersHolder
-
properties
-
listenerProxy
-
sessionInstance
-
unknownChannelReferenceHandler
-
-
Constructor Details
-
AbstractConnectionService
-
-
Method Details
-
getProperties
Description copied from interface: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, 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 alongthen it will be parsed into one. Also, if the mapped value is anIntegerbut alongis expected, then it will be converted into one.- Specified by:
getPropertiesin interfacePropertyResolver- Returns:
- a valid
Mapcontaining configuration values, nevernull. Note: may be immutable.
-
getPortForwardingEventListenerProxy
- Specified by:
getPortForwardingEventListenerProxyin interfacePortForwardingEventListenerManager- Returns:
- A proxy listener representing all the currently registered listener through this manager
-
addPortForwardingEventListener
Description copied from interface:PortForwardingEventListenerManagerAdd a port forwarding listener- Specified by:
addPortForwardingEventListenerin interfacePortForwardingEventListenerManager- Parameters:
listener- ThePortForwardingEventListenerto add - nevernull
-
removePortForwardingEventListener
Description copied from interface:PortForwardingEventListenerManagerRemove a port forwarding listener- Specified by:
removePortForwardingEventListenerin interfacePortForwardingEventListenerManager- Parameters:
listener- ThePortForwardingEventListenerto remove - ignored ifnull
-
getUnknownChannelReferenceHandler
- Specified by:
getUnknownChannelReferenceHandlerin interfaceUnknownChannelReferenceHandlerManager- Returns:
- The
UnknownChannelReferenceHandlerManagerto use - ifnullthen any reference to unknown channel causes anSshChannelNotFoundException
-
setUnknownChannelReferenceHandler
- Specified by:
setUnknownChannelReferenceHandlerin interfaceUnknownChannelReferenceHandlerManager- Parameters:
handler- TheUnknownChannelReferenceHandlerManagerto use - ifnullthen any reference to unknown channel causes anSshChannelNotFoundException
-
getRegisteredManagers
- Specified by:
getRegisteredManagersin 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
- Specified by:
addPortForwardingEventListenerManagerin interfacePortForwardingEventListenerManagerHolder
-
removePortForwardingEventListenerManager
- Specified by:
removePortForwardingEventListenerManagerin interfacePortForwardingEventListenerManagerHolder
-
getChannels
-
getSession
- Specified by:
getSessionin interfaceSessionHolder<Session>
-
start
public void start() -
startHeartBeat
-
sendHeartBeat
protected boolean sendHeartBeat()Sends a heartbeat message/packet- Returns:
trueif heartbeat successfully sent
-
futureDone
-
stopHeartBeat
protected void stopHeartBeat() -
getForwarder
Description copied from interface:ConnectionServiceRetrieve the forwarder instance- Specified by:
getForwarderin interfaceConnectionService- Returns:
- The
Forwarder
-
preClose
protected void preClose()Description copied from class:AbstractCloseablepreClose is guaranteed to be called before doCloseGracefully or doCloseImmediately. When preClose() is called, isClosing() == true- Overrides:
preClosein classAbstractCloseable
-
createForwardingFilter
-
getX11ForwardSupport
- Specified by:
getX11ForwardSupportin interfaceConnectionService
-
createX11ForwardSupport
-
getAgentForwardSupport
- Specified by:
getAgentForwardSupportin interfaceConnectionService
-
createAgentForwardSupport
-
getInnerCloseable
- Specified by:
getInnerCloseablein classAbstractInnerCloseable
-
getNextChannelId
protected long getNextChannelId() -
registerChannel
Description copied from interface:ConnectionServiceRegister a newly created channel with a new unique identifier- Specified by:
registerChannelin interfaceConnectionService- Parameters:
channel- TheChannelto register- Returns:
- The assigned id of this channel - a UINT32 represented as a
long - Throws:
IOException- If failed to initialize and register the channel
-
unregisterChannel
Remove this channel from the list of managed channels- Specified by:
unregisterChannelin interfaceConnectionService- Parameters:
channel- the channel
-
process
Description copied from interface:ServiceService the request. -
isAllowMoreSessions
public boolean isAllowMoreSessions()- Specified by:
isAllowMoreSessionsin interfaceConnectionService
-
setAllowMoreSessions
public void setAllowMoreSessions(boolean allow) - Specified by:
setAllowMoreSessionsin interfaceConnectionService
-
channelOpenConfirmation
- Throws:
IOException
-
channelOpenFailure
- Throws:
IOException
-
channelData
Process incoming data on a channel- Parameters:
buffer- the buffer containing the data- Throws:
IOException- if an error occurs
-
channelExtendedData
Process incoming extended data on a channel- Parameters:
buffer- the buffer containing the data- Throws:
IOException- if an error occurs
-
channelWindowAdjust
Process a window adjust packet on a channel- Parameters:
buffer- the buffer containing the window adjustment parameters- Throws:
IOException- if an error occurs
-
channelEof
Process end of file on a channel- Parameters:
buffer- the buffer containing the packet- Throws:
IOException- if an error occurs
-
channelClose
Close a channel due to a close packet received- Parameters:
buffer- the buffer containing the packet- Throws:
IOException- if an error occurs
-
channelRequest
Service a request on a channel- Parameters:
buffer- the buffer containing the request- Throws:
IOException- if an error occurs
-
channelFailure
Process a failure on a channel- Parameters:
buffer- the buffer containing the packet- Throws:
IOException- if an error occurs
-
channelSuccess
Process a success on a channel- Parameters:
buffer- the buffer containing the packet- Throws:
IOException- if an error occurs
-
getChannel
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
- Throws:
IOException
-
resolveUnknownChannelReferenceHandler
Description copied from interface:UnknownChannelReferenceHandlerManagerCheck if current manager has a specific handler set for it - if not, try and resolve one from the "parent" container (if any)- Specified by:
resolveUnknownChannelReferenceHandlerin interfaceUnknownChannelReferenceHandlerManager- Returns:
- The resolved handler instance
-
channelOpen
- Throws:
Exception
-
sendChannelOpenFailure
protected IoWriteFuture sendChannelOpenFailure(Buffer buffer, long sender, int reasonCode, String message, String lang) throws IOException - Throws:
IOException
-
globalRequest
Process global requests- Parameters:
buffer- The requestBuffer- Returns:
- An
IoWriteFuturerepresenting 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
-
requestSuccess
- Throws:
Exception
-
requestFailure
- Throws:
Exception
-
toString
-