Class CompositeBackPressureHandler

java.lang.Object
io.awspring.cloud.sqs.listener.backpressure.CompositeBackPressureHandler
All Implemented Interfaces:
BackPressureHandler, BatchAwareBackPressureHandler, IdentifiableContainerComponent

public class CompositeBackPressureHandler extends Object implements BatchAwareBackPressureHandler, IdentifiableContainerComponent
Composite BackPressureHandler implementation that delegates the back-pressure handling to a list of BackPressureHandlers.

This class is used to combine multiple back-pressure handlers into a single one. It allows for more complex back-pressure handling strategies by combining different implementations.

The order in which the back-pressure handlers are registered in the CompositeBackPressureHandler is important as it will affect the blocking and limiting behaviour of the back-pressure handling.

When request(int amount) is called, the first back-pressure handler in the list is called with amount as the requested amount of permits. The returned amount of permits (which is less than or equal to the initial amount) is then passed to the next back-pressure handler in the list. This process of reducing the amount to request for the next handlers in the chain is called "limiting". This process continues until all back-pressure handlers have been called or 0 permits has been returned.

Once the final amount of available permits have been computed, unused acquired permits on back-pressure handlers (due to later limiting happening in the chain) are released.

If no permits were obtained, the request(int) method will wait up to noPermitsReturnedWaitTimeout for a release of permits before returning.

This handler builds on the original SemaphoreBackPressureHandler, separating specific responsibilities into a more modular form and enabling composition with other handlers as part of an extensible backpressure strategy.

Since:
4.0.0
Author:
Loïc Rouchon, Tomaz Fernandes
See Also: