Package io.opencensus.trace
Class SpanId
java.lang.Object
io.opencensus.trace.SpanId
- All Implemented Interfaces:
Comparable<SpanId>
A class that represents a span identifier. A valid span identifier is an 8-byte array with at
least one non-zero byte.
- Since:
- 0.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private final long
static final SpanId
The invalidSpanId
.private static final long
static final int
The size in bytes of theSpanId
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
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
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
Returns aSpanId
built from a lowercase base16 representation.static SpanId
fromLowerBase16
(CharSequence src, int srcOffset) Returns aSpanId
built from a lowercase base16 representation.static SpanId
generateRandomId
(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.Returns the lowercase base16 encoding of thisSpanId
.toString()
-
Field Details
-
SIZE
public static final int SIZEThe size in bytes of theSpanId
.- Since:
- 0.5
- See Also:
-
INVALID
The invalidSpanId
. All bytes are 0.- Since:
- 0.5
-
BASE16_SIZE
private static final int BASE16_SIZE- See Also:
-
INVALID_ID
private static final long INVALID_ID- See Also:
-
id
private final long id
-
-
Constructor Details
-
SpanId
private SpanId(long id)
-
-
Method Details
-
fromBytes
Returns aSpanId
built from a byte representation.- Parameters:
src
- the representation of theSpanId
.- Returns:
- a
SpanId
whose representation is given by thesrc
parameter. - Throws:
NullPointerException
- ifsrc
is null.IllegalArgumentException
- ifsrc.length
is notSIZE
.- Since:
- 0.5
-
fromBytes
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:
NullPointerException
- ifsrc
is null.IndexOutOfBoundsException
- ifsrcOffset+SpanId.SIZE
is greater thansrc.length
.- Since:
- 0.5
-
fromLowerBase16
Returns aSpanId
built from a lowercase base16 representation.- Parameters:
src
- the lowercase base16 representation.- Returns:
- a
SpanId
built from a lowercase base16 representation. - Throws:
NullPointerException
- ifsrc
is null.IllegalArgumentException
- ifsrc.length
is not2 * SpanId.SIZE
OR if thestr
has invalid characters.- Since:
- 0.11
-
fromLowerBase16
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:
NullPointerException
- ifsrc
is null.IllegalArgumentException
- if not enough characters in thesrc
from thesrcOffset
.- Since:
- 0.11
-
generateRandomId
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:
NullPointerException
- ifdest
is null.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:
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
Returns the lowercase base16 encoding of thisSpanId
.- Returns:
- the lowercase base16 encoding of this
SpanId
. - Since:
- 0.11
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<SpanId>
-