Author: abelevich
Date: 2009-07-29 14:10:34 -0400 (Wed, 29 Jul 2009)
New Revision: 15046
Added:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/AbstractCacheFactory.java
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/CacheManager.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/EhCacheCacheFactory.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/JBossCacheCacheFactory.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/LRUMapCacheFactory.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/OSCacheCacheFactory.java
Log:
Added:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/AbstractCacheFactory.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/AbstractCacheFactory.java
(rev 0)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/AbstractCacheFactory.java 2009-07-29
18:10:34 UTC (rev 15046)
@@ -0,0 +1,34 @@
+package org.ajax4jsf.cache;
+
+import java.util.Map;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public abstract class AbstractCacheFactory implements CacheFactory {
+
+ private RegisterCallback registerCallback;
+
+ public Cache createCache(String cacheName, Map<?,?> env) {
+ Cache cache = createCache(env);
+ if(registerCallback != null) {
+ if(cacheName == null) {
+ cacheName = cache.getClass().getName();
+ }
+ registerCallback.register(cacheName, cache);
+ }
+ return cache;
+ }
+
+ public abstract Cache createCache(Map <?,?> env);
+
+ public RegisterCallback getRegisterCallback() {
+ return registerCallback;
+ }
+
+ public void setRegisterCallback(RegisterCallback registerCallback) {
+ this.registerCallback = registerCallback;
+ }
+
+}
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/CacheManager.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/CacheManager.java 2009-07-29
16:00:43 UTC (rev 15045)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/CacheManager.java 2009-07-29
18:10:34 UTC (rev 15046)
@@ -49,8 +49,16 @@
// REVIEW brian(a)quiotix.com
// Should this be a HashMap<String, WeakReference<Cache>>?
- private final Map caches = Collections.synchronizedMap(new HashMap());
+ private final Map <String, Cache> caches = Collections.synchronizedMap(new
HashMap<String, Cache>());
+
+
+ private RegisterCallback _registerCallback = new RegisterCallback() {
+ public void register(String cacheName, Cache cache) {
+ registerCache(cacheName, cache);
+ }
+
+ };
/**
* Returns the singleton CacheManager
*/
@@ -59,14 +67,14 @@
}
public Cache getCache(String cacheName) {
- return (Cache) caches.get(cacheName);
+ return caches.get(cacheName);
}
public void registerCache(String cacheName, Cache cache) {
caches.put(cacheName, cache);
}
-
- public CacheFactory getCacheFactory(Map env) {
+
+ public AbstractCacheFactory getCacheFactory(Map env , boolean registerCacheOnCreate)
{
String[] factories;
String configuredFactoryName = findFactory(FACTORY_PROPERTY_NAME, env);
@@ -81,7 +89,11 @@
for (String factoryName : factories) {
try {
Class<?> spiClass = Class.forName(factoryName, true, loader);
- CacheFactory cacheFactory =
CacheFactory.class.cast(spiClass.newInstance());
+ //CacheFactory cacheFactory =
CacheFactory.class.cast(spiClass.newInstance());
+ AbstractCacheFactory cacheFactory =
AbstractCacheFactory.class.cast(spiClass.newInstance());
+ if(registerCacheOnCreate) {
+ cacheFactory.setRegisterCallback(_registerCallback);
+ }
log.info("Selected [" + factoryName + "]");
@@ -95,7 +107,11 @@
return new LRUMapCacheFactory();
}
- private ClassLoader findClassLoader() {
+ public Map <String, Cache> getCaches() {
+ return caches;
+ }
+
+ private ClassLoader findClassLoader() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) cl = ClassLoader.getSystemClassLoader();
return cl;
@@ -156,4 +172,5 @@
return null;
}
+
}
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/EhCacheCacheFactory.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/EhCacheCacheFactory.java 2009-07-29
16:00:43 UTC (rev 15045)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/EhCacheCacheFactory.java 2009-07-29
18:10:34 UTC (rev 15046)
@@ -12,7 +12,7 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class EhCacheCacheFactory implements CacheFactory {
+public class EhCacheCacheFactory extends AbstractCacheFactory {
private static final Log log = LogFactory.getLog(EhCacheCacheFactory.class);
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/JBossCacheCacheFactory.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/JBossCacheCacheFactory.java 2009-07-29
16:00:43 UTC (rev 15045)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/JBossCacheCacheFactory.java 2009-07-29
18:10:34 UTC (rev 15046)
@@ -25,7 +25,7 @@
*/
//TODO - to doc - no max size eviction support
-public class JBossCacheCacheFactory implements CacheFactory {
+public class JBossCacheCacheFactory extends AbstractCacheFactory {
private org.jboss.cache.CacheFactory<String, Object> cacheFactory;
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/LRUMapCacheFactory.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/LRUMapCacheFactory.java 2009-07-29
16:00:43 UTC (rev 15045)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/LRUMapCacheFactory.java 2009-07-29
18:10:34 UTC (rev 15046)
@@ -32,7 +32,7 @@
* created 01.05.2007
*
*/
-public class LRUMapCacheFactory implements CacheFactory {
+public class LRUMapCacheFactory extends AbstractCacheFactory {
private static final Log log = LogFactory.getLog(LRUMapCacheFactory.class);
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/OSCacheCacheFactory.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/OSCacheCacheFactory.java 2009-07-29
16:00:43 UTC (rev 15045)
+++
root/framework/trunk/impl/src/main/java/org/ajax4jsf/cache/OSCacheCacheFactory.java 2009-07-29
18:10:34 UTC (rev 15046)
@@ -38,7 +38,7 @@
* created 01.05.2007
*
*/
-public class OSCacheCacheFactory implements CacheFactory {
+public class OSCacheCacheFactory extends AbstractCacheFactory {
private static final Log log = LogFactory.getLog(OSCacheCacheFactory.class);
Show replies by date