public static LogContext current() { LogContext context = s_currentContext.get(); if (context == null) { context = registerSystemLogContextOnceOnly(); } return context; }
public static CallContext current() { CallContext context = s_currentContext.get(); // TODO other than async job and api dispatches, there are many system background running threads // that do not setup CallContext at all, however, many places in code that are touched by these background tasks // assume not-null CallContext. Following is a fix to address therefore caused NPE problems // // There are security implications with this. It assumes that all system background running threads are // indeed have no problem in running under system context. // if (context == null) { context = registerSystemCallContextOnceOnly(); } return context; }
public static CallContext registerPlaceHolderContext() { final CallContext context = new CallContext(0, 0, UUID.randomUUID().toString()); s_currentContext.set(context); s_currentContextStack.get().push(context); return context; }
public static void unregister() { final LogContext context = s_currentContext.get(); if (context != null) { s_currentContext.remove(); if (s_logger.isTraceEnabled()) { s_logger.trace("Unregistered: " + context); } } MDC.clear(); }
public static CallContext unregister() { final CallContext context = s_currentContext.get(); if (context == null) { return null; } s_currentContext.remove(); if (s_logger.isTraceEnabled()) { s_logger.trace("Unregistered: " + context); } MDC.remove("ctx"); final Stack<CallContext> stack = s_currentContextStack.get(); stack.pop(); if (!stack.isEmpty()) { s_currentContext.set(stack.peek()); } else { s_currentContext.set(null); } return context; }
public static LogContext registerSystemLogContextOnceOnly() { try { final LogContext context = s_currentContext.get(); if (context == null) { return register(null, null, User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, UUID.randomUUID().toString()); } assert context.getCallingUserId() == User.UID_SYSTEM : "You are calling a very specific method that registers a one time system context. This method is meant for " + "background threads that does processing."; return context; } catch (final Exception e) { s_logger.error("Failed to register the system log context.", e); throw new CloudRuntimeException("Failed to register system log context", e); } }
public static CallContext registerSystemCallContextOnceOnly() { try { final CallContext context = s_currentContext.get(); if (context == null) { return register(null, null, User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, UUID.randomUUID().toString()); } assert context.getCallingUserId() == User.UID_SYSTEM : "You are calling a very specific method that registers a one time system context. This method is meant for " + "background threads that does processing."; return context; } catch (final Exception e) { s_logger.error("Failed to register the system call context.", e); throw new CloudRuntimeException("Failed to register system call context", e); } }
protected static CallContext register(final User callingUser, final Account callingAccount, final Long userId, final Long accountId, final String contextId) { /* Unit tests will have multiple times of setup/tear-down call to this, remove assertions to all unit test to run assert s_currentContext.get() == null : "There's a context already so what does this new register context mean? " + s_currentContext.get().toString(); if (s_currentContext.get() != null) { // FIXME: This should be removed soon. I added this check only to surface all the places that have this problem. throw new CloudRuntimeException("There's a context already so what does this new register context mean? " + s_currentContext.get().toString()); } */ CallContext callingContext = null; if (userId == null || accountId == null) { callingContext = new CallContext(callingUser, callingAccount, contextId); } else { callingContext = new CallContext(userId, accountId, contextId); } s_currentContext.set(callingContext); MDC.put("ctx", " (ctx: " + UuidUtils.first(contextId) + ")"); if (s_logger.isTraceEnabled()) { s_logger.trace("Registered: " + callingContext); } s_currentContextStack.get().push(callingContext); return callingContext; }