ca.mcgill.cs.postina.scribe
Class MessageID

java.lang.Object
  extended by ca.mcgill.cs.postina.scribe.MessageID
All Implemented Interfaces:
java.io.Serializable

public class MessageID
extends java.lang.Object
implements java.io.Serializable

A messageID is a unique identifier of a message. The messageID is used to implement reliability.

Version:
8-Jan-08
Author:
Dominik Zindel
See Also:
Serialized Form

Field Summary
private  int counter
          An integer number counting the number of times the messages has already been sent over the network.
private  rice.p2p.commonapi.NodeHandle destinationHandle
           
private  rice.p2p.commonapi.Id destinationId
           
private  int messageNumber
          An integer number.
private  rice.p2p.commonapi.Id senderId
          The unique identifier of the originator of the message.
private  long sendTimeStamp
          The system time (milliseconds) at which the message was sent.
private static long serialVersionUID
           
 
Constructor Summary
MessageID(rice.p2p.commonapi.Id senderId, rice.p2p.commonapi.Id destinationId, rice.p2p.commonapi.NodeHandle destinationHandle, int messageNumber)
          The default constructor for a messageID
 
Method Summary
 boolean equals(java.lang.Object o)
           
 int getCounter()
          This method gets the number of times the message has already been sent.
 rice.p2p.commonapi.NodeHandle getDestinationHandle()
           
 rice.p2p.commonapi.Id getDestinationId()
           
 int getMessageNumber()
          This method gets the number of the message.
 long getRemainingTimeOut(long timeout)
          This method computes the time that is remaining before the message times out.
 rice.p2p.commonapi.Id getSenderId()
          This method gets the unique identifier of the sender of the message.
 long getSendTimeStamp()
          This method gets the Unix time stamp at which the message was sent the last time.
 int hashCode()
           
 boolean hasTimedOut(long timeout)
          This method checks if the message is older than the specified time.
 void incCounter()
          This message increases the counter of the number of times the message has been sent by one.
 void resetSendTimeStamp()
          This method resets the time stamp of the messageId to the current system time.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

counter

private int counter
An integer number counting the number of times the messages has already been sent over the network. This is used for reliability as a message is not resent an infinite number of times.


destinationHandle

private final rice.p2p.commonapi.NodeHandle destinationHandle

destinationId

private final rice.p2p.commonapi.Id destinationId

messageNumber

private final int messageNumber
An integer number. Note that this number is not unique in the network as each client has its own counter for the messageNumber. However, the combination of the ID of the sender and the messagenumber is guaranteed to be unique.


senderId

private final rice.p2p.commonapi.Id senderId
The unique identifier of the originator of the message. The senderId is used for all actions except sending the acknowledgment.


sendTimeStamp

private long sendTimeStamp
The system time (milliseconds) at which the message was sent.

Constructor Detail

MessageID

public MessageID(rice.p2p.commonapi.Id senderId,
                 rice.p2p.commonapi.Id destinationId,
                 rice.p2p.commonapi.NodeHandle destinationHandle,
                 int messageNumber)
The default constructor for a messageID

Parameters:
senderHandle - The Pastry-nodehandle of the originator of the message.
senderId - The unique Id (by Pastry) of the sender of the message.
messageNumber - The number of the message.
Method Detail

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

getCounter

public int getCounter()
This method gets the number of times the message has already been sent.

Returns:
The integer number of times the message has been sent so far.

getDestinationHandle

public rice.p2p.commonapi.NodeHandle getDestinationHandle()
Returns:
the destinationHandle

getDestinationId

public rice.p2p.commonapi.Id getDestinationId()
Returns:
the destinationId

getMessageNumber

public int getMessageNumber()
This method gets the number of the message.

Returns:
An integer number.

getRemainingTimeOut

public long getRemainingTimeOut(long timeout)
This method computes the time that is remaining before the message times out.

Parameters:
timeout - The timeout after which the message times out.
Returns:
A long number of milliseconds, representing the difference between timeout and the age of the message. If the message has already timed out (i.e. the return value would be negative), 0 is returned.

getSenderId

public rice.p2p.commonapi.Id getSenderId()
This method gets the unique identifier of the sender of the message.

Returns:
The Id of the originator of the message.

getSendTimeStamp

public long getSendTimeStamp()
This method gets the Unix time stamp at which the message was sent the last time.

Returns:
A long representing the Unix system time.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

hasTimedOut

public boolean hasTimedOut(long timeout)
This method checks if the message is older than the specified time.

Parameters:
timeout - The minimum age in milliseconds of the message to return true.
Returns:
True if the message is at least timeout milliseconds olds, false otherwise.

incCounter

public void incCounter()
This message increases the counter of the number of times the message has been sent by one.


resetSendTimeStamp

public void resetSendTimeStamp()
This method resets the time stamp of the messageId to the current system time. This is used when a message has to be resent.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object