Search in sources :

Example 81 with CacheException

use of javax.cache.CacheException in project pratilipi by Pratilipi.

the class MemcacheGaeImpl method putAll.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <K, T extends Serializable> void putAll(Map<K, T> keyValueMap, int expirationDeltaMinutes) {
    Map props = new HashMap();
    if (expirationDeltaMinutes > 0)
        props.put(GCacheFactory.EXPIRATION_DELTA, expirationDeltaMinutes * 60);
    for (int i = 0; i < 5; i++) {
        if (i > 0) {
            try {
                long sleepMillis = (long) Math.pow(2, i - 1) * 100;
                logger.log(Level.INFO, "Retrying in " + sleepMillis + " milliseconds ...");
                Thread.sleep(sleepMillis);
            } catch (InterruptedException ex) {
                logger.log(Level.SEVERE, "Thread sleep interrupted.", ex);
            }
        }
        try {
            Cache cache = CacheManager.getInstance().getCacheFactory().createCache(props);
            cache.putAll(keyValueMap);
            break;
        } catch (GCacheException | MemcacheServiceException ex) {
            logger.log(Level.SEVERE, "Failed to update one or more values.", ex);
        } catch (CacheException ex) {
            logger.log(Level.SEVERE, "Failed to create cache instance.", ex);
        }
    }
}
Also used : HashMap(java.util.HashMap) GCacheException(com.google.appengine.api.memcache.stdimpl.GCacheException) CacheException(javax.cache.CacheException) GCacheException(com.google.appengine.api.memcache.stdimpl.GCacheException) MemcacheServiceException(com.google.appengine.api.memcache.MemcacheServiceException) HashMap(java.util.HashMap) Map(java.util.Map) Cache(javax.cache.Cache)

Example 82 with CacheException

use of javax.cache.CacheException in project pratilipi by Pratilipi.

the class MemcacheGaeImpl method put.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <K, T extends Serializable> void put(K key, T value, int expirationDeltaMinutes) {
    Map props = new HashMap();
    if (expirationDeltaMinutes > 0)
        props.put(GCacheFactory.EXPIRATION_DELTA, expirationDeltaMinutes * 60);
    for (int i = 0; i < 5; i++) {
        if (i > 0) {
            try {
                long sleepMillis = (long) Math.pow(2, i - 1) * 100;
                logger.log(Level.INFO, "Retrying in " + sleepMillis + " milliseconds ...");
                Thread.sleep(sleepMillis);
            } catch (InterruptedException ex) {
                logger.log(Level.SEVERE, "Thread sleep interrupted.", ex);
            }
        }
        try {
            Cache cache = CacheManager.getInstance().getCacheFactory().createCache(props);
            cache.put(key, value);
            break;
        } catch (GCacheException | MemcacheServiceException ex) {
            logger.log(Level.SEVERE, "Failed to update value.", ex);
        } catch (CacheException ex) {
            logger.log(Level.SEVERE, "Failed to create cache instance.", ex);
        }
    }
}
Also used : HashMap(java.util.HashMap) GCacheException(com.google.appengine.api.memcache.stdimpl.GCacheException) CacheException(javax.cache.CacheException) GCacheException(com.google.appengine.api.memcache.stdimpl.GCacheException) MemcacheServiceException(com.google.appengine.api.memcache.MemcacheServiceException) HashMap(java.util.HashMap) Map(java.util.Map) Cache(javax.cache.Cache)

Example 83 with CacheException

use of javax.cache.CacheException in project pratilipi by Pratilipi.

the class MemcacheGaeImpl method remove.

@Override
public <K> void remove(K key) {
    try {
        Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
        cache.remove(key);
    } catch (CacheException ex) {
        logger.log(Level.SEVERE, "Failed to create cache instance.", ex);
    }
}
Also used : GCacheException(com.google.appengine.api.memcache.stdimpl.GCacheException) CacheException(javax.cache.CacheException) Cache(javax.cache.Cache)

Example 84 with CacheException

use of javax.cache.CacheException in project pratilipi by Pratilipi.

the class MemcacheGaeImpl method get.

@SuppressWarnings("unchecked")
@Override
public <K, T extends Serializable> T get(K key) {
    try {
        Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
        T value = (T) cache.get(key);
        if (value == null)
            logger.log(Level.INFO, "Cache Miss: " + key);
        //				logger.log( Level.INFO, "Cache Hit: " + key );
        return value;
    } catch (InvalidValueException | ClassCastException e) {
        logger.log(Level.SEVERE, "Failed to typecaste cached value to required type.", e);
        return null;
    } catch (CacheException e) {
        logger.log(Level.SEVERE, "Failed to create cache instance.", e);
        return null;
    }
}
Also used : InvalidValueException(com.google.appengine.api.memcache.InvalidValueException) GCacheException(com.google.appengine.api.memcache.stdimpl.GCacheException) CacheException(javax.cache.CacheException) Cache(javax.cache.Cache)

Example 85 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class CacheAbstractJdbcStore method getOrCreateCacheMappings.

/**
     * @param cacheName Cache name to check mappings for.
     * @return Type mappings for specified cache name.
     * @throws CacheException If failed to initialize cache mappings.
     */
private Map<Object, EntryMapping> getOrCreateCacheMappings(@Nullable String cacheName) throws CacheException {
    Map<Object, EntryMapping> entryMappings = cacheMappings.get(cacheName);
    if (entryMappings != null)
        return entryMappings;
    cacheMappingsLock.lock();
    try {
        entryMappings = cacheMappings.get(cacheName);
        if (entryMappings != null)
            return entryMappings;
        List<JdbcType> cacheTypes = new ArrayList<>(types.length);
        for (JdbcType type : types) if ((cacheName != null && cacheName.equals(type.getCacheName())) || (cacheName == null && type.getCacheName() == null))
            cacheTypes.add(type);
        entryMappings = U.newHashMap(cacheTypes.size());
        if (!cacheTypes.isEmpty()) {
            boolean binarySupported = ignite.configuration().getMarshaller() instanceof BinaryMarshaller;
            for (JdbcType type : cacheTypes) {
                String keyType = type.getKeyType();
                String valType = type.getValueType();
                TypeKind keyKind = kindForName(keyType, binarySupported);
                checkTypeConfiguration(cacheName, keyKind, keyType, type.getKeyFields());
                Object keyTypeId = typeIdForTypeName(keyKind, keyType);
                if (entryMappings.containsKey(keyTypeId))
                    throw new CacheException("Key type must be unique in type metadata [cache=" + U.maskName(cacheName) + ", type=" + keyType + "]");
                TypeKind valKind = kindForName(valType, binarySupported);
                checkTypeConfiguration(cacheName, valKind, valType, type.getValueFields());
                entryMappings.put(keyTypeId, new EntryMapping(cacheName, dialect, type, keyKind, valKind, sqlEscapeAll));
            }
            Map<String, Map<Object, EntryMapping>> mappings = new HashMap<>(cacheMappings);
            mappings.put(cacheName, entryMappings);
            prepareBuilders(cacheName, cacheTypes);
            cacheMappings = mappings;
        }
        return entryMappings;
    } finally {
        cacheMappingsLock.unlock();
    }
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) CacheException(javax.cache.CacheException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

CacheException (javax.cache.CacheException)144 Ignite (org.apache.ignite.Ignite)42 IgniteException (org.apache.ignite.IgniteException)36 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)26 Transaction (org.apache.ignite.transactions.Transaction)25 ArrayList (java.util.ArrayList)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 IgniteCache (org.apache.ignite.IgniteCache)18 CountDownLatch (java.util.concurrent.CountDownLatch)17 List (java.util.List)16 Map (java.util.Map)16 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)15 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)13 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)13 HashMap (java.util.HashMap)12 IgniteTransactions (org.apache.ignite.IgniteTransactions)12 CyclicBarrier (java.util.concurrent.CyclicBarrier)11 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)10 Cache (javax.cache.Cache)9