Package io.opencensus.trace
Class TraceId
- java.lang.Object
-
- io.opencensus.trace.TraceId
-
-
Field Summary
Fields Modifier and Type Field Description private static intBASE16_SIZEprivate longidHiprivate longidLostatic TraceIdINVALIDThe invalidTraceId.private static longINVALID_IDstatic intSIZEThe size in bytes of theTraceId.
-
Constructor Summary
Constructors Modifier Constructor Description privateTraceId(long idHi, long idLo)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(TraceId that)voidcopyBytesTo(byte[] dest, int destOffset)Copies the byte array representations of theTraceIdinto thedestbeginning at thedestOffsetoffset.voidcopyLowerBase16To(char[] dest, int destOffset)Copies the lowercase base16 representations of theTraceIdinto thedestbeginning at thedestOffsetoffset.booleanequals(java.lang.Object obj)static TraceIdfromBytes(byte[] src)Returns aTraceIdbuilt from a byte representation.static TraceIdfromBytes(byte[] src, int srcOffset)Returns aTraceIdwhose representation is copied from thesrcbeginning at thesrcOffsetoffset.static TraceIdfromLowerBase16(java.lang.CharSequence src)Returns aTraceIdbuilt from a lowercase base16 representation.static TraceIdfromLowerBase16(java.lang.CharSequence src, int srcOffset)Returns aTraceIdbuilt from a lowercase base16 representation.static TraceIdgenerateRandomId(java.util.Random random)Generates a new randomTraceId.byte[]getBytes()Returns the 16-bytes array representation of theTraceId.longgetLowerLong()Returns the lower 8 bytes of the trace-id as a long value, assuming little-endian order.inthashCode()booleanisValid()Returns whether theTraceIdis valid.java.lang.StringtoLowerBase16()Returns the lowercase base16 encoding of thisTraceId.java.lang.StringtoString()
-
-
-
Field Detail
-
SIZE
public static final int SIZE
The size in bytes of theTraceId.- Since:
- 0.5
- See Also:
- Constant Field Values
-
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
-
INVALID
public static final TraceId INVALID
The invalidTraceId. All bytes are '\0'.- Since:
- 0.5
-
idHi
private final long idHi
-
idLo
private final long idLo
-
-
Method Detail
-
fromBytes
public static TraceId fromBytes(byte[] src)
Returns aTraceIdbuilt from a byte representation.- Parameters:
src- the representation of theTraceId.- Returns:
- a
TraceIdwhose representation is given by thesrcparameter. - Throws:
java.lang.NullPointerException- ifsrcis null.java.lang.IllegalArgumentException- ifsrc.lengthis notSIZE.- Since:
- 0.5
-
fromBytes
public static TraceId fromBytes(byte[] src, int srcOffset)
Returns aTraceIdwhose representation is copied from thesrcbeginning at thesrcOffsetoffset.- Parameters:
src- the buffer where the representation of theTraceIdis copied.srcOffset- the offset in the buffer where the representation of theTraceIdbegins.- Returns:
- a
TraceIdwhose representation is copied from the buffer. - Throws:
java.lang.NullPointerException- ifsrcis null.java.lang.IndexOutOfBoundsException- ifsrcOffset+TraceId.SIZEis greater thansrc.length.- Since:
- 0.5
-
fromLowerBase16
public static TraceId fromLowerBase16(java.lang.CharSequence src)
Returns aTraceIdbuilt from a lowercase base16 representation.- Parameters:
src- the lowercase base16 representation.- Returns:
- a
TraceIdbuilt from a lowercase base16 representation. - Throws:
java.lang.NullPointerException- ifsrcis null.java.lang.IllegalArgumentException- ifsrc.lengthis not2 * TraceId.SIZEOR if thestrhas invalid characters.- Since:
- 0.11
-
fromLowerBase16
public static TraceId fromLowerBase16(java.lang.CharSequence src, int srcOffset)
Returns aTraceIdbuilt from a lowercase base16 representation.- Parameters:
src- the lowercase base16 representation.srcOffset- the offset in the buffer where the representation of theTraceIdbegins.- Returns:
- a
TraceIdbuilt 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 TraceId generateRandomId(java.util.Random random)
Generates a new randomTraceId.- Parameters:
random- the random number generator.- Returns:
- a new valid
TraceId. - Since:
- 0.5
-
getBytes
public byte[] getBytes()
Returns the 16-bytes array representation of theTraceId.- Returns:
- the 16-bytes array representation of the
TraceId. - Since:
- 0.5
-
copyBytesTo
public void copyBytesTo(byte[] dest, int destOffset)Copies the byte array representations of theTraceIdinto 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+TraceId.SIZEis greater thandest.length.- Since:
- 0.5
-
copyLowerBase16To
public void copyLowerBase16To(char[] dest, int destOffset)Copies the lowercase base16 representations of theTraceIdinto thedestbeginning at thedestOffsetoffset.- Parameters:
dest- the destination buffer.destOffset- the starting offset in the destination buffer.- Throws:
java.lang.IndexOutOfBoundsException- ifdestOffset + 2 * TraceId.SIZEis greater thandest.length.- Since:
- 0.18
-
isValid
public boolean isValid()
Returns whether theTraceIdis valid. A valid trace identifier is a 16-byte array with at least one non-zero byte.- Returns:
trueif theTraceIdis valid.- Since:
- 0.5
-
toLowerBase16
public java.lang.String toLowerBase16()
Returns the lowercase base16 encoding of thisTraceId.- Returns:
- the lowercase base16 encoding of this
TraceId. - Since:
- 0.11
-
getLowerLong
@Internal public long getLowerLong()
Returns the lower 8 bytes of the trace-id as a long value, assuming little-endian order. This is used in ProbabilitySampler.This method is marked as internal and subject to change.
- Returns:
- the lower 8 bytes of the trace-id as a long value, assuming little-endian order.
-
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
-
-