Package net.sf.ehcache.config

Examples of net.sf.ehcache.config.Configuration


public class EHCacheUtilsTest extends Assert {
    @Test
    public void testUseGlobalManager() {
        Bus bus = BusFactory.getThreadDefaultBus();
     
        Configuration conf =
                ConfigurationFactory.parseConfiguration(
                        EHCacheManagerHolder.class.getResource("/cxf-test-ehcache.xml"));
        conf.setName("myGlobalConfig");
       
        CacheManager.newInstance(conf);
       
        CacheManager manager = EHCacheUtils.getCacheManager(bus,
                EHCacheManagerHolder.class.getResource("/cxf-test-ehcache.xml"));
View Full Code Here


            // ignore
        }
        if (configFileURL == null) {
            cacheManager = CacheManager.create();
        } else {
            Configuration conf = ConfigurationFactory.parseConfiguration(configFileURL);
           
            if (bus != null) {
                conf.setName(bus.getId());
                DiskStoreConfiguration dsc = conf.getDiskStoreConfiguration();
                if (dsc != null && "java.io.tmpdir".equals(dsc.getOriginalPath())) {
                    String path = conf.getDiskStoreConfiguration().getPath() + File.separator
                        + bus.getId();
                    conf.getDiskStoreConfiguration().setPath(path);
                }
            }
           
            cacheManager = CacheManager.create(conf);
        }
View Full Code Here

    /**
     * initialises the CacheManager
     */
    protected void init(Configuration initialConfiguration, String configurationFileName, URL configurationURL,
            InputStream configurationInputStream) {
        Configuration localConfiguration = initialConfiguration;
        if (initialConfiguration == null) {
            localConfiguration = parseConfiguration(configurationFileName, configurationURL, configurationInputStream);
            this.configuration = localConfiguration;
        } else {
            this.configuration = initialConfiguration;
        }

        if (this.configuration.getTerracottaConfiguration() != null) {
            this.configuration.getTerracottaConfiguration().freezeConfig();
        }
        validateConfiguration();

        if (localConfiguration.getName() != null) {
            this.name = localConfiguration.getName();
        }

        this.allowsDynamicCacheConfig = localConfiguration.getDynamicConfig();
        this.terracottaClientConfiguration = localConfiguration.getTerracottaConfiguration();

        terracottaClient = new TerracottaClient(this, new TerracottaClientRejoinListener() {
            public void clusterRejoinStarted() {
                CacheManager.this.clusterRejoinStarted();
            }

            public void clusterRejoinComplete() {
                CacheManager.this.clusterRejoinComplete();
            }
        }, localConfiguration.getTerracottaConfiguration());

        Map<String, CacheConfiguration> cacheConfigs = localConfiguration.getCacheConfigurations();
        if (localConfiguration.getDefaultCacheConfiguration() != null
                && localConfiguration.getDefaultCacheConfiguration().isTerracottaClustered()) {
            terracottaClient.createClusteredInstanceFactory(cacheConfigs);
        } else {
            for (CacheConfiguration config : cacheConfigs.values()) {
                if (config.isTerracottaClustered()) {
                    terracottaClient.createClusteredInstanceFactory(cacheConfigs);
                    break;
                }
            }
        }

        if (terracottaClient.getClusteredInstanceFactory() != null && this.name == null) {
            this.name = CacheManager.DEFAULT_NAME;
        }

        TransactionIDFactory transactionIDFactory = createTransactionIDFactory();
        this.transactionController = new TransactionController(transactionIDFactory, configuration.getDefaultTransactionTimeoutInSeconds());

        ConfigurationHelper configurationHelper = new ConfigurationHelper(this, localConfiguration);
        configure(configurationHelper);
        status = Status.STATUS_ALIVE;

        for (CacheManagerPeerProvider cacheManagerPeerProvider : cacheManagerPeerProviders.values()) {
            cacheManagerPeerProvider.init();
        }

        cacheManagerEventListenerRegistry.init();
        addShutdownHookIfRequired();

        cacheManagerTimer = new FailSafeTimer(getName());
        checkForUpdateIfNeeded(localConfiguration.getUpdateCheck());

        mbeanRegistrationProvider = MBEAN_REGISTRATION_PROVIDER_FACTORY.createMBeanRegistrationProvider(localConfiguration);

        // do this last
        addConfiguredCaches(configurationHelper);
View Full Code Here

     *             if the configuration cannot be parsed
     */
    private synchronized Configuration parseConfiguration(String configurationFileName, URL configurationURL,
            InputStream configurationInputStream) throws CacheException {
        reinitialisationCheck();
        Configuration parsedConfig;
        if (configurationFileName != null) {

            LOG.debug("Configuring CacheManager from {}", configurationFileName);
            parsedConfig = ConfigurationFactory.parseConfiguration(new File(configurationFileName));
        } else if (configurationURL != null) {
View Full Code Here

     */
    public String getOriginalConfigurationText() {
        if (configuration.getConfigurationSource() == null) {
            return "Originally configured programmatically. No original configuration source text.";
        } else {
            Configuration originalConfiguration = configuration.getConfigurationSource().createConfiguration();
            return ConfigurationUtil.generateCacheManagerConfigurationText(originalConfiguration);
        }
    }
View Full Code Here

     */
    public String getOriginalConfigurationText(String cacheName) throws CacheException {
        if (configuration.getConfigurationSource() == null) {
            return "Originally configured programmatically. No original configuration source text.";
        } else {
            Configuration originalConfiguration = configuration.getConfigurationSource().createConfiguration();
            CacheConfiguration cacheConfiguration = originalConfiguration.getCacheConfigurations().get(cacheName);
            if (cacheConfiguration == null) {
                throw new CacheException("Cache with name '" + cacheName + "' does not exist in the original configuration");
            }
            return ConfigurationUtil.generateCacheConfigurationText(cacheConfiguration);
        }
View Full Code Here

            String configurationResourceName = null;
            if (properties != null) {
                configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME);
            }
            if (configurationResourceName == null || configurationResourceName.length() == 0) {
                Configuration configuration = ConfigurationFactory.parseConfiguration();
                manager = new CacheManager(configuration);
            } else {
                URL url;
                try {
                    url = new URL(configurationResourceName);
                } catch (MalformedURLException e) {
                    url = loadResource(configurationResourceName);
                }
                Configuration configuration = HibernateUtil.loadAndCorrectConfiguration(url);
                manager = new CacheManager(configuration);
            }
            mbeanRegistrationHelper.registerMBean(manager, properties);
        } catch (net.sf.ehcache.CacheException e) {
            if (e.getMessage().startsWith("Cannot parseConfiguration CacheManager. Attempt to create a new instance of " +
View Full Code Here

                            LOG.debug("prepending / to {}. It should be placed in the root of the classpath rather than in a package.",
                                    configurationResourceName);
                    }
                    url = loadResource(configurationResourceName);
                }
                Configuration configuration = HibernateUtil.loadAndCorrectConfiguration(url);
                manager = CacheManager.create(configuration);
                REFERENCE_COUNT.incrementAndGet();
            }
            mbeanRegistrationHelper.registerMBean(manager, properties);
        } catch (net.sf.ehcache.CacheException e) {
View Full Code Here

     * Create a cache manager configuration from the supplied url, correcting it for Hibernate compatibility.
     * <p>
     * Currently correcting for Hibernate compatibility means simply switching any identity based value modes to serialization.
     */
    static Configuration loadAndCorrectConfiguration(URL url) {
        Configuration config = ConfigurationFactory.parseConfiguration(url);
        if (config.getDefaultCacheConfiguration().isTerracottaClustered()) {
            if (ValueMode.IDENTITY.equals(config.getDefaultCacheConfiguration().getTerracottaConfiguration().getValueMode())) {
                LOG.warn("The default cache value mode for this Ehcache configuration is \"identity\". This is incompatible with clustered "
                        + "Hibernate caching - the value mode has therefore been switched to \"serialization\"");
                config.getDefaultCacheConfiguration().getTerracottaConfiguration().setValueMode(ValueMode.SERIALIZATION.name());
            }
            setupHibernateTimeoutBehavior(config.getDefaultCacheConfiguration().getTerracottaConfiguration().getNonstopConfiguration());
        }

        for (CacheConfiguration cacheConfig : config.getCacheConfigurations().values()) {
            if (cacheConfig.isTerracottaClustered()) {
                if (ValueMode.IDENTITY.equals(cacheConfig.getTerracottaConfiguration().getValueMode())) {
                LOG.warn("The value mode for the {0} cache is \"identity\". This is incompatible with clustered Hibernate caching - "
                        + "the value mode has therefore been switched to \"serialization\"", cacheConfig.getName());
                    cacheConfig.getTerracottaConfiguration().setValueMode(ValueMode.SERIALIZATION.name());
View Full Code Here

   */
  private void init(String id, String name, String diskStorePath) {
    InputStream configInputStream = null;
    try {
      configInputStream = getClass().getClassLoader().getResourceAsStream(CACHE_MANAGER_CONFIG);
      Configuration cacheManagerConfig = ConfigurationFactory.parseConfiguration(configInputStream);
      cacheManagerConfig.getDiskStoreConfiguration().setPath(diskStorePath);
      cacheManager = new CacheManager(cacheManagerConfig);
      cacheManager.setName(id);
    } finally {
      IOUtils.closeQuietly(configInputStream);
    }
View Full Code Here

TOP

Related Classes of net.sf.ehcache.config.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.