public abstract class Channel extends Object implements Runnable
Session
.
It should be considered an implementation detail that
Channel implements Runnable
– external code never
has to invoke the run()
method.
Session.openChannel(java.lang.String)
Modifier and Type | Field and Description |
---|---|
protected byte[] |
type |
Modifier and Type | Method and Description |
---|---|
void |
connect()
Opens the channel without any timeout.
|
void |
connect(int connectTimeout)
Opens the channel.
|
void |
disconnect()
disconnects this channel.
|
protected com.jcraft.jsch.Packet |
genChannelOpenPacket() |
int |
getExitStatus()
retrieves the exit status of the remote command corresponding
to this channel.
|
InputStream |
getExtInputStream()
Gets an InputStream for extended data of this channel.
|
int |
getId()
returns the session-specific identifier of the channel.
|
InputStream |
getInputStream()
Gets an InputStream for this channel.
|
OutputStream |
getOutputStream()
Gets an OutputStream for this channel.
|
Session |
getSession()
Retrieves the session to which this channel belongs.
|
boolean |
isClosed()
returns true if this channel is already closed
(or another thread is in progress of closing the channel).
|
boolean |
isConnected()
returns true if this channel is currently
connected (which also means that the session
is still connected).
|
boolean |
isEOF()
Checks if we have already read all the data,
i.e. whether the remote side sent an end-of-file
notification for this channel.
|
void |
run()
not to be called externally.
|
protected void |
sendChannelOpen() |
protected void |
sendOpenConfirmation()
sends a message confirming the opening of the channel.
|
protected void |
sendOpenFailure(int reasoncode)
sends a message indicating the failure of a channel-opening
to the remote side.
|
void |
sendSignal(String signal)
sends a signal to the process at the other side.
|
void |
setExtOutputStream(OutputStream out)
Sets the OutputStream for extended data for this channel.
|
void |
setExtOutputStream(OutputStream out,
boolean dontclose)
Sets the OutputStream for extended data for this channel.
|
void |
setInputStream(InputStream in)
Sets the InputStream for this channel.
|
void |
setInputStream(InputStream in,
boolean dontclose)
Sets the InputStream for this channel.
|
void |
setOutputStream(OutputStream out)
Sets the OutputStream for this channel.
|
void |
setOutputStream(OutputStream out,
boolean dontclose)
Sets the OutputStream for this channel.
|
void |
setXForwarding(boolean foo)
Enables or disables X forwarding for this channel.
|
void |
start()
Not to be called externally.
|
public void connect() throws JSchException
connect(0)
if not
overridden in subclasses.JSchException
public void connect(int connectTimeout) throws JSchException
SSH_MSH_CHANNEL_OPEN
message
and waits until the response is received.
Warning: Some subclasses override connect()
instead of
this method, so calling this method with timeout parameter may then
invoke the wrong method.connectTimeout
- the maximum time to wait for the
channel to be established, in milliseconds. If 0, we wait
as long as needed (but at most 1000 times 50 milliseconds each).JSchException
- if a timeout occured, or some other connection
problem.public void setXForwarding(boolean foo)
ChannelShell
, ChannelSftp
,
ChannelExec
, ChannelSubsystem
).public void start() throws JSchException
connect(int)
when the connection
is established.
This implementation here does nothing, but it is overridden in some
subclasses.JSchException
public boolean isEOF()
public void setInputStream(InputStream in)
disconnect(com.jcraft.jsch.Session)
.
This method should be called before connect()
.public void setInputStream(InputStream in, boolean dontclose)
connect()
.dontclose
- if true, we do not close the stream
after usage.public void setOutputStream(OutputStream out)
connect()
.
The stream will be closed on disconnect(com.jcraft.jsch.Session)
.getInputStream()
public void setOutputStream(OutputStream out, boolean dontclose)
connect()
.dontclose
- if true, we do not close the stream
on disconnect(com.jcraft.jsch.Session)
.getInputStream()
public void setExtOutputStream(OutputStream out)
Note: This implementation does not differentiate between different 'data_type_code' values, as RFC 4254 only defines one type, namely SSH_EXTENDED_DATA_STDERR.
This method should be called beforeconnect()
.
The stream will be closed on disconnect(com.jcraft.jsch.Session)
.getExtInputStream()
public void setExtOutputStream(OutputStream out, boolean dontclose)
Note: This implementation does not differentiate between different 'data_type_code' values, as RFC 4254 only defines one type, namely SSH_EXTENDED_DATA_STDERR.
This method should be called beforeconnect()
.dontclose
- if true, we do not close the stream
on disconnect(com.jcraft.jsch.Session)
.getExtInputStream()
public InputStream getInputStream() throws IOException
setOutputStream(java.io.OutputStream)
.
It should be called before connect()
.IOException
public InputStream getExtInputStream() throws IOException
setExtOutputStream(java.io.OutputStream)
.
It should be called before connect()
.IOException
public OutputStream getOutputStream() throws IOException
setInputStream(java.io.InputStream)
.
It should be called before connect()
.IOException
public void run()
public boolean isClosed()
public void disconnect()
public boolean isConnected()
public void sendSignal(String signal) throws Exception
signal
- the signal name, without the "SIG" prefix.Exception
public int getExitStatus()
public Session getSession() throws JSchException
JSchException
- if there is no such session.public int getId()
protected void sendOpenConfirmation() throws Exception
Exception
protected void sendOpenFailure(int reasoncode)
protected com.jcraft.jsch.Packet genChannelOpenPacket()
This is a simplified version of the inofficial Javadoc created by PaĆlo Ebermann. Have a look at the official homepage.