public abstract class ChannelNG<T extends SshContext> extends java.lang.Object implements Channel
| Modifier and Type | Class and Description |
|---|---|
protected class |
ChannelNG.ChannelInputStream |
| Modifier and Type | Field and Description |
|---|---|
protected CachingDataWindow |
cache |
protected SshConnection |
con |
protected ConnectionProtocol<T> |
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 ChannelDataWindow |
localWindow |
protected ChannelDataWindow |
remoteWindow |
| Constructor and Description |
|---|
ChannelNG(java.lang.String channelType,
int maximumPacketSize,
int initialWindowSize,
int maximumWindowSpace,
int minimumWindowSpace) |
ChannelNG(java.lang.String channelType,
int maximumPacketSize,
int initialWindowSize,
int maximumWindowSpace,
int minimumWindowSpace,
ChannelRequestFuture closeFuture,
boolean autoConsume)
Construct a channel with the specified settings.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(ChannelEventListener listener)
Enable other objects to receive channel events
|
protected boolean |
canClose()
Can this channel close?
|
protected boolean |
checkWindowSpace() |
void |
clearIdleState(IdleStateListener listener)
Clear an idle state listener.
|
void |
close() |
protected void |
close(boolean forceClose)
This method closes the channel and free's its resources.
|
protected CachingDataWindow |
createCache(int maximumWindowSpace) |
protected abstract byte[] |
createChannel()
Called when the channel is being created.
|
protected void |
evaluateWindowSpace()
Called to evaluate the window space available.
|
java.lang.String |
getChannelType()
The name of this channel.
|
ChannelRequestFuture |
getCloseFuture()
Get this channels close future.
|
Connection<T> |
getConnection() |
ConnectionProtocol<T> |
getConnectionProtocol()
Returns the
ConnectionProtocol associated with this channel. |
T |
getContext()
Get the current configuration from the underlying connection.
|
java.io.InputStream |
getInputStream() |
long |
getLastActivity() |
int |
getLocalId()
The local channel id
|
int |
getLocalPacket()
The maximum size of a single packet that the local side will accept.
|
int |
getLocalWindow()
The current size of the local data window.
|
int |
getMaxiumRemotePacketSize() |
int |
getMaxiumRemoteWindowSize() |
ChannelRequestFuture |
getOpenFuture()
Get this channels close future.
|
java.io.OutputStream |
getOutputStream() |
int |
getRemoteId()
The remote sides channel id
|
int |
getRemotePacket()
The maximum size of a single packet that the remote side will accept.
|
int |
getRemoteWindow()
The current size of the remote data window.
|
java.lang.String |
getSessionIdentifier()
Get the session id for the current connection.
|
int |
getTimeout() |
void |
haltIncomingData() |
boolean |
isClosed()
Indicates the channel has been closed
|
boolean |
isClosing()
Indicates whether the channel is currently performing a close operation
|
boolean |
isConnected() |
boolean |
isIncomingDataHalted() |
boolean |
isLocalEOF() |
protected boolean |
isOpen()
Get the open state of the channel.
|
boolean |
isRemoteEOF() |
protected void |
log(java.lang.String message) |
protected void |
log(java.lang.String action,
java.lang.String message) |
protected void |
log(java.lang.String message,
java.lang.Throwable t) |
protected void |
logMessage(java.lang.String message) |
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 void |
onChannelData(java.nio.ByteBuffer data) |
protected void |
onChannelError(java.lang.Throwable e) |
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(java.lang.String type,
boolean wantreply,
byte[] requestdata)
Called when a channel request is received.
|
protected void |
onExtendedData(java.nio.ByteBuffer 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 void |
processChannelRequestResponse(boolean success) |
protected void |
registerExtendedDataType(java.lang.Integer type) |
void |
resetIdleState(IdleStateListener listener)
Allows a channel to register and receive idle state events.
|
void |
resumeIncomingData() |
void |
sendChannelDataAndBlock(byte[] data)
Send channel data to the remote side of the channel.
|
void |
sendChannelDataAndBlock(byte[] data,
int off,
int len,
java.lang.Runnable r) |
void |
sendChannelDataAndBlock(byte[] data,
java.lang.Runnable r) |
void |
sendChannelDataAndBlock(java.nio.ByteBuffer buf)
Send channel data from a ByteBuffer
|
void |
sendChannelDataAndBlock(java.nio.ByteBuffer buf,
int type,
java.lang.Runnable r)
Send channel data from a ByteBuffer
|
void |
sendChannelDataAndBlock(java.nio.ByteBuffer buf,
java.lang.Runnable r) |
void |
sendChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata) |
void |
sendChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata,
ChannelRequestFuture future)
Send a channel request.
|
void |
sendData(byte[] data,
int off,
int len) |
void |
sendEOF()
You can send EOF when you have no more data to send.
|
protected void |
sendExtendedData(byte[] data,
int type)
Send extended channel data.
|
protected void |
sendExtendedData(byte[] data,
int off,
int len,
int type)
Send extended channel data.
|
protected void |
sendRequestResponse(boolean succeeded)
Send a channel request.
|
protected void |
sendWindowAdjust()
Adjust the local window by adding more bytes.
|
void |
sendWindowAdjust(int count) |
void |
setTimeout(int timeout) |
protected ConnectionProtocol<T extends SshContext> connection
protected ChannelDataWindow localWindow
protected ChannelDataWindow remoteWindow
protected CachingDataWindow cache
protected SshConnection con
public ChannelNG(java.lang.String channelType,
int maximumPacketSize,
int initialWindowSize,
int maximumWindowSpace,
int minimumWindowSpace,
ChannelRequestFuture closeFuture,
boolean autoConsume)
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.public ChannelNG(java.lang.String channelType,
int maximumPacketSize,
int initialWindowSize,
int maximumWindowSpace,
int minimumWindowSpace)
protected CachingDataWindow createCache(int maximumWindowSpace)
public java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public boolean isClosed()
public boolean isConnected()
public int getMaxiumRemoteWindowSize()
public int getMaxiumRemotePacketSize()
public void resetIdleState(IdleStateListener listener)
IdleStateListener instance passed as a parameter
will receive notification once the channel reaches an idle state.
NOTE: It is the callers responsibility to call clearIdleState method to
ensure references are released.listener - IdleStateListenerpublic void clearIdleState(IdleStateListener listener)
listener - public void addEventListener(ChannelEventListener listener)
addEventListener in interface Channellistener - public java.lang.String getChannelType()
public ChannelRequestFuture getOpenFuture()
public ChannelRequestFuture getCloseFuture()
public int getRemoteWindow()
getRemoteWindow in interface Channelpublic int getLocalWindow()
getLocalWindow in interface Channelpublic int getLocalPacket()
getLocalPacket in interface Channelpublic int getRemotePacket()
public int getLocalId()
public int getRemoteId()
public java.lang.String getSessionIdentifier()
protected void registerExtendedDataType(java.lang.Integer type)
protected void onWindowAdjust(int count)
public long getLastActivity()
public void setTimeout(int timeout)
public int getTimeout()
public Connection<T> getConnection()
getConnection in interface Channelpublic ConnectionProtocol<T> getConnectionProtocol()
ConnectionProtocol associated with this channel.protected void onChannelData(java.nio.ByteBuffer data)
public void sendChannelDataAndBlock(byte[] data)
throws java.io.IOException
data - java.io.IOExceptionpublic void sendChannelDataAndBlock(byte[] data,
java.lang.Runnable r)
throws java.io.IOException
java.io.IOExceptionpublic void sendData(byte[] data,
int off,
int len)
throws java.io.IOException
public void sendChannelDataAndBlock(byte[] data,
int off,
int len,
java.lang.Runnable r)
throws java.io.IOException
java.io.IOExceptionpublic void sendChannelDataAndBlock(java.nio.ByteBuffer buf)
throws java.io.IOException
buf - java.io.IOExceptionpublic void sendChannelDataAndBlock(java.nio.ByteBuffer buf,
java.lang.Runnable r)
throws java.io.IOException
java.io.IOExceptionpublic void sendChannelDataAndBlock(java.nio.ByteBuffer buf,
int type,
java.lang.Runnable r)
throws java.io.IOException
buf - r - java.io.IOExceptionpublic T getContext()
getContext in interface Channelprotected void sendExtendedData(byte[] data,
int type)
throws java.io.IOException
data - type - java.io.IOExceptionprotected void sendExtendedData(byte[] data,
int off,
int len,
int type)
throws java.io.IOException
data - off - len - type - java.io.IOExceptionprotected void onExtendedData(java.nio.ByteBuffer data,
int type)
data - public void sendChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata,
ChannelRequestFuture future)
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[]).
sendChannelRequest in interface Channeltype - wantreply - requestdata - public void sendChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata)
sendChannelRequest in interface Channelprotected void processChannelRequestResponse(boolean success)
protected void onChannelOpenFailure()
protected void onRemoteClose()
public boolean isClosing()
protected void close(boolean forceClose)
protected abstract void onChannelFree()
protected abstract byte[] createChannel()
throws java.io.IOException
java.io.IOExceptionprotected abstract byte[] openChannel(byte[] requestdata)
throws WriteOperationRequest,
ChannelOpenException
requestdata - WriteOperationRequestChannelOpenExceptionprotected abstract void onChannelOpenConfirmation()
protected abstract void onChannelClosed()
protected abstract void onChannelOpen()
protected abstract void onChannelClosing()
protected abstract void onChannelRequest(java.lang.String type,
boolean wantreply,
byte[] requestdata)
type - wantreply - requestdata - protected void evaluateWindowSpace()
remaining - protected abstract void onRemoteEOF()
public void sendEOF()
protected boolean canClose()
protected abstract void onLocalEOF()
protected boolean isOpen()
protected void sendRequestResponse(boolean succeeded)
succeeded - protected void sendWindowAdjust()
count - public void sendWindowAdjust(int count)
sendWindowAdjust in interface Channelprotected void logMessage(java.lang.String message)
protected void log(java.lang.String action,
java.lang.String message)
protected void log(java.lang.String message)
protected void log(java.lang.String message,
java.lang.Throwable t)
public boolean isLocalEOF()
isLocalEOF in interface Channelpublic boolean isRemoteEOF()
isRemoteEOF in interface Channelpublic boolean isIncomingDataHalted()
public void haltIncomingData()
public void resumeIncomingData()
protected boolean checkWindowSpace()
protected void onChannelError(java.lang.Throwable e)
Copyright © 2021. All rights reserved.