use of org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable in project infinispan by infinispan.
the class StateTransferGetListenersCommand method invokeAsync.
@Override
public CompletionStage<Collection<ClusterListenerReplicateCallable<Object, Object>>> invokeAsync(ComponentRegistry registry) throws Throwable {
StateProvider stateProvider = registry.getStateTransferManager().getStateProvider();
Collection<ClusterListenerReplicateCallable<Object, Object>> listeners = stateProvider.getClusterListenersToInstall();
return CompletableFuture.completedFuture(listeners);
}
use of org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable 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.notifications.cachelistener.cluster.ClusterListenerReplicateCallable in project infinispan by infinispan.
the class CacheNotifierImpl method registerClusterListenerCallablesToInstall.
private void registerClusterListenerCallablesToInstall(Set<Object> enlistedAlready, Set<ClusterListenerReplicateCallable<K, V>> callables, List<CacheEntryListenerInvocation<K, V>> listenerInvocations) {
for (CacheEntryListenerInvocation<K, V> listener : listenerInvocations) {
if (!enlistedAlready.contains(listener.getTarget())) {
// If clustered means it is local - so use our address
if (listener.isClustered()) {
Set<Class<? extends Annotation>> filterAnnotations = listener.getFilterAnnotations();
callables.add(new ClusterListenerReplicateCallable(cache.wired().getName(), listener.getIdentifier(), rpcManager.getAddress(), listener.getFilter(), listener.getConverter(), listener.isSync(), filterAnnotations, listener.getKeyDataConversion(), listener.getValueDataConversion(), listener.useStorageFormat()));
enlistedAlready.add(listener.getTarget());
} else if (listener.getTarget() instanceof RemoteClusterListener) {
RemoteClusterListener lcl = (RemoteClusterListener) listener.getTarget();
Set<Class<? extends Annotation>> filterAnnotations = listener.getFilterAnnotations();
callables.add(new ClusterListenerReplicateCallable(cache.wired().getName(), lcl.getId(), lcl.getOwnerAddress(), listener.getFilter(), listener.getConverter(), listener.isSync(), filterAnnotations, listener.getKeyDataConversion(), listener.getValueDataConversion(), listener.useStorageFormat()));
enlistedAlready.add(listener.getTarget());
}
}
}
}
use of org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable in project infinispan by infinispan.
the class StateConsumerImpl method getClusterListeners.
private CompletionStage<Collection<ClusterListenerReplicateCallable<Object, Object>>> getClusterListeners(int topologyId, List<Address> sources) {
// Try the first member. If the request fails, fall back to the second member and so on.
if (sources.isEmpty()) {
if (// TODO Ignore self again
log.isTraceEnabled())
log.trace("Unable to acquire cluster listeners from other members, assuming none are present");
return CompletableFuture.completedFuture(Collections.emptySet());
}
Address source = sources.get(0);
// Don't send the request to self
if (sources.get(0).equals(rpcManager.getAddress())) {
return getClusterListeners(topologyId, sources.subList(1, sources.size()));
}
if (log.isTraceEnabled())
log.tracef("Requesting cluster listeners of cache %s from node %s", cacheName, sources);
CacheRpcCommand cmd = commandsFactory.buildStateTransferGetListenersCommand(topologyId);
CompletionStage<ValidResponse> remoteStage = rpcManager.invokeCommand(source, cmd, SingleResponseCollector.validOnly(), rpcOptions);
return handleAndCompose(remoteStage, (response, throwable) -> {
if (throwable != null) {
log.exceptionDuringClusterListenerRetrieval(source, throwable);
}
if (response instanceof SuccessfulResponse) {
return CompletableFuture.completedFuture((Collection<ClusterListenerReplicateCallable<Object, Object>>) response.getResponseValue());
} else {
log.unsuccessfulResponseForClusterListeners(source, response);
return getClusterListeners(topologyId, sources.subList(1, sources.size()));
}
});
}
Aggregations