Class SshCache


  • public final class SshCache
    extends java.lang.Object
    a class to cache SSH Connections and Channel for the SSH Repository each session is defined by connecting user / host / port two maps are used to find cache entries one map is using the above keys, the other uses the session itself
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void attachChannelSftp​(com.jcraft.jsch.Session session, com.jcraft.jsch.ChannelSftp channel)
      attaches a channelSftp to an existing session cache entry
      void clearSession​(com.jcraft.jsch.Session session)
      discardes session entries from the cache
      com.jcraft.jsch.ChannelSftp getChannelSftp​(com.jcraft.jsch.Session session)
      retrieves an sftp channel from the cache
      static SshCache getInstance()  
      com.jcraft.jsch.Session getSession​(java.lang.String host, int port, java.lang.String username, java.lang.String userPassword, java.io.File pemFile, java.lang.String pemPassword, java.io.File passFile)
      Gets a session from the cache or establishes a new session if necessary
      • Methods inherited from class java.lang.Object

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

      • getInstance

        public static SshCache getInstance()
      • clearSession

        public void clearSession​(com.jcraft.jsch.Session session)
        discardes session entries from the cache
        Parameters:
        session - to clear
      • getChannelSftp

        public com.jcraft.jsch.ChannelSftp getChannelSftp​(com.jcraft.jsch.Session session)
                                                   throws java.io.IOException
        retrieves an sftp channel from the cache
        Parameters:
        session - to connect to
        Returns:
        channelSftp or null if not successful (channel not existent or dead)
        Throws:
        java.io.IOException
      • attachChannelSftp

        public void attachChannelSftp​(com.jcraft.jsch.Session session,
                                      com.jcraft.jsch.ChannelSftp channel)
        attaches a channelSftp to an existing session cache entry
        Parameters:
        session - to attach the channel to
        channel - channel to attach
      • getSession

        public com.jcraft.jsch.Session getSession​(java.lang.String host,
                                                  int port,
                                                  java.lang.String username,
                                                  java.lang.String userPassword,
                                                  java.io.File pemFile,
                                                  java.lang.String pemPassword,
                                                  java.io.File passFile)
                                           throws java.io.IOException
        Gets a session from the cache or establishes a new session if necessary
        Parameters:
        host - to connect to
        port - to use for session (-1 == use standard port)
        username - for the session to use
        userPassword - to use for authentication (optional)
        pemFile - File to use for public key authentication
        pemPassword - to use for accessing the pemFile (optional)
        passFile - to store credentials
        Returns:
        session or null if not successful
        Throws:
        java.io.IOException