Search in sources :

Example 6 with CacheException

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

the class ClientCacheProxy method invoke.

@Override
public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... arguments) throws EntryProcessorException {
    ensureOpen();
    validateNotNull(key);
    if (entryProcessor == null) {
        throw new NullPointerException("Entry Processor is null");
    }
    final Data keyData = toData(key);
    Data epData = toData(entryProcessor);
    List<Data> argumentsData = null;
    if (arguments != null) {
        argumentsData = new ArrayList<Data>(arguments.length);
        for (int i = 0; i < arguments.length; i++) {
            argumentsData.add(toData(arguments[i]));
        }
    }
    final int completionId = nextCompletionId();
    ClientMessage request = CacheEntryProcessorCodec.encodeRequest(nameWithPrefix, keyData, epData, argumentsData, completionId);
    try {
        final ICompletableFuture<ClientMessage> f = invoke(request, keyData, completionId);
        final ClientMessage response = getSafely(f);
        final Data data = CacheEntryProcessorCodec.decodeResponse(response).response;
        // At client side, we don't know what entry processor does so we ignore it from statistics perspective
        return toObject(data);
    } catch (CacheException ce) {
        throw ce;
    } catch (Exception e) {
        throw new EntryProcessorException(e);
    }
}
Also used : EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) Data(com.hazelcast.nio.serialization.Data) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException)

Example 7 with CacheException

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

the class AbstractCacheProxyBase method close.

@Override
public void close() {
    if (!isClosed.compareAndSet(false, true)) {
        return;
    }
    Exception caughtException = null;
    for (Future f : loadAllTasks) {
        try {
            f.get(TIMEOUT, TimeUnit.SECONDS);
        } catch (Exception e) {
            if (caughtException == null) {
                caughtException = e;
            }
            getNodeEngine().getLogger(getClass()).warning("Problem while waiting for loadAll tasks to complete", e);
        }
    }
    loadAllTasks.clear();
    closeListeners();
    if (caughtException != null) {
        throw new CacheException("Problem while waiting for loadAll tasks to complete", caughtException);
    }
}
Also used : CacheException(javax.cache.CacheException) Future(java.util.concurrent.Future) CacheException(javax.cache.CacheException)

Example 8 with CacheException

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

the class CacheProxy method invoke.

@Override
public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... arguments) throws EntryProcessorException {
    ensureOpen();
    validateNotNull(key);
    checkNotNull(entryProcessor, "Entry Processor is null");
    Data keyData = serializationService.toData(key);
    Integer completionId = registerCompletionLatch(1);
    Operation op = operationProvider.createEntryProcessorOperation(keyData, completionId, entryProcessor, arguments);
    try {
        OperationService operationService = getNodeEngine().getOperationService();
        int partitionId = getPartitionId(keyData);
        InternalCompletableFuture<T> future = operationService.invokeOnPartition(getServiceName(), op, partitionId);
        T safely = future.join();
        waitCompletionLatch(completionId);
        return safely;
    } catch (CacheException ce) {
        deregisterCompletionLatch(completionId);
        throw ce;
    } catch (Exception e) {
        deregisterCompletionLatch(completionId);
        throw new EntryProcessorException(e);
    }
}
Also used : EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) Data(com.hazelcast.nio.serialization.Data) CacheListenerRegistrationOperation(com.hazelcast.cache.impl.operation.CacheListenerRegistrationOperation) Operation(com.hazelcast.spi.Operation) OperationService(com.hazelcast.spi.OperationService) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException)

Example 9 with CacheException

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

the class CacheProxy method loadAll.

@Override
public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) {
    ensureOpen();
    validateNotNull(keys);
    for (K key : keys) {
        CacheProxyUtil.validateConfiguredTypes(cacheConfig, key);
    }
    HashSet<Data> keysData = new HashSet<Data>(keys.size());
    for (K key : keys) {
        keysData.add(serializationService.toData(key));
    }
    LoadAllTask loadAllTask = new LoadAllTask(operationProvider, keysData, replaceExistingValues, completionListener);
    try {
        submitLoadAllTask(loadAllTask);
    } catch (Exception e) {
        if (completionListener != null) {
            completionListener.onException(e);
        }
        throw new CacheException(e);
    }
}
Also used : CacheException(javax.cache.CacheException) Data(com.hazelcast.nio.serialization.Data) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) HashSet(java.util.HashSet)

Example 10 with CacheException

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

the class MXBeanUtil method calculateObjectName.

/**
     * Creates an object name using the scheme.
     * "javax.cache:type=Cache&lt;Statistics|Configuration&gt;,name=&lt;cacheName&gt;"
     */
public static ObjectName calculateObjectName(String cacheManagerName, String name, boolean stats) {
    String cacheManagerNameSafe = mbeanSafe(cacheManagerName);
    String cacheName = mbeanSafe(name);
    try {
        String objectNameType = stats ? "Statistics" : "Configuration";
        return new ObjectName("javax.cache:type=Cache" + objectNameType + ",CacheManager=" + cacheManagerNameSafe + ",Cache=" + cacheName);
    } catch (MalformedObjectNameException e) {
        throw new CacheException("Illegal ObjectName for Management Bean. " + "CacheManager=[" + cacheManagerNameSafe + "], Cache=[" + cacheName + "]", e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CacheException(javax.cache.CacheException) 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