Search in sources :

Example 1 with GCacheException

use of com.google.appengine.api.memcache.stdimpl.GCacheException 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 2 with GCacheException

use of com.google.appengine.api.memcache.stdimpl.GCacheException 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)

Aggregations

MemcacheServiceException (com.google.appengine.api.memcache.MemcacheServiceException)2 GCacheException (com.google.appengine.api.memcache.stdimpl.GCacheException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Cache (javax.cache.Cache)2 CacheException (javax.cache.CacheException)2