Search in sources :

Example 76 with CacheException

use of javax.cache.CacheException in project hazelcast by hazelcast.

the class CacheLoadAllOperation method run.

@Override
public void run() throws Exception {
    int partitionId = getPartitionId();
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    Set<Data> filteredKeys = null;
    if (keys != null) {
        filteredKeys = new HashSet<Data>();
        for (Data k : keys) {
            if (partitionService.getPartitionId(k) == partitionId) {
                filteredKeys.add(k);
            }
        }
    }
    if (filteredKeys == null || filteredKeys.isEmpty()) {
        return;
    }
    try {
        ICacheService service = getService();
        cache = service.getOrCreateRecordStore(name, partitionId);
        Set<Data> keysLoaded = cache.loadAll(filteredKeys, replaceExistingValues);
        int loadedKeyCount = keysLoaded.size();
        if (loadedKeyCount > 0) {
            backupRecords = new HashMap<Data, CacheRecord>(loadedKeyCount);
            for (Data key : keysLoaded) {
                CacheRecord record = cache.getRecord(key);
                // So if the loaded key is evicted, don't send it to backup.
                if (record != null) {
                    backupRecords.put(key, record);
                }
            }
            shouldBackup = !backupRecords.isEmpty();
        }
    } catch (CacheException e) {
        response = new CacheClearResponse(e);
    }
}
Also used : CacheClearResponse(com.hazelcast.cache.impl.CacheClearResponse) CacheRecord(com.hazelcast.cache.impl.record.CacheRecord) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheException(javax.cache.CacheException) IPartitionService(com.hazelcast.spi.partition.IPartitionService) Data(com.hazelcast.nio.serialization.Data)

Example 77 with CacheException

use of javax.cache.CacheException in project hazelcast by hazelcast.

the class CacheClearOperation method run.

@Override
public void run() {
    if (cache == null) {
        return;
    }
    try {
        cache.clear();
        response = new CacheClearResponse(Boolean.TRUE);
    } catch (CacheException e) {
        response = new CacheClearResponse(e);
    }
}
Also used : CacheClearResponse(com.hazelcast.cache.impl.CacheClearResponse) CacheException(javax.cache.CacheException)

Example 78 with CacheException

use of javax.cache.CacheException in project hazelcast by hazelcast.

the class CacheRemoveAllKeysMessageTask method reduce.

@Override
protected ClientMessage reduce(Map<Integer, Object> map) {
    for (Map.Entry<Integer, Object> entry : map.entrySet()) {
        if (entry.getValue() == null) {
            continue;
        }
        final CacheClearResponse cacheClearResponse = (CacheClearResponse) nodeEngine.toObject(entry.getValue());
        final Object response = cacheClearResponse.getResponse();
        if (response instanceof CacheException) {
            throw (CacheException) response;
        }
    }
    return null;
}
Also used : CacheClearResponse(com.hazelcast.cache.impl.CacheClearResponse) CacheException(javax.cache.CacheException) Map(java.util.Map)

Example 79 with CacheException

use of javax.cache.CacheException in project hazelcast by hazelcast.

the class CacheRemoveAllMessageTask method reduce.

@Override
protected Object reduce(Map<Integer, Object> map) {
    for (Map.Entry<Integer, Object> entry : map.entrySet()) {
        if (entry.getValue() == null) {
            continue;
        }
        final CacheClearResponse cacheClearResponse = (CacheClearResponse) nodeEngine.toObject(entry.getValue());
        final Object response = cacheClearResponse.getResponse();
        if (response instanceof CacheException) {
            throw (CacheException) response;
        }
    }
    return null;
}
Also used : CacheClearResponse(com.hazelcast.cache.impl.CacheClearResponse) CacheException(javax.cache.CacheException) Map(java.util.Map)

Example 80 with CacheException

use of javax.cache.CacheException in project redisson by redisson.

the class JCacheManager method enableStatistics.

@Override
public void enableStatistics(String cacheName, boolean enabled) {
    checkNotClosed();
    if (cacheName == null) {
        throw new NullPointerException();
    }
    JCache<?, ?> cache = caches.get(cacheName);
    if (cache == null) {
        throw new NullPointerException();
    }
    if (enabled) {
        JCacheStatisticsMXBean statBean = statBeans.get(cache);
        if (statBean == null) {
            statBean = new JCacheStatisticsMXBean();
            JCacheStatisticsMXBean oldBean = statBeans.putIfAbsent(cache, statBean);
            if (oldBean != null) {
                statBean = oldBean;
            }
        }
        try {
            ObjectName objectName = queryNames("Statistics", cache);
            if (!mBeanServer.isRegistered(objectName)) {
                mBeanServer.registerMBean(statBean, objectName);
            }
        } catch (MalformedObjectNameException e) {
            throw new CacheException(e);
        } catch (InstanceAlreadyExistsException e) {
            throw new CacheException(e);
        } catch (MBeanRegistrationException e) {
            throw new CacheException(e);
        } catch (NotCompliantMBeanException e) {
            throw new CacheException(e);
        }
    } else {
        unregisterStatisticsBean(cache);
    }
    cache.getConfiguration(JCacheConfiguration.class).setStatisticsEnabled(enabled);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) JCacheConfiguration(org.redisson.jcache.configuration.JCacheConfiguration) CacheException(javax.cache.CacheException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) JCacheStatisticsMXBean(org.redisson.jcache.bean.JCacheStatisticsMXBean) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

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