org.infinispan.xsite.BackupReceiverRepositoryImpl Maven / Gradle / Ivy
package org.infinispan.xsite;
import org.infinispan.Cache;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.annotations.Start;
import org.infinispan.factories.annotations.Stop;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachemanagerlistener.annotation.CacheStopped;
import org.infinispan.notifications.cachemanagerlistener.event.CacheStoppedEvent;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* @author Mircea Markus
* @since 5.2
*/
@Listener
public class BackupReceiverRepositoryImpl implements BackupReceiverRepository {
private static Log log = LogFactory.getLog(BackupReceiverRepositoryImpl.class);
private final ConcurrentMap backupReceivers = new ConcurrentHashMap<>();
public EmbeddedCacheManager cacheManager;
@Inject
public void setup(EmbeddedCacheManager cacheManager) {
this.cacheManager = cacheManager;
}
@Start
public void start() {
cacheManager.addListener(this);
}
@Stop
public void stop() {
cacheManager.removeListener(this);
}
@CacheStopped
public void cacheStopped(CacheStoppedEvent cse) {
log.debugf("Processing cache stop: %s. Cache name: '%s'", cse, cse.getCacheName());
for (SiteCachePair scp : backupReceivers.keySet()) {
log.debugf("Processing entry %s", scp);
if (scp.localCacheName.equals(cse.getCacheName())) {
log.debugf("Deregistering backup receiver %s", scp);
backupReceivers.remove(scp);
}
}
}
/**
* Returns the local cache associated defined as backup for the provided remote (site, cache) combo, or throws an
* exception of no such site is defined.
*
* Also starts the cache if not already stated; that is because the cache is needed for update after when this method
* is invoked.
*/
@Override
public BackupReceiver getBackupReceiver(String remoteSite, String remoteCache) {
SiteCachePair toLookFor = new SiteCachePair(remoteCache, remoteSite);
BackupReceiver backupManager = backupReceivers.get(toLookFor);
if (backupManager != null) return backupManager;
//check the default cache first
Configuration dcc = cacheManager.getDefaultCacheConfiguration();
if (isBackupForRemoteCache(remoteSite, remoteCache, dcc, EmbeddedCacheManager.DEFAULT_CACHE_NAME)) {
Cache
© 2015 - 2025 Weber Informatics LLC | Privacy Policy