当前位置: 首页>>代码示例>>Java>>正文


Java ThreadContext.clearMap方法代码示例

本文整理汇总了Java中org.apache.logging.log4j.ThreadContext.clearMap方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadContext.clearMap方法的具体用法?Java ThreadContext.clearMap怎么用?Java ThreadContext.clearMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.logging.log4j.ThreadContext的用法示例。


在下文中一共展示了ThreadContext.clearMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sessionEvent

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
public void sessionEvent(MCRSessionEvent event) {
    switch (event.getType()) {
        case activated:
            ThreadContext.put("ipAddress", event.getSession().getCurrentIP());
            ThreadContext.put("loginId", event.getSession().getUserInformation().getUserID());
            ThreadContext.put("mcrSession", event.getSession().getID());
            ThreadContext.put("language", event.getSession().getCurrentLanguage());
            break;
        case passivated:
            ThreadContext.clearMap();
            break;

        default:
            break;
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:18,代码来源:MCRSessionThreadContext.java

示例2: beforeExecute

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
protected void beforeExecute(Thread t, Runnable r) {
    ThreadContext.clearMap();
    ThreadContext.clearStack();

    ThreadAroundHook debugHook = null;
    List<ThreadAroundHook> tmpHooks;       
    synchronized (_hooks) {
        tmpHooks = new ArrayList<ThreadAroundHook>(_hooks);
    }
    
    for (ThreadAroundHook hook : tmpHooks) {
        debugHook = hook;
        try {
            hook.beforeExecute(t, r);
        } catch (Exception e) {
            _logger.warn("Unhandle exception happend during executing ThreadAroundHook: " + debugHook.getClass().getCanonicalName(), e);
        }
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:21,代码来源:ScheduledThreadPoolExecutorExt.java

示例3: afterExecute

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
protected void afterExecute(Runnable r, Throwable t) {
    ThreadContext.clearMap();
    ThreadContext.clearStack();

    ThreadAroundHook debugHook = null;
    List<ThreadAroundHook> tmpHooks;
    synchronized (_hooks) {
        tmpHooks = new ArrayList<ThreadAroundHook>(_hooks);
    }
    
    for (ThreadAroundHook hook : tmpHooks) {
        debugHook = hook;
        try {
            hook.afterExecute(r, t);
        } catch (Exception e) {
            _logger.warn("Unhandle exception happend during executing ThreadAroundHook: " + debugHook.getClass().getCanonicalName(), e);
        }
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:21,代码来源:ScheduledThreadPoolExecutorExt.java

示例4: perfTest

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
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());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:27,代码来源:ThreadContextUtilityClass.java

示例5: testLookup

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testLookup() {
    final Map<String, String> map = new HashMap<>();
    map.put(TESTKEY, TESTVAL);
    final StrLookup lookup = new Interpolator(new MapLookup(map));
    ThreadContext.put(TESTKEY, TESTVAL);
    String value = lookup.lookup(TESTKEY);
    assertEquals(TESTVAL, value);
    value = lookup.lookup("ctx:" + TESTKEY);
    assertEquals(TESTVAL, value);
    value = lookup.lookup("sys:" + TESTKEY);
    assertEquals(TESTVAL, value);
    value = lookup.lookup("SYS:" + TESTKEY2);
    assertEquals(TESTVAL, value);
    value = lookup.lookup("BadKey");
    assertNull(value);
    ThreadContext.clearMap();
    value = lookup.lookup("ctx:" + TESTKEY);
    assertEquals(TESTVAL, value);
    value = lookup.lookup("jndi:" + TEST_CONTEXT_RESOURCE_NAME);
    assertEquals(TEST_CONTEXT_NAME, value);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:InterpolatorTest.java

示例6: LoggingApp

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public LoggingApp(final String member) {

        ThreadContext.clearMap();

        RequestContext.setSessionId("session1234");
        RequestContext.setIpAddress("127.0.0.1");
        RequestContext.setClientId("02121");
        RequestContext.setProductName("IB");
        RequestContext.setProductVersion("4.18.1");
        RequestContext.setLocale("en_US");
        RequestContext.setRegion("prod");

        if (events == null) {
            events = MockEventsSupplier.getAllEvents(member);
        }
    }
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:LoggingApp.java

示例7: testConverterFullEmpty

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testConverterFullEmpty() {
    ThreadContext.clearMap();
    final Message msg = new SimpleMessage("Hello");
    final MdcPatternConverter converter = MdcPatternConverter.newInstance(null);
    final LogEvent event = Log4jLogEvent.newBuilder() //
            .setLoggerName("MyLogger") //
            .setLevel(Level.DEBUG) //
            .setMessage(msg) //
            .build();
    final StringBuilder sb = new StringBuilder();
    converter.format(event, sb);
    final String str = sb.toString();
    final String expected = "{}";
    assertTrue("Incorrect result. Expected " + expected + ", actual " + str, str.equals(expected));
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:MdcPatternConverterTest.java

示例8: testJavascriptFilter

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testJavascriptFilter() throws Exception {
    final Logger logger = LogManager.getLogger("TestJavaScriptFilter");
    logger.traceEntry();
    logger.info("This should not be logged");
    ThreadContext.put("UserId", "JohnDoe");
    logger.info("This should be logged");
    ThreadContext.clearMap();
    final ListAppender app = getContext().getListAppender("List");
    final List<String> messages = app.getMessages();
    try {
        assertNotNull("No Messages", messages);
        assertTrue("Incorrect number of messages. Expected 2, Actual " + messages.size(), messages.size() == 2);
    } finally {
        app.clear();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:AbstractScriptFilterTest.java

示例9: testEvents

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void testEvents() {
    ThreadContext.put("loginId", "JohnDoe");
    ThreadContext.put("ipAddress", "192.168.0.120");
    ThreadContext.put("locale", Locale.US.getDisplayName());
    final TransferMessage msg = new TransferMessage();
    msg.put("ToAccount", "123456");
    msg.put("FromAccount", "123457");
    msg.put("Amount", "200.00");
    EventLogger.logEvent(msg);
    msg.setCompletionStatus("Transfer Complete");
    EventLogger.logEvent(msg);
    ThreadContext.clearMap();
    // TODO: do something with the results

}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:XmlEvents.java

示例10: before

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
protected void before() throws Throwable {
    threadContextHolder = new ThreadContextHolder(restoreMap, restoreStack);
    if (restoreMap) {
        ThreadContext.clearMap();
    }
    if (restoreStack) {
        ThreadContext.clearStack();
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:11,代码来源:ThreadContextRule.java

示例11: setContextMap

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked") // nothing we can do about this, restricted by SLF4J API
public void setContextMap(@SuppressWarnings("rawtypes") final Map map) {
    ThreadContext.clearMap();
    for (final Map.Entry<String, String> entry : ((Map<String, String>) map).entrySet()) {
        ThreadContext.put(entry.getKey(), entry.getValue());
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:9,代码来源:Log4jMDCAdapter.java

示例12: mdc

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void mdc() {
    ThreadContext.put("TestYear", Integer.toString(2010));
    logger.debug("Debug message");
    ThreadContext.clearMap();
    logger.debug("Debug message");
    assertThat(list.strList, hasSize(2));
    assertTrue("Incorrect year", list.strList.get(0).startsWith("2010"));
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:11,代码来源:LoggerTest.java

示例13: mdc

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void mdc() {
    ThreadContext.put("TestYear", "2010");
    logger.debug("Debug message");
    ThreadContext.clearMap();
    logger.debug("Debug message");
    final List<LogEvent> events = app.getEvents();
    assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), 2, events.size());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:10,代码来源:StrictXmlConfigTest.java

示例14: structuredData

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
@Test
public void structuredData() {
    ThreadContext.put("loginId", "JohnDoe");
    ThreadContext.put("ipAddress", "192.168.0.120");
    ThreadContext.put("locale", Locale.US.getDisplayName());
    final StructuredDataMessage msg = new StructuredDataMessage("[email protected]", "Transfer Complete", "Transfer");
    msg.put("ToAccount", "123456");
    msg.put("FromAccount", "123457");
    msg.put("Amount", "200.00");
    logger.info(MarkerManager.getMarker("EVENT"), msg);
    ThreadContext.clearMap();
    final List<LogEvent> events = app.getEvents();
    assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:15,代码来源:StrictXmlConfigTest.java

示例15: clearAndPut

import org.apache.logging.log4j.ThreadContext; //导入方法依赖的package包/类
public void clearAndPut() {
    ThreadContext.clearMap();
    for (int i = 0; i < count; i++) {
        ThreadContext.put(keys[i], values[i]);
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:7,代码来源:ThreadContextBenchmark.java


注:本文中的org.apache.logging.log4j.ThreadContext.clearMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。