Class AbstractConnectionService

    • Field Detail

      • MAX_CONCURRENT_CHANNELS_PROP

        public static final java.lang.String MAX_CONCURRENT_CHANNELS_PROP
        Property that can be used to configure max. allowed concurrent active channels
        See Also:
        registerChannel(Channel), Constant Field Values
      • 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 in SSH_MSH_IGNORE messages 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<ForwardingFilter> forwarderHolder
      • allowMoreSessions

        private final java.util.concurrent.atomic.AtomicBoolean allowMoreSessions
      • properties

        private final java.util.Map<java.lang.String,​java.lang.Object> properties
    • 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: 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, 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.

        Specified by:
        getProperties in interface PropertyResolver
        Returns:
        a valid Map containing configuration values, never null. Note: may be immutable.
      • getChannels

        public java.util.Collection<Channel> getChannels()
      • start

        public void start()
        Specified by:
        start in interface Service
      • startHeartBeat

        protected java.util.concurrent.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()
      • 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 class AbstractCloseable
      • getNextChannelId

        protected int getNextChannelId()
      • registerChannel

        public int registerChannel​(Channel channel)
                            throws java.io.IOException
        Description copied from interface: ConnectionService
        Register a newly created channel with a new unique identifier
        Specified by:
        registerChannel in interface ConnectionService
        Parameters:
        channel - The Channel to register
        Returns:
        The assigned id of this channel
        Throws:
        java.io.IOException - If failed to initialize and register the channel
      • handleChannelRegistrationFailure

        protected void handleChannelRegistrationFailure​(Channel channel,
                                                        int channelId)
                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • unregisterChannel

        public void unregisterChannel​(Channel channel)
        Remove this channel from the list of managed channels
        Specified by:
        unregisterChannel in interface ConnectionService
        Parameters:
        channel - the channel
      • process

        public void process​(int cmd,
                            Buffer buffer)
                     throws java.lang.Exception
        Description copied from interface: Service
        Service the request.
        Specified by:
        process in interface Service
        Parameters:
        cmd - The incoming command type
        buffer - The Buffer containing optional command parameters
        Throws:
        java.lang.Exception - If failed to process the command
      • 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 channel
        buffer - 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
      • 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 request Buffer
        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:
        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:
        toString in class java.lang.Object