/** * Detaches this context from the current thread. * <p> * This will notify all sub contexts ({@link SubContext}) that this context essentially ended. */ public void detachContext() { for (SubContext ctx : subContext.values()) { try { ctx.detach(); } catch (Exception e) { Exceptions.handle() .error(e) .withSystemErrorMessage("Error detaching sub context '%s': %s (%s)", ctx.getClass().getName()) .handle(); } } }
/** * Forks and creates a sub context. * <p> * All instantiated sub contexts are forked, the MDC is re-initialized. * * @return a copy of the current call context including a fork of all available sub contexts. * @see SubContext#fork() */ public CallContext fork() { CallContext newCtx = initialize(false, getMDCValue(MDC_FLOW).asString()); newCtx.watch = watch; newCtx.addToMDC(MDC_PARENT, getMDCValue(TaskContext.MDC_SYSTEM).asString()); subContext.forEach((key, value) -> newCtx.subContext.put(key, value.fork())); newCtx.lang = lang; newCtx.lazyLanguageInstaller = lazyLanguageInstaller; newCtx.fallbackLang = fallbackLang; return newCtx; }