use of com.github.benmanes.caffeine.cache.CacheLoader in project storm by apache.
the class HBaseLookupBolt method prepare.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void prepare(Map config, TopologyContext topologyContext, OutputCollector collector) {
super.prepare(config, topologyContext, collector);
cacheEnabled = Boolean.parseBoolean(config.getOrDefault("hbase.cache.enable", "false").toString());
int cacheTTL = Integer.parseInt(config.getOrDefault("hbase.cache.ttl.seconds", "300").toString());
int maxCacheSize = Integer.parseInt(config.getOrDefault("hbase.cache.size", "1000").toString());
if (cacheEnabled) {
cache = Caffeine.newBuilder().maximumSize(maxCacheSize).expireAfterWrite(cacheTTL, TimeUnit.SECONDS).build(new CacheLoader<byte[], Result>() {
@Override
public Result load(byte[] rowKey) throws Exception {
Get get = hBaseClient.constructGetRequests(rowKey, projectionCriteria);
if (LOG.isDebugEnabled()) {
LOG.debug("Cache miss for key:" + new String(rowKey));
}
return hBaseClient.batchGet(Lists.newArrayList(get))[0];
}
});
}
}
Aggregations