@ThreadSafe public final class GuardedSession<I> extends Object
I) within predefined usage permits.
See access(long, TimeUnit, Consumer).
Created by ashwin.jayaprakash.
| Constructor and Description |
|---|
GuardedSession(I item) |
GuardedSession(int concurrentPermits,
I item) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
access(Consumer<? super I> consumer) |
boolean |
access(long waitDuration,
TimeUnit waitDurationUnits,
Consumer<? super I> consumer) |
I |
discard()
Waits for all
borrowers to safely return their items. |
public GuardedSession(I item)
item - Concurrency permit of 1.public GuardedSession(int concurrentPermits,
I item)
concurrentPermits - item - Cannot be null.public boolean access(Consumer<? super I> consumer) throws InterruptedException
consumer - InterruptedExceptionaccess(long, TimeUnit, Consumer)public boolean access(long waitDuration,
TimeUnit waitDurationUnits,
Consumer<? super I> consumer)
throws InterruptedException
waitDuration - waitDurationUnits - consumer - InterruptedException - If the item could not be borrowed because:
- Session has already been discarded
- Or, the permit could not acquired within the given duration.
public I discard() throws InterruptedException
borrowers to safely return their items.stopped. After this method
returns successfully, this session cannot be used.
Null if the session has already been discarded.
InterruptedExceptionCopyright © 2018. All rights reserved.