Author: bpoussin Date: 2013-12-12 11:17:26 +0100 (Thu, 12 Dec 2013) New Revision: 3872 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/3872 Log: prevent '/ by zero' and refuse to adjuste cache to 0. Modified: trunk/src/main/java/fr/ifremer/isisfish/util/IsisCacheBackendOnGuava.java Modified: trunk/src/main/java/fr/ifremer/isisfish/util/IsisCacheBackendOnGuava.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/util/IsisCacheBackendOnGuava.java 2013-12-12 09:50:22 UTC (rev 3871) +++ trunk/src/main/java/fr/ifremer/isisfish/util/IsisCacheBackendOnGuava.java 2013-12-12 10:17:26 UTC (rev 3872) @@ -197,28 +197,32 @@ * @param amount new size of cache in byte */ public void adjustedCache(long amount){ - // on estime le nombre d'entree necessaire pour ce volume de donnees - long bytePerStep = totalCached / Math.max(1, numberStepCached); - long entriesPerStep = numberCached / Math.max(1, numberStepCached); + if (amount == 0) { + log.info("Cache size not ajusted because 0 is not acceptable amount"); + } else { + // on estime le nombre d'entree necessaire pour ce volume de donnees + long bytePerStep = totalCached / Math.max(1, numberStepCached); + long entriesPerStep = numberCached / Math.max(1, numberStepCached); - long initialCapacity = amount * entriesPerStep / Math.max(1, bytePerStep); - long stepEquivalent = initialCapacity / entriesPerStep; + long initialCapacity = amount * entriesPerStep / Math.max(1, bytePerStep); + long stepEquivalent = initialCapacity / Math.max(1, entriesPerStep); - // use amount as new size for cache - // if this new size is less than maxCache, use it - // to keep more memory for JVM - sizeCache = Math.min(this.maxCache, amount); + // use amount as new size for cache + // if this new size is less than maxCache, use it + // to keep more memory for JVM + sizeCache = Math.min(this.maxCache, amount); + + CacheBuilder builder = CacheBuilder.newBuilder(); + builder.maximumWeight(sizeCache); + builder.weigher(isisWeigher); + if (initialCapacity > 0) { + builder.initialCapacity((int)initialCapacity); + } + cache = builder.build(); - CacheBuilder builder = CacheBuilder.newBuilder(); - builder.maximumWeight(sizeCache); - builder.weigher(isisWeigher); - if (initialCapacity > 0) { - builder.initialCapacity((int)initialCapacity); + log.info(String.format("Cache size ajusted to %s (equivalent to %s step need)", + StringUtil.convertMemory(sizeCache), stepEquivalent)); } - cache = builder.build(); - - log.info(String.format("Cache size ajusted to %s (equivalent to %s step need)", - StringUtil.convertMemory(sizeCache), stepEquivalent)); } /**