Class WrapperWithContext<T>
- java.lang.Object
-
- nl.talsmasoftware.context.delegation.Wrapper<T>
-
- nl.talsmasoftware.context.delegation.WrapperWithContext<T>
-
public abstract class WrapperWithContext<T> extends Wrapper<T>
Wrapper that also contains a fixed context snapshot.- Author:
- Sjoerd Talsma
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedWrapperWithContext(ContextSnapshot snapshot, T delegate)Creates a new Wrapper with the specified context snapshot.protectedWrapperWithContext(ContextSnapshotSupplier supplier, T delegate)Wraps the delegate and provides a context snapshot.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)inthashCode()protected ContextSnapshotsnapshot()Calls the supplier for the context snapshot, making sure it is called only once for this wrapper instance.StringtoString()-
Methods inherited from class nl.talsmasoftware.context.delegation.Wrapper
delegate, nonNullDelegate
-
-
-
-
Constructor Detail
-
WrapperWithContext
protected WrapperWithContext(ContextSnapshot snapshot, T delegate)
Creates a new Wrapper with the specified context snapshot.- Parameters:
snapshot- The context snapshot (required, non-null)delegate- The wrapped delegate object providing core functionality
-
WrapperWithContext
protected WrapperWithContext(ContextSnapshotSupplier supplier, T delegate)
Wraps the delegate and provides a context snapshot.Note: Make sure the supplier function does not obtain the context snapshot from any threadlocal storage! The wrapper is designed to propagate contexts from one thread to another. Therefore, the snapshot must be
capturedin the source thread andreactivatedin the target thread. If unsure, please use theconstructor with snapshotinstead.- Parameters:
supplier- The supplier for the (fixed!) context snapshot. This can be a straightforward 'holder' object or an ongoing background call. Please do not make this supplier function access anyThreadLocalvalue, as the wrapper is designed to propagate the snapshot from thread to thread!delegate- The delegate object to be wrapped.- See Also:
WrapperWithContext(ContextSnapshot, Object)
-
-
Method Detail
-
snapshot
protected ContextSnapshot snapshot()
Calls the supplier for the context snapshot, making sure it is called only once for this wrapper instance.- Returns:
- The snapshot value.
-
-