Search in sources :

Example 1 with CacheLoaderException

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);
    }
}
Also used : CacheLoaderException(javax.cache.integration.CacheLoaderException) Expirable(com.github.benmanes.caffeine.jcache.Expirable)

Example 2 with CacheLoaderException

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.");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SQLException(java.sql.SQLException) CacheLoaderException(javax.cache.integration.CacheLoaderException) ResultSet(java.sql.ResultSet) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler) Person(org.apache.ignite.examples.model.Person)

Example 3 with CacheLoaderException

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;
    };
}
Also used : Context(org.glassfish.internal.api.JavaEEContextUtil.Context) CacheLoaderException(javax.cache.integration.CacheLoaderException) Factory(javax.cache.configuration.Factory) Cleanup(lombok.Cleanup) Map(java.util.Map)

Example 4 with CacheLoaderException

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;
    }
}
Also used : CacheLoaderException(javax.cache.integration.CacheLoaderException) Data(com.hazelcast.internal.serialization.Data) SampleableCacheRecordMap(com.hazelcast.cache.impl.record.SampleableCacheRecordMap) Map(java.util.Map) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) TenantControl(com.hazelcast.spi.tenantcontrol.TenantControl)

Example 5 with CacheLoaderException

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;
}
Also used : GoraException(org.apache.gora.util.GoraException) CacheLoaderException(javax.cache.integration.CacheLoaderException)

Aggregations

CacheLoaderException (javax.cache.integration.CacheLoaderException)34 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 SQLException (java.sql.SQLException)11 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 PreparedStatement (java.sql.PreparedStatement)7 CacheWriterException (javax.cache.integration.CacheWriterException)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 NoSuchElementException (java.util.NoSuchElementException)5 Nullable (org.jetbrains.annotations.Nullable)5 Person (org.apache.ignite.examples.model.Person)4 ArrayList (java.util.ArrayList)3 ExecutorService (java.util.concurrent.ExecutorService)3 EntryProcessorException (javax.cache.processor.EntryProcessorException)3 IgniteException (org.apache.ignite.IgniteException)3 Expirable (com.github.benmanes.caffeine.jcache.Expirable)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2