Repository: incubator-blur Updated Branches: refs/heads/master 77e1f4f2f -> ec4b5260e
Fixing possible NPE for metric when asked for metric before construction of cache map is complete. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/19749a39 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/19749a39 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/19749a39 Branch: refs/heads/master Commit: 19749a390bf29ca799c911cc93a662fd57ad2c6d Parents: 77e1f4f Author: Aaron McCurry <[email protected]> Authored: Sat Apr 11 10:21:00 2015 -0400 Committer: Aaron McCurry <[email protected]> Committed: Sat Apr 11 10:21:00 2015 -0400 ---------------------------------------------------------------------- .../apache/blur/server/cache/ThriftCache.java | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/19749a39/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java b/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java index a1beb03..382fecd 100644 --- a/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java +++ b/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java @@ -84,6 +84,22 @@ public class ThriftCache { _hits = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, THRIFT_CACHE, HIT), HIT, TimeUnit.SECONDS); _misses = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, THRIFT_CACHE, MISS), MISS, TimeUnit.SECONDS); _evictions = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, THRIFT_CACHE, EVICTION), EVICTION, TimeUnit.SECONDS); + _cacheMap = new ConcurrentLinkedHashMap.Builder<ThriftCacheKey<?>, ThriftCacheValue<?>>() + .weigher(new EntryWeigher<ThriftCacheKey<?>, ThriftCacheValue<?>>() { + @Override + public int weightOf(ThriftCacheKey<?> key, ThriftCacheValue<?> value) { + return key.size() + value.size(); + } + }).listener(new EvictionListener<ThriftCacheKey<?>, ThriftCacheValue<?>>() { + @Override + public void onEviction(ThriftCacheKey<?> key, ThriftCacheValue<?> value) { + _evictions.mark(); + _evictionsAtomicLong.incrementAndGet(); + } + }).maximumWeightedCapacity(totalNumberOfBytes).build(); + _hitsAtomicLong = new AtomicLong(); + _missesAtomicLong = new AtomicLong(); + _evictionsAtomicLong = new AtomicLong(); Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, THRIFT_CACHE, SIZE), new Gauge<Long>() { @Override public Long value() { @@ -102,22 +118,6 @@ public class ThriftCache { return (long) _attributeKeys.size(); } }); - _cacheMap = new ConcurrentLinkedHashMap.Builder<ThriftCacheKey<?>, ThriftCacheValue<?>>() - .weigher(new EntryWeigher<ThriftCacheKey<?>, ThriftCacheValue<?>>() { - @Override - public int weightOf(ThriftCacheKey<?> key, ThriftCacheValue<?> value) { - return key.size() + value.size(); - } - }).listener(new EvictionListener<ThriftCacheKey<?>, ThriftCacheValue<?>>() { - @Override - public void onEviction(ThriftCacheKey<?> key, ThriftCacheValue<?> value) { - _evictions.mark(); - _evictionsAtomicLong.incrementAndGet(); - } - }).maximumWeightedCapacity(totalNumberOfBytes).build(); - _hitsAtomicLong = new AtomicLong(); - _missesAtomicLong = new AtomicLong(); - _evictionsAtomicLong = new AtomicLong(); } public <K extends TBase<?, ?>, V extends TBase<?, ?>> V put(ThriftCacheKey<K> key, V t) throws BlurException {
