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);
}
}
}
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);
}
}
}
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);
}
}
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;
}
}
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();
}
}
Aggregations