[seam-commits] Seam SVN: r14594 - in branches/community/Seam_2_3: jboss-seam and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Apr 17 04:05:00 EDT 2012


Author: manaRH
Date: 2012-04-17 04:04:56 -0400 (Tue, 17 Apr 2012)
New Revision: 14594

Added:
   branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/cache/AbstractInfinispanCacheProvider.java
   branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/cache/InfinispanCacheProvider.java
Modified:
   branches/community/Seam_2_3/bom/pom.xml
   branches/community/Seam_2_3/jboss-seam/pom.xml
   branches/community/Seam_2_3/jboss-seam/src/main/resources/org/jboss/seam/cache-2.3.xsd
Log:
JBSEAM-4921 added InfinispanCacheProvider

Modified: branches/community/Seam_2_3/bom/pom.xml
===================================================================
--- branches/community/Seam_2_3/bom/pom.xml	2012-04-16 17:15:14 UTC (rev 14593)
+++ branches/community/Seam_2_3/bom/pom.xml	2012-04-17 08:04:56 UTC (rev 14594)
@@ -41,9 +41,9 @@
 		<version.jbossas7>7.1.1.Final</version.jbossas7>
 		<version.jsf2>2.1.7</version.jsf2>
         <version.webdriver>0.9.7376</version.webdriver>
+        <version.infinispan>5.1.3.FINAL</version.infinispan>
 
 
-
 		<!-- ***************** -->
 		<!-- Repository Deployment URLs -->
 		<!-- ***************** -->
@@ -1006,7 +1006,16 @@
 				<artifactId>jboss-as-arquillian-container-remote</artifactId>
 				<version>${version.jbossas7}</version>
 			</dependency>
-
+            <dependency>
+		         <groupId>org.infinispan</groupId>
+		         <artifactId>infinispan-core</artifactId>
+		         <version>${version.infinispan}</version>
+		      </dependency>
+		    <dependency>
+                <groupId>org.infinispan</groupId>
+                <artifactId>infinispan-tree</artifactId>
+                <version>${version.infinispan}</version>
+            </dependency>
 		</dependencies>
 	</dependencyManagement>
 

Modified: branches/community/Seam_2_3/jboss-seam/pom.xml
===================================================================
--- branches/community/Seam_2_3/jboss-seam/pom.xml	2012-04-16 17:15:14 UTC (rev 14593)
+++ branches/community/Seam_2_3/jboss-seam/pom.xml	2012-04-17 08:04:56 UTC (rev 14594)
@@ -77,6 +77,15 @@
 
 	<dependencies>
 
+        <dependency>
+            <groupId>org.infinispan</groupId>
+            <artifactId>infinispan-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.infinispan</groupId>
+            <artifactId>infinispan-tree</artifactId>
+        </dependency>
+        
 		<dependency>
 			<groupId>org.hibernate</groupId>
 			<artifactId>hibernate-core</artifactId>

Added: branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/cache/AbstractInfinispanCacheProvider.java
===================================================================
--- branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/cache/AbstractInfinispanCacheProvider.java	                        (rev 0)
+++ branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/cache/AbstractInfinispanCacheProvider.java	2012-04-17 08:04:56 UTC (rev 14594)
@@ -0,0 +1,38 @@
+package org.jboss.seam.cache;
+
+import org.infinispan.tree.Fqn;
+
+public abstract class AbstractInfinispanCacheProvider<T> extends CacheProvider<T>
+{
+   
+   public AbstractInfinispanCacheProvider()
+   {
+      super.setConfiguration("infinispan.xml");
+   }
+   
+   private Fqn defaultFqn;
+   
+   protected Fqn getFqn(String region)
+   {
+      if (region != null)
+      {
+         return Fqn.fromString(region);
+      }
+      else
+      {
+         if (defaultFqn == null)
+         {
+            defaultFqn = Fqn.fromString(getDefaultRegion());
+         }
+         return defaultFqn;
+      }
+   }
+   
+   @Override
+   public void setDefaultRegion(String defaultRegion)
+   {
+      super.setDefaultRegion(defaultRegion);
+      this.defaultFqn = Fqn.fromString(defaultRegion);
+   }
+
+}
\ No newline at end of file

Added: branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/cache/InfinispanCacheProvider.java
===================================================================
--- branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/cache/InfinispanCacheProvider.java	                        (rev 0)
+++ branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/cache/InfinispanCacheProvider.java	2012-04-17 08:04:56 UTC (rev 14594)
@@ -0,0 +1,129 @@
+package org.jboss.seam.cache;
+
+import static org.jboss.seam.ScopeType.APPLICATION;
+import static org.jboss.seam.annotations.Install.BUILT_IN;
+
+import java.lang.reflect.Method;
+
+import org.infinispan.Cache;
+import org.infinispan.tree.Fqn;
+import org.infinispan.tree.TreeCache;
+import org.infinispan.tree.TreeCacheFactory;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.manager.DefaultCacheManager;
+import org.jboss.seam.annotations.AutoCreate;
+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;
+import org.jboss.seam.util.Reflections;
+
+/**
+ * Implementation of CacheProvider backed by Infinispan 5.x. for simple objects.
+ * 
+ * @author Marek Novotny
+ */
+
+ at Name("org.jboss.seam.cache.cacheProvider")
+ at Scope(APPLICATION)
+ at BypassInterceptors
+ at Install(value = false, precedence = BUILT_IN, classDependencies = { "org.infinispan.tree.TreeCache", "org.jgroups.MembershipListener" })
+ at AutoCreate
+ at SuppressWarnings("rawtypes")
+public class InfinispanCacheProvider extends AbstractInfinispanCacheProvider<TreeCache<Object, Object>>
+{
+
+   private org.infinispan.tree.TreeCache cache;
+
+   private static final LogProvider log = Logging.getLogProvider(InfinispanCacheProvider.class);
+
+   private static Method GET;
+   private static Method PUT;
+   private static Method REMOVE;
+   private static Method REMOVE_NODE;
+
+   static
+   {
+      try
+      {
+         GET = TreeCache.class.getDeclaredMethod("get", Fqn.class, Object.class);
+         PUT = TreeCache.class.getDeclaredMethod("put", Fqn.class, Object.class, Object.class);
+         REMOVE = TreeCache.class.getDeclaredMethod("remove", Fqn.class, Object.class);
+         REMOVE_NODE = TreeCache.class.getDeclaredMethod("removeNode", Fqn.class);
+      }
+      catch (Exception e)
+      {
+         log.error(e);
+         throw new IllegalStateException("Unable to use Infinispan Cache", e);
+      }
+   }
+
+   @SuppressWarnings("unchecked")
+   @Create
+   public void create()
+   {
+      log.debug("Starting Infinispan Cache");
+
+      try
+      {
+         DefaultCacheManager manager = new DefaultCacheManager(getConfigurationAsStream());        
+         Cache defaultCache = manager.getCache();
+         cache = new TreeCacheFactory().createTreeCache(defaultCache);
+      }
+      catch (Exception e)
+      {
+         throw new IllegalStateException("Error starting Infinispan Cache", e);
+      }
+   }
+
+   @Destroy
+   public void destroy()
+   {
+      log.debug("Stopping Infinispan Cache");
+      try
+      {
+         cache.stop();
+         cache = null;
+      }
+      catch (Exception e)
+      {
+         throw new IllegalStateException("Error stopping Infinispan Cache", e);
+      }
+   }
+
+   @Override
+   public Object get(String region, String key)
+   {
+      return Reflections.invokeAndWrap(GET, cache, getFqn(region), key);
+   }
+
+   @Override
+   public void put(String region, String key, Object object)
+   {
+      Reflections.invokeAndWrap(PUT, cache, getFqn(region), key, object);
+   }
+
+   @Override
+   public void remove(String region, String key)
+   {
+      Reflections.invokeAndWrap(REMOVE, cache, getFqn(region), key);
+   }
+
+   @Override
+   public void clear()
+   {
+      Reflections.invokeAndWrap(REMOVE_NODE, cache, getFqn(null));
+   }
+
+   @Override
+   public TreeCache getDelegate()
+   {
+      return cache;
+   }
+
+}
\ No newline at end of file

Modified: branches/community/Seam_2_3/jboss-seam/src/main/resources/org/jboss/seam/cache-2.3.xsd
===================================================================
--- branches/community/Seam_2_3/jboss-seam/src/main/resources/org/jboss/seam/cache-2.3.xsd	2012-04-16 17:15:14 UTC (rev 14593)
+++ branches/community/Seam_2_3/jboss-seam/src/main/resources/org/jboss/seam/cache-2.3.xsd	2012-04-17 08:04:56 UTC (rev 14594)
@@ -48,6 +48,15 @@
       </xs:complexType>
    </xs:element>
 
+   <xs:element name="infinispan-cache-provider">
+      <xs:annotation>
+         <xs:documentation>The Infinispan 5.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:attributeGroup name="attlist.cacheProvider">
       <xs:attribute name="default-region" type="components:string" />
       <xs:attribute name="configuration" type="components:string" />



More information about the seam-commits mailing list