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:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.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.
-
-
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 private java.util.concurrent.atomic.AtomicReference<AgentForwardSupport>agentForwardHolderprivate java.util.concurrent.atomic.AtomicBooleanallowMoreSessionsprotected java.util.Map<java.lang.Integer,Channel>channelsMap of channels keyed by the identifierstatic java.lang.StringDEFAULT_SESSION_IGNORE_HEARTBEAT_STRINGUsed inSSH_MSH_IGNOREmessages for the keep-alive mechanismprivate java.util.concurrent.atomic.AtomicReference<Forwarder>forwarderHolderprivate java.util.concurrent.ScheduledFuture<?>heartBeatprotected java.util.concurrent.atomic.AtomicLongheartbeatCountprivate PortForwardingEventListenerlistenerProxyprivate java.util.Collection<PortForwardingEventListener>listenersprivate java.util.Collection<PortForwardingEventListenerManager>managersHolderprotected java.util.concurrent.atomic.AtomicIntegernextChannelIdNext channel identifierprivate java.util.Map<java.lang.String,java.lang.Object>propertiesstatic java.util.function.IntUnaryOperatorRESPONSE_BUFFER_GROWTH_FACTORDefault growth factor function used to resize response buffersprivate AbstractSessionsessionInstanceprivate UnknownChannelReferenceHandlerunknownChannelReferenceHandlerprivate java.util.concurrent.atomic.AtomicReference<X11ForwardSupport>x11ForwardHolder-
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.PropertyResolver
EMPTY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractConnectionService(AbstractSession session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPortForwardingEventListener(PortForwardingEventListener listener)Add a port forwarding listenerbooleanaddPortForwardingEventListenerManager(PortForwardingEventListenerManager manager)voidchannelClose(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)AgentForwardSupportgetAgentForwardSupport()protected ChannelgetChannel(byte cmd, int recipient, Buffer buffer)protected ChannelgetChannel(byte cmd, Buffer buffer)Retrieve the channel designated by the given packetjava.util.Collection<Channel>getChannels()ForwardergetForwarder()Retrieve the forwarder instanceprotected CloseablegetInnerCloseable()protected intgetNextChannelId()PortForwardingEventListenergetPortForwardingEventListenerProxy()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()AbstractSessiongetSession()UnknownChannelReferenceHandlergetUnknownChannelReferenceHandler()X11ForwardSupportgetX11ForwardSupport()protected IoWriteFutureglobalRequest(Buffer buffer)Process global requestsprotected IoWriteFuturehandleUnknownRequest(Buffer buffer, java.lang.String req, boolean wantReply)booleanisAllowMoreSessions()protected voidpreClose()preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.voidprocess(int cmd, Buffer buffer)Service the request.intregisterChannel(Channel channel)Register a newly created channel with a new unique identifiervoidremovePortForwardingEventListener(PortForwardingEventListener listener)Remove a port forwarding listenerbooleanremovePortForwardingEventListenerManager(PortForwardingEventListenerManager manager)protected voidrequestFailure(Buffer buffer)protected voidrequestSuccess(Buffer buffer)UnknownChannelReferenceHandlerresolveUnknownChannelReferenceHandler()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, int sender, int reasonCode, java.lang.String message, java.lang.String lang)protected IoWriteFuturesendGlobalResponse(Buffer buffer, java.lang.String req, RequestHandler.Result result, boolean wantReply)protected booleansendHeartBeat()Sends a heartbeat message/packetvoidsetAllowMoreSessions(boolean allow)voidsetUnknownChannelReferenceHandler(UnknownChannelReferenceHandler handler)voidstart()protected java.util.concurrent.ScheduledFuture<?>startHeartBeat()protected voidstopHeartBeat()java.lang.StringtoString()voidunregisterChannel(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
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
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, isEmpty
-
Methods inherited from interface org.apache.sshd.common.Service
getParentPropertyResolver
-
Methods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeat
-
Methods inherited from interface org.apache.sshd.common.session.SessionHolder
getSessionContext
-
-
-
-
Field Detail
-
RESPONSE_BUFFER_GROWTH_FACTOR
public static final java.util.function.IntUnaryOperator RESPONSE_BUFFER_GROWTH_FACTOR
Default growth factor function used to resize response buffers
-
DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
public static final java.lang.String DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING
Used inSSH_MSH_IGNOREmessages for the keep-alive mechanism- See Also:
- Constant Field Values
-
channels
protected final java.util.Map<java.lang.Integer,Channel> channels
Map of channels keyed by the identifier
-
nextChannelId
protected final java.util.concurrent.atomic.AtomicInteger nextChannelId
Next channel identifier
-
heartbeatCount
protected final java.util.concurrent.atomic.AtomicLong heartbeatCount
-
heartBeat
private java.util.concurrent.ScheduledFuture<?> heartBeat
-
agentForwardHolder
private final java.util.concurrent.atomic.AtomicReference<AgentForwardSupport> agentForwardHolder
-
x11ForwardHolder
private final java.util.concurrent.atomic.AtomicReference<X11ForwardSupport> x11ForwardHolder
-
forwarderHolder
private final java.util.concurrent.atomic.AtomicReference<Forwarder> forwarderHolder
-
allowMoreSessions
private final java.util.concurrent.atomic.AtomicBoolean allowMoreSessions
-
listeners
private final java.util.Collection<PortForwardingEventListener> listeners
-
managersHolder
private final java.util.Collection<PortForwardingEventListenerManager> managersHolder
-
properties
private final java.util.Map<java.lang.String,java.lang.Object> properties
-
listenerProxy
private final PortForwardingEventListener listenerProxy
-
sessionInstance
private final AbstractSession sessionInstance
-
unknownChannelReferenceHandler
private UnknownChannelReferenceHandler unknownChannelReferenceHandler
-
-
Constructor Detail
-
AbstractConnectionService
protected AbstractConnectionService(AbstractSession session)
-
-
Method Detail
-
getProperties
public java.util.Map<java.lang.String,java.lang.Object> 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
public PortForwardingEventListener getPortForwardingEventListenerProxy()
- Specified by:
getPortForwardingEventListenerProxyin interfacePortForwardingEventListenerManager- Returns:
- A proxy listener representing all the currently registered listener through this manager
-
addPortForwardingEventListener
public void addPortForwardingEventListener(PortForwardingEventListener listener)
Description copied from interface:PortForwardingEventListenerManagerAdd a port forwarding listener- Specified by:
addPortForwardingEventListenerin interfacePortForwardingEventListenerManager- Parameters:
listener- ThePortForwardingEventListenerto add - nevernull
-
removePortForwardingEventListener
public void removePortForwardingEventListener(PortForwardingEventListener listener)
Description copied from interface:PortForwardingEventListenerManagerRemove a port forwarding listener- Specified by:
removePortForwardingEventListenerin interfacePortForwardingEventListenerManager- Parameters:
listener- ThePortForwardingEventListenerto remove - ignored ifnull
-
getUnknownChannelReferenceHandler
public UnknownChannelReferenceHandler getUnknownChannelReferenceHandler()
- Specified by:
getUnknownChannelReferenceHandlerin interfaceUnknownChannelReferenceHandlerManager- Returns:
- The
UnknownChannelReferenceHandlerManagerto use - ifnullthen any reference to unknown channel causes anSshChannelNotFoundException
-
setUnknownChannelReferenceHandler
public void setUnknownChannelReferenceHandler(UnknownChannelReferenceHandler handler)
- Specified by:
setUnknownChannelReferenceHandlerin interfaceUnknownChannelReferenceHandlerManager- Parameters:
handler- TheUnknownChannelReferenceHandlerManagerto use - ifnullthen any reference to unknown channel causes anSshChannelNotFoundException
-
getRegisteredManagers
public java.util.Collection<PortForwardingEventListenerManager> 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
public boolean addPortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
- Specified by:
addPortForwardingEventListenerManagerin interfacePortForwardingEventListenerManagerHolder
-
removePortForwardingEventListenerManager
public boolean removePortForwardingEventListenerManager(PortForwardingEventListenerManager manager)
- Specified by:
removePortForwardingEventListenerManagerin interfacePortForwardingEventListenerManagerHolder
-
getChannels
public java.util.Collection<Channel> getChannels()
-
getSession
public AbstractSession getSession()
- Specified by:
getSessionin interfaceSessionHolder<Session>
-
startHeartBeat
protected java.util.concurrent.ScheduledFuture<?> startHeartBeat()
-
sendHeartBeat
protected boolean sendHeartBeat()
Sends a heartbeat message/packet- Returns:
trueif heartbeat successfully sent
-
futureDone
protected void futureDone(IoWriteFuture future)
-
stopHeartBeat
protected void stopHeartBeat()
-
getForwarder
public Forwarder 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
-
getX11ForwardSupport
public X11ForwardSupport getX11ForwardSupport()
- Specified by:
getX11ForwardSupportin interfaceConnectionService
-
createX11ForwardSupport
protected X11ForwardSupport createX11ForwardSupport(Session session)
-
getAgentForwardSupport
public AgentForwardSupport getAgentForwardSupport()
- Specified by:
getAgentForwardSupportin interfaceConnectionService
-
createAgentForwardSupport
protected AgentForwardSupport createAgentForwardSupport(Session session)
-
getInnerCloseable
protected Closeable getInnerCloseable()
- Specified by:
getInnerCloseablein classAbstractInnerCloseable
-
getNextChannelId
protected int getNextChannelId()
-
registerChannel
public int registerChannel(Channel channel) throws java.io.IOException
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
- Throws:
java.io.IOException- If failed to initialize and register the channel
-
unregisterChannel
public void unregisterChannel(Channel channel)
Remove this channel from the list of managed channels- Specified by:
unregisterChannelin interfaceConnectionService- Parameters:
channel- the channel
-
process
public void process(int cmd, Buffer buffer) throws java.lang.ExceptionDescription 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(Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
channelOpenFailure
public void channelOpenFailure(Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
channelData
public void channelData(Buffer buffer) throws java.io.IOException
Process incoming data on a channel- Parameters:
buffer- the buffer containing the data- Throws:
java.io.IOException- if an error occurs
-
channelExtendedData
public void channelExtendedData(Buffer buffer) throws java.io.IOException
Process incoming extended data on a channel- Parameters:
buffer- the buffer containing the data- Throws:
java.io.IOException- if an error occurs
-
channelWindowAdjust
public void channelWindowAdjust(Buffer buffer) throws java.io.IOException
Process a window adjust packet on a channel- Parameters:
buffer- the buffer containing the window adjustment parameters- Throws:
java.io.IOException- if an error occurs
-
channelEof
public void channelEof(Buffer buffer) throws java.io.IOException
Process end of file on a channel- Parameters:
buffer- the buffer containing the packet- Throws:
java.io.IOException- if an error occurs
-
channelClose
public void channelClose(Buffer buffer) throws java.io.IOException
Close a channel due to a close packet received- Parameters:
buffer- the buffer containing the packet- Throws:
java.io.IOException- if an error occurs
-
channelRequest
public void channelRequest(Buffer buffer) throws java.io.IOException
Service a request on a channel- Parameters:
buffer- the buffer containing the request- Throws:
java.io.IOException- if an error occurs
-
channelFailure
public void channelFailure(Buffer buffer) throws java.io.IOException
Process a failure on a channel- Parameters:
buffer- the buffer containing the packet- Throws:
java.io.IOException- if an error occurs
-
channelSuccess
public void channelSuccess(Buffer buffer) throws java.io.IOException
Process a success on a channel- Parameters:
buffer- the buffer containing the packet- Throws:
java.io.IOException- if an error occurs
-
getChannel
protected Channel getChannel(byte cmd, Buffer buffer) throws java.io.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:
java.io.IOException- if the channel does not exists
-
getChannel
protected Channel getChannel(byte cmd, int recipient, Buffer buffer) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveUnknownChannelReferenceHandler
public UnknownChannelReferenceHandler 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
protected void channelOpen(Buffer buffer) throws java.lang.Exception
- Throws:
java.lang.Exception
-
sendChannelOpenFailure
protected IoWriteFuture sendChannelOpenFailure(Buffer buffer, int sender, int reasonCode, java.lang.String message, java.lang.String lang) throws java.io.IOException
- Throws:
java.io.IOException
-
globalRequest
protected IoWriteFuture globalRequest(Buffer buffer) throws java.lang.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:
java.lang.Exception- If failed to process the request
-
handleUnknownRequest
protected IoWriteFuture handleUnknownRequest(Buffer buffer, java.lang.String req, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
sendGlobalResponse
protected IoWriteFuture sendGlobalResponse(Buffer buffer, java.lang.String req, RequestHandler.Result result, boolean wantReply) throws java.io.IOException
- Throws:
java.io.IOException
-
requestSuccess
protected void requestSuccess(Buffer buffer) throws java.lang.Exception
- Throws:
java.lang.Exception
-
requestFailure
protected void requestFailure(Buffer buffer) throws java.lang.Exception
- Throws:
java.lang.Exception
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-