List of usage examples for org.springframework.cache.ehcache EhCacheCacheManager setCacheManager
public void setCacheManager(@Nullable net.sf.ehcache.CacheManager cacheManager)
From source file:org.ngrinder.infra.config.DynamicCacheConfig.java
/** * Create cache manager dynamically according to the configuration. * * @return EhCacheCacheManager bean//w w w . j av a 2 s. c o m */ @SuppressWarnings("rawtypes") @Bean(name = "cacheManager") public EhCacheCacheManager dynamicCacheManager() { EhCacheCacheManager cacheManager = new EhCacheCacheManager(); Configuration cacheManagerConfig; InputStream inputStream = null; try { if (!isClustered()) { inputStream = new ClassPathResource("ehcache.xml").getInputStream(); cacheManagerConfig = ConfigurationFactory.parseConfiguration(inputStream); } else { CoreLogger.LOGGER.info("In cluster mode."); inputStream = new ClassPathResource("ehcache-dist.xml").getInputStream(); cacheManagerConfig = ConfigurationFactory.parseConfiguration(inputStream); Pair<FactoryConfiguration, NetworkUtils.IPPortPair> result = createRMICacheManagerPeerProviderFactory( cacheManagerConfig); cacheManagerConfig.addCacheManagerPeerProviderFactory(result.getFirst()); cacheManagerConfig.addCacheManagerPeerListenerFactory( createPearListenerFactory(result.getSecond().getIP(), result.getSecond().getPort())); } cacheManagerConfig.setName(getCacheName()); CacheManager mgr = CacheManager.create(cacheManagerConfig); cacheManager.setCacheManager(mgr); } catch (IOException e) { CoreLogger.LOGGER.error("Error while setting up cache", e); } finally { IOUtils.closeQuietly(inputStream); } return cacheManager; }
From source file:org.ngrinder.agent.service.MockDynamicCacheConfig.java
@SuppressWarnings("rawtypes") @Override/*w w w . ja v a 2 s . co m*/ public EhCacheCacheManager dynamicCacheManager() { EhCacheCacheManager cacheManager = new EhCacheCacheManager(); Configuration cacheManagerConfig; InputStream inputStream = null; try { CoreLogger.LOGGER.info("In cluster mode."); inputStream = new ClassPathResource("ehcache-dist.xml").getInputStream(); cacheManagerConfig = ConfigurationFactory.parseConfiguration(inputStream); FactoryConfiguration peerProviderConfig = new FactoryConfiguration(); peerProviderConfig.setClass(RMICacheManagerPeerProviderFactory.class.getName()); List<String> replicatedCacheNames = getReplicatedCacheNames(cacheManagerConfig); Pair<NetworkUtils.IPPortPair, String> properties = createManualDiscoveryCacheProperties( replicatedCacheNames); NetworkUtils.IPPortPair currentListener = properties.getFirst(); String peerProperty = properties.getSecond(); peerProviderConfig.setProperties(peerProperty); cacheManagerConfig.addCacheManagerPeerProviderFactory(peerProviderConfig); System.setProperty("java.rmi.server.hostname", currentListener.getFormattedIP()); FactoryConfiguration peerListenerConfig = new FactoryConfiguration(); peerListenerConfig.setClass(RMICacheManagerPeerListenerFactory.class.getName()); String peerListenerProperty = String.format("hostName=%s, port=%d, socketTimeoutMillis=1000", currentListener.getFormattedIP(), currentListener.getPort()); peerListenerConfig.setProperties(peerListenerProperty); cacheManagerConfig.addCacheManagerPeerListenerFactory(peerListenerConfig); CoreLogger.LOGGER.info("clusterURLs:{}", peerListenerProperty); cacheManagerConfig.setName("TestCluster"); CacheManager mgr = CacheManager.create(cacheManagerConfig); cacheManager.setCacheManager(mgr); } catch (IOException e) { CoreLogger.LOGGER.error("Error while setting up cache", e); } finally { IOUtils.closeQuietly(inputStream); } return cacheManager; }