Class SpanId

java.lang.Object
io.opencensus.trace.SpanId
All Implemented Interfaces:
Comparable<SpanId>

@Immutable public final class SpanId extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    private static final int
     
    private final long
     
    static final SpanId
    The invalid SpanId.
    private static final long
     
    static final int
    The size in bytes of the SpanId.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    SpanId(long id)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    void
    copyBytesTo(byte[] dest, int destOffset)
    Copies the byte array representations of the SpanId into the dest beginning at the destOffset offset.
    void
    copyLowerBase16To(char[] dest, int destOffset)
    Copies the lowercase base16 representations of the SpanId into the dest beginning at the destOffset offset.
    boolean
     
    static SpanId
    fromBytes(byte[] src)
    Returns a SpanId built from a byte representation.
    static SpanId
    fromBytes(byte[] src, int srcOffset)
    Returns a SpanId whose representation is copied from the src beginning at the srcOffset offset.
    static SpanId
    Returns a SpanId built from a lowercase base16 representation.
    static SpanId
    fromLowerBase16(CharSequence src, int srcOffset)
    Returns a SpanId built from a lowercase base16 representation.
    static SpanId
    Generates a new random SpanId.
    byte[]
    Returns the byte representation of the SpanId.
    int
     
    boolean
    Returns whether the span identifier is valid.
    Returns the lowercase base16 encoding of this SpanId.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • SIZE

      public static final int SIZE
      The size in bytes of the SpanId.
      Since:
      0.5
      See Also:
    • INVALID

      public static final SpanId INVALID
      The invalid SpanId. 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

      public static SpanId fromBytes(byte[] src)
      Returns a SpanId built from a byte representation.
      Parameters:
      src - the representation of the SpanId.
      Returns:
      a SpanId whose representation is given by the src parameter.
      Throws:
      NullPointerException - if src is null.
      IllegalArgumentException - if src.length is not SIZE.
      Since:
      0.5
    • fromBytes

      public static SpanId fromBytes(byte[] src, int srcOffset)
      Returns a SpanId whose representation is copied from the src beginning at the srcOffset offset.
      Parameters:
      src - the buffer where the representation of the SpanId is copied.
      srcOffset - the offset in the buffer where the representation of the SpanId begins.
      Returns:
      a SpanId whose representation is copied from the buffer.
      Throws:
      NullPointerException - if src is null.
      IndexOutOfBoundsException - if srcOffset+SpanId.SIZE is greater than src.length.
      Since:
      0.5
    • fromLowerBase16

      public static SpanId fromLowerBase16(CharSequence src)
      Returns a SpanId built from a lowercase base16 representation.
      Parameters:
      src - the lowercase base16 representation.
      Returns:
      a SpanId built from a lowercase base16 representation.
      Throws:
      NullPointerException - if src is null.
      IllegalArgumentException - if src.length is not 2 * SpanId.SIZE OR if the str has invalid characters.
      Since:
      0.11
    • fromLowerBase16

      public static SpanId fromLowerBase16(CharSequence src, int srcOffset)
      Returns a SpanId built from a lowercase base16 representation.
      Parameters:
      src - the lowercase base16 representation.
      srcOffset - the offset in the buffer where the representation of the SpanId begins.
      Returns:
      a SpanId built from a lowercase base16 representation.
      Throws:
      NullPointerException - if src is null.
      IllegalArgumentException - if not enough characters in the src from the srcOffset.
      Since:
      0.11
    • generateRandomId

      public static SpanId generateRandomId(Random random)
      Generates a new random SpanId.
      Parameters:
      random - The random number generator.
      Returns:
      a valid new SpanId.
      Since:
      0.5
    • getBytes

      public byte[] getBytes()
      Returns the byte representation of the SpanId.
      Returns:
      the byte representation of the SpanId.
      Since:
      0.5
    • copyBytesTo

      public void copyBytesTo(byte[] dest, int destOffset)
      Copies the byte array representations of the SpanId into the dest beginning at the destOffset offset.
      Parameters:
      dest - the destination buffer.
      destOffset - the starting offset in the destination buffer.
      Throws:
      NullPointerException - if dest is null.
      IndexOutOfBoundsException - if destOffset+SpanId.SIZE is greater than dest.length.
      Since:
      0.5
    • copyLowerBase16To

      public void copyLowerBase16To(char[] dest, int destOffset)
      Copies the lowercase base16 representations of the SpanId into the dest beginning at the destOffset offset.
      Parameters:
      dest - the destination buffer.
      destOffset - the starting offset in the destination buffer.
      Throws:
      IndexOutOfBoundsException - if destOffset + 2 * SpanId.SIZE is greater than dest.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 String toLowerBase16()
      Returns the lowercase base16 encoding of this SpanId.
      Returns:
      the lowercase base16 encoding of this SpanId.
      Since:
      0.11
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(SpanId that)
      Specified by:
      compareTo in interface Comparable<SpanId>