java.lang.Object
stormpot.internal.StackCompletion
- All Implemented Interfaces:
Flow.Publisher<Void>,ForkJoinPool.ManagedBlocker,Completion
An implementation of
Completion based on a wait-free stack.
This implementation also supports a callback mechanism that trigger every time
an await(Timeout) or block() call is about to block.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA callback that will be notified when threads block on a given completion. -
Constructor Summary
ConstructorsConstructorDescriptionCreate an unfinished completion with noStackCompletion.OnAwaitcallback.StackCompletion(boolean completed) Create a possibly finished completion with noStackCompletion.OnAwaitcallback.StackCompletion(StackCompletion.OnAwait onAwait) Create an unfinished completion with the givenStackCompletion.OnAwaitcallback. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCauses the current thread to wait until the completion is finished, or the thread isinterrupted, or the specified waiting time elapses.booleanblock()voidcomplete()Complete this completion and notify all waiters and subscribers.booleanImmediately return whether the completion has completed or not.booleanvoidpropagateTo(StackCompletion other) Complete the given completion when this completion completes.voidsubscribe(Flow.Subscriber<? super Void> subscriber)
-
Constructor Details
-
StackCompletion
public StackCompletion()Create an unfinished completion with noStackCompletion.OnAwaitcallback. -
StackCompletion
public StackCompletion(boolean completed) Create a possibly finished completion with noStackCompletion.OnAwaitcallback.- Parameters:
completed-trueif the completion should be initialized in the finished state, otherwisefalse.
-
StackCompletion
Create an unfinished completion with the givenStackCompletion.OnAwaitcallback.- Parameters:
onAwait- The callback to notify for blocking, may benull.
-
-
Method Details
-
complete
public void complete()Complete this completion and notify all waiters and subscribers. -
subscribe
- Specified by:
subscribein interfaceFlow.Publisher<Void>
-
propagateTo
Complete the given completion when this completion completes. If the given completion completes first, then their subscription to this completion is cancelled.- Parameters:
other- The completion to propagate to.
-
await
Description copied from interface:CompletionCauses the current thread to wait until the completion is finished, or the thread isinterrupted, or the specified waiting time elapses.If the task represented by this completion has already completed, the method immediately returns
true.If the current thread already has its interrupted status set upon entry to this method, or the thread is interrupted while waiting, then an
InterruptedExceptionis thrown and the current threads interrupted status is cleared.If the specified waiting time elapses, then the method returns
false.- Specified by:
awaitin interfaceCompletion- Parameters:
timeout- The timeout delimiting the maximum time to wait for the task to complete. Timeouts with zero or negative values will cause the method to return immediately.- Returns:
trueif the task represented by this completion completed within the specified waiting time, or was already complete upon entry to this method; orfalseif the specified Timeout elapsed before the task could finish.- Throws:
InterruptedException- if the current thread is interrupted while waiting.
-
block
- Specified by:
blockin interfaceForkJoinPool.ManagedBlocker- Throws:
InterruptedException
-
isReleasable
public boolean isReleasable()- Specified by:
isReleasablein interfaceForkJoinPool.ManagedBlocker
-
isCompleted
public boolean isCompleted()Description copied from interface:CompletionImmediately return whether the completion has completed or not.- Specified by:
isCompletedin interfaceCompletion- Returns:
trueif this completion has completed, otherwisefalse.
-