com.sonyericsson.hudson.plugins.gerrit.gerritevents.ssh
Class SshConnectionImpl

java.lang.Object
  extended by com.sonyericsson.hudson.plugins.gerrit.gerritevents.ssh.SshConnectionImpl
All Implemented Interfaces:
SshConnection

public class SshConnectionImpl
extends Object
implements SshConnection

A simple ssh client connection with private key.

Author:
Robert Sandell <robert.sandell@sonyericsson.com>

Field Summary
protected static String CMD_EXEC
          SSH Command to open an "exec channel".
 
Constructor Summary
protected SshConnectionImpl(String host, int port, Authentication authentication)
          Creates and opens a SshConnection.
 
Method Summary
 void disconnect()
          Disconnects the connection.
 String executeCommand(String command)
          Execute an ssh command on the server.
 com.jcraft.jsch.ChannelExec executeCommandChannel(String command)
          This version takes a command to run, and then returns a wrapper instance that exposes all the standard state of the channel (stdin, stdout, stderr, exit status, etc).
 Reader executeCommandReader(String command)
          Execute an ssh command on the server, without closing the session so that a Reader can be returned with streaming data from the server.
 boolean isAuthenticated()
          Is the connection authenticated.
 boolean isConnected()
          Is the connection connected.
 boolean isSessionOpen()
          Returns if there already is an open session on this connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CMD_EXEC

protected static final String CMD_EXEC
SSH Command to open an "exec channel".

See Also:
Constant Field Values
Constructor Detail

SshConnectionImpl

protected SshConnectionImpl(String host,
                            int port,
                            Authentication authentication)
                     throws SshException,
                            IOException
Creates and opens a SshConnection.

Parameters:
host - the host to connect to.
port - the port.
authentication - the authentication-info
Throws:
SshException - if something happens - usually due to bad config.
IOException - if the unfortunate happens.
Method Detail

isConnected

public boolean isConnected()
Is the connection connected.

Specified by:
isConnected in interface SshConnection
Returns:
true if it is so.

isAuthenticated

public boolean isAuthenticated()
Is the connection authenticated.

Specified by:
isAuthenticated in interface SshConnection
Returns:
true if it is so.

isSessionOpen

public boolean isSessionOpen()
Returns if there already is an open session on this connection.

Specified by:
isSessionOpen in interface SshConnection
Returns:
true if it is so.

executeCommand

public String executeCommand(String command)
                      throws SshException
Execute an ssh command on the server. After the command is sent the used channel is disconnected.

Specified by:
executeCommand in interface SshConnection
Parameters:
command - the command to execute.
Returns:
a String containing the output from the command.
Throws:
SshException - if so.

executeCommandReader

public Reader executeCommandReader(String command)
                            throws SshException,
                                   IOException
Execute an ssh command on the server, without closing the session so that a Reader can be returned with streaming data from the server.

Specified by:
executeCommandReader in interface SshConnection
Parameters:
command - the command to execute.
Returns:
a Reader with streaming data from the server.
Throws:
IOException - if it is so.
SshException - if there are any ssh problems.

executeCommandChannel

public com.jcraft.jsch.ChannelExec executeCommandChannel(String command)
                                                  throws SshException,
                                                         IOException
This version takes a command to run, and then returns a wrapper instance that exposes all the standard state of the channel (stdin, stdout, stderr, exit status, etc).

Specified by:
executeCommandChannel in interface SshConnection
Parameters:
command - the command to execute.
Returns:
a Channel with access to all streams and the exit code.
Throws:
IOException - if it is so.
SshException - if there are any ssh problems.
See Also:
executeCommandReader(String)

disconnect

public void disconnect()
Disconnects the connection.

Specified by:
disconnect in interface SshConnection


Copyright © 2004-2012 Hudson. All Rights Reserved.