Class BreakingBytesRefBuilder

java.lang.Object
org.elasticsearch.compute.operator.BreakingBytesRefBuilder
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.lucene.util.Accountable, org.elasticsearch.core.Releasable

public class BreakingBytesRefBuilder extends Object implements org.apache.lucene.util.Accountable, org.elasticsearch.core.Releasable
Builder for bytes arrays that checks its size against a CircuitBreaker.
  • Field Summary

    Fields inherited from interface org.apache.lucene.util.Accountable

    NULL_ACCOUNTABLE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Build.
    BreakingBytesRefBuilder(CircuitBreaker breaker, String label, int initialCapacity)
    Build.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(byte b)
    Append a byte.
    void
    append(byte[] b, int off, int len)
    Append bytes.
    void
    append(org.apache.lucene.util.BytesRef bytes)
    Append bytes.
    byte[]
    Return the underlying bytes being built for direct manipulation.
    org.apache.lucene.util.BytesRef
    Returns a view of the data added as a BytesRef.
    void
    Reset the builder to an empty bytes array.
    void
     
    void
    copyBytes(org.apache.lucene.util.BytesRef newBytes)
    Set the content of the builder to the given bytes.
    void
    grow(int capacity)
    Make sure that the underlying bytes has a capacity of at least capacity.
    int
    The number of bytes in this buffer.
    long
     
    void
    setLength(int length)
    Set the number of bytes in this buffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.lucene.util.Accountable

    getChildResources
  • Constructor Details

    • BreakingBytesRefBuilder

      public BreakingBytesRefBuilder(CircuitBreaker breaker, String label)
      Build.
      Parameters:
      breaker - the CircuitBreaker to check on resize
      label - the label reported by the breaker when it breaks
    • BreakingBytesRefBuilder

      public BreakingBytesRefBuilder(CircuitBreaker breaker, String label, int initialCapacity)
      Build.
      Parameters:
      breaker - the CircuitBreaker to check on resize
      label - the label reported by the breaker when it breaks
      initialCapacity - the number of bytes initially allocated
  • Method Details

    • grow

      public void grow(int capacity)
      Make sure that the underlying bytes has a capacity of at least capacity.
    • bytes

      public byte[] bytes()
      Return the underlying bytes being built for direct manipulation. Callers will typically use this in combination with grow(int), length() and setLength(int) like this: <pre> bytesRefBuilder.grow(bytesRefBuilder.length() + Long.BYTES); LONG.set(bytesRefBuilder.bytes(), bytesRefBuilder.length(), value); bytesRefBuilder.setLength(bytesRefBuilder.length() + Long.BYTES); </pre>
    • length

      public int length()
      The number of bytes in this buffer. It is not> the capacity of the buffer.
    • setLength

      public void setLength(int length)
      Set the number of bytes in this buffer. Does not deallocate the underlying buffer, only the length once built.
    • append

      public void append(byte b)
      Append a byte.
    • append

      public void append(byte[] b, int off, int len)
      Append bytes.
    • append

      public void append(org.apache.lucene.util.BytesRef bytes)
      Append bytes.
    • copyBytes

      public void copyBytes(org.apache.lucene.util.BytesRef newBytes)
      Set the content of the builder to the given bytes.
    • clear

      public void clear()
      Reset the builder to an empty bytes array. Doesn't deallocate any memory.
    • bytesRefView

      public org.apache.lucene.util.BytesRef bytesRefView()
      Returns a view of the data added as a BytesRef. Importantly, this does not copy the bytes and any further modification to the BreakingBytesRefBuilder will modify the returned BytesRef. The caller must copy the bytes if they wish to keep them.
    • ramBytesUsed

      public long ramBytesUsed()
      Specified by:
      ramBytesUsed in interface org.apache.lucene.util.Accountable
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface org.elasticsearch.core.Releasable