org.jdesktop.wonderland.common.messages
Class MessageID

java.lang.Object
  extended by org.jdesktop.wonderland.common.messages.MessageID
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable

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

A unique identifier for a message. Unique MessageIDs can be generated using the MessageIDGenerator included as part of this class. Custom MessageIDGenerators can be used as well as the default generator. In multinode darkstar each machine in the server cluster will need to generate unique message ID's, a custom MessageIDGenerator will be usedm the first 32 bits will be the server ID, the last 32 bits the message ID.

Author:
jkaplan
See Also:
Serialized Form

Nested Class Summary
static class MessageID.DefaultMessageIDGenerator
          The default MessageIDGenerator uses a static long to generate message ids.
static interface MessageID.MessageIDGenerator
          A utility class for generating message ids.
 
Constructor Summary
MessageID()
          No-arg constructor required for externalizable
MessageID(long id)
          Create a messageID from the given String.
 
Method Summary
 boolean equals(java.lang.Object o)
          Compare two message ids based on the underlying ID string
static MessageID generateMessageID()
          Generate a new, unique messageID
 long getID()
          Access the id of this message
 int hashCode()
           
 void readExternal(java.io.ObjectInput in)
          Read an id from stream
static void setMessageIDGenerator(MessageID.MessageIDGenerator idGen)
          Set the default message ID generator
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
          Write a message ID to a stream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageID

public MessageID()
No-arg constructor required for externalizable


MessageID

public MessageID(long id)
Create a messageID from the given String. To generate a brand new, unique messageID, use the generateMessageID() method instead.

Method Detail

generateMessageID

public static MessageID generateMessageID()
Generate a new, unique messageID

Returns:
a new, unique messageID generated using the default MessageIDGenerator

getID

public long getID()
Access the id of this message

Returns:
the internal id

setMessageIDGenerator

public static void setMessageIDGenerator(MessageID.MessageIDGenerator idGen)
Set the default message ID generator

Parameters:
idGen - the new default message ID generator

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Write a message ID to a stream. A message ID is written in the following form: where length is the length of the id converted to the US-ASCII encoding.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - the output to write to
Throws:
java.io.IOException - if there is an error writing

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Read an id from stream

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - the input to read from
Throws:
java.io.IOException - if there is an error reading

equals

public boolean equals(java.lang.Object o)
Compare two message ids based on the underlying ID string

Overrides:
equals in class java.lang.Object
Parameters:
o - the other object to compare
Returns:
true if the object is a MessageID which has the same underlying ID as this object.

hashCode

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

toString

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


Open Wonderland - http://openwonderland.org