本文整理了Java中org.slf4j.MDC.getCopyOfContextMap()
方法的一些代码示例,展示了MDC.getCopyOfContextMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MDC.getCopyOfContextMap()
方法的具体详情如下:
包路径:org.slf4j.MDC
类名称:MDC
方法名:getCopyOfContextMap
[英]Return a copy of the current thread's context map, with keys and values of type String. Returned value may be null.
[中]返回当前线程上下文映射的副本,其中包含字符串类型的键和值。返回值可能为空。
代码示例来源:origin: apache/incubator-gobblin
public MDCPropagatingCallable(Callable<T> callable) {
this.callable = callable;
this.context = MDC.getCopyOfContextMap();
}
代码示例来源:origin: apache/incubator-gobblin
public MDCPropagatingRunnable(Runnable runnable) {
this.runnable = runnable;
this.context = MDC.getCopyOfContextMap();
}
代码示例来源:origin: debezium/debezium
protected PreviousContext() {
Map<String, String> context = MDC.getCopyOfContextMap();
this.context = context != null ? context : EMPTY_CONTEXT;
}
代码示例来源:origin: apache/incubator-gobblin
public BaseGobblinJob() {
this.mdcContext = MDC.getCopyOfContextMap();
}
代码示例来源:origin: wildfly/wildfly
public Map<String, Object> getMdcMap() {
@SuppressWarnings({"unchecked"})
final Map<String, Object> map = MDC.getCopyOfContextMap();
return map == null ? Collections.<String, Object>emptyMap() : map;
}
}
代码示例来源:origin: org.slf4j/log4j-over-slf4j
/**
* This method is not part of the Log4J public API. However it
* has been called by other projects. This method is here temporarily
* until projects who are depending on this method release fixes.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Deprecated
public static Hashtable getContext() {
Map map = org.slf4j.MDC.getCopyOfContextMap();
if (map != null) {
return new Hashtable(map);
} else {
return new Hashtable();
}
}
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public void run() {
Map<String, String> originalContext = MDC.getCopyOfContextMap();
if (context != null) {
MDC.setContextMap(context);
}
try {
this.runnable.run();
} finally {
if (originalContext != null) {
MDC.setContextMap(originalContext);
} else {
MDC.clear();
}
}
}
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public T call() throws Exception {
T answer;
Map<String, String> originalContext = MDC.getCopyOfContextMap();
if (context != null) {
MDC.setContextMap(context);
}
try {
answer = this.callable.call();
} finally {
if (originalContext != null) {
MDC.setContextMap(originalContext);
} else {
MDC.clear();
}
}
return answer;
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public void logNativeQuery(RequestLogLine requestLogLine) throws IOException
final Map mdc = MDC.getCopyOfContextMap();
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void testMDCStagemonitorDeactivated() throws Exception {
when(corePlugin.isStagemonitorActive()).thenReturn(false);
when(corePlugin.getMeasurementSession())
.thenReturn(new MeasurementSession("MDCSpanEventListenerTest", "testHost", null));
mdcSpanInterceptor.onStart(spanWrapper);
assertNull(MDC.getCopyOfContextMap());
}
代码示例来源:origin: apache/incubator-gobblin
Map<String, String> originalContext = MDC.getCopyOfContextMap();
if (this.mdcContext != null) {
MDC.setContextMap(this.mdcContext);
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void testMdc() throws Exception {
Stagemonitor.reset(new MeasurementSession("MDCSpanEventListenerTest", "testHost", "testInstance"));
when(corePlugin.getMeasurementSession())
.thenReturn(new MeasurementSession("MDCSpanEventListenerTest", "testHost", "testInstance"));
mdcSpanInterceptor.onStart(spanWrapper);
assertNotNull(MDC.get("spanId"));
assertNotNull(MDC.get("traceId"));
assertNull(MDC.get("parentId"));
mdcSpanInterceptor.onFinish(spanWrapper, null, 0);
assertThat(MDC.getCopyOfContextMap()).isEmpty();
}
代码示例来源:origin: rhwayfun/spring-boot-learning-examples
@RequestMapping("/mdc/{id}")
@ResponseBody
public String mdcController(@PathVariable String id, HttpServletRequest request) {
MDC.put("traceId", request.getPathInfo());
threadPool.execute(wrap(new Runnable() {
@Override
public void run() {
logger.info("This is an mdc context controller");
}
}, MDC.getCopyOfContextMap()));
return request.getPathInfo();
}
代码示例来源:origin: webx/citrus
/** 取得当前MDC map的复本。 */
@SuppressWarnings("unchecked")
protected Map<String, String> getMDCCopy() {
Map<String, String> mdc = MDC.getCopyOfContextMap();
if (mdc == null) {
mdc = createHashMap();
}
return mdc;
}
代码示例来源:origin: rhwayfun/spring-boot-learning-examples
/**
* Pool where task threads take fixed MDC from the thread that creates the pool.
*/
@SuppressWarnings("unchecked")
public static MdcThreadPoolExecutor newWithCurrentMdc(int corePoolSize, int maximumPoolSize, long keepAliveTime,
TimeUnit unit, BlockingQueue<Runnable> workQueue) {
return new MdcThreadPoolExecutor(MDC.getCopyOfContextMap(), corePoolSize, maximumPoolSize, keepAliveTime, unit,
workQueue);
}
代码示例来源:origin: rhwayfun/spring-boot-learning-examples
/**
* All executions will have MDC injected. {@code ThreadPoolExecutor}'s submission methods ({@code submit()} etc.)
* all delegate to this.
*/
@Override
public void execute(Runnable command) {
super.execute(wrap(command, MDC.getCopyOfContextMap()));
}
代码示例来源:origin: rhwayfun/spring-boot-learning-examples
@RequestMapping("/test/{id}")
@ResponseBody
public String test(@PathVariable String id, HttpServletRequest request) {
MDC.put("traceId", request.getRequestURI());
threadPool.execute(wrap(new Runnable() {
@Override
public void run() {
logger.info("线程池任务执行--------2");
}
}, MDC.getCopyOfContextMap()));
return request.getRequestURI();
}
代码示例来源:origin: advantageous/qbit
@Test
public void testNoRequest() throws Exception {
mdcForHttpRequestInterceptor.before(methodCallBuilder
.setName("m1").build());
final Map<String, String> mdc = MDC.getCopyOfContextMap();
assertNull(mdc);
mdcForHttpRequestInterceptor.after(null, null);
final Map<String, String> mdc2 = MDC.getCopyOfContextMap();
assertNull(mdc2);
}
代码示例来源:origin: advantageous/qbit
@Test
public void testNoHeaders() throws Exception {
mdcForHttpRequestInterceptor = new SetupMdcForHttpRequestInterceptor(Collections.emptySet());
mdcForHttpRequestInterceptor.before(methodCallBuilder
.setOriginatingRequest(httpRequest).setName("m1").build());
final Map<String, String> mdc = MDC.getCopyOfContextMap();
validate(mdc, false);
mdcForHttpRequestInterceptor.after(null, null);
final Map<String, String> mdc2 = MDC.getCopyOfContextMap();
assertNull(mdc2);
}
代码示例来源:origin: advantageous/qbit
@Test
public void test() throws Exception {
mdcForHttpRequestInterceptor.before(methodCallBuilder
.setOriginatingRequest(httpRequest).setName("m1").build());
final Map<String, String> mdc = MDC.getCopyOfContextMap();
validate(mdc);
mdcForHttpRequestInterceptor.after(null, null);
final Map<String, String> mdc2 = MDC.getCopyOfContextMap();
assertNull(mdc2);
}
内容来源于网络,如有侵权,请联系作者删除!