You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by jw...@apache.org on 2006/10/04 19:33:48 UTC

svn commit: r452986 - /incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java

Author: jwaldman
Date: Wed Oct  4 12:33:47 2006
New Revision: 452986

URL: http://svn.apache.org/viewvc?view=rev&rev=452986
Log:
ADFFACES-194 better help for RequestContext was already released or never attached or added twice. Committed for Arjuna

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java

Modified: incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java?view=diff&rev=452986&r1=452985&r2=452986
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/RequestContext.java Wed Oct  4 12:33:47 2006
@@ -26,6 +26,7 @@
 
 import org.apache.myfaces.trinidad.change.ChangeManager;
 import org.apache.myfaces.trinidad.config.RegionManager;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.webapp.UploadedFileProcessor;
 
 /**
@@ -421,10 +422,17 @@
    */
   public void release()
   {
+    if (_LOG.isFinest())
+    {
+      _LOG.finest("RequestContext released.", 
+                  new RuntimeException("This is not an error. This trace is for debugging."));
+    }
+    
     Object o = _CURRENT_CONTEXT.get();
     if (o == null)
-      throw new IllegalStateException("RequestContext was already released or " +
-                                      "had never been attached.");
+      throw new IllegalStateException(
+              _addHelp("RequestContext was already released or " +
+                       "had never been attached."));
     if (o != this)
       throw new IllegalStateException("Trying to release a different " +
                      "RequestContext than the current context.");
@@ -440,14 +448,34 @@
    */
   public void attach()
   {
+    if (_LOG.isFinest())
+    {
+      _LOG.finest("RequestContext attached.", 
+                  new RuntimeException("This is not an error. This trace is for debugging."));
+    }
+
     Object o = _CURRENT_CONTEXT.get();
     if (o != null)
-      throw new IllegalStateException("Trying to attach RequestContext to a " +
-                                      "thread that already had one.");
+    {
+      throw new IllegalStateException(
+              _addHelp("Trying to attach RequestContext to a " +
+                       "thread that already had one."));
+    }
     _CURRENT_CONTEXT.set(this);
   }
+  
+  private static String _addHelp(String error)
+  {
+    if (!_LOG.isFinest())
+    {
+      error += " To enable stack traces of each RequestContext attach/release call," +
+        " enable Level.FINEST logging for the "+RequestContext.class;
+    }
+    return error;
+  }
 
   static private final ThreadLocal<RequestContext> _CURRENT_CONTEXT = 
     new ThreadLocal<RequestContext>();
-  
+  static private final TrinidadLogger _LOG =
+    TrinidadLogger.createTrinidadLogger(RequestContext.class);
 }