Package edu.byu.hbll.box.internal.core
Class QuotaSemaphore
- java.lang.Object
-
- edu.byu.hbll.box.internal.core.QuotaSemaphore
-
-
Constructor Summary
Constructors Constructor Description QuotaSemaphore(int quota)
Creates a newQuotaSemaphore
with the given quota count.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
run()
Resets the quota.boolean
tryAquire(long timeout, TimeUnit unit)
Acquires semaphore if quota not reached.
-
-
-
Constructor Detail
-
QuotaSemaphore
public QuotaSemaphore(int quota)
Creates a newQuotaSemaphore
with the given quota count.- Parameters:
quota
- the quota
-
-
Method Detail
-
tryAquire
public boolean tryAquire(long timeout, TimeUnit unit) throws InterruptedException
Acquires semaphore if quota not reached. Once quota is reached, acquisitions will block until timeout or until quota is reset by callingrun()
.- Parameters:
timeout
- the maximum time to wait for a permitunit
- the time unit of thetimeout
argument- Returns:
true
if a permit was acquired andfalse
if the waiting time elapsed before a permit was acquired- Throws:
InterruptedException
- if an interrupt occurs
-
-