[exo-jcr-commits] exo-jcr SVN: r5334 - in kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services: cache/impl/infinispan/distributed and 2 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Dec 16 04:49:19 EST 2011
Author: nfilotto
Date: 2011-12-16 04:49:19 -0500 (Fri, 16 Dec 2011)
New Revision: 5334
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/AbstractMapper.java
Log:
EXOJCR-1682: Improve ISPN integration to support properly the distribution mode (kernel)
* Fixed some Sonar violations
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java 2011-12-15 17:46:42 UTC (rev 5333)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java 2011-12-16 09:49:19 UTC (rev 5334)
@@ -201,8 +201,9 @@
}
catch (Exception e)
{
- throw new ExoCacheInitException("Cannot initialize the CacheManager corresponding to the configuration '"
- + cacheConfigTemplate + "'", e);
+ throw new ExoCacheInitException(
+ "Cannot initialize the CacheManager corresponding to the configuration '" + cacheConfigTemplate
+ + "'", e);
}
GlobalConfiguration config = cacheManager.getGlobalConfiguration();
@@ -224,7 +225,7 @@
{
throw new ExoCacheInitException(e);
}
- }
+ }
}
/**
@@ -293,35 +294,36 @@
{
try
{
- cacheManager = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<DefaultCacheManager>()
- {
- public DefaultCacheManager run() throws Exception
+ cacheManager =
+ SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<DefaultCacheManager>()
{
- // A custom configuration has been set
- if (LOG.isInfoEnabled())
- LOG.info("A custom configuration has been set for the cache '" + region + "'.");
- // Create the CacheManager by loading the configuration
- DefaultCacheManager customCacheManager =
- new DefaultCacheManager(configManager.getInputStream(customConfig), false);
- GlobalConfiguration gc = customCacheManager.getGlobalConfiguration();
- // Configure JGroups and JMX since it could affect the state of the Global Config
- configureCacheManager(gc);
- // Check if a CacheManager with the same GlobalConfiguration exists
- DefaultCacheManager currentCacheManager = mappingGlobalConfigCacheManager.get(gc);
- if (currentCacheManager == null)
+ public DefaultCacheManager run() throws Exception
{
- // No cache manager has been defined so far for this Cache Configuration
- currentCacheManager = customCacheManager;
- // Use a different cache manager name to prevent naming conflict
- gc.fluent().globalJmxStatistics()
- .cacheManagerName(gc.getCacheManagerName() + "_" + region + "_" + ctx.getName());
- currentCacheManager.start();
- // We register this new cache manager
- mappingGlobalConfigCacheManager.put(gc, customCacheManager);
+ // A custom configuration has been set
+ if (LOG.isInfoEnabled())
+ LOG.info("A custom configuration has been set for the cache '" + region + "'.");
+ // Create the CacheManager by loading the configuration
+ DefaultCacheManager customCacheManager =
+ new DefaultCacheManager(configManager.getInputStream(customConfig), false);
+ GlobalConfiguration gc = customCacheManager.getGlobalConfiguration();
+ // Configure JGroups and JMX since it could affect the state of the Global Config
+ configureCacheManager(gc);
+ // Check if a CacheManager with the same GlobalConfiguration exists
+ DefaultCacheManager currentCacheManager = mappingGlobalConfigCacheManager.get(gc);
+ if (currentCacheManager == null)
+ {
+ // No cache manager has been defined so far for this Cache Configuration
+ currentCacheManager = customCacheManager;
+ // Use a different cache manager name to prevent naming conflict
+ gc.fluent().globalJmxStatistics()
+ .cacheManagerName(gc.getCacheManagerName() + "_" + region + "_" + ctx.getName());
+ currentCacheManager.start();
+ // We register this new cache manager
+ mappingGlobalConfigCacheManager.put(gc, customCacheManager);
+ }
+ return currentCacheManager;
}
- return currentCacheManager;
- }
- });
+ });
}
catch (PrivilegedActionException e)
{
@@ -334,7 +336,7 @@
{
throw new Exception(e);
}
- }
+ }
conf = cacheManager.getDefaultConfiguration().clone();
}
else if (config.isDistributed())
@@ -372,16 +374,17 @@
{
try
{
- return SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Cache<Serializable, Object>>()
- {
- public Cache<Serializable, Object> run() throws Exception
+ return SecurityHelper
+ .doPrivilegedExceptionAction(new PrivilegedExceptionAction<Cache<Serializable, Object>>()
{
- // Define the configuration
- cacheManager.defineConfiguration(region, conf);
- // create and start the cache
- return cacheManager.getCache(region);
- }
- });
+ public Cache<Serializable, Object> run() throws Exception
+ {
+ // Define the configuration
+ cacheManager.defineConfiguration(region, conf);
+ // create and start the cache
+ return cacheManager.getCache(region);
+ }
+ });
}
catch (PrivilegedActionException e)
{
@@ -394,7 +397,7 @@
{
throw new Exception(e);
}
- }
+ }
}
});
}
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java 2011-12-15 17:46:42 UTC (rev 5333)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java 2011-12-16 09:49:19 UTC (rev 5334)
@@ -82,7 +82,7 @@
*/
private static final Log LOG = ExoLogger
.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.DistributedExoCache");
-
+
public static final String CACHE_NAME = "eXoCache";
private final AtomicInteger hits = new AtomicInteger(0);
@@ -92,7 +92,7 @@
private String label;
private String name;
-
+
private final String fullName;
private boolean distributed;
@@ -118,12 +118,12 @@
setLogEnabled(config.isLogEnabled());
setReplicated(config.isRepicated());
}
-
+
AdvancedCache<CacheKey<K>, V> getCache()
{
return cache;
}
-
+
/**
* {@inheritDoc}
*/
@@ -164,7 +164,7 @@
}
lListeners.add(new ListenerContext<K, V>(listener, this));
}
-
+
@SuppressWarnings("rawtypes")
private ConcurrentMap<String, List<ListenerContext>> getOrCreateListeners()
{
@@ -187,7 +187,7 @@
ConcurrentMap<String, List<ListenerContext>> listeners = ALL_LISTENERS.get(cache);
return listeners == null ? null : listeners.get(fullName);
}
-
+
/**
* {@inheritDoc}
*/
@@ -199,7 +199,8 @@
@Override
public Void run()
{
- MapReduceTask<CacheKey<K>, V, String, CacheKey<K>> task = new MapReduceTask<CacheKey<K>, V, String, CacheKey<K>>(cache);
+ MapReduceTask<CacheKey<K>, V, String, CacheKey<K>> task =
+ new MapReduceTask<CacheKey<K>, V, String, CacheKey<K>>(cache);
task.mappedWith(new ClearCacheMapper<K, V>(fullName)).reducedWith(new ClearCacheReducer<String, V, K>());
task.execute();
return null;
@@ -270,7 +271,8 @@
@Override
public Map<String, Integer> run()
{
- MapReduceTask<CacheKey<K>, V, String, Integer> task = new MapReduceTask<CacheKey<K>, V, String, Integer>(cache);
+ MapReduceTask<CacheKey<K>, V, String, Integer> task =
+ new MapReduceTask<CacheKey<K>, V, String, Integer>(cache);
task.mappedWith(new GetSizeMapper<K, V>(fullName)).reducedWith(new GetSizeReducer<String>());
return task.execute();
}
@@ -281,7 +283,7 @@
{
sum += i;
}
- return sum;
+ return sum;
}
/**
@@ -295,8 +297,10 @@
@Override
public Map<String, List<V>> run()
{
- MapReduceTask<CacheKey<K>, V, String, List<V>> task = new MapReduceTask<CacheKey<K>, V, String, List<V>>(cache);
- task.mappedWith(new GetCachedObjectsMapper<K, V>(fullName)).reducedWith(new GetCachedObjectsReducer<String, V>());
+ MapReduceTask<CacheKey<K>, V, String, List<V>> task =
+ new MapReduceTask<CacheKey<K>, V, String, List<V>>(cache);
+ task.mappedWith(new GetCachedObjectsMapper<K, V>(fullName)).reducedWith(
+ new GetCachedObjectsReducer<String, V>());
return task.execute();
}
@@ -467,7 +471,7 @@
{
@Override
- public Map<K, V> run()
+ public Map<K, V> run()
{
MapReduceTask<CacheKey<K>, V, K, V> task = new MapReduceTask<CacheKey<K>, V, K, V>(cache);
task.mappedWith(new GetEntriesMapper<K, V>(fullName)).reducedWith(new GetEntriesReducer<K, V>());
@@ -475,7 +479,7 @@
}
});
-
+
for (K key : map.keySet())
{
if (key == null)
@@ -617,8 +621,8 @@
LOG.warn("Cannot execute the CacheListener properly", e);
}
}
- }
-
+ }
+
@SuppressWarnings({"rawtypes", "unchecked"})
void onGet(CacheKey<K> key, V obj)
{
@@ -814,14 +818,17 @@
{
return cache.getConfiguration().getExpirationWakeUpInterval();
}
-
+
public static class CacheKey<K> implements Externalizable
{
private K key;
-
+
private String fullName;
- public CacheKey() {}
+ public CacheKey()
+ {
+ }
+
public CacheKey(String fullName, K key)
{
this.fullName = fullName;
@@ -835,7 +842,7 @@
{
return key;
}
-
+
/**
* @return the fullName
*/
@@ -843,7 +850,7 @@
{
return fullName;
}
-
+
/**
* @see java.lang.Object#hashCode()
*/
@@ -895,7 +902,7 @@
public String toString()
{
return "CacheKey [fullName=" + fullName + ", key=" + key + "]";
- }
+ }
/**
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
@@ -918,29 +925,31 @@
in.readFully(buf);
fullName = new String(buf, "UTF-8");
key = (K)in.readObject();
- }
+ }
}
-
- private abstract static class AbstractExoCacheMapper<K, V, KOut, VOut> extends AbstractMapper<CacheKey<K>, V, KOut, VOut> implements Externalizable
+
+ private abstract static class AbstractExoCacheMapper<K, V, KOut, VOut> extends
+ AbstractMapper<CacheKey<K>, V, KOut, VOut> implements Externalizable
{
/**
* The full name of the cache instance
*/
private String fullName;
- public AbstractExoCacheMapper() {}
-
+ public AbstractExoCacheMapper()
+ {
+ }
+
public AbstractExoCacheMapper(String fullName)
{
this.fullName = fullName;
}
-
+
/**
* The serial version UID
*/
private static final long serialVersionUID = 7962676854308932222L;
-
/**
* @see org.exoplatform.services.ispn.AbstractMapper#isValid(java.lang.Object)
*/
@@ -968,31 +977,32 @@
byte[] buf = new byte[in.readInt()];
in.readFully(buf);
fullName = new String(buf, "UTF-8");
- }
+ }
}
-
+
public static class GetSizeMapper<K, V> extends AbstractExoCacheMapper<K, V, String, Integer>
{
- public GetSizeMapper() {}
-
+ public GetSizeMapper()
+ {
+ }
+
public GetSizeMapper(String fullName)
{
super(fullName);
}
-
-
+
/**
- * @see org.exoplatform.services.ispn.AbstractMapper#_map(java.lang.Object, java.lang.Object, org.infinispan.distexec.mapreduce.Collector)
+ * {@inheritDoc}
*/
@Override
protected void _map(CacheKey<K> key, V value, Collector<String, Integer> collector)
{
collector.emit("total", Integer.valueOf(1));
}
-
+
}
-
+
public static class GetSizeReducer<K> implements Reducer<K, Integer>
{
@@ -1014,31 +1024,32 @@
sum += i;
}
return sum;
- }
+ }
}
-
+
public static class GetCachedObjectsMapper<K, V> extends AbstractExoCacheMapper<K, V, String, List<V>>
{
- public GetCachedObjectsMapper() {}
-
+ public GetCachedObjectsMapper()
+ {
+ }
+
public GetCachedObjectsMapper(String fullName)
{
super(fullName);
}
-
-
+
/**
- * @see org.exoplatform.services.ispn.AbstractMapper#_map(java.lang.Object, java.lang.Object, org.infinispan.distexec.mapreduce.Collector)
+ * {@inheritDoc}
*/
@Override
protected void _map(CacheKey<K> key, V value, Collector<String, List<V>> collector)
{
collector.emit("values", Collections.singletonList(value));
}
-
- }
-
+
+ }
+
public static class GetCachedObjectsReducer<K, V> implements Reducer<K, List<V>>
{
@@ -1060,31 +1071,32 @@
values.addAll(vals);
}
return values;
- }
+ }
}
-
+
public static class ClearCacheMapper<K, V> extends AbstractExoCacheMapper<K, V, String, CacheKey<K>>
{
- public ClearCacheMapper() {}
-
+ public ClearCacheMapper()
+ {
+ }
+
public ClearCacheMapper(String fullName)
{
super(fullName);
}
-
-
+
/**
- * @see org.exoplatform.services.ispn.AbstractMapper#_map(java.lang.Object, java.lang.Object, org.infinispan.distexec.mapreduce.Collector)
+ * {@inheritDoc}
*/
@Override
protected void _map(CacheKey<K> key, V value, Collector<String, CacheKey<K>> collector)
{
collector.emit("keys", key);
}
-
- }
-
+
+ }
+
public static class ClearCacheReducer<K, V, KIn> implements Reducer<K, CacheKey<KIn>>
{
@@ -1110,7 +1122,8 @@
LOG.error("The top container could not be found");
return null;
}
- DistributedCacheManager dcm = (DistributedCacheManager)container.getComponentInstanceOfType(DistributedCacheManager.class);
+ DistributedCacheManager dcm =
+ (DistributedCacheManager)container.getComponentInstanceOfType(DistributedCacheManager.class);
if (dcm == null)
{
LOG.error("The DistributedCacheManager could not be found at top container level, please configure it.");
@@ -1134,32 +1147,33 @@
}
for (CacheKey<KIn> key : keys)
{
- cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.FAIL_SILENTLY).remove(key);
+ cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.FAIL_SILENTLY).remove(key);
}
return null;
- }
+ }
}
-
+
public static class GetEntriesMapper<K, V> extends AbstractExoCacheMapper<K, V, K, V>
{
- public GetEntriesMapper() {}
-
+ public GetEntriesMapper()
+ {
+ }
+
public GetEntriesMapper(String fullName)
{
super(fullName);
}
-
-
+
/**
- * @see org.exoplatform.services.ispn.AbstractMapper#_map(java.lang.Object, java.lang.Object, org.infinispan.distexec.mapreduce.Collector)
+ * {@inheritDoc}
*/
@Override
protected void _map(CacheKey<K> key, V value, Collector<K, V> collector)
{
collector.emit(key.getKey(), value);
- }
+ }
}
-
+
public static class GetEntriesReducer<K, V> implements Reducer<K, V>
{
@@ -1175,6 +1189,6 @@
public V reduce(K reducedKey, Iterator<V> iter)
{
return iter == null || !iter.hasNext() ? null : iter.next();
- }
+ }
}
}
\ No newline at end of file
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java 2011-12-15 17:46:42 UTC (rev 5333)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java 2011-12-16 09:49:19 UTC (rev 5334)
@@ -90,16 +90,16 @@
if (config instanceof GenericExoCacheConfig)
{
final GenericExoCacheConfig gConfig = (GenericExoCacheConfig)config;
- return create(config, cacheConfig, cacheGetter, gConfig.getStrategy(), gConfig.getMaxEntries(), gConfig
- .getLifespan(), gConfig.getMaxIdle() == 0 ? defaultMaxIdle : gConfig.getMaxIdle(), gConfig
- .getWakeUpInterval() == 0 ? defaultWakeUpInterval : gConfig.getWakeUpInterval());
+ return create(config, cacheConfig, cacheGetter, gConfig.getStrategy(), gConfig.getMaxEntries(),
+ gConfig.getLifespan(), gConfig.getMaxIdle() == 0 ? defaultMaxIdle : gConfig.getMaxIdle(),
+ gConfig.getWakeUpInterval() == 0 ? defaultWakeUpInterval : gConfig.getWakeUpInterval());
}
else
{
final long period = config.getLiveTime();
- return create(config, cacheConfig, cacheGetter, config.getImplementation() == null ? defaultStrategy : config
- .getImplementation(), config.getMaxSize(), period > 0 ? period * 1000 : -1, defaultMaxIdle,
- defaultWakeUpInterval);
+ return create(config, cacheConfig, cacheGetter,
+ config.getImplementation() == null ? defaultStrategy : config.getImplementation(), config.getMaxSize(),
+ period > 0 ? period * 1000 : -1, defaultMaxIdle, defaultWakeUpInterval);
}
}
@@ -111,7 +111,9 @@
Callable<Cache<Serializable, Object>> cacheGetter, String strategy, int maxEntries, long lifespan, long maxIdle,
long wakeUpInterval) throws ExoCacheInitException
{
- EvictionStrategy es = strategy == null || strategy.length() == 0 ? null : EvictionStrategy.valueOf(strategy.toUpperCase(Locale.ENGLISH));
+ EvictionStrategy es =
+ strategy == null || strategy.length() == 0 ? null : EvictionStrategy.valueOf(strategy
+ .toUpperCase(Locale.ENGLISH));
if (es == null)
{
es = EvictionStrategy.LRU;
@@ -172,8 +174,8 @@
}
@ManagedName("Lifespan")
- @ManagedDescription("Maximum lifespan of a cache entry, after which the entry is expired cluster-wide." +
- " -1 means the entries never expire.")
+ @ManagedDescription("Maximum lifespan of a cache entry, after which the entry is expired cluster-wide."
+ + " -1 means the entries never expire.")
public long getLiveTime()
{
return cacheConfig.getExpirationLifespan();
@@ -181,8 +183,8 @@
@Managed
@ManagedName("MaxIdle")
- @ManagedDescription("Maximum idle time a cache entry will be maintained in the cache. " +
- "If the idle time is exceeded, the entry will be expired cluster-wide. -1 means the entries never expire.")
+ @ManagedDescription("Maximum idle time a cache entry will be maintained in the cache. "
+ + "If the idle time is exceeded, the entry will be expired cluster-wide. -1 means the entries never expire.")
public long getMaxIdle()
{
return cacheConfig.getExpirationMaxIdle();
@@ -190,8 +192,8 @@
@Managed
@ManagedName("WakeUpInterval")
- @ManagedDescription("Interval between subsequent eviction runs. If you wish to disable the periodic eviction " +
- "process altogether, set wakeupInterval to -1.")
+ @ManagedDescription("Interval between subsequent eviction runs. If you wish to disable the periodic eviction "
+ + "process altogether, set wakeupInterval to -1.")
public long getWakeUpInterval()
{
return cacheConfig.getExpirationWakeUpInterval();
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/AbstractMapper.java
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/AbstractMapper.java 2011-12-15 17:46:42 UTC (rev 5333)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/AbstractMapper.java 2011-12-16 09:49:19 UTC (rev 5334)
@@ -37,7 +37,7 @@
private static final long serialVersionUID = 7118530772747505976L;
/**
- * @see org.infinispan.distexec.mapreduce.Mapper#map(java.lang.Object, java.lang.Object, org.infinispan.distexec.mapreduce.Collector)
+ * {@inheritDoc}
*/
@Override
public void map(KIn key, VIn value, Collector<KOut, VOut> collector)
@@ -49,9 +49,8 @@
}
/**
- * This method is in fact an internal mapping
- *
- * @see org.infinispan.distexec.mapreduce.Mapper#map(java.lang.Object, java.lang.Object, org.infinispan.distexec.mapreduce.Collector)
+ * This method is in fact an internal mapping, it will be called by the map method in
+ * case the given key matches with the context
*/
protected abstract void _map(KIn key, VIn value, Collector<KOut, VOut> collector);
More information about the exo-jcr-commits
mailing list