|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpeer2me.message.Message
public class Message
This class is used by the framework to exchange messages between nodes in the network. A message
can contain many messageparts, which can be serialized objects, primitive datatypes and files.
When adding serialized objects to a message, the object must implement the interface peer2me.util.Serializable.
If a message only contains one serialized object or only primitive datatypes, it can be sent as one
bytestream over the network. However, if the message contains several serialized objects and/or large files,
the message must be sent in several "chunks" over the network. In order for the receiving node to
put all these parts together, all chuncks that belongs to the same message must have the same ID, which
in this class is the String messageID
. Different messages however, must have different unique
IDs.
All constants in this class must be in the range 300-399
Serializable
Field Summary | |
---|---|
static int |
MESSAGE_DISCONNECT
|
static int |
MESSAGE_FILE
Identifies a message that contains a file or a part of a file |
static int |
MESSAGE_NODE_JOIN
When an application performs a search for new devices, it will automatically after the search has finished, send a message that contains information about all nodes to all the nodes the application has found. |
static int |
MESSAGE_NODE_LEFT
Identifies a message that contains information about a node that is leaving the network |
static int |
MESSAGE_NODE_MOVE
Identifies a message that contains information that a node has been moved from one group to another |
static int |
MESSAGE_PRIMITIVES_OR_SERIALIZED_OBJECT
Identifies a message that contains primitive types or serialized object |
Constructor Summary | |
---|---|
Message()
Constructor that should be used by the application that creates a new message that is to be sent over the network. |
|
Message(java.lang.String messageID)
When a node receives a message, the framework needs to create a new message object since the message is really sent as pure bytes over the network. |
Method Summary | |
---|---|
void |
addElement(java.lang.String key,
boolean value)
Adds a boolean this message |
void |
addElement(java.lang.String key,
char value)
Adds a char this message |
void |
addElement(java.lang.String key,
double value)
Adds a double this message |
void |
addElement(java.lang.String key,
float value)
Adds a float this message |
void |
addElement(java.lang.String key,
int value)
Adds an int to this message |
void |
addElement(java.lang.String key,
long value)
Adds a long this message |
void |
addElement(java.lang.String key,
short value)
Adds a short this message |
void |
addElement(java.lang.String key,
java.lang.String value)
Adds a String this message |
void |
addFile(java.lang.String key,
java.lang.String fullPath)
Adds a file to this message. |
void |
addFileInfo(java.lang.String key,
FileInfo fileInfo)
Adds information about a received file. |
void |
addObjectBytes(java.lang.String key,
byte[] bytes)
Adds an array of bytes to this message as a messagePart. |
void |
addReceivedFile(java.lang.String key,
FileObject fileObject)
When a message containing a file or a part of a file is received, a messapart containing the file must be created. |
boolean |
addRecipient(Node node)
Adds a node to the collection of nodes that are to receive the message. |
void |
addRecipients(Group group)
Sets an entire group of nodes as recipients of the message |
void |
addRecipients(Node[] nodes)
Sets an array of nodes as recipients of this message |
void |
addSerializedObject(java.lang.String key,
java.lang.Object o)
Adds a serialized object to this message. |
void |
extractPrimitivesToSeparateParts()
Extracts all the primitive variables from one MessagePart to several MessageParts. |
MessagePart[] |
getAllMessageParts()
Returns all the MessageParts that are attached to this message Should only be used by the framework itself |
boolean |
getBoolean(java.lang.String key)
Returns the boolean value that is assosiated with the key |
char |
getChar(java.lang.String key)
Returns the char value that is assosiated with the key |
double |
getDouble(java.lang.String key)
Returns the double value that is assosiated with the key |
FileInfo |
getFile(java.lang.String key)
Returns a FileInfo object that contains information about the received file. |
float |
getFloat(java.lang.String key)
Returns the float value that is assosiated with the key |
int |
getInt(java.lang.String key)
Returns the int value that is assosiated with the key |
long |
getLong(java.lang.String key)
Returns the long value that is assosiated with the key |
java.lang.String |
getMessageID()
Gets the ID of this message. |
MessagePart |
getMessagePart(java.lang.String key)
Should only be used by the framework itself |
int |
getMessageType()
Returns what kind of message this is |
Node[] |
getRecipients()
Returns all the recipients of this message |
Node |
getSender()
Returns a Node representation of the sender of this message |
java.lang.Object |
getSerializedObject(java.lang.String key)
Gets the serialized object that is assosiated with the given key |
short |
getShort(java.lang.String key)
Returns the short value that is assosiated with the key |
java.lang.String |
getString(java.lang.String key)
Returns the String value that is assosiated with the key |
int |
numberOfChunksNeeded()
Calculates the number of chunks that this message must be split into in order to send it over the network |
void |
setMessageID(java.lang.String messageID)
Sets the ID of this message. |
void |
setMessageType(int messageType)
Sets the type of this message |
void |
setSender(Node sender)
Sets the sender of this message. |
void |
storeAllPrimitivesInOnePart()
When adding primitive variables to this message, all the variables are stored as separate MessageParts. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MESSAGE_DISCONNECT
public static final int MESSAGE_FILE
public static final int MESSAGE_NODE_JOIN
public static final int MESSAGE_NODE_LEFT
public static final int MESSAGE_NODE_MOVE
public static final int MESSAGE_PRIMITIVES_OR_SERIALIZED_OBJECT
Constructor Detail |
---|
public Message()
new Date().getTime()
function combined with the method getHexString
in class peer2me.util.HexBuilder
.
public Message(java.lang.String messageID)
messageID
- The unique identificator of this messageMethod Detail |
---|
public int numberOfChunksNeeded()
public boolean addRecipient(Node node)
node
- The node that should receive the message
public void addRecipients(Group group)
group
- The group of recipients that will receive the messagepublic void addRecipients(Node[] nodes)
nodes
- An array of nodes that should receive this messagepublic void addElement(java.lang.String key, int value)
int
to this message
key
- The unique key that the int
will be assosiated withvalue
- The int
value that will be attached to this messagepublic void addElement(java.lang.String key, double value)
double
this message
key
- The unique key that the double
will be assosiated withvalue
- The double
value that will be attached to this messagepublic void addElement(java.lang.String key, char value)
char
this message
key
- The unique key that the char
will be assosiated withvalue
- The char
value that will be attached to this messagepublic void addElement(java.lang.String key, boolean value)
boolean
this message
key
- The unique key that the boolean
will be assosiated withvalue
- The boolean
value that will be attached to this messagepublic void addElement(java.lang.String key, java.lang.String value)
String
this message
key
- The unique key that the String
will be assosiated withvalue
- The String
value that will be attached to this messagepublic void addElement(java.lang.String key, long value)
long
this message
key
- The unique key that the long
will be assosiated withvalue
- The long
value that will be attached to this messagepublic void addElement(java.lang.String key, float value)
float
this message
key
- The unique key that the float
will be assosiated withvalue
- The float
value that will be attached to this messagepublic void addElement(java.lang.String key, short value)
short
this message
key
- The unique key that the short
will be assosiated withvalue
- The short
value that will be attached to this messagepublic void extractPrimitivesToSeparateParts()
BluetoothListener
class when a message is received.
public void storeAllPrimitivesInOnePart()
primitives
.
This enables the framework to send all the primitive variables in one chunk. When the message is
received on the receiving node, the parts are extracted back to the original structure by invoking the
method extractPrimitvesToSeparateParts
This method should only be used by classes inside the peer2me package.
public void addFile(java.lang.String key, java.lang.String fullPath)
SendFileObject
class.
key
- The unique key that the file will be assosiated withfullPath
- The full path to the directory of which the file is located. An example of such a path
is: file:///SDCard/images/animal.jpg
public void addReceivedFile(java.lang.String key, FileObject fileObject)
key
- The unique key that the file will be assosiated withfileObject
- The fileObject that will be attached to this messagepublic MessagePart getMessagePart(java.lang.String key)
key
- A unique key that is assosiated with a messagePart
public int getInt(java.lang.String key)
int
value that is assosiated with the key
key
- A unique key that is assosiated with an int
value
int
that is assosiated with the key
public double getDouble(java.lang.String key)
double
value that is assosiated with the key
key
- A unique key that is assosiated with an double
value
double
that is assosiated with the key
public java.lang.String getString(java.lang.String key)
String
value that is assosiated with the key
key
- A unique key that is assosiated with an String
value
String
that is assosiated with the key
public boolean getBoolean(java.lang.String key)
boolean
value that is assosiated with the key
key
- A unique key that is assosiated with an boolean
value
boolean
that is assosiated with the key
public long getLong(java.lang.String key)
long
value that is assosiated with the key
key
- A unique key that is assosiated with an long
value
long
that is assosiated with the key
public float getFloat(java.lang.String key)
float
value that is assosiated with the key
key
- A unique key that is assosiated with an float
value
float
that is assosiated with the key
public short getShort(java.lang.String key)
short
value that is assosiated with the key
key
- A unique key that is assosiated with an short
value
short
that is assosiated with the key
public char getChar(java.lang.String key)
char
value that is assosiated with the key
key
- A unique key that is assosiated with an char
value
char
that is assosiated with the key
public void addFileInfo(java.lang.String key, FileInfo fileInfo)
addFile(String, String)
This method should only be used by the framework itself
key
- A unique key that is assosiated with the filefileInfo
- The FileInfo objectpublic FileInfo getFile(java.lang.String key)
key
- A unique key that is assosiated with the file
public MessagePart[] getAllMessageParts()
public Node[] getRecipients()
public int getMessageType()
MESSAGE_DISCONNECT
, MESSAGE_FILE
,
MESSAGE_NODE_JOIN
, MESSAGE_NODE_LEFT
or MESSAGE_PRIMITIVES_OR_SERIALIZED_OBJECT
public Node getSender()
Node
public void setSender(Node sender)
sender
- The sender of this messagepublic java.lang.String getMessageID()
public void setMessageID(java.lang.String messageID)
messageID
- The ID that this message will be assosiated withpublic void addSerializedObject(java.lang.String key, java.lang.Object o) throws InvalidKeyException
key
- The unique key that will be assosiated with the serialized objecto
- A serialized object. The object MUST implement the interface Serializable
.
InvalidKeyException
- Will be thrown if the key given is of lenght = 0 or null.public java.lang.Object getSerializedObject(java.lang.String key) throws UnknownKeyException
key
- The unique key that is assosiated with the object
UnknownKeyException
- If the serialized object is not foundpublic void addObjectBytes(java.lang.String key, byte[] bytes)
storeAllPrimitivesInOnePart
key
- The key can only be assosiated to a serialized object or primitive variables stored in an
array of bytes. The latter will always be assosiated with the key primitives
.bytes
- The array of bytes that will be stored in this message as a MessagePart.storeAllPrimitivesInOnePart()
,
addSerializedObject(String, Object)
public void setMessageType(int messageType)
messageType
- Must be one of the following: MESSAGE_DISCONNECT
, MESSAGE_FILE
,
MESSAGE_NODE_JOIN
, MESSAGE_NODE_LEFT
,
or MESSAGE_PRIMITIVES_OR_SERIALIZED_OBJECT
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |