java.lang.Object
io.mishmash.opentelemetry.server.collector.Batch<T>
Type Parameters:
T - the type of elements (or work items) of this batch
Direct Known Subclasses:
SubscribersBatch

public class Batch<T> extends Object
Contains a number of elements that should be processed together, and in parallel, but actual processing might happen at different paces. Essentially it's used as a way of flow control - an OTLP client submits a 'batch' of logs, metrics or traces and each individual item might be processed by more than one LogsSubscriber, MetricsSubscriber or SpansSubscriber. A response (success or failure) cannot be returned to the client before the entire OTLP packet is processed by all subscribers, but each subscriber might work on its own pace. So, a LogsCollector, a MetricsCollector or a TracesCollector will create a batch of elements and subscribers, load it with data from an OTLP packet and 'delay' the response to the client until all the processing - of all elements by all subscribers - is done.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Batch(io.opentelemetry.context.Context ctx)
    Create a new batch that will process elements within the given Context.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(T element)
    Add a single element to this batch.
    void
    addAll(Collection<T> batchElements)
    Add a collection of elements to this batch.
    void
    Cancel this batch.
    void
    complete(T element)
    Complete a single element of this batch.
    void
    Complete this batch with an error.
    protected io.opentelemetry.context.Scope
    Make the Context the current context of the current thread.
    Returns a future that will complete when this batch completes.
    io.opentelemetry.context.Context
    Get the Context to use when processing data in this batch.
    Get the elements of this batch that were already processed.
    boolean
    Check if this batch was cancelled.
    boolean
    Check if all necessary elements of this batch have been added to it.
    protected void
    Called when the batch is completed.
    void
    Mark this batch as successfully loaded - all elements have been added successfully.
    void
    Mark this batch as not fully loaded because of an error.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Batch

      public Batch(io.opentelemetry.context.Context ctx)
      Create a new batch that will process elements within the given Context.
      Parameters:
      ctx - the context
  • Method Details

    • add

      public void add(T element)
      Add a single element to this batch.
      Parameters:
      element - the element to add
    • addAll

      public void addAll(Collection<T> batchElements)
      Add a collection of elements to this batch.
      Parameters:
      batchElements - the elements to add
    • complete

      public void complete(T element)
      Complete a single element of this batch. The batch will successfully complete only when all of its elements are completed successfully.
      Parameters:
      element - the completed element
    • completeExceptionally

      public void completeExceptionally(Throwable t)
      Complete this batch with an error.
      Parameters:
      t - the error encountered
    • setLoaded

      public void setLoaded()
      Mark this batch as successfully loaded - all elements have been added successfully.
    • setLoadFailed

      public void setLoadFailed(Throwable t)
      Mark this batch as not fully loaded because of an error.
      Parameters:
      t - the error encountered during loading
    • isLoaded

      public boolean isLoaded()
      Check if all necessary elements of this batch have been added to it.
      Returns:
      true if batch was loaded successfully
    • future

      public CompletableFuture<Void> future()
      Returns a future that will complete when this batch completes.
      Returns:
      the future
    • getProcessedElements

      public Set<T> getProcessedElements()
      Get the elements of this batch that were already processed.
      Returns:
      a set of processed items
    • cancel

      public void cancel()
      Cancel this batch.
    • isCancelled

      public boolean isCancelled()
      Check if this batch was cancelled.
      Returns:
      true if cancelled
    • currentOtelScope

      protected io.opentelemetry.context.Scope currentOtelScope()
      Make the Context the current context of the current thread.
      Returns:
      the OpenTelemetry Scope
    • getOtelContext

      public io.opentelemetry.context.Context getOtelContext()
      Get the Context to use when processing data in this batch.
      Returns:
      the context of this batch
    • otelComplete

      protected void otelComplete(Throwable t)
      Called when the batch is completed.
      Parameters:
      t - the cause of an error or null if successful