Interface FluentSynchronizerApi.Value<T extends @Nullable Object>
- All Superinterfaces:
FluentSynchronizerApi.Common
- Enclosing interface:
- FluentSynchronizerApi
-
Method Summary
Modifier and TypeMethodDescriptionAdds an action to the chain that will discard the chain result.invoke()Invokes the action chain in a synchronized block.<R extends @Nullable Object>
FluentSynchronizerApi.Value<R>Adds an action to the chain that processes or transforms the chain result.sleepUntil(BooleanSupplier state) Adds sleeping to the action chain.sleepUntil(BooleanSupplier state, Duration checkInterval) Adds sleeping to the action chain.Adds an action which wakes other chains.wakeOthersIf(Predicate<T> predicate) Adds an action which conditionally wakes other chains.
-
Method Details
-
sleepUntil
Description copied from interface:FluentSynchronizerApi.CommonAdds sleeping to the action chain.This action ensures the given condition is met before performing the next action. When this action begins, the supplier is called immediately.
- Supplier returns
false: -
The chain sleeps until another chain wakes it up. The supplier is then called again and if it still
returns
false, the chain resumes sleeping. - Supplier returns
true: - The chain proceeds to perform the next action.
- Specified by:
sleepUntilin interfaceFluentSynchronizerApi.Common- Parameters:
state- the supplier that returnstrueif the action chain should proceed to the next action,falseotherwise.
- Supplier returns
-
sleepUntil
Description copied from interface:FluentSynchronizerApi.CommonAdds sleeping to the action chain.This action ensures the given condition is met before performing the next action. When this action begins, the supplier is called immediately.
- Supplier returns
false: -
The chain sleeps until either another chain wakes it up or the
checkIntervalhas passed.In both cases, the supplier is then called again and if it still returns
false, the chain resumes sleeping. - Supplier returns
true: - The chain proceeds to perform the next action.
- Specified by:
sleepUntilin interfaceFluentSynchronizerApi.Common- Parameters:
state- the supplier that returnstrueif the action chain should proceed to the next action,falseotherwise.checkInterval- how often the condition should be re-checked even if no wake call happens, ornullfor "never".
- Supplier returns
-
wakeOthers
FluentSynchronizerApi.Value<T> wakeOthers()Description copied from interface:FluentSynchronizerApi.CommonAdds an action which wakes other chains.- Specified by:
wakeOthersin interfaceFluentSynchronizerApi.Common
-
wakeOthersIf
Adds an action which conditionally wakes other chains. If the condition isfalse, the chain immediately proceeds to perform the next action.- Parameters:
predicate- a test operating on the chain result that returnstrueif this action chain should wake other chains,falseotherwise.- Throws:
NullPointerException- ifpredicateis null
-
map
Adds an action to the chain that processes or transforms the chain result.- Parameters:
function- the mapping function- Throws:
NullPointerException- iffunctionis null
-
invoke
Invokes the action chain in a synchronized block.All actions will be performed in order. This method blocks until all actions in the chain have been completed.
While several action chains can be invoked concurrently on the same synchronizer, only one of them will perform an action at any given time. As this involves acquiring a lock shared with other action chains, care must be taken to avoid deadlocks, just as if using
synchronizedblocks andObject.wait()/Object.notifyAll()directly.- Returns:
- the chain result
- Throws:
UncheckedInterruptedException- if the thread was interrupted while waiting (i.e. performing a sleep action).
-
discardResult
FluentSynchronizerApi.VoidInvoke discardResult()Adds an action to the chain that will discard the chain result. This allows adding subsequentrun(Runnable)actions or a differentget(Supplier)action.
-