use of javax.cache.integration.CacheLoaderException in project caffeine by ben-manes.
the class JCacheLoaderAdapter method load.
@Override
public Expirable<V> load(K key) {
try {
boolean statsEnabled = statistics.isEnabled();
long start = statsEnabled ? ticker.read() : 0L;
V value = delegate.load(key);
if (value == null) {
return null;
}
dispatcher.publishCreated(cache, key, value);
if (statsEnabled) {
// Subtracts the load time from the get time
statistics.recordGetTime(start - ticker.read());
}
return new Expirable<>(value, expireTimeMS());
} catch (CacheLoaderException e) {
throw e;
} catch (RuntimeException e) {
throw new CacheLoaderException(e);
}
}
use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class CacheSpringPersonStore method loadCache.
/**
* {@inheritDoc}
*/
@Override
public void loadCache(final IgniteBiInClosure<Long, Person> clo, Object... args) {
if (args == null || args.length == 0 || args[0] == null)
throw new CacheLoaderException("Expected entry count parameter is not provided.");
int entryCnt = (Integer) args[0];
final AtomicInteger cnt = new AtomicInteger();
jdbcTemplate.query("select * from PERSON limit ?", new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3));
clo.apply(person.id, person);
cnt.incrementAndGet();
}
}, entryCnt);
System.out.println(">>> Loaded " + cnt + " values into cache.");
}
use of javax.cache.integration.CacheLoaderException in project Payara by payara.
the class CompleteConfigurationProxy method proxyLoader.
private Factory<CacheLoader<K, V>> proxyLoader(final Factory<CacheLoader<K, V>> fact) {
return new Factory<CacheLoader<K, V>>() {
@Override
public CacheLoader<K, V> create() {
@Cleanup Context ctx = ctxUtil.pushContext();
final CacheLoader<K, V> loader = fact.create();
return new CacheLoaderImpl(loader);
}
class CacheLoaderImpl implements CacheLoader<K, V> {
public CacheLoaderImpl(CacheLoader<K, V> loader) {
this.loader = loader;
}
@Override
public V load(K k) throws CacheLoaderException {
@Cleanup Context context = ctxUtil.pushRequestContext();
return loader.load(k);
}
@Override
public Map<K, V> loadAll(Iterable<? extends K> itrbl) throws CacheLoaderException {
@Cleanup Context context = ctxUtil.pushRequestContext();
return loader.loadAll(itrbl);
}
private final CacheLoader<K, V> loader;
}
private static final long serialVersionUID = 1L;
};
}
use of javax.cache.integration.CacheLoaderException in project hazelcast by hazelcast.
the class AbstractCacheRecordStore method loadAllCacheEntry.
protected Map<Data, Object> loadAllCacheEntry(Set<Data> keys) {
try (TenantControl.Closeable ctx = cacheLoader.getTenantControl().setTenant()) {
if (cacheLoader.exists()) {
Map<Object, Data> keysToLoad = createHashMap(keys.size());
for (Data key : keys) {
Object localKeyObj = dataToValue(key);
keysToLoad.put(localKeyObj, key);
}
Map<Object, Object> loaded;
try {
loaded = cacheLoader.get().loadAll(keysToLoad.keySet());
} catch (Throwable e) {
if (!(e instanceof CacheLoaderException)) {
throw new CacheLoaderException("Exception in CacheLoader during loadAll", e);
} else {
throw (CacheLoaderException) e;
}
}
Map<Data, Object> result = createHashMap(keysToLoad.size());
for (Map.Entry<Object, Data> entry : keysToLoad.entrySet()) {
Object keyObj = entry.getKey();
Object valueObject = loaded.get(keyObj);
Data keyData = entry.getValue();
result.put(keyData, valueObject);
}
return result;
}
return null;
}
}
use of javax.cache.integration.CacheLoaderException in project gora by apache.
the class JCacheCacheLoader method load.
@Override
public T load(K key) throws CacheLoaderException {
T persistent = null;
try {
persistent = dataStore.get(key);
LOG.info("Loaded data bean from persistent datastore on key {}.", key.toString());
} catch (GoraException ex) {
throw new CacheLoaderException(ex);
}
return persistent;
}
Aggregations