use of org.infinispan.commons.CacheListenerException in project infinispan by infinispan.
the class CacheNotifierImpl method registerClusterListeners.
private <C> CompletionStage<Void> registerClusterListeners(List<Address> members, UUID generatedId, Address ourAddress, CacheEventFilter<? super K, ? super V> filter, CacheEventConverter<? super K, ? super V, C> converter, Listener l, Object listener, DataConversion keyDataConversion, DataConversion valueDataConversion, boolean useStorageFormat) {
if (log.isTraceEnabled()) {
log.tracef("Replicating cluster listener to other nodes %s for cluster listener with id %s", members, generatedId);
}
ClusterListenerReplicateCallable<K, V> callable = new ClusterListenerReplicateCallable(cache.wired().getName(), generatedId, ourAddress, filter, converter, l.sync(), findListenerCallbacks(listener), keyDataConversion, valueDataConversion, useStorageFormat);
TriConsumer<Address, Void, Throwable> handleSuspect = (a, ignore, t) -> {
if (t != null && !(t instanceof SuspectException)) {
log.debugf(t, "Address: %s encountered an exception while adding cluster listener", a);
throw new CacheListenerException(t);
}
};
// Send to all nodes but ours
CompletionStage<Void> completionStage = clusterExecutor.filterTargets(a -> !ourAddress.equals(a)).submitConsumer(callable, handleSuspect);
// the listener - unfortunately if there are no nodes it throws a SuspectException, so we ignore that
return completionStage.thenCompose(v -> clusterExecutor.filterTargets(a -> !members.contains(a) && !a.equals(ourAddress)).submitConsumer(callable, handleSuspect).exceptionally(t -> {
// Ignore any suspect exception
if (!(t instanceof SuspectException)) {
throw new CacheListenerException(t);
}
return null;
}));
}
use of org.infinispan.commons.CacheListenerException in project infinispan by infinispan.
the class AbstractJCache method put.
protected V put(BasicCache<K, V> cache, BasicCache<K, V> createCheckCache, K key, V value, boolean isPutIfAbsent) {
// Use a separate cache reference to check whether entry is created or
// not. A separate reference allows for listener notifications to be
// skipped selectively.
V prev = createCheckCache.get(key);
boolean isCreated = prev == null;
// If putIfAbsent and entry already present, skip early
if (!isCreated && isPutIfAbsent)
return prev;
V ret;
Duration ttl = isCreated ? Expiration.getExpiry(expiryPolicy, Expiration.Operation.CREATION) : Expiration.getExpiry(expiryPolicy, Expiration.Operation.UPDATE);
try {
if (ttl == null || ttl.isEternal()) {
ret = isPutIfAbsent ? cache.putIfAbsent(key, value) : cache.put(key, value);
} else if (ttl.equals(Duration.ZERO)) {
// If the entry is modified, explicitly remove it.
if (!isCreated)
ret = cache.remove(key);
else
ret = null;
} else {
long duration = ttl.getDurationAmount();
TimeUnit timeUnit = ttl.getTimeUnit();
ret = isPutIfAbsent ? cache.putIfAbsent(key, value, duration, timeUnit) : cache.put(key, value, duration, timeUnit);
}
return ret;
} catch (CacheListenerException e) {
throw Exceptions.launderCacheListenerException(e);
}
}
Aggregations