[jboss-cvs] JBossAS SVN: r72379 - in trunk/tomcat: src/main/org/jboss/web/tomcat/service/sso and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 17 14:59:25 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-04-17 14:59:25 -0400 (Thu, 17 Apr 2008)
New Revision: 72379

Modified:
   trunk/tomcat/.classpath
   trunk/tomcat/build.xml
   trunk/tomcat/pom.xml
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/ClusteredSingleSignOn.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/TreeCacheSSOClusterManager.java
Log:
[JBAS-5380] Convert ClusteredSingleSignOn to use CacheManager

Modified: trunk/tomcat/.classpath
===================================================================
--- trunk/tomcat/.classpath	2008-04-17 18:56:12 UTC (rev 72378)
+++ trunk/tomcat/.classpath	2008-04-17 18:59:25 UTC (rev 72379)
@@ -6,7 +6,8 @@
 	<classpathentry exported="true" kind="src" path="/aspects"/>
 	<classpathentry exported="true" kind="src" path="/connector"/>
 	<classpathentry exported="true" kind="src" path="/iiop"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry exported="true" kind="src" path="/cluster"/>
+   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry exported="true" kind="lib" path="/thirdparty/sun-servlet/lib/jsp-api.jar"/>
 	<classpathentry exported="true" kind="lib" path="/thirdparty/apache-logging/lib/commons-logging.jar"/>
 	<classpathentry exported="true" kind="lib" path="/thirdparty/jboss/cache/jbosscache-core/lib/jbosscache-core.jar" sourcepath="/thirdparty/jboss/cache/jbosscache-core/lib/jbosscache-core-sources.jar"/>

Modified: trunk/tomcat/build.xml
===================================================================
--- trunk/tomcat/build.xml	2008-04-17 18:56:12 UTC (rev 72378)
+++ trunk/tomcat/build.xml	2008-04-17 18:59:25 UTC (rev 72379)
@@ -330,8 +330,6 @@
          file="${build.lib}/jbossweb-cluster.aop"/>
    <copy tofile="${build.deploy}/cluster/jbossweb-cluster-beans.xml"
          file="${build.resources}/jbossweb-cluster-beans.xml"/>
-   <copy tofile="${build.deploy}/cluster/jbossweb-clusteredsso-beans.xml"
-         file="${build.resources}/jbossweb-clusteredsso-beans.xml"/>
 
     <!-- Update the build marker to allow bypassing -->
     <touch file="${build-bypass.marker}"/>

Modified: trunk/tomcat/pom.xml
===================================================================
--- trunk/tomcat/pom.xml	2008-04-17 18:56:12 UTC (rev 72378)
+++ trunk/tomcat/pom.xml	2008-04-17 18:59:25 UTC (rev 72379)
@@ -197,6 +197,10 @@
     </dependency>
     <dependency>
       <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-as-cluster</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
       <artifactId>jboss-as-iiop</artifactId>
     </dependency>
     <dependency>

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/ClusteredSingleSignOn.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/ClusteredSingleSignOn.java	2008-04-17 18:56:12 UTC (rev 72378)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/ClusteredSingleSignOn.java	2008-04-17 18:59:25 UTC (rev 72379)
@@ -47,7 +47,7 @@
 /**
  * A <strong>Valve</strong> that supports a "single sign on" user experience,
  * where the security identity of a user who successfully authenticates to one
- * web application is propogated to other web applications in the same
+ * web application is propagated to other web applications in the same
  * security domain.  For successful use, the following requirements must
  * be met:
  * <ul>
@@ -73,7 +73,8 @@
    /** By default we let SSOs without active sessions live for 30 mins */
    public static final int DEFAULT_MAX_EMPTY_LIFE = 1800;
    /** The default JBoss Cache to use for storing SSO entries */
-   public static final String DEFAULT_CACHE_NAME = "jboss.cache:service=ClusteredSSOCache";
+   public static final String DEFAULT_CACHE_NAME = "clustered-sso";
+   public static final String LEGACY_CACHE_NAME = "jboss.cache:service=TomcatClusteringCache";
       
    // Override the superclass value
    static

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-17 18:56:12 UTC (rev 72378)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/sso/TreeCacheSSOClusterManager.java	2008-04-17 18:59:25 UTC (rev 72379)
@@ -32,6 +32,7 @@
 import javax.management.MBeanAttributeInfo;
 import javax.management.MBeanInfo;
 import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import javax.transaction.Status;
 import javax.transaction.TransactionManager;
@@ -41,6 +42,7 @@
 import org.apache.catalina.Session;
 import org.apache.catalina.util.LifecycleSupport;
 import org.jboss.cache.Cache;
+import org.jboss.cache.CacheStatus;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.Node;
@@ -56,6 +58,8 @@
 import org.jboss.cache.notifications.event.NodeRemovedEvent;
 import org.jboss.cache.notifications.event.ViewChangedEvent;
 import org.jboss.cache.pojo.PojoCache;
+import org.jboss.ha.cachemanager.CacheManagerLocator;
+import org.jboss.ha.cachemanager.PojoCacheManager;
 import org.jboss.logging.Logger;
 import org.jboss.mx.util.MBeanServerLocator;
 import org.jboss.util.NestedRuntimeException;
@@ -127,14 +131,14 @@
    private ThreadLocal<String> beingRemotelyRemoved = new ThreadLocal<String>();
 
    /**
-    * ObjectName of the TreeCache
+    * String name to use to access the TreeCache
     */
-   private ObjectName cacheObjectName = null;
+   private String cacheName = null;
 
    /**
-    * String version of the object name to use to access the TreeCache
+    * ObjectName of the TreeCache if legacy JMX integration is used
     */
-   private String cacheName = null;
+   private ObjectName cacheObjectName = null;
    
    /**
     * The cache itself.
@@ -233,42 +237,17 @@
       return cacheName;
    }
 
-   public void setCacheName(String objectName)
+   public void setCacheName(String configName)
       throws Exception
    {
-      if (objectName == null)
-      {
-         setCacheObjectName(null);
-      }
-      else if (objectName.equals(cacheName) == false)
-      {
-         setCacheObjectName(new ObjectName(objectName));
-      }
-   }
-
-   public ObjectName getCacheObjectName()
-   {
-      return cacheObjectName;
-   }
-
-   public void setCacheObjectName(ObjectName objectName)
-      throws Exception
-   {
-      // If no change, do nothing
-      if ((objectName != null && objectName.equals(cacheObjectName))
-         || (cacheObjectName != null && cacheObjectName.equals(objectName))
-         || (objectName == null && cacheObjectName == null))
-      {
+      if (configName == cacheName ||
+            (cacheName != null  && cacheName.equals(configName)))
          return;
-      }
 
       removeAsCacheListener();
       this.tm = null;
       
-      this.cacheObjectName = objectName;
-      this.cacheName = (objectName == null
-         ? null
-         : objectName.getCanonicalName());
+      this.cacheName = configName;
 
       if (false == isTreeCacheAvailable(true))
       {
@@ -954,8 +933,10 @@
       }
       catch (Exception e)
       {
-         throw new LifecycleException("Caught exception looking up " +
-                                      "TransactionManager from TreeCache", e);
+         // LifecycleException doesn't use normal exception chaining, so
+         // log the real problem here so we can sii what it is
+         log.error("Caught exception integrating with JBoss Cache", e);
+         throw new LifecycleException("Caught exception integrating with JBoss Cache", e);
       }
       
       started = true;
@@ -1206,11 +1187,43 @@
    {
       if (forceCheck || treeCacheAvailable == false)
       {
-         boolean available = (cacheObjectName != null);
+         boolean available = (cacheName != null);
          if (available)
-         {
-            Set s = server.queryMBeans(cacheObjectName, null);
-            available = s.size() > 0;
+         {       
+            try
+            {
+               PojoCacheManager pcm = CacheManagerLocator.getCacheManagerLocator().getCacheManager(null);
+               available = pcm.getConfigurationNames().contains(cacheName);
+            }
+            catch (IllegalStateException ise)
+            {
+               log.debug("No CacheManager available");
+            }
+            
+            if (!available && cacheName.indexOf(':') > -1)
+            {
+               // See if there is a legacy JMX binding
+               String onameStr = cacheName;
+               if (ClusteredSingleSignOn.DEFAULT_CACHE_NAME.equals(cacheName))
+                  onameStr = ClusteredSingleSignOn.LEGACY_CACHE_NAME;
+               try
+               {
+                  ObjectName oname = new ObjectName(onameStr);
+                  Set s = server.queryMBeans(oname, null);
+                  if (s.size() > 0)
+                  {
+                     available = true;
+                     // Save the object name to tell integrateWithCache to use JMX
+                     cacheObjectName = oname;
+                     cacheName = onameStr;
+                  }
+               }
+               catch (Exception e)
+               {
+                  // no jmx
+               }
+            }
+            
             if (available)
             {
                try
@@ -1227,7 +1240,7 @@
                catch (Exception e)
                {
                   log.error("Caught exception configuring from cache " +
-                            cacheObjectName, e);
+                            cacheName, e);
                   available = false;
                }
             }
@@ -1255,22 +1268,41 @@
       if (cache == null)
       {
          // Determine if our cache is a PojoCache or a plain Cache
-         MBeanInfo info = server.getMBeanInfo(getCacheObjectName());
-         MBeanAttributeInfo[] attrs = info.getAttributes();
-         for (MBeanAttributeInfo attr : attrs)
+         if (cacheObjectName == null)
          {
-            if ("PojoCache".equals(attr.getName()))
+            PojoCacheManager pcm = CacheManagerLocator.getCacheManagerLocator().getCacheManager(null);
+            if (pcm.getPojoCacheNames().contains(cacheName))
             {
-               cache = ((PojoCache) server.getAttribute(getCacheObjectName(), "PojoCache")).getCache();
-               break;
+               cache = pcm.getPojoCache(cacheName, true).getCache();
             }
-            else if ("Cache".equals(attr.getName()))
+            else
             {
-               cache = (Cache) server.getAttribute(getCacheObjectName(), "Cache");
-               break;
+               cache = pcm.getCache(cacheName, true);
             }
          }
+         else
+         {            
+            // 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;
+               }
+            }
+         }
          
+         if (cache.getCacheStatus() != CacheStatus.STARTED)
+            cache.start();
+         
          // Ensure we have a transaction manager and a cluster-wide unique address
          configureFromCache();
          
@@ -1282,7 +1314,7 @@
          // Scan for any SSOs with no entries; mark them for expiration
          launchSSOCleaner(true);
          
-         log.debug("Successfully integrated with cache service " + cacheObjectName);
+         log.debug("Successfully integrated with cache service " + cacheName);
       }
    }
 




More information about the jboss-cvs-commits mailing list