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, EventListener, org.apache.sshd.common.Closeable, PortForwardingEventListenerManager, PortForwardingEventListenerManagerHolder, org.apache.sshd.common.PropertyResolver, Service, ConnectionService, ReservedSessionMessagesHandler, org.apache.sshd.common.session.SessionContextHolder, org.apache.sshd.common.session.SessionHeartbeatController, SessionHolder<Session>, UnknownChannelReferenceHandlerManager, org.apache.sshd.common.util.SshdEventListener
- Direct Known Subclasses:
ClientConnectionService, ServerConnectionService
public abstract class AbstractConnectionService
extends org.apache.sshd.common.util.closeable.AbstractInnerCloseable
implements ConnectionService, ReservedSessionMessagesHandler
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
org.apache.sshd.common.util.closeable.AbstractCloseable.StateNested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
org.apache.sshd.common.session.SessionHeartbeatController.HeartbeatType -
Field Summary
FieldsModifier and TypeFieldDescriptionMap of channels keyed by the identifierstatic final StringUsed inSSH_MSH_IGNOREmessages for the keep-alive mechanismprotected final AtomicLongprotected final AtomicLongNext channel identifier - a UINT32 represented as a longstatic final IntUnaryOperatorDefault growth factor function used to resize response buffersFields 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(org.apache.sshd.common.util.buffer.Buffer buffer) Close a channel due to a close packet receivedvoidchannelData(org.apache.sshd.common.util.buffer.Buffer buffer) Process incoming data on a channelvoidchannelEof(org.apache.sshd.common.util.buffer.Buffer buffer) Process end of file on a channelvoidchannelExtendedData(org.apache.sshd.common.util.buffer.Buffer buffer) Process incoming extended data on a channelvoidchannelFailure(org.apache.sshd.common.util.buffer.Buffer buffer) Process a failure on a channelprotected voidchannelOpen(org.apache.sshd.common.util.buffer.Buffer buffer) voidchannelOpenConfirmation(org.apache.sshd.common.util.buffer.Buffer buffer) voidchannelOpenFailure(org.apache.sshd.common.util.buffer.Buffer buffer) voidchannelRequest(org.apache.sshd.common.util.buffer.Buffer buffer) Service a request on a channelvoidchannelSuccess(org.apache.sshd.common.util.buffer.Buffer buffer) Process a success on a channelvoidchannelWindowAdjust(org.apache.sshd.common.util.buffer.Buffer buffer) Process a window adjust packet on a channelprotected AgentForwardSupportcreateAgentForwardSupport(Session session) protected ForwardercreateForwardingFilter(Session session) protected X11ForwardSupportcreateX11ForwardSupport(Session session) protected voidfutureDone(org.apache.sshd.common.future.HasException future) protected ChannelgetChannel(byte cmd, long recipient, org.apache.sshd.common.util.buffer.Buffer buffer) protected ChannelgetChannel(byte cmd, org.apache.sshd.common.util.buffer.Buffer buffer) Retrieve the channel designated by the given packetRetrieve the forwarder instanceprotected org.apache.sshd.common.Closeableprotected longprotected org.apache.sshd.common.io.IoWriteFutureglobalRequest(org.apache.sshd.common.util.buffer.Buffer buffer) Process global requestsbooleanhandleUnimplementedMessage(Session session, int cmd, org.apache.sshd.common.util.buffer.Buffer buffer) Invoked when a packet with an un-implemented message is received - includingSSH_MSG_UNIMPLEMENTEDitselfprotected org.apache.sshd.common.io.IoWriteFuturehandleUnknownRequest(org.apache.sshd.common.util.buffer.Buffer buffer, String req, boolean wantReply) booleanprotected voidpreClose()voidprocess(int cmd, org.apache.sshd.common.util.buffer.Buffer buffer) Service the request.longregisterChannel(Channel channel) Register a newly created channel with a new unique identifiervoidRemove a port forwarding listenerbooleanorg.apache.sshd.common.util.buffer.BufferSend a global request and wait for the response, if the request is sent withwant-reply = true.request(org.apache.sshd.common.util.buffer.Buffer buffer, String request, GlobalRequestFuture.ReplyHandler replyHandler) Send a global request and handle the reply asynchronously.protected voidrequestFailure(org.apache.sshd.common.util.buffer.Buffer buffer) Indicates the reception of aSSH_MSG_REQUEST_FAILUREmessageprotected voidrequestSuccess(org.apache.sshd.common.util.buffer.Buffer buffer) Indicates the reception of aSSH_MSG_REQUEST_SUCCESSmessageCheck if current manager has a specific handler set for it - if not, try and resolve one from the "parent" container (if any)protected org.apache.sshd.common.io.IoWriteFuturesendChannelOpenFailure(org.apache.sshd.common.util.buffer.Buffer buffer, long sender, int reasonCode, String message, String lang) protected org.apache.sshd.common.io.IoWriteFuturesendGlobalResponse(org.apache.sshd.common.util.buffer.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 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 ConnectionService
request, requestMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringProperty, isEmptyMethods inherited from interface ReservedSessionMessagesHandler
handleDebugMessage, handleIgnoreMessage, sendIdentification, sendKexInitRequest, sendReservedHeartbeatMethods inherited from interface Service
getParentPropertyResolverMethods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatMethods inherited from interface 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
-
nextChannelId
Next channel identifier - a UINT32 represented as a long -
heartbeatCount
-
-
Constructor Details
-
AbstractConnectionService
-
-
Method Details
-
getProperties
-
getPortForwardingEventListenerProxy
- Specified by:
getPortForwardingEventListenerProxyin interfacePortForwardingEventListenerManager- Returns:
- A proxy listener representing all the currently registered listeners in 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
-
startHeartBeat
-
sendHeartBeat
protected boolean sendHeartBeat()Sends a heartbeat message/packet- Returns:
trueif heartbeat successfully sent
-
futureDone
protected void futureDone(org.apache.sshd.common.future.HasException future) -
stopHeartBeat
protected void stopHeartBeat() -
getForwarder
Description copied from interface:ConnectionServiceRetrieve the forwarder instance- Specified by:
getForwarderin interfaceConnectionService- Returns:
- The
Forwarder
-
request
public org.apache.sshd.common.util.buffer.Buffer request(String request, org.apache.sshd.common.util.buffer.Buffer buffer, long maxWaitMillis) throws IOException Description copied from interface:ConnectionServiceSend a global request and wait for the response, if the request is sent withwant-reply = true.- Specified by:
requestin interfaceConnectionService- Parameters:
request- the request name - used mainly for logging and debuggingbuffer- the buffer containing the global requestmaxWaitMillis- maximum time in milliseconds to wait for the request to finish - must be positive- Returns:
- the return buffer if the request was successful,
nullotherwise. - Throws:
IOException- if an error occurred when encoding or sending the packet
-
request
public GlobalRequestFuture request(org.apache.sshd.common.util.buffer.Buffer buffer, String request, GlobalRequestFuture.ReplyHandler replyHandler) throws IOException Description copied from interface:ConnectionServiceSend a global request and handle the reply asynchronously. Ifwant-reply = true, pass the receivedBufferto the givenGlobalRequestFuture.ReplyHandler, which may execute in a different thread.- want-reply == true && replyHandler != null
- The returned future is fulfilled with
nullwhen the request was sent, or with an exception if the request could not be sent. ThereplyHandleris invoked once the reply is received, with the SSH reply code and the data received. - want-reply == true && replyHandler == null
- The returned future is fulfilled with an exception if the request could not be sent, or a failure reply was received. If a success reply was received, the future is fulfilled with the received data buffer.
- want-reply == false
- The returned future is fulfilled with an empty
Bufferwhen the request was sent, or with an exception if the request could not be sent. If a reply handler is given, it is invoked with that empty buffer. The handler is not invoked if sending the request failed.
- Specified by:
requestin interfaceConnectionService- Parameters:
buffer- theBuffercontaining the global request, with thewant-replyflag set as appropriaterequest- the request namereplyHandler-GlobalRequestFuture.ReplyHandlerfor handling the reply; may benull- Returns:
- Created
GlobalRequestFuture - Throws:
IOException- if an error occurred while encoding or sending the packet
-
handleUnimplementedMessage
public boolean handleUnimplementedMessage(Session session, int cmd, org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception Description copied from interface:ReservedSessionMessagesHandlerInvoked when a packet with an un-implemented message is received - includingSSH_MSG_UNIMPLEMENTEDitself- Specified by:
handleUnimplementedMessagein interfaceReservedSessionMessagesHandler- Parameters:
session- TheSessionthrough which the message was receivedcmd- The received (un-implemented) commandbuffer- TheBuffercontaining the data - positioned just beyond the command- Returns:
trueif message handled internally,falseif should return aSSH_MSG_UNIMPLEMENTEDreply (default behavior)- Throws:
Exception- If failed to handle the message- See Also:
-
preClose
protected void preClose()- Overrides:
preClosein classorg.apache.sshd.common.util.closeable.AbstractCloseable
-
createForwardingFilter
-
getX11ForwardSupport
- Specified by:
getX11ForwardSupportin interfaceConnectionService
-
createX11ForwardSupport
-
getAgentForwardSupport
- Specified by:
getAgentForwardSupportin interfaceConnectionService
-
createAgentForwardSupport
-
getInnerCloseable
protected org.apache.sshd.common.Closeable getInnerCloseable()- Specified by:
getInnerCloseablein classorg.apache.sshd.common.util.closeable.AbstractInnerCloseable
-
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
public void channelOpenConfirmation(org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException - 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
public void channelExtendedData(org.apache.sshd.common.util.buffer.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(org.apache.sshd.common.util.buffer.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
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
protected Channel getChannel(byte cmd, org.apache.sshd.common.util.buffer.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, long recipient, org.apache.sshd.common.util.buffer.Buffer buffer) throws IOException - 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
-
sendChannelOpenFailure
protected org.apache.sshd.common.io.IoWriteFuture sendChannelOpenFailure(org.apache.sshd.common.util.buffer.Buffer buffer, long sender, int reasonCode, String message, String lang) throws IOException - Throws:
IOException
-
globalRequest
protected org.apache.sshd.common.io.IoWriteFuture globalRequest(org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception 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 org.apache.sshd.common.io.IoWriteFuture handleUnknownRequest(org.apache.sshd.common.util.buffer.Buffer buffer, String req, boolean wantReply) throws IOException - Throws:
IOException
-
sendGlobalResponse
protected org.apache.sshd.common.io.IoWriteFuture sendGlobalResponse(org.apache.sshd.common.util.buffer.Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException - Throws:
IOException
-
requestSuccess
-
requestFailure
-
toString
-