Search in sources :

Example 1 with CacheManagerNotifier

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);
}
Also used : CacheManagerNotifier(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier)

Example 2 with CacheManagerNotifier

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();
}
Also used : CacheManagerNotifier(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier)

Example 3 with CacheManagerNotifier

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);
}
Also used : Address(org.infinispan.remoting.transport.Address) CacheManagerNotifier(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier)

Example 4 with CacheManagerNotifier

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");
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) ComponentRegistry(org.infinispan.factories.ComponentRegistry) CacheManagerNotifier(org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier) ListenerHolder(org.infinispan.notifications.cachelistener.ListenerHolder)

Aggregations

CacheManagerNotifier (org.infinispan.notifications.cachemanagerlistener.CacheManagerNotifier)4 Address (org.infinispan.remoting.transport.Address)2 ComponentRegistry (org.infinispan.factories.ComponentRegistry)1 ListenerHolder (org.infinispan.notifications.cachelistener.ListenerHolder)1