예제 #1
0
  public static CallContext unregister() {
    CallContext context = s_currentContext.get();
    if (context == null) {
      return null;
    }
    s_currentContext.remove();
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("Unregistered: " + context);
    }
    String contextId = context.getContextId();
    String sessionIdOnStack = null;
    String sessionIdPushedToNDC = "ctx-" + UuidUtils.first(contextId);
    while ((sessionIdOnStack = NDC.pop()) != null) {
      if (sessionIdPushedToNDC.equals(sessionIdOnStack)) {
        break;
      }
      if (s_logger.isTraceEnabled()) {
        s_logger.trace("Popping from NDC: " + contextId);
      }
    }

    Stack<CallContext> stack = s_currentContextStack.get();
    stack.pop();

    if (!stack.isEmpty()) {
      s_currentContext.set(stack.peek());
    }

    return context;
  }
예제 #2
0
  /**
   * This method should only be called if you can propagate the context id from another CallContext.
   *
   * @param callingUser calling user
   * @param callingAccount calling account
   * @param contextId context id propagated from another call context
   * @return CallContext
   */
  public static CallContext register(User callingUser, Account callingAccount, 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 = new CallContext(callingUser, callingAccount, contextId);
    s_currentContext.set(callingContext);
    NDC.push("ctx-" + UuidUtils.first(contextId));
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("Registered: " + callingContext);
    }

    s_currentContextStack.get().push(callingContext);

    return callingContext;
  }
예제 #3
0
 @Override
 public String getShortUuid() {
   return UuidUtils.first(uuid);
 }