Class Batch<T>
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
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
ConstructorsConstructorDescriptionBatch(io.opentelemetry.context.Context ctx) Create a new batch that will process elements within the givenContext. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a single element to this batch.voidaddAll(Collection<T> batchElements) Add a collection of elements to this batch.voidcancel()Cancel this batch.voidComplete a single element of this batch.voidComplete this batch with an error.protected io.opentelemetry.context.ScopeMake theContextthe current context of the current thread.future()Returns a future that will complete when this batch completes.io.opentelemetry.context.ContextGet theContextto use when processing data in this batch.Get the elements of this batch that were already processed.booleanCheck if this batch was cancelled.booleanisLoaded()Check if all necessary elements of this batch have been added to it.protected voidCalled when the batch is completed.voidMark this batch as successfully loaded - all elements have been added successfully.voidMark this batch as not fully loaded because of an error.
-
Constructor Details
-
Batch
public Batch(io.opentelemetry.context.Context ctx) Create a new batch that will process elements within the givenContext.- Parameters:
ctx- the context
-
-
Method Details
-
add
Add a single element to this batch.- Parameters:
element- the element to add
-
addAll
Add a collection of elements to this batch.- Parameters:
batchElements- the elements to add
-
complete
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
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
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
Returns a future that will complete when this batch completes.- Returns:
- the future
-
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 theContextthe current context of the current thread.- Returns:
- the OpenTelemetry Scope
-
getOtelContext
public io.opentelemetry.context.Context getOtelContext()Get theContextto use when processing data in this batch.- Returns:
- the context of this batch
-
otelComplete
Called when the batch is completed.- Parameters:
t- the cause of an error or null if successful
-