当前位置: 首页>>代码示例>>Java>>正文


Java CacheEventListener类代码示例

本文整理汇总了Java中net.sf.ehcache.event.CacheEventListener的典型用法代码示例。如果您正苦于以下问题:Java CacheEventListener类的具体用法?Java CacheEventListener怎么用?Java CacheEventListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CacheEventListener类属于net.sf.ehcache.event包,在下文中一共展示了CacheEventListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCacheEventListener

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
@Override
public CacheEventListener createCacheEventListener(Properties props) {
    try {
        if (props == null || props.isEmpty()) {
            manager = EhcacheHydratedCacheManagerImpl.getInstance();
        } else {
            String managerClass = props.getProperty("managerClass");
            Class<?> clazz = Class.forName(managerClass);
            Method method = clazz.getDeclaredMethod("getInstance");
            manager = (HydratedCacheManager) method.invoke(null);
        }
    } catch (Exception e) {
        throw new RuntimeException("Unable to create a CacheEventListener instance", e);
    }
    return (CacheEventListener) manager;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:17,代码来源:HydratedCacheEventListenerFactory.java

示例2: createCache

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
/**
 * Create a raw Cache object based on the configuration of this FactoryBean.
 */
protected Cache createCache() {
	// Only call EHCache 1.6 constructor if actually necessary (for compatibility with EHCache 1.3+)
	Cache cache = (!this.clearOnFlush) ?
			new Cache(this.cacheName, this.maxElementsInMemory, this.memoryStoreEvictionPolicy,
					this.overflowToDisk, null, this.eternal, this.timeToLive, this.timeToIdle,
					this.diskPersistent, this.diskExpiryThreadIntervalSeconds, null,
					this.bootstrapCacheLoader, this.maxElementsOnDisk, this.diskSpoolBufferSize,
					this.clearOnFlush) :
			new Cache(this.cacheName, this.maxElementsInMemory, this.memoryStoreEvictionPolicy,
					this.overflowToDisk, null, this.eternal, this.timeToLive, this.timeToIdle,
					this.diskPersistent, this.diskExpiryThreadIntervalSeconds, null,
					this.bootstrapCacheLoader, this.maxElementsOnDisk, this.diskSpoolBufferSize);

	if (this.cacheEventListeners != null) {
		for (CacheEventListener listener : this.cacheEventListeners) {
			cache.getCacheEventNotificationService().registerListener(listener);
		}
	}
	if (this.disabled) {
		cache.setDisabled(true);
	}
	net.sf.ehcache.config.CacheConfiguration config = cache.getCacheConfiguration();
	config.setMaxEntriesLocalHeap(maxElementsInMemory);
	return cache;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:29,代码来源:EhCacheFactoryBean.java

示例3: BigMemoryGoStore

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
public BigMemoryGoStore() {
    Configuration managerConfiguration = new Configuration()
            .name("benchmark")
            .cache(new CacheConfiguration()
                    .name("store")
                    .maxBytesLocalHeap(50, MemoryUnit.MEGABYTES)
                    .maxBytesLocalOffHeap(500, MemoryUnit.MEGABYTES)
                    .eternal(true)
            );

    cacheManager = CacheManager.create(managerConfiguration);
    cache = cacheManager.getCache("store");

    // get notified when cache is not big enough
    CacheEventListener evictionListener = new CacheEventListenerAdapter() {
        @Override
        public void notifyElementEvicted(Ehcache ehcache, Element element) {
            cacheFull = true;
        }
    };
    cache.getCacheEventNotificationService().registerListener(evictionListener);
}
 
开发者ID:bgranvea,项目名称:offheapstore-benchmark,代码行数:23,代码来源:BigMemoryGoStore.java

示例4: extendEhCacheWithCustomConfig

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
/**
 * Extend the already initialized cache manager with additional configuration.
 *
 * @param cacheManager
 *            the cache manager to modify
 * @param config
 *            the configuration to parse for settings that can be added at runtime
 */
@SuppressWarnings("unchecked")
private static void extendEhCacheWithCustomConfig(CacheManager cacheManager,
        Configuration config) {

    ConfigurationHelper helper = new ConfigurationHelper(cacheManager, config);
    Set<net.sf.ehcache.Cache> caches = helper.createCaches();
    for (net.sf.ehcache.Cache cache : caches) {
        if (cacheManager.cacheExists(cache.getName())) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Skipping cache with name " + cache.getName()
                        + " because it already exists");
            }
            Set<CacheEventListener> listeners = cache.getCacheEventNotificationService()
                    .getCacheEventListeners();
            net.sf.ehcache.Cache existCache = cacheManager.getCache(cache.getName());
            for (CacheEventListener listener : listeners) {
                LOG.debug("copy cache event listener for cache " + cache.getName());
                existCache.getCacheEventNotificationService().registerListener(listener);
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Adding cache with name " + cache.getName());
            }
            cacheManager.addCache(cache);
        }
    }
    attachPeerProviderToPlaceHolder(cacheManager, helper);
    attachPeerListenerToPlaceHolder(cacheManager, helper);
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:38,代码来源:SingletonEhCacheManagerFactory.java

示例5: registerCacheEventListener

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
@Override
public void registerCacheEventListener(org.sakaiproject.memory.api.CacheEventListener cacheEventListener) {
    super.registerCacheEventListener(cacheEventListener);
    if (cacheEventListener == null) {
        cache.getCacheEventNotificationService().unregisterListener(this);
    } else {
        cache.getCacheEventNotificationService().registerListener(this);
    }
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:10,代码来源:EhcacheCache.java

示例6: createInMemoryCache

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
public static Ehcache createInMemoryCache(String cacheName, CacheEntryFactory entryFactory, int maxElements) {
  CacheManager manager = CacheManager.getInstance();
  Ehcache cache = getCache(cacheName);
  if (cache == null) {
    // Create the cache
    cache = new Cache(cacheName,
        maxElements,
        memoryStoreEvictionPolicy, overflowToDisk,
        diskStorePath, eternal, timeToLive,
        timeToIdle, diskPersistent,
        diskExpiryThreadIntervalSeconds, null);
    // Associate the cacheEntryFactory with the cache
    SelfPopulatingCache selfPopulatingCache = new SelfPopulatingCache(cache,
        entryFactory);
    // Add any additional listener properties
    if (manager.getCachePeerListener("RMI") != null) {
      LOG.info("Setting RMI properties");
      Properties properties = new Properties();
      properties.put("replicateAsynchronously", "true");
      properties.put("replicatePuts", "false");
      properties.put("replicateUpdates", "true");
      properties.put("replicateRemovals", "true");
      properties.put("replicateUpdatesViaCopy", "false");
      properties.put("asynchronousReplicationIntervalMillis", "1000");
      RMICacheReplicatorFactory factory = new RMICacheReplicatorFactory();
      CacheEventListener listener = factory.createCacheEventListener(properties);
      selfPopulatingCache.getCacheEventNotificationService().registerListener(listener);
      RMIBootstrapCacheLoaderFactory bootstrapFactory = new RMIBootstrapCacheLoaderFactory();
      BootstrapCacheLoader bootstrapCacheLoader = bootstrapFactory.createBootstrapCacheLoader(new Properties());
      selfPopulatingCache.setBootstrapCacheLoader(bootstrapCacheLoader);
      LOG.debug("RMI enabled");
    }
    // Make the cache available
    manager.addCache(selfPopulatingCache);
    LOG.info("cache created: " + cache.getName());
  }
  return cache;
}
 
开发者ID:Concursive,项目名称:concourseconnect-community,代码行数:39,代码来源:CacheUtils.java

示例7: getCacheEventListener

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
public CacheEventListener getCacheEventListener() {
    return cacheEventListener;
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:4,代码来源:JbootEhcacheImpl.java

示例8: setCacheEventListener

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
public void setCacheEventListener(CacheEventListener cacheEventListener) {
    this.cacheEventListener = cacheEventListener;
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:4,代码来源:JbootEhcacheImpl.java

示例9: createCacheEventListener

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
@Override
public CacheEventListener createCacheEventListener(Properties properties) {
    return new CustomerCacheEventListener();
}
 
开发者ID:yiduyangyi,项目名称:cache,代码行数:5,代码来源:CustomerCacheEventListenerFactory.java

示例10: afterPropertiesSet

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws CacheException, IOException {
	// If no cache name given, use bean name as cache name.
	String cacheName = getName();
	if (cacheName == null) {
		cacheName = this.beanName;
		setName(cacheName);
	}

	// If no CacheManager given, fetch the default.
	if (this.cacheManager == null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Using default EhCache CacheManager for cache region '" + cacheName + "'");
		}
		this.cacheManager = CacheManager.getInstance();
	}

	synchronized (this.cacheManager) {
		// Fetch cache region: If none with the given name exists, create one on the fly.
		Ehcache rawCache;
		boolean cacheExists = this.cacheManager.cacheExists(cacheName);

		if (cacheExists) {
			if (logger.isDebugEnabled()) {
				logger.debug("Using existing EhCache cache region '" + cacheName + "'");
			}
			rawCache = this.cacheManager.getEhcache(cacheName);
		}
		else {
			if (logger.isDebugEnabled()) {
				logger.debug("Creating new EhCache cache region '" + cacheName + "'");
			}
			rawCache = createCache();
			rawCache.setBootstrapCacheLoader(this.bootstrapCacheLoader);
		}

		if (this.cacheEventListeners != null) {
			for (CacheEventListener listener : this.cacheEventListeners) {
				rawCache.getCacheEventNotificationService().registerListener(listener);
			}
		}

		// Needs to happen after listener registration but before setStatisticsEnabled
		if (!cacheExists) {
			this.cacheManager.addCache(rawCache);
		}

		// Only necessary on EhCache <2.7: As of 2.7, statistics are on by default.
		if (setStatisticsAvailable) {
			if (this.statisticsEnabled) {
				rawCache.setStatisticsEnabled(true);
			}
			if (this.sampledStatisticsEnabled) {
				rawCache.setSampledStatisticsEnabled(true);
			}
		}
		if (this.disabled) {
			rawCache.setDisabled(true);
		}

		Ehcache decoratedCache = decorateCache(rawCache);
		if (decoratedCache != rawCache) {
			this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
		}
		this.cache = decoratedCache;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:68,代码来源:EhCacheFactoryBean.java

示例11: afterPropertiesSet

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws CacheException {
	// If no cache name given, use bean name as cache name.
	String cacheName = getName();
	if (cacheName == null) {
		cacheName = this.beanName;
		setName(cacheName);
	}

	// If no CacheManager given, fetch the default.
	if (this.cacheManager == null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Using default EhCache CacheManager for cache region '" + cacheName + "'");
		}
		this.cacheManager = CacheManager.getInstance();
	}

	synchronized (this.cacheManager) {
		// Fetch cache region: If none with the given name exists, create one on the fly.
		Ehcache rawCache;
		boolean cacheExists = this.cacheManager.cacheExists(cacheName);

		if (cacheExists) {
			if (logger.isDebugEnabled()) {
				logger.debug("Using existing EhCache cache region '" + cacheName + "'");
			}
			rawCache = this.cacheManager.getEhcache(cacheName);
		}
		else {
			if (logger.isDebugEnabled()) {
				logger.debug("Creating new EhCache cache region '" + cacheName + "'");
			}
			rawCache = createCache();
			rawCache.setBootstrapCacheLoader(this.bootstrapCacheLoader);
		}

		if (this.cacheEventListeners != null) {
			for (CacheEventListener listener : this.cacheEventListeners) {
				rawCache.getCacheEventNotificationService().registerListener(listener);
			}
		}

		// Needs to happen after listener registration but before setStatisticsEnabled
		if (!cacheExists) {
			this.cacheManager.addCache(rawCache);
		}

		// Only necessary on EhCache <2.7: As of 2.7, statistics are on by default.
		if (this.statisticsEnabled && setStatisticsEnabledMethod != null) {
			ReflectionUtils.invokeMethod(setStatisticsEnabledMethod, rawCache, true);
		}
		if (this.sampledStatisticsEnabled && setSampledStatisticsEnabledMethod != null) {
			ReflectionUtils.invokeMethod(setSampledStatisticsEnabledMethod, rawCache, true);
		}

		if (this.disabled) {
			rawCache.setDisabled(true);
		}

		Ehcache decoratedCache = decorateCache(rawCache);
		if (decoratedCache != rawCache) {
			this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
		}
		this.cache = decoratedCache;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:67,代码来源:EhCacheFactoryBean.java

示例12: CacheEventListenerRegistry

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
public CacheEventListenerRegistry(List<CacheEventListener> eventListeners) {
    this.eventListeners = eventListeners;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:CacheEventListenerRegistry.java

示例13: addCacheEventListener

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
public void addCacheEventListener(CacheEventListener listener) {
    getEventListeners().add(listener);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:CacheEventListenerRegistry.java

示例14: getEventListeners

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
public synchronized List<CacheEventListener> getEventListeners() {
    if (eventListeners == null) {
        eventListeners = new ArrayList<CacheEventListener>();
    }
    return eventListeners;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:CacheEventListenerRegistry.java

示例15: initializeCache

import net.sf.ehcache.event.CacheEventListener; //导入依赖的package包/类
/**
 * Returns {@link Cache} instance or create new one if not exists.
 * 
 * @return {@link Cache}
 */
public Ehcache initializeCache() {
    CacheManager cacheManager = getCacheManagerFactory().getInstance();
    Ehcache cache;
    if (cacheManager.cacheExists(config.getCacheName())) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Found an existing cache: {}", config.getCacheName());
            LOG.trace("Cache {} currently contains {} elements",
                    config.getCacheName(),
                    cacheManager.getEhcache(config.getCacheName()).getSize());
        }
        cache = cacheManager.getEhcache(config.getCacheName());
    } else {
        cache = new Cache(config.getCacheName(),
                config.getMaxElementsInMemory(),
                config.getMemoryStoreEvictionPolicy(),
                config.isOverflowToDisk(),
                config.getDiskStorePath(),
                config.isEternal(),
                config.getTimeToLiveSeconds(),
                config.getTimeToIdleSeconds(),
                config.isDiskPersistent(),
                config.getDiskExpiryThreadIntervalSeconds(),
                null);

        for (CacheEventListener listener : config.getEventListenerRegistry().getEventListeners()) {
            cache.getCacheEventNotificationService().registerListener(listener);
        }

        for (CacheLoaderWrapper loader : config.getCacheLoaderRegistry().getCacheLoaders()) {
            loader.init(cache);
            cache.registerCacheLoader(loader);
        }

        cacheManager.addCache(cache);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Added a new cache: " + cache.getName());
        }
    }

    return cache;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:48,代码来源:CacheEndpoint.java


注:本文中的net.sf.ehcache.event.CacheEventListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。