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
Connection
implementation.-
Nested Class Summary
Nested classes/interfaces inherited from interface net.schmizz.sshj.common.ErrorNotifiable
ErrorNotifiable.Util
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Queue
<Promise<SSHPacket, ConnectionException>> private final Object
private final KeepAlive
keep-alive
mechanismprivate int
private final AtomicInteger
private final Map
<String, ForwardedChannelOpener> private int
private long
Fields inherited from class net.schmizz.sshj.AbstractService
log, name, trans
-
Constructor Summary
ConstructorsConstructorDescriptionConnectionImpl
(Transport trans, KeepAliveProvider keepAlive) Create with an associatedTransport
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 an attachedChannel
.void
forget
(ForwardedChannelOpener opener) Forget an attachedForwardedChannelOpener
.get
(int id) private Channel
getChannel
(SSHPacket buffer) int
int
long
private void
gotChannelOpen
(SSHPacket buf) private void
gotGlobalReqResponse
(SSHPacket response) private void
void
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
.sendGlobalRequest
(String name, boolean wantReply, byte[] specifics) Send an SSH global request.void
sendOpenFailure
(int recipient, OpenFailException.Reason reason, 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
-
Field Details
-
internalSynchronizer
-
nextID
-
channels
-
openers
-
globalReqPromises
-
keepAlive
keep-alive
mechanism -
windowSize
private long windowSize -
maxPacketSize
private int maxPacketSize -
timeoutMs
private volatile int timeoutMs
-
-
Constructor Details
-
ConnectionImpl
Create with an associatedTransport
.- Parameters:
trans
- transport layerkeepAlive
- the keep alive provider
-
-
Method Details
-
attach
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
- 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
- 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
Description copied from interface:Connection
Forget an attachedChannel
.- Specified by:
forget
in interfaceConnection
- Parameters:
chan
- the channel
-
forget
Description copied from interface:Connection
Forget an attachedForwardedChannelOpener
.- Specified by:
forget
in interfaceConnection
- Parameters:
opener
- the opener to forget
-
attach
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
-
getChannel
- Throws:
ConnectionException
-
handle
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
- 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
Description copied from interface:Connection
Wait for the situation that no channels are attached (e.g., got closed).- Specified by:
join
in interfaceConnection
- Throws:
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(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
-
gotGlobalReqResponse
- Throws:
ConnectionException
-
gotChannelOpen
-
sendOpenFailure
public void sendOpenFailure(int recipient, OpenFailException.Reason reason, 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
Description copied from interface:ErrorNotifiable
Notifies this object of anerror
.- Specified by:
notifyError
in interfaceErrorNotifiable
- Overrides:
notifyError
in classAbstractService
-
gotGlobalRequest
-
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
- Specified by:
getKeepAlive
in interfaceConnection
- Returns:
- The configured
KeepAlive
mechanism.
-