T - the type of events in this queue. Usually SourceRecord is
used, but in cases where additional metadata must be passed from
producers to the consumer, a custom type wrapping source records
may be used.@ThreadSafe public class ChangeEventQueue<T> extends Object implements ChangeEventQueueMetrics
The queue is configurable in different aspects, e.g. its maximum size and the
time to sleep (block) between two subsequent poll calls. See the
ChangeEventQueue.Builder for the different options. The queue applies back-pressure
semantics, i.e. if it holds the maximum number of elements, subsequent calls
to enqueue(Object) will block until elements have been removed from
the queue.
If an exception occurs on the producer side, the producer should make that
exception known by calling producerException(RuntimeException) before stopping its
operation. Upon the next call to poll(), that exception will be
raised, causing Kafka Connect to stop the connector and mark it as
FAILED.
| Modifier and Type | Class and Description |
|---|---|
static class |
ChangeEventQueue.Builder<T> |
| Modifier and Type | Field and Description |
|---|---|
private T |
bufferedEvent |
private boolean |
buffering |
private AtomicLong |
currentQueueSizeInBytes |
private static org.slf4j.Logger |
LOGGER |
private Supplier<LoggingContext.PreviousContext> |
loggingContextSupplier |
private int |
maxBatchSize |
private int |
maxQueueSize |
private long |
maxQueueSizeInBytes |
private Metronome |
metronome |
private Map<T,Long> |
objectMap |
private Duration |
pollInterval |
private RuntimeException |
producerException |
private BlockingQueue<T> |
queue |
| Modifier | Constructor and Description |
|---|---|
private |
ChangeEventQueue(Duration pollInterval,
int maxQueueSize,
int maxBatchSize,
Supplier<LoggingContext.PreviousContext> loggingContextSupplier,
long maxQueueSizeInBytes,
boolean buffering) |
| Modifier and Type | Method and Description |
|---|---|
long |
currentQueueSizeInBytes() |
void |
disableBuffering()
Disable buffering for the queue
|
protected void |
doEnqueue(T record) |
void |
enqueue(T record)
Enqueues a record so that it can be obtained via
poll(). |
void |
flushBuffer(Function<T,T> recordModifier)
Applies a function to the event and the buffer and adds it to the queue.
|
long |
maxQueueSizeInBytes() |
List<T> |
poll()
Returns the next batch of elements from this queue.
|
void |
producerException(RuntimeException producerException) |
int |
remainingCapacity() |
private void |
throwProducerExceptionIfPresent() |
int |
totalCapacity() |
private static final org.slf4j.Logger LOGGER
private final Duration pollInterval
private final int maxBatchSize
private final int maxQueueSize
private final long maxQueueSizeInBytes
private final BlockingQueue<T> queue
private final Metronome metronome
private final Supplier<LoggingContext.PreviousContext> loggingContextSupplier
private final AtomicLong currentQueueSizeInBytes
private boolean buffering
private T bufferedEvent
private volatile RuntimeException producerException
private ChangeEventQueue(Duration pollInterval, int maxQueueSize, int maxBatchSize, Supplier<LoggingContext.PreviousContext> loggingContextSupplier, long maxQueueSizeInBytes, boolean buffering)
public void enqueue(T record) throws InterruptedException
poll(). This method
will block if the queue is full.record - the record to be enqueuedInterruptedException - if this thread has been interruptedpublic void flushBuffer(Function<T,T> recordModifier) throws InterruptedException
recordModifier - InterruptedExceptionpublic void disableBuffering()
protected void doEnqueue(T record) throws InterruptedException
InterruptedExceptionpublic List<T> poll() throws InterruptedException
InterruptedException - if this thread has been interrupted while waiting for more
elements to arrivepublic void producerException(RuntimeException producerException)
private void throwProducerExceptionIfPresent()
public int totalCapacity()
totalCapacity in interface ChangeEventQueueMetricspublic int remainingCapacity()
remainingCapacity in interface ChangeEventQueueMetricspublic long maxQueueSizeInBytes()
maxQueueSizeInBytes in interface ChangeEventQueueMetricspublic long currentQueueSizeInBytes()
currentQueueSizeInBytes in interface ChangeEventQueueMetricsCopyright © 2021 JBoss by Red Hat. All rights reserved.