Class AbstractChannel
- java.lang.Object
-
- net.schmizz.sshj.connection.channel.AbstractChannel
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ErrorNotifiable
,SSHPacketHandler
,Channel
- Direct Known Subclasses:
AbstractDirectChannel
,AbstractForwardedChannel
public abstract class AbstractChannel extends java.lang.Object implements Channel
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AbstractChannel.TransportRunnable
-
Nested classes/interfaces inherited from interface net.schmizz.sshj.connection.channel.Channel
Channel.Direct, Channel.Forwarded
-
Nested classes/interfaces inherited from interface net.schmizz.sshj.common.ErrorNotifiable
ErrorNotifiable.Util
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
autoExpand
private java.util.Queue<Event<ConnectionException>>
chanReqResponseEvents
protected Event<ConnectionException>
closeEvent
Channel close eventprivate boolean
closeRequested
Whether we have already sent a CHANNEL_CLOSE request to the serverprotected Connection
conn
Connection layerprivate boolean
eof
private int
id
Channel IDprivate ChannelInputStream
in
stdout streamprotected org.slf4j.Logger
log
protected LoggerFactory
loggerFactory
Loggerprotected Window.Local
lwin
Local windowprivate java.util.concurrent.locks.ReentrantLock
openCloseLock
protected Event<ConnectionException>
openEvent
Channel open eventprivate ChannelOutputStream
out
stdin streamprivate int
recipient
Remote recipient IDprivate static int
REMOTE_MAX_PACKET_SIZE_CEILING
private java.nio.charset.Charset
remoteCharset
Remote character setprotected Window.Remote
rwin
Remote windowprotected Transport
trans
Transport layerprivate java.lang.String
type
Channel type
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractChannel(Connection conn, java.lang.String type)
protected
AbstractChannel(Connection conn, java.lang.String type, java.nio.charset.Charset remoteCharset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this channel.protected void
closeAllStreams()
Called when all I/O streams should be closed.protected void
eofInputStreams()
Called when EOF has been received.protected void
finishOff()
boolean
getAutoExpand()
int
getID()
java.io.InputStream
getInputStream()
int
getLocalMaxPacketSize()
long
getLocalWinSize()
LoggerFactory
getLoggerFactory()
Get the LoggerFactory associated with the SSH client.java.io.OutputStream
getOutputStream()
int
getRecipient()
java.nio.charset.Charset
getRemoteCharset()
int
getRemoteMaxPacketSize()
long
getRemoteWinSize()
java.lang.String
getType()
private void
gotChannelRequest(SSHPacket buf)
private void
gotClose()
private void
gotEOF()
protected void
gotExtendedData(SSHPacket buf)
private void
gotResponse(boolean success)
protected void
gotUnknown(Message msg, SSHPacket buf)
private void
gotWindowAdjustment(SSHPacket buf)
void
handle(Message msg, SSHPacket buf)
Delegate handling of some SSH packet to this object.protected void
handleRequest(java.lang.String reqType, SSHPacket buf)
protected void
init(int recipient, long remoteWinSize, long remoteMaxPacketSize)
boolean
isEOF()
Returns whether EOF has been received.boolean
isOpen()
void
join()
void
join(long timeout, java.util.concurrent.TimeUnit unit)
protected SSHPacket
newBuffer(Message cmd)
void
notifyError(SSHException error)
Notifies this object of anerror
.protected void
receiveInto(ChannelInputStream stream, SSHPacket buf)
protected Event<ConnectionException>
sendChannelRequest(java.lang.String reqType, boolean wantReply, Buffer.PlainBuffer reqSpecific)
protected void
sendClose()
void
setAutoExpand(boolean autoExpand)
Set whether local window should automatically expand when data is received, irrespective of whether data has been read from that stream.java.lang.String
toString()
(package private) boolean
whileOpen(AbstractChannel.TransportRunnable runnable)
-
-
-
Field Detail
-
REMOTE_MAX_PACKET_SIZE_CEILING
private static final int REMOTE_MAX_PACKET_SIZE_CEILING
- See Also:
- Constant Field Values
-
loggerFactory
protected final LoggerFactory loggerFactory
Logger
-
log
protected final org.slf4j.Logger log
-
trans
protected final Transport trans
Transport layer
-
conn
protected final Connection conn
Connection layer
-
type
private final java.lang.String type
Channel type
-
id
private final int id
Channel ID
-
recipient
private int recipient
Remote recipient ID
-
remoteCharset
private final java.nio.charset.Charset remoteCharset
Remote character set
-
eof
private boolean eof
-
chanReqResponseEvents
private final java.util.Queue<Event<ConnectionException>> chanReqResponseEvents
-
openCloseLock
private final java.util.concurrent.locks.ReentrantLock openCloseLock
-
openEvent
protected final Event<ConnectionException> openEvent
Channel open event
-
closeEvent
protected final Event<ConnectionException> closeEvent
Channel close event
-
closeRequested
private boolean closeRequested
Whether we have already sent a CHANNEL_CLOSE request to the server
-
lwin
protected final Window.Local lwin
Local window
-
in
private final ChannelInputStream in
stdout stream
-
rwin
protected Window.Remote rwin
Remote window
-
out
private ChannelOutputStream out
stdin stream
-
autoExpand
private volatile boolean autoExpand
-
-
Constructor Detail
-
AbstractChannel
protected AbstractChannel(Connection conn, java.lang.String type)
-
AbstractChannel
protected AbstractChannel(Connection conn, java.lang.String type, java.nio.charset.Charset remoteCharset)
-
-
Method Detail
-
init
protected void init(int recipient, long remoteWinSize, long remoteMaxPacketSize)
-
getAutoExpand
public boolean getAutoExpand()
- Specified by:
getAutoExpand
in interfaceChannel
- Returns:
- whether auto-expansion of local window is set.
- See Also:
Channel.setAutoExpand(boolean)
-
getInputStream
public java.io.InputStream getInputStream()
- Specified by:
getInputStream
in interfaceChannel
- Returns:
- the
InputStream
for this channel.
-
getLocalMaxPacketSize
public int getLocalMaxPacketSize()
- Specified by:
getLocalMaxPacketSize
in interfaceChannel
- Returns:
- the maximum packet size that we have specified.
-
getLocalWinSize
public long getLocalWinSize()
- Specified by:
getLocalWinSize
in interfaceChannel
- Returns:
- the current local window size.
-
getOutputStream
public java.io.OutputStream getOutputStream()
- Specified by:
getOutputStream
in interfaceChannel
- Returns:
- an
OutputStream
for this channel.
-
getRecipient
public int getRecipient()
- Specified by:
getRecipient
in interfaceChannel
- Returns:
- the channel ID at the remote end.
-
getRemoteCharset
public java.nio.charset.Charset getRemoteCharset()
- Specified by:
getRemoteCharset
in interfaceChannel
- Returns:
- the character set used to communicate with the remote machine for certain strings (like paths).
-
getRemoteMaxPacketSize
public int getRemoteMaxPacketSize()
- Specified by:
getRemoteMaxPacketSize
in interfaceChannel
- Returns:
- the maximum packet size as specified by the remote end.
-
getRemoteWinSize
public long getRemoteWinSize()
- Specified by:
getRemoteWinSize
in interfaceChannel
- Returns:
- the current remote window size.
-
getType
public java.lang.String getType()
-
handle
public void handle(Message msg, SSHPacket buf) throws SSHException
Description copied from interface:SSHPacketHandler
Delegate handling of some SSH packet to this object.- Specified by:
handle
in interfaceSSHPacketHandler
- Parameters:
msg
- the SSHmessage identifier
buf
-SSHPacket
containing rest of the request- Throws:
SSHException
- if there is a non-recoverable error
-
isEOF
public boolean isEOF()
Description copied from interface:Channel
Returns whether EOF has been received.
-
getLoggerFactory
public LoggerFactory getLoggerFactory()
Description copied from interface:Channel
Get the LoggerFactory associated with the SSH client.- Specified by:
getLoggerFactory
in interfaceChannel
-
gotClose
private void gotClose() throws TransportException
- Throws:
TransportException
-
closeAllStreams
protected void closeAllStreams()
Called when all I/O streams should be closed. Subclasses can override but must call super.
-
notifyError
public void notifyError(SSHException error)
Description copied from interface:ErrorNotifiable
Notifies this object of anerror
.- Specified by:
notifyError
in interfaceErrorNotifiable
-
setAutoExpand
public void setAutoExpand(boolean autoExpand)
Description copied from interface:Channel
Set whether local window should automatically expand when data is received, irrespective of whether data has been read from that stream. This is useful e.g. when a remote command produces a lot of output that would fill the local window but you are not interested in reading from itsInputStream
.- Specified by:
setAutoExpand
in interfaceChannel
- Parameters:
autoExpand
- whether local windows should automatically expand
-
close
public void close() throws ConnectionException, TransportException
Description copied from interface:Channel
Close this channel.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
ConnectionException
TransportException
-
join
public void join() throws ConnectionException
- Specified by:
join
in interfaceChannel
- Throws:
ConnectionException
-
join
public void join(long timeout, java.util.concurrent.TimeUnit unit) throws ConnectionException
- Specified by:
join
in interfaceChannel
- Throws:
ConnectionException
-
sendClose
protected void sendClose() throws TransportException
- Throws:
TransportException
-
isOpen
public boolean isOpen()
-
whileOpen
boolean whileOpen(AbstractChannel.TransportRunnable runnable) throws TransportException, ConnectionException
-
gotChannelRequest
private void gotChannelRequest(SSHPacket buf) throws ConnectionException, TransportException
-
gotWindowAdjustment
private void gotWindowAdjustment(SSHPacket buf) throws ConnectionException
- Throws:
ConnectionException
-
finishOff
protected void finishOff()
-
gotExtendedData
protected void gotExtendedData(SSHPacket buf) throws SSHException
- Throws:
SSHException
-
gotUnknown
protected void gotUnknown(Message msg, SSHPacket buf) throws ConnectionException, TransportException
-
handleRequest
protected void handleRequest(java.lang.String reqType, SSHPacket buf) throws ConnectionException, TransportException
-
receiveInto
protected void receiveInto(ChannelInputStream stream, SSHPacket buf) throws SSHException
- Throws:
SSHException
-
sendChannelRequest
protected Event<ConnectionException> sendChannelRequest(java.lang.String reqType, boolean wantReply, Buffer.PlainBuffer reqSpecific) throws TransportException
- Throws:
TransportException
-
gotResponse
private void gotResponse(boolean success) throws ConnectionException
- Throws:
ConnectionException
-
gotEOF
private void gotEOF() throws TransportException
- Throws:
TransportException
-
eofInputStreams
protected void eofInputStreams()
Called when EOF has been received. Subclasses can override but must call super.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-