Esempio n. 1
0
 /**
  * Constructor which specifies the cacheName as well as the sizeLimit, expireTime and
  * useSoftReference. The passed sizeLimit, expireTime and useSoftReference will be overridden by
  * values from cache.properties if found.
  *
  * @param sizeLimit The sizeLimit member is set to this value
  * @param expireTime The expireTime member is set to this value
  * @param cacheName The name of the cache.
  * @param useSoftReference Specifies whether or not to use soft references for this cache.
  */
 private UtilCache(
     String cacheName,
     int sizeLimit,
     int maxInMemory,
     long expireTimeMillis,
     boolean useSoftReference,
     boolean useFileSystemStore,
     String propName,
     String... propNames) {
   this.name = cacheName;
   this.sizeLimit = sizeLimit;
   this.maxInMemory = maxInMemory;
   this.expireTimeNanos = TimeUnit.NANOSECONDS.convert(expireTimeMillis, TimeUnit.MILLISECONDS);
   this.useSoftReference = useSoftReference;
   this.useFileSystemStore = useFileSystemStore;
   setPropertiesParams(propName);
   setPropertiesParams(propNames);
   int maxMemSize = this.maxInMemory;
   if (maxMemSize == 0) maxMemSize = sizeLimit;
   if (maxMemSize == 0) {
     memoryTable = new ConcurrentHashMap<Object, CacheLine<V>>();
   } else {
     memoryTable =
         new Builder<Object, CacheLine<V>>()
             .maximumWeightedCapacity(maxMemSize)
             .listener(this)
             .build();
   }
   if (this.useFileSystemStore) {
     // create the manager the first time it is needed
     jdbmMgr = fileManagers.get(fileStore);
     if (jdbmMgr == null) {
       Debug.logImportant(
           "Creating file system cache store for cache with name: " + cacheName, module);
       try {
         String hazeHome = System.getProperty("haze.home");
         if (hazeHome == null) {
           Debug.logError("No haze.home property set in environment", module);
         } else {
           jdbmMgr = new JdbmRecordManager(hazeHome + "/" + fileStore);
         }
       } catch (IOException e) {
         Debug.logError(
             e,
             "Error creating file system cache store for cache with name: " + cacheName,
             module);
       }
       fileManagers.putIfAbsent(fileStore, jdbmMgr);
     }
     jdbmMgr = fileManagers.get(fileStore);
     if (jdbmMgr != null) {
       try {
         this.fileTable = HTree.createInstance(jdbmMgr);
         jdbmMgr.setNamedObject(cacheName, this.fileTable.getRecid());
         jdbmMgr.commit();
       } catch (IOException e) {
         Debug.logError(e, module);
       }
     }
   }
 }