java.lang.Object
net.i2p.addressbook.HostChecker.DynamicSemaphore
Enclosing class:
HostChecker

private static final class HostChecker.DynamicSemaphoreextends Object
Semaphore whose permit limit can change at runtime, so concurrency adjustments apply to a cycle already in progress. Raising the limit wakes blocked acquirers; lowering it only affects future acquisitions, never in-flight ones.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Object
    Lock guarding the permit counts.
    private int
    Permits allowed after a resize.
    private int
    Permits currently available.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DynamicSemaphore(int maxPermits)
    Creates a semaphore that can be resized.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    (package private) void
    Block until below the concurrent limit, then count one more acquisition.
    (package private) void
    Release one acquisition and wake a blocked acquirer.
    (package private) void
    setMaxPermits(int maxPermits)
    Raise or lower the concurrent acquisition limit.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _lock

      private final Object _lock
      Lock guarding the permit counts.
    • _permits

      private int _permits
      Permits currently available.
    • _maxPermits

      private volatile int _maxPermits
      Permits allowed after a resize.
  • Constructor Details

    • DynamicSemaphore

      DynamicSemaphore(int maxPermits)
      Creates a semaphore that can be resized.
      Parameters:
      maxPermits - the initial permit limit
  • Method Details

    • setMaxPermits

      void setMaxPermits(int maxPermits)
      Raise or lower the concurrent acquisition limit.
      Parameters:
      maxPermits - the new limit
    • acquire

      void acquire() throws InterruptedException
      Block until below the concurrent limit, then count one more acquisition.
      Throws:
      InterruptedException - if the calling thread is interrupted while waiting for a permit
    • release

      void release()
      Release one acquisition and wake a blocked acquirer.