[seam-commits] Seam SVN: r8753 - in trunk: build and 7 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Aug 20 14:26:02 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-08-20 14:26:02 -0400 (Wed, 20 Aug 2008)
New Revision: 8753

Added:
   trunk/src/main/org/jboss/seam/cache-2.1.xsd
   trunk/src/main/org/jboss/seam/cache/
   trunk/src/main/org/jboss/seam/cache/AbstractJBossCacheProvider.java
   trunk/src/main/org/jboss/seam/cache/CacheProvider.java
   trunk/src/main/org/jboss/seam/cache/EhCacheProvider.java
   trunk/src/main/org/jboss/seam/cache/JbossCache2Provider.java
   trunk/src/main/org/jboss/seam/cache/JbossCacheProvider.java
   trunk/src/main/org/jboss/seam/cache/JbossPojoCacheProvider.java
   trunk/src/main/org/jboss/seam/cache/package-info.java
Removed:
   trunk/src/main/org/jboss/seam/core/PojoCache.java
Modified:
   trunk/build.xml
   trunk/build/core.pom.xml
   trunk/build/root.pom.xml
   trunk/build/ui.pom.xml
   trunk/build/utilities.build.xml
   trunk/src/main/org/jboss/seam/init/Initialization.java
   trunk/ui/src/main/config/component/cache.xml
   trunk/ui/src/main/java/org/jboss/seam/ui/component/UICache.java
   trunk/ui/src/main/java/org/jboss/seam/ui/renderkit/CacheRendererBase.java
Log:
JBSEAM-1891

Modified: trunk/build/core.pom.xml
===================================================================
--- trunk/build/core.pom.xml	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/build/core.pom.xml	2008-08-20 18:26:02 UTC (rev 8753)
@@ -175,12 +175,28 @@
       <optional>true</optional>
     </dependency>
 
+   <dependency>
+	  <groupId>net.sf.ehcache</groupId>
+      <artifactId>ehcache</artifactId>
+      <optional>true</optional>
+    </dependency>
+
+    <!-- Order matters of jboss:jboss-cache and org.jboss.cache:jbosscache-core -->
+
     <dependency>
       <groupId>jboss</groupId>
       <artifactId>jboss-cache</artifactId>
       <optional>true</optional>
     </dependency>
+        
+    <dependency>
+      <groupId>org.jboss.cache</groupId>
+      <artifactId>jbosscache-core</artifactId>
+      <optional>true</optional>
+    </dependency>
     
+
+    
     <!-- This is actually a dep of jboss-cache, but it doesn't declare it -->
     <dependency>
       <groupId>jboss</groupId>

Modified: trunk/build/root.pom.xml
===================================================================
--- trunk/build/root.pom.xml	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/build/root.pom.xml	2008-08-20 18:26:02 UTC (rev 8753)
@@ -240,6 +240,25 @@
         <artifactId>jboss-cache</artifactId>
         <version>1.4.1.SP9</version>
       </dependency>
+      
+      <dependency>
+        <groupId>net.sf.ehcache</groupId>
+        <artifactId>ehcache</artifactId>
+        <version>1.2.3</version>
+        <exclusions>
+          <exclusion>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+    
+      <!-- You should adjust this in the initcore task in build.xml as well -->
+      <dependency>
+        <groupId>org.jboss.cache</groupId>
+        <artifactId>jbosscache-core</artifactId>
+        <version>2.2.0.CR6</version>
+      </dependency>
 
       <dependency>
         <groupId>jgroups</groupId>

Modified: trunk/build/ui.pom.xml
===================================================================
--- trunk/build/ui.pom.xml	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/build/ui.pom.xml	2008-08-20 18:26:02 UTC (rev 8753)
@@ -121,12 +121,6 @@
         </exclusion>
       </exclusions>
     </dependency>
-
-    <dependency>
-      <groupId>jboss</groupId>
-      <artifactId>jboss-cache</artifactId>
-      <optional>true</optional>
-    </dependency>
     
     <!-- This is actually a dep of jboss-cache, but it doesn't declare it -->
     <dependency>

Modified: trunk/build/utilities.build.xml
===================================================================
--- trunk/build/utilities.build.xml	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/build/utilities.build.xml	2008-08-20 18:26:02 UTC (rev 8753)
@@ -30,8 +30,10 @@
 		<attribute name="id" />
 		<attribute name="scope" />
 		<attribute name="pom" />
+		<element name="nested" implicit="true" optional="true" />
 		<sequential>
 			<artifact:dependencies pathId="@{scope}.@{id}.path" filesetId="@{scope}.@{id}.fileset" versionsId="@{scope}.@{id}.versions" useScope="@{scope}" settingsFile="${maven.settings.xml}">
+				<nested />
 				<pom file="@{pom}" settingsFile="${maven.settings.xml}" />
 			</artifact:dependencies>
 		</sequential>

Modified: trunk/build.xml
===================================================================
--- trunk/build.xml	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/build.xml	2008-08-20 18:26:02 UTC (rev 8753)
@@ -173,6 +173,9 @@
 
 	<target name="initcore" depends="init">
 		<init classesdir="${classes.core.dir}" srcdir="${src.core.dir}" modulename="core" pom="${core.pom}" />
+		<inlineDependencies id="jbosscache2" scope="compile">
+			<dependency groupId="org.jboss.cache" artifactId="jbosscache-core" version="2.2.0.CR6" />
+	   </inlineDependencies>
 	</target>
 
 	<target name="antlr" depends="initcore" description="Generate ANTLR parser">
@@ -192,7 +195,18 @@
 	</target>
 
 	<target name="compilecore" depends="initcore,select-compiler,antlr">
-		<compile classesdir="${classes.core.dir}" srcdir="${src.core.dir}" classpath="compile.core.path" />
+		<compile classesdir="${classes.core.dir}" srcdir="${src.core.dir}" classpath="compile.core.path">
+		   <exclude name="org/jboss/seam/cache/JbossCache2Provider*" />
+	   </compile>
+		<!-- Fiddle to make sure we compile the JBossCache2 stuff with JBossCache2" -->
+		<path id="compile.core-jbosscache2.path">
+         <path refid="compile.jbosscache2.path" />
+         <path refid="compile.core.path" />
+         <fileset dir="${classes.core.dir}" />
+      </path>
+		<compile classesdir="${classes.core.dir}" srcdir="${src.core.dir}" classpath="compile.core-jbosscache2.path">
+         <include name="org/jboss/seam/cache/JbossCache2Provider*" />
+      </compile>
 	</target>
 
 	<target name="jarcore" depends="compilecore" description="Build the distribution .jar file using M2 dependency management">
@@ -874,7 +888,8 @@
 					<patternset refid="meta.files" />
 				</fileset>
 			</copy>
-			<dependencies id="@{modulename}" scope="@{scope}" pom="@{pom}" />
+			<dependencies id="@{modulename}" scope="@{scope}" pom="@{pom}">
+			</dependencies>
 		</sequential>
 	</macrodef>
 
@@ -882,13 +897,10 @@
 		<attribute name="classesdir" />
 		<attribute name="srcdir" />
 		<attribute name="classpath" />
-		<element name="compile.classpath" optional="true" implicit="true" />
+		<element name="javac.nested" optional="true" implicit="true"/>
 		<sequential>
-			<javac source="1.5" target="1.5" destdir="@{classesdir}" debug="${javac.debug}" deprecation="${javac.deprecation}" nowarn="on" srcdir="@{srcdir}">
-				<classpath>
-					<path refid="@{classpath}" />
-					<compile.classpath />
-				</classpath>
+			<javac source="1.5" target="1.5" destdir="@{classesdir}" debug="${javac.debug}" deprecation="${javac.deprecation}" nowarn="on" srcdir="@{srcdir}" classpathref="@{classpath}" >
+				<javac.nested />
 			</javac>
 		</sequential>
 	</macrodef>

Added: trunk/src/main/org/jboss/seam/cache/AbstractJBossCacheProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/cache/AbstractJBossCacheProvider.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/cache/AbstractJBossCacheProvider.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -0,0 +1,34 @@
+package org.jboss.seam.cache;
+
+import org.jboss.cache.Fqn;
+
+public abstract class AbstractJBossCacheProvider<T> extends CacheProvider<T>
+{
+   
+   public AbstractJBossCacheProvider()
+   {
+      super.setConfiguration("treecache.xml");
+   }
+   
+   private Fqn defaultFqn = Fqn.fromString(defaultRegion);
+   
+   protected Fqn getFqn(String region)
+   {
+      if (region != null)
+      {
+         return Fqn.fromString(region);
+      }
+      else
+      {
+         return defaultFqn;
+      }
+   }
+   
+   @Override
+   public void setDefaultRegion(String defaultRegion)
+   {
+      super.setDefaultRegion(defaultRegion);
+      this.defaultFqn = Fqn.fromString(defaultRegion);
+   }
+
+}
\ No newline at end of file


Property changes on: trunk/src/main/org/jboss/seam/cache/AbstractJBossCacheProvider.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/main/org/jboss/seam/cache/CacheProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/cache/CacheProvider.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/cache/CacheProvider.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -0,0 +1,147 @@
+package org.jboss.seam.cache;
+
+import java.io.InputStream;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.ResourceLoader;
+
+/**
+ * CacheProvider provides methods to control and manipulate the configured cache
+ * 
+ * @author Sebastian Hennebrueder
+ * @author Pete Muir
+ */
+
+public abstract class CacheProvider<T>
+{
+
+   /**
+    * the region name to be used if no region is specified
+    */
+   public static final String DEFAULT_REGION = "org.jboss.seam.cache.DefaultRegion";
+   private String configuration;
+   protected String defaultRegion = DEFAULT_REGION;
+
+   /**
+    * @return - the cache the cache provider delegates to
+    */
+   public abstract T getDelegate();
+
+   /**
+    * Get the configuration file used by the cache
+    * 
+    */
+   public String getConfiguration()
+   {
+      return this.configuration;
+   }
+
+   protected InputStream getConfigurationAsStream()
+   {
+      return ResourceLoader.instance().getResourceAsStream(getConfiguration());
+   }
+
+   /**
+    * Set the configuration file to be used by the cache
+    */
+   public void setConfiguration(String cfgResourceName)
+   {
+      this.configuration = cfgResourceName;
+   }
+
+   /**
+    * Fetches an object for the given key from the cache and returns it if
+    * found. Only the default cache region will be searched.
+    * 
+    * @param key - a key to identify the object.
+    * @return - the object if found or null if not
+    */
+   public Object get(String key)
+   {
+      return get(null, key);
+   }
+
+   /**
+    * Fetches an object for the given key from the cache and returns it if
+    * found. Only the specified cache region will be searched.
+    * 
+    * @param region - the name of a cache region
+    * @param key - a key to identify the object.
+    * @return - the object if found or null if not
+    */
+   public abstract Object get(String key, String region);
+
+   /**
+    * Put an object into the cache. The object is placed in the default cache
+    * region under the given key.
+    * 
+    * @param key - a key to identify the object
+    * @param object - the object to be stored in the cache
+    */
+   public void put(String key, Object object)
+   {
+      put(null, key, object);
+   }
+
+   /**
+    * Puts an object into the cache. The object is placed in the specified cache
+    * region under the given key.
+    * 
+    * @param region - the name of a cache region
+    * @param key - a key to identify the object
+    * @param object - the object to be stored in the cache
+    */
+   public abstract void put(String region, String key, Object object);
+
+   /**
+    * Removes an object from the cache. The object is removed from the default
+    * cache region under the given key.
+    * 
+    * @param key - a key to identify the object
+    */
+   public void remove(String key)
+   {
+      remove(null, key);
+   }
+
+   /**
+    * Removes an object from the cache. The object is removed from the specified
+    * cache region under the given key.
+    * 
+    * @param region - the name of a cache region
+    * @param key - a key to identify the object
+    */
+   public abstract void remove(String region, String key);
+
+   /**
+    * Removes all objects from all cache regions
+    */
+   public abstract void clear();
+
+   public String getDefaultRegion()
+   {
+      return defaultRegion;
+   }
+
+   public void setDefaultRegion(String defaultRegion)
+   {
+      this.defaultRegion = defaultRegion;
+   }
+
+   public static CacheProvider instance()
+   {
+      if (!Contexts.isApplicationContextActive())
+      {
+         throw new IllegalStateException("No active application scope");
+      }
+      return (CacheProvider) Component.getInstance("org.jboss.seam.cache.cacheProvider", ScopeType.APPLICATION);
+   }
+
+   public static <T> CacheProvider<T> instance(Class<? extends T> type)
+   {
+      return instance();
+   }
+
+}


Property changes on: trunk/src/main/org/jboss/seam/cache/CacheProvider.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/main/org/jboss/seam/cache/EhCacheProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/cache/EhCacheProvider.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/cache/EhCacheProvider.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -0,0 +1,135 @@
+package org.jboss.seam.cache;
+
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+import static org.jboss.seam.ScopeType.STATELESS;
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
+
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+/**
+ * Implementation of CacheProvider backed by EhCache. The default cache region
+ * issues <i>org.jboss.seam.cache.DefaultCache</> as the default cache region.
+ * 
+ * @author Sebastian Hennebrueder
+ * @author Pete Muir
+ */
+ at Name("org.jboss.seam.cache.cacheProvider")
+ at Scope(STATELESS)
+ at BypassInterceptors
+ at Install(value = false, precedence = BUILT_IN, classDependencies="net.sf.ehcache.Cache")
+public class EhCacheProvider extends CacheProvider<CacheManager>
+{
+
+   private CacheManager cacheManager;
+
+   private static final LogProvider log = Logging.getLogProvider(EhCacheProvider.class);
+
+   @Override
+   public CacheManager getDelegate()
+   {
+      return cacheManager;
+   }
+
+   @Override
+   public void put(String region, String key, Object object)
+   {
+      Cache cache = getCacheRegion(region);
+      Element element = new Element(key, object);
+      cache.put(element);
+   }
+
+   @Override
+   public void clear()
+   {
+      String[] strings = cacheManager.getCacheNames();
+      for (String cacheName : strings)
+      {
+         Cache cache = getCacheRegion(cacheName);
+         cache.removeAll();
+      }
+   }
+
+   @Override
+   public Object get(String region, String key)
+   {
+      Cache cache = getCacheRegion(region);
+      Element element = cache.get(key);
+      if (element != null)
+      {
+         return element.getObjectValue();
+      }
+      else
+      {
+         return null;
+      }
+   }
+
+   private net.sf.ehcache.Cache getCacheRegion(String regionName)
+   {
+      if (regionName == null)
+      {
+         regionName = getDefaultRegion();
+      }
+      Cache result = cacheManager.getCache(regionName);
+      if (result == null)
+      {
+         throw new IllegalArgumentException("Cache region not found");
+      }
+      return result;
+   }
+
+   @Override
+   public void remove(String region, String key)
+   {
+      Cache cache = getCacheRegion(region);
+      cache.remove(key);
+   }
+
+   @Create
+   public void create()
+   {
+      log.debug("Starting EhCacheProvider cache");
+      // TODO validate if there is any common approach to load resources in Seam
+      try
+      {
+         if (getConfiguration() != null)
+         {
+            cacheManager = new CacheManager(getConfigurationAsStream());
+         }
+         else
+         {
+            cacheManager = new CacheManager();
+         }
+      }
+      catch (net.sf.ehcache.CacheException e)
+      {
+         throw new IllegalStateException("Error starting EHCache Cache", e);
+      }
+   }
+
+   @Destroy
+   public void destroy()
+   {
+      log.debug("Stopping EhCacheProvider cache");
+
+      try
+      {
+         cacheManager.shutdown();
+         cacheManager = null;
+      }
+      catch (RuntimeException e)
+      {
+         throw new IllegalStateException("Error stopping EHCache Cache", e);
+      }
+   }
+
+}


Property changes on: trunk/src/main/org/jboss/seam/cache/EhCacheProvider.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/main/org/jboss/seam/cache/JbossCache2Provider.java
===================================================================
--- trunk/src/main/org/jboss/seam/cache/JbossCache2Provider.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/cache/JbossCache2Provider.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -0,0 +1,103 @@
+package org.jboss.seam.cache;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+/**
+ * Implementation of CacheProvider backed by JBoss Cache 2.x.
+ * for simple objects.
+ * 
+ * @author Sebastian Hennebrueder
+ * @author Pete Muir
+ */
+
+ at Name("org.jboss.seam.cache.cacheProvider")
+ at Scope(APPLICATION)
+ at BypassInterceptors
+ at Install(precedence = BUILT_IN, classDependencies="org.jboss.cache.Cache")
+public class JbossCache2Provider extends AbstractJBossCacheProvider<Cache>
+{
+
+   private org.jboss.cache.Cache cache;
+
+   private static final LogProvider log = Logging.getLogProvider(JbossCache2Provider.class);
+
+   @Create
+   public void create()
+   {
+      log.debug("Starting JBoss Cache");
+
+      try
+      {
+         CacheFactory factory = new DefaultCacheFactory();
+         cache = factory.createCache(getConfigurationAsStream());
+
+         cache.create();
+         cache.start();
+      }
+      catch (Exception e)
+      {
+         log.error(e, e);
+         throw new IllegalStateException("Error starting JBoss Cache", e);
+      }
+   }
+
+   @Destroy
+   public void destroy()
+   {
+      log.debug("Stopping JBoss Cache");
+      try
+      {
+         cache.stop();
+         cache.destroy();
+         cache = null;
+      }
+      catch (Exception e)
+      {
+         throw new IllegalStateException("Error stopping JBoss Cache", e);
+      }
+   }
+
+   @Override
+   public Object get(String region, String key)
+   {
+      return cache.get(getFqn(region), key);
+   }
+
+   @Override
+   public void put(String region, String key, Object object)
+   {
+      cache.put(getFqn(region), key, object);
+   }
+
+   @Override
+   public void remove(String region, String key)
+   {
+      cache.remove(getFqn(region), key);
+   }
+
+   @Override
+   public void clear()
+   {
+      cache.removeNode(getFqn(null));
+   }
+
+   @Override
+   public Cache getDelegate()
+   {
+      return cache;
+   }
+
+}
\ No newline at end of file


Property changes on: trunk/src/main/org/jboss/seam/cache/JbossCache2Provider.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/main/org/jboss/seam/cache/JbossCacheProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/cache/JbossCacheProvider.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/cache/JbossCacheProvider.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -0,0 +1,140 @@
+package org.jboss.seam.cache;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+import static org.jboss.seam.annotations.Install.FRAMEWORK;
+
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Node;
+import org.jboss.cache.PropertyConfigurator;
+import org.jboss.cache.TreeCache;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+/**
+ * Implementation of CacheProvider backed by JBoss Cache 1.x
+ * 
+ * @author Sebastian Hennebrueder
+ * @author Pete Muir
+ */
+
+ at Name("org.jboss.seam.cache.cacheProvider")
+ at Scope(APPLICATION)
+ at BypassInterceptors
+ at Install(precedence = FRAMEWORK, classDependencies="org.jboss.cache.TreeCache")
+public class JbossCacheProvider extends AbstractJBossCacheProvider<TreeCache>
+{
+
+   private TreeCache cache;
+
+   private static final LogProvider log = Logging.getLogProvider(JbossCacheProvider.class);
+
+   @Create
+   public void create()
+   {
+      log.info("Starting JBoss Treecache 1.x");
+
+      try
+      {
+         cache = new TreeCache();
+         new PropertyConfigurator().configure(cache, getConfigurationAsStream());
+         cache.createService();
+         cache.startService();
+
+      }
+      catch (Exception e)
+      {
+         throw new IllegalStateException("Error starting JBoss Treecache 1.x", e);
+      }
+   }
+
+   @Destroy
+   public void destroy()
+   {
+      log.info("Stopping JBoss Treecache 1.x");
+
+      try
+      {
+         cache.stopService();
+         cache.destroyService();
+      }
+      catch (RuntimeException e)
+      {
+         throw new IllegalStateException("Error stopping JBoss Treecache 1.x", e);
+      }
+      cache = null;
+   }
+
+   @Override
+   public Object get(String region, String key)
+   {
+      try
+      {
+         Node node = cache.get(getFqn(region));
+         if (node != null)
+         {
+            return node.get(key);
+         }
+         else
+         {
+            return null;
+         }
+      }
+      catch (CacheException e)
+      {
+         throw new IllegalStateException(String.format("Cache throw exception when trying to get %s from region %s.", key, region), e);
+      }
+   }
+
+   @Override
+   public void put(String region, String key, Object object)
+   {
+      try
+      {
+         cache.put(getFqn(region), key, object);
+      }
+      catch (CacheException e)
+      {
+         throw new IllegalStateException(String.format("JBoss Cache throw exception when adding object for key %s to region %s", key, region), e);
+      }
+   }
+
+   @Override
+   public void remove(String region, String key)
+   {
+      try
+      {
+         cache.remove(getFqn(region), key);
+      }
+      catch (CacheException e)
+      {
+         throw new IllegalStateException(String.format("JBoss Cache throw exception when removing object for key %s in region %s", key, region), e);
+      }
+
+   }
+
+   @Override
+   public TreeCache getDelegate()
+   {
+      return cache;
+   }
+
+   @Override
+   public void clear()
+   {
+      try
+      {
+         cache.remove(getFqn(null));
+      }
+      catch (CacheException e)
+      {
+         throw new IllegalStateException(String.format("JBoss Cache throw exception when clearing default cache."), e);
+      }
+   }
+
+}
\ No newline at end of file


Property changes on: trunk/src/main/org/jboss/seam/cache/JbossCacheProvider.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/main/org/jboss/seam/cache/JbossPojoCacheProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/cache/JbossPojoCacheProvider.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/cache/JbossPojoCacheProvider.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -0,0 +1,130 @@
+package org.jboss.seam.cache;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import org.jboss.cache.CacheException;
+import org.jboss.cache.aop.PojoCache;
+import org.jboss.seam.annotations.Create;
+import org.jboss.seam.annotations.Destroy;
+import org.jboss.seam.annotations.Install;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+/**
+ * Implementation of CacheProvider backed by JBoss POJO Cache 1.x
+ * 
+ * @author Sebastian Hennebrueder
+ * @author Pete Muir
+ */
+
+ at Name("org.jboss.seam.cache.cacheProvider")
+ at Scope(APPLICATION)
+ at BypassInterceptors
+ at Install(value = false, precedence = BUILT_IN, classDependencies="org.jboss.cache.aop.PojoCache")
+public class JbossPojoCacheProvider extends AbstractJBossCacheProvider<PojoCache>
+{
+
+   private PojoCache cache;
+
+   private static final LogProvider log = Logging.getLogProvider(JbossPojoCacheProvider.class);
+
+   @Create
+   public void create()
+   {
+      log.debug("Starting JBoss POJO Cache 1.x");
+
+      try
+      {
+         cache = new PojoCache();
+         new org.jboss.cache.PropertyConfigurator().configure(cache, getConfigurationAsStream());
+         cache.createService();
+         cache.startService();
+
+      }
+      catch (Exception e)
+      {
+         throw new IllegalStateException("Error starting JBoss POJO Cache 1.x", e);
+      }
+   }
+
+   @Destroy
+   public void destroy()
+   {
+      log.debug("Stopping JBoss Treecache 1.x");
+
+      try
+      {
+         cache.stopService();
+         cache.destroyService();
+      }
+      catch (RuntimeException e)
+      {
+         throw new IllegalStateException("Error stopping JBoss Treecache 1.x", e);
+      }
+      cache = null;
+   }
+
+   @Override
+   public Object get(String region, String key)
+   {
+      try
+      {
+         return cache.get(getFqn(key));
+      }
+      catch (CacheException e)
+      {
+         throw new IllegalStateException(String.format("Cache throw exception when trying to get %s from region %s.", key, region), e);
+      }
+   }
+
+   @Override
+   public void put(String region, String key, Object object)
+   {
+      try
+      {
+         cache.put(getFqn(region), key, object);
+      }
+      catch (CacheException e)
+      {
+         throw new IllegalStateException(String.format("JBoss Cache throw exception when adding object for key %s to region %s", key, region), e);
+      }
+   }
+
+   @Override
+   public void remove(String region, String key)
+   {
+      try
+      {
+         cache.remove(getFqn(region), key);
+      }
+      catch (CacheException e)
+      {
+         throw new IllegalStateException(String.format("JBoss Cache throw exception when removing object for key %s in region %s", key, region), e);
+      }
+
+   }
+
+   @Override
+   public PojoCache getDelegate()
+   {
+      return cache;
+   }
+
+   @Override
+   public void clear()
+   {
+      try
+      {
+         cache.remove(getFqn(null));
+      }
+      catch (CacheException e)
+      {
+         throw new IllegalStateException(String.format("JBoss Cache throw exception when clearing default cache."), e);
+      }
+   }
+
+}
\ No newline at end of file


Property changes on: trunk/src/main/org/jboss/seam/cache/JbossPojoCacheProvider.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/main/org/jboss/seam/cache/package-info.java
===================================================================
--- trunk/src/main/org/jboss/seam/cache/package-info.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/cache/package-info.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -0,0 +1,9 @@
+/**
+ * A set of Seam components that provide caching
+ */
+ at Namespace(value="http://jboss.com/products/seam/cache", prefix="org.jboss.seam.cache")
+ at AutoCreate
+package org.jboss.seam.cache;
+
+import org.jboss.seam.annotations.AutoCreate;
+import org.jboss.seam.annotations.Namespace;


Property changes on: trunk/src/main/org/jboss/seam/cache/package-info.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/main/org/jboss/seam/cache-2.1.xsd
===================================================================
--- trunk/src/main/org/jboss/seam/cache-2.1.xsd	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/cache-2.1.xsd	2008-08-20 18:26:02 UTC (rev 8753)
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+   elementFormDefault="qualified"
+   targetNamespace="http://jboss.com/products/seam/cache"
+   xmlns:cache="http://jboss.com/products/seam/cache"
+   xmlns:components="http://jboss.com/products/seam/components"
+   attributeFormDefault="unqualified">
+   <xs:import namespace="http://jboss.com/products/seam/components"
+      schemaLocation="components-2.1.xsd" />
+   
+   <xs:element name="eh-cache-provider">
+      <xs:annotation>
+         <xs:documentation>The EHCache provider</xs:documentation>
+      </xs:annotation>
+      <xs:complexType mixed="true">
+         <xs:attributeGroup ref="components:attlist.component" />
+         <xs:attributeGroup ref="cache:attlist.cacheProvider" />
+      </xs:complexType>
+   </xs:element>
+   
+   <xs:element name="jboss-cache-provider">
+      <xs:annotation>
+         <xs:documentation>The JBoss 1.x Cache provider</xs:documentation>
+      </xs:annotation>
+      <xs:complexType mixed="true">
+         <xs:attributeGroup ref="components:attlist.component" />
+         <xs:attributeGroup ref="cache:attlist.cacheProvider" />
+      </xs:complexType>
+   </xs:element>
+   
+   <xs:element name="jboss-cache2-provider">
+      <xs:annotation>
+         <xs:documentation>The JBoss 2.x cache provider</xs:documentation>
+      </xs:annotation>
+      <xs:complexType mixed="true">
+         <xs:attributeGroup ref="components:attlist.component" />
+         <xs:attributeGroup ref="cache:attlist.cacheProvider" />
+      </xs:complexType>
+   </xs:element>
+
+   <xs:element name="jboss-pojo-cache-provider">
+      <xs:annotation>
+         <xs:documentation>The JBoss 1.x POJOCache provider</xs:documentation>
+      </xs:annotation>
+      <xs:complexType mixed="true">
+         <xs:attributeGroup ref="components:attlist.component" />
+         <xs:attributeGroup ref="cache:attlist.cacheProvider" />
+      </xs:complexType>
+   </xs:element>
+
+   <xs:attributeGroup name="attlist.cacheProvider">
+      <xs:attribute name="default-region" type="components:string" />
+      <xs:attribute name="configuration" type="components:string" />
+   </xs:attributeGroup>
+
+</xs:schema>


Property changes on: trunk/src/main/org/jboss/seam/cache-2.1.xsd
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: trunk/src/main/org/jboss/seam/core/PojoCache.java
===================================================================
--- trunk/src/main/org/jboss/seam/core/PojoCache.java	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/src/main/org/jboss/seam/core/PojoCache.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -1,82 +0,0 @@
-//$Id$
-package org.jboss.seam.core;
-
-import static org.jboss.seam.annotations.Install.BUILT_IN;
-
-import org.jboss.cache.PropertyConfigurator;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Create;
-import org.jboss.seam.annotations.Destroy;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.Unwrap;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-
-/**
- * Integration with JBoss Cache
- * 
- * @author Gavin King
- *
- */
- at Name("org.jboss.seam.core.pojoCache")
- at Scope(ScopeType.APPLICATION)
- at BypassInterceptors
- at Install(value=false, precedence=BUILT_IN)
-public class PojoCache 
-{
-
-   private static final LogProvider log = Logging.getLogProvider(PojoCache.class);
-
-   private org.jboss.cache.aop.PojoCache cache;
-   private String cfgResourceName = "treecache.xml";
-
-   @Create
-   public void start() throws Exception 
-   {
-      log.debug("starting JBoss Cache");
-      cache = new org.jboss.cache.aop.PojoCache();
-      new PropertyConfigurator().configure(cache, cfgResourceName);
-      cache.createService();
-      cache.startService();
-   }
-   
-   @Destroy
-   public void stop() 
-   {
-      log.debug("stopping JBoss Cache");
-      cache.stopService();
-      cache.destroyService();
-      cache = null;
-   }
-
-   @Unwrap
-   public org.jboss.cache.aop.PojoCache getCache() 
-   {
-      return cache;
-   }
-
-   public String getCfgResourceName()
-   {
-      return cfgResourceName;
-   }
-
-   public void setCfgResourceName(String cfgResourceName)
-   {
-      this.cfgResourceName = cfgResourceName;
-   }
-
-   public static org.jboss.cache.aop.PojoCache instance()
-   {
-      if ( !Contexts.isApplicationContextActive() )
-      {
-         throw new IllegalStateException("No active application scope");
-      }
-      return (org.jboss.cache.aop.PojoCache) Component.getInstance(PojoCache.class, ScopeType.APPLICATION);
-   }
-   
-}

Modified: trunk/src/main/org/jboss/seam/init/Initialization.java
===================================================================
--- trunk/src/main/org/jboss/seam/init/Initialization.java	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/src/main/org/jboss/seam/init/Initialization.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -42,7 +42,6 @@
 import org.jboss.seam.contexts.ServletLifecycle;
 import org.jboss.seam.core.Expressions;
 import org.jboss.seam.core.Init;
-import org.jboss.seam.core.PojoCache;
 import org.jboss.seam.deployment.DotPageDotXmlDeploymentHandler;
 import org.jboss.seam.deployment.HotDeploymentStrategy;
 import org.jboss.seam.deployment.StandardDeploymentStrategy;
@@ -931,18 +930,7 @@
    }
 
    private void addSpecialComponents(Init init)
-   {
-      try
-      {
-         Reflections.classForName("org.jboss.cache.aop.PojoCache");
-         addComponentDescriptor( new ComponentDescriptor(PojoCache.class, true) );
-      }
-      catch (ClassNotFoundException e) {}
-      catch (NoClassDefFoundError e) {
-         //temp solution due to broken JEMS installer portal profile!
-         log.warn("Did not install PojoCache due to NoClassDefFoundError: " + e.getMessage());
-      }
-   }
+   {}
 
    private void installComponents(Init init)
    {

Modified: trunk/ui/src/main/config/component/cache.xml
===================================================================
--- trunk/ui/src/main/config/component/cache.xml	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/ui/src/main/config/component/cache.xml	2008-08-20 18:26:02 UTC (rev 8753)
@@ -7,7 +7,7 @@
 		<classname>org.jboss.seam.ui.component.html.HtmlCache</classname>
 		<superclass>org.jboss.seam.ui.component.UICache</superclass>
 		<description>
-			<![CDATA[Cache the rendered page fragment using JBoss Cache. Note that <s:cache> actually uses the instance of JBoss Cache managed by the built-in pojoCache component.]]>
+			<![CDATA[Cache the rendered page fragment using the installed cache provider.]]>
 		</description>
 		<renderer generate="false" override="false">
 			<name>org.jboss.seam.ui.CacheRenderer</name>
@@ -36,8 +36,14 @@
 		<property>
 			<name>region</name>
 			<classname>java.lang.String</classname>
-			<description>a JBoss Cache node to use (different nodes can have different expiry policies).</description>
+			<description>a cache node to use (different nodes can have different expiry policies).</description>
 		</property>
+      <property elonly="true">
+         <name>cacheProvider</name>
+         <classname>org.jboss.seam.cache.CacheProvider</classname>
+         <description>The cache provider to use, only needed if you install alter the default cache provider in an application where multiple cache providers are in use</description>
+         <defaultvalue>org.jboss.seam.cache.CacheProvider.instance()</defaultvalue>
+      </property>
 		<property elonly="true">
 			<name>enabled</name>
 			<classname>boolean</classname>

Modified: trunk/ui/src/main/java/org/jboss/seam/ui/component/UICache.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/component/UICache.java	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/component/UICache.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -23,7 +23,9 @@
 
 import javax.faces.component.UIComponentBase;
 
+import org.jboss.seam.cache.CacheProvider;
 
+
 /**
  * JSF component class
  * 
@@ -42,5 +44,9 @@
    public abstract String getRegion();
    
    public abstract void setRegion(String region);
+   
+   public abstract CacheProvider getCacheProvider();
+   
+   public abstract void setCacheProvider(CacheProvider cacheProvider);
 
 }

Modified: trunk/ui/src/main/java/org/jboss/seam/ui/renderkit/CacheRendererBase.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/renderkit/CacheRendererBase.java	2008-08-20 15:28:21 UTC (rev 8752)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/renderkit/CacheRendererBase.java	2008-08-20 18:26:02 UTC (rev 8753)
@@ -1,29 +1,34 @@
 package org.jboss.seam.ui.renderkit;
 
-import java.io.IOException;
-import java.io.StringWriter;
+import org.jboss.seam.cache.CacheProvider;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+import org.jboss.seam.ui.component.UICache;
+import org.jboss.seam.ui.util.cdk.RendererBase;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
 
-import org.jboss.seam.core.PojoCache;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
-import org.jboss.seam.ui.component.UICache;
-import org.jboss.seam.ui.util.cdk.RendererBase;
+public class CacheRendererBase extends RendererBase {
 
-public class CacheRendererBase extends RendererBase
-{
-   
    private static final LogProvider log = Logging.getLogProvider(UICache.class);
-   
+
+   /**
+    * last time we logged the failure of the cache
+    */
+   private static Calendar lastLog = null;
+
    @Override
    protected Class getComponentClass()
    {
       return UICache.class;
    }
-   
+
    @Override
    protected void doEncodeChildren(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException
    {
@@ -31,7 +36,7 @@
       if (cache.isEnabled())
       {
          String key = cache.getKey();
-         String cachedContent = getFromCache(key, cache.getRegion());
+         String cachedContent = (String) cache.getCacheProvider().get(key, cache.getRegion()); 
          if (cachedContent == null)
          {
             log.debug("rendering from scratch: " + key);
@@ -42,7 +47,7 @@
             context.setResponseWriter(writer);
             String output = stringWriter.getBuffer().toString();
             writer.write(output);
-            putInCache(key, cache.getRegion(), output);
+            cache.getCacheProvider().put(key, cache.getRegion(), output);
          }
          else
          {
@@ -55,33 +60,7 @@
          renderChildren(context, component);
       }
    }
-   
 
-   private static void putInCache(String key, String region, String content)
-   {
-      try
-      {
-         PojoCache.instance().put(region, key, content);
-      }
-      catch (Exception ce)
-      {
-         log.error("error accessing cache", ce);
-      }
-   }
-
-   private static String getFromCache(String key, String region)
-   {
-      try
-      {
-         return (String) PojoCache.instance().get(region, key);
-      }
-      catch (Exception ce)
-      {
-         log.error("error accessing cache", ce);
-         return null;
-      }
-   }
-
    @Override
    public boolean getRendersChildren()
    {




More information about the seam-commits mailing list