public final class SshMessageStore
extends java.lang.Object
This class implements a message store that can be used to provide a blocking mechanism for transport protocol messages.
Constructor and Description |
---|
SshMessageStore()
Contructs the message store.
|
Modifier and Type | Method and Description |
---|---|
void |
addMessage(byte[] msgdata)
Adds a raw message to the store and processes the data into a registered
message.
|
void |
addMessage(SshMessage msg)
Add a formed message to the store.
|
void |
addMessageListener(SshMessageListener listener) |
void |
breakWaiting() |
void |
close()
Closes the store.
|
SshMessage |
createMessage(byte[] msgdata)
Create a formed message from raw message data.
|
SshMessage |
getMessage(int messageId)
Get a message from the store.
|
SshMessage |
getMessage(int[] messageIdFilter)
Get a message from the store.
|
SshMessage |
getMessage(int[] messageIdFilter,
int timeout)
Get a message from the store.
|
SshMessage |
getMessage(int messageId,
int timeout)
Get a message from the store.
|
java.lang.Object[] |
getRegisteredMessageIds()
Returns an Object array (Integers) of the registered message ids.
|
boolean |
hasMessages()
Evaluate whether the store has any messages.
|
boolean |
isClosed()
Evaluate whether the message store is closed.
|
boolean |
isRegisteredMessage(java.lang.Integer messageId)
Determines if the message id is a registered message of this store.
|
SshMessage |
nextMessage()
Get the next message in the store or wait until a new message arrives.
|
SshMessage |
peekMessage(int messageId)
Get a message from the store without removing it.
|
SshMessage |
peekMessage(int[] messageIdFilter)
Get a message from the store without removing or blocking if the message
does not exist.
|
SshMessage |
peekMessage(int[] messageIdFilter,
int timeout)
Get a message from the store without removing it; only blocking for the
number of milliseconds specified in the timeout field.
|
SshMessage |
peekMessage(int messageId,
int timeout)
Get a message from the store without removing it, only blocking for the
number of milliseconds specified in the timeout field.
|
void |
registerMessage(int messageId,
java.lang.Class implementor)
Register a message implementation with the store.
|
void |
removeMessage(SshMessage msg)
Removes a message from the message store.
|
int |
size()
Returns the number of messages contained within this message store.
|
public SshMessageStore()
Contructs the message store.
public boolean isClosed()
Evaluate whether the message store is closed.
public void addMessageListener(SshMessageListener listener)
public SshMessage getMessage(int[] messageIdFilter) throws MessageStoreEOFException, java.lang.InterruptedException
Get a message from the store. This method will block until a message with an id matching the supplied filter arrives, or the message store closes. The message is removed from the store.
messageIdFilter
- an array of message ids that are acceptableMessageStoreEOFException
- if the message store is closedjava.lang.InterruptedException
- if the thread was interruptedpublic SshMessage getMessage(int[] messageIdFilter, int timeout) throws MessageStoreEOFException, MessageNotAvailableException, java.lang.InterruptedException
Get a message from the store. This method will block until a message with an id matching the supplied filter arrives, the specified timeout is reached or the message store closes. The message is removed from the store.
messageIdFilter
- an array of message ids that are acceptable.timeout
- the maximum number of milliseconds to block before
returning.MessageStoreEOFException
- if the message store is closedMessageNotAvailableException
- if the message is not available
after a timeoutjava.lang.InterruptedException
- if the thread is interruptedpublic SshMessage getMessage(int messageId) throws MessageStoreEOFException, java.lang.InterruptedException
Get a message from the store. This method will block until a message with an id matching the supplied id arrives, or the message store closes. The message is removed from the store.
messageId
- the id of the message requriedMessageStoreEOFException
- if the message store closedjava.lang.InterruptedException
- if the thread is interruptedpublic SshMessage getMessage(int messageId, int timeout) throws MessageStoreEOFException, MessageNotAvailableException, java.lang.InterruptedException
Get a message from the store. This method will block until a message with an id matching the supplied id arrives,the specified timeout is reached or the message store closes. The message will be removed from the store.
messageId
- the id of the message requriedtimeout
- the maximum number of milliseconds to block before
returning.MessageStoreEOFException
- if the message store closedjava.lang.InterruptedException
- if the thread is interruptedjava.lang.InterruptedException
MessageNotAvailableException
public boolean hasMessages()
Evaluate whether the store has any messages.
public int size()
Returns the number of messages contained within this message store.
public boolean isRegisteredMessage(java.lang.Integer messageId)
Determines if the message id is a registered message of this store.
messageId
- the message idpublic void addMessage(byte[] msgdata) throws MessageNotRegisteredException, InvalidMessageException
Adds a raw message to the store and processes the data into a registered message.
msgdata
- the raw message data to processMessageNotRegisteredException
- if the message id of the raw data
is not a registered messageInvalidMessageException
- if the message is invalidpublic void addMessage(SshMessage msg) throws MessageNotRegisteredException
Add a formed message to the store.
msg
- the message to add to the storeMessageNotRegisteredException
- if the message type is not
registered with the storepublic void close()
Closes the store. This will cause any blocking operations on the message store to return.
public SshMessage nextMessage() throws MessageStoreEOFException, java.lang.InterruptedException
Get the next message in the store or wait until a new message arrives. The message is removed from the store.
MessageStoreEOFException
- if the message store is closedjava.lang.InterruptedException
- if the thread is interruptedpublic void breakWaiting()
public SshMessage peekMessage(int[] messageIdFilter) throws MessageStoreEOFException, MessageNotAvailableException, java.lang.InterruptedException
Get a message from the store without removing or blocking if the message does not exist.
messageIdFilter
- the id of the message requriedMessageStoreEOFException
- if the message store closedMessageNotAvailableException
- if the message is not availablejava.lang.InterruptedException
- if the thread is interruptedpublic SshMessage peekMessage(int[] messageIdFilter, int timeout) throws MessageStoreEOFException, MessageNotAvailableException, java.lang.InterruptedException
Get a message from the store without removing it; only blocking for the number of milliseconds specified in the timeout field. If timeout is zero, the method will not block.
messageIdFilter
- an array of acceptable message idstimeout
- the number of milliseconds to waitMessageStoreEOFException
- if the message store is closedMessageNotAvailableException
- if the message is not availablejava.lang.InterruptedException
- if the thread is interruptedpublic SshMessage peekMessage(int messageId) throws MessageStoreEOFException, MessageNotAvailableException, java.lang.InterruptedException
Get a message from the store without removing it.
messageId
- the acceptable message idMessageStoreEOFException
- if the message store is closed.MessageNotAvailableException
- if the message is not available.java.lang.InterruptedException
- if the thread is interruptedpublic void removeMessage(SshMessage msg)
Removes a message from the message store.
msg
- the message to removepublic SshMessage peekMessage(int messageId, int timeout) throws MessageStoreEOFException, MessageNotAvailableException, java.lang.InterruptedException
Get a message from the store without removing it, only blocking for the number of milliseconds specified in the timeout field.
messageId
- the acceptable message idtimeout
- the timeout setting in millisecondsMessageStoreEOFException
- if the message store is closedMessageNotAvailableException
- if the message is not availablejava.lang.InterruptedException
- if the thread is interruptedpublic void registerMessage(int messageId, java.lang.Class implementor)
Register a message implementation with the store.
messageId
- the id of the messageimplementor
- the class of the implementationpublic java.lang.Object[] getRegisteredMessageIds()
Returns an Object array (Integers) of the registered message ids.
public SshMessage createMessage(byte[] msgdata) throws MessageNotRegisteredException, InvalidMessageException
Create a formed message from raw message data.
msgdata
- the raw message dataMessageNotRegisteredException
- if the message is not a registered
messageInvalidMessageException
- if the message is invalidCopyright © 2002-2003 Lee David Painter & Contributors. All Rights Reserved.