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 ErrorNotifiable
ErrorNotifiable.Util -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Queue<Promise<SSHPacket, ConnectionException>> private final Objectprivate final KeepAlivekeep-alivemechanismprivate intprivate final AtomicIntegerprivate final Map<String, ForwardedChannelOpener> private intprivate longFields inherited from class AbstractService
log, name, trans -
Constructor Summary
ConstructorsConstructorDescriptionConnectionImpl(Transport trans, KeepAliveProvider keepAlive) Create with an associatedTransport. -
Method Summary
Modifier and TypeMethodDescriptionvoidAttach aChannelto this connection.voidattach(ForwardedChannelOpener opener) Attach aForwardedChannelOpenerto this connection, which will be delegated opening of anyCHANNEL_OPENpacketsfor which it is responsible.voidForget an attachedChannel.voidforget(ForwardedChannelOpener opener) Forget an attachedForwardedChannelOpener.get(int id) private ChannelgetChannel(SSHPacket buffer) intintlongprivate voidgotChannelOpen(SSHPacket buf) private voidgotGlobalReqResponse(SSHPacket response) private voidvoidDelegate handling of some SSH packet to this object.voidjoin()Wait for the situation that no channels are attached (e.g., got closed).intnextID()voidnotifyError(SSHException error) Notifies this object of anerror.sendGlobalRequest(String name, boolean wantReply, byte[] specifics) Send an SSH global request.voidsendOpenFailure(int recipient, OpenFailException.Reason reason, String message) Send aSSH_MSG_OPEN_FAILUREfor specifiedReasonandmessage.voidsetMaxPacketSize(int maxPacketSize) Set the maximum packet size for the local window this connection recommends to anyChannel's that ask for it.voidsetTimeoutMs(int timeoutMs) voidsetWindowSize(long windowSize) Set the size for the local window this connection recommends to anyChannel's that ask for it.Methods inherited from class AbstractService
getName, notifyUnimplemented, request
-
Field Details
-
internalSynchronizer
-
nextID
-
channels
-
openers
-
globalReqPromises
-
keepAlive
keep-alivemechanism -
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:ConnectionAttach aChannelto this connection. A channel must be attached to the connection if it is to receive any channel-specific data that is received.- Specified by:
attachin interfaceConnection- Parameters:
chan- the channel
-
get
- Specified by:
getin interfaceConnection- Parameters:
id- number of the channel to retrieve- Returns:
- an attached
Channelof specified channel number, ornullif no such channel was attached
-
get
- Specified by:
getin interfaceConnection- Parameters:
chanType- channel type- Returns:
- an attached
ForwardedChannelOpenerof specified channel-type, ornullif no such channel was attached
-
forget
Description copied from interface:ConnectionForget an attachedChannel.- Specified by:
forgetin interfaceConnection- Parameters:
chan- the channel
-
forget
Description copied from interface:ConnectionForget an attachedForwardedChannelOpener.- Specified by:
forgetin interfaceConnection- Parameters:
opener- the opener to forget
-
attach
Description copied from interface:ConnectionAttach aForwardedChannelOpenerto this connection, which will be delegated opening of anyCHANNEL_OPENpacketsfor which it is responsible.- Specified by:
attachin interfaceConnection- Parameters:
opener- an opener for forwarded channels
-
getChannel
- Throws:
ConnectionException
-
handle
Description copied from interface:SSHPacketHandlerDelegate handling of some SSH packet to this object.- Specified by:
handlein interfaceSSHPacketHandler- Overrides:
handlein classAbstractService- Parameters:
msg- the SSHmessage identifierbuf-SSHPacketcontaining rest of the request- Throws:
SSHException- if there is a non-recoverable error
-
getMaxPacketSize
public int getMaxPacketSize()- Specified by:
getMaxPacketSizein interfaceConnection- Returns:
- the maximum packet size for the local window this connection recommends to any
Channel's that ask for it.
-
getTransport
- Specified by:
getTransportin interfaceConnection- Returns:
- the associated
Transport.
-
setMaxPacketSize
public void setMaxPacketSize(int maxPacketSize) Description copied from interface:ConnectionSet the maximum packet size for the local window this connection recommends to anyChannel's that ask for it.- Specified by:
setMaxPacketSizein interfaceConnection- Parameters:
maxPacketSize- maximum packet size in bytes
-
getWindowSize
public long getWindowSize()- Specified by:
getWindowSizein 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:ConnectionSet the size for the local window this connection recommends to anyChannel's that ask for it.- Specified by:
setWindowSizein interfaceConnection- Parameters:
windowSize- window size in bytes
-
join
Description copied from interface:ConnectionWait for the situation that no channels are attached (e.g., got closed).- Specified by:
joinin interfaceConnection- Throws:
InterruptedException- if the thread is interrupted
-
nextID
public int nextID()- Specified by:
nextIDin interfaceConnection- Returns:
- an available ID a
Channelcan rightfully claim.
-
sendGlobalRequest
public Promise<SSHPacket, ConnectionException> sendGlobalRequest(String name, boolean wantReply, byte[] specifics) throws TransportException Description copied from interface:ConnectionSend an SSH global request.- Specified by:
sendGlobalRequestin interfaceConnection- Parameters:
name- request namewantReply- whether a reply is requestedspecifics-SSHPacketcontaining fields specific to the request- Returns:
- a
Promisefor the reply data (in casewantReplyis true) which allows waiting on the reply, ornullif 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:ConnectionSend aSSH_MSG_OPEN_FAILUREfor specifiedReasonandmessage.- Specified by:
sendOpenFailurein 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:ErrorNotifiableNotifies this object of anerror.- Specified by:
notifyErrorin interfaceErrorNotifiable- Overrides:
notifyErrorin classAbstractService
-
gotGlobalRequest
-
setTimeoutMs
public void setTimeoutMs(int timeoutMs) Description copied from interface:ConnectionSet thetimeoutthis connection uses for blocking operations and recommends to anyotherclassesthat ask for it.- Specified by:
setTimeoutMsin interfaceConnection- Parameters:
timeoutMs- timeout in milliseconds
-
getTimeoutMs
public int getTimeoutMs()- Specified by:
getTimeoutMsin interfaceConnection- Returns:
- the
timeoutin milliseconds that this connection uses for blocking operations and recommends to anyotherclassesthat ask for it.
-
getKeepAlive
- Specified by:
getKeepAlivein interfaceConnection- Returns:
- The configured
KeepAlivemechanism.
-