Class UpperBound

java.lang.Object
org.springframework.integration.util.UpperBound

public final class UpperBound
extends Object
Thin wrapper around a Semaphore that allows to create a potentially unlimited upper bound to by used in buffers of messages (e.g. a QueueChannel or a MessageStore).
Since:
2.0
Author:
Mark Fisher, Iwein Fuld, Artem Bilan, Gary Russell
  • Constructor Summary

    Constructors 
    Constructor Description
    UpperBound​(int capacity)
    Create an UpperBound with the given capacity.
  • Method Summary

    Modifier and Type Method Description
    int availablePermits()  
    void release()
    Releases one lock on the underlying semaphore.
    void release​(int permits)
    Releases several locks on the underlying semaphore.
    String toString()  
    boolean tryAcquire​(long timeoutInMilliseconds)
    Acquires a permit from the underlying semaphore if this UpperBound is bounded and returns true if it succeeds within the given timeout.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • UpperBound

      public UpperBound​(int capacity)
      Create an UpperBound with the given capacity. If the given capacity is less than 1 an infinite UpperBound is created.
      Parameters:
      capacity - The capacity.
  • Method Details

    • availablePermits

      public int availablePermits()
    • tryAcquire

      public boolean tryAcquire​(long timeoutInMilliseconds)
      Acquires a permit from the underlying semaphore if this UpperBound is bounded and returns true if it succeeds within the given timeout. If the timeout is less than 0, it will block indefinitely.
      Parameters:
      timeoutInMilliseconds - The time to wait until a permit is available.
      Returns:
      true if a permit is acquired.
    • release

      public void release()
      Releases one lock on the underlying semaphore. This is typically not done by the same Thread that acquired the lock, but by the thread that picked up the message.
    • release

      public void release​(int permits)
      Releases several locks on the underlying semaphore. This is typically not done by the same Thread that acquired the lock, but by the thread that picked up the message.
      Parameters:
      permits - The number of permits to release.
    • toString

      public String toString()
      Overrides:
      toString in class Object