public class ConnectionImpl extends AbstractService implements Connection
Connection
implementation.ErrorNotifiable.Util
log, name, trans
Constructor and Description |
---|
ConnectionImpl(Transport trans,
KeepAliveProvider keepAlive)
Create with an associated
Transport . |
Modifier and Type | Method and Description |
---|---|
void |
attach(Channel chan)
Attach a
Channel to this connection. |
void |
attach(ForwardedChannelOpener opener)
Attach a
ForwardedChannelOpener to this connection, which will be delegated opening of any CHANNEL_OPEN packets for which it is responsible . |
void |
forget(Channel chan)
Forget an attached
Channel . |
void |
forget(ForwardedChannelOpener opener)
Forget an attached
ForwardedChannelOpener . |
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 an
error . |
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 a
SSH_MSG_OPEN_FAILURE for specified Reason and message . |
void |
setMaxPacketSize(int maxPacketSize)
Set the maximum packet size for the local window this connection recommends to any
Channel 's that ask for
it. |
void |
setTimeoutMs(int timeoutMs)
|
void |
setWindowSize(long windowSize)
Set the size for the local window this connection recommends to any
Channel 's that ask for it. |
getName, notifyUnimplemented, request
public ConnectionImpl(Transport trans, KeepAliveProvider keepAlive)
Transport
.config
- the ssh configtrans
- transport layerkeepAlive
- the keep alive providerpublic void attach(Channel chan)
Connection
Channel
to this connection. A channel must be attached to the connection if it is to receive any
channel-specific data that is received.attach
in interface Connection
chan
- the channelpublic Channel get(int id)
get
in interface Connection
id
- number of the channel to retrieveChannel
of specified channel number, or null
if no such channel was attachedpublic ForwardedChannelOpener get(java.lang.String chanType)
get
in interface Connection
chanType
- channel typeForwardedChannelOpener
of specified channel-type, or null
if no such channel
was attachedpublic void forget(Channel chan)
Connection
Channel
.forget
in interface Connection
chan
- the channelpublic void forget(ForwardedChannelOpener opener)
Connection
ForwardedChannelOpener
.forget
in interface Connection
opener
- the opener to forgetpublic void attach(ForwardedChannelOpener opener)
Connection
ForwardedChannelOpener
to this connection, which will be delegated opening of any CHANNEL_OPEN
packets for which it is responsible
.attach
in interface Connection
opener
- an opener for forwarded channelspublic void handle(Message msg, SSHPacket buf) throws SSHException
SSHPacketHandler
handle
in interface SSHPacketHandler
handle
in class AbstractService
msg
- the SSH message identifier
buf
- SSHPacket
containing rest of the requestSSHException
- if there is a non-recoverable errorpublic int getMaxPacketSize()
getMaxPacketSize
in interface Connection
Channel
's that ask
for it.public Transport getTransport()
getTransport
in interface Connection
Transport
.public void setMaxPacketSize(int maxPacketSize)
Connection
Channel
's that ask for
it.setMaxPacketSize
in interface Connection
maxPacketSize
- maximum packet size in bytespublic long getWindowSize()
getWindowSize
in interface Connection
Channel
's that ask for it.public void setWindowSize(long windowSize)
Connection
Channel
's that ask for it.setWindowSize
in interface Connection
windowSize
- window size in bytespublic void join() throws java.lang.InterruptedException
Connection
join
in interface Connection
java.lang.InterruptedException
- if the thread is interruptedpublic int nextID()
nextID
in interface Connection
Channel
can rightfully claim.public Promise<SSHPacket,ConnectionException> sendGlobalRequest(java.lang.String name, boolean wantReply, byte[] specifics) throws TransportException
Connection
sendGlobalRequest
in interface Connection
name
- request namewantReply
- whether a reply is requestedspecifics
- SSHPacket
containing fields specific to the requestPromise
for the reply data (in case wantReply
is true) which
allows waiting on the reply, or null
if a reply is not requested.TransportException
- if there is an error sending the requestpublic void sendOpenFailure(int recipient, OpenFailException.Reason reason, java.lang.String message) throws TransportException
Connection
SSH_MSG_OPEN_FAILURE
for specified Reason
and message
.sendOpenFailure
in interface Connection
recipient
- number of the recipient channelreason
- a reason for the failuremessage
- an explanatory messageTransportException
- if there is a transport-layer errorpublic void notifyError(SSHException error)
ErrorNotifiable
error
.notifyError
in interface ErrorNotifiable
notifyError
in class AbstractService
public void setTimeoutMs(int timeoutMs)
Connection
timeout
this connection uses for blocking operations and recommends to any other
classes
that ask for it.setTimeoutMs
in interface Connection
timeoutMs
- timeout in millisecondspublic int getTimeoutMs()
getTimeoutMs
in interface Connection
timeout
in milliseconds that this connection uses for blocking operations and recommends to
any other
classes
that ask for it.public KeepAlive getKeepAlive()
getKeepAlive
in interface Connection
KeepAlive
mechanism.