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 classSemaphoreSequencer.Token
-
Constructor Summary
Constructors Constructor Description SemaphoreSequencer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull SemaphoreSequencer.Tokenacquire(String key)Ensures the exclusiveness regarding the 'key' bind to the returned token.protected voidactivate(org.osgi.service.component.ComponentContext context)protected voidcleanOldSemaphores(Map<SemaphoreSequencer.Token,WeakReference<SemaphoreSequencer.Token>> tokensToClear)protected voiddeactivate(org.osgi.service.component.ComponentContext context)We release all locks currently held to unblock threads waiting for something.voidrelease(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:SequencerServiceEnsures the exclusiveness regarding the 'key' bind to the returned token. Remember to use this in a try finally withSequencerService.release(Token).- Specified by:
acquirein interfaceSequencerService<SemaphoreSequencer.Token>- Returns:
- the token which is necessary to release the binding
-
release
public void release(SemaphoreSequencer.Token token)
Description copied from interface:SequencerServiceStops 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:
releasein 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)
-
-