org.iperg.part.core
Class IpIdentifier

java.lang.Object
  extended by org.iperg.part.core.IpIdentifier
All Implemented Interfaces:
IpSerializable

public class IpIdentifier
extends java.lang.Object
implements IpSerializable

The IpIdentifier class represents identifiers that may be unique in time and space. That is, an instance of the IpIdentifier class that is created at a specific time by an IPerG process can be made unique in relation to all other IpIdentifier instances created by other IPerG processes at any time.

Depending on the way in which IpIdentifier instances are created, they may or may not be unique. For instance, using the empty constructor will create an identifier that is not unique in time and space:

 IpIdentifier id = new IpIdentifier(); 
An identifier can be made unique by callings its makeUnique method.
 id.makeUnique();

If an identifier is created by passing a byte stream to the constructor, the new identifier uniqueness wull dependend on the data encoded in the stream.

 IpIdentifier id = new IpIdentifier(stream); 

Version:
1.0.0 Initial version
Author:
Olov Stahl - olovs@sics.se

Constructor Summary
IpIdentifier()
          Create a new zero identifier which is NOT be unique.
IpIdentifier(IpIdentifier srcId)
          Create a new identifier which is a copy of another identifier.
IpIdentifier(IpInputStream stream)
          Create a new identifier by reading data from an input stream.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Check if the identifier equals another object (identifier)
static IpIdentifier fromString(java.lang.String s)
          Return a new IpIdentifier initialised by a string representation.
 int hashCode()
          Return a hash value for the identifier.
 boolean isZero()
          Check if the identifier is a "zero" identifier
 void makeReadOnly()
          By making the object read only, its state can not be modified, e.g., by calling the read method.
 void makeUnique()
          Make sure that the identifier is unique in time and space
static IpIdentifier newUniqueId()
          Create and return a new unique identifier instance.
 void read(IpInputStream stream)
          Read the state of the process object from an input stream.
 void setIncarnation(short incarnation)
           
 java.lang.String toString()
          Return a string representation of a identifier
 void write(IpOutputStream stream)
          Write the state of the process object into an putput stream .
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IpIdentifier

public IpIdentifier()
Create a new zero identifier which is NOT be unique.


IpIdentifier

public IpIdentifier(IpIdentifier srcId)
Create a new identifier which is a copy of another identifier. The identifier will be unique if the source identifier is unique.

Parameters:
srcId - The identifier to copy

IpIdentifier

public IpIdentifier(IpInputStream stream)
             throws java.io.IOException
Create a new identifier by reading data from an input stream. The identifier will be unique if the identifier whose state is encoded on the stream is unique.

Throws:
java.io.IOException
Method Detail

makeUnique

public void makeUnique()
Make sure that the identifier is unique in time and space


makeReadOnly

public void makeReadOnly()
By making the object read only, its state can not be modified, e.g., by calling the read method.


isZero

public boolean isZero()
Check if the identifier is a "zero" identifier

Returns:
true if identifier is a zero identifier, false otherwise

equals

public boolean equals(java.lang.Object obj)
Check if the identifier equals another object (identifier)

Overrides:
equals in class java.lang.Object
Parameters:
obj - The other object (identifier)
Returns:
true if identifiers are equal, false otherwise

write

public void write(IpOutputStream stream)
Write the state of the process object into an putput stream .

Specified by:
write in interface IpSerializable
Parameters:
stream - The output stream into which the process object's state should be written
Throws:
java.io.IOException - if an io exception occured while writing the identifier to the stream

read

public void read(IpInputStream stream)
Read the state of the process object from an input stream.

Specified by:
read in interface IpSerializable
Parameters:
stream - The input stream object from which the process object's state should be read
Throws:
java.io.IOException - if marshalling failed

toString

public java.lang.String toString()
Return a string representation of a identifier

Overrides:
toString in class java.lang.Object

fromString

public static IpIdentifier fromString(java.lang.String s)
Return a new IpIdentifier initialised by a string representation. The string must have been returned from the toString method:
 IpIdentifier id1 = new IpIdentifier();
 IpIdentifier id2 = IpIdentifier.fromString(id1.toString());

Returns:
A new identifier or null if string could not be parsed

newUniqueId

public static IpIdentifier newUniqueId()
Create and return a new unique identifier instance.

Returns:
THe new identifier

hashCode

public int hashCode()
Return a hash value for the identifier. We want to make sure that two identifier instances that are "equal" (i.e., their time, host and pid variable values are equal) return the same hash value.

Overrides:
hashCode in class java.lang.Object
Returns:
A hash value for the identifier

setIncarnation

public void setIncarnation(short incarnation)