Class RunnableWithContext
- java.lang.Object
-
- nl.talsmasoftware.context.delegation.Wrapper<T>
-
- nl.talsmasoftware.context.delegation.WrapperWithContext<T>
-
- nl.talsmasoftware.context.functions.RunnableWithContext
-
- All Implemented Interfaces:
Runnable
public class RunnableWithContext extends WrapperWithContext<T> implements Runnable
A wrapper forRunnablethatreactivates a context snapshotbefore calling a delegate.- Author:
- Sjoerd Talsma
-
-
Field Summary
Fields Modifier and Type Field Description protected Consumer<ContextSnapshot>contextSnapshotConsumerThe context snapshot consumer to provide a new snapshot to after the function is completed, may benull.
-
Constructor Summary
Constructors Modifier Constructor Description protectedRunnableWithContext(Supplier<ContextSnapshot> supplier, Runnable delegate, Consumer<ContextSnapshot> consumer)RunnableWithContext(ContextSnapshot snapshot, Runnable delegate)Creates a new runnable that performs the following steps, in-order: first reactivate the given snapshot then run the delegateRunnableWithContext(ContextSnapshot snapshot, Runnable delegate, Consumer<ContextSnapshot> consumer)Creates a new runnable that performs the following steps, in-order: first reactivate the given snapshot then run the delegate finally, if a consumer was provided capture a new ContextSnapshot
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected Optional<Consumer<ContextSnapshot>>consumer()Deprecated.The functional wrappers currently no longer use this method.voidrun()-
Methods inherited from class nl.talsmasoftware.context.delegation.WrapperWithContext
equals, hashCode, snapshot, toString
-
Methods inherited from class nl.talsmasoftware.context.delegation.Wrapper
delegate, nonNullDelegate
-
-
-
-
Field Detail
-
contextSnapshotConsumer
protected final Consumer<ContextSnapshot> contextSnapshotConsumer
The context snapshot consumer to provide a new snapshot to after the function is completed, may benull.
-
-
Constructor Detail
-
RunnableWithContext
public RunnableWithContext(ContextSnapshot snapshot, Runnable delegate)
Creates a new runnable that performs the following steps, in-order:- first reactivate the given snapshot
- then run the delegate
- Parameters:
snapshot- A snapshot for the contexts to run the delegate in.delegate- The delegate to run.- See Also:
RunnableWithContext(ContextSnapshot, Runnable, Consumer)
-
RunnableWithContext
public RunnableWithContext(ContextSnapshot snapshot, Runnable delegate, Consumer<ContextSnapshot> consumer)
Creates a new runnable that performs the following steps, in-order:- first reactivate the given snapshot
- then run the delegate
- finally, if a consumer was provided capture a new ContextSnapshot
- Parameters:
snapshot- A snapshot for the contexts to run the delegate in.delegate- The delegate to run.consumer- An optional consumer for the resulting contexts after the delegate ran (in case it changed)
-
RunnableWithContext
protected RunnableWithContext(Supplier<ContextSnapshot> supplier, Runnable delegate, Consumer<ContextSnapshot> consumer)
-
-
Method Detail
-
consumer
@Deprecated protected Optional<Consumer<ContextSnapshot>> consumer()
Deprecated.The functional wrappers currently no longer use this method.- Returns:
- An optional post-action consumer to receive a new context snapshot taken after the action.
-
-