myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sobr...@apache.org
Subject svn commit: r711984 - in /myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config: GlobalConfiguratorImpl.java ThreadLocalResetter.java
Date Thu, 06 Nov 2008 21:44:21 GMT
Author: sobryan
Date: Thu Nov  6 13:44:17 2008
New Revision: 711984

URL: http://svn.apache.org/viewvc?rev=711984&view=rev
Log:
TRINIDAD-1287 - Threadlocal system does not clean up on init

* Took work done for TRINIDAD-1273 and applied a call to the cleanup
  code at the end of init and destroy.

Modified:
    myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
    myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ThreadLocalResetter.java

Modified: myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java?rev=711984&r1=711983&r2=711984&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
(original)
+++ myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/GlobalConfiguratorImpl.java
Thu Nov  6 13:44:17 2008
@@ -241,20 +241,28 @@
   {
     if (_initialized)
     {
-      for (final Configurator config : _services)
+      try
       {
-        try
+        for (final Configurator config : _services)
         {
-          config.destroy();
-        }
-        catch (final Throwable t)
-        {
-          // we always want to continue to destroy things, so log errors and continue
-          _LOG.severe(t);
+          try
+          {
+            config.destroy();
+          }
+          catch (final Throwable t)
+          {
+            // we always want to continue to destroy things, so log errors and continue
+            _LOG.severe(t);
+          }
         }
+        _services = null;
+        _initialized = false;
+      }
+      finally
+      {
+        //release any managed threadlocals that may have been used durring destroy
+        _releaseManagedThreadLocals();
       }
-      _services = null;
-      _initialized = false;
     }
   }
 
@@ -272,15 +280,21 @@
     {
       if (!_isDisabled(externalContext))
       {
-        final RequestType type = RequestType.getType(externalContext);
-
-        // Do not end services at the end of a portal action request
-        if (type != RequestType.PORTAL_ACTION)
+        try
         {
-          _endConfiguratorServiceRequest(externalContext);
+          final RequestType type = RequestType.getType(externalContext);
+  
+          // Do not end services at the end of a portal action request
+          if (type != RequestType.PORTAL_ACTION)
+          {
+            _endConfiguratorServiceRequest(externalContext);
+          }
+        }
+        finally
+        {
+          _releaseRequestContext(externalContext);
+          _releaseManagedThreadLocals();
         }
-
-        _releaseRequestContext(externalContext);
       }
       RequestType.clearType(externalContext);
     }
@@ -348,35 +362,44 @@
 
     if (!_initialized)
     {
-      _services = ClassLoaderUtils.getServices(Configurator.class.getName());
-
-      // Create a new RequestContextFactory is needed
-      if (RequestContextFactory.getFactory() == null)
+      try
       {
-        RequestContextFactory.setFactory(new RequestContextFactoryImpl());
-      }
-
-      // Create a new SkinFactory if needed.
-      if (SkinFactory.getFactory() == null)
-      {
-        SkinFactory.setFactory(new SkinFactoryImpl());
-      }
-
-      // register the base skins
-      SkinUtils.registerBaseSkins();
-
-      for (final Configurator config : _services)
-      {
-        config.init(externalContext);
+        _services = ClassLoaderUtils.getServices(Configurator.class.getName());
+  
+        // Create a new RequestContextFactory is needed
+        if (RequestContextFactory.getFactory() == null)
+        {
+          RequestContextFactory.setFactory(new RequestContextFactoryImpl());
+        }
+  
+        // Create a new SkinFactory if needed.
+        if (SkinFactory.getFactory() == null)
+        {
+          SkinFactory.setFactory(new SkinFactoryImpl());
+        }
+  
+        // register the base skins
+        SkinUtils.registerBaseSkins();
+  
+        for (final Configurator config : _services)
+        {
+          config.init(externalContext);
+        }
+  
+        // after the 'services' filters are initialized, then register
+        // the skin extensions found in trinidad-skins.xml. This
+        // gives a chance to the 'services' filters to create more base
+        // skins that the skins in trinidad-skins.xml can extend.
+        SkinUtils.registerSkinExtensions(externalContext);
+        _initialized = true;
+      }
+      finally
+      {
+        
+        //Do cleanup of anything which may have use the thread local manager durring
+        //init.
+        _releaseManagedThreadLocals();
       }
-
-      // after the 'services' filters are initialized, then register
-      // the skin extensions found in trinidad-skins.xml. This
-      // gives a chance to the 'services' filters to create more base
-      // skins that the skins in trinidad-skins.xml can extend.
-      SkinUtils.registerSkinExtensions(externalContext);
-
-      _initialized = true;
     }
     else
     {
@@ -416,12 +439,9 @@
         _LOG.warning("REQUESTCONTEXT_NOT_PROPERLY_RELEASED");
       }
       context.release();
-      ThreadLocalResetter resetter = _threadResetter.get();
-      
-      if (resetter != null)
-        resetter.__removeRequestThreadLocals();
+      _releaseManagedThreadLocals();
     }
-
+    
     // See if we've got a cached RequestContext instance; if so,
     // reattach it
     final Object cachedRequestContext = externalContext.getRequestMap().get(
@@ -460,15 +480,19 @@
       context.release();
       assert RequestContext.getCurrentInstance() == null;
 
-      // now that the request is over, clean up all of the request-scoped
-      // ThreadLocals.
-      ThreadLocalResetter resetter = _threadResetter.get();
-      
-      if (resetter != null)
-        resetter.__removeRequestThreadLocals();
     }
   }
 
+  private void _releaseManagedThreadLocals() 
+  {
+    ThreadLocalResetter resetter = _threadResetter.get();
+    
+    if (resetter != null)
+    {
+      resetter.__removeThreadLocals();
+    }
+  }
+  
   private void _endConfiguratorServiceRequest(final ExternalContext ec)
   {
     // Physical request has now ended

Modified: myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ThreadLocalResetter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ThreadLocalResetter.java?rev=711984&r1=711983&r2=711984&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ThreadLocalResetter.java
(original)
+++ myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/ThreadLocalResetter.java
Thu Nov  6 13:44:17 2008
@@ -20,7 +20,6 @@
 
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.apache.myfaces.trinidad.util.ThreadLocalUtils;
 import org.apache.myfaces.trinidad.util.ThreadLocalUtils.ThreadLocalLifecycle;
 import org.apache.myfaces.trinidad.util.ThreadLocalUtils.ThreadLocalManager;
 
@@ -60,7 +59,7 @@
    * Called by the GlobalConfiguratorImpl when the request is finished so that the
    * ThreadLocalResetter can ask the ThreadLocalManager to clean itself up
    */
-  void __removeRequestThreadLocals()
+  void __removeThreadLocals()
   {
     ThreadLocalManager threadLocalManager = _threadLocalManager.get();
     



Mime
View raw message