public abstract class SshMessageRouter extends Object
This abstract class provides a synchronized message routing framework that can be used for both the SSH1 and SSH2 protocols. The protocol implementation supplies a message reader interface, to which only one thread is allowed access at any one time, threads requiring a message whilst another thread is blocking are queued to await notification of when the reader is available. Since a message read by one thread may be destined for another the router takes charge of this before notifying other queued threads that the block is available. When they receive this notification they first check their own message stores before requesting the block again.
Constructor and Description |
---|
SshMessageRouter(SshMessageReader reader,
int maxChannels,
boolean buffered) |
Modifier and Type | Method and Description |
---|---|
void |
addShutdownHook(Runnable r) |
protected int |
allocateChannel(SshAbstractChannel channel) |
void |
blockForMessage(long timeout) |
protected abstract SshMessage |
createMessage(byte[] msg)
Called by the message routing framework to request the creation of an
SshMessage . |
protected void |
freeChannel(SshAbstractChannel channel) |
protected SshAbstractChannel[] |
getActiveChannels() |
Thread |
getBackgroundThread() |
int |
getChannelCount() |
protected SshMessageStore |
getGlobalMessages() |
int |
getMaxChannels() |
SshMessageReader |
getReader() |
boolean |
hasBackgroundThread() |
boolean |
isBlockingThread(Thread thread) |
boolean |
isBuffered() |
protected int |
maximumChannels() |
protected SshMessage |
nextMessage(SshAbstractChannel channel,
MessageObserver observer,
long timeout) |
protected abstract void |
onThreadExit()
Called when the threaded router closes.
|
protected abstract boolean |
processGlobalMessage(SshMessage msg)
Called by the message routing framework so that the routing implementation may process
a global message.
|
void |
signalClosingState() |
void |
start() |
void |
stop() |
public SshMessageRouter(SshMessageReader reader, int maxChannels, boolean buffered)
public SshMessageReader getReader()
public Thread getBackgroundThread()
public boolean hasBackgroundThread()
public void start()
public void addShutdownHook(Runnable r)
public boolean isBuffered()
public void stop()
public void signalClosingState()
protected SshMessageStore getGlobalMessages()
public int getMaxChannels()
protected int allocateChannel(SshAbstractChannel channel)
protected void freeChannel(SshAbstractChannel channel)
protected SshAbstractChannel[] getActiveChannels()
protected int maximumChannels()
public int getChannelCount()
protected SshMessage nextMessage(SshAbstractChannel channel, MessageObserver observer, long timeout) throws SshException, InterruptedException
SshException
InterruptedException
public boolean isBlockingThread(Thread thread)
public void blockForMessage(long timeout) throws SshException
SshException
protected abstract void onThreadExit()
protected abstract SshMessage createMessage(byte[] msg) throws SshException
Called by the message routing framework to request the creation of an
SshMessage
.
messageid
- SshException
protected abstract boolean processGlobalMessage(SshMessage msg) throws SshException
Called by the message routing framework so that the routing implementation may process
a global message. If the message is processed and no further action is required this method
should return true
, if the method returns false
then the message
will be added to the global message store.
msg
- true
if the message was processed, otherwise false
IOException
SshException
Copyright © 2024. All rights reserved.