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


Java ThreadContext类代码示例

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


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

示例1: complete

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void complete(final Channel channel, final O ioTask) {

	ThreadContext.put(KEY_CLASS_NAME, CLS_NAME);
	ThreadContext.put(KEY_TEST_STEP_ID, stepId);

	try {
		ioTask.finishResponse();
	} catch(final IllegalStateException e) {
		LogUtil.exception(Level.DEBUG, e, "{}: invalid I/O task state", ioTask.toString());
	}
	if(channel != null) {
		connPool.release(channel);
	}
	ioTaskCompleted(ioTask);
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:17,代码来源:NetStorageDriverBase.java

示例2: invoke

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void invoke(Event event)
{
    if (GETCONTEXT)
        ThreadContext.put("mod", owner == null ? "" : owner.getName());
    if (handler != null)
    {
        if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
        {
            if (filter == null || filter == ((IGenericEvent)event).getGenericType())
            {
                handler.invoke(event);
            }
        }
    }
    if (GETCONTEXT)
        ThreadContext.remove("mod");
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:20,代码来源:ASMEventHandler.java

示例3: LoggingApp

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

        ThreadContext.clear();

        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:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:LoggingApp.java

示例4: resolve

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public JsonNode resolve(TemplateResolverContext context, LogEvent logEvent, String key) {
    ThreadContext.ContextStack contextStack = logEvent.getContextStack();
    if (contextStack.getDepth() == 0) {
        return null;
    }
    Pattern itemPattern = context.getNdcPattern();
    ArrayNode contextStackNode = context.getObjectMapper().createArrayNode();
    for (String contextStackItem : contextStack.asList()) {
        boolean matches = itemPattern == null || itemPattern.matcher(contextStackItem).matches();
        if (matches) {
            contextStackNode.add(contextStackItem);
        }
    }
    return contextStackNode;
}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:17,代码来源:ContextStackResolver.java

示例5: invoke

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void invoke(Event event)
{
    if (owner != null && GETCONTEXT)
    {
        ThreadContext.put("mod", owner.getName());
    }
    else if (GETCONTEXT)
    {
        ThreadContext.put("mod", "");
    }
    if (handler != null)
    {
        if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
        {
            handler.invoke(event);
        }
    }
    if (GETCONTEXT)
        ThreadContext.remove("mod");
}
 
开发者ID:SchrodingersSpy,项目名称:TRHS_Club_Mod_2016,代码行数:22,代码来源:ASMEventHandler.java

示例6: 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

示例7: doFilter

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
		throws IOException, ServletException {
	String id = UUID.randomUUID().toString();
	ThreadContext.put("id", id);
	try {
		HttpServletResponse resp = (HttpServletResponse) response;
		resp.setHeader("Log-ID", id);
		chain.doFilter(request, response);
	} catch (Throwable e) {
		logger.error("error", e);
	} finally {
		ThreadContext.remove("id");
		ThreadContext.remove("username");
	}

}
 
开发者ID:shilongdai,项目名称:bookManager,代码行数:18,代码来源:PreSescLoggingFilter.java

示例8: clear

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static void clear() {
    // CB ThreadLocals
    MethodInterceptorContext.cleanupThread();
    AppRegistry.cleanupThread();
    MessageBus.cleanupThread();
    GeemoduleRegistry.cleanupThread();

    // Clear Log4j which is causing memory leaks
    ThreadContext.clearAll();

    // Also clear this one to be on the safe side
    MDC.clear();

    Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
    Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);

    for (Thread t : threadArray) {
        if (t.getName().contains("Abandoned connection cleanup thread")
            || t.getName().matches("com\\.google.*Finalizer")) {
            synchronized (t) {
                t.stop();
            }
        }
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:27,代码来源:ThreadClearer.java

示例9: initMerchantLogger

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
protected void initMerchantLogger() {
    ApplicationContext appCtx = App.get().context();

    Merchant merchant = appCtx.getMerchant();
    Store store = appCtx.getStore();

    String logPath = merchant.getLogPath();
    // Log4j does not like backslashes in directory path.
    logPath = logPath.replace(Char.BACKSLASH, Char.SLASH);

    ThreadContext.put("log.route.name", "CB-App-Rolling-Log");
    ThreadContext.put("log.path", logPath);
    ThreadContext.put("appctx.merchant", merchant.getCompanyName());
    ThreadContext.put("appctx.store", store.getName());

    log = LogManager.getLogger(getClass());
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:18,代码来源:ApplicationInitFilter.java

示例10: doFilterInternal

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void doFilterInternal(final HttpServletRequest request,
        final HttpServletResponse response, final FilterChain fc)
        throws IOException, ServletException {
    String allowedMtds = (RequestMethod.GET.name() + "," + 
            RequestMethod.POST.name() + "," + RequestMethod.PATCH.name());
    response.setHeader(HttpHeaders.SERVER, "FAIR data point (JAVA)");
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, 
            HttpHeaders.CONTENT_TYPE);
    response.setHeader(HttpHeaders.ALLOW, allowedMtds);
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS,
            (HttpHeaders.ACCEPT));
    ThreadContext.put("ipAddress", request.getRemoteAddr());
    ThreadContext.put("responseStatus", String.valueOf(
            response.getStatus()));
    fc.doFilter(request, response);
    ThreadContext.clearAll();
}
 
开发者ID:DTL-FAIRData,项目名称:FAIRDataPoint,代码行数:20,代码来源:ApplicationFilter.java

示例11: testName

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Test
public void testName() throws Exception {
    // Log in Main Thread
    logger.info("Log in main!");

    final ExecutorService executorService = Executors.newFixedThreadPool(2);

    // Run task in thread pool
    executorService.submit(createTask()).get();

    // Init Log Context, set TTL
    // More KV if needed
    final String TRACE_ID = "trace-id";
    final String TRACE_ID_VALUE = "XXX-YYY-ZZZ";
    ThreadContext.put(TRACE_ID, TRACE_ID_VALUE);

    // Log in Main Thread
    logger.info("Log in main!");
    executorService.submit(createTask()).get();

    logger.info("Exit main");
    executorService.shutdown();
}
 
开发者ID:oldratlee,项目名称:log4j2-ttl-thread-context-map,代码行数:24,代码来源:TtlThreadContextMapTest.java

示例12: invoke

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
@Override
public void invoke(Event event)
{
    if (owner != null)
    {
        ThreadContext.put("mod", owner.getName());
    }
    else
    {
        ThreadContext.put("mod", "");
    }
    if (handler != null)
    {
        if (!event.isCancelable() || !event.isCanceled() || subInfo.receiveCanceled())
        {
            handler.invoke(event);
        }
    }
    ThreadContext.remove("mod");
}
 
开发者ID:alexandrage,项目名称:CauldronGit,代码行数:21,代码来源:ASMEventHandler.java

示例13: setThreadLoggingContext

import org.apache.logging.log4j.ThreadContext; //导入依赖的package包/类
private void setThreadLoggingContext(Message msg) {
    ThreadContext.clearAll();

    if (msg instanceof APIMessage) {
        ThreadContext.put(Constants.THREAD_CONTEXT_API, msg.getId());
        ThreadContext.put(Constants.THREAD_CONTEXT_TASK_NAME, msg.getClass().getName());
    } else {
        Map<String, String> ctx = msg.getHeaderEntry(TASK_CONTEXT);
        if (ctx != null) {
            ThreadContext.putAll(ctx);
        }
    }

    if (msg.getHeaders().containsKey(TASK_STACK)) {
        List<String> taskStack = msg.getHeaderEntry(TASK_STACK);
        ThreadContext.setStack(taskStack);
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:19,代码来源:CloudBusImpl2.java

示例14: 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

示例15: 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


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