Class ConcurrencyLimiterBlockingBackPressureHandler
java.lang.Object
io.awspring.cloud.sqs.listener.backpressure.ConcurrencyLimiterBlockingBackPressureHandler
- All Implemented Interfaces:
BackPressureHandler,BatchAwareBackPressureHandler,IdentifiableContainerComponent
public class ConcurrencyLimiterBlockingBackPressureHandler
extends Object
implements BatchAwareBackPressureHandler, IdentifiableContainerComponent
A blocking
BackPressureHandler that limits concurrency using a Semaphore. Suitable for scenarios
requiring strict control over the number of concurrently processed messages.
Designed to be used stand-alone or in conjunction with other BackPressureHandlers within a
CompositeBackPressureHandler.
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classNested classes/interfaces inherited from interface io.awspring.cloud.sqs.listener.backpressure.BackPressureHandler
BackPressureHandler.ReleaseReason -
Method Summary
Modifier and TypeMethodDescriptionbuilder()booleanAttempts to acquire all permits up to the specified timeout.getId()Get the component id.voidrelease(int amount, BackPressureHandler.ReleaseReason reason) Releases the specified amount of permits for processed messages.intrequest(int amount) Requests a number of permits.intRequest a batch of permits.voidSet the component id.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.awspring.cloud.sqs.listener.backpressure.BackPressureHandler
releaseMethods inherited from interface io.awspring.cloud.sqs.listener.backpressure.BatchAwareBackPressureHandler
getBatchSize, releaseBatch
-
Method Details
-
builder
-
setId
Description copied from interface:IdentifiableContainerComponentSet the component id.- Specified by:
setIdin interfaceIdentifiableContainerComponent- Parameters:
id- the id.
-
getId
Description copied from interface:IdentifiableContainerComponentGet the component id.- Specified by:
getIdin interfaceIdentifiableContainerComponent- Returns:
- the id.
-
requestBatch
Description copied from interface:BatchAwareBackPressureHandlerRequest a batch of permits.- Specified by:
requestBatchin interfaceBatchAwareBackPressureHandler- Returns:
- the number of permits acquired.
- Throws:
InterruptedException- if the Thread is interrupted while waiting for permits.
-
request
Description copied from interface:BackPressureHandlerRequests a number of permits. Each obtained permit allows theMessageSourceto retrieve one message.- Specified by:
requestin interfaceBackPressureHandler- Parameters:
amount- the amount of permits to request.- Returns:
- the amount of permits obtained.
- Throws:
InterruptedException- if the Thread is interrupted while waiting for permits.
-
release
Description copied from interface:BackPressureHandlerReleases the specified amount of permits for processed messages. Each message that has been processed should release one permit, whether processing was successful or not.This method can be called in the following use cases:
BackPressureHandler.ReleaseReason.LIMITED: all/some permits were not used because another BackPressureHandler has a lower permits limit and the difference in permits needs to be returned.BackPressureHandler.ReleaseReason.NONE_FETCHED: none of the permits were actually used because no messages were retrieved from SQS. Permits need to be returned.BackPressureHandler.ReleaseReason.PARTIAL_FETCH: some of the permits were used (some messages were retrieved from SQS). The unused ones need to be returned. The amount to be returned might be 0, in which case it means all the permits will be used as the same number of messages were fetched from SQS.BackPressureHandler.ReleaseReason.PROCESSED: a message processing finished, successfully or not.
- Specified by:
releasein interfaceBackPressureHandler- Specified by:
releasein interfaceBatchAwareBackPressureHandler- Parameters:
amount- the amount of permits to release.reason- the reason why the permits were released.
-
drain
Description copied from interface:BackPressureHandlerAttempts to acquire all permits up to the specified timeout. If successful, means all permits were returned and thus no activity is left in theMessageSource.- Specified by:
drainin interfaceBackPressureHandler- Parameters:
timeout- the maximum amount of time to wait for all permits to be released.- Returns:
- whether all permits were acquired.
-