net.sf.dropboxmq.messagetranscoders
Interface MessageTranscoder

All Known Implementing Classes:
DefaultMessageTranscoder

public interface MessageTranscoder

A MessageTranscoder is used to encode or decode message metadata. Custom transcoders can be used to read and write metadata for messages that were produced by or will be consumed by clients that do not use DropboxMQ. One common use of MessageTranscoder is to override the default message filename when sending messages to non-DropboxMQ client. Such a client may expect message filenames to have a very specific format.

Created: 17 Dec 2005

Version:
$Revision: 231 $, $Date: 2011-08-12 21:50:47 -0600 (Fri, 12 Aug 2011) $
Author:
Dwayne Schultz

Method Summary
 Message decodeMetadata(SessionImpl session, File messageFile, String originalFilename, boolean priorityAndSelectorOnly, String messageSelector)
          Decodes the provided metadata and creates a new emtpy message.
 String encodeMetadata(Message message)
          Encodes the metadata of a given message.
 

Method Detail

encodeMetadata

String encodeMetadata(Message message)
                      throws JMSException
Encodes the metadata of a given message. The metadata is used to name the message file.

Parameters:
message - the message that is being sent
Returns:
a string representation of the messages metadata
Throws:
JMSException - if the transcoder fails to encode the metadata contained in the message. Such an exception or any RuntimeException will cause the message to not be sent.

decodeMetadata

Message decodeMetadata(SessionImpl session,
                       File messageFile,
                       String originalFilename,
                       boolean priorityAndSelectorOnly,
                       String messageSelector)
                       throws IOException
Decodes the provided metadata and creates a new emtpy message.

Parameters:
session - a session that should be used to create a new message that will contain the metadata after it has been decoded
messageFile - the message file containing metadata to be decoded
originalFilename - the original name of the file as it was produced. The name returned by messageFile.getName() has been modified from the original. If a transcoder needs to decode metadata from the message filename, this parameter should be used.
priorityAndSelectorOnly - decodeMetadata() is called twice, first for determining priority and applying any message selectors, and second as a message is consumed; careful transcoders can apply some optimizations to the first call when this value will be set to true
messageSelector - the message selector to be applied to the message. May be used to further optimize the decoding process. If priorityAndSelectorOnly is true and messageSelector is null, transcoders can safely decode the JMS priority and JMS timestamp only. If priorityAndSelectorOnly is true, messageSelector does not contain a specific selection and the decoding of metadata to support the specific selection is costly, transcoders can safely skip the decoding of the specific selection. For instance perhaps decoding the JMS type (@see javax.jms.Message#getJMSType()) requires parsing the message body. A transcoder may scan the message for JMSType and if priorityAndSelectorOnly is true and messageSelector does not contain JMSType, the transcoder can safely choose to not parse the message body.
Returns:
the newly created message
Throws:
IOException - if the transcoder encounters any problems reading the message file, the exception should be passed up to the caller