// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/ssh/Authentication.java
// public class Authentication {
//     private File privateKeyFile;
//     private byte[] privateKeyPhrase;
//     private String username;
//     private String privateKeyFilePassword;
// 
//     /**
//      * Constructor.
//      * @param privateKeyFile the key.
//      * @param username the username.
//      * @param privateKeyFilePassword password for the key file, or null if there is none.
//      * @param privateKeyPhrase phrase of privatekey.
//      */
//     public Authentication(File privateKeyFile,
//             String username,
//             String privateKeyFilePassword,
//             byte[] privateKeyPhrase) {
//         this.privateKeyFile = privateKeyFile;
//         this.username = username;
//         this.privateKeyFilePassword = privateKeyFilePassword;
//         this.privateKeyPhrase = privateKeyPhrase;
//     }
// 
//     /**
//      * Constructor.
//      * @param privateKeyFile the key.
//      * @param username the username.
//      * @param privateKeyFilePassword password for the key file, or null if there is none.
//      */
//     public Authentication(File privateKeyFile, String username, String privateKeyFilePassword) {
//         this(privateKeyFile, username, privateKeyFilePassword, null);
//     }
// 
//     /**
//      * Constructor.
//      * With null as privateKeyFilePassword.
//      * @param privateKeyFile the key.
//      * @param username the username.
//      */
//     public Authentication(File privateKeyFile, String username) {
//         this(privateKeyFile, username, null, null);
//     }
// 
//     /**
//      * The file path to the private key.
//      * @return the path.
//      */
//     public File getPrivateKeyFile() {
//         return privateKeyFile;
//     }
// 
//     /**
//      * The password for the private key file.
//      * @return the password.
//      */
//     public String getPrivateKeyFilePassword() {
//         return privateKeyFilePassword;
//     }
// 
//     /**
//      * The username to authenticate as.
//      * @return the username.
//      */
//     public String getUsername() {
//         return username;
//     }
// 
//     /**
//      * The phrase of private key.
//      * @return the phrase.
//      */
//     public byte[] getPrivateKeyPhrase() {
//         return privateKeyPhrase;
//     }
// }


import com.sonymobile.tools.gerrit.gerritevents.ssh.Authentication;
import com.sonymobile.tools.gerrit.gerritevents.ssh.SshConnection;
import java.io.IOException;
package com.sonymobile.tools.gerrit.gerritevents;



/**
 * {@link GerritQueryHandler} with a persisted SSH connection.
 * Saves the performance overhead of creating a new connection for each query.
 */
public class GerritQueryHandlerWithPersistedConnection extends GerritQueryHandler {

    private SshConnection activeConnection = null;

    /**
     * Creates a {@link GerritQueryHandler} with persisted SSH connection.
     *
     * @param gerritHostName    the hostName
     * @param gerritSshPort     the ssh port that the gerrit server listens to.
     * @param gerritProxy       the ssh Proxy url
     * @param authentication    the authentication credentials.
     * @param connectionTimeout the connection timeout.
     */
    public GerritQueryHandlerWithPersistedConnection(String gerritHostName, int gerritSshPort,
                                                     String gerritProxy, Authentication authentication,
                                                     int connectionTimeout) {
        super(gerritHostName, gerritSshPort, gerritProxy, authentication, connectionTimeout);
    }

    /**
     * Returns a fresh SSH connection if the persisted one is not valid.
     * Otherwise returns the existing connection.
     *
     * @return an active SSH connection
     * @throws IOException for IO issues
     */
    @Override
    protected SshConnection getConnection() throws IOException {
        if (!isPersistedConnectionValid()) {
            activeConnection = super.getConnection();
// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/ssh/Authentication.java
// public class Authentication {
//     private File privateKeyFile;
//     private byte[] privateKeyPhrase;
//     private String username;
//     private String privateKeyFilePassword;
// 
//     /**
//      * Constructor.
//      * @param privateKeyFile the key.
//      * @param username the username.
//      * @param privateKeyFilePassword password for the key file, or null if there is none.
//      * @param privateKeyPhrase phrase of privatekey.
//      */
//     public Authentication(File privateKeyFile,
//             String username,
//             String privateKeyFilePassword,
//             byte[] privateKeyPhrase) {
//         this.privateKeyFile = privateKeyFile;
//         this.username = username;
//         this.privateKeyFilePassword = privateKeyFilePassword;
//         this.privateKeyPhrase = privateKeyPhrase;
//     }
// 
//     /**
//      * Constructor.
//      * @param privateKeyFile the key.
//      * @param username the username.
//      * @param privateKeyFilePassword password for the key file, or null if there is none.
//      */
//     public Authentication(File privateKeyFile, String username, String privateKeyFilePassword) {
//         this(privateKeyFile, username, privateKeyFilePassword, null);
//     }
// 
//     /**
//      * Constructor.
//      * With null as privateKeyFilePassword.
//      * @param privateKeyFile the key.
//      * @param username the username.
//      */
//     public Authentication(File privateKeyFile, String username) {
//         this(privateKeyFile, username, null, null);
//     }
// 
//     /**
//      * The file path to the private key.
//      * @return the path.
//      */
//     public File getPrivateKeyFile() {
//         return privateKeyFile;
//     }
// 
//     /**
//      * The password for the private key file.
//      * @return the password.
//      */
//     public String getPrivateKeyFilePassword() {
//         return privateKeyFilePassword;
//     }
// 
//     /**
//      * The username to authenticate as.
//      * @return the username.
//      */
//     public String getUsername() {
//         return username;
//     }
// 
//     /**
//      * The phrase of private key.
//      * @return the phrase.
//      */
//     public byte[] getPrivateKeyPhrase() {
//         return privateKeyPhrase;
//     }
// }


// Path: src/main/java/com/sonymobile/tools/gerrit/gerritevents/GerritQueryHandlerWithPersistedConnection.java
import com.sonymobile.tools.gerrit.gerritevents.ssh.Authentication;
import com.sonymobile.tools.gerrit.gerritevents.ssh.SshConnection;
import java.io.IOException;

package com.sonymobile.tools.gerrit.gerritevents;



/**
 * {@link GerritQueryHandler} with a persisted SSH connection.
 * Saves the performance overhead of creating a new connection for each query.
 */
public class GerritQueryHandlerWithPersistedConnection extends GerritQueryHandler {

    private SshConnection activeConnection = null;

    /**
     * Creates a {@link GerritQueryHandler} with persisted SSH connection.
     *
     * @param gerritHostName    the hostName
     * @param gerritSshPort     the ssh port that the gerrit server listens to.
     * @param gerritProxy       the ssh Proxy url
     * @param authentication    the authentication credentials.
     * @param connectionTimeout the connection timeout.
     */
    public GerritQueryHandlerWithPersistedConnection(String gerritHostName, int gerritSshPort,
                                                     String gerritProxy, Authentication authentication,
                                                     int connectionTimeout) {
        super(gerritHostName, gerritSshPort, gerritProxy, authentication, connectionTimeout);
    }

    /**
     * Returns a fresh SSH connection if the persisted one is not valid.
     * Otherwise returns the existing connection.
     *
     * @return an active SSH connection
     * @throws IOException for IO issues
     */
    @Override
    protected SshConnection getConnection() throws IOException {
        if (!isPersistedConnectionValid()) {
            activeConnection = super.getConnection();
            logger.trace("SSH connection is not valid anymore, a new one was created.");