Package io.awspring.cloud.sqs.listener
Class SemaphoreBackPressureHandler
java.lang.Object
io.awspring.cloud.sqs.listener.SemaphoreBackPressureHandler
- All Implemented Interfaces:
BackPressureHandler,BatchAwareBackPressureHandler,IdentifiableContainerComponent
public class SemaphoreBackPressureHandler
extends Object
implements BatchAwareBackPressureHandler, IdentifiableContainerComponent
BackPressureHandler implementation that uses a Semaphore for handling backpressure.- Since:
- 3.0
- Author:
- Tomaz Fernandes
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()booleanAttempts to acquire all permits up to the specified timeout.intReturn the configured batch size for this handler.getId()Get the component id.voidrelease(int amount) Release the specified amount of permits.voidRelease a batch of permits.intrequest(int amount) Request a number of permits.intRequest a batch of permits.voidSet the component id.
-
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.
-
request
Description copied from interface:BackPressureHandlerRequest 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.
-
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.
-
releaseBatch
public void releaseBatch()Description copied from interface:BatchAwareBackPressureHandlerRelease a batch of permits. This has the semantics of letting theBackPressureHandlerknow that all permits from a batch are being released, in opposition toBackPressureHandler.release(int)in which any number of permits can be specified.- Specified by:
releaseBatchin interfaceBatchAwareBackPressureHandler
-
getBatchSize
public int getBatchSize()Description copied from interface:BatchAwareBackPressureHandlerReturn the configured batch size for this handler.- Specified by:
getBatchSizein interfaceBatchAwareBackPressureHandler- Returns:
- the batch size.
-
release
public void release(int amount) Description copied from interface:BackPressureHandlerRelease the specified amount of permits. Each message that has been processed should release one permit, whether processing was successful or not.- Specified by:
releasein interfaceBackPressureHandler- Parameters:
amount- the amount of permits to release.
-
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.
-