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
Connectionimplementation.
-
-
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 voidattach(Channel chan)Attach aChannelto this connection.voidattach(ForwardedChannelOpener opener)Attach aForwardedChannelOpenerto this connection, which will be delegated opening of anyCHANNEL_OPENpacketsfor which it is responsible.voidforget(Channel chan)Forget an attachedChannel.voidforget(ForwardedChannelOpener opener)Forget an attachedForwardedChannelOpener.Channelget(int id)ForwardedChannelOpenerget(java.lang.String chanType)KeepAlivegetKeepAlive()intgetMaxPacketSize()intgetTimeoutMs()TransportgetTransport()longgetWindowSize()voidhandle(Message msg, SSHPacket buf)Delegate 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.Promise<SSHPacket,ConnectionException>sendGlobalRequest(java.lang.String name, boolean wantReply, byte[] specifics)Send an SSH global request.voidsendOpenFailure(int recipient, OpenFailException.Reason reason, java.lang.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 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: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
public Channel get(int id)
- 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
public ForwardedChannelOpener get(java.lang.String chanType)
- Specified by:
getin interfaceConnection- Parameters:
chanType- channel type- Returns:
- an attached
ForwardedChannelOpenerof specified channel-type, ornullif no such channel was attached
-
forget
public void forget(Channel chan)
Description copied from interface:ConnectionForget an attachedChannel.- Specified by:
forgetin interfaceConnection- Parameters:
chan- the channel
-
forget
public void forget(ForwardedChannelOpener opener)
Description copied from interface:ConnectionForget an attachedForwardedChannelOpener.- Specified by:
forgetin interfaceConnection- Parameters:
opener- the opener to forget
-
attach
public void attach(ForwardedChannelOpener opener)
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
-
handle
public void handle(Message msg, SSHPacket buf) throws SSHException
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
public Transport 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
public void join() throws java.lang.InterruptedExceptionDescription copied from interface:ConnectionWait for the situation that no channels are attached (e.g., got closed).- Specified by:
joinin interfaceConnection- Throws:
java.lang.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(java.lang.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
-
sendOpenFailure
public void sendOpenFailure(int recipient, OpenFailException.Reason reason, java.lang.String message) throws TransportExceptionDescription 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
public void notifyError(SSHException error)
Description copied from interface:ErrorNotifiableNotifies this object of anerror.- Specified by:
notifyErrorin interfaceErrorNotifiable- Overrides:
notifyErrorin classAbstractService
-
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
public KeepAlive getKeepAlive()
- Specified by:
getKeepAlivein interfaceConnection- Returns:
- The configured
KeepAlivemechanism.
-
-