Package com.tangosol.util
Class UID
java.lang.Object
com.tangosol.util.Base
com.tangosol.util.UID
- All Implemented Interfaces:
ExternalizableLite
,PortableObject
,Serializable
,Comparable
public class UID
extends Base
implements Comparable, Serializable, ExternalizableLite, PortableObject
A UID is a 128-bit identifier that is almost guaranteed to be unique.
- Author:
- cp 2000.09.12
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Compares this object with the specified object for order.boolean
Determine if two UIDs are equal.int
Determine the internet address of the host that generated the UID instance (or a random number if no internet address was available)int
getCount()
Determine the "counter" portion of the UID that ensures that two UIDs generated at the same exact time by the same process are unique.long
Determine the date/time value that the UID instance was generated.int
hashCode()
Determine a hash code for the UID object.static void
Allow UID identifiers to be generated or parsed at the command line.void
Restore the contents of a user type instance by reading its state using the specified PofReader object.void
Restore the contents of this object by loading the object's state from the passed DataInput object.void
save
(DataOutput stream) Store this UID in a stream.byte[]
Convert the UID to a byte array of 16 bytes.char[]
Convert the UID to a character array of 32 hex digits.static long
toLong
(InetAddress addr) Converts and IP address to a long value.toString()
Convert the UID to a printable String.static String
toString
(long l) Converts a long value to an address string in the form returned by InetAddress#getHostAddress.void
writeExternal
(PofWriter out) Save the contents of a POF user type instance by writing its state using the specified PofWriter object.void
writeExternal
(DataOutput out) Save the contents of this object by storing the object's state into the passed DataOutput object.Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Constructor Details
-
UID
public UID()Construct a UID (default constructor). -
UID
public UID(int nAddr, long lDatetime, int nCount) Construct a UID from its constituent members (advanced constructor).- Parameters:
nAddr
- the InetAddress-related portion of the UIDlDatetime
- the creation date/time millis portion of the UIDnCount
- the counter portion of the UID
-
UID
public UID(byte[] ab) Construct a UID from a byte array.- Parameters:
ab
- a byte array as would be returned from UID.toByteArray()
-
UID
Construct a UID from a String.- Parameters:
s
- a String as would be returned from UID.toString()
-
UID
Construct a UID from a stream. This is a custom serialization implementation that is unrelated to the Serializable interface and the Java implementation of persistence.- Parameters:
stream
- an object implementing java.io.DataInput that contains the internal information that a previous UID wrote- Throws:
IOException
- if an error occurs reading from the stream
-
-
Method Details
-
main
Allow UID identifiers to be generated or parsed at the command line. For example, to generate 10 identifiers: java com.tangosol.util.UID 10 -
getAddress
public int getAddress()Determine the internet address of the host that generated the UID instance (or a random number if no internet address was available)- Returns:
- a 4-byte integer value holding an internet address in the byte order that is used by InetAddress and LicensedObject
-
getTimestamp
public long getTimestamp()Determine the date/time value that the UID instance was generated.- Returns:
- date/time value in millis that the UID instance was generated
-
getCount
public int getCount()Determine the "counter" portion of the UID that ensures that two UIDs generated at the same exact time by the same process are unique.- Returns:
- a number that helps to make the UID unique
-
toString
Convert the UID to a printable String. -
toByteArray
public byte[] toByteArray()Convert the UID to a byte array of 16 bytes.- Returns:
- the UID data as a byte array of 16 bytes
-
toCharArray
public char[] toCharArray()Convert the UID to a character array of 32 hex digits.- Returns:
- the UID data as a character array of 32 hex digits
-
equals
Determine if two UIDs are equal. -
compareTo
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.- Specified by:
compareTo
in interfaceComparable
- Parameters:
o
- the Object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
- Throws:
ClassCastException
- if the specified object's type prevents it from being compared to this Object
-
hashCode
public int hashCode()Determine a hash code for the UID object. -
save
Store this UID in a stream. This is a custom serialization implementation that is unrelated to the Serializable interface and the Java implementation of persistence.- Parameters:
stream
- an object implementing java.io.DataOutput that this UID should write its internal information to.- Throws:
IOException
- if an error occurs writing to the stream
-
readExternal
Restore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
readExternal
in interfaceExternalizableLite
- Parameters:
in
- the DataInput stream to read data from in order to restore the state of this object- Throws:
IOException
- if an I/O exception occurs
-
writeExternal
Save the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
writeExternal
in interfaceExternalizableLite
- Parameters:
out
- the DataOutput stream to write the state of this object to- Throws:
IOException
- if an I/O exception occurs
-
readExternal
Restore the contents of a user type instance by reading its state using the specified PofReader object.- Specified by:
readExternal
in interfacePortableObject
- Parameters:
in
- the PofReader from which to read the object's state- Throws:
IOException
- if an I/O error occurs
-
writeExternal
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.- Specified by:
writeExternal
in interfacePortableObject
- Parameters:
out
- the PofWriter to which to write the object's state- Throws:
IOException
- if an I/O error occurs
-
toLong
Converts and IP address to a long value.- Parameters:
addr
- an instance of InetAddress to convert to a long- Returns:
- a long value holding the IP address
-
toString
Converts a long value to an address string in the form returned by InetAddress#getHostAddress.- Parameters:
l
- the long value holding the IP address- Returns:
- the IP address string "%d.%d.%d.%d"
-