APIdia Launch Partner
Top Description Fields Constructors Methods
java.rmi.server

public final Class UID

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.DataInput, .DataOutput, .IOException, .Serializable, java.security.SecureRandom

A UID represents an identifier that is unique over time with respect to the host it is generated on, or one of 216 "well-known" identifiers.

The UID() constructor can be used to generate an identifier that is unique over time with respect to the host it is generated on. The UID(short) constructor can be used to create one of 216 well-known identifiers.

A UID instance contains three primitive values:

An independently generated UID instance is unique over time with respect to the host it is generated on as long as the host requires more than one millisecond to reboot and its system clock is never set backward. A globally unique identifier can be constructed by pairing a UID instance with a unique host identifier, such as an IP address.

Authors
Ann Wollrath, Peter Jones
Since
1.1

Field Summary

Modifier and TypeField and Description
private final short
count

16-bit number to distinguish UID instances created in the same VM with the same time value

private static int
private static boolean
private static short
private static long
private static final Object
private static final long
serialVersionUID

indicate compatibility with JDK 1.1.x version of class

private final long
time

a time (as returned by System#currentTimeMillis()) at which the VM that this UID was generated in was alive

private final int
unique

number that uniquely identifies the VM that this UID was generated in with respect to its host and at the given time

Constructor Summary

AccessConstructor and Description
public
UID()

Generates a UID that is unique over time with respect to the host that it was generated on.

public
UID(short
number for well-known UID
num
)

Creates a "well-known" UID.

private
UID(int unique, long time, short count)

Constructs a UID given data read from a stream.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the given object is equivalent to this one, and false otherwise
equals
(Object
the object to compare this UID to
obj
)

Overrides java.lang.Object.equals.

Compares the specified object with this UID for equality.

public int

Returns:

the hash code value for this UID
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hash code value for this UID.

public static UID

Returns:

unmarshalled UID instance
read
(DataInput
the DataInput instance to read UID from
in
)

Constructs and returns a new UID instance by unmarshalling a binary representation from an DataInput instance.

public String

Returns:

a string representation of this UID
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this UID.

public void
write(DataOutput
the DataOutput instance to write this UID to
out
)

Marshals a binary representation of this UID to a DataOutput instance.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

countback to summary
private final short count

16-bit number to distinguish UID instances created in the same VM with the same time value

hostUniqueback to summary
private static int hostUnique
hostUniqueSetback to summary
private static boolean hostUniqueSet
lastCountback to summary
private static short lastCount
lastTimeback to summary
private static long lastTime
lockback to summary
private static final Object lock
serialVersionUIDback to summary
private static final long serialVersionUID

indicate compatibility with JDK 1.1.x version of class

timeback to summary
private final long time

a time (as returned by System#currentTimeMillis()) at which the VM that this UID was generated in was alive

uniqueback to summary
private final int unique

number that uniquely identifies the VM that this UID was generated in with respect to its host and at the given time

Constructor Detail

UIDback to summary
public UID()

Generates a UID that is unique over time with respect to the host that it was generated on.

UIDback to summary
public UID(short num)

Creates a "well-known" UID. There are 216 possible such well-known ids.

A UID created via this constructor will not clash with any UIDs generated via the no-arg constructor.

Parameters
num:short

number for well-known UID

UIDback to summary
private UID(int unique, long time, short count)

Constructs a UID given data read from a stream.

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Compares the specified object with this UID for equality. This method returns true if and only if the specified object is a UID instance with the same unique, time, and count values as this one.

Parameters
obj:Object

the object to compare this UID to

Returns:boolean

true if the given object is equivalent to this one, and false otherwise

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hash code value for this UID.

Returns:int

the hash code value for this UID

readback to summary
public static UID read(DataInput in) throws IOException

Constructs and returns a new UID instance by unmarshalling a binary representation from an DataInput instance.

Specifically, this method first invokes the given stream's DataInput#readInt() method to read a unique value, then it invoke's the stream's DataInput#readLong() method to read a time value, then it invoke's the stream's DataInput#readShort() method to read a count value, and then it creates and returns a new UID instance that contains the unique, time, and count values that were read from the stream.

Parameters
in:DataInput

the DataInput instance to read UID from

Returns:UID

unmarshalled UID instance

Exceptions
IOException:
if an I/O error occurs while performing this operation
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this UID.

Returns:String

a string representation of this UID

writeback to summary
public void write(DataOutput out) throws IOException

Marshals a binary representation of this UID to a DataOutput instance.

Specifically, this method first invokes the given stream's DataOutput#writeInt(int) method with this UID's unique value, then it invokes the stream's DataOutput#writeLong(long) method with this UID's time value, and then it invokes the stream's DataOutput#writeShort(int) method with this UID's count value.

Parameters
out:DataOutput

the DataOutput instance to write this UID to

Exceptions
IOException:
if an I/O error occurs while performing this operation