net.tomp2p.message
Class Message

java.lang.Object
  extended by net.tomp2p.message.Message

public class Message
extends Object

The message is in binary format in TomP2P. It is defined as follows and has several header and payload fields. Since we do the serialization manually, we do not need a serialization field.

Author:
Thomas Bocek

Nested Class Summary
static class Message.Command
           
static class Message.Content
           
static class Message.Type
           
 
Constructor Summary
Message()
          Creates message with a random ID
 
Method Summary
 void finished()
           
 SimpleBloomFilter<Number160> getBloomFilter1()
           
 SimpleBloomFilter<Number160> getBloomFilter2()
           
 Message.Command getCommand()
          Command of the message, such as GET, PING, etc.
 Message.Content getContentType1()
          Returns first content type.
 Message.Content getContentType2()
          Returns second content type, only if first is not empty
 Message.Content getContentType3()
          Returns second content type, only if first is not empty
 Message.Content getContentType4()
          Returns second content type, only if first is not empty
 Map<Number160,Data> getDataMap()
           
 Map<Number480,Data> getDataMap480()
           
 long getFinished()
           
 Map<Number160,HashData> getHashDataMap()
           
 int getInteger()
           
 Number160 getKey()
           
 Number160 getKeyKey1()
           
 Number160 getKeyKey2()
           
 Map<Number160,Number160> getKeyMap()
           
 Collection<Number160> getKeys()
           
 Collection<Number480> getKeys480()
           
 long getLength()
          The length of the payload
 long getLong()
           
 int getMessageId()
          Randomly generated message ID
 Collection<PeerAddress> getNeighbors()
          Returns the stored neighbors
 int getOptions()
           
 org.jboss.netty.buffer.ChannelBuffer getPayload1()
           
 org.jboss.netty.buffer.ChannelBuffer getPayload2()
           
 PublicKey getPublicKey()
           
 PeerAddress getRecipient()
          The ID of the recipient.
 PeerAddress getSender()
          The ID of the sender.
 Collection<TrackerData> getTrackerData()
           
 Message.Type getType()
          Determines if its a request oCommandr reply, and what kind of reply (error, warning states)
 int getVersion()
          Returns the version, which is 32bit.
 boolean hasContent()
           
 boolean isConvertNumber480to160()
           
 boolean isError()
           
static boolean isError(Message.Type type)
           
 boolean isFireAndForget()
           
 boolean isHintSign()
           
 boolean isKeepAlive()
           
 boolean isNotOk()
           
 boolean isOk()
           
 boolean isRequest()
           
 boolean isUDP()
           
 Message replaceDataMap(Map<Number480,Data> dataMap480)
           
 Message setCommand(Message.Command command)
          Command of the message, such as GET, PING, etc.
 Message setContentType(Message.Content contentType)
          Convient method to set content type.
 void setConvertNumber480to160(boolean convertNumber480to160)
           
 Message setDataMap(Map<Number160,Data> dataMap)
           
 Message setDataMap480(Map<Number480,Data> dataMap480)
           
 Message setDataMapConvert(Map<Number480,Data> dataMap480)
           
 Message setHashDataMap(Map<Number160,HashData> hashDataMap)
           
 void setHintSign(boolean hintSign)
           
 Message setInteger(int int_number)
           
 void setKeepAlive(boolean isKeepAlive)
           
 Message setKey(Number160 key3)
           
 Message setKeyKey(Number160 key1, Number160 key2)
           
 Message setKeyMap(Map<Number160,Number160> keyMap)
           
 Message setKeys(Collection<Number160> keys)
           
 Message setKeys480(Collection<Number480> keys480)
           
 Message setKeysConvert(Collection<Number480> keys480)
           
 Message setLength(long length)
          Set payload length.
 Message setLong(long long_number)
           
 Message setMessageId(int messageId)
          For deserialization, we need to set the id
 Message setNeighbors(Collection<PeerAddress> neighbors)
           
 Message setNeighbors(Collection<PeerAddress> neighbors, int useAtMostNeighbors)
           
 void setOptions(int options)
           
 Message setPayload(org.jboss.netty.buffer.ChannelBuffer payload)
           
 Message setPublicKey(PublicKey publicKey)
           
 Message setPublicKeyAndSign(KeyPair keyPair)
           
 Message setRecipient(PeerAddress recipient)
          Set the ID of the recipient.
 Message setSender(PeerAddress sender)
          The ID of the sender.
 void setTCP()
           
 Message setTrackerData(Collection<TrackerData> trackerData)
           
 Message setTwoBloomFilter(SimpleBloomFilter<Number160> bloomFilter1, SimpleBloomFilter<Number160> bloomFilter2)
           
 Message setType(Message.Type type)
          Set the message type.
 void setUDP()
           
 Message setVersion(int version)
          For deserialization
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Message

public Message()
Creates message with a random ID

Method Detail

getMessageId

public int getMessageId()
Randomly generated message ID

Returns:
message Id

setMessageId

public Message setMessageId(int messageId)
For deserialization, we need to set the id

Parameters:
messageId - The message Id

setUDP

public void setUDP()

setTCP

public void setTCP()

isUDP

public boolean isUDP()

finished

public void finished()

getFinished

public long getFinished()

getVersion

public int getVersion()
Returns the version, which is 32bit. Each application can choose and version to not intefere with other applications

Returns:
The application version that uses this P2P framework

setVersion

public Message setVersion(int version)
For deserialization

Parameters:
version - The 24bit version

getType

public Message.Type getType()
Determines if its a request oCommandr reply, and what kind of reply (error, warning states)

Returns:
Type of the message

setType

public Message setType(Message.Type type)
Set the message type. Either its a request or reply (with error and warning codes)

Parameters:
type - Type of the message

getCommand

public Message.Command getCommand()
Command of the message, such as GET, PING, etc.

Returns:
Command

setCommand

public Message setCommand(Message.Command command)
Command of the message, such as GET, PING, etc.

Parameters:
command - Command

getSender

public PeerAddress getSender()
The ID of the sender. Note that the IP is set via the socket.


setSender

public Message setSender(PeerAddress sender)
The ID of the sender. The IP of the sender will *not* be transferred, as this information is in the IP packet.

Parameters:
sender - The ID of the sender.

getRecipient

public PeerAddress getRecipient()
The ID of the recipient. Note that the IP is set via the socket.

Returns:
The ID of the recipient

setRecipient

public Message setRecipient(PeerAddress recipient)
Set the ID of the recipient. The IP is used to connect to the recipient, but the IP is *not* transferred.

Parameters:
recipient - The ID of the recipient

getLength

public long getLength()
The length of the payload

Returns:
Length of the payload, if no payload set, returns 0.

setLength

public Message setLength(long length)
Set payload length. This can also be used to not transfer payload even if payload has been set. If contentlength is set to 0, no payload will be transferred.

Parameters:
contentLength - The length of the payload

getContentType1

public Message.Content getContentType1()
Returns first content type. Content type can be empty if not set

Returns:
Content type 1

getContentType2

public Message.Content getContentType2()
Returns second content type, only if first is not empty

Returns:
Content type 2

getContentType3

public Message.Content getContentType3()
Returns second content type, only if first is not empty

Returns:
Content type 2

getContentType4

public Message.Content getContentType4()
Returns second content type, only if first is not empty

Returns:
Content type 2

setContentType

public Message setContentType(Message.Content contentType)
Convient method to set content type. Set first content type 1, if this is set (not empty), then set the second one.

Parameters:
contentType -

isRequest

public boolean isRequest()

isFireAndForget

public boolean isFireAndForget()

isOk

public boolean isOk()

isNotOk

public boolean isNotOk()

isError

public boolean isError()

isError

public static boolean isError(Message.Type type)

setNeighbors

public Message setNeighbors(Collection<PeerAddress> neighbors)

setNeighbors

public Message setNeighbors(Collection<PeerAddress> neighbors,
                            int useAtMostNeighbors)

getNeighbors

public Collection<PeerAddress> getNeighbors()
Returns the stored neighbors

Returns:
Null if no neighbors set or the list of neighbors

setKeys480

public Message setKeys480(Collection<Number480> keys480)

setKeysConvert

public Message setKeysConvert(Collection<Number480> keys480)

setKeys

public Message setKeys(Collection<Number160> keys)

getKeys

public Collection<Number160> getKeys()

getKeys480

public Collection<Number480> getKeys480()

replaceDataMap

public Message replaceDataMap(Map<Number480,Data> dataMap480)

setDataMap480

public Message setDataMap480(Map<Number480,Data> dataMap480)

setDataMapConvert

public Message setDataMapConvert(Map<Number480,Data> dataMap480)

setDataMap

public Message setDataMap(Map<Number160,Data> dataMap)

getDataMap

public Map<Number160,Data> getDataMap()

getDataMap480

public Map<Number480,Data> getDataMap480()

setKey

public Message setKey(Number160 key3)

setKeyKey

public Message setKeyKey(Number160 key1,
                         Number160 key2)

getKeyKey1

public Number160 getKeyKey1()

getKeyKey2

public Number160 getKeyKey2()

getKey

public Number160 getKey()

setKeyMap

public Message setKeyMap(Map<Number160,Number160> keyMap)

getKeyMap

public Map<Number160,Number160> getKeyMap()

setLong

public Message setLong(long long_number)

getLong

public long getLong()

setPayload

public Message setPayload(org.jboss.netty.buffer.ChannelBuffer payload)

getPayload1

public org.jboss.netty.buffer.ChannelBuffer getPayload1()

getPayload2

public org.jboss.netty.buffer.ChannelBuffer getPayload2()

setInteger

public Message setInteger(int int_number)

getInteger

public int getInteger()

getPublicKey

public PublicKey getPublicKey()

setPublicKey

public Message setPublicKey(PublicKey publicKey)

setPublicKeyAndSign

public Message setPublicKeyAndSign(KeyPair keyPair)

setHintSign

public void setHintSign(boolean hintSign)

isHintSign

public boolean isHintSign()

setTrackerData

public Message setTrackerData(Collection<TrackerData> trackerData)

getTrackerData

public Collection<TrackerData> getTrackerData()

setConvertNumber480to160

public void setConvertNumber480to160(boolean convertNumber480to160)

isConvertNumber480to160

public boolean isConvertNumber480to160()

hasContent

public boolean hasContent()

setOptions

public void setOptions(int options)

getOptions

public int getOptions()

setKeepAlive

public void setKeepAlive(boolean isKeepAlive)

isKeepAlive

public boolean isKeepAlive()

toString

public String toString()
Overrides:
toString in class Object

setHashDataMap

public Message setHashDataMap(Map<Number160,HashData> hashDataMap)

getHashDataMap

public Map<Number160,HashData> getHashDataMap()

setTwoBloomFilter

public Message setTwoBloomFilter(SimpleBloomFilter<Number160> bloomFilter1,
                                 SimpleBloomFilter<Number160> bloomFilter2)

getBloomFilter1

public SimpleBloomFilter<Number160> getBloomFilter1()

getBloomFilter2

public SimpleBloomFilter<Number160> getBloomFilter2()


Copyright © 2013. All Rights Reserved.