Package io.opencensus.trace
Class SpanId
- java.lang.Object
-
- io.opencensus.trace.SpanId
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BASE16_SIZE
private long
id
static SpanId
INVALID
The invalidSpanId
.private static long
INVALID_ID
static int
SIZE
The size in bytes of theSpanId
.
-
Constructor Summary
Constructors Modifier Constructor Description private
SpanId(long id)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(SpanId that)
void
copyBytesTo(byte[] dest, int destOffset)
Copies the byte array representations of theSpanId
into thedest
beginning at thedestOffset
offset.void
copyLowerBase16To(char[] dest, int destOffset)
Copies the lowercase base16 representations of theSpanId
into thedest
beginning at thedestOffset
offset.boolean
equals(java.lang.Object obj)
static SpanId
fromBytes(byte[] src)
Returns aSpanId
built from a byte representation.static SpanId
fromBytes(byte[] src, int srcOffset)
Returns aSpanId
whose representation is copied from thesrc
beginning at thesrcOffset
offset.static SpanId
fromLowerBase16(java.lang.CharSequence src)
Returns aSpanId
built from a lowercase base16 representation.static SpanId
fromLowerBase16(java.lang.CharSequence src, int srcOffset)
Returns aSpanId
built from a lowercase base16 representation.static SpanId
generateRandomId(java.util.Random random)
Generates a new randomSpanId
.byte[]
getBytes()
Returns the byte representation of theSpanId
.int
hashCode()
boolean
isValid()
Returns whether the span identifier is valid.java.lang.String
toLowerBase16()
Returns the lowercase base16 encoding of thisSpanId
.java.lang.String
toString()
-
-
-
Field Detail
-
SIZE
public static final int SIZE
The size in bytes of theSpanId
.- Since:
- 0.5
- See Also:
- Constant Field Values
-
INVALID
public static final SpanId INVALID
The invalidSpanId
. All bytes are 0.- Since:
- 0.5
-
BASE16_SIZE
private static final int BASE16_SIZE
- See Also:
- Constant Field Values
-
INVALID_ID
private static final long INVALID_ID
- See Also:
- Constant Field Values
-
id
private final long id
-
-
Method Detail
-
fromBytes
public static SpanId fromBytes(byte[] src)
Returns aSpanId
built from a byte representation.- Parameters:
src
- the representation of theSpanId
.- Returns:
- a
SpanId
whose representation is given by thesrc
parameter. - Throws:
java.lang.NullPointerException
- ifsrc
is null.java.lang.IllegalArgumentException
- ifsrc.length
is notSIZE
.- Since:
- 0.5
-
fromBytes
public static SpanId fromBytes(byte[] src, int srcOffset)
Returns aSpanId
whose representation is copied from thesrc
beginning at thesrcOffset
offset.- Parameters:
src
- the buffer where the representation of theSpanId
is copied.srcOffset
- the offset in the buffer where the representation of theSpanId
begins.- Returns:
- a
SpanId
whose representation is copied from the buffer. - Throws:
java.lang.NullPointerException
- ifsrc
is null.java.lang.IndexOutOfBoundsException
- ifsrcOffset+SpanId.SIZE
is greater thansrc.length
.- Since:
- 0.5
-
fromLowerBase16
public static SpanId fromLowerBase16(java.lang.CharSequence src)
Returns aSpanId
built from a lowercase base16 representation.- Parameters:
src
- the lowercase base16 representation.- Returns:
- a
SpanId
built from a lowercase base16 representation. - Throws:
java.lang.NullPointerException
- ifsrc
is null.java.lang.IllegalArgumentException
- ifsrc.length
is not2 * SpanId.SIZE
OR if thestr
has invalid characters.- Since:
- 0.11
-
fromLowerBase16
public static SpanId fromLowerBase16(java.lang.CharSequence src, int srcOffset)
Returns aSpanId
built from a lowercase base16 representation.- Parameters:
src
- the lowercase base16 representation.srcOffset
- the offset in the buffer where the representation of theSpanId
begins.- Returns:
- a
SpanId
built from a lowercase base16 representation. - Throws:
java.lang.NullPointerException
- ifsrc
is null.java.lang.IllegalArgumentException
- if not enough characters in thesrc
from thesrcOffset
.- Since:
- 0.11
-
generateRandomId
public static SpanId generateRandomId(java.util.Random random)
Generates a new randomSpanId
.- Parameters:
random
- The random number generator.- Returns:
- a valid new
SpanId
. - Since:
- 0.5
-
getBytes
public byte[] getBytes()
Returns the byte representation of theSpanId
.- Returns:
- the byte representation of the
SpanId
. - Since:
- 0.5
-
copyBytesTo
public void copyBytesTo(byte[] dest, int destOffset)
Copies the byte array representations of theSpanId
into thedest
beginning at thedestOffset
offset.- Parameters:
dest
- the destination buffer.destOffset
- the starting offset in the destination buffer.- Throws:
java.lang.NullPointerException
- ifdest
is null.java.lang.IndexOutOfBoundsException
- ifdestOffset+SpanId.SIZE
is greater thandest.length
.- Since:
- 0.5
-
copyLowerBase16To
public void copyLowerBase16To(char[] dest, int destOffset)
Copies the lowercase base16 representations of theSpanId
into thedest
beginning at thedestOffset
offset.- Parameters:
dest
- the destination buffer.destOffset
- the starting offset in the destination buffer.- Throws:
java.lang.IndexOutOfBoundsException
- ifdestOffset + 2 * SpanId.SIZE
is greater thandest.length
.- Since:
- 0.18
-
isValid
public boolean isValid()
Returns whether the span identifier is valid. A valid span identifier is an 8-byte array with at least one non-zero byte.- Returns:
true
if the span identifier is valid.- Since:
- 0.5
-
toLowerBase16
public java.lang.String toLowerBase16()
Returns the lowercase base16 encoding of thisSpanId
.- Returns:
- the lowercase base16 encoding of this
SpanId
. - Since:
- 0.11
-
equals
public boolean equals(@Nullable java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-