incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject svn commit: r1403180 - in /sling/whiteboard/ieb/cache: ehcache/ ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ impl/ impl/src/ impl/src/main/ impl/src/main/java/ impl/src/main/java/org/ impl/src/main/java/org/apache/ impl/src/main/java/o...
Date Mon, 29 Oct 2012 07:06:22 GMT
Author: ieb
Date: Mon Oct 29 07:06:20 2012
New Revision: 1403180

URL: http://svn.apache.org/viewvc?rev=1403180&view=rev
Log:
SLING-2555 Added Infinispan implementation (with note the Infinispan Jars are LGPLv2.1). Created a utility jar to aide implementation of other frameworks.

Added:
    sling/whiteboard/ieb/cache/impl/
    sling/whiteboard/ieb/cache/impl/README.txt
      - copied, changed from r1403171, sling/whiteboard/ieb/cache/ehcache/README.txt
    sling/whiteboard/ieb/cache/impl/pom.xml
      - copied, changed from r1403171, sling/whiteboard/ieb/cache/ehcache/pom.xml
    sling/whiteboard/ieb/cache/impl/src/
    sling/whiteboard/ieb/cache/impl/src/main/
    sling/whiteboard/ieb/cache/impl/src/main/java/
    sling/whiteboard/ieb/cache/impl/src/main/java/org/
    sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/
    sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/
    sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/
    sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/
    sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/
    sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/AbstractCacheManagerService.java
      - copied, changed from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/CacheManagerServiceImpl.java
    sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapCacheImpl.java   (contents, props changed)
      - copied, changed from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapCacheImpl.java
    sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapDeligate.java   (contents, props changed)
      - copied, changed from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapDeligate.java
    sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/ThreadLocalCacheMap.java
      - copied, changed from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ThreadLocalCacheMap.java
    sling/whiteboard/ieb/cache/infinispan/
    sling/whiteboard/ieb/cache/infinispan/README.txt   (with props)
    sling/whiteboard/ieb/cache/infinispan/pom.xml
      - copied, changed from r1403171, sling/whiteboard/ieb/cache/ehcache/pom.xml
    sling/whiteboard/ieb/cache/infinispan/src/
    sling/whiteboard/ieb/cache/infinispan/src/main/
    sling/whiteboard/ieb/cache/infinispan/src/main/java/
    sling/whiteboard/ieb/cache/infinispan/src/main/java/org/
    sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/
    sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/
    sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/
    sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/
    sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/
    sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheImpl.java   (with props)
    sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java   (with props)
    sling/whiteboard/ieb/cache/infinispan/src/main/resources/
    sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/
    sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/
    sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/
    sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/
    sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/cache/
    sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/cache/infinispan/
    sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/cache/infinispan/config.xml   (with props)
    sling/whiteboard/ieb/cache/infinispan/src/test/
    sling/whiteboard/ieb/cache/infinispan/src/test/java/
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheConfigTest.java   (with props)
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/MapBuilder.java   (contents, props changed)
      - copied, changed from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ThreadLocalCacheMap.java
    sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/TestCache.java   (with props)
Removed:
    sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapCacheImpl.java
    sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapDeligate.java
    sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ThreadLocalCacheMap.java
Modified:
    sling/whiteboard/ieb/cache/ehcache/README.txt
    sling/whiteboard/ieb/cache/ehcache/pom.xml
    sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/CacheManagerServiceImpl.java

Modified: sling/whiteboard/ieb/cache/ehcache/README.txt
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/ehcache/README.txt?rev=1403180&r1=1403179&r2=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/README.txt (original)
+++ sling/whiteboard/ieb/cache/ehcache/README.txt Mon Oct 29 07:06:20 2012
@@ -1,7 +1,6 @@
-Commons Cache.
-
-This is an implementation of the Cache API based on EhCache.
+EhCache Implementation of the CacheManagerService.
 
+This bundle contains an implementation of the CacheManagerService based on EhCache.
 
 Acknowledgments
 

Modified: sling/whiteboard/ieb/cache/ehcache/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/ehcache/pom.xml?rev=1403180&r1=1403179&r2=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/pom.xml (original)
+++ sling/whiteboard/ieb/cache/ehcache/pom.xml Mon Oct 29 07:06:20 2012
@@ -59,7 +59,10 @@
 		               !edu.emory.mathcs.backport.java.util.*,
 		               *
 		            </Import-Package>
-		            <Private-Package>org.apache.sling.commons.cache.ehcache.*</Private-Package>
+		            <Private-Package>
+		            org.apache.sling.commons.cache.ehcache.*,
+		            org.apache.sling.commons.cache.impl.*
+		            </Private-Package>
 		            <DynamicImport-Package>sun.misc.*</DynamicImport-Package>
 		            <Embed-Transitive>true</Embed-Transitive>
 		            <Embed-Dependency>ehcache,jsr107cache</Embed-Dependency>
@@ -76,10 +79,9 @@
 	       	<version>0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
-        	<groupId>commons-io</groupId>
-        	<artifactId>commons-io</artifactId>
-        	<version>1.4</version>
-        	<scope>provided</scope>
+	       	<groupId>org.apache.sling</groupId>
+	       	<artifactId>org.apache.sling.commons.cache.impl</artifactId>
+	       	<version>0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>net.sf.ehcache</groupId>

Modified: sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/CacheManagerServiceImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/CacheManagerServiceImpl.java?rev=1403180&r1=1403179&r2=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/CacheManagerServiceImpl.java (original)
+++ sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/CacheManagerServiceImpl.java Mon Oct 29 07:06:20 2012
@@ -19,7 +19,6 @@
 
 package org.apache.sling.commons.cache.ehcache;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -27,15 +26,14 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.management.ManagementFactory;
 import java.lang.ref.WeakReference;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.management.MBeanServer;
 
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.management.ManagementService;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -43,7 +41,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.cache.api.Cache;
 import org.apache.sling.commons.cache.api.CacheManagerService;
-import org.apache.sling.commons.cache.api.CacheScope;
+import org.apache.sling.commons.cache.impl.AbstractCacheManagerService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,7 +50,7 @@ import org.slf4j.LoggerFactory;
  */
 @Component(immediate = true, metatype = true)
 @Service(value = CacheManagerService.class)
-public class CacheManagerServiceImpl implements CacheManagerService {
+public class CacheManagerServiceImpl extends AbstractCacheManagerService {
 
 	public static final String DEFAULT_CACHE_CONFIG = "sling/ehcacheConfig.xml";
 
@@ -76,9 +74,7 @@ public class CacheManagerServiceImpl imp
 	private static final Logger LOGGER = LoggerFactory
 			.getLogger(CacheManagerServiceImpl.class);
 	private CacheManager cacheManager;
-	private Map<String, Cache<?>> caches = new HashMap<String, Cache<?>>();
-	private ThreadLocalCacheMap requestCacheMapHolder = new ThreadLocalCacheMap();
-	private ThreadLocalCacheMap threadCacheMapHolder = new ThreadLocalCacheMap();
+	private Map<String, Cache<?>> caches = new ConcurrentHashMap<String, Cache<?>>();
 
 	public CacheManagerServiceImpl() throws IOException {
 	}
@@ -146,46 +142,6 @@ public class CacheManagerServiceImpl imp
 
 	}
 
-	private String toString(Object object, String defaultValue) {
-		if (object == null) {
-			return defaultValue;
-		}
-		return String.valueOf(object);
-	}
-
-	private InputStream processConfig(InputStream in,
-			Map<String, Object> properties) throws IOException {
-		if (in == null) {
-			return null;
-		}
-		StringBuilder config = new StringBuilder(IOUtils.toString(in, "UTF-8"));
-		in.close();
-		int pos = 0;
-		for (;;) {
-			int start = config.indexOf("${", pos);
-			if (start < 0) {
-				break;
-			}
-			int end = config.indexOf("}", start);
-			if (end < 0) {
-				throw new IllegalArgumentException(
-						"Config file malformed, unterminated variable "
-								+ config.substring(start,
-										Math.min(start + 10, config.length())));
-			}
-			String key = config.substring(start + 2, end);
-			if (properties.containsKey(key)) {
-				String replacement = (String) properties.get(key);
-				config.replace(start, end + 1, replacement);
-				pos = start + replacement.length();
-			} else {
-				throw new IllegalArgumentException(
-						"Missing replacement property " + key);
-			}
-		}
-		return new ByteArrayInputStream(config.toString().getBytes("UTF-8"));
-
-	}
 
 	/**
 	 * perform a shutdown
@@ -198,71 +154,17 @@ public class CacheManagerServiceImpl imp
 		}
 	}
 
-	/**
-	 * {@inheritDoc}
-	 * 
-	 * @see org.apache.sling.commons.cache.api.CacheManagerService#getCache(java.lang.String)
-	 */
-	public <V> Cache<V> getCache(String name, CacheScope scope) {
-		switch (scope) {
-		case INSTANCE:
-			return getInstanceCache(name);
-		case CLUSTERINVALIDATED:
-			return getInstanceCache(name);
-		case CLUSTERREPLICATED:
-			return getInstanceCache(name);
-		case REQUEST:
-			return getRequestCache(name);
-		case THREAD:
-			return getThreadCache(name);
-		default:
-			return getInstanceCache(name);
-		}
-	}
 
 	/**
-	 * Generate a cache bound to the thread.
-	 * 
 	 * @param name
 	 * @return
 	 */
-	@SuppressWarnings("unchecked")
-	private <V> Cache<V> getThreadCache(String name) {
-		Map<String, Cache<?>> threadCacheMap = threadCacheMapHolder.get();
-		Cache<V> threadCache = (Cache<V>) threadCacheMap.get(name);
-		if (threadCache == null) {
-			threadCache = new MapCacheImpl<V>();
-			threadCacheMap.put(name, threadCache);
-		}
-		return threadCache;
-	}
-
-	/**
-	 * Generate a cache bound to the request
-	 * 
-	 * @param name
-	 * @return
-	 */
-	@SuppressWarnings("unchecked")
-	private <V> Cache<V> getRequestCache(String name) {
-		Map<String, Cache<?>> requestCacheMap = requestCacheMapHolder.get();
-		Cache<V> requestCache = (Cache<V>) requestCacheMap.get(name);
-		if (requestCache == null) {
-			requestCache = new MapCacheImpl<V>();
-			requestCacheMap.put(name, requestCache);
-		}
-		return requestCache;
-	}
-
-	/**
-	 * @param name
-	 * @return
-	 */
-	@SuppressWarnings("unchecked")
-	private <V> Cache<V> getInstanceCache(String name) {
+	@Override
+	protected <V> Cache<V> getInstanceCache(String name) {
 		if (name == null) {
 			return new CacheImpl<V>(cacheManager, null);
 		} else {
+			@SuppressWarnings("unchecked")
 			Cache<V> c = (Cache<V>) caches.get(name);
 			if (c == null) {
 				c = new CacheImpl<V>(cacheManager, name);
@@ -272,44 +174,6 @@ public class CacheManagerServiceImpl imp
 		}
 	}
 
-	/**
-	 * {@inheritDoc}
-	 * 
-	 * @see org.apache.sling.commons.cache.api.CacheManagerService#unbind(org.apache.sling.commons.cache.api.CacheScope)
-	 */
-	public void unbind(CacheScope scope) {
-		switch (scope) {
-		case REQUEST:
-			unbindRequest();
-			break;
-		case THREAD:
-			unbindThread();
-			break;
-		default:
-			break;
-		}
-	}
 
-	/**
-   *
-   */
-	private void unbindThread() {
-		Map<String, Cache<?>> threadCache = threadCacheMapHolder.get();
-		for (Cache<?> cache : threadCache.values()) {
-			cache.clear();
-		}
-		threadCacheMapHolder.remove();
-	}
-
-	/**
-   *
-   */
-	private void unbindRequest() {
-		Map<String, Cache<?>> requestCache = requestCacheMapHolder.get();
-		for (Cache<?> cache : requestCache.values()) {
-			cache.clear();
-		}
-		requestCacheMapHolder.remove();
-	}
 
 }

Copied: sling/whiteboard/ieb/cache/impl/README.txt (from r1403171, sling/whiteboard/ieb/cache/ehcache/README.txt)
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/impl/README.txt?p2=sling/whiteboard/ieb/cache/impl/README.txt&p1=sling/whiteboard/ieb/cache/ehcache/README.txt&r1=1403171&r2=1403180&rev=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/README.txt (original)
+++ sling/whiteboard/ieb/cache/impl/README.txt Mon Oct 29 07:06:20 2012
@@ -1,6 +1,8 @@
-Commons Cache.
+EhCache Implementation of the CacheManagerService.
 
-This is an implementation of the Cache API based on EhCache.
+This is support jar for implementing Cache services. It contains an abstract implementation of all the in
+memory versions of cache that the cache service has to supply leaving instance, cluster invalidated and cluster
+replicated caches upto the supporting cache library.
 
 
 Acknowledgments

Copied: sling/whiteboard/ieb/cache/impl/pom.xml (from r1403171, sling/whiteboard/ieb/cache/ehcache/pom.xml)
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/impl/pom.xml?p2=sling/whiteboard/ieb/cache/impl/pom.xml&p1=sling/whiteboard/ieb/cache/ehcache/pom.xml&r1=1403171&r2=1403180&rev=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/pom.xml (original)
+++ sling/whiteboard/ieb/cache/impl/pom.xml Mon Oct 29 07:06:20 2012
@@ -27,74 +27,33 @@
         <relativePath>../../../parent/pom.xml</relativePath>
     </parent>
 
-    <artifactId>org.apache.sling.commons.cache.ehcache</artifactId>
+    <artifactId>org.apache.sling.commons.cache.impl</artifactId>
     <version>0.1-SNAPSHOT</version>
-    <packaging>bundle</packaging>
+    <packaging>jar</packaging>
 
     <name>Apache Sling Cache API</name>
     <description>
-        This bundle provides an implementation of the Cache API using ehcache.
+        This bundle provides an implementation support for Cache implementations. It is a utility jar that should be embedded.
     </description>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/ehcache</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/ehcache</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/ehcache</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/impl</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/impl</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/impl</url>
     </scm>
     
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <version>2.3.6</version>
-                <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-		            <Import-Package>
-		               !sun.misc,
-		               !org.jgroups.*,
-		               !org.hibernate.cache,
-		               !edu.emory.mathcs.backport.java.util.*,
-		               *
-		            </Import-Package>
-		            <Private-Package>org.apache.sling.commons.cache.ehcache.*</Private-Package>
-		            <DynamicImport-Package>sun.misc.*</DynamicImport-Package>
-		            <Embed-Transitive>true</Embed-Transitive>
-		            <Embed-Dependency>ehcache,jsr107cache</Embed-Dependency>
-                    </instructions>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-
     <dependencies>
         <dependency>
 	       	<groupId>org.apache.sling</groupId>
 	       	<artifactId>org.apache.sling.commons.cache.api</artifactId>
 	       	<version>0.1-SNAPSHOT</version>
         </dependency>
+
         <dependency>
         	<groupId>commons-io</groupId>
         	<artifactId>commons-io</artifactId>
         	<version>1.4</version>
-        	<scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>net.sf.ehcache</groupId>
-      		<artifactId>ehcache</artifactId>
-      		<version>1.5.0</version>
-    	</dependency>
-	    <dependency>
-            <groupId>net.sf.jsr107cache</groupId>
-            <artifactId>jsr107cache</artifactId>
-            <version>1.0</version>
-	    </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
-            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
@@ -102,17 +61,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-        	<groupId>org.slf4j</groupId>
-        	<artifactId>slf4j-simple</artifactId>
-       		<scope>test</scope>
-        </dependency>
-         <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-all</artifactId>
-            <version>1.8.2</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>

Copied: sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/AbstractCacheManagerService.java (from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/CacheManagerServiceImpl.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/AbstractCacheManagerService.java?p2=sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/AbstractCacheManagerService.java&p1=sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/CacheManagerServiceImpl.java&r1=1403171&r2=1403180&rev=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/CacheManagerServiceImpl.java (original)
+++ sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/AbstractCacheManagerService.java Mon Oct 29 07:06:20 2012
@@ -17,186 +17,31 @@
  * under the License.
  */
 
-package org.apache.sling.commons.cache.ehcache;
+package org.apache.sling.commons.cache.impl;
 
 import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.management.ManagementFactory;
-import java.lang.ref.WeakReference;
-import java.util.HashMap;
 import java.util.Map;
 
-import javax.management.MBeanServer;
-
-import net.sf.ehcache.CacheManager;
-import net.sf.ehcache.management.ManagementService;
-
 import org.apache.commons.io.IOUtils;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.cache.api.Cache;
 import org.apache.sling.commons.cache.api.CacheManagerService;
 import org.apache.sling.commons.cache.api.CacheScope;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
- * The <code>CacheManagerServiceImpl</code>
+ * The <code>AbstractCacheManagerService</code>
  */
-@Component(immediate = true, metatype = true)
-@Service(value = CacheManagerService.class)
-public class CacheManagerServiceImpl implements CacheManagerService {
-
-	public static final String DEFAULT_CACHE_CONFIG = "sling/ehcacheConfig.xml";
-
-	@Property(value = DEFAULT_CACHE_CONFIG)
-	public static final String CACHE_CONFIG = "cache-config";
-
-	@Property(value = "The Apache Software Foundation")
-	static final String SERVICE_VENDOR = "service.vendor";
-
-	@Property(value = "Cache Manager Service Implementation")
-	static final String SERVICE_DESCRIPTION = "service.description";
-
-	@Property()
-	public static final String BIND_ADDRESS = "bind-address";
+public abstract class AbstractCacheManagerService implements CacheManagerService {
 
-	@Property(value = "sling/ehcache/data")
-	public static final String CACHE_STORE = "cache-store";
 
-	private static final String CONFIG_PATH = "org/apache/sling/commons/cache/ehcache/ehcacheConfig.xml";
-
-	private static final Logger LOGGER = LoggerFactory
-			.getLogger(CacheManagerServiceImpl.class);
-	private CacheManager cacheManager;
-	private Map<String, Cache<?>> caches = new HashMap<String, Cache<?>>();
 	private ThreadLocalCacheMap requestCacheMapHolder = new ThreadLocalCacheMap();
 	private ThreadLocalCacheMap threadCacheMapHolder = new ThreadLocalCacheMap();
 
-	public CacheManagerServiceImpl() throws IOException {
-	}
-
-	@Activate
-	public void activate(Map<String, Object> properties)
-			throws FileNotFoundException, IOException {
-		String config = toString(properties.get(CACHE_CONFIG),
-				DEFAULT_CACHE_CONFIG);
-		File configFile = new File(config);
-		if (configFile.exists()) {
-			LOGGER.info("Configuring Cache from {} ",
-					configFile.getAbsolutePath());
-			InputStream in = null;
-			try {
-				in = processConfig(new FileInputStream(configFile), properties);
-				cacheManager = new CacheManager(in);
-			} finally {
-				if (in != null) {
-					in.close();
-				}
-			}
-		} else {
-			LOGGER.info("Configuring Cache from Classpath Default {} ",
-					CONFIG_PATH);
-			InputStream in = processConfig(this.getClass().getClassLoader()
-					.getResourceAsStream(CONFIG_PATH), properties);
-			if (in == null) {
-				throw new IOException(
-						"Unable to open config at classpath location "
-								+ CONFIG_PATH);
-			}
-			cacheManager = new CacheManager(in);
-			in.close();
-		}
-
-		final WeakReference<CacheManagerServiceImpl> ref = new WeakReference<CacheManagerServiceImpl>(
-				this);
-		/*
-		 * Add in a shutdown hook, for safety
-		 */
-		Runtime.getRuntime().addShutdownHook(new Thread() {
-			/*
-			 * (non-Javadoc)
-			 * 
-			 * @see java.lang.Thread#run()
-			 */
-			@Override
-			public void run() {
-				try {
-					CacheManagerServiceImpl cm = ref.get();
-					if (cm != null) {
-						cm.deactivate();
-					}
-				} catch (Throwable t) {
-					LOGGER.debug(t.getMessage(), t);
-				}
-			}
-		});
-
-		// register the cache manager with JMX
-		MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
-		ManagementService.registerMBeans(cacheManager, mBeanServer, true, true,
-				true, true);
-
+	public AbstractCacheManagerService() throws IOException {
 	}
 
-	private String toString(Object object, String defaultValue) {
-		if (object == null) {
-			return defaultValue;
-		}
-		return String.valueOf(object);
-	}
 
-	private InputStream processConfig(InputStream in,
-			Map<String, Object> properties) throws IOException {
-		if (in == null) {
-			return null;
-		}
-		StringBuilder config = new StringBuilder(IOUtils.toString(in, "UTF-8"));
-		in.close();
-		int pos = 0;
-		for (;;) {
-			int start = config.indexOf("${", pos);
-			if (start < 0) {
-				break;
-			}
-			int end = config.indexOf("}", start);
-			if (end < 0) {
-				throw new IllegalArgumentException(
-						"Config file malformed, unterminated variable "
-								+ config.substring(start,
-										Math.min(start + 10, config.length())));
-			}
-			String key = config.substring(start + 2, end);
-			if (properties.containsKey(key)) {
-				String replacement = (String) properties.get(key);
-				config.replace(start, end + 1, replacement);
-				pos = start + replacement.length();
-			} else {
-				throw new IllegalArgumentException(
-						"Missing replacement property " + key);
-			}
-		}
-		return new ByteArrayInputStream(config.toString().getBytes("UTF-8"));
-
-	}
-
-	/**
-	 * perform a shutdown
-	 */
-	@Deactivate
-	public void deactivate() {
-		if (cacheManager != null) {
-			cacheManager.shutdown();
-			cacheManager = null;
-		}
-	}
 
 	/**
 	 * {@inheritDoc}
@@ -219,6 +64,8 @@ public class CacheManagerServiceImpl imp
 			return getInstanceCache(name);
 		}
 	}
+	
+	
 
 	/**
 	 * Generate a cache bound to the thread.
@@ -227,7 +74,7 @@ public class CacheManagerServiceImpl imp
 	 * @return
 	 */
 	@SuppressWarnings("unchecked")
-	private <V> Cache<V> getThreadCache(String name) {
+	protected <V> Cache<V> getThreadCache(String name) {
 		Map<String, Cache<?>> threadCacheMap = threadCacheMapHolder.get();
 		Cache<V> threadCache = (Cache<V>) threadCacheMap.get(name);
 		if (threadCache == null) {
@@ -244,7 +91,7 @@ public class CacheManagerServiceImpl imp
 	 * @return
 	 */
 	@SuppressWarnings("unchecked")
-	private <V> Cache<V> getRequestCache(String name) {
+	protected <V> Cache<V> getRequestCache(String name) {
 		Map<String, Cache<?>> requestCacheMap = requestCacheMapHolder.get();
 		Cache<V> requestCache = (Cache<V>) requestCacheMap.get(name);
 		if (requestCache == null) {
@@ -258,19 +105,7 @@ public class CacheManagerServiceImpl imp
 	 * @param name
 	 * @return
 	 */
-	@SuppressWarnings("unchecked")
-	private <V> Cache<V> getInstanceCache(String name) {
-		if (name == null) {
-			return new CacheImpl<V>(cacheManager, null);
-		} else {
-			Cache<V> c = (Cache<V>) caches.get(name);
-			if (c == null) {
-				c = new CacheImpl<V>(cacheManager, name);
-				caches.put(name, c);
-			}
-			return c;
-		}
-	}
+	protected abstract <V> Cache<V> getInstanceCache(String name);
 
 	/**
 	 * {@inheritDoc}
@@ -311,5 +146,49 @@ public class CacheManagerServiceImpl imp
 		}
 		requestCacheMapHolder.remove();
 	}
+	
+
+	protected String toString(Object object, String defaultValue) {
+		if (object == null) {
+			return defaultValue;
+		}
+		return String.valueOf(object);
+	}
+
+	
+	protected InputStream processConfig(InputStream in,
+			Map<String, Object> properties) throws IOException {
+		if (in == null) {
+			return null;
+		}
+		StringBuilder config = new StringBuilder(IOUtils.toString(in, "UTF-8"));
+		in.close();
+		int pos = 0;
+		for (;;) {
+			int start = config.indexOf("${", pos);
+			if (start < 0) {
+				break;
+			}
+			int end = config.indexOf("}", start);
+			if (end < 0) {
+				throw new IllegalArgumentException(
+						"Config file malformed, unterminated variable "
+								+ config.substring(start,
+										Math.min(start + 10, config.length())));
+			}
+			String key = config.substring(start + 2, end);
+			if (properties.containsKey(key)) {
+				String replacement = (String) properties.get(key);
+				config.replace(start, end + 1, replacement);
+				pos = start + replacement.length();
+			} else {
+				throw new IllegalArgumentException(
+						"Missing replacement property " + key);
+			}
+		}
+		return new ByteArrayInputStream(config.toString().getBytes("UTF-8"));
+
+	}
+
 
 }

Copied: sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapCacheImpl.java (from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapCacheImpl.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapCacheImpl.java?p2=sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapCacheImpl.java&p1=sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapCacheImpl.java&r1=1403171&r2=1403180&rev=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapCacheImpl.java (original)
+++ sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapCacheImpl.java Mon Oct 29 07:06:20 2012
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.commons.cache.ehcache;
+package org.apache.sling.commons.cache.impl;
 
 import java.util.ArrayList;
 import java.util.HashMap;

Propchange: sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapCacheImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapDeligate.java (from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapDeligate.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapDeligate.java?p2=sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapDeligate.java&p1=sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapDeligate.java&r1=1403171&r2=1403180&rev=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/MapDeligate.java (original)
+++ sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapDeligate.java Mon Oct 29 07:06:20 2012
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.commons.cache.ehcache;
+package org.apache.sling.commons.cache.impl;
 
 import java.util.Collection;
 import java.util.Map;

Propchange: sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/MapDeligate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/ThreadLocalCacheMap.java (from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ThreadLocalCacheMap.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/ThreadLocalCacheMap.java?p2=sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/ThreadLocalCacheMap.java&p1=sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ThreadLocalCacheMap.java&r1=1403171&r2=1403180&rev=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ThreadLocalCacheMap.java (original)
+++ sling/whiteboard/ieb/cache/impl/src/main/java/org/apache/sling/commons/cache/impl/ThreadLocalCacheMap.java Mon Oct 29 07:06:20 2012
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.sling.commons.cache.ehcache;
+package org.apache.sling.commons.cache.impl;
 
 import java.util.HashMap;
 import java.util.Map;

Added: sling/whiteboard/ieb/cache/infinispan/README.txt
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/README.txt?rev=1403180&view=auto
==============================================================================
--- sling/whiteboard/ieb/cache/infinispan/README.txt (added)
+++ sling/whiteboard/ieb/cache/infinispan/README.txt Mon Oct 29 07:06:20 2012
@@ -0,0 +1,5 @@
+Infinispan Implementation of the CacheManagerService.
+
+This is an implementation of the Cache service using Infinispan from JBoss. It may not be suitable for inclusion in 
+Sling since Infinispan is LGPL v2.1
+

Propchange: sling/whiteboard/ieb/cache/infinispan/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/ieb/cache/infinispan/README.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: sling/whiteboard/ieb/cache/infinispan/pom.xml (from r1403171, sling/whiteboard/ieb/cache/ehcache/pom.xml)
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/pom.xml?p2=sling/whiteboard/ieb/cache/infinispan/pom.xml&p1=sling/whiteboard/ieb/cache/ehcache/pom.xml&r1=1403171&r2=1403180&rev=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/pom.xml (original)
+++ sling/whiteboard/ieb/cache/infinispan/pom.xml Mon Oct 29 07:06:20 2012
@@ -27,19 +27,19 @@
         <relativePath>../../../parent/pom.xml</relativePath>
     </parent>
 
-    <artifactId>org.apache.sling.commons.cache.ehcache</artifactId>
+    <artifactId>org.apache.sling.commons.cache.infinispan</artifactId>
     <version>0.1-SNAPSHOT</version>
     <packaging>bundle</packaging>
 
     <name>Apache Sling Cache API</name>
     <description>
-        This bundle provides an implementation of the Cache API using ehcache.
+        This bundle provides an implementation of the Cache API using infinispan.
     </description>
 
     <scm>
-        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/ehcache</connection>
-        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/ehcache</developerConnection>
-        <url>http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/ehcache</url>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/infinispan</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/infinispan</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan</url>
     </scm>
     
 
@@ -53,16 +53,26 @@
                 <configuration>
                     <instructions>
 		            <Import-Package>
-		               !sun.misc,
-		               !org.jgroups.*,
-		               !org.hibernate.cache,
-		               !edu.emory.mathcs.backport.java.util.*,
+		               !org.jboss.logmanager, 
+		               !org.jboss.modules,
+		               !net.jcip.annotations,
+		               !org.testng,
+		               !org.testng.annotations,
 		               *
 		            </Import-Package>
-		            <Private-Package>org.apache.sling.commons.cache.ehcache.*</Private-Package>
+		            <Private-Package>
+		            	org.apache.sling.commons.cache.infinispan.*,
+		            	org.apache.sling.commons.cache.impl.*
+		            	</Private-Package>
 		            <DynamicImport-Package>sun.misc.*</DynamicImport-Package>
 		            <Embed-Transitive>true</Embed-Transitive>
-		            <Embed-Dependency>ehcache,jsr107cache</Embed-Dependency>
+		            <Embed-Dependency>
+		            infinispan-core,
+		            jgroups,
+		            jboss-marshalling,
+		            jboss-logging,
+		            jboss-marshalling-river
+		            </Embed-Dependency>
                     </instructions>
                 </configuration>
             </plugin>
@@ -76,21 +86,15 @@
 	       	<version>0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
-        	<groupId>commons-io</groupId>
-        	<artifactId>commons-io</artifactId>
-        	<version>1.4</version>
-        	<scope>provided</scope>
+	       	<groupId>org.apache.sling</groupId>
+	       	<artifactId>org.apache.sling.commons.cache.impl</artifactId>
+	       	<version>0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
-            <groupId>net.sf.ehcache</groupId>
-      		<artifactId>ehcache</artifactId>
-      		<version>1.5.0</version>
-    	</dependency>
-	    <dependency>
-            <groupId>net.sf.jsr107cache</groupId>
-            <artifactId>jsr107cache</artifactId>
-            <version>1.0</version>
-	    </dependency>
+            <groupId>org.infinispan</groupId>
+            <artifactId>infinispan-core</artifactId>
+            <version>5.1.8.Final</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.scr.annotations</artifactId>

Added: sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheImpl.java?rev=1403180&view=auto
==============================================================================
--- sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheImpl.java (added)
+++ sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheImpl.java Mon Oct 29 07:06:20 2012
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.commons.cache.infinispan;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+import org.apache.sling.commons.cache.api.Cache;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class CacheImpl<V> implements Cache<V> {
+
+	private static final Logger LOGGER = LoggerFactory
+			.getLogger(CacheImpl.class);
+	private String cacheName;
+	private long miss;
+	private long hits;
+	private long gets;
+	private org.infinispan.Cache<String, V> cache;
+
+	/**
+	 * @param cacheManager
+	 * @param name
+	 */
+	public CacheImpl(EmbeddedCacheManager cacheManager, String name) {
+		if (name == null) {
+			cacheName = "default";
+		} else {
+			cacheName = name;
+		}
+		synchronized (cacheManager) {
+			cache = cacheManager.getCache(cacheName, true);
+			if (cache == null) {
+				throw new RuntimeException(
+						"Failed to create Cache with name " + cacheName);
+			}
+		}
+	}
+
+	/**
+	 * {@inherit-doc}
+	 * 
+	 * @see org.apache.sling.commons.cache.api.Cache#clear()
+	 */
+	public void clear() {
+		cache.clear();
+	}
+
+	/**
+	 * {@inherit-doc}
+	 * 
+	 * @see org.apache.sling.commons.cache.api.Cache#containsKey(java.lang.String)
+	 */
+	public boolean containsKey(String key) {
+		return cache.containsKey(key);
+	}
+
+	/**
+	 * {@inherit-doc}
+	 * 
+	 * @see org.apache.sling.commons.cache.api.Cache#get(java.lang.String)
+	 */
+	public V get(String key) {
+		return stats(cache.get(key));
+	}
+
+	/**
+	 * Records stats
+	 * 
+	 * @param objectValue
+	 * @return the Object Value
+	 */
+	@SuppressWarnings("unchecked")
+	private V stats(Object objectValue) {
+		if (objectValue == null) {
+			miss++;
+		} else {
+			hits++;
+		}
+		gets++;
+		if (gets % 1000 == 0) {
+			long hp = (100 * hits) / gets;
+			long mp = (100 * miss) / gets;
+			LOGGER.info(
+					"{} Cache Stats hits {} ({}%), misses {} ({}%), calls {}",
+					new Object[] { cacheName, hits, hp, miss, mp, gets });
+		}
+		return (V) objectValue;
+	}
+
+	/**
+	 * {@inherit-doc}
+	 * 
+	 * @see org.apache.sling.commons.cache.api.Cache#put(java.lang.String,
+	 *      java.lang.Object)
+	 */
+	public V put(String key, V payload) {
+		V previous = null;
+		if (cache.containsKey(key)) {
+			V v = cache.get(key);
+			if (v != null) {
+				previous = (V) v;
+			}
+		}
+		cache.put(key, payload);
+		return previous;
+	}
+
+	/**
+	 * {@inherit-doc}
+	 * 
+	 * @see org.apache.sling.commons.cache.api.Cache#remove(java.lang.String)
+	 */
+	public void remove(String key) {
+		cache.remove(key);
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * 
+	 * @see org.apache.sling.commons.cache.api.Cache#removeChildren(java.lang.String)
+	 */
+	public void removeChildren(String key) {
+		cache.remove(key);
+		if (!key.endsWith("/")) {
+			key = key + "/";
+		}
+		for (String k : cache.keySet()) {
+			if (k.startsWith(key)) {
+				cache.remove(k);
+			}
+		}
+	}
+
+	/**
+	 * {@inheritDoc}
+	 * 
+	 * @see org.apache.sling.commons.cache.api.Cache#list()
+	 */
+	public List<V> list() {
+		List<V> values = new ArrayList<V>();
+		for (String k : cache.keySet()) {
+			V v = cache.get(k);
+			if (v != null) {
+				values.add(v);
+			}
+		}
+		return values;
+	}
+
+}

Propchange: sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java?rev=1403180&view=auto
==============================================================================
--- sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java (added)
+++ sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java Mon Oct 29 07:06:20 2012
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.cache.infinispan;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.ref.WeakReference;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.commons.cache.api.Cache;
+import org.apache.sling.commons.cache.api.CacheManagerService;
+import org.apache.sling.commons.cache.impl.AbstractCacheManagerService;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(immediate = true, metatype = true)
+@Service(value = CacheManagerService.class)
+public class CacheManagerServiceImpl extends AbstractCacheManagerService {
+
+	public static final String DEFAULT_CACHE_CONFIG = "sling/infinispanConfig.xml";
+
+	@Property(value = DEFAULT_CACHE_CONFIG)
+	public static final String CACHE_CONFIG = "cache-config";
+
+	@Property(value = "The Apache Software Foundation")
+	static final String SERVICE_VENDOR = "service.vendor";
+
+	@Property(value = "Cache Manager Service Implementation")
+	static final String SERVICE_DESCRIPTION = "service.description";
+
+	@Property()
+	public static final String BIND_ADDRESS = "bind-address";
+
+	@Property(value = "sling/infinispan/data")
+	public static final String CACHE_STORE = "cache-store";
+
+	private static final String CONFIG_PATH = "org/apache/sling/commons/cache/infinispan/config.xml";
+
+	private static final Logger LOGGER = LoggerFactory
+			.getLogger(CacheManagerServiceImpl.class);
+	private EmbeddedCacheManager cacheManager;
+	private Map<String, Cache<?>> caches = new ConcurrentHashMap<String, Cache<?>>();
+
+
+	public CacheManagerServiceImpl() throws IOException {
+		super();
+	}
+
+	@Activate
+	public void activate(Map<String, Object> properties)
+			throws FileNotFoundException, IOException {
+
+		String config = toString(properties.get(CACHE_CONFIG),
+				DEFAULT_CACHE_CONFIG);
+		File configFile = new File(config);
+		if (configFile.exists()) {
+			LOGGER.info("Configuring Cache from {} ",
+					configFile.getAbsolutePath());
+			InputStream in = null;
+			try {
+				in = processConfig(new FileInputStream(configFile), properties);
+				cacheManager  = new DefaultCacheManager(in);
+			} finally {
+				if (in != null) {
+					in.close();
+				}
+			}
+		} else {
+			LOGGER.info("Configuring Cache from Classpath Default {} ",
+					CONFIG_PATH);
+			InputStream in = processConfig(this.getClass().getClassLoader()
+					.getResourceAsStream(CONFIG_PATH), properties);
+			if (in == null) {
+				throw new IOException(
+						"Unable to open config at classpath location "
+								+ CONFIG_PATH);
+			}
+			cacheManager  = new DefaultCacheManager(in);
+			in.close();
+		}
+		
+
+		final WeakReference<CacheManagerServiceImpl> ref = new WeakReference<CacheManagerServiceImpl>(
+				this);
+		/*
+		 * Add in a shutdown hook, for safety
+		 */
+		Runtime.getRuntime().addShutdownHook(new Thread() {
+			/*
+			 * (non-Javadoc)
+			 * 
+			 * @see java.lang.Thread#run()
+			 */
+			@Override
+			public void run() {
+				try {
+					CacheManagerServiceImpl cm = ref.get();
+					if (cm != null) {
+						cm.deactivate();
+					}
+				} catch (Throwable t) {
+					LOGGER.debug(t.getMessage(), t);
+				}
+			}
+		});
+
+		// JMX Registration is performed by configuration
+	}
+	
+	/**
+	 * perform a shutdown
+	 */
+	@Deactivate
+	public void deactivate() {
+		if (cacheManager != null) {
+			cacheManager.stop();
+			cacheManager = null;
+		}
+	}
+
+
+
+	@Override
+	protected <V> Cache<V> getInstanceCache(String name) {
+		if (name == null) {
+			return new CacheImpl<V>(cacheManager, null);
+		} else {
+			@SuppressWarnings("unchecked")
+			Cache<V> c = (Cache<V>) caches.get(name);
+			if (c == null) {
+				c = new CacheImpl<V>(cacheManager, name);
+				caches.put(name, c);
+			}
+			return c;
+		}
+	}
+
+}

Propchange: sling/whiteboard/ieb/cache/infinispan/src/main/java/org/apache/sling/commons/cache/infinispan/CacheManagerServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/cache/infinispan/config.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/cache/infinispan/config.xml?rev=1403180&view=auto
==============================================================================
--- sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/cache/infinispan/config.xml (added)
+++ sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/cache/infinispan/config.xml Mon Oct 29 07:06:20 2012
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<infinispan>   
+</infinispan>
\ No newline at end of file

Propchange: sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/cache/infinispan/config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/ieb/cache/infinispan/src/main/resources/org/apache/sling/commons/cache/infinispan/config.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheConfigTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheConfigTest.java?rev=1403180&view=auto
==============================================================================
--- sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheConfigTest.java (added)
+++ sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheConfigTest.java Mon Oct 29 07:06:20 2012
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.cache.infinispan;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.sling.commons.cache.api.Cache;
+import org.apache.sling.commons.cache.api.CacheScope;
+import org.apache.sling.commons.cache.api.ThreadBound;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class CacheConfigTest {
+
+	private CacheManagerServiceImpl cacheManagerService;
+
+	@Before
+	public void setUp() throws IOException, InstantiationException,
+			IllegalAccessException, ClassNotFoundException {
+		cacheManagerService = new CacheManagerServiceImpl();
+		Map<String, Object> properties = MapBuilder.getMap(CacheManagerServiceImpl.CACHE_STORE,
+				(Object) "target/ehcache/store", 
+				CacheManagerServiceImpl.BIND_ADDRESS, "127.0.0.1",
+				CacheManagerServiceImpl.CACHE_CONFIG, "src/test/resources/testconfig/simple-ehcacheConfig.xml"
+				);
+		cacheManagerService.activate(properties);
+	}
+
+
+	@After
+	public void tearDown() {
+		cacheManagerService.deactivate();
+	}
+
+	private void exerciseCache(String cacheName, CacheScope scope) {
+		Cache<String> cache = cacheManagerService.getCache(cacheName, scope);
+		cache.put("fish", "cat");
+		assertTrue("Expected element to be in cache", cache.containsKey("fish"));
+		Cache<String> sameCache = cacheManagerService
+				.getCache(cacheName, scope);
+		assertEquals("Expected cache to work", "cat", sameCache.get("fish"));
+		sameCache.put("fish", "differentcat");
+		assertEquals("Expected cache value to propogate", "differentcat",
+				cache.get("fish"));
+		sameCache.remove("fish");
+		sameCache.remove("another");
+		assertNull("Expected item to be removed from cache", cache.get("fish"));
+		cache.put("foo", "bar");
+		cache.clear();
+		assertNull("Expected cache to be empty", cache.get("foo"));
+		cacheManagerService.unbind(scope);
+	}
+
+	@Test
+	public void testCacheStorage() {
+		for (CacheScope scope : CacheScope.values()) {
+			exerciseCache("TestCache", scope);
+		}
+	}
+
+	@Test
+	public void testNullCacheNames() {
+		for (CacheScope scope : CacheScope.values()) {
+			exerciseCache(null, scope);
+		}
+	}
+
+	@Test
+	public void testCacheWithChildKeys() {
+		for (CacheScope scope : CacheScope.values()) {
+			String cacheName = "SomeTestCache";
+			Cache<String> cache = cacheManagerService
+					.getCache(cacheName, scope);
+			cache.put("fish", "cat");
+			assertTrue("Expected element to be in cache",
+					cache.containsKey("fish"));
+			cache.put("fish/child", "childcat");
+			cache.put("fish/child/child", "childcatchild");
+			Cache<String> sameCache = cacheManagerService.getCache(cacheName,
+					scope);
+			sameCache.removeChildren("fish/child/child");
+			assertNull("Expected key to be removed",
+					cache.get("fish/child/child"));
+			sameCache.removeChildren("fish");
+			assertNull("Expected key to be removed", cache.get("fish"));
+			assertNull("Expected key to be removed", cache.get("fish/child"));
+		}
+	}
+
+	@Test
+	public void testThreadUnbinding() {
+		ThreadBound testItem = Mockito.mock(ThreadBound.class);
+		Cache<ThreadBound> threadBoundCache = cacheManagerService.getCache(
+				"testCache", CacheScope.THREAD);
+		threadBoundCache.put("testItem", testItem);
+		threadBoundCache.remove("testItem");
+		threadBoundCache.put("testItem", testItem);
+		threadBoundCache.clear();
+		
+		Mockito.verify(testItem, Mockito.times(2)).unbind();
+	}
+
+}

Propchange: sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/CacheConfigTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/MapBuilder.java (from r1403171, sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ThreadLocalCacheMap.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/MapBuilder.java?p2=sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/MapBuilder.java&p1=sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ThreadLocalCacheMap.java&r1=1403171&r2=1403180&rev=1403180&view=diff
==============================================================================
--- sling/whiteboard/ieb/cache/ehcache/src/main/java/org/apache/sling/commons/cache/ehcache/ThreadLocalCacheMap.java (original)
+++ sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/MapBuilder.java Mon Oct 29 07:06:20 2012
@@ -16,28 +16,26 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+package org.apache.sling.commons.cache.infinispan;
+
 
-package org.apache.sling.commons.cache.ehcache;
 
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.sling.commons.cache.api.Cache;
-
 /**
- * Represents a Cache stored on the thread, used in the request thread and in
- * other threads. When used in Threads there is a potential for memory leaks as
- * perm space is not cleaned up. This will be caused by references to
- * classloaders being in the Map, and keeping the classloaders open.
+ * A very simple class that avoids needing Guava as a dependency (aka Google Collections)
+ *
  */
-public class ThreadLocalCacheMap extends ThreadLocal<Map<String, Cache<?>>> {
-	/**
-	 * {@inheritDoc}
-	 * 
-	 * @see java.lang.ThreadLocal#initialValue()
-	 */
-	@Override
-	protected Map<String, Cache<?>> initialValue() {
-		return new HashMap<String, Cache<?>>();
+public class MapBuilder {
+
+	@SuppressWarnings("unchecked")
+	public static <K, V> Map<K, V> getMap(Object ... kv) {
+		Map<K,V> m = new HashMap<K, V>();
+		for ( int i = 0; i < kv.length; i+=2 ) {
+			m.put((K)kv[i], (V)kv[i+1]);
+		}
+		return m;
 	}
+
 }

Propchange: sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/MapBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/TestCache.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/TestCache.java?rev=1403180&view=auto
==============================================================================
--- sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/TestCache.java (added)
+++ sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/TestCache.java Mon Oct 29 07:06:20 2012
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.cache.infinispan;
+
+
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.sling.commons.cache.api.Cache;
+import org.apache.sling.commons.cache.api.CacheScope;
+import org.apache.sling.commons.cache.api.ThreadBound;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestCache {
+
+  private CacheManagerServiceImpl cacheManagerService;
+
+  @Before
+  public void setUp() throws IOException, InstantiationException, IllegalAccessException,
+      ClassNotFoundException {
+    cacheManagerService = new CacheManagerServiceImpl();
+    Map<String, Object> properties = MapBuilder.getMap("cache-store",(Object)"target/infinispan/store", "bind-address", "127.0.0.1");
+	cacheManagerService.activate(properties);
+  }
+  
+  @After
+  public void tearDown() {
+	  cacheManagerService.deactivate();
+  }
+
+  private void exerciseCache(String cacheName, CacheScope scope) {
+    Cache<String> cache = cacheManagerService.getCache(cacheName, scope);
+    cache.put("fish", "cat");
+    assertTrue("Expected element to be in cache", cache.containsKey("fish"));
+    Cache<String> sameCache = cacheManagerService.getCache(cacheName, scope);
+    assertEquals("Expected cache to work", "cat", sameCache.get("fish"));
+    sameCache.put("fish", "differentcat");
+    assertEquals("Expected cache value to propogate", "differentcat", cache.get("fish"));
+    sameCache.remove("fish");
+    sameCache.remove("another");
+    assertNull("Expected item to be removed from cache", cache.get("fish"));
+    cache.put("foo", "bar");
+    cache.clear();
+    assertNull("Expected cache to be empty", cache.get("foo"));
+    cacheManagerService.unbind(scope);
+  }
+
+  @Test
+  public void testCacheStorage() {
+    for (CacheScope scope : CacheScope.values()) {
+      exerciseCache("TestCache", scope);
+    }
+  }
+
+  @Test
+  public void testNullCacheNames() {
+    for (CacheScope scope : CacheScope.values()) {
+      exerciseCache(null, scope);
+    }
+  }
+
+  @Test
+  public void testCacheWithChildKeys() {
+    for (CacheScope scope : CacheScope.values()) {
+      String cacheName = "SomeTestCache";
+      Cache<String> cache = cacheManagerService.getCache(cacheName, scope);
+      cache.put("fish", "cat");
+      assertTrue("Expected element to be in cache", cache.containsKey("fish"));
+      cache.put("fish/child", "childcat");
+      cache.put("fish/child/child", "childcatchild");
+      Cache<String> sameCache = cacheManagerService.getCache(cacheName, scope);
+      sameCache.removeChildren("fish/child/child");
+      assertNull("Expected key to be removed", cache.get("fish/child/child"));
+      sameCache.removeChildren("fish");
+      assertNull("Expected key to be removed", cache.get("fish"));
+      assertNull("Expected key to be removed", cache.get("fish/child"));
+    }
+  }
+
+  @Test
+  public void testThreadUnbinding() {
+    ThreadBound testItem = Mockito.mock(ThreadBound.class);
+    Cache<ThreadBound> threadBoundCache = cacheManagerService.getCache("testCache",
+        CacheScope.THREAD);
+    threadBoundCache.put("testItem", testItem);
+    threadBoundCache.remove("testItem");
+    threadBoundCache.put("testItem", testItem);
+    threadBoundCache.clear();
+    
+    Mockito.verify(testItem, Mockito.times(2)).unbind();
+  }
+
+}

Propchange: sling/whiteboard/ieb/cache/infinispan/src/test/java/org/apache/sling/commons/cache/infinispan/TestCache.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message