Top Description Fields Constructors Methods
org.apache.sshd.common.session.helpers

public abstract Class AbstractConnectionService

extends AbstractInnerCloseable
implements ConnectionService
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.session.ConnectionService, org.apache.sshd.common.forward.PortForwardingEventListenerManagerHolder, org.apache.sshd.common.forward.PortForwardingEventListenerManager, org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager, org.apache.sshd.common.session.SessionHeartbeatController, org.apache.sshd.common.PropertyResolver, org.apache.sshd.common.Service, org.apache.sshd.common.Closeable, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable, org.apache.sshd.common.session.SessionHolder, org.apache.sshd.common.session.SessionContextHolder
Known Direct Subclasses
org.apache.sshd.server.session.ServerConnectionService, org.apache.sshd.client.session.ClientConnectionService
Imports
java.io.IOException, java.time.Duration, java.util.ArrayList, .Collection, .Collections, .Map, .Objects, java.util.concurrent.ConcurrentHashMap, .CopyOnWriteArraySet, .ScheduledExecutorService, .ScheduledFuture, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, .AtomicReference, java.util.function.IntUnaryOperator, org.apache.sshd.agent.common.AgentForwardSupport, .DefaultAgentForwardSupport, org.apache.sshd.client.channel.AbstractClientChannel, org.apache.sshd.client.future.OpenFuture, org.apache.sshd.common.Closeable, .FactoryManager, .SshConstants, org.apache.sshd.common.channel.Channel, .ChannelFactory, .ChannelListener, .LocalWindow, .RequestHandler, org.apache.sshd.common.channel.exception.SshChannelNotFoundException, .SshChannelOpenException, org.apache.sshd.common.forward.Forwarder, .ForwarderFactory, .PortForwardingEventListener, .PortForwardingEventListenerManager, org.apache.sshd.common.future.HasException, org.apache.sshd.common.io.AbstractIoWriteFuture, .IoWriteFuture, org.apache.sshd.common.kex.KexState, org.apache.sshd.common.session.ConnectionService, .ReservedSessionMessagesHandler, .Session, .UnknownChannelReferenceHandler, org.apache.sshd.common.util.EventListenerUtils, .GenericUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.Buffer, org.apache.sshd.common.util.closeable.AbstractInnerCloseable, org.apache.sshd.common.util.functors.Int2IntFunction, org.apache.sshd.core.CoreModuleProperties, org.apache.sshd.server.x11.DefaultX11ForwardSupport, .X11ForwardSupport

Base implementation of ConnectionService.
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
private final AtomicReference<AgentForwardSupport>
private final AtomicBoolean
protected final Map<Long, Channel>
channels

Map of channels keyed by the identifier

public static final String
DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING

Used in SSH_MSH_IGNORE messages for the keep-alive mechanism

private final AtomicReference<Forwarder>
private ScheduledFuture<?>
protected final AtomicLong
private final PortForwardingEventListener
private final Collection<PortForwardingEventListener>
private final Collection<PortForwardingEventListenerManager>
protected final AtomicLong
nextChannelId

Next channel identifier - a UINT32 represented as a long

private final Map<String, Object>
public static final IntUnaryOperator
RESPONSE_BUFFER_GROWTH_FACTOR

Default growth factor function used to resize response buffers

private final AbstractSession
private UnknownChannelReferenceHandler
private final AtomicReference<X11ForwardSupport>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
public void
channelClose(Buffer
the buffer containing the packet
buffer
)

Close a channel due to a close packet received

public void
channelData(Buffer
the buffer containing the data
buffer
)

Process incoming data on a channel

public void
channelEof(Buffer
the buffer containing the packet
buffer
)

Process end of file on a channel

public void
channelExtendedData(Buffer
the buffer containing the data
buffer
)

Process incoming extended data on a channel

public void
channelFailure(Buffer
the buffer containing the packet
buffer
)

Process a failure on a channel

protected void
public void
public void
public void
channelRequest(Buffer
the buffer containing the request
buffer
)

Service a request on a channel

public void
channelSuccess(Buffer
the buffer containing the packet
buffer
)

Process a success on a channel

public void
channelWindowAdjust(Buffer
the buffer containing the window adjustment parameters
buffer
)

Process a window adjust packet on a channel

protected AgentForwardSupport
protected Forwarder
protected X11ForwardSupport
protected void
public AgentForwardSupport
protected Channel

Returns:

the target channel
getChannel
(byte
The command being processed for the channel
cmd
,
Buffer
the incoming packet
buffer
)

Retrieve the channel designated by the given packet

protected Channel
getChannel(byte cmd, long recipient, Buffer buffer)

public Collection<Channel>
public Forwarder
protected Closeable
protected long
public PortForwardingEventListener
public Map<String, Object>
getProperties()

Implements org.apache.sshd.common.PropertyResolver.getProperties.

A map of properties that can be used to configure the SSH server or client.

public Collection<PortForwardingEventListenerManager>
public AbstractSession
public UnknownChannelReferenceHandler
public X11ForwardSupport
protected IoWriteFuture

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"
globalRequest
(Buffer
The request Buffer
buffer
)

Process global requests

protected IoWriteFuture
handleUnknownRequest(Buffer buffer, String req, boolean wantReply)

public boolean
protected void
preClose()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.preClose.

preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately.

public void
process(int
The incoming command type
cmd
,
Buffer
The Buffer containing optional command parameters
buffer
)

Implements org.apache.sshd.common.Service.process.

Service the request.

public long
registerChannel(Channel
The Channel to register
channel
)

Implements org.apache.sshd.common.session.ConnectionService.registerChannel.

Register a newly created channel with a new unique identifier

public void
public boolean
protected void
protected void
public UnknownChannelReferenceHandler
resolveUnknownChannelReferenceHandler()

Implements org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager.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, long sender, int reasonCode, String message, String lang)

protected IoWriteFuture
sendGlobalResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply)

protected boolean

Returns:

true if heartbeat successfully sent
sendHeartBeat
()

Sends a heartbeat message/packet

public void
public void
public void
protected synchronized ScheduledFuture<?>
protected synchronized void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
unregisterChannel(Channel
the channel
channel
)

Implements org.apache.sshd.common.session.ConnectionService.unregisterChannel.

Remove this channel from the list of managed channels

Inherited from org.apache.sshd.common.util.closeable.AbstractInnerCloseable:
doCloseGracefullydoCloseImmediately

Field Detail

agentForwardHolderback to summary
private final AtomicReference<AgentForwardSupport> agentForwardHolder
allowMoreSessionsback to summary
private final AtomicBoolean allowMoreSessions
channelsback to summary
protected final Map<Long, Channel> channels

Map of channels keyed by the identifier

DEFAULT_SESSION_IGNORE_HEARTBEAT_STRINGback to summary
public static final String DEFAULT_SESSION_IGNORE_HEARTBEAT_STRING

Used in SSH_MSH_IGNORE messages for the keep-alive mechanism

forwarderHolderback to summary
private final AtomicReference<Forwarder> forwarderHolder
heartBeatback to summary
private ScheduledFuture<?> heartBeat
heartbeatCountback to summary
protected final AtomicLong heartbeatCount
listenerProxyback to summary
private final PortForwardingEventListener listenerProxy
listenersback to summary
private final Collection<PortForwardingEventListener> listeners
managersHolderback to summary
private final Collection<PortForwardingEventListenerManager> managersHolder
nextChannelIdback to summary
protected final AtomicLong nextChannelId

Next channel identifier - a UINT32 represented as a long

propertiesback to summary
private final Map<String, Object> properties
RESPONSE_BUFFER_GROWTH_FACTORback to summary
public static final IntUnaryOperator RESPONSE_BUFFER_GROWTH_FACTOR

Default growth factor function used to resize response buffers

sessionInstanceback to summary
private final AbstractSession sessionInstance
unknownChannelReferenceHandlerback to summary
private UnknownChannelReferenceHandler unknownChannelReferenceHandler
x11ForwardHolderback to summary
private final AtomicReference<X11ForwardSupport> x11ForwardHolder

Constructor Detail

AbstractConnectionServiceback to summary
protected AbstractConnectionService(AbstractSession session)

Method Detail

addPortForwardingEventListenerback to summary
public void addPortForwardingEventListener(PortForwardingEventListener listener)

Implements org.apache.sshd.common.forward.PortForwardingEventListenerManager.addPortForwardingEventListener.

Doc from org.apache.sshd.common.forward.PortForwardingEventListenerManager.addPortForwardingEventListener.

Add a port forwarding listener

Parameters
listener:PortForwardingEventListener

The PortForwardingEventListener to add - never null

Annotations
@Override
addPortForwardingEventListenerManagerback to summary
public boolean addPortForwardingEventListenerManager(PortForwardingEventListenerManager manager)

Implements org.apache.sshd.common.forward.PortForwardingEventListenerManagerHolder.addPortForwardingEventListenerManager.

Annotations
@Override
channelCloseback to summary
public void channelClose(Buffer buffer) throws IOException

Close a channel due to a close packet received

Parameters
buffer:Buffer

the buffer containing the packet

Exceptions
IOException:
if an error occurs
channelDataback to summary
public void channelData(Buffer buffer) throws IOException

Process incoming data on a channel

Parameters
buffer:Buffer

the buffer containing the data

Exceptions
IOException:
if an error occurs
channelEofback to summary
public void channelEof(Buffer buffer) throws IOException

Process end of file on a channel

Parameters
buffer:Buffer

the buffer containing the packet

Exceptions
IOException:
if an error occurs
channelExtendedDataback to summary
public void channelExtendedData(Buffer buffer) throws IOException

Process incoming extended data on a channel

Parameters
buffer:Buffer

the buffer containing the data

Exceptions
IOException:
if an error occurs
channelFailureback to summary
public void channelFailure(Buffer buffer) throws IOException

Process a failure on a channel

Parameters
buffer:Buffer

the buffer containing the packet

Exceptions
IOException:
if an error occurs
channelOpenback to summary
protected void channelOpen(Buffer buffer) throws Exception
channelOpenConfirmationback to summary
public void channelOpenConfirmation(Buffer buffer) throws IOException
channelOpenFailureback to summary
public void channelOpenFailure(Buffer buffer) throws IOException
channelRequestback to summary
public void channelRequest(Buffer buffer) throws IOException

Service a request on a channel

Parameters
buffer:Buffer

the buffer containing the request

Exceptions
IOException:
if an error occurs
channelSuccessback to summary
public void channelSuccess(Buffer buffer) throws IOException

Process a success on a channel

Parameters
buffer:Buffer

the buffer containing the packet

Exceptions
IOException:
if an error occurs
channelWindowAdjustback to summary
public void channelWindowAdjust(Buffer buffer) throws IOException

Process a window adjust packet on a channel

Parameters
buffer:Buffer

the buffer containing the window adjustment parameters

Exceptions
IOException:
if an error occurs
createAgentForwardSupportback to summary
protected AgentForwardSupport createAgentForwardSupport(Session session)
createForwardingFilterback to summary
protected Forwarder createForwardingFilter(Session session)
createX11ForwardSupportback to summary
protected X11ForwardSupport createX11ForwardSupport(Session session)
futureDoneback to summary
protected void futureDone(HasException future)
getAgentForwardSupportback to summary
public AgentForwardSupport getAgentForwardSupport()

Implements org.apache.sshd.common.session.ConnectionService.getAgentForwardSupport.

Annotations
@Override
getChannelback to summary
protected Channel getChannel(byte cmd, Buffer buffer) throws IOException

Retrieve the channel designated by the given packet

Parameters
cmd:byte

The command being processed for the channel

buffer:Buffer

the incoming packet

Returns:Channel

the target channel

Exceptions
IOException:
if the channel does not exists
getChannelback to summary
protected Channel getChannel(byte cmd, long recipient, Buffer buffer) throws IOException
getChannelsback to summary
public Collection<Channel> getChannels()
getForwarderback to summary
public Forwarder getForwarder()

Implements org.apache.sshd.common.session.ConnectionService.getForwarder.

Doc from org.apache.sshd.common.session.ConnectionService.getForwarder.

Retrieve the forwarder instance

Returns:Forwarder

The Forwarder

Annotations
@Override
getInnerCloseableback to summary
protected Closeable getInnerCloseable()

Implements abstract org.apache.sshd.common.util.closeable.AbstractInnerCloseable.getInnerCloseable.

Annotations
@Override
getNextChannelIdback to summary
protected long getNextChannelId()
getPortForwardingEventListenerProxyback to summary
public PortForwardingEventListener getPortForwardingEventListenerProxy()

Implements org.apache.sshd.common.forward.PortForwardingEventListenerManager.getPortForwardingEventListenerProxy.

Returns:PortForwardingEventListener

Doc from org.apache.sshd.common.forward.PortForwardingEventListenerManager.getPortForwardingEventListenerProxy.

A proxy listener representing all the currently registered listener through this manager

Annotations
@Override
getPropertiesback to summary
public Map<String, Object> getProperties()

Implements org.apache.sshd.common.PropertyResolver.getProperties.

Doc from org.apache.sshd.common.PropertyResolver.getProperties.

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, 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.

Returns:Map<String, Object>

a valid Map containing configuration values, never null

Note

may be immutable.

Annotations
@Override
getRegisteredManagersback to summary
public Collection<PortForwardingEventListenerManager> getRegisteredManagers()

Implements org.apache.sshd.common.forward.PortForwardingEventListenerManagerHolder.getRegisteredManagers.

Returns:Collection<PortForwardingEventListenerManager>

Doc from org.apache.sshd.common.forward.PortForwardingEventListenerManagerHolder.getRegisteredManagers.

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.

Annotations
@Override
getSessionback to summary
public AbstractSession getSession()

Implements org.apache.sshd.common.session.SessionHolder.getSession.

Annotations
@Override
getUnknownChannelReferenceHandlerback to summary
public UnknownChannelReferenceHandler getUnknownChannelReferenceHandler()

Implements org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager.getUnknownChannelReferenceHandler.

Returns:UnknownChannelReferenceHandler

Doc from org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager.getUnknownChannelReferenceHandler.

The UnknownChannelReferenceHandlerManager to use - if null then any reference to unknown channel causes an SshChannelNotFoundException

Annotations
@Override
getX11ForwardSupportback to summary
public X11ForwardSupport getX11ForwardSupport()

Implements org.apache.sshd.common.session.ConnectionService.getX11ForwardSupport.

Annotations
@Override
globalRequestback to summary
protected IoWriteFuture globalRequest(Buffer buffer) throws Exception

Process global requests

Parameters
buffer:Buffer

The request Buffer

Returns:IoWriteFuture

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"

Exceptions
Exception:
If failed to process the request
handleUnknownRequestback to summary
protected IoWriteFuture handleUnknownRequest(Buffer buffer, String req, boolean wantReply) throws IOException
isAllowMoreSessionsback to summary
public boolean isAllowMoreSessions()

Implements org.apache.sshd.common.session.ConnectionService.isAllowMoreSessions.

Annotations
@Override
preCloseback to summary
protected void preClose()

Overrides org.apache.sshd.common.util.closeable.AbstractCloseable.preClose.

Doc from org.apache.sshd.common.util.closeable.AbstractCloseable.preClose.

preClose is guaranteed to be called before doCloseGracefully or doCloseImmediately. When preClose() is called, isClosing() == true

Annotations
@Override
processback to summary
public void process(int cmd, Buffer buffer) throws Exception

Implements org.apache.sshd.common.Service.process.

Doc from org.apache.sshd.common.Service.process.

Service the request.

Parameters
cmd:int

The incoming command type

buffer:Buffer

The Buffer containing optional command parameters

Annotations
@Override
Exceptions
Exception:
If failed to process the command
registerChannelback to summary
public long registerChannel(Channel channel) throws IOException

Implements org.apache.sshd.common.session.ConnectionService.registerChannel.

Doc from org.apache.sshd.common.session.ConnectionService.registerChannel.

Register a newly created channel with a new unique identifier

Parameters
channel:Channel

The Channel to register

Returns:long

The assigned id of this channel - a UINT32 represented as a long

Annotations
@Override
Exceptions
IOException:
If failed to initialize and register the channel
removePortForwardingEventListenerback to summary
public void removePortForwardingEventListener(PortForwardingEventListener listener)

Implements org.apache.sshd.common.forward.PortForwardingEventListenerManager.removePortForwardingEventListener.

Doc from org.apache.sshd.common.forward.PortForwardingEventListenerManager.removePortForwardingEventListener.

Remove a port forwarding listener

Parameters
listener:PortForwardingEventListener

The PortForwardingEventListener to remove - ignored if null

Annotations
@Override
removePortForwardingEventListenerManagerback to summary
public boolean removePortForwardingEventListenerManager(PortForwardingEventListenerManager manager)

Implements org.apache.sshd.common.forward.PortForwardingEventListenerManagerHolder.removePortForwardingEventListenerManager.

Annotations
@Override
requestFailureback to summary
protected void requestFailure(Buffer buffer) throws Exception
requestSuccessback to summary
protected void requestSuccess(Buffer buffer) throws Exception
resolveUnknownChannelReferenceHandlerback to summary
public UnknownChannelReferenceHandler resolveUnknownChannelReferenceHandler()

Implements org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager.resolveUnknownChannelReferenceHandler.

Doc from org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager.resolveUnknownChannelReferenceHandler.

Check if current manager has a specific handler set for it - if not, try and resolve one from the "parent" container (if any)

Returns:UnknownChannelReferenceHandler

The resolved handler instance

Annotations
@Override
sendChannelOpenFailureback to summary
protected IoWriteFuture sendChannelOpenFailure(Buffer buffer, long sender, int reasonCode, String message, String lang) throws IOException
sendGlobalResponseback to summary
protected IoWriteFuture sendGlobalResponse(Buffer buffer, String req, RequestHandler.Result result, boolean wantReply) throws IOException
sendHeartBeatback to summary
protected boolean sendHeartBeat()

Sends a heartbeat message/packet

Returns:boolean

true if heartbeat successfully sent

setAllowMoreSessionsback to summary
public void setAllowMoreSessions(boolean allow)

Implements org.apache.sshd.common.session.ConnectionService.setAllowMoreSessions.

Annotations
@Override
setUnknownChannelReferenceHandlerback to summary
public void setUnknownChannelReferenceHandler(UnknownChannelReferenceHandler handler)

Implements org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager.setUnknownChannelReferenceHandler.

Parameters
handler:UnknownChannelReferenceHandler

Doc from org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager.setUnknownChannelReferenceHandler.

The UnknownChannelReferenceHandlerManager to use - if null then any reference to unknown channel causes an SshChannelNotFoundException

Annotations
@Override
startback to summary
public void start()

Implements org.apache.sshd.common.Service.start.

Annotations
@Override
startHeartBeatback to summary
protected synchronized ScheduledFuture<?> startHeartBeat()
stopHeartBeatback to summary
protected synchronized void stopHeartBeat()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
unregisterChannelback to summary
public void unregisterChannel(Channel channel)

Implements org.apache.sshd.common.session.ConnectionService.unregisterChannel.

Remove this channel from the list of managed channels

Parameters
channel:Channel

the channel

Annotations
@Override