Class SemaphoreSequencer
- java.lang.Object
-
- com.composum.sling.core.concurrent.SemaphoreSequencer
-
- All Implemented Interfaces:
SequencerService<SemaphoreSequencer.Token>
public class SemaphoreSequencer extends Object implements SequencerService<SemaphoreSequencer.Token>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SemaphoreSequencer.Token
-
Constructor Summary
Constructors Constructor Description SemaphoreSequencer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull SemaphoreSequencer.Token
acquire(String key)
Ensures the exclusiveness regarding the 'key' bind to the returned token.protected void
activate(org.osgi.service.component.ComponentContext context)
protected void
cleanOldSemaphores(Map<SemaphoreSequencer.Token,WeakReference<SemaphoreSequencer.Token>> tokensToClear)
protected void
deactivate(org.osgi.service.component.ComponentContext context)
We release all locks currently held to unblock threads waiting for something.void
release(SemaphoreSequencer.Token token)
Stops the exclusive access to the 'key' encapsulated in the token which was generated by the corresponding 'acquire()'.
-
-
-
Method Detail
-
acquire
@NotNull public @NotNull SemaphoreSequencer.Token acquire(String key)
Description copied from interface:SequencerService
Ensures the exclusiveness regarding the 'key' bind to the returned token. Remember to use this in a try finally withSequencerService.release(Token)
.- Specified by:
acquire
in interfaceSequencerService<SemaphoreSequencer.Token>
- Returns:
- the token which is necessary to release the binding
-
release
public void release(SemaphoreSequencer.Token token)
Description copied from interface:SequencerService
Stops the exclusive access to the 'key' encapsulated in the token which was generated by the corresponding 'acquire()'. Must be called after a successfulSequencerService.acquire(String)
, and the Token must be discarded afterwards.- Specified by:
release
in interfaceSequencerService<SemaphoreSequencer.Token>
-
activate
protected void activate(org.osgi.service.component.ComponentContext context)
-
deactivate
protected void deactivate(org.osgi.service.component.ComponentContext context)
We release all locks currently held to unblock threads waiting for something. That can break our users, but what can you do when the service is deactivated? That's probably better than having blocked threads lying around.
-
cleanOldSemaphores
protected void cleanOldSemaphores(Map<SemaphoreSequencer.Token,WeakReference<SemaphoreSequencer.Token>> tokensToClear)
-
-