org.apache.logging.log4j.ThreadContext.getImmutableContext()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中org.apache.logging.log4j.ThreadContext.getImmutableContext()方法的一些代码示例,展示了ThreadContext.getImmutableContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadContext.getImmutableContext()方法的具体详情如下:
包路径:org.apache.logging.log4j.ThreadContext
类名称:ThreadContext
方法名:getImmutableContext

ThreadContext.getImmutableContext介绍

[英]Returns an immutable view of the current thread's context Map.
[中]返回当前线程上下文映射的不可变视图。

代码示例

代码示例来源:origin: wildfly/wildfly

@Override
public Map<String, Object> getMdcMap() {
  return new HashMap<String, Object>(ThreadContext.getImmutableContext());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

final Map<String, String> mdc = ThreadContext.getImmutableContext();
if (mdc.size() > 0) {
  sb.append(SPACE);

代码示例来源: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 testGetImmutableContextReturnsImmutableMapIfEmpty() {
  ThreadContext.clearMap();
  final Map<String, String> immutable = ThreadContext.getImmutableContext();
  immutable.put("otherkey", "otherval");
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

public static void testGetImmutableContextReturnsImmutableMapIfNonEmpty() {
  ThreadContext.clearMap();
  ThreadContext.put("key", "val");
  final Map<String, String> immutable = ThreadContext.getImmutableContext();
  immutable.put("otherkey", "otherval");
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

public static void testGetImmutableContextReturnsEmptyMapIfEmpty() {
  ThreadContext.clearMap();
  assertTrue(ThreadContext.getImmutableContext().isEmpty());
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

sb.append(' ');
sb.append(msg.getFormattedMessage());
final Map<String, String> mdc = ThreadContext.getImmutableContext();
if (mdc.size() > 0) {
  sb.append(' ');

代码示例来源:origin: org.apache.logging.log4j/log4j-api

public static void perfTest() throws Exception {
  ThreadContext.clearMap();
  final Timer complete = new Timer("ThreadContextTest");
  complete.start();
  ThreadContext.put("Var1", "value 1");
  ThreadContext.put("Var2", "value 2");
  ThreadContext.put("Var3", "value 3");
  ThreadContext.put("Var4", "value 4");
  ThreadContext.put("Var5", "value 5");
  ThreadContext.put("Var6", "value 6");
  ThreadContext.put("Var7", "value 7");
  ThreadContext.put("Var8", "value 8");
  ThreadContext.put("Var9", "value 9");
  ThreadContext.put("Var10", "value 10");
  final int loopCount = 1000000;
  final Timer timer = new Timer("ThreadContextCopy", loopCount);
  timer.start();
  for (int i = 0; i < loopCount; ++i) {
    final Map<String, String> map = ThreadContext.getImmutableContext();
    assertNotNull(map);
  }
  timer.stop();
  complete.stop();
  System.out.println(timer.toString());
  System.out.println(complete.toString());
}

代码示例来源: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: weld/core

@Override
public Map<String, Object> getMdcMap() {
  return new HashMap<String, Object>(ThreadContext.getImmutableContext());
}

代码示例来源:origin: org.apache.activemq/artemis-jms-client-all

@Override
public Map<String, Object> getMdcMap() {
  return new HashMap<String, Object>(ThreadContext.getImmutableContext());
}

代码示例来源:origin: apache/activemq-artemis

@Override
public Map<String, Object> getMdcMap() {
  return new HashMap<String, Object>(ThreadContext.getImmutableContext());
}

代码示例来源:origin: org.jboss.weld.se/weld-se

@Override
public Map<String, Object> getMdcMap() {
  return new HashMap<String, Object>(ThreadContext.getImmutableContext());
}

代码示例来源:origin: apache/activemq-artemis

@Override
public Map<String, Object> getMdcMap() {
  return new HashMap<String, Object>(ThreadContext.getImmutableContext());
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public Map<String, Object> getMdcMap() {
  return new HashMap<String, Object>(ThreadContext.getImmutableContext());
}

代码示例来源:origin: org.jboss.weld.se/weld-se-shaded

@Override
public Map<String, Object> getMdcMap() {
  return new HashMap<String, Object>(ThreadContext.getImmutableContext());
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@Override
public Map<String, Object> getMdcMap() {
  return new HashMap<String, Object>(ThreadContext.getImmutableContext());
}

代码示例来源:origin: zstackio/zstack

if (msg.getResourceUuid() != null) {
  vo = dbf.findByUuid(msg.getResourceUuid(), LongJobVO.class);
  vo.setApiId(ThreadContext.getImmutableContext().get(Constants.THREAD_CONTEXT_API));
  vo.setState(LongJobState.Waiting);
  vo.setExecuteTime(null);
  vo.setApiId(ThreadContext.getImmutableContext().get(Constants.THREAD_CONTEXT_API));
  vo.setJobName(msg.getJobName());
  vo.setJobData(msg.getJobData());

代码示例来源:origin: zstackio/zstack

private LongJobVO createSuccessLongJob(APISubmitLongJobMsg msg) {
  // create LongJobVO
  LongJobVO vo = new LongJobVO();
  if (msg.getResourceUuid() != null) {
    vo.setUuid(msg.getResourceUuid());
  } else {
    vo.setUuid(Platform.getUuid());
  }
  if (msg.getName() != null) {
    vo.setName(msg.getName());
  } else {
    vo.setName(msg.getJobName());
  }
  vo.setDescription(msg.getDescription());
  vo.setApiId(ThreadContext.getImmutableContext().get(Constants.THREAD_CONTEXT_API));
  vo.setJobName(msg.getJobName());
  vo.setJobData(msg.getJobData());
  vo.setState(LongJobState.Succeeded);
  vo.setJobResult(LongJobState.Succeeded.toString());
  vo.setTargetResourceUuid(msg.getTargetResourceUuid());
  vo.setManagementNodeUuid(Platform.getManagementServerId());
  vo.setAccountUuid(msg.getSession().getAccountUuid());
  vo = dbf.persistAndRefresh(vo);
  msg.setJobUuid(vo.getUuid());
  tagMgr.createTags(msg.getSystemTags(), msg.getUserTags(), vo.getUuid(), LongJobVO.class.getSimpleName());
  return vo;
}

相关文章