com.sshtools.j2ssh.transport
Class SshMessageStore

java.lang.Object
  extended by com.sshtools.j2ssh.transport.SshMessageStore

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.

Since:
0.2.0
Version:
$Revision: 1.42 $
Author:
Lee David Painter

Constructor Summary
SshMessageStore()
           Contructs the message store.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SshMessageStore

public SshMessageStore()

Contructs the message store.

Since:
0.2.0
Method Detail

isClosed

public boolean isClosed()

Evaluate whether the message store is closed.

Returns:
Since:
0.2.0

addMessageListener

public void addMessageListener(SshMessageListener listener)

getMessage

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.

Parameters:
messageIdFilter - an array of message ids that are acceptable
Returns:
the next available message
Throws:
MessageStoreEOFException - if the message store is closed
java.lang.InterruptedException - if the thread was interrupted
Since:
0.2.0

getMessage

public 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.

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 closed
MessageNotAvailableException - if the message is not available after a timeout
java.lang.InterruptedException - if the thread is interrupted
Since:
0.2.0

getMessage

public 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.

Parameters:
messageId - the id of the message requried
Returns:
the next available message with the id supplied
Throws:
MessageStoreEOFException - if the message store closed
java.lang.InterruptedException - if the thread is interrupted
Since:
0.2.0

getMessage

public 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.

Parameters:
messageId - the id of the message requried
timeout - the maximum number of milliseconds to block before returning.
Returns:
the next available message with the id supplied
Throws:
MessageStoreEOFException - if the message store closed
java.lang.InterruptedException - if the thread is interrupted
java.lang.InterruptedException
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

public boolean isRegisteredMessage(java.lang.Integer messageId)

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 message
InvalidMessageException - if the message is invalid
Since:
0.2.0

addMessage

public void addMessage(SshMessage msg)
                throws MessageNotRegisteredException

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

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.

Returns:
the next available message.
Throws:
MessageStoreEOFException - if the message store is closed
java.lang.InterruptedException - if the thread is interrupted
Since:
0.2.0

breakWaiting

public void breakWaiting()

peekMessage

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.

Parameters:
messageIdFilter - the id of the message requried
Returns:
the next available message with the id supplied
Throws:
MessageStoreEOFException - if the message store closed
MessageNotAvailableException - if the message is not available
java.lang.InterruptedException - if the thread is interrupted
Since:
0.2.0

peekMessage

public 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.

Parameters:
messageIdFilter - an array of acceptable message ids
timeout - the number of milliseconds to wait
Returns:
the next available message of the acceptable message ids
Throws:
MessageStoreEOFException - if the message store is closed
MessageNotAvailableException - if the message is not available
java.lang.InterruptedException - if the thread is interrupted
Since:
0.2.0

peekMessage

public SshMessage peekMessage(int messageId)
                       throws MessageStoreEOFException,
                              MessageNotAvailableException,
                              java.lang.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.
java.lang.InterruptedException - if the thread is interrupted
Since:
0.2.0

removeMessage

public void removeMessage(SshMessage msg)

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,
                              java.lang.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 id
timeout - the timeout setting in milliseconds
Returns:
the next available message
Throws:
MessageStoreEOFException - if the message store is closed
MessageNotAvailableException - if the message is not available
java.lang.InterruptedException - if the thread is interrupted
Since:
0.2.0

registerMessage

public void registerMessage(int messageId,
                            java.lang.Class implementor)

Register a message implementation with the store.

Parameters:
messageId - the id of the message
implementor - the class of the implementation
Since:
0.2.0

getRegisteredMessageIds

public java.lang.Object[] 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 message
InvalidMessageException - if the message is invalid
Since:
0.2.0


Copyright © 2002-2003 Lee David Painter & Contributors. All Rights Reserved.