* This methods adds programmatically the required {@link CacheLoader} needed to prevent
* any {@link TimeoutException}
*/
private void addCacheLoader()
{
CacheLoaderConfig config = cache.getConfiguration().getCacheLoaderConfig();
List<IndividualCacheLoaderConfig> oldConfigs;
if (config == null || (oldConfigs = config.getIndividualCacheLoaderConfigs()) == null || oldConfigs.isEmpty())
{
if (LOG.isInfoEnabled())
{
LOG.info("No cache loader has been defined, thus no need to encapsulate any cache loader.");
}
return;
}
CacheLoaderManager clm =
((CacheSPI<Serializable, Object>)cache).getComponentRegistry().getComponent(CacheLoaderManager.class);
if (clm == null)
{
LOG.error("The CacheLoaderManager cannot be found");
return;
}
CacheLoader currentCL = clm.getCacheLoader();
if (currentCL == null)
{
LOG.error("The CacheLoader cannot be found");
return;
}
ControllerCacheLoader ccl = new ControllerCacheLoader(currentCL);
List<IndividualCacheLoaderConfig> newConfig = new ArrayList<IndividualCacheLoaderConfig>(1);
// create CacheLoaderConfig
IndividualCacheLoaderConfig cclConfig = new IndividualCacheLoaderConfig();
// set CacheLoader
cclConfig.setCacheLoader(ccl);
// set parameters
cclConfig.setFetchPersistentState(clm.isFetchPersistentState());
cclConfig.setAsync(false);
cclConfig.setIgnoreModifications(false);
CacheLoaderConfig.IndividualCacheLoaderConfig first = config.getFirstCacheLoaderConfig();
cclConfig.setPurgeOnStartup(first != null && first.isPurgeOnStartup());
newConfig.add(cclConfig);
config.setIndividualCacheLoaderConfigs(newConfig);
if (LOG.isInfoEnabled())
{
LOG.info("The configured cache loader has been encapsulated successfully");
}