Package net.schmizz.sshj.connection
Class ConnectionImpl
- java.lang.Object
-
- net.schmizz.sshj.AbstractService
-
- net.schmizz.sshj.connection.ConnectionImpl
-
- All Implemented Interfaces:
ErrorNotifiable
,SSHPacketHandler
,Connection
,Service
public class ConnectionImpl extends AbstractService implements Connection
Connection
implementation.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.schmizz.sshj.common.ErrorNotifiable
ErrorNotifiable.Util
-
-
Field Summary
-
Fields inherited from class net.schmizz.sshj.AbstractService
log, name, trans
-
-
Constructor Summary
Constructors Constructor Description ConnectionImpl(Transport trans, KeepAliveProvider keepAlive)
Create with an associatedTransport
.
-
Method Summary
Modifier and Type Method Description void
attach(Channel chan)
Attach aChannel
to this connection.void
attach(ForwardedChannelOpener opener)
Attach aForwardedChannelOpener
to this connection, which will be delegated opening of anyCHANNEL_OPEN
packetsfor which it is responsible
.void
forget(Channel chan)
Forget an attachedChannel
.void
forget(ForwardedChannelOpener opener)
Forget an attachedForwardedChannelOpener
.Channel
get(int id)
ForwardedChannelOpener
get(java.lang.String chanType)
KeepAlive
getKeepAlive()
int
getMaxPacketSize()
int
getTimeoutMs()
Transport
getTransport()
long
getWindowSize()
void
handle(Message msg, SSHPacket buf)
Delegate handling of some SSH packet to this object.void
join()
Wait for the situation that no channels are attached (e.g., got closed).int
nextID()
void
notifyError(SSHException error)
Notifies this object of anerror
.Promise<SSHPacket,ConnectionException>
sendGlobalRequest(java.lang.String name, boolean wantReply, byte[] specifics)
Send an SSH global request.void
sendOpenFailure(int recipient, OpenFailException.Reason reason, java.lang.String message)
Send aSSH_MSG_OPEN_FAILURE
for specifiedReason
andmessage
.void
setMaxPacketSize(int maxPacketSize)
Set the maximum packet size for the local window this connection recommends to anyChannel
's that ask for it.void
setTimeoutMs(int timeoutMs)
void
setWindowSize(long windowSize)
Set the size for the local window this connection recommends to anyChannel
's that ask for it.-
Methods inherited from class net.schmizz.sshj.AbstractService
getName, notifyUnimplemented, request
-
-
-
-
Constructor Detail
-
ConnectionImpl
public ConnectionImpl(Transport trans, KeepAliveProvider keepAlive)
Create with an associatedTransport
.- Parameters:
trans
- transport layerkeepAlive
- the keep alive provider
-
-
Method Detail
-
attach
public void attach(Channel chan)
Description copied from interface:Connection
Attach aChannel
to this connection. A channel must be attached to the connection if it is to receive any channel-specific data that is received.- Specified by:
attach
in interfaceConnection
- Parameters:
chan
- the channel
-
get
public Channel get(int id)
- Specified by:
get
in interfaceConnection
- Parameters:
id
- number of the channel to retrieve- Returns:
- an attached
Channel
of specified channel number, ornull
if no such channel was attached
-
get
public ForwardedChannelOpener get(java.lang.String chanType)
- Specified by:
get
in interfaceConnection
- Parameters:
chanType
- channel type- Returns:
- an attached
ForwardedChannelOpener
of specified channel-type, ornull
if no such channel was attached
-
forget
public void forget(Channel chan)
Description copied from interface:Connection
Forget an attachedChannel
.- Specified by:
forget
in interfaceConnection
- Parameters:
chan
- the channel
-
forget
public void forget(ForwardedChannelOpener opener)
Description copied from interface:Connection
Forget an attachedForwardedChannelOpener
.- Specified by:
forget
in interfaceConnection
- Parameters:
opener
- the opener to forget
-
attach
public void attach(ForwardedChannelOpener opener)
Description copied from interface:Connection
Attach aForwardedChannelOpener
to this connection, which will be delegated opening of anyCHANNEL_OPEN
packetsfor which it is responsible
.- Specified by:
attach
in interfaceConnection
- Parameters:
opener
- an opener for forwarded channels
-
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
- Overrides:
handle
in classAbstractService
- Parameters:
msg
- the SSHmessage identifier
buf
-SSHPacket
containing rest of the request- Throws:
SSHException
- if there is a non-recoverable error
-
getMaxPacketSize
public int getMaxPacketSize()
- Specified by:
getMaxPacketSize
in interfaceConnection
- Returns:
- the maximum packet size for the local window this connection recommends to any
Channel
's that ask for it.
-
getTransport
public Transport getTransport()
- Specified by:
getTransport
in interfaceConnection
- Returns:
- the associated
Transport
.
-
setMaxPacketSize
public void setMaxPacketSize(int maxPacketSize)
Description copied from interface:Connection
Set the maximum packet size for the local window this connection recommends to anyChannel
's that ask for it.- Specified by:
setMaxPacketSize
in interfaceConnection
- Parameters:
maxPacketSize
- maximum packet size in bytes
-
getWindowSize
public long getWindowSize()
- Specified by:
getWindowSize
in interfaceConnection
- Returns:
- the size for the local window this connection recommends to any
Channel
's that ask for it.
-
setWindowSize
public void setWindowSize(long windowSize)
Description copied from interface:Connection
Set the size for the local window this connection recommends to anyChannel
's that ask for it.- Specified by:
setWindowSize
in interfaceConnection
- Parameters:
windowSize
- window size in bytes
-
join
public void join() throws java.lang.InterruptedException
Description copied from interface:Connection
Wait for the situation that no channels are attached (e.g., got closed).- Specified by:
join
in interfaceConnection
- Throws:
java.lang.InterruptedException
- if the thread is interrupted
-
nextID
public int nextID()
- Specified by:
nextID
in interfaceConnection
- Returns:
- an available ID a
Channel
can rightfully claim.
-
sendGlobalRequest
public Promise<SSHPacket,ConnectionException> sendGlobalRequest(java.lang.String name, boolean wantReply, byte[] specifics) throws TransportException
Description copied from interface:Connection
Send an SSH global request.- Specified by:
sendGlobalRequest
in interfaceConnection
- Parameters:
name
- request namewantReply
- whether a reply is requestedspecifics
-SSHPacket
containing fields specific to the request- Returns:
- a
Promise
for the reply data (in casewantReply
is true) which allows waiting on the reply, ornull
if a reply is not requested. - Throws:
TransportException
- if there is an error sending the request
-
sendOpenFailure
public void sendOpenFailure(int recipient, OpenFailException.Reason reason, java.lang.String message) throws TransportException
Description copied from interface:Connection
Send aSSH_MSG_OPEN_FAILURE
for specifiedReason
andmessage
.- Specified by:
sendOpenFailure
in interfaceConnection
- Parameters:
recipient
- number of the recipient channelreason
- a reason for the failuremessage
- an explanatory message- Throws:
TransportException
- if there is a transport-layer error
-
notifyError
public void notifyError(SSHException error)
Description copied from interface:ErrorNotifiable
Notifies this object of anerror
.- Specified by:
notifyError
in interfaceErrorNotifiable
- Overrides:
notifyError
in classAbstractService
-
setTimeoutMs
public void setTimeoutMs(int timeoutMs)
Description copied from interface:Connection
Set thetimeout
this connection uses for blocking operations and recommends to anyother
classes
that ask for it.- Specified by:
setTimeoutMs
in interfaceConnection
- Parameters:
timeoutMs
- timeout in milliseconds
-
getTimeoutMs
public int getTimeoutMs()
- Specified by:
getTimeoutMs
in interfaceConnection
- Returns:
- the
timeout
in milliseconds that this connection uses for blocking operations and recommends to anyother
classes
that ask for it.
-
getKeepAlive
public KeepAlive getKeepAlive()
- Specified by:
getKeepAlive
in interfaceConnection
- Returns:
- The configured
KeepAlive
mechanism.
-
-