Package nl.talsmasoftware.context
Interface ContextSnapshot
-
public interface ContextSnapshotInterface for a 'snapshot' that can capture the (then-) 'active context' from all known registeredContextManagerimplementations.
Obtain a new snapshot by callingContextManagers.createContextSnapshot()which will include a snapshot for all supportedContexttypes through their respectivemanagers.This allows for a generic method to:
- Create a new snapshot of the active context (for all registered ContextManagers).
- Pass the returned
ContextSnapshotalong to a background job. - Allow the background job to (temporary)
reactivatethe snapshot for some required code path. - The reactivation is also a
Contextof its own. Although it does not return any specificvalue, it must beclosedwhen the work requiring the context snapshot is done. This prevents context values leaking in case the used threads are returned to some pool.
- Author:
- Sjoerd Talsma
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Context<Void>reactivate()This method activates all contained values by the snapshot in their respectiveContextimplementations.
-
-
-
Method Detail
-
reactivate
Context<Void> reactivate()
This method activates all contained values by the snapshot in their respectiveContextimplementations.The reactivated context is of type
Void, because it does not contain any value itself. It closes all contained snapshot values collectively from itsclose()method.Note: The reactivated context must be closed from the same thread that reactivated it. It is the responsibility of the caller to make sure this happens (preferably in a try-with-resources block)
Using the ContextAwareExecutorService is a safe way to propagate context snapshots without having to worry about closing them.- Returns:
- A new reactivationcontext with the snapshot values that will be valid until closed (or new values are registered).
-
-