[jboss-cvs] JBossAS SVN: r72465 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Apr 19 23:30:04 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-04-19 23:30:04 -0400 (Sat, 19 Apr 2008)
New Revision: 72465

Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/TreeCacheSSOClusterManager.java
Log:
[JBAS-5380] Don't leak TCCL to cache/jgroups

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/TreeCacheSSOClusterManager.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/TreeCacheSSOClusterManager.java	2008-04-20 02:10:57 UTC (rev 72464)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/TreeCacheSSOClusterManager.java	2008-04-20 03:30:04 UTC (rev 72465)
@@ -22,6 +22,7 @@
 package org.jboss.web.tomcat.service.sso;
 
 import java.io.Serializable;
+import java.security.AccessController;
 import java.security.Principal;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -62,6 +63,7 @@
 import org.jboss.logging.Logger;
 import org.jboss.mx.util.MBeanServerLocator;
 import org.jboss.util.NestedRuntimeException;
+import org.jboss.util.loading.ContextClassLoaderSwitcher;
 import org.jboss.util.threadpool.ThreadPool;
 
 /**
@@ -1261,47 +1263,59 @@
    {
       if (cache == null)
       {
-         // Determine if our cache is a PojoCache or a plain Cache
-         if (cacheObjectName == null)
-         {
-            PojoCacheManager pcm = CacheManagerLocator.getCacheManagerLocator().getCacheManager(null);
-            if (pcm.getPojoCacheNames().contains(cacheName))
+         // We are likely going to cause creation and start of a cache here;
+         // we don't want to leak the TCCL to cache/jgroups threads, so
+         // we switch it to our classloader
+         ContextClassLoaderSwitcher switcher = (ContextClassLoaderSwitcher) AccessController.doPrivileged(ContextClassLoaderSwitcher.INSTANTIATOR);
+         ContextClassLoaderSwitcher.SwitchContext switchContext = switcher.getSwitchContext(getClass().getClassLoader());
+         try
+         {// Determine if our cache is a PojoCache or a plain Cache
+            if (cacheObjectName == null)
             {
-               cache = pcm.getPojoCache(cacheName, true).getCache();
-            }
-            else
-            {
-               cache = pcm.getCache(cacheName, true);
-            }
-         }
-         else if (server != null)
-         {            
-            // Look in JMX
-            MBeanInfo info = server.getMBeanInfo(cacheObjectName);
-            MBeanAttributeInfo[] attrs = info.getAttributes();
-            for (MBeanAttributeInfo attr : attrs)
-            {
-               if ("PojoCache".equals(attr.getName()))
+               PojoCacheManager pcm = CacheManagerLocator.getCacheManagerLocator().getCacheManager(null);
+               if (pcm.getPojoCacheNames().contains(cacheName))
                {
-                  cache = ((PojoCache) server.getAttribute(cacheObjectName, "PojoCache")).getCache();
-                  break;
+                  cache = pcm.getPojoCache(cacheName, true).getCache();
                }
-               else if ("Cache".equals(attr.getName()))
+               else
                {
-                  cache = (Cache) server.getAttribute(cacheObjectName, "Cache");
-                  break;
+                  cache = pcm.getCache(cacheName, true);
                }
             }
+            else if (server != null)
+            {            
+               // Look in JMX
+               MBeanInfo info = server.getMBeanInfo(cacheObjectName);
+               MBeanAttributeInfo[] attrs = info.getAttributes();
+               for (MBeanAttributeInfo attr : attrs)
+               {
+                  if ("PojoCache".equals(attr.getName()))
+                  {
+                     cache = ((PojoCache) server.getAttribute(cacheObjectName, "PojoCache")).getCache();
+                     break;
+                  }
+                  else if ("Cache".equals(attr.getName()))
+                  {
+                     cache = (Cache) server.getAttribute(cacheObjectName, "Cache");
+                     break;
+                  }
+               }
+            }
+            else
+            {
+               // Shouldn't be possible or isTreeCacheAvailable would return false
+               throw new IllegalStateException("No JBoss Cache available under name " + cacheName);
+            }
+            
+            if (cache.getCacheStatus() != CacheStatus.STARTED)
+               cache.start();
          }
-         else
+         finally
          {
-            // Shouldn't be possible or isTreeCacheAvailable would return false
-            throw new IllegalStateException("No JBoss Cache available under name " + cacheName);
+            // Restore the TCCL
+            switchContext.reset();
          }
          
-         if (cache.getCacheStatus() != CacheStatus.STARTED)
-            cache.start();
-         
          // Ensure we have a transaction manager and a cluster-wide unique address
          configureFromCache();
          
@@ -1323,7 +1337,7 @@
     * region may not be active, so here we ensure it is.
     * 
     * @throws Exception
-    */
+    */   
    private void activateCacheRegion() throws Exception
    {
       if (cache.getConfiguration().isInactiveOnStartup())




More information about the jboss-cvs-commits mailing list