Class SshMessageStore

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

public final class SshMessageStore extends 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 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

      public void addMessageListener(SshMessageListener listener)
    • 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 closed
      InterruptedException - 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 closed
      MessageNotAvailableException - if the message is not available after a timeout
      InterruptedException - if the thread is interrupted
      Since:
      0.2.0
    • getMessage

      public SshMessage getMessage(int messageId) throws MessageStoreEOFException, 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
      InterruptedException - 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 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
      InterruptedException - if the thread is interrupted
      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(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

      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
      InterruptedException - 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 closed
      MessageNotAvailableException - if the message is not available
      InterruptedException - 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 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
      InterruptedException - if the thread is interrupted
      Since:
      0.2.0
    • peekMessage

      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

      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, 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
      InterruptedException - if the thread is interrupted
      Since:
      0.2.0
    • registerMessage

      public void registerMessage(int messageId, 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 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