org.exolab.jms.persistence
Class Messages

java.lang.Object
  |
  +--org.exolab.jms.persistence.Messages

public class Messages
extends java.lang.Object

This class manages the persistence of message objects.

Version:
$Revision: 1.3 $ $Date: 2005/06/09 14:39:52 $
Author:
Tim Anderson

Constructor Summary
protected Messages()
          Default constructor does nothing at the moment.
 
Method Summary
 void add(java.sql.Connection connection, MessageImpl message)
          Add a message to the database, in the context of the specified transaction and connection.
 void close()
          Reset the instance.
 MessageImpl deserialize(byte[] blob)
          Set the message from a serialized blob
 MessageImpl get(java.sql.Connection connection, java.lang.String messageId)
          Return the message identified by the message Id
 java.util.HashMap getMessageIds(java.sql.Connection connection, long time, int hint)
          Retrieve the specified number of message ids from the database with a time greater than that specified.
 java.util.Vector getMessages(java.sql.Connection connection, java.lang.String destination, int priority, long time)
          Retrieve the next set of messages for the specified destination with an acceptance time greater or equal to that specified.
 java.util.Vector getNonExpiredMessages(java.sql.Connection connection, JmsDestination destination)
          Retrieve the message handle for all unexpired messages
 java.util.Vector getUnprocessedMessages(java.sql.Connection connection)
          Retrieve a list of unprocessed messages and return them to the client.
static Messages initialise()
          Create an initialise the singleton istance of this class.
static Messages instance()
          Returns a reference to the singleton instance.
 void remove(java.sql.Connection connection, java.lang.String messageId)
          Remove a message with the specified identity from the database
 void removeExpiredMessages(java.sql.Connection connection)
          Delete all expired messages and associated message handles.
 int removeMessages(java.sql.Connection connection, java.lang.String destination)
          Delete all messages for the given destination
 byte[] serialize(MessageImpl message)
          Get the message as a serialized blob
 void update(java.sql.Connection connection, MessageImpl message)
          Update the message state in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Messages

protected Messages()
Default constructor does nothing at the moment.
Method Detail

instance

public static Messages instance()
Returns a reference to the singleton instance.

Note that initialise() must have been invoked first for this to return a valid instance.

Returns:
Messages the singleton instance

initialise

public static Messages initialise()
Create an initialise the singleton istance of this class.
Returns:
Messages the singleton instance

add

public void add(java.sql.Connection connection,
                MessageImpl message)
         throws PersistenceException
Add a message to the database, in the context of the specified transaction and connection.
Parameters:
connection - - execute on this connection
message - - the message to add
Throws:
PersistenceException - - an sql related error

update

public void update(java.sql.Connection connection,
                   MessageImpl message)
            throws PersistenceException
Update the message state in the database. This will be called to set the message state to processed by the provider
Parameters:
connection - - execute on this connection
message - - the message to update
Throws:
PersistenceException - - an sql related error

remove

public void remove(java.sql.Connection connection,
                   java.lang.String messageId)
            throws PersistenceException
Remove a message with the specified identity from the database
Parameters:
connection - - execute on this connection
messageId - - the message id of the message to remove
Throws:
PersistenceException - - an sql related error

get

public MessageImpl get(java.sql.Connection connection,
                       java.lang.String messageId)
                throws PersistenceException
Return the message identified by the message Id
Parameters:
connection - - execute on this connection
messageId - - id of message to retrieve
Returns:
MessageImpl - the associated message
Throws:
PersistenceException - - an sql related error

removeMessages

public int removeMessages(java.sql.Connection connection,
                          java.lang.String destination)
                   throws PersistenceException
Delete all messages for the given destination
Parameters:
connection - - execute on this connection
destination - the destination to remove messages for
Returns:
int - the number of messages purged
Throws:
PersistenceException - - an sql related error

getMessages

public java.util.Vector getMessages(java.sql.Connection connection,
                                    java.lang.String destination,
                                    int priority,
                                    long time)
                             throws PersistenceException
Retrieve the next set of messages for the specified destination with an acceptance time greater or equal to that specified. It will retrieve around 200 or so messages depending on what is available.
Parameters:
connection - - execute on this connection
destination - - the destination
priority - - the priority of the messages
time - - with timestamp greater or equal to this
Returns:
Vector - one or more MessageImpl objects
Throws:
PersistenceException - - if an SQL error occurs

getMessageIds

public java.util.HashMap getMessageIds(java.sql.Connection connection,
                                       long time,
                                       int hint)
                                throws PersistenceException
Retrieve the specified number of message ids from the database with a time greater than that specified. The number of items to retrieve is only a hint and does not reflect the number of messages actually returned.
Parameters:
connection - - execute on this connection
time - - with timestamp greater than
hint - - an indication of the number of messages to return.
Returns:
a map of messageId Strings to their creation time
Throws:
PersistenceException - - if an SQL error occurs

getUnprocessedMessages

public java.util.Vector getUnprocessedMessages(java.sql.Connection connection)
                                        throws PersistenceException
Retrieve a list of unprocessed messages and return them to the client. An unprocessed message has been accepted by the system but not processed.
Parameters:
connection - - execute on this connection
Returns:
Vector - one or more MessageImpl objects
Throws:
PersistenceException - - if an SQL error occurs

getNonExpiredMessages

public java.util.Vector getNonExpiredMessages(java.sql.Connection connection,
                                              JmsDestination destination)
                                       throws PersistenceException
Retrieve the message handle for all unexpired messages
Parameters:
connection - - execute on this connection
destination - - the destination in question
Returns:
Vector - collection of PersistentMessageHandle objects
Throws:
PersistenceException - - sql releated exception

removeExpiredMessages

public void removeExpiredMessages(java.sql.Connection connection)
                           throws PersistenceException
Delete all expired messages and associated message handles.
Parameters:
connection - - execute on this connection
Throws:
PersistenceException - - if an SQL error occurs

close

public void close()
Reset the instance. We need to deprecate this method since this class does not contain state information

serialize

public byte[] serialize(MessageImpl message)
                 throws PersistenceException
Get the message as a serialized blob
Parameters:
message - the message to serialize
Returns:
byte[] the serialized message

deserialize

public MessageImpl deserialize(byte[] blob)
                        throws PersistenceException
Set the message from a serialized blob
Parameters:
blob - the serialized message
Returns:
the re-constructed message


Copyright © 1999-2005 The OpenJMS Group. All Rights Reserved.