-
- System.setProperty("ehcache.disk.store.dir", CdmUtils.getCdmHomeDir().getAbsolutePath() + File.separator + "cdmlib-model");
- try {
- // NOTE:Programmatically creating the cache manager may solve the problem of
- // recreating data written to disk on startup
- // see https://stackoverflow.com/questions/1729605/ehcache-persist-to-disk-issues
- //String cacheFilePath = CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE.getFile().getAbsolutePath();
- InputStream in = this.getClass().getClassLoader().getResourceAsStream("cdmlib-ehcache.xml");
- cdmlibModelCacheManager = new CacheManager(in);
-
- } catch (CacheException e) {
- throw new CdmClientCacheException(e);
- }
-// } catch (IOException e) {
-// throw new CdmClientCacheException(e);
-// }
+
+
+ try {
+ // NOTE:Programmatically creating the cache manager may solve the problem of
+ // recreating data written to disk on startup
+ // see https://stackoverflow.com/questions/1729605/ehcache-persist-to-disk-issues
+ //String cacheFilePath = CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE.getFile().getAbsolutePath();
+ //InputStream in = this.getClass().getClassLoader().getResourceAsStream("cdmlib-ehcache.xml");
+
+ SizeOfPolicyConfiguration sizeOfConfig = new SizeOfPolicyConfiguration();
+ sizeOfConfig.setMaxDepth(1000);
+ sizeOfConfig.setMaxDepthExceededBehavior("abort");
+
+ CacheConfiguration modelcc = new CacheConfiguration(CDM_MODEL_CACHE_NAME, 0)
+ .eternal(true)
+ .statistics(true)
+ .sizeOfPolicy(sizeOfConfig)
+ .overflowToOffHeap(false);
+
+ cdmlibModelCache = new Cache(modelcc);
+
+ CacheManager.create().addCache(cdmlibModelCache);
+ initCdmModelCache(cdmlibModelCache);
+
+ } catch (CacheException e) {
+ throw new CdmClientCacheException(e);
+ }
+
+ }
+
+ private void initCdmModelCache(final Cache cache) {
+
+ initThread = new Thread() {
+ @Override
+ public void run(){
+ synchronized (cdmlibModelCache) {
+ CdmModelCacher cmdmc = new CdmModelCacher();
+ cmdmc.cacheGetterFields(cache);
+ cacheInitialised = true;
+ logger.info("Initialisation of CDM getter fields complete");
+ cdmlibModelCache.notify();
+ }
+ }
+
+ };
+ initThread.start();