guarana.framework.message
Class Message<T>

java.lang.Object
  extended by guarana.framework.message.Message<T>
All Implemented Interfaces:
Serializable, Comparable<Message<T>>

public class Message<T>
extends Object
implements Serializable, Comparable<Message<T>>

An abstraction of a piece of information that is exchanged and transformed across an EAI solution. The structure of messages depends completely on the solutions in which they are involved.

Since:
Guaranį SDK 1.0.0
Author:
Rafael Z. Frantz
See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Constructor Summary
Message()
          Constructs a new message.
Message(Message<?> parent)
          Constructs a new message that has a given message as parent.
 
Method Summary
 Object addAttachment(String name, Object attachment)
          Adds an attachment to this message.
 void addParent(Message<?> parent)
          Adds a parent to the message.
 int compareTo(Message<T> msg)
          
 Message<T> copy()
          Creates a copy of this message.
 Object getAttachment(String name)
          Returns the attachment associated with the given name.
 Set<String> getAttachmentNames()
          Returns all attachment names.
 Map<String,Object> getAttachments()
          Returns all attachments from this message.
 T getBody()
          Return the body of this message.
 Header getHeader()
          Returns the header of this message.
 boolean hasAttachements()
          Checks if this message has attachments.
 Object removeAttachment(String name)
          Removes an attachment from this message.
 void setAttachments(Map<String,Object> attachments)
          Sets several attachments at once for a message.
 void setBody(T body)
          Sets the body of the message.
 void setHeader(Header header)
          Sets the header of this message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

Message

public Message()
Constructs a new message.


Message

public Message(Message<?> parent)
Constructs a new message that has a given message as parent. Attachments and header from the original message remain the same; however, a new ID is given to the child message. The parent message ID is added to the child's header ancestors list.

Parameters:
parent - The parent message of this current message.
Method Detail

copy

public Message<T> copy()
Creates a copy of this message. Attachments, header, body and message ID from the original message remain the same.

Returns:
a new object containing the copy of the current message; otherwise, null if the message could not be copied.

addParent

public void addParent(Message<?> parent)
Adds a parent to the message. Messages keep a list of their ancestors ID, so they can be used to trace the path of a message. A message can have more than one parent, for example, if it is the result of an aggregation or an enricher task. Use this method to add more parents to the message.

Parameters:
parent - The parent message of this current message.

addAttachment

public Object addAttachment(String name,
                            Object attachment)
Adds an attachment to this message.

Parameters:
name - The name of the attachment.
attachment - The attachment.
Returns:
the previous attachment already in the message if the new one has the same name or null if there is no previous attachment with this name.

removeAttachment

public Object removeAttachment(String name)
Removes an attachment from this message.

Parameters:
name - The name of the attachment.
Returns:
the attachment to which this name is associated, or null if there is no attachment mapped with this name.

getAttachment

public Object getAttachment(String name)
Returns the attachment associated with the given name.

Parameters:
name - The name of the attachment.
Returns:
the attachment, or null if there is no value associated with the given name.

getAttachmentNames

public Set<String> getAttachmentNames()
Returns all attachment names.

Returns:
a collection with all attachment names.

hasAttachements

public boolean hasAttachements()
Checks if this message has attachments.

Returns:
True if there is at least one attachment in the message.

getHeader

public Header getHeader()
Returns the header of this message.

Returns:
the header.

setHeader

public void setHeader(Header header)
Sets the header of this message.

Parameters:
header - a header for this message.

getBody

public T getBody()
Return the body of this message.

Returns:
the body.

setBody

public void setBody(T body)
Sets the body of the message.

Parameters:
body - The body of this message

getAttachments

public Map<String,Object> getAttachments()
Returns all attachments from this message.

Returns:
all attachments.

setAttachments

public void setAttachments(Map<String,Object> attachments)
Sets several attachments at once for a message.

Parameters:
attachments - A map structure with several attachments.

compareTo

public int compareTo(Message<T> msg)

Specified by:
compareTo in interface Comparable<Message<T>>


Guaranį DSL Home