本文整理了Java中org.apache.logging.log4j.ThreadContext.getImmutableStack()
方法的一些代码示例,展示了ThreadContext.getImmutableStack()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext.getImmutableStack()
方法的具体详情如下:
包路径:org.apache.logging.log4j.ThreadContext
类名称:ThreadContext
方法名:getImmutableStack
[英]Gets an immutable copy of this current thread's context stack.
[中]获取当前线程上下文堆栈的不可变副本。
代码示例来源:origin: org.apache.logging.log4j/log4j-api
/**
* Constructs a new holder initialized with an immutable copy of the ThreadContext stack and map.
*
* @param restoreContext
* @param restoreStack
*/
public ThreadContextHolder(final boolean restoreContext, final boolean restoreStack) {
this.restoreContext = restoreContext;
this.restoreStack = restoreStack;
this.immutableContext = restoreContext ? ThreadContext.getImmutableContext() : null;
this.immutableStack = restoreStack ? ThreadContext.getImmutableStack() : null;
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
public static void testGetImmutableStackReturnsEmptyStackIfEmpty() {
ThreadContext.clearStack();
assertTrue(ThreadContext.getImmutableStack().asList().isEmpty());
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Test
public void pushAllWillPushAllValues() throws Exception {
ThreadContext.push(key);
final List<String> messages = ThreadContext.getImmutableStack().asList();
ThreadContext.pop();
try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.pushAll(messages)) {
assertThat(ThreadContext.peek(), is(key));
}
assertThat(ThreadContext.peek(), is(""));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
final ThreadContext.ContextStack stack = ThreadContext.getImmutableStack();
ThreadContext.clearStack();
代码示例来源:origin: org.apache.logging.log4j/log4j-core
final ThreadContext.ContextStack stack = ThreadContext.getImmutableStack();
ThreadContext.clearStack();
代码示例来源:origin: zstackio/zstack
private static String getParentUuid() {
if (ThreadContext.getImmutableStack().isEmpty()) {
return null;
}
if (ThreadContext.getImmutableStack().size() == 1) {
String uuid = ThreadContext.get(Constants.THREAD_CONTEXT_API);
assert uuid != null;
return uuid;
}
List<String> lst = ThreadContext.getImmutableStack().asList();
return lst.get(lst.size()-2);
}
代码示例来源:origin: zstackio/zstack
private void evalThreadContextToMessage(Message msg) {
Map<String, String> ctx = ThreadContext.getImmutableContext();
if (ctx != null) {
msg.putHeaderEntry(CloudBus.HEADER_TASK_CONTEXT, ctx);
}
List<String> taskStack = ThreadContext.getImmutableStack().asList();
if (taskStack != null && !taskStack.isEmpty()) {
msg.putHeaderEntry(CloudBus.HEADER_TASK_STACK, taskStack);
}
}
代码示例来源:origin: zstackio/zstack
private void evalThreadContextToMessage(Message msg) {
Map<String, String> ctx = ThreadContext.getImmutableContext();
if (ctx != null) {
msg.putHeaderEntry(THREAD_CONTEXT, new HashMap<>(ctx));
}
List<String> list = ThreadContext.getImmutableStack().asList();
if (list != null && !list.isEmpty()) {
msg.putHeaderEntry(THREAD_CONTEXT_STACK, new ArrayList<>(list));
}
Map<Object, Object> tctx = TaskContext.getTaskContext();
if (tctx != null) {
msg.putHeaderEntry(TASK_CONTEXT, tctx);
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
final StringMap contextData = new SortedArrayStringMap();
contextData.putValue("A", "B");
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Exception exception = new Exception("test");
final Marker marker = MarkerManager.getMarker("EVENTTEST");
代码示例来源:origin: org.apache.logging.log4j/log4j-core
final StringMap contextData = ContextDataFactory.createContextData();
contextData.putValue("A", "B");
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Exception exception = new Exception("test");
final Marker marker = MarkerManager.getMarker("EVENTTEST");
代码示例来源:origin: org.apache.logging.log4j/log4j-core
final StringMap contextData = new SortedArrayStringMap();
contextData.putValue("A", "B");
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Exception exception = new Exception("test");
final Marker marker = MarkerManager.getMarker("EVENTTEST");
代码示例来源:origin: org.apache.logging.log4j/log4j-core
contextData.putValue("A", "B");
ThreadContext.push("first");
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Exception exception = new Exception("test");
final Marker marker = MarkerManager.getMarker("EVENTTEST");
final ContextStack contextStack2 = ThreadContext.getImmutableStack();
different("different contextStack", builder(event).setContextStack(contextStack2), event);
different("null contextStack", builder(event).setContextStack(null), event);
代码示例来源:origin: ops4j/org.ops4j.pax.logging
private void initTranslator(final RingBufferLogEventTranslator translator, final String fqcn,
final Level level, final Marker marker, final Message message, final Throwable thrown) {
translator.setBasicValues(this, name, marker, fqcn, level, message, //
// don't construct ThrowableProxy until required
thrown,
// needs shallow copy to be fast (LOG4J2-154)
ThreadContext.getImmutableStack(), //
// location (expensive to calculate)
calcLocationIfRequested(fqcn), //
CLOCK.currentTimeMillis(), //
nanoClock.nanoTime() //
);
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
@Override
public void translateTo(final RingBufferLogEvent event, final long sequence, final Object... args) {
// Implementation note: candidate for optimization: exceeds 35 bytecodes.
final AsyncLogger asyncLogger = (AsyncLogger) args[0];
final StackTraceElement location = (StackTraceElement) args[1];
final String fqcn = (String) args[2];
final Level level = (Level) args[3];
final Marker marker = (Marker) args[4];
final Message message = (Message) args[5];
final Throwable thrown = (Throwable) args[6];
// needs shallow copy to be fast (LOG4J2-154)
final ContextStack contextStack = ThreadContext.getImmutableStack();
final Thread currentThread = Thread.currentThread();
final String threadName = THREAD_NAME_CACHING_STRATEGY.getThreadName();
event.setValues(asyncLogger, asyncLogger.getName(), marker, fqcn, level, message, thrown,
// config properties are taken care of in the EventHandler thread
// in the AsyncLogger#actualAsyncLog method
CONTEXT_DATA_INJECTOR.injectContextData(null, (StringMap) event.getContextData()),
contextStack, currentThread.getId(), threadName, currentThread.getPriority(), location,
CLOCK.currentTimeMillis(), nanoClock.nanoTime());
}
内容来源于网络,如有侵权,请联系作者删除!