Class SshdSession

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.apache.sshd.client.SshClient client  
      private java.util.concurrent.CopyOnWriteArrayList<SessionCloseListener> listeners  
      private static org.slf4j.Logger LOG  
      private static int MAX_DEPTH  
      private org.apache.sshd.client.session.ClientSession session  
      private static java.util.regex.Pattern SHORT_SSH_FORMAT  
      private URIish uri  
    • Constructor Summary

      Constructors 
      Constructor Description
      SshdSession​(URIish uri, java.util.function.Supplier<org.apache.sshd.client.SshClient> clientFactory)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCloseListener​(SessionCloseListener listener)
      Adds a SessionCloseListener to this session.
      private void close​(java.io.Closeable toClose, java.lang.Throwable error)  
      (package private) void connect​(java.time.Duration timeout)  
      private org.apache.sshd.client.session.ClientSession connect​(org.apache.sshd.client.config.hosts.HostConfigEntry config, org.apache.sshd.common.AttributeRepository context, java.time.Duration timeout)  
      private org.apache.sshd.client.session.ClientSession connect​(URIish target, java.util.List<URIish> jumps, org.apache.sshd.common.future.SshFutureListener<org.apache.sshd.common.future.CloseFuture> listener, java.time.Duration timeout, int depth)  
      private java.util.List<URIish> determineHops​(java.util.List<URIish> currentHops, org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig, java.lang.String host)  
      void disconnect()
      Disconnects the remote session.
      private void disconnect​(java.lang.Throwable reason)  
      java.lang.Process exec​(java.lang.String commandName, int timeout)
      Creates a new remote Process to execute the given command.
      FtpChannel getFtpChannel()
      Obtain an FtpChannel to perform SFTP operations in this SshdSession.
      private org.apache.sshd.client.config.hosts.HostConfigEntry getHostConfig​(java.lang.String username, java.lang.String host, int port)  
      private void notifyCloseListeners()  
      private java.util.List<URIish> parseProxyJump​(java.lang.String proxyJump)  
      void removeCloseListener​(SessionCloseListener listener)
      Removes the given listener; has no effect if the listener is not currently registered with this session.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • SHORT_SSH_FORMAT

        private static final java.util.regex.Pattern SHORT_SSH_FORMAT
      • listeners

        private final java.util.concurrent.CopyOnWriteArrayList<SessionCloseListener> listeners
      • uri

        private final URIish uri
      • client

        private org.apache.sshd.client.SshClient client
      • session

        private org.apache.sshd.client.session.ClientSession session
    • Constructor Detail

      • SshdSession

        SshdSession​(URIish uri,
                    java.util.function.Supplier<org.apache.sshd.client.SshClient> clientFactory)
    • Method Detail

      • connect

        void connect​(java.time.Duration timeout)
              throws java.io.IOException
        Throws:
        java.io.IOException
      • connect

        private org.apache.sshd.client.session.ClientSession connect​(URIish target,
                                                                     java.util.List<URIish> jumps,
                                                                     org.apache.sshd.common.future.SshFutureListener<org.apache.sshd.common.future.CloseFuture> listener,
                                                                     java.time.Duration timeout,
                                                                     int depth)
                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • connect

        private org.apache.sshd.client.session.ClientSession connect​(org.apache.sshd.client.config.hosts.HostConfigEntry config,
                                                                     org.apache.sshd.common.AttributeRepository context,
                                                                     java.time.Duration timeout)
                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        private void close​(java.io.Closeable toClose,
                           java.lang.Throwable error)
      • getHostConfig

        private org.apache.sshd.client.config.hosts.HostConfigEntry getHostConfig​(java.lang.String username,
                                                                                  java.lang.String host,
                                                                                  int port)
                                                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • determineHops

        private java.util.List<URIish> determineHops​(java.util.List<URIish> currentHops,
                                                     org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig,
                                                     java.lang.String host)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • parseProxyJump

        private java.util.List<URIish> parseProxyJump​(java.lang.String proxyJump)
                                               throws java.net.URISyntaxException
        Throws:
        java.net.URISyntaxException
      • addCloseListener

        public void addCloseListener​(@NonNull
                                     SessionCloseListener listener)
        Adds a SessionCloseListener to this session. Has no effect if the given listener is already registered with this session.
        Parameters:
        listener - to add
      • removeCloseListener

        public void removeCloseListener​(@NonNull
                                        SessionCloseListener listener)
        Removes the given listener; has no effect if the listener is not currently registered with this session.
        Parameters:
        listener - to remove
      • notifyCloseListeners

        private void notifyCloseListeners()
      • exec

        public java.lang.Process exec​(java.lang.String commandName,
                                      int timeout)
                               throws java.io.IOException
        Description copied from interface: RemoteSession
        Creates a new remote Process to execute the given command. The returned process's streams exist and are connected, and execution of the process is already started.
        Specified by:
        exec in interface RemoteSession
        Parameters:
        commandName - command to execute
        timeout - timeout value, in seconds, for creating the remote process
        Returns:
        a new remote process, already started
        Throws:
        java.io.IOException - may be thrown in several cases. For example, on problems opening input or output streams or on problems connecting or communicating with the remote host. For the latter two cases, a TransportException may be thrown (a subclass of java.io.IOException).
      • disconnect

        private void disconnect​(java.lang.Throwable reason)