use of javax.cache.CacheException in project ignite by apache.
the class IgniteCacheRandomOperationBenchmark method createAdditionalCaches.
/**
* Creates additional caches.
*
* @throws Exception If failed.
*/
private void createAdditionalCaches() throws Exception {
Map<String, CacheConfiguration> cfgMap;
try {
// Loading spring application context and getting all of the caches configurations in the map.
cfgMap = IgniteNode.loadConfiguration(args.configuration()).get2().getBeansOfType(CacheConfiguration.class);
} catch (BeansException e) {
throw new Exception("Failed to instantiate bean [type=" + CacheConfiguration.class + ", err=" + e.getMessage() + ']', e);
}
if (cfgMap == null || cfgMap.isEmpty())
throw new Exception("Failed to find cache configurations in: " + args.configuration());
// Getting cache configuration from the map using name specified in property file.
CacheConfiguration<Object, Object> ccfg = cfgMap.get(args.additionalCachesName());
if (ccfg == null)
throw new Exception("Failed to find cache configuration [cache=" + args.additionalCachesName() + ", cfg=" + args.configuration() + ']');
for (int i = 0; i < args.additionalCachesNumber(); i++) {
CacheConfiguration<Object, Object> newCfg = new CacheConfiguration<>(ccfg);
newCfg.setName("additional_" + args.additionalCachesName() + "_cache_" + i);
try {
ignite().createCache(newCfg);
} catch (CacheException e) {
BenchmarkUtils.error("Failed to create additional cache [ name = " + args.additionalCachesName() + ", err" + e.getMessage() + ']', e);
}
}
}
use of javax.cache.CacheException in project ignite by apache.
the class WebSessionFilter method updateAttributesV2.
/**
* @param sesId Session ID.
* @param ses Web session.
*/
public void updateAttributesV2(final String sesId, final WebSessionV2 ses) throws IOException {
assert sesId != null;
assert ses != null;
final Map<String, byte[]> updatesMap = ses.binaryUpdatesMap();
if (log.isDebugEnabled())
log.debug("Session binary attributes updated [id=" + sesId + ", updates=" + updatesMap.keySet() + ']');
try {
for (int i = 0; i < retries; i++) {
try {
final IgniteCache<String, WebSessionEntity> cache0 = cacheWithExpiryPolicy(ses.getMaxInactiveInterval(), binaryCache);
cache0.invoke(sesId, new WebSessionAttributeProcessor(updatesMap.isEmpty() ? null : updatesMap, ses.getLastAccessedTime(), ses.getMaxInactiveInterval(), ses.isMaxInactiveIntervalChanged()));
break;
} catch (CacheException | IgniteException | IllegalStateException e) {
handleAttributeUpdateException(sesId, i, e);
}
}
} catch (Exception e) {
U.error(log, "Failed to update session V2 attributes [id=" + sesId + ']', e);
}
}
use of javax.cache.CacheException in project ignite by apache.
the class WebSessionFilter method doFilterV2.
/**
* @param httpReq Request.
* @param res Response.
* @param chain Filter chain.
* @return Session ID.
* @throws IOException In case of I/O error.
* @throws ServletException In case oif servlet error.
* @throws CacheException In case of other error.
*/
private String doFilterV2(HttpServletRequest httpReq, ServletResponse res, FilterChain chain) throws IOException, ServletException, CacheException {
WebSessionV2 cached = null;
String sesId = httpReq.getRequestedSessionId();
if (sesId != null) {
sesId = transformSessionId(sesId);
// Load from cache.
for (int i = 0; i < retries; i++) {
try {
final WebSessionEntity entity = binaryCache.get(sesId);
if (entity != null)
cached = new WebSessionV2(sesId, httpReq.getSession(false), false, ctx, entity, marshaller);
break;
} catch (CacheException | IgniteException | IllegalStateException e) {
handleLoadSessionException(sesId, i, e);
}
}
if (cached != null) {
if (log.isDebugEnabled())
log.debug("Using cached session for ID: " + sesId);
} else // If not found - invalidate session and create new one.
// Invalidate, because session might be removed from cache
// according to expiry policy.
{
if (log.isDebugEnabled())
log.debug("Cached session was invalidated and doesn't exist: " + sesId);
final HttpSession ses = httpReq.getSession(false);
if (ses != null) {
try {
ses.invalidate();
} catch (IllegalStateException ignore) {
// Session was already invalidated.
}
}
cached = createSessionV2(httpReq);
}
} else
// No session was requested by the client, create new one and put in the request.
cached = createSessionV2(httpReq);
assert cached != null;
sesId = cached.getId();
httpReq = new RequestWrapperV2(httpReq, cached);
chain.doFilter(httpReq, res);
WebSessionV2 cachedNew = (WebSessionV2) httpReq.getSession(false);
if (cachedNew != null && cachedNew.isValid())
updateAttributesV2(cachedNew.getId(), cachedNew);
return sesId;
}
use of javax.cache.CacheException in project caffeine by ben-manes.
the class LoadingCacheProxy method getAll.
/** Returns the entries, loading if necessary, and optionally updates their access expiry time. */
@SuppressWarnings("PMD.AvoidCatchingNPE")
private Map<K, V> getAll(Set<? extends K> keys, boolean updateAccessTime) {
requireNotClosed();
boolean statsEnabled = statistics.isEnabled();
long start = statsEnabled ? ticker.read() : 0L;
try {
Map<K, Expirable<V>> entries = getAndFilterExpiredEntries(keys, updateAccessTime);
if (entries.size() != keys.size()) {
List<K> keysToLoad = keys.stream().filter(key -> !entries.containsKey(key)).collect(Collectors.<K>toList());
entries.putAll(cache.getAll(keysToLoad));
}
Map<K, V> result = copyMap(entries);
if (statsEnabled) {
statistics.recordGetTime(ticker.read() - start);
}
return result;
} catch (NullPointerException | IllegalStateException | ClassCastException | CacheException e) {
throw e;
} catch (RuntimeException e) {
throw new CacheException(e);
} finally {
dispatcher.awaitSynchronous();
}
}
use of javax.cache.CacheException in project hazelcast by hazelcast.
the class AbstractHazelcastCacheManager method createCacheInternal.
private <K, V, C extends Configuration<K, V>> ICacheInternal<K, V> createCacheInternal(String cacheName, C configuration) throws IllegalArgumentException {
checkIfManagerNotClosed();
checkNotNull(cacheName, "cacheName must not be null");
checkNotNull(configuration, "configuration must not be null");
CacheConfig<K, V> newCacheConfig = createCacheConfig(cacheName, configuration);
if (caches.containsKey(newCacheConfig.getNameWithPrefix())) {
throw new CacheException("A cache named " + cacheName + " already exists.");
}
// Create cache config on all nodes as sync
CacheConfig<K, V> currentCacheConfig = createCacheConfig(cacheName, newCacheConfig, true, true);
// Create cache proxy object with cache config
ICacheInternal<K, V> cacheProxy = createCacheProxy(newCacheConfig);
if (currentCacheConfig == null) {
// Put created cache config.
// Single thread region because "createConfigOnPartition" is single threaded by partition thread
addCacheConfigIfAbsent(newCacheConfig);
// Put created cache. No need to a "putIfAbsent" as this is a single threaded region
caches.put(newCacheConfig.getNameWithPrefix(), cacheProxy);
// Register listeners
registerListeners(newCacheConfig, cacheProxy);
return cacheProxy;
}
ICacheInternal<?, ?> cache = getOrPutIfAbsent(currentCacheConfig.getNameWithPrefix(), cacheProxy);
CacheConfig config = cache.getConfiguration(CacheConfig.class);
if (config.equals(newCacheConfig)) {
return (ICacheInternal<K, V>) cache;
}
throw new CacheException("A cache named " + cacheName + " already exists.");
}
Aggregations