Class AsynchronousSemaphore

java.lang.Object
com.codingchili.core.benchmarking.AsynchronousSemaphore

public class AsynchronousSemaphore extends Object
An asynchronous semaphore.

This implementation does not make sure that a principal releasing a permit actually owned the permit.

  • Constructor Summary

    Constructors
    Constructor
    Description
    AsynchronousSemaphore​(CoreContext context, int limit)
    Creates a new asynchronous semaphore.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    acquire​(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler, int timeoutMS)
    Acquires a permit from the semaphore when ones becomes available.
    void
    Returns a permit to the semaphore without checking that the principal returning a permit actually owns a permit.

    Methods inherited from class java.lang.Object

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

    • AsynchronousSemaphore

      public AsynchronousSemaphore(CoreContext context, int limit)
      Creates a new asynchronous semaphore.
      Parameters:
      context - the context on which the semaphore operates.
      limit - the maximum number of permits to allow concurrently.
  • Method Details

    • acquire

      public void acquire(io.vertx.core.Handler<io.vertx.core.AsyncResult<Void>> handler, int timeoutMS)
      Acquires a permit from the semaphore when ones becomes available. If the timeout is expired while waiting the future will fail.
      Parameters:
      handler - the handler to be called when a permit is received.
      timeoutMS - the maximum time to wait for a permit.
    • release

      public void release()
      Returns a permit to the semaphore without checking that the principal returning a permit actually owns a permit.