edu.rit.m2mi
Class Eoid

java.lang.Object
  extended by edu.rit.m2mi.Eoid
All Implemented Interfaces:
Externalizable, Serializable, Comparable

public class Eoid
extends Object
implements Comparable, Externalizable

Class Eoid encapsulates an exported object identifier (EOID). An EOID uniquely identifies an object that has been exported to the M2MI layer. An EOID is a 128-bit value consisting of the following fields (from most significant to least significant): a 48-bit sequence number, a 48-bit device ID, and a 32-bit process ID. The wildcard EOID, which designates all objects that implement a certain target interface, has a value of 0.

Class Eoid provides the next() method to generate a series of EOIDs. The first generated EOID has its sequence number initialized from the system clock (System.currentTimeMillis()); has its device ID initialized to the device's globally unique device ID from the device properties file (see class DeviceProperties); and has its process ID initialized to that of the current process (see class Platform). Thereafter, each successively generated EOID has a sequence number 1 greater than the previous EOID and has the same device ID and process ID.

Class Eoid also provides the increment() method to generate an EOID that is "1 greater" than an existing EOID. The new EOID's sequence number is set to 1 greater than the existing EOID's sequence number. The new EOID's device ID and process ID are set to those of the current device and process. Class Eoid further provides the compareTo method for determining the order of two EOIDs and the max() and min() methods for choosing the larger or smaller of two EOIDs. Thus, EOIDs can be used as Lamport timestamp values for a logical clock in a distributed system.

See Also:
Serialized Form

Field Summary
static Eoid WILDCARD
          The wildcard EOID.
 
Constructor Summary
Eoid()
          Construct a new EOID.
 
Method Summary
 int compareTo(Object obj)
          Compare this EOID with the given object.
 boolean equals(Object obj)
          Determine if this EOID is equal to the given object.
 int hashCode()
          Returns a hash code for this EOID.
 Eoid increment()
          Generate the next EOID after this EOID.
static Eoid max(Eoid eoid1, Eoid eoid2)
          Determine the larger of the two given EOIDs.
static Eoid min(Eoid eoid1, Eoid eoid2)
          Determine the smaller of the two given EOIDs.
static Eoid next()
          Generate the next EOID in the series of generated EOIDs.
 void read(DataInput theDataInput)
          Read this EOID from the given data input stream.
 void readExternal(ObjectInput theObjectInput)
          Read this EOID from the given object input stream.
 String toString()
          Returns a string version of this EOID.
 void write(DataOutput theDataOutput)
          Write this EOID to the given data output stream.
 void writeExternal(ObjectOutput theObjectOutput)
          Write this EOID to the given object output stream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

WILDCARD

public static final Eoid WILDCARD
The wildcard EOID.

Constructor Detail

Eoid

public Eoid()
Construct a new EOID. The EOID's value is 0, which stands for a wildcard value.

Method Detail

next

public static Eoid next()
Generate the next EOID in the series of generated EOIDs. The new EOID's sequence number is 1 higher than the sequence number of the last EOID generated by next(); if this is the first time next() has been called, the new EOID's sequence number is initialized from the system clock. The new EOID's device ID and process ID are those of the current device and process.

Returns:
Next EOID.

increment

public Eoid increment()
Generate the next EOID after this EOID. The new EOID's sequence number is 1 higher than this EOID's sequence number. The new EOID's device ID and process ID are those of the current device and process.

Returns:
The next EOID after this EOID.

max

public static Eoid max(Eoid eoid1,
                       Eoid eoid2)
Determine the larger of the two given EOIDs.

Parameters:
eoid1 - First EOID.
eoid2 - Second EOID.
Returns:
eoid1 if eoid1 >= eoid2; eoid2 if eoid1 < eoid2.
Throws:
NullPointerException - (unchecked exception) Thrown if eoid1 is null or eoid2 is null.

min

public static Eoid min(Eoid eoid1,
                       Eoid eoid2)
Determine the smaller of the two given EOIDs.

Parameters:
eoid1 - First EOID.
eoid2 - Second EOID.
Returns:
eoid1 if eoid1 <= eoid2; eoid2 if eoid1 > eoid2.
Throws:
NullPointerException - (unchecked exception) Thrown if eoid1 is null or eoid2 is null.

compareTo

public int compareTo(Object obj)
Compare this EOID with the given object.

Specified by:
compareTo in interface Comparable
Parameters:
obj - Object to compare to. It must be a non-null instance of class Eoid.
Returns:
A number less than 0 if this EOID is less than obj; 0 if this EOID is equal to obj; a number greater than 0 if this EOID is greater than obj.
Throws:
NullPointerException - (unchecked exception) Thrown if obj is null.
ClassCastException - (unchecked exception) Thrown if obj is not an instance of class Eoid.

equals

public boolean equals(Object obj)
Determine if this EOID is equal to the given object.

Overrides:
equals in class Object
Parameters:
obj - Object to test.
Returns:
True if obj is a non-null instance of class Eoid with the same value as this EOID, false otherwise.

hashCode

public int hashCode()
Returns a hash code for this EOID.

Overrides:
hashCode in class Object
Returns:
Hash code.

toString

public String toString()
Returns a string version of this EOID. The sequence number, device ID, and process ID field values are displayed in hexadecimal with hyphens in between.

Overrides:
toString in class Object

write

public void write(DataOutput theDataOutput)
           throws IOException
Write this EOID to the given data output stream.

Parameters:
theDataOutput - Data output stream.
Throws:
IOException - Thrown if an I/O error occurred.

read

public void read(DataInput theDataInput)
          throws IOException
Read this EOID from the given data input stream. This method assumes the value was written to the stream by write().

Parameters:
theDataInput - Data input stream.
Throws:
IOException - Thrown if an I/O error occurred.

writeExternal

public void writeExternal(ObjectOutput theObjectOutput)
                   throws IOException
Write this EOID to the given object output stream.

Specified by:
writeExternal in interface Externalizable
Parameters:
theObjectOutput - Object output stream.
Throws:
IOException - Thrown if an I/O error occurred.

readExternal

public void readExternal(ObjectInput theObjectInput)
                  throws IOException
Read this EOID from the given object input stream. This method assumes the value was written to the stream by writeExternal().

Specified by:
readExternal in interface Externalizable
Parameters:
theObjectInput - Object input stream.
Throws:
IOException - Thrown if an I/O error occurred.


Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.