本文整理汇总了Java中net.sf.ehcache.config.Configuration类的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Configuration类属于net.sf.ehcache.config包,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEHCacheCompatiblity
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testEHCacheCompatiblity() throws Exception {
// get the default cache manager
CacheManagerFactory factory = new DefaultCacheManagerFactory();
CacheManager manager = factory.getInstance();
assertEquals(Status.STATUS_ALIVE, manager.getStatus());
// create another unrelated cache manager
Configuration conf =
ConfigurationFactory.parseConfiguration(DefaultCacheManagerFactory.class.getResource("/test-ehcache.xml"));
assertNotNull(conf);
conf.setName("otherCache");
CacheManager other = CacheManager.create(conf);
assertEquals(Status.STATUS_ALIVE, other.getStatus());
// shutdown this unrelated cache manager
other.shutdown();
assertEquals(Status.STATUS_SHUTDOWN, other.getStatus());
// the default cache manager should be still running
assertEquals(Status.STATUS_ALIVE, manager.getStatus());
factory.doStop();
// the default cache manger is shutdown
assertEquals(Status.STATUS_SHUTDOWN, manager.getStatus());
}
示例2: ServletCache
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
private ServletCache(String name, int type) {
this.type = type;
Configuration managerConfig = new Configuration();
CacheConfiguration mqCf = new CacheConfiguration(name, CacheConfig
.getConfig().getMaxElementsInMemory());
mqCf.setEternal(true);
DiskStoreConfiguration dsCf = new DiskStoreConfiguration();
dsCf.setPath(CacheConfig.getConfig().getDiskStorePath());
managerConfig.addDiskStore(dsCf);
mqCf.setMaxElementsOnDisk(0);
mqCf.setMaxEntriesLocalHeap(CacheConfig.getConfig()
.getMaxElementsInMemory());
mqCf.persistence(new PersistenceConfiguration()
.strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP));
mqCf.setTransactionalMode("OFF");
mqCf.setMemoryStoreEvictionPolicy(CacheConfig.getConfig()
.getMemoryStoreEvictionPolicy());
managerConfig.addCache(mqCf);
cacheManager = new CacheManager(managerConfig);
cache = cacheManager.getCache(name);
}
示例3: internalCreateCacheManager
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
/**
* Actual creation of the singleton.
*
* @param config
* the parsed EhCache configuration
* @return the cache manager
* @throws CacheException
* in case the creation failed
*/
private static synchronized CacheManager internalCreateCacheManager(Configuration config)
throws CacheException {
if (SINGLETON != null) {
extendEhCacheWithCustomConfig(SINGLETON, config);
} else {
// for better control over the files created by the application override the diskstore
// path
// for flushing cached data to disk
overrideDiskStorePath(config);
// disable the update check
config.setUpdateCheck(false);
SINGLETON = new CacheManager(config);
}
return SINGLETON;
}
示例4: getInstance
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
public synchronized CacheManager getInstance() {
if (cacheManager == null) {
cacheManager = createCacheManagerInstance();
// always turn off ET phone-home
LOG.debug("Turning off EHCache update checker ...");
Configuration config = cacheManager.getConfiguration();
try {
// need to set both the system property and bypass the setUpdateCheck method as that can be changed dynamically
System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
ReflectionHelper.setField(config.getClass().getDeclaredField("updateCheck"), config, false);
LOG.info("Turned off EHCache update checker. updateCheck={}", config.getUpdateCheck());
} catch (Throwable e) {
// ignore
LOG.warn("Error turning off EHCache update checker. Beware information sent over the internet!", e);
}
}
return cacheManager;
}
示例5: testCreateCacheManagers
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testCreateCacheManagers() throws Exception {
// no arg
assertNotNull("create with no arg", EHCacheUtil.createCacheManager());
URL configURL = EHCacheUtil.class.getResource("/test-ehcache.xml");
assertNotNull(configURL);
// string
assertNotNull("create with string", EHCacheUtil.createCacheManager(configURL.getPath()));
// url
assertNotNull("create with url", EHCacheUtil.createCacheManager(configURL));
// inputstream
assertNotNull("create with inputstream", EHCacheUtil.createCacheManager(configURL.openStream()));
// config
Configuration conf = ConfigurationFactory.parseConfiguration(configURL);
assertNotNull(conf);
assertNotNull("create with configuration", EHCacheUtil.createCacheManager(conf));
}
示例6: createTestCacheManager
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
/**
* Creates a unique cache manager.
*
* @param uniqueName the unique name, typically a test case class name
* @return the unique cache manager, not null
*/
public static CacheManager createTestCacheManager(String uniqueName) {
ArgumentChecker.notNull(uniqueName, "uniqueName");
if (UNIQUE_TEST_NAMES.putIfAbsent(uniqueName, uniqueName) != null) {
throw new OpenGammaRuntimeException("CacheManager has already been created with unique name: " + uniqueName);
}
try {
InputStream configStream = getTestEhCacheConfig();
Configuration config = ConfigurationFactory.parseConfiguration(configStream);
config.setName(uniqueName);
config.setUpdateCheck(false);
return CacheManager.newInstance(config);
} catch (CacheException ex) {
throw new OpenGammaRuntimeException("Unable to create CacheManager", ex);
}
}
示例7: getEhCacheConfig
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
private static synchronized Configuration getEhCacheConfig() {
String ehcacheConfigFile = DEFAULT_EHCACHE_CONFIG_FILE;
String overrideEhcacheConfigFile = System.getProperty("ehcache.config"); // passed in by Ant
if (overrideEhcacheConfigFile != null) {
ehcacheConfigFile = overrideEhcacheConfigFile;
System.err.println("Using ehcache.config from system property: " + ehcacheConfigFile);
} else {
System.err.println("Using default ehcache.config file name: " + ehcacheConfigFile);
}
try (InputStream resource = EHCacheUtils.class.getResourceAsStream(ehcacheConfigFile)) {
Configuration config = ConfigurationFactory.parseConfiguration(resource);
config.setUpdateCheck(false);
return config;
} catch (IOException ex) {
throw new OpenGammaRuntimeException("Unable to read ehcache file", ex);
}
}
示例8: setupCacheSource
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
private void setupCacheSource(final boolean lazyReads, final int cacheSize, final int flushDelay) {
InMemoryViewComputationCacheSource cache = new InMemoryViewComputationCacheSource(s_fudgeContext);
ViewComputationCacheServer server = new ViewComputationCacheServer(cache);
_serverSocket = new ServerSocketFudgeConnectionReceiver(cache.getFudgeContext(), server, Executors
.newCachedThreadPool());
_serverSocket.setLazyFudgeMsgReads(lazyReads);
_serverSocket.start();
_socket = new SocketFudgeConnection(cache.getFudgeContext());
_socket.setFlushDelay(flushDelay);
try {
_socket.setInetAddress(InetAddress.getLocalHost());
} catch (UnknownHostException e) {
throw new OpenGammaRuntimeException("", e);
}
_socket.setPortNumber(_serverSocket.getPortNumber());
RemoteCacheClient client = new RemoteCacheClient(_socket);
Configuration configuration = new Configuration();
CacheConfiguration cacheConfig = new CacheConfiguration();
cacheConfig.setMaxElementsInMemory(cacheSize);
configuration.setDefaultCacheConfiguration(cacheConfig);
_cacheSource = new RemoteViewComputationCacheSource(client, new DefaultFudgeMessageStoreFactory(
new InMemoryBinaryDataStoreFactory(), s_fudgeContext), _cacheManager);
}
示例9: getCacheManager
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
private CacheManager getCacheManager() {
if (manager == null) {
Configuration config = new Configuration();
CacheConfiguration cacheconfig = new CacheConfiguration(getName(), maxElementsInMemory);
cacheconfig.setDiskExpiryThreadIntervalSeconds(diskExpiryThreadIntervalSeconds);
cacheconfig.setDiskPersistent(diskPersistent);
cacheconfig.setEternal(eternal);
cacheconfig.setMaxElementsOnDisk(maxElementsOnDisk);
cacheconfig.setMemoryStoreEvictionPolicyFromObject(memoryStoreEvictionPolicy);
cacheconfig.setOverflowToDisk(overflowToDisk);
cacheconfig.setTimeToIdleSeconds(timeToIdleSeconds);
cacheconfig.setTimeToLiveSeconds(timeToLiveSeconds);
DiskStoreConfiguration diskStoreConfigurationParameter = new DiskStoreConfiguration();
diskStoreConfigurationParameter.setPath(getPath().getAbsolutePath());
config.addDiskStore(diskStoreConfigurationParameter);
config.setDefaultCacheConfiguration(cacheconfig);
manager = new CacheManager(config);
}
return manager;
}
示例10: main
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
public static void main(String[] args) throws IllegalAccessException {
CacheManager manager = CacheManager.create();
Configuration configuration = manager.getConfiguration();
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
Object object= poolConfig;
Field[] fields = object.getClass().getDeclaredFields();
String prefix="cache.ehcache.";
for(Field field:fields){
field.setAccessible(true);
Method method = getSetMethod(object.getClass(),field);
if(method!=null&& CacheConfig.checkIsBasicType(field.getType())){
System.out.println("#默认值"+field.get(object));
System.out.println(prefix+field.getName());
}
}
}
示例11: afterPropertiesSet
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
public void afterPropertiesSet() throws IOException, CacheException {
log.info("Initializing EHCache CacheManager");
Configuration config = null;
if (this.configLocation != null) {
config = ConfigurationFactory
.parseConfiguration(this.configLocation.getInputStream());
if (this.diskStoreLocation != null) {
DiskStoreConfiguration dc = new DiskStoreConfiguration();
dc.setPath(this.diskStoreLocation.getFile().getAbsolutePath());
try {
config.addDiskStore(dc);
} catch (ObjectExistsException e) {
log.warn("if you want to config distStore in spring,"
+ " please remove diskStore in config file!", e);
}
}
}
if (config != null) {
this.cacheManager = new CacheManager(config);
} else {
this.cacheManager = new CacheManager();
}
if (this.cacheManagerName != null) {
this.cacheManager.setName(this.cacheManagerName);
}
}
示例12: getProperties
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
@Override
public Properties getProperties() {
Configuration ec = cacheManager.getConfiguration();
Properties p = new Properties();
p.put("name", ec.getName());
p.put("source", ec.getConfigurationSource().toString());
p.put("timeoutSeconds", ec.getDefaultTransactionTimeoutInSeconds());
p.put("maxBytesDisk", ec.getMaxBytesLocalDisk());
p.put("maxBytesHeap", ec.getMaxBytesLocalHeap());
p.put("maxDepth", ec.getSizeOfPolicyConfiguration().getMaxDepth());
p.put("defaultCacheMaxEntries", ec.getDefaultCacheConfiguration().getMaxEntriesLocalHeap());
p.put("defaultCacheTimeToIdleSecs", ec.getDefaultCacheConfiguration().getTimeToIdleSeconds());
p.put("defaultCacheTimeToLiveSecs", ec.getDefaultCacheConfiguration().getTimeToLiveSeconds());
p.put("defaultCacheEternal", ec.getDefaultCacheConfiguration().isEternal());
return p;
}
示例13: init
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
/**
* Itializes the service by creating a manager object with a given configuration file.
*/
private void init( )
{
Configuration configuration = ConfigurationFactory.parseConfiguration( );
configuration.setName( LUTECE_CACHEMANAGER_NAME );
_manager = CacheManager.create( configuration );
loadDefaults( );
loadCachesConfig( );
boolean bJmxMonitoring = AppPropertiesService.getProperty( PROPERTY_JMX_MONITORING, FALSE ).equals( TRUE );
if ( bJmxMonitoring )
{
initJmxMonitoring( );
}
}
示例14: BigMemoryGoStore
import net.sf.ehcache.config.Configuration; //导入依赖的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);
}
示例15: getInjector
import net.sf.ehcache.config.Configuration; //导入依赖的package包/类
private Injector getInjector(Properties customProperties) {
Injector injector = Guice.createInjector(new JoynrPropertiesModule(customProperties), new AbstractModule() {
@Override
protected void configure() {
bind(DomainAccessControlProvisioning.class).to(StaticDomainAccessControlProvisioning.class);
bind(DomainAccessControlStore.class).to(DomainAccessControlStoreEhCache.class);
}
@Provides
CacheManager provideCacheManager() {
Configuration configuration = new Configuration();
configuration.setName("GDACEhCacheManager");
return CacheManager.create(configuration);
}
});
return injector;
}