Package net.sf.ehcache.config

Examples of net.sf.ehcache.config.Configuration


import org.junit.Test;

public class EHCacheManagerHolderTest extends Assert {
    @Test
    public void testCreateCacheManager() {
        Configuration conf =
            ConfigurationFactory.parseConfiguration(EHCacheManagerHolder.class.getResource("/cxf-test-ehcache.xml"));
           
        assertNotNull(conf);
        conf.setName("testCache");
       
        CacheManager manager1 = EHCacheManagerHolder.createCacheManager(conf);
        assertNotNull(manager1);
        CacheManager manager2 = EHCacheManagerHolder.createCacheManager();
        assertNotNull(manager2);
View Full Code Here


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

                configurationResourceName
            );
          }
          url = loadResource( configurationResourceName );
        }
        final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration( url );
        manager = CacheManager.create( configuration );
        REFERENCE_COUNT.incrementAndGet();
      }
      mbeanRegistrationHelper.registerMBean( manager, properties );
    }
View Full Code Here

   * @param url The url to load the config from
   *
   * @return The Ehcache Configuration object
   */
  public static Configuration loadAndCorrectConfiguration(URL url) {
    final Configuration config = ConfigurationFactory.parseConfiguration( url );
   
    // EHC-875 / HHH-6576
    if ( config == null ) {
      return null;
    }
   
    if ( config.getDefaultCacheConfiguration().isTerracottaClustered() ) {
      if ( ValueMode.IDENTITY
          .equals( config.getDefaultCacheConfiguration().getTerracottaConfiguration().getValueMode() ) ) {
        LOG.incompatibleCacheValueMode();
        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.incompatibleCacheValueModePerCache( cacheConfig.getName() );
          cacheConfig.getTerracottaConfiguration().setValueMode( ValueMode.SERIALIZATION.name() );
        }
View Full Code Here

        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);
            }
        }
View Full Code Here

        init(null, null, null, null);
    }

    private void init(Configuration configuration, String configurationFileName, URL configurationURL,
                      InputStream configurationInputStream) {
        Configuration localConfiguration = configuration;
        if (configuration == null) {
            localConfiguration = parseConfiguration(configurationFileName, configurationURL, configurationInputStream);
        } else {
            localConfiguration.setSource("Programmatically configured.");
        }

        ConfigurationHelper configurationHelper = new ConfigurationHelper(this, localConfiguration);
        configure(configurationHelper);
        status = Status.STATUS_ALIVE;
View Full Code Here

     * @throws CacheException if the configuration cannot be parsed
     */
    private synchronized Configuration parseConfiguration(String configurationFileName, URL configurationURL,
                                                          InputStream configurationInputStream) throws CacheException {
        reinitialisationCheck();
        Configuration configuration;
        String configurationSource;
        if (configurationFileName != null) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Configuring CacheManager from " + configurationFileName);
            }
            configuration = ConfigurationFactory.parseConfiguration(new File(configurationFileName));
            configurationSource = "file located at " + configurationFileName;
        } else if (configurationURL != null) {
            configuration = ConfigurationFactory.parseConfiguration(configurationURL);
            configurationSource = "URL of " + configurationURL;
        } else if (configurationInputStream != null) {
            configuration = ConfigurationFactory.parseConfiguration(configurationInputStream);
            configurationSource = "InputStream " + configurationInputStream;
        } else {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Configuring ehcache from classpath.");
            }
            configuration = ConfigurationFactory.parseConfiguration();
            configurationSource = "classpath";
        }
        configuration.setSource(configurationSource);
        return configuration;

    }
View Full Code Here

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

            // ignore
        }
        if (configFileURL == null) {
            cacheManager = EHCacheUtil.createCacheManager();
        } 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 = EHCacheUtil.createCacheManager(conf);
        }
View Full Code Here

        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();
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.