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);
}
}
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);
}
}
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);
}
}
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);
}
}
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<Statistics|Configuration>,name=<cacheName>"
*/
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);
}
}
Aggregations