use of org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier in project infinispan by infinispan.
the class DefaultCacheManager method addListenerAsync.
@Override
public CompletionStage<Void> addListenerAsync(Object listener) {
authorizer.checkPermission(getSubject(), AuthorizationPermission.LISTEN);
CacheManagerNotifier notifier = globalComponentRegistry.getComponent(CacheManagerNotifier.class);
return notifier.addListenerAsync(listener);
}
use of org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier in project infinispan by infinispan.
the class DefaultCacheManager method getListeners.
@Deprecated
@Override
public Set<Object> getListeners() {
authorizer.checkPermission(getSubject(), AuthorizationPermission.LISTEN);
CacheManagerNotifier notifier = globalComponentRegistry.getComponent(CacheManagerNotifier.class);
return notifier.getListeners();
}
use of org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier in project infinispan by infinispan.
the class AbstractClusterListenerUtilTest method waitUntilViewChangeOccurs.
protected void waitUntilViewChangeOccurs(final CacheContainer cacheContainer, final String uniqueId, final CheckPoint checkPoint) {
CacheManagerNotifier cmn = TestingUtil.extractGlobalComponent(cacheContainer, CacheManagerNotifier.class);
final Answer<Object> forwardedAnswer = AdditionalAnswers.delegatesTo(cmn);
CacheManagerNotifier mockNotifier = mock(CacheManagerNotifier.class, withSettings().defaultAnswer(forwardedAnswer));
doAnswer(invocation -> {
// Wait for main thread to sync up
checkPoint.trigger("pre_view_listener_invoked_" + uniqueId);
// Now wait until main thread lets us through
checkPoint.awaitStrict("pre_view_listener_release_" + uniqueId, 10, TimeUnit.SECONDS);
try {
return forwardedAnswer.answer(invocation);
} finally {
checkPoint.trigger("post_view_listener_invoked_" + uniqueId);
}
}).when(mockNotifier).notifyViewChange(anyList(), anyList(), any(Address.class), anyInt());
TestingUtil.replaceComponent(cacheContainer, CacheManagerNotifier.class, mockNotifier, true);
}
use of org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier in project infinispan by infinispan.
the class ClusterListenerReplicateCallable method accept.
@Override
public void accept(EmbeddedCacheManager cacheManager, Cache<K, V> cache) {
ComponentRegistry componentRegistry = SecurityActions.getComponentRegistry(cache.getAdvancedCache());
CacheNotifier<K, V> cacheNotifier = componentRegistry.getComponent(CacheNotifier.class);
CacheManagerNotifier cacheManagerNotifier = componentRegistry.getComponent(CacheManagerNotifier.class);
Address ourAddress = cache.getCacheManager().getAddress();
ClusterEventManager<K, V> eventManager = componentRegistry.getComponent(ClusterEventManager.class);
if (filter != null) {
componentRegistry.wireDependencies(filter);
}
if (converter != null && converter != filter) {
componentRegistry.wireDependencies(converter);
}
// Only register listeners if we aren't the ones that registered the cluster listener
if (!ourAddress.equals(origin)) {
// Make sure the origin is around otherwise don't register the listener - some way with identifier (CHM maybe?)
if (cacheManager.getMembers().contains(origin)) {
// the same id. Note we can't use a static CHM due to running more than 1 node in same JVM
synchronized (cacheNotifier) {
boolean alreadyInstalled = false;
// First make sure the listener is not already installed, if it is we don't do anything.
for (Object installedListener : cacheNotifier.getListeners()) {
if (installedListener instanceof RemoteClusterListener && identifier.equals(((RemoteClusterListener) installedListener).getId())) {
alreadyInstalled = true;
break;
}
}
if (!alreadyInstalled) {
RemoteClusterListener listener = new RemoteClusterListener(identifier, origin, cacheNotifier, cacheManagerNotifier, eventManager, sync);
ListenerHolder listenerHolder = new ListenerHolder(listener, keyDataConversion, valueDataConversion, useStorageFormat);
cacheNotifier.addFilteredListener(listenerHolder, filter, converter, filterAnnotations);
cacheManagerNotifier.addListener(listener);
// It is possible the member is now gone after registered, if so we have to remove just to be sure
if (!cacheManager.getMembers().contains(origin)) {
cacheNotifier.removeListener(listener);
cacheManagerNotifier.removeListener(listener);
if (log.isTraceEnabled()) {
log.tracef("Removing local cluster listener for remote cluster listener that was just registered, as the origin %s went away concurrently", origin);
}
} else if (log.isTraceEnabled()) {
log.tracef("Registered local cluster listener for remote cluster listener from origin %s with id %s", origin, identifier);
}
} else if (log.isTraceEnabled()) {
log.tracef("Local cluster listener from origin %s with id %s was already installed, ignoring", origin, identifier);
}
}
} else if (log.isTraceEnabled()) {
log.tracef("Not registering local cluster listener for remote cluster listener from origin %s, as the origin went away", origin);
}
} else if (log.isTraceEnabled()) {
log.trace("Not registering local cluster listener as we are the node who registered the cluster listener");
}
}
Aggregations