|
17 | 17 |
|
18 | 18 | import nl.talsmasoftware.context.api.Context; |
19 | 19 | import nl.talsmasoftware.context.api.ContextManager; |
| 20 | +import nl.talsmasoftware.context.api.ContextSnapshot; |
20 | 21 | import org.slf4j.MDC; |
21 | 22 |
|
22 | 23 | import java.util.Collections; |
|
30 | 31 | * getting the active context is fully delegated to the MDC. |
31 | 32 | * |
32 | 33 | * <p> |
| 34 | + * Upon {@linkplain ContextSnapshot#reactivate() reactivation}, |
| 35 | + * these captured values (and <em>only</em> these captured values) are reactivated in the MDC. |
| 36 | + * <ul> |
| 37 | + * <li>MDC keys that exist in the target MDC which are <em>not</em> part of the snapshot are left unchanged. |
| 38 | + * <li>MDC keys with the case-insensitive substring {@code "thread"}, are <em>not</em> captured |
| 39 | + * in the {@linkplain ContextSnapshot}, |
| 40 | + * since they most-likely contain a thread-specific value. |
| 41 | + * <li>When a reactivation is <em>closed</em>, the <em>previous</em> MDC values <em>for the captured keys</em> are restored. |
| 42 | + * All other keys that are not part of the context snapshot will be left unchanged. |
| 43 | + * </ul> |
| 44 | + * |
| 45 | + * <p> |
33 | 46 | * Closing a context returned form {@link #activate(Map)} restores the MDC |
34 | 47 | * to the values it had before the context was created.<br> |
35 | 48 | * This means that closing nested contexts out-of-order will probably result in an undesirable state.<br> |
36 | 49 | * It is therefore strongly advised to use Java's {@code try-with-resources} mechanism to ensure proper |
37 | 50 | * closing of nested MDC contexts. |
38 | 51 | * |
39 | | - * <p> |
40 | | - * This manager does not implement the optional {@link #clear()} method. |
| 52 | + * @author Sjoerd Talsma |
| 53 | + * @implNote This manager does not implement the optional {@link #clear()} method. |
41 | 54 | * {@linkplain ContextManager#clearAll()} will therefore <strong>not</strong> clear the {@linkplain MDC}. |
42 | 55 | * Please use {@linkplain MDC#clear()} explicitly to do that. |
43 | | - * |
44 | | - * @author Sjoerd Talsma |
45 | 56 | */ |
46 | 57 | public class Slf4jMdcManager implements ContextManager<Map<String, String>> { |
47 | 58 | /** |
|
0 commit comments