Interface SemaphoreKeeper<K>
-
- Type Parameters:
K
- key type
- All Known Implementing Classes:
SemaphoreKeeperGuavaImpl
public interface SemaphoreKeeper<K>
Key based semaphore provider. For the same key there is always only one semaphore available. Unused semaphores are garbage-collect.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
releaseGuard(@Nullable Semaphore guard)
Unlock and release guard.Semaphore
summonGuard(@NonNull K key)
Create or load semaphore for key from cache.Semaphore
summonGuardAndAcquire(@NonNull K key)
Get guard and lock for key.
-
-
-
Method Detail
-
summonGuard
Semaphore summonGuard(@NonNull K key)
Create or load semaphore for key from cache.- Parameters:
key
- semaphore identifier- Returns:
- new or existing semaphore for given key, for one key there is always only one semaphore available
-
summonGuardAndAcquire
Semaphore summonGuardAndAcquire(@NonNull K key)
Get guard and lock for key.- Parameters:
key
- for which guard should be created and acquired- Returns:
- semaphore guard
-
releaseGuard
void releaseGuard(@Nullable Semaphore guard)
Unlock and release guard.- Parameters:
guard
- semaphore guard which should be released
-
-