Search in sources :

Example 71 with CacheException

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);
        }
    }
}
Also used : CacheException(javax.cache.CacheException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteException(org.apache.ignite.IgniteException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheException(javax.cache.CacheException) BeansException(org.springframework.beans.BeansException) BeansException(org.springframework.beans.BeansException)

Example 72 with CacheException

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);
    }
}
Also used : CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) WebSessionAttributeProcessor(org.apache.ignite.internal.websession.WebSessionAttributeProcessor) ServletException(javax.servlet.ServletException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) WebSessionEntity(org.apache.ignite.internal.websession.WebSessionEntity)

Example 73 with CacheException

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;
}
Also used : CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) HttpSession(javax.servlet.http.HttpSession) WebSessionEntity(org.apache.ignite.internal.websession.WebSessionEntity)

Example 74 with CacheException

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();
    }
}
Also used : Ticker(com.github.benmanes.caffeine.cache.Ticker) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Executor(java.util.concurrent.Executor) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) Set(java.util.Set) CompletionListener(javax.cache.integration.CompletionListener) Collectors(java.util.stream.Collectors) CacheLoader(javax.cache.integration.CacheLoader) Objects(java.util.Objects) List(java.util.List) Map(java.util.Map) Cache(javax.cache.Cache) Optional(java.util.Optional) JCacheStatisticsMXBean(com.github.benmanes.caffeine.jcache.management.JCacheStatisticsMXBean) CacheException(javax.cache.CacheException) CacheManager(javax.cache.CacheManager) EventDispatcher(com.github.benmanes.caffeine.jcache.event.EventDispatcher) CaffeineConfiguration(com.github.benmanes.caffeine.jcache.configuration.CaffeineConfiguration) CacheException(javax.cache.CacheException)

Example 75 with CacheException

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.");
}
Also used : CacheException(javax.cache.CacheException) CacheConfig(com.hazelcast.config.CacheConfig)

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