本文整理汇总了Java中net.sf.ehcache.config.Configuration.setName方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setName方法的具体用法?Java Configuration.setName怎么用?Java Configuration.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.ehcache.config.Configuration
的用法示例。
在下文中一共展示了Configuration.setName方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
示例3: 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( );
}
}
示例4: afterPropertiesSet
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void afterPropertiesSet() throws Exception {
Cache.ID = key + "." + Dates.newDateStringOfFormatDateTimeSSSNoneSpace();
Cache.HOST = Utils.getLocalHostIP();
Cache.CACHE_STORE = key + spliter + "cache" + spliter + "store";
Cache.CACHE_STORE_SYNC = Cache.CACHE_STORE + spliter + "sync";
if (this.localEnabled) {
Configuration configuration = new Configuration();
configuration.setName(Cache.ID);
configuration.setMaxBytesLocalHeap(localMaxBytesLocalHeap);
configuration.setMaxBytesLocalDisk(localMaxBytesLocalDisk);
// DiskStore
// 每次启动设置新的文件地址,以避免重启期间一级缓存未同步,以及单机多应用启动造成EhcacheManager重复的问题.
DiskStoreConfiguration dsc = new DiskStoreConfiguration();
dsc.setPath(localStoreLocation + Cache.ID);
configuration.diskStore(dsc);
// DefaultCache
CacheConfiguration defaultCacheConfiguration = new CacheConfiguration();
defaultCacheConfiguration.setEternal(false);
defaultCacheConfiguration.setOverflowToDisk(true);
defaultCacheConfiguration.setDiskPersistent(false);
defaultCacheConfiguration.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU);
defaultCacheConfiguration.setDiskExpiryThreadIntervalSeconds(localDiskExpiryThreadIntervalSeconds);
// 默认false,使用引用.设置为true,避免外部代码修改了缓存对象.造成EhCache的缓存对象也随之改变
// 但是设置为true后,将引起element的tti不自动刷新.如果直接新建element去覆盖原值.则本地ttl和远程ttl会产生一定的误差.
// 因此,使用时放弃手动覆盖方式刷新本地tti,当本地tti过期后,自动从Redis中再获取即可.
defaultCacheConfiguration.copyOnRead(true);
defaultCacheConfiguration.copyOnWrite(true);
defaultCacheConfiguration.setTimeToIdleSeconds(localTimeToIdleSeconds);
defaultCacheConfiguration.setTimeToLiveSeconds(localTimeToLiveSeconds);
configuration.setDefaultCacheConfiguration(defaultCacheConfiguration);
configuration.setDynamicConfig(false);
configuration.setUpdateCheck(false);
this.cacheManager = new CacheManager(configuration);
this.cacheSync = new RedisPubSubSync(this);// 使用Redis Topic发送订阅缓存变更消息
}
}
示例5: load
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
public static void load() {
Configuration config = new Configuration();
config.setName("stallionFilterCache");
CacheManager.create(config);
manager = CacheManager.create();
}
示例6: afterPropertiesSet
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws CacheException {
logger.info("Initializing EhCache CacheManager");
Configuration configuration = (this.configLocation != null ?
EhCacheManagerUtils.parseConfiguration(this.configLocation) : ConfigurationFactory.parseConfiguration());
if (this.cacheManagerName != null) {
configuration.setName(this.cacheManagerName);
}
if (this.shared) {
// Old-school EhCache singleton sharing...
// No way to find out whether we actually created a new CacheManager
// or just received an existing singleton reference.
this.cacheManager = CacheManager.create(configuration);
}
else if (this.acceptExisting) {
// EhCache 2.5+: Reusing an existing CacheManager of the same name.
// Basically the same code as in CacheManager.getInstance(String),
// just storing whether we're dealing with an existing instance.
synchronized (CacheManager.class) {
this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName);
if (this.cacheManager == null) {
this.cacheManager = new CacheManager(configuration);
}
else {
this.locallyManaged = false;
}
}
}
else {
// Throwing an exception if a CacheManager of the same name exists already...
this.cacheManager = new CacheManager(configuration);
}
}
示例7: CacheQueue
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
/**
* 构造函数
*
* @param block
* --是否为阻塞队列,true是阻塞队列,false是非阻塞队列
* @param cacheLength
* --内存中队列长度,值>0;
* @param persistDirPath
* --数据落地目录(<b>注意:一个队列对应一个目录路径,多个队列共享一个目录路径,是不允许的,会出现数据不一致的情况! <
* /b>)
*/
public CacheQueue(final boolean block, final int cacheLength,
final String persistDirPath) {
if (cacheLength < 0) {
throw new AppRuntimeException("cacheLength must >0!");
}
if (block) {
this.tmpQueue = new BlockQueue();
} else {
this.tmpQueue = new NoBlockConcurrentQueue();
}
psKeys = new ConcurrentLinkedQueue<Long>();
hcName = "cq-" + persistDirPath.hashCode();
Configuration managerConfig = new Configuration();
CacheConfiguration mqCf = new CacheConfiguration(hcName, cacheLength);
mqCf.setEternal(true);
// mqCf.setDiskStorePath(persistDirPath);
mqCf.setMaxElementsOnDisk(0);
mqCf.setTransactionalMode("OFF");
mqCf.setMemoryStoreEvictionPolicy("LFU");
// mqCf.setDiskPersistent(true);
// mqCf.setMaxElementsInMemory(cacheLength);
mqCf.setMaxEntriesLocalHeap(cacheLength);
// mqCf.setOverflowToDisk(true);
mqCf.persistence(new PersistenceConfiguration()
.strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP));
managerConfig.addCache(mqCf);
DiskStoreConfiguration dsCf = new DiskStoreConfiguration();
dsCf.setPath(persistDirPath);
managerConfig.addDiskStore(dsCf);
managerConfig.setName(hcName);
// cacheManager = new CacheManager(managerConfig);
cacheManager = CacheManager.newInstance(managerConfig);
cache = cacheManager.getCache(hcName);
count = new AtomicLong(0);
}
示例8: afterPropertiesSet
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
public void afterPropertiesSet() throws IOException, CacheException {
logger.info("Initializing EhCache CacheManager");
InputStream is = (this.configLocation != null ? this.configLocation.getInputStream() : null);
try {
// A bit convoluted for EhCache 1.x/2.0 compatibility.
// To be much simpler once we require EhCache 2.1+
if (this.cacheManagerName != null) {
if (this.shared && createWithConfiguration == null) {
// No CacheManager.create(Configuration) method available before EhCache 2.1;
// can only set CacheManager name after creation.
this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
this.cacheManager.setName(this.cacheManagerName);
}
else {
Configuration configuration = (is != null ? ConfigurationFactory.parseConfiguration(is) :
ConfigurationFactory.parseConfiguration());
configuration.setName(this.cacheManagerName);
if (this.shared) {
this.cacheManager = (CacheManager) ReflectionUtils.invokeMethod(createWithConfiguration, null, configuration);
}
else {
this.cacheManager = new CacheManager(configuration);
}
}
}
// For strict backwards compatibility: use simplest possible constructors...
else if (this.shared) {
this.cacheManager = (is != null ? CacheManager.create(is) : CacheManager.create());
}
else {
this.cacheManager = (is != null ? new CacheManager(is) : new CacheManager());
}
}
finally {
if (is != null) {
is.close();
}
}
}
示例9: provideCacheManager
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
@Provides
@Singleton
CacheManager provideCacheManager() {
Configuration configuration = new Configuration();
configuration.setName("GDACEhCacheManager");
return CacheManager.create(configuration);
}
示例10: provideCacheManager
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
@Provides
@Singleton
public CacheManager provideCacheManager() {
Configuration configuration = new Configuration();
configuration.setName("LDACEhCacheManager");
configuration.setUpdateCheck(false);
return CacheManager.create(configuration);
}
示例11: afterPropertiesSet
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws IOException, CacheException {
logger.info("Initializing EhCache CacheManager");
InputStream is = (this.configLocation != null ? this.configLocation.getInputStream() : null);
try {
Configuration configuration = (is != null ?
ConfigurationFactory.parseConfiguration(is) : ConfigurationFactory.parseConfiguration());
if (this.cacheManagerName != null) {
configuration.setName(this.cacheManagerName);
}
if (this.shared) {
// Old-school EhCache singleton sharing...
// No way to find out whether we actually created a new CacheManager
// or just received an existing singleton reference.
this.cacheManager = CacheManager.create(configuration);
}
else if (this.acceptExisting) {
// EhCache 2.5+: Reusing an existing CacheManager of the same name.
// Basically the same code as in CacheManager.getInstance(String),
// just storing whether we're dealing with an existing instance.
synchronized (CacheManager.class) {
this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName);
if (this.cacheManager == null) {
this.cacheManager = new CacheManager(configuration);
}
else {
this.locallyManaged = false;
}
}
}
else {
// Throwing an exception if a CacheManager of the same name exists already...
this.cacheManager = new CacheManager(configuration);
}
}
finally {
if (is != null) {
is.close();
}
}
}
示例12: load
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
public static void load() {
Configuration config = new Configuration();
config.setName("stallionLocalMemoryCache");
manager = CacheManager.create();
}
示例13: init
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
@PostConstruct
@SuppressWarnings("unused")
private void init() throws Exception {
// Init Cache
Configuration c = new Configuration();
c.setName("sessionManager");
manager = CacheManager.create(c);
CacheConfiguration config = new CacheConfiguration();
config.eternal(false).name(CACHE_NAME).maxEntriesLocalHeap(maxEntries).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU).timeToIdleSeconds(timeToIdle).timeToLiveSeconds(timeToLive);
if (!manager.cacheExists(CACHE_NAME)) {
manager.addCache(new Cache(config));
}
sessions = manager.getCache(CACHE_NAME);
// Init JMS replication
ConnectionFactory factory = new ActiveMQConnectionFactory(this.url);
Connection conn = factory.createConnection();
conn.start();
jmsSession = (TopicSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Topic topic = jmsSession.createTopic(TOPIC_NAME);
tp = jmsSession.createPublisher(topic);
listener = new Thread() { // Thread created once upon container startup
@Override
public void run() {
try {
MessageConsumer consumer = jmsSession.createConsumer(topic);
while (live) {
ObjectMessage msg = (ObjectMessage) consumer.receive();
LOG.debug("Received replication message: {}", msg);
if (PUT.equals(msg.getStringProperty(ACTION_KEY))) {
sessions.put(new Element(msg.getStringProperty(TOKEN_KEY), msg.getObject()));
} else if (REMOVE.equals(msg.getStringProperty(ACTION_KEY))) {
sessions.remove(msg.getStringProperty(TOKEN_KEY));
}
}
} catch (JMSException e) {
LOG.error("Error reading replication message", e);
}
}
};
listener.start();
}
示例14: buildCacheManager
import net.sf.ehcache.config.Configuration; //导入方法依赖的package包/类
/**
* Build an EhCache {@link CacheManager} from the default configuration.
* <p>The CacheManager will be configured from "ehcache.xml" in the root of the class path
* (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
* If no configuration file can be found, a fail-safe fallback configuration will be used.
* @param name the desired name of the cache manager
* @return the new EhCache CacheManager
* @throws CacheException in case of configuration parsing failure
*/
public static CacheManager buildCacheManager(String name) throws CacheException {
Configuration configuration = ConfigurationFactory.parseConfiguration();
configuration.setName(name);
return new CacheManager(configuration);
}