Package i5.las2peer.communication
Class Message
java.lang.Object
i5.las2peer.communication.Message
Base class for sending messages between
AgentImpl
s.
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
-
Constructor Summary
ConstructorDescriptionMessage()
constructor for theXmlAble
facilitiesGenerate a new message in response to the given one.Generate a new message in response to the given one.Message
(Message responseTo, Serializable data) Generate a new message in response to the given one.Message
(Message responseTo, Serializable data, long timeoutMs) Generate a new message in response to the given one.Message
(AgentImpl from, long topic, Serializable data) create a new message to a topic with default timeoutMessage
(AgentImpl from, long topic, Serializable data, long timeoutMs) create a new message to all agents listening on the given topiccreate a new message with default timeoutcreate a new messageMessage
(AgentImpl from, AgentImpl to, Serializable data) create a new message with default timeoutMessage
(AgentImpl from, AgentImpl to, Serializable data, long timeOutMs) create a new message -
Method Summary
Modifier and TypeMethodDescriptionclone()
void
close()
close this message (envelope)static Message
createFromXml
(String xml) factory: create a message from an XML documentget the content of this message may be Serializable or XmlAblelong
getId()
Gets the id of this messageget the designated recipient of this message only works after opening or creating of the messageGets the id of the recipient agentget the sending agent of this message only works after opening or creation the messageget the id of the sending agentget the id of the sending node The type depends on on the Node implementation (Long forLocalNode
and NodeHandle forPastryNodeImpl
long
long
Gets the id of the receiving topiclong
boolean
boolean
isOpen()
boolean
boolean
isTopic()
Check if this message is sent to a topicvoid
open
(AgentImpl unlockedRecipient, AgentStorage storage) open the message, i.e.void
open
(AgentImpl unlockedRecipient, AgentStorage storage, ClassLoader contentClsLoader) open the message, i.e.void
open
(AgentStorage storage) open the message, i.e.void
setRecipientId
(String id) set the id of the recipient (used by the node when receiving messages from topics)void
setSendingNodeId
(Long id) set the id of the node sending this message The long-variant is to use in case of a LocalNode network.void
set the id of the node sending this messagevoid
setSendingNodeId
(rice.p2p.commonapi.NodeHandle handle) set the if of the node sending this message The NodeHandle-variant is for Pastry based networks.void
setStateFromXml
(String xml) for XmlAble: set the state of this object from the given xml documentfrom XmlAble return a XML representation of this instancevoid
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:
-
-
Constructor Details
-
Message
public Message()constructor for theXmlAble
facilities -
Message
public Message(AgentImpl from, AgentImpl to, Serializable data) throws EncodingFailedException, InternalSecurityException, SerializationException create 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, Serializable data, long timeOutMs) throws EncodingFailedException, InternalSecurityException, SerializationException create 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, SerializationException create 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, SerializationException create 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, Serializable data) throws EncodingFailedException, InternalSecurityException, SerializationException create 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, Serializable data, long timeoutMs) throws EncodingFailedException, InternalSecurityException, SerializationException create 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, SerializationException Generate 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, SerializationException Generate 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, Serializable data, long timeoutMs) throws EncodingFailedException, InternalSecurityException, SerializationException Generate 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, Serializable data) throws EncodingFailedException, InternalSecurityException, SerializationException Generate 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
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
Gets the id of the recipient agent- Returns:
- id of the receiving agent
-
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
true
if this message is sent to a topic
-
getId
public long getId()Gets the id of this message- Returns:
- id
-
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. aAgentContext
bound 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, AgentException open 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, ClassLoader contentClsLoader) throws InternalSecurityException, AgentException open 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
- Returns:
- timestamp of message creation as Date object
-
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
from XmlAble return a XML representation of this instance- Specified by:
toXmlString
in 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
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
set the id of the recipient (used by the node when receiving messages from topics)- Parameters:
id
- A receiver id
-
setSendingNodeId
set the id of the node sending this message- Parameters:
id
- A sending node id object
-
getSendingNodeId
get the id of the sending node The type depends on on the Node implementation (Long forLocalNode
and 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:
clone
in classObject
- Throws:
CloneNotSupportedException
-