Class PendingOffsets
java.lang.Object
pl.allegro.tech.hermes.consumers.consumer.offset.PendingOffsets
This class manages pending offsets for message consumption in a thread-safe manner. It ensures
that the number of pending offsets does not exceed a specified maximum limit.
The slots map is effectively a bounded map, guarded by the
maxPendingOffsetsSemaphore. This semaphore ensures that the number of entries in the
slots map does not exceed maxPendingOffsets and prevents running out of memory. The
semaphore is used to acquire permits before adding entries to the map and to release permits when
entries are removed.
The inflightSemaphore is used to limit the number of messages that are currently being
processed (inflight). It helps control the concurrency level of message processing.
Note: Methods that modify the state of the slots map, such as markAsProcessed
and markAsInflight, must only be called after successfully acquiring a permit using the
tryAcquireSlot method.
-
Constructor Summary
ConstructorsConstructorDescriptionPendingOffsets(pl.allegro.tech.hermes.api.SubscriptionName subscriptionName, pl.allegro.tech.hermes.common.metric.MetricsFacade metrics, int inflightQueueSize, int maxPendingOffsets) -
Method Summary
Modifier and TypeMethodDescriptionvoidmarkAsInflight(SubscriptionPartitionOffset subscriptionPartitionOffset) voidmarkAsProcessed(SubscriptionPartitionOffset subscriptionPartitionOffset) voidvoidsetInflightSize(int inflightQueueSize) booleantryAcquireSlot(Duration processingInterval)
-
Constructor Details
-
PendingOffsets
public PendingOffsets(pl.allegro.tech.hermes.api.SubscriptionName subscriptionName, pl.allegro.tech.hermes.common.metric.MetricsFacade metrics, int inflightQueueSize, int maxPendingOffsets)
-
-
Method Details
-
setInflightSize
public void setInflightSize(int inflightQueueSize) -
markAsProcessed
-
tryAcquireSlot
- Throws:
InterruptedException
-
markAsInflight
-
getOffsetsSnapshotAndReleaseProcessedSlots
-
releaseSlot
public void releaseSlot()
-