diff --git a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/RequestContext.java b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/RequestContext.java index c7b3e07684739..23395be5b3575 100644 --- a/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/RequestContext.java +++ b/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/RequestContext.java @@ -31,7 +31,7 @@ */ class RequestContext implements ManagedContext { - private static final Logger LOGGER = Logger.getLogger(RequestContext.class.getPackage().getName()); + private static final Logger LOG = Logger.getLogger(RequestContext.class.getPackage().getName()); private final CurrentContext currentContext; @@ -39,11 +39,15 @@ class RequestContext implements ManagedContext { private final LazyValue> beforeDestroyedNotifier; private final LazyValue> destroyedNotifier; + private final boolean debugEnabled; + public RequestContext(CurrentContext currentContext) { this.currentContext = currentContext; this.initializedNotifier = new LazyValue<>(RequestContext::createInitializedNotifier); this.beforeDestroyedNotifier = new LazyValue<>(RequestContext::createBeforeDestroyedNotifier); this.destroyedNotifier = new LazyValue<>(RequestContext::createDestroyedNotifier); + // we do not need to check the effective log level + this.debugEnabled = LOG.isDebugEnabled(); } @Override @@ -122,6 +126,15 @@ public void destroy(Contextual contextual) { @Override public void activate(ContextState initialState) { + if (debugEnabled) { + String stack = Arrays.stream(Thread.currentThread().getStackTrace()) + .skip(2) + .limit(7) + .map(se -> "\n\t" + se.toString()) + .collect(Collectors.joining()); + LOG.debugf("Activate %s %s\n\t...", + initialState != null ? Integer.toHexString(initialState.hashCode()) : "new", stack); + } if (initialState == null) { currentContext.set(new RequestContextState(new ConcurrentHashMap<>())); // Fire an event with qualifier @Initialized(RequestScoped.class) if there are any observers for it @@ -151,6 +164,14 @@ public ContextState getStateIfActive() { @Override public void deactivate() { + if (debugEnabled) { + String stack = Arrays.stream(Thread.currentThread().getStackTrace()) + .skip(2) + .limit(7) + .map(se -> "\n\t" + se.toString()) + .collect(Collectors.joining()); + LOG.debugf("Deactivate%s\n\t...", stack); + } currentContext.remove(); } @@ -161,6 +182,14 @@ public void destroy() { @Override public void destroy(ContextState state) { + if (debugEnabled) { + String stack = Arrays.stream(Thread.currentThread().getStackTrace()) + .skip(2) + .limit(7) + .map(se -> "\n\t" + se.toString()) + .collect(Collectors.joining()); + LOG.debugf("Destroy %s%s\n\t...", state != null ? Integer.toHexString(state.hashCode()) : "", stack); + } if (state == null) { // nothing to destroy return; @@ -174,7 +203,7 @@ public void destroy(ContextState state) { try { fireIfNotEmpty(beforeDestroyedNotifier); } catch (Exception e) { - LOGGER.warn("An error occurred during delivery of the @BeforeDestroyed(RequestScoped.class) event", e); + LOG.warn("An error occurred during delivery of the @BeforeDestroyed(RequestScoped.class) event", e); } //Performance: avoid an iterator on the map elements map.forEach(this::destroyContextElement); @@ -182,7 +211,7 @@ public void destroy(ContextState state) { try { fireIfNotEmpty(destroyedNotifier); } catch (Exception e) { - LOGGER.warn("An error occurred during delivery of the @Destroyed(RequestScoped.class) event", e); + LOG.warn("An error occurred during delivery of the @Destroyed(RequestScoped.class) event", e); } map.clear(); }