|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.maverick.sshd.Channel
public abstract class Channel
This abstract class provides the basic functions of an SSH2 channel. All terminal sessions, forwarded connections etc, are channels. Either side may open a channel and multiple channels are multiplexed into a single connection. Channels are flow-controlled so that no data may be sent to a channel until a message is received to indicate that a window space is available.
Channel implementations are identified by name and to support the
opening of a channel your server should add the channel's unique name to the
com.maverick.sshd.ConfigurationContext#supportedChannels(). This can
be completed in your com.maverick.sshd.SshDaemon#configure(ConfigurationContext) method.
protected void configure(ConfigurationContext context) {
context.supportedChannels().add(
"chat@sshtools.com",
Class.forName("com.sshtools.ChatChannel"));
}
Data sent by the channel is buffered and sent when window space is available
on the remote side. The incoming window space is decremented whenever data is
received with the abstract #evaluateWindowSpace(int) method being called
to enable the channel implementation to add further window space should it
require.
| Nested Class Summary | |
|---|---|
protected class |
Channel.QueuedData
|
| Field Summary | |
|---|---|
protected ConnectionProtocol |
connection
The Connection Protocol instance managing this session, use this instance to disconnect the session or obtain the ip address of the remote client. |
protected long |
localwindow
|
protected Object |
localWindowLock
|
protected int |
state
|
| Constructor Summary | |
|---|---|
Channel(String channelType,
int maximumPacketSize,
long initialWindowSize)
Construct a channel with the specified settings. |
|
| Method Summary | |
|---|---|
void |
addEventListener(ChannelEventListener listener)
Enable other objects to receive channel events |
void |
addInputListener(OutputStream out)
Add an OutputStream to receive all channel data input from the remote side of the connection. |
void |
addOutputListener(OutputStream out)
Add an OutputStream to receive all of the channels output. |
protected boolean |
canClose()
Can this channel close? |
void |
close()
This method closes the channel and free's its resources. |
protected abstract byte[] |
createChannel()
Called when the channel is being created. |
protected abstract void |
evaluateWindowSpace(long remaining)
Called to evaluate the window space available. |
ConnectionProtocol |
getConnection()
Returns the ConnectionProtocol associated with this channel. |
SshContext |
getContext()
Get the current configuration from the underlying connection. |
abstract String |
getInformation()
|
int |
getLocalId()
The local channel id |
int |
getLocalPacket()
The maximum size of a single packet that the local side will accept. |
long |
getLocalWindow()
The current size of the local data window. |
String |
getName()
The name of this channel. |
int |
getQueueSize()
|
int |
getRemoteId()
The remote sides channel id |
int |
getRemotePacket()
The maximum size of a single packet that the remote side will accept. |
long |
getRemoteWindow()
The current size of the remote data window. |
String |
getSessionIdentifier()
Get the session id for the current connection. |
protected boolean |
hasQueuedData()
|
protected void |
idle(org.apache.mina.core.session.IdleStatus status)
|
boolean |
isClosed()
Indicates the channel has been closed |
boolean |
isClosing()
Indicates whether the channel is currently performing a close operation |
boolean |
isEOF()
Indicates that the channel is EOF (it will not be receiving any more data from the remote side). |
boolean |
isLocalEOF()
|
boolean |
isOpen()
Get the open state of the channel. |
boolean |
isRemoteEOF()
|
protected abstract void |
onChannelClosed()
Called when the channel has been closed to enable resources to be freed. |
protected abstract void |
onChannelClosing()
Called before the channel is closed |
protected abstract void |
onChannelData(byte[] data)
Called by the channel when data arrives from the remote side. |
protected abstract void |
onChannelFree()
This method is called when the channel has been closed and all its resources are no longer required. |
protected abstract void |
onChannelOpen()
Called when the channel has been opened - this method is only called when the remote side requests a channel open. |
protected abstract void |
onChannelOpenConfirmation()
Called when the channel has been confirmed as open by the remote side - this method is only called when the channel has been requested by this side of the connection |
protected void |
onChannelOpenFailure()
Called when the remote side fails to open a channel in response to our request. |
protected abstract void |
onChannelRequest(String type,
boolean wantreply,
byte[] requestdata)
Called when a channel request is received. |
protected abstract void |
onExtendedData(byte[] data,
int type)
Called by the channel when extended data arrives |
protected abstract void |
onLocalEOF()
Called when the local side is EOF. |
protected void |
onRemoteClose()
Called when the remote side closes the channel. |
protected abstract void |
onRemoteEOF()
Called when the remote side reports its OutputStream as EOF. |
protected void |
onWindowAdjust(int count)
|
protected abstract byte[] |
openChannel(byte[] requestdata)
Called when the channel is being opened. |
protected int |
queueSize()
|
protected void |
registerExtendedData(int type)
Call this method to register an extended data type. |
void |
removeEventListener(ChannelEventListener listener)
|
void |
sendChannelData(org.apache.mina.core.buffer.IoBuffer buf)
Send channel data to the remote side of the channel. |
void |
sendChannelData(org.apache.mina.core.buffer.IoBuffer buf,
Runnable r)
|
protected void |
sendChannelRequest(String type,
boolean wantreply,
byte[] requestdata)
Send a channel request. |
protected void |
sendEOF()
You can send EOF when you have no more data to send. |
protected void |
sendExtendedData(org.apache.mina.core.buffer.IoBuffer buf,
int type)
Send extended channel data. |
protected void |
sendRequestResponse(boolean succeeded)
Send a channel request. |
protected void |
sendWindowAdjust(long count)
Adjust the local window by adding more bytes. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected ConnectionProtocol connection
protected long localwindow
protected Object localWindowLock
protected int state
| Constructor Detail |
|---|
public Channel(String channelType,
int maximumPacketSize,
long initialWindowSize)
channelType - the name of the channel, for example "session" or "tcpip-forward"maximumPacketSize - the maximum size of an individual packet that the remote side can send through the channelinitialWindowSize - the initial size of the local window.| Method Detail |
|---|
public boolean isClosed()
public boolean isLocalEOF()
public boolean isRemoteEOF()
public abstract String getInformation()
public boolean isEOF()
public int getQueueSize()
public void addEventListener(ChannelEventListener listener)
listener - public void removeEventListener(ChannelEventListener listener)
public void addInputListener(OutputStream out)
out - OutputStreampublic void addOutputListener(OutputStream out)
out - OutputStreampublic String getName()
getName in interface com.maverick.ssh.components.SshComponentpublic long getRemoteWindow()
public long getLocalWindow()
public int getLocalPacket()
public int getRemotePacket()
public int getLocalId()
public int getRemoteId()
protected int queueSize()
protected void registerExtendedData(int type)
throws IOException
type -
IOExceptionpublic String getSessionIdentifier()
protected void onWindowAdjust(int count)
protected boolean hasQueuedData()
public ConnectionProtocol getConnection()
ConnectionProtocol associated with this channel.
public void sendChannelData(org.apache.mina.core.buffer.IoBuffer buf)
data - off - len -
public void sendChannelData(org.apache.mina.core.buffer.IoBuffer buf,
Runnable r)
public SshContext getContext()
protected void sendExtendedData(org.apache.mina.core.buffer.IoBuffer buf,
int type)
data - off - len - type - protected abstract void onChannelData(byte[] data)
data -
protected abstract void onExtendedData(byte[] data,
int type)
data -
protected void sendChannelRequest(String type,
boolean wantreply,
byte[] requestdata)
Send a channel request. Many channel types have extensions that are specific to that particular channel type. An example is requresting a pty (pseudo terminal) for an interactive session. This method enables the sending of channel requests but does not support receiving responses. This should not present a problem as server implementations tend to send messages as one way information, for example the exit-status request of an interactive session.
To handle requests from a client implement
onChannelRequest(String,boolean,byte[]).
type - wantreply - requestdata - protected void onChannelOpenFailure()
protected void onRemoteClose()
public boolean isClosing()
public void close()
protected abstract void onChannelFree()
protected abstract byte[] createChannel()
throws IOException,
com.maverick.ssh.common.ChannelOpenException
IOException
com.maverick.ssh.common.ChannelOpenException
protected abstract byte[] openChannel(byte[] requestdata)
throws WriteOperationRequest,
com.maverick.ssh.common.ChannelOpenException
requestdata -
WriteOperationRequest
com.maverick.ssh.common.ChannelOpenExceptionprotected abstract void onChannelOpenConfirmation()
protected abstract void onChannelClosed()
protected abstract void onChannelOpen()
protected abstract void onChannelClosing()
protected abstract void onChannelRequest(String type,
boolean wantreply,
byte[] requestdata)
type - wantreply - requestdata - protected abstract void evaluateWindowSpace(long remaining)
remaining - protected abstract void onRemoteEOF()
protected void sendEOF()
protected boolean canClose()
protected abstract void onLocalEOF()
public boolean isOpen()
protected void sendRequestResponse(boolean succeeded)
succeeded - protected void sendWindowAdjust(long count)
count - protected void idle(org.apache.mina.core.session.IdleStatus status)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||