Class SshMessageStore
This class implements a message store that can be used to provide a blocking mechanism for transport protocol messages.
- Since:
- 0.2.0
- Version:
- $Revision: 1.42 $
- Author:
- Lee David Painter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
void
close()
Closes the store.createMessage
(byte[] msgdata) Create a formed message from raw message data.getMessage
(int messageId) Get a message from the store.getMessage
(int[] messageIdFilter) Get a message from the store.getMessage
(int[] messageIdFilter, int timeout) Get a message from the store.getMessage
(int messageId, int timeout) Get a message from the store.Object[]
Returns an Object array (Integers) of the registered message ids.boolean
Evaluate whether the store has any messages.boolean
isClosed()
Evaluate whether the message store is closed.boolean
isRegisteredMessage
(Integer messageId) Determines if the message id is a registered message of this store.Get the next message in the store or wait until a new message arrives.peekMessage
(int messageId) Get a message from the store without removing it.peekMessage
(int[] messageIdFilter) Get a message from the store without removing or blocking if the message does not exist.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.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, 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.
-
Constructor Details
-
SshMessageStore
public SshMessageStore()Contructs the message store.
- Since:
- 0.2.0
-
-
Method Details
-
isClosed
public boolean isClosed()Evaluate whether the message store is closed.
- Returns:
- Since:
- 0.2.0
-
addMessageListener
-
getMessage
public SshMessage getMessage(int[] messageIdFilter) throws MessageStoreEOFException, 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.
- Parameters:
messageIdFilter
- an array of message ids that are acceptable- Returns:
- the next available message
- Throws:
MessageStoreEOFException
- if the message store is closedInterruptedException
- if the thread was interrupted- Since:
- 0.2.0
-
getMessage
public SshMessage getMessage(int[] messageIdFilter, int timeout) throws MessageStoreEOFException, MessageNotAvailableException, 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.
- Parameters:
messageIdFilter
- an array of message ids that are acceptable.timeout
- the maximum number of milliseconds to block before returning.- Returns:
- the next available message
- Throws:
MessageStoreEOFException
- if the message store is closedMessageNotAvailableException
- if the message is not available after a timeoutInterruptedException
- if the thread is interrupted- Since:
- 0.2.0
-
getMessage
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.
- Parameters:
messageId
- the id of the message requried- Returns:
- the next available message with the id supplied
- Throws:
MessageStoreEOFException
- if the message store closedInterruptedException
- if the thread is interrupted- Since:
- 0.2.0
-
getMessage
public SshMessage getMessage(int messageId, int timeout) throws MessageStoreEOFException, MessageNotAvailableException, 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.
- Parameters:
messageId
- the id of the message requriedtimeout
- the maximum number of milliseconds to block before returning.- Returns:
- the next available message with the id supplied
- Throws:
MessageStoreEOFException
- if the message store closedInterruptedException
- if the thread is interruptedInterruptedException
MessageNotAvailableException
- Since:
- 0.2.0
-
hasMessages
public boolean hasMessages()Evaluate whether the store has any messages.
- Returns:
- true if messages exist, otherwise false
- Since:
- 0.2.0
-
size
public int size()Returns the number of messages contained within this message store.
- Returns:
- the number of messages
- Since:
- 0.2.0
-
isRegisteredMessage
Determines if the message id is a registered message of this store.
- Parameters:
messageId
- the message id- Returns:
- true if the message id is registered, otherwise false
- Since:
- 0.2.0
-
addMessage
public void addMessage(byte[] msgdata) throws MessageNotRegisteredException, InvalidMessageException Adds a raw message to the store and processes the data into a registered message.
- Parameters:
msgdata
- the raw message data to process- Throws:
MessageNotRegisteredException
- if the message id of the raw data is not a registered messageInvalidMessageException
- if the message is invalid- Since:
- 0.2.0
-
addMessage
Add a formed message to the store.
- Parameters:
msg
- the message to add to the store- Throws:
MessageNotRegisteredException
- if the message type is not registered with the store- Since:
- 0.2.0
-
close
public void close()Closes the store. This will cause any blocking operations on the message store to return.
- Since:
- 0.2.0
-
nextMessage
Get the next message in the store or wait until a new message arrives. The message is removed from the store.
- Returns:
- the next available message.
- Throws:
MessageStoreEOFException
- if the message store is closedInterruptedException
- if the thread is interrupted- Since:
- 0.2.0
-
breakWaiting
public void breakWaiting() -
peekMessage
public SshMessage peekMessage(int[] messageIdFilter) throws MessageStoreEOFException, MessageNotAvailableException, InterruptedException Get a message from the store without removing or blocking if the message does not exist.
- Parameters:
messageIdFilter
- the id of the message requried- Returns:
- the next available message with the id supplied
- Throws:
MessageStoreEOFException
- if the message store closedMessageNotAvailableException
- if the message is not availableInterruptedException
- if the thread is interrupted- Since:
- 0.2.0
-
peekMessage
public SshMessage peekMessage(int[] messageIdFilter, int timeout) throws MessageStoreEOFException, MessageNotAvailableException, 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.
- Parameters:
messageIdFilter
- an array of acceptable message idstimeout
- the number of milliseconds to wait- Returns:
- the next available message of the acceptable message ids
- Throws:
MessageStoreEOFException
- if the message store is closedMessageNotAvailableException
- if the message is not availableInterruptedException
- if the thread is interrupted- Since:
- 0.2.0
-
peekMessage
public SshMessage peekMessage(int messageId) throws MessageStoreEOFException, MessageNotAvailableException, InterruptedException Get a message from the store without removing it.
- Parameters:
messageId
- the acceptable message id- Returns:
- the next available message.
- Throws:
MessageStoreEOFException
- if the message store is closed.MessageNotAvailableException
- if the message is not available.InterruptedException
- if the thread is interrupted- Since:
- 0.2.0
-
removeMessage
Removes a message from the message store.
- Parameters:
msg
- the message to remove- Since:
- 0.2.0
-
peekMessage
public SshMessage peekMessage(int messageId, int timeout) throws MessageStoreEOFException, MessageNotAvailableException, InterruptedException Get a message from the store without removing it, only blocking for the number of milliseconds specified in the timeout field.
- Parameters:
messageId
- the acceptable message idtimeout
- the timeout setting in milliseconds- Returns:
- the next available message
- Throws:
MessageStoreEOFException
- if the message store is closedMessageNotAvailableException
- if the message is not availableInterruptedException
- if the thread is interrupted- Since:
- 0.2.0
-
registerMessage
Register a message implementation with the store.
- Parameters:
messageId
- the id of the messageimplementor
- the class of the implementation- Since:
- 0.2.0
-
getRegisteredMessageIds
Returns an Object array (Integers) of the registered message ids.
- Returns:
- the registered message id array
- Since:
- 0.2.0
-
createMessage
public SshMessage createMessage(byte[] msgdata) throws MessageNotRegisteredException, InvalidMessageException Create a formed message from raw message data.
- Parameters:
msgdata
- the raw message data- Returns:
- the formed message
- Throws:
MessageNotRegisteredException
- if the message is not a registered messageInvalidMessageException
- if the message is invalid- Since:
- 0.2.0
-