Interface BackPressureHandler

All Known Subinterfaces:
BatchAwareBackPressureHandler
All Known Implementing Classes:
SemaphoreBackPressureHandler

public interface BackPressureHandler
Abstraction to handle backpressure within a PollingMessageSource. Release methods must be thread-safe so that many messages can be processed asynchronously. Example strategies are semaphore-based, rate limiter-based, a mix of both, or any other.
Since:
3.0
Author:
Tomaz Fernandes
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    drain(Duration timeout)
    Attempts to acquire all permits up to the specified timeout.
    void
    release(int amount)
    Release the specified amount of permits.
    int
    request(int amount)
    Request a number of permits.
  • Method Details

    • request

      int request(int amount) throws InterruptedException
      Request a number of permits. Each obtained permit allows the MessageSource to retrieve one message.
      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

      void release(int amount)
      Release the specified amount of permits. Each message that has been processed should release one permit, whether processing was successful or not.
      Parameters:
      amount - the amount of permits to release.
    • drain

      boolean drain(Duration timeout)
      Attempts to acquire all permits up to the specified timeout. If successful, means all permits were returned and thus no activity is left in the MessageSource.
      Parameters:
      timeout - the maximum amount of time to wait for all permits to be released.
      Returns:
      whether all permits were acquired.