org.universAAL.middleware.bus.msg
Class BusMessage

Package class diagram package BusMessage
java.lang.Object
  extended by org.universAAL.middleware.bus.msg.BusMessage
All Implemented Interfaces:
BrokerMessage

public class BusMessage
extends Object
implements BrokerMessage

Author:
mtazari - Saied Tazari

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.universAAL.middleware.brokers.message.BrokerMessage
BrokerMessage.BrokerMessageTypes
 
Field Summary
 String brokerName
           
 
Constructor Summary
BusMessage(MessageType type, Object content, AbstractBus creator)
          Constructor - a message of particular type with particular content
BusMessage(String message)
          Constructor - parses the string passed as a parameter and creates a Message object.
 
Method Summary
 void addReceiver(PeerCard pc)
           
 void addReceivers(PeerCard[] receivers)
           
static BusMessage createP2PReply(String messageIDInReplyTo, PeerCard receiver, Object content, AbstractBus creator)
          Create a reply message to the message with the given ID, with the content and receiver passed as a parameter.
 BusMessage createReply(Object content)
          Create reply message to this message, with the content passed as a parameter.
static String createUniqueID()
          generates a globally unique ID, based on a counter and some string that represents this JVM
static Object deserializeAsContent(String s)
           
 Object getContent()
           
 String getContentAsString()
           
 String getID()
           
 long getIDAsLong()
           
 String getInReplyTo()
          Returns the ID of the message this message replies to.
 BrokerMessage.BrokerMessageTypes getMType()
           
 PeerCard[] getReceivers()
           
 PeerCard getSender()
           
 MessageType getType()
           
 boolean hasReceiver(PeerCard receiver)
           
 String marshall(BrokerMessage message)
           
 boolean receiverResidesOnDifferentPeer()
           
 boolean senderResidesOnDifferentPeer()
           
 boolean sentBySamePeerAs(PeerCard peer)
           
static void setMessageContentSerializer(MessageContentSerializer mcs)
           
 void setReceiver(PeerCard receiver)
          If the given peer is not null, removes any existing receiver and adds the given peer as the only receiver.
 void setReceivers(List<PeerCard> receivers)
           
 void setSender(PeerCard sender)
           
static void setThisPeer(PeerCard peer)
           
 String toString()
          Serialize the message as string.
static String trySerializationAsContent(Object o)
          A safe wrapping for calling contentSerializer.serialize(o).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

brokerName

public String brokerName
Constructor Detail

BusMessage

public BusMessage(MessageType type,
                  Object content,
                  AbstractBus creator)
Constructor - a message of particular type with particular content

Parameters:
type -
content - Content of the message, typically a Resource.

BusMessage

public BusMessage(String message)
Constructor - parses the string passed as a parameter and creates a Message object.

Parameters:
message - the string to parse (the serialization of a message object).
Method Detail

createUniqueID

public static String createUniqueID()
generates a globally unique ID, based on a counter and some string that represents this JVM

Returns:
String - the created unique ID

setMessageContentSerializer

public static void setMessageContentSerializer(MessageContentSerializer mcs)

setThisPeer

public static void setThisPeer(PeerCard peer)

setReceivers

public void setReceivers(List<PeerCard> receivers)

trySerializationAsContent

public static String trySerializationAsContent(Object o)
A safe wrapping for calling contentSerializer.serialize(o).

Parameters:
o - - Object to serialize
Returns:
String 1. the result of o.toString() if the serializer is null; 2. otherwise the result of calling the serialize() method of the serializer, which might be null if the serializer fails to serialize the given object

deserializeAsContent

public static Object deserializeAsContent(String s)

addReceiver

public void addReceiver(PeerCard pc)

addReceivers

public void addReceivers(PeerCard[] receivers)

createReply

public BusMessage createReply(Object content)
Create reply message to this message, with the content passed as a parameter.

Parameters:
content - the content of the created reply, typically a Resource .
Returns:
Message the reply message.

createP2PReply

public static BusMessage createP2PReply(String messageIDInReplyTo,
                                        PeerCard receiver,
                                        Object content,
                                        AbstractBus creator)
Create a reply message to the message with the given ID, with the content and receiver passed as a parameter.

Parameters:
messageIDInReplyTo - ID of the message to which the returned message is a reply to.
receiver - the receiving peer.
content - Content of the message, typically a Resource.
Returns:
a new BusMessage, or null if the parameters are invalid.

getContent

public Object getContent()
Returns:
Object the content of the message.

getContentAsString

public String getContentAsString()
Returns:
String the string serialization of the content.

getID

public String getID()
Returns:
the unique ID of the message.

getIDAsLong

public long getIDAsLong()

getInReplyTo

public String getInReplyTo()
Returns the ID of the message this message replies to.

Returns:
String the ID of the message this message replies to.

getType

public MessageType getType()
Returns:
MessageType

receiverResidesOnDifferentPeer

public boolean receiverResidesOnDifferentPeer()

senderResidesOnDifferentPeer

public boolean senderResidesOnDifferentPeer()

sentBySamePeerAs

public boolean sentBySamePeerAs(PeerCard peer)

setReceiver

public void setReceiver(PeerCard receiver)
If the given peer is not null, removes any existing receiver and adds the given peer as the only receiver.

Parameters:
receiver -

toString

public String toString()
Serialize the message as string.

Specified by:
toString in interface BrokerMessage
Overrides:
toString in class Object
Returns:
String the serialized message.

marshall

public String marshall(BrokerMessage message)

getMType

public BrokerMessage.BrokerMessageTypes getMType()
Specified by:
getMType in interface BrokerMessage

getReceivers

public PeerCard[] getReceivers()
Specified by:
getReceivers in interface BrokerMessage

hasReceiver

public boolean hasReceiver(PeerCard receiver)

getSender

public PeerCard getSender()

setSender

public void setSender(PeerCard sender)


Copyright © 2014 universAAL Consortium. All Rights Reserved.