/** Execute the given runnable within the context of this CDC. */ public void execute(Runnable r) { String session = MDC.get(MDC_SESSION); String cell = MDC.get(MDC_CELL); String domain = MDC.get(MDC_DOMAIN); NDC ndc = NDC.cloneNdc(); try { apply(); r.run(); } finally { setMdc(MDC_DOMAIN, domain); setMdc(MDC_CELL, cell); setMdc(MDC_SESSION, session); NDC.set(ndc); } }
/** * Restore the cells diagnostic context to the calling thread. The old diagnostic context is * captured and returned. */ public CDC restore() { CDC cdc = new CDC(); apply(); return cdc; }
@Override public void close() { apply(); }