Package io.opencensus.trace
Class SpanId
- java.lang.Object
-
- io.opencensus.trace.SpanId
-
-
Field Summary
Fields Modifier and Type Field Description private static intBASE16_SIZEprivate longidstatic SpanIdINVALIDThe invalidSpanId.private static longINVALID_IDstatic intSIZEThe size in bytes of theSpanId.
-
Constructor Summary
Constructors Modifier Constructor Description privateSpanId(long id)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(SpanId that)voidcopyBytesTo(byte[] dest, int destOffset)Copies the byte array representations of theSpanIdinto thedestbeginning at thedestOffsetoffset.voidcopyLowerBase16To(char[] dest, int destOffset)Copies the lowercase base16 representations of theSpanIdinto thedestbeginning at thedestOffsetoffset.booleanequals(java.lang.Object obj)static SpanIdfromBytes(byte[] src)Returns aSpanIdbuilt from a byte representation.static SpanIdfromBytes(byte[] src, int srcOffset)Returns aSpanIdwhose representation is copied from thesrcbeginning at thesrcOffsetoffset.static SpanIdfromLowerBase16(java.lang.CharSequence src)Returns aSpanIdbuilt from a lowercase base16 representation.static SpanIdfromLowerBase16(java.lang.CharSequence src, int srcOffset)Returns aSpanIdbuilt from a lowercase base16 representation.static SpanIdgenerateRandomId(java.util.Random random)Generates a new randomSpanId.byte[]getBytes()Returns the byte representation of theSpanId.inthashCode()booleanisValid()Returns whether the span identifier is valid.java.lang.StringtoLowerBase16()Returns the lowercase base16 encoding of thisSpanId.java.lang.StringtoString()
-
-
-
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 aSpanIdbuilt from a byte representation.- Parameters:
src- the representation of theSpanId.- Returns:
- a
SpanIdwhose representation is given by thesrcparameter. - Throws:
java.lang.NullPointerException- ifsrcis null.java.lang.IllegalArgumentException- ifsrc.lengthis notSIZE.- Since:
- 0.5
-
fromBytes
public static SpanId fromBytes(byte[] src, int srcOffset)
Returns aSpanIdwhose representation is copied from thesrcbeginning at thesrcOffsetoffset.- Parameters:
src- the buffer where the representation of theSpanIdis copied.srcOffset- the offset in the buffer where the representation of theSpanIdbegins.- Returns:
- a
SpanIdwhose representation is copied from the buffer. - Throws:
java.lang.NullPointerException- ifsrcis null.java.lang.IndexOutOfBoundsException- ifsrcOffset+SpanId.SIZEis greater thansrc.length.- Since:
- 0.5
-
fromLowerBase16
public static SpanId fromLowerBase16(java.lang.CharSequence src)
Returns aSpanIdbuilt from a lowercase base16 representation.- Parameters:
src- the lowercase base16 representation.- Returns:
- a
SpanIdbuilt from a lowercase base16 representation. - Throws:
java.lang.NullPointerException- ifsrcis null.java.lang.IllegalArgumentException- ifsrc.lengthis not2 * SpanId.SIZEOR if thestrhas invalid characters.- Since:
- 0.11
-
fromLowerBase16
public static SpanId fromLowerBase16(java.lang.CharSequence src, int srcOffset)
Returns aSpanIdbuilt from a lowercase base16 representation.- Parameters:
src- the lowercase base16 representation.srcOffset- the offset in the buffer where the representation of theSpanIdbegins.- Returns:
- a
SpanIdbuilt from a lowercase base16 representation. - Throws:
java.lang.NullPointerException- ifsrcis null.java.lang.IllegalArgumentException- if not enough characters in thesrcfrom 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 theSpanIdinto thedestbeginning at thedestOffsetoffset.- Parameters:
dest- the destination buffer.destOffset- the starting offset in the destination buffer.- Throws:
java.lang.NullPointerException- ifdestis null.java.lang.IndexOutOfBoundsException- ifdestOffset+SpanId.SIZEis greater thandest.length.- Since:
- 0.5
-
copyLowerBase16To
public void copyLowerBase16To(char[] dest, int destOffset)Copies the lowercase base16 representations of theSpanIdinto thedestbeginning at thedestOffsetoffset.- Parameters:
dest- the destination buffer.destOffset- the starting offset in the destination buffer.- Throws:
java.lang.IndexOutOfBoundsException- ifdestOffset + 2 * SpanId.SIZEis 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:
trueif 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-