Package i5.las2peer.communication
Class Message
java.lang.Object
i5.las2peer.communication.Message
- All Implemented Interfaces:
XmlAble,java.lang.Cloneable
public class Message extends java.lang.Object implements XmlAble, java.lang.Cloneable
Base class for sending messages between
AgentImpls.
The content of the message will be encrypted symmetrically with a randomly generated key, this key will be encrypted
asymmetrically for the recipient of the message.
Additionally, the contents will be signed with the private key of the sender.
Therefore, it is necessary, that the generating Thread has access to the private key of the sending agent.
When specifying a topic, the message will be sent to all agents listening to the topic. Since these agents are not
known, the message will not be encrypted.-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_TIMEOUT -
Constructor Summary
Constructors Constructor Description Message()constructor for theXmlAblefacilitiesMessage(Message responseTo, XmlAble data)Generate a new message in response to the given one.Message(Message responseTo, XmlAble data, long timeoutMs)Generate a new message in response to the given one.Message(Message responseTo, java.io.Serializable data)Generate a new message in response to the given one.Message(Message responseTo, java.io.Serializable data, long timeoutMs)Generate a new message in response to the given one.Message(AgentImpl from, long topic, java.io.Serializable data)create a new message to a topic with default timeoutMessage(AgentImpl from, long topic, java.io.Serializable data, long timeoutMs)create a new message to all agents listening on the given topicMessage(AgentImpl from, AgentImpl to, XmlAble data)create a new message with default timeoutMessage(AgentImpl from, AgentImpl to, XmlAble data, long timeoutMs)create a new messageMessage(AgentImpl from, AgentImpl to, java.io.Serializable data)create a new message with default timeoutMessage(AgentImpl from, AgentImpl to, java.io.Serializable data, long timeOutMs)create a new message -
Method Summary
Modifier and Type Method Description Messageclone()voidclose()close this message (envelope)static MessagecreateFromXml(java.lang.String xml)factory: create a message from an XML documentjava.lang.ObjectgetContent()get the content of this message may be Serializable or XmlAblelonggetId()Gets the id of this messageAgentImplgetRecipient()get the designated recipient of this message only works after opening or creating of the messagejava.lang.StringgetRecipientId()Gets the id of the recipient agentjava.lang.LonggetResponseToId()AgentImplgetSender()get the sending agent of this message only works after opening or creation the messagejava.lang.StringgetSenderId()get the id of the sending agentjava.io.SerializablegetSendingNodeId()get the id of the sending node The type depends on on the Node implementation (Long forLocalNodeand NodeHandle forPastryNodeImpljava.util.DategetTimeoutDate()longgetTimeoutTs()longgetTimestamp()java.util.DategetTimestampDate()java.lang.LonggetTopicId()Gets the id of the receiving topiclonggetValidMs()booleanisExpired()booleanisOpen()booleanisResponse()booleanisTopic()Check if this message is sent to a topicvoidopen(AgentImpl unlockedRecipient, AgentStorage storage)open the message, i.e. decrypt the content with the private key of the receiving agent the private key has to be unlocked first!voidopen(AgentImpl unlockedRecipient, AgentStorage storage, java.lang.ClassLoader contentClsLoader)open the message, i.e. decrypt the content with the private key of the receiving agent the private key has to be unlocked first!voidopen(AgentStorage storage)open the message, i.e. decrypt the content with the private key of the receiving agent The storage has to know an unlocked version of the recipient agent!voidsetRecipientId(java.lang.String id)set the id of the recipient (used by the node when receiving messages from topics)voidsetSendingNodeId(java.lang.Long id)set the id of the node sending this message The long-variant is to use in case of a LocalNode network.voidsetSendingNodeId(java.lang.Object id)set the id of the node sending this messagevoidsetSendingNodeId(rice.p2p.commonapi.NodeHandle handle)set the if of the node sending this message The NodeHandle-variant is for Pastry based networks.voidsetStateFromXml(java.lang.String xml)for XmlAble: set the state of this object from the given xml documentjava.lang.StringtoXmlString()from XmlAble return a XML representation of this instancevoidverifySignature()verify the signature of this message the content has to be available for this
-
Field Details
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUT- See Also:
- Constant Field Values
-
-
Constructor Details
-
Message
public Message()constructor for theXmlAblefacilities -
Message
public Message(AgentImpl from, AgentImpl to, java.io.Serializable data) throws EncodingFailedException, InternalSecurityException, SerializationExceptioncreate a new message with default timeout- Parameters:
from- A sending agentto- A receiving agentdata- Arbitrary data to wrap in the message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
Message
public Message(AgentImpl from, AgentImpl to, java.io.Serializable data, long timeOutMs) throws EncodingFailedException, InternalSecurityException, SerializationExceptioncreate a new message- Parameters:
from- A sending agentto- A receiving agentdata- Arbitrary data to wrap in the messagetimeOutMs- timeout for the validity of the new message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
Message
public Message(AgentImpl from, AgentImpl to, XmlAble data) throws EncodingFailedException, InternalSecurityException, SerializationExceptioncreate a new message with default timeout- Parameters:
from- A sending agentto- A receiving agentdata- Arbitrary data to wrap in the message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
Message
public Message(AgentImpl from, AgentImpl to, XmlAble data, long timeoutMs) throws EncodingFailedException, InternalSecurityException, SerializationExceptioncreate a new message- Parameters:
from- A sending agentto- A receiving agentdata- Arbitrary data to wrap in the messagetimeoutMs- timeout for the validity of the new message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
Message
public Message(AgentImpl from, long topic, java.io.Serializable data) throws EncodingFailedException, InternalSecurityException, SerializationExceptioncreate a new message to a topic with default timeout- Parameters:
from- A sending agenttopic- A target topicdata- Arbitrary data to wrap in the message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
Message
public Message(AgentImpl from, long topic, java.io.Serializable data, long timeoutMs) throws EncodingFailedException, InternalSecurityException, SerializationExceptioncreate a new message to all agents listening on the given topic- Parameters:
from- A sending agenttopic- A target topicdata- Arbitrary data to wrap in the messagetimeoutMs- A timeout to send message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
Message
public Message(Message responseTo, XmlAble data, long timeoutMs) throws EncodingFailedException, InternalSecurityException, SerializationExceptionGenerate a new message in response to the given one. Sender and recipient will be derived from the given message.- Parameters:
responseTo- A message referencedata- Arbitrary data to wrap in the messagetimeoutMs- timeout for the validity of the new message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
Message
public Message(Message responseTo, XmlAble data) throws EncodingFailedException, InternalSecurityException, SerializationExceptionGenerate a new message in response to the given one. Sender and recipient will be derived from the given message.- Parameters:
responseTo- A message referencedata- Arbitrary data to wrap in the message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
Message
public Message(Message responseTo, java.io.Serializable data, long timeoutMs) throws EncodingFailedException, InternalSecurityException, SerializationExceptionGenerate a new message in response to the given one. Sender and recipient will be derived from the given message.- Parameters:
responseTo- A message referencedata- Arbitrary data to wrap in the messagetimeoutMs- A timeout to send message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
Message
public Message(Message responseTo, java.io.Serializable data) throws EncodingFailedException, InternalSecurityException, SerializationExceptionGenerate a new message in response to the given one. Sender and recipient will be derived from the given message.- Parameters:
responseTo- A message referencedata- Arbitrary data to wrap in the message- Throws:
EncodingFailedException- If the content serialization failsInternalSecurityException- the private key of the sender is not accessible for signingSerializationException- If the content serialization fails
-
-
Method Details
-
getSender
get the sending agent of this message only works after opening or creation the message- Returns:
- sending agent
-
getSenderId
public java.lang.String getSenderId()get the id of the sending agent- Returns:
- id of the sending agent
-
getRecipient
get the designated recipient of this message only works after opening or creating of the message- Returns:
- (designated) receiver
-
getRecipientId
public java.lang.String getRecipientId()Gets the id of the recipient agent- Returns:
- id of the receiving agent
-
getTopicId
public java.lang.Long getTopicId()Gets the id of the receiving topic- Returns:
- Returns the topic id
-
isTopic
public boolean isTopic()Check if this message is sent to a topic- Returns:
- Returns
trueif this message is sent to a topic
-
getId
public long getId()Gets the id of this message- Returns:
- id
-
getResponseToId
public java.lang.Long getResponseToId()- Returns:
- id of the message, this one is a response to
-
isResponse
public boolean isResponse()- Returns:
- true, if this message is a response to another one
-
getContent
get the content of this message may be Serializable or XmlAble- Returns:
- actual content of the message
- Throws:
InternalSecurityException- the message (envelope) has to be opened (decrypted) first
-
open
open the message, i.e. decrypt the content with the private key of the receiving agent The storage has to know an unlocked version of the recipient agent! (i.e. aAgentContextbound to him.- Parameters:
storage- An agent storage to use- Throws:
InternalSecurityException- If the private key of the receiver has to be unlocked for decryptionAgentException- If an issue with the sender agent occurs
-
open
public void open(AgentImpl unlockedRecipient, AgentStorage storage) throws InternalSecurityException, AgentExceptionopen the message, i.e. decrypt the content with the private key of the receiving agent the private key has to be unlocked first!- Parameters:
unlockedRecipient- An unlocked recipientstorage- An agent storage to use- Throws:
InternalSecurityException- If the private key of the receiver has to be unlocked for decryptionAgentException- If an issue with the sender agent occursAgentNotFoundException- If an issue with the sender agent occurs
-
open
public void open(AgentImpl unlockedRecipient, AgentStorage storage, java.lang.ClassLoader contentClsLoader) throws InternalSecurityException, AgentExceptionopen the message, i.e. decrypt the content with the private key of the receiving agent the private key has to be unlocked first!- Parameters:
unlockedRecipient- An unlocked recipientstorage- An agent storage to usecontentClsLoader- A class loader to deserialize the content- Throws:
InternalSecurityException- If the private key of the receiver has to be unlocked for decryptionAgentException- If an issue with the sender agent occursAgentNotFoundException- If an issue with the sender agent occurs
-
verifySignature
verify the signature of this message the content has to be available for this- Throws:
InternalSecurityException- If signature verification fails
-
close
public void close()close this message (envelope) -
isOpen
public boolean isOpen()- Returns:
- true, if the content of this message is accessible
-
getValidMs
public long getValidMs()- Returns:
- the time in ms the message is valid
-
getTimestamp
public long getTimestamp()- Returns:
- unix timestamp of message creation
-
getTimestampDate
public java.util.Date getTimestampDate()- Returns:
- timestamp of message creation as Date object
-
getTimeoutDate
public java.util.Date getTimeoutDate()- Returns:
- the date of timeout for this message
-
getTimeoutTs
public long getTimeoutTs()- Returns:
- timestamp of the timeout for this message
-
isExpired
public boolean isExpired()- Returns:
- true, if this message is expired
-
toXmlString
public java.lang.String toXmlString()from XmlAble return a XML representation of this instance- Specified by:
toXmlStringin interfaceXmlAble- Returns:
- a XML String representation
-
setStateFromXml
for XmlAble: set the state of this object from the given xml document- Parameters:
xml- An XML data string- Throws:
MalformedXMLException- If the XML data string is malformed
-
setSendingNodeId
public void setSendingNodeId(rice.p2p.commonapi.NodeHandle handle)set the if of the node sending this message The NodeHandle-variant is for Pastry based networks.- Parameters:
handle- A sending node handle
-
setSendingNodeId
public void setSendingNodeId(java.lang.Long id)set the id of the node sending this message The long-variant is to use in case of a LocalNode network.- Parameters:
id- A sending node id
-
setRecipientId
public void setRecipientId(java.lang.String id)set the id of the recipient (used by the node when receiving messages from topics)- Parameters:
id- A receiver id
-
setSendingNodeId
public void setSendingNodeId(java.lang.Object id)set the id of the node sending this message- Parameters:
id- A sending node id object
-
getSendingNodeId
public java.io.Serializable getSendingNodeId()get the id of the sending node The type depends on on the Node implementation (Long forLocalNodeand NodeHandle forPastryNodeImpl- Returns:
- id of the sending las2peer node
-
createFromXml
factory: create a message from an XML document- Parameters:
xml- An XML data string- Returns:
- a message generated from the given XML document
- Throws:
MalformedXMLException- If the XML data string is malformed
-
clone
- Overrides:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException
-