Java 类net.sf.ehcache.config.Configuration 实例源码

项目:BJAF3.x    文件:ServletCache.java   
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);
}
项目:communote-server    文件:SingletonEhCacheManagerFactory.java   
/**
 * 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;
}
项目:Camel    文件:CacheManagerFactory.java   
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;
}
项目:Camel    文件:EHCacheUtilTest.java   
@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));
}
项目:Camel    文件:DefaultCacheManagerFactoryTest.java   
@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());
}
项目:FinanceAnalytics    文件:EHCacheUtils.java   
/**
 * 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);
  }
}
项目:FinanceAnalytics    文件:EHCacheUtils.java   
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);
  }
}
项目:FinanceAnalytics    文件:ServerSocketRemoteViewComputationCacheTest.java   
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);
}
项目:universal-java-matrix-package    文件:EhcacheMap.java   
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;
}
项目:dubbo-plus    文件:GenerateEhCacheDefaultConfig.java   
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());
        }
    }
}
项目:jeecms6    文件:WebEhCacheManagerFacotryBean.java   
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);
    }
}
项目:sakai    文件:EhcacheMemoryService.java   
@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;
}
项目:lutece-core    文件:CacheService.java   
/**
 * 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( );
    }
}
项目:sakai    文件:EhcacheMemoryService.java   
@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;
}
项目:Lottery    文件:WebEhCacheManagerFacotryBean.java   
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);
    }
}
项目:offheapstore-benchmark    文件:BigMemoryGoStore.java   
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);
}
项目:joynr    文件:ProvisionedDomainAccessControlStoreTest.java   
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;
}
项目:smart-cache    文件:CacheTemplate.java   
@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发送订阅缓存变更消息
    }
}
项目:airsonic    文件:CacheFactory.java   
public void afterPropertiesSet() throws Exception {
    Configuration configuration = ConfigurationFactory.parseConfiguration();

    // Override configuration to make sure cache is stored in Airsonic home dir.
    File cacheDir = new File(SettingsService.getAirsonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());

    cacheManager = CacheManager.create(configuration);
}
项目:stallion-core    文件:FilterCache.java   
public static void load() {

        Configuration config = new Configuration();
        config.setName("stallionFilterCache");
        CacheManager.create(config);
        manager = CacheManager.create();
    }
项目:spring4-understanding    文件:EhCacheManagerFactoryBean.java   
@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);
    }
}
项目:spring4-understanding    文件:EhCacheCacheManagerTests.java   
@Before
public void setup() {
    nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests")
            .defaultCache(new CacheConfiguration("default", 100)));
    addNativeCache(CACHE_NAME);

    cacheManager = new EhCacheCacheManager(nativeCacheManager);
    cacheManager.setTransactionAware(false);
    cacheManager.afterPropertiesSet();

    transactionalCacheManager = new EhCacheCacheManager(nativeCacheManager);
    transactionalCacheManager.setTransactionAware(true);
    transactionalCacheManager.afterPropertiesSet();
}
项目:spring4-understanding    文件:EhCacheCacheTests.java   
@Before
public void setUp() {
    cacheManager = new CacheManager(new Configuration().name("EhCacheCacheTests")
            .defaultCache(new CacheConfiguration("default", 100)));
    nativeCache = new net.sf.ehcache.Cache(new CacheConfiguration(CACHE_NAME, 100));
    cacheManager.addCache(nativeCache);

    cache = new EhCacheCache(nativeCache);
}
项目:Bananarama    文件:IndexedCollectionAdapter.java   
public IndexedCollectionAdapter(BananaRama parent){
    //This must be configurable in the future
    final Configuration conf = ConfigurationFactory
            .parseConfiguration();

    conf.getDefaultCacheConfiguration()
            .getPersistenceConfiguration()
            .strategy(PersistenceConfiguration.Strategy.NONE);

    cacheManager =  CacheManager.newInstance(conf);
    cache = cacheManager.addCacheIfAbsent(CACHE_NAME);
    this.parent = parent;
}
项目:BJAF3.x    文件:PersistQueue.java   
/**
 * 构造函数
 * 
 * @param block
 *            --是否为阻塞队列,true是阻塞队列,false是非阻塞队列
 * @param cacheLength
 *            --内存中队列长度,值>0;
 * @param persistDirPath
 *            --持久数据落地目录(<b>注意:一个队列对应一个目录路径,多个队列共享一个目录路径,是不允许的,会出现数据不一致的情况!
 *            < /b>)
 */
public PersistQueue(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 = "pq_" + 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.LOCALRESTARTABLE));
    managerConfig.addCache(mqCf);
    DiskStoreConfiguration dsCf = new DiskStoreConfiguration();
    dsCf.setPath(persistDirPath);
    managerConfig.addDiskStore(dsCf);
    cacheManager = new CacheManager(managerConfig);
    cache = cacheManager.getCache(hcName);
    Element e = cache.get(hcName);
    if (null == e) {
        count = new AtomicLong(0);
    } else {
        Long cv = (Long) e.getObjectValue();
        count = new AtomicLong(cv.longValue());
    }
}
项目:BJAF3.x    文件:CacheQueue.java   
/**
 * 构造函数
 * 
 * @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);
}
项目:subsonic    文件:CacheFactory.java   
public void afterPropertiesSet() throws Exception {
    Configuration configuration = ConfigurationFactory.parseConfiguration();

    // Override configuration to make sure cache is stored in Subsonic home dir.
    File cacheDir = new File(SettingsService.getSubsonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());

    cacheManager = CacheManager.create(configuration);
}
项目:communote-server    文件:DefaultEhCacheConfigurer.java   
/**
 * {@inheritDoc}
 */
@Override
public Configuration getConfiguration(Properties properties) throws CacheException {
    Configuration config = ConfigurationFactory.parseConfiguration(resolveEhcacheConfigFile());
    postProcessConfiguration(config, properties);
    return config;
}
项目:communote-server    文件:SingletonEhCacheManagerFactory.java   
/**
 * 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);
}
项目:communote-server    文件:SingletonEhCacheManagerFactory.java   
/**
 * Override the disk store path that is used for flushing cached elements to disk.
 *
 * @param config
 *            the loaded configuration
 */
private static void overrideDiskStorePath(Configuration config) {
    File diskStoreDir = new File(CommunoteRuntime.getInstance().getConfigurationManager()
            .getStartupProperties().getCacheRootDirectory(), DISK_STORE_SUBDIR);
    String diskStorePath = diskStoreDir.getAbsolutePath();
    if (StringUtils.isNotEmpty(diskStorePath)) {
        if (config.getDiskStoreConfiguration() != null) {
            // override disk store path
            config.getDiskStoreConfiguration().setPath(diskStorePath);
        }
    }
}
项目:Camel    文件:EHCacheUtil.java   
static CacheManager createCacheManager(Configuration conf) throws CacheException {
    if (useCreateNewMethod) {
        return CacheManager.newInstance(conf);
    } else {
        return CacheManager.create(conf);
    }
}
项目:purecloud-iot    文件:TestEhcacheProtocolRequirements.java   
@BeforeClass
public static void setUpGlobal() {
    final Configuration config = new Configuration();
    config.addDefaultCache(
            new CacheConfiguration("default", Integer.MAX_VALUE)
                .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
                .overflowToDisk(false));
    CACHE_MANAGER = CacheManager.create(config);
}
项目:eHMP    文件:Bootstrap.java   
private void initializeEhcacheDiskStore(Environment environment) {
    DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();
    diskStoreConfiguration.setPath(environment.getProperty(HmpProperties.EHCACHE_DATA_DIR));

    Configuration configuration = ConfigurationFactory.parseConfiguration();
    configuration.addDiskStore(diskStoreConfiguration);

    CacheManager.newInstance(configuration);
}
项目:fiware-keypass    文件:BlockingCacheFactory.java   
public BlockingCacheFactory(int timeToLiveSeconds, int maxEntriesLocalHeap) {
    Configuration cfg = new Configuration();
    CacheConfiguration.CacheDecoratorFactoryConfiguration cdfc =
            new CacheConfiguration.CacheDecoratorFactoryConfiguration();
    cdfc.setClass(BlockingCacheDecoratorFactory.class.getName());
    CacheConfiguration defaultCacheCfg = new CacheConfiguration();
    defaultCacheCfg.addCacheDecoratorFactory(cdfc);
    defaultCacheCfg.setTimeToLiveSeconds(timeToLiveSeconds);
    defaultCacheCfg.setMaxEntriesLocalHeap(maxEntriesLocalHeap);
    cfg.addDefaultCache(defaultCacheCfg);

    manager = CacheManager.create(cfg);

}
项目:FutureSonic-Server    文件:CacheFactory.java   
public void afterPropertiesSet() throws Exception {
    Configuration configuration = ConfigurationFactory.parseConfiguration();

    // Override configuration to make sure cache is stored in Subsonic home dir.
    File cacheDir = new File(SettingsService.getSubsonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());

    cacheManager = CacheManager.create(configuration);
}
项目:madsonic-server-5.1    文件:CacheFactory.java   
public void afterPropertiesSet() throws Exception {
    Configuration configuration = ConfigurationFactory.parseConfiguration();

    // Override configuration to make sure cache is stored in Madsonic home dir.
    File cacheDir = new File(SettingsService.getMadsonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());

    cacheManager = CacheManager.create(configuration);
}
项目:class-guard    文件:EhCacheManagerFactoryBean.java   
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();
        }
    }
}
项目:madsonic-server-5.0    文件:CacheFactory.java   
public void afterPropertiesSet() throws Exception {
    Configuration configuration = ConfigurationFactory.parseConfiguration();

    // Override configuration to make sure cache is stored in Subsonic home dir.
    File cacheDir = new File(SettingsService.getSubsonicHome(), "cache");
    configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());

    cacheManager = CacheManager.create(configuration);
}
项目:Brisk    文件:PortalServlet.java   
public PortalServlet()
        throws IOException
{
    logger.info("Brisk CMS started!");

    homeDirectory = new File("/Users/dmi/Documents/Labs/TestCMSTemplates");
    configDirectory = new File(homeDirectory, "conf");

    if (!homeDirectory.exists())
        throw new FileNotFoundException("Could not find brisk home directory.");

    cmsContext = new CMSContext();
    cmsContext.settings = new Settings(new File(configDirectory, "cms.properties"));
    cmsContext.homeDirectory = homeDirectory;
    cmsContext.sitesDirectory = new File(homeDirectory, "sites");
    cmsContext.imagesDirectory = new File(homeDirectory, "images");

    // Cache setup
    cmsContext.vhostCache = new VhostCache(cmsContext.settings.vhostCacheLifeTime);

    DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration().path(new File(homeDirectory, "cache").getPath());
    Configuration configuration = new Configuration().name("cmscache").diskStore(diskStoreConfiguration);
    cmsContext.cacheManager = CacheManager.create(configuration);
    cmsContext.cacheManager.addCache(createImageCache("imagecache", cmsContext.settings));
    cmsContext.cacheManager.addCache(createPageCache("pagecache", cmsContext.settings));
    cmsContext.client = ClientFactory.create();


}
项目:jooby    文件:ConfigurationBuilderTest.java   
@SuppressWarnings("rawtypes")
@Test
public void cacheManagerEventListenerFactory() {

  Config config = ConfigFactory.empty()
      .withValue("cacheManagerEventListenerFactory.class", fromAnyRef("MyEventListener"));

  Configuration eh = new ConfigurationBuilder().build(config);
  FactoryConfiguration factory = eh.getCacheManagerEventListenerFactoryConfiguration();
  assertEquals("MyEventListener", factory.getFullyQualifiedClassPath());
}