/** * 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. * @return the new EhCache CacheManager * @throws CacheException in case of configuration parsing failure */ public static CacheManager buildCacheManager() throws CacheException { return new CacheManager(ConfigurationFactory.parseConfiguration()); }
/** * Parse EhCache configuration from the given resource, for further use with * custom {@link CacheManager} creation. * @param configLocation the location of the configuration file (as a Spring resource) * @return the EhCache Configuration handle * @throws CacheException in case of configuration parsing failure * @see CacheManager#CacheManager(Configuration) * @see CacheManager#create(Configuration) */ public static Configuration parseConfiguration(Resource configLocation) throws CacheException { InputStream is = null; try { is = configLocation.getInputStream(); return ConfigurationFactory.parseConfiguration(is); } catch (IOException ex) { throw new CacheException("Failed to parse EhCache configuration resource", ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { // ignore } } } }
/** * 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); }
/** * 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. * @return the new EhCache CacheManager * @throws CacheException in case of configuration parsing failure */ public static CacheManager buildCacheManager() throws CacheException { return new CacheManager(ConfigurationFactory.parseConfiguration()); }
/** * Parse EhCache configuration from the given resource, for further use with * custom {@link CacheManager} creation. * @param configLocation the location of the configuration file (as a Spring resource) * @return the EhCache Configuration handle * @throws CacheException in case of configuration parsing failure * @see CacheManager#CacheManager(Configuration) * @see CacheManager#create(Configuration) */ public static Configuration parseConfiguration(Resource configLocation) throws CacheException { InputStream is = null; try { is = configLocation.getInputStream(); return ConfigurationFactory.parseConfiguration(is); } catch (IOException ex) { throw new CacheException("Failed to parse EhCache configuration resource", ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { // ignore } } } }
/** * 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); }
EhCacheManagerUtils.parseConfiguration(this.configLocation) : ConfigurationFactory.parseConfiguration()); if (this.cacheManagerName != null) { configuration.setName(this.cacheManagerName);
EhCacheManagerUtils.parseConfiguration(this.configLocation) : ConfigurationFactory.parseConfiguration()); if (this.cacheManagerName != null) { configuration.setName(this.cacheManagerName);
final Configuration configuration = ConfigurationFactory.parseConfiguration(); setCacheManagerNameIfNeeded( settings, configuration, properties ); return new CacheManager( configuration );
/** * {@inheritDoc} * * @see net.sf.ehcache.config.generator.ConfigurationSource#getConfiguration() */ @Override public Configuration createConfiguration() { return ConfigurationFactory.parseConfiguration(file); }
/** * {@inheritDoc} * * @see net.sf.ehcache.config.generator.ConfigurationSource#createConfiguration() */ @Override public Configuration createConfiguration() { return ConfigurationFactory.parseConfiguration(url); }
/** * {@inheritDoc} * * @see net.sf.ehcache.config.generator.ConfigurationSource#createConfiguration() */ @Override public Configuration createConfiguration() { return ConfigurationFactory.parseConfiguration(); }
final Configuration config = ConfigurationFactory.parseConfiguration( url );
private net.sf.ehcache.config.Configuration parseCacheManagerConfiguration(String xmlCacheManagerConfig) { net.sf.ehcache.config.Configuration targetConfiguration; targetConfiguration = ConfigurationFactory.parseConfiguration(new BufferedInputStream(new ByteArrayInputStream(xmlCacheManagerConfig .getBytes()))); return targetConfiguration; }
/** * A factory method to create a CacheManager with default config, or return it if it exists. * <p> * The configuration will be read, {@link Ehcache}s created and required stores initialized. When the {@link CacheManager} is no longer * required, call shutdown to free resources. * * @return the singleton CacheManager * @throws CacheException * if the CacheManager cannot be created */ public static CacheManager newInstance() throws CacheException { return newInstance(ConfigurationFactory.parseConfiguration(), "Creating new CacheManager with default config"); }
/** * {@inheritDoc} * * @see net.sf.ehcache.config.generator.ConfigurationSource#createConfiguration() */ @Override public Configuration createConfiguration() { try { stream.reset(); return ConfigurationFactory.parseConfiguration(stream); } catch (IOException e) { throw new CacheException(e); } }
/** * A factory method to create a CacheManager with a specified configuration. * <p> * If the specified configuration has different names for the CacheManager, it will return a new one for each unique name or return * already created one. * * @param configurationFileName * an xml file compliant with the ehcache.xsd schema * <p> * The configuration will be read, {@link Ehcache}s created and required stores initialized. When the {@link CacheManager} is * no longer required, call shutdown to free resources. */ public static CacheManager newInstance(String configurationFileName) throws CacheException { return newInstance(ConfigurationFactory.parseConfiguration(new File(configurationFileName)), "Creating new CacheManager with config file: " + configurationFileName); }
/** * A factory method to create a CacheManager from a java.io.InputStream. * <p> * This method makes it possible to use an inputstream for configuration. Note: it is the clients responsibility to close the * inputstream. * <p> * * If the specified configuration has different names for the CacheManager, it will return a new one for each unique name or return * already created one. * * @param inputStream * InputStream of xml compliant with the ehcache.xsd schema * <p> * The configuration will be read, {@link Ehcache}s created and required stores initialized. When the {@link CacheManager} is * no longer required, call shutdown to free resources. */ public static CacheManager newInstance(InputStream inputStream) throws CacheException { return newInstance(ConfigurationFactory.parseConfiguration(inputStream), "Creating new CacheManager with InputStream"); }
/** * Configures a bean from an XML file in the classpath. */ public static Configuration parseConfiguration() throws CacheException { ClassLoader standardClassloader = Thread.currentThread().getContextClassLoader(); URL url = null; if (standardClassloader != null) { url = standardClassloader.getResource(DEFAULT_CLASSPATH_CONFIGURATION_FILE); } if (url == null) { url = ConfigurationFactory.class.getResource(DEFAULT_CLASSPATH_CONFIGURATION_FILE); } if (url != null) { LOG.debug("Configuring ehcache from ehcache.xml found in the classpath: " + url); } else { url = ConfigurationFactory.class.getResource(FAILSAFE_CLASSPATH_CONFIGURATION_FILE); LOG.warn("No configuration found. Configuring ehcache from ehcache-failsafe.xml " + " found in the classpath: {}", url); } Configuration configuration = parseConfiguration(url); configuration.setSource(ConfigurationSource.getConfigurationSource()); return configuration; }
/** * 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() != null && config.getDefaultCacheConfiguration().isTerracottaClustered()) { setupHibernateTimeoutBehavior(config.getDefaultCacheConfiguration().getTerracottaConfiguration().getNonstopConfiguration()); } for (CacheConfiguration cacheConfig : config.getCacheConfigurations().values()) { if (cacheConfig.isTerracottaClustered()) { setupHibernateTimeoutBehavior(cacheConfig.getTerracottaConfiguration().getNonstopConfiguration()); } } return config; }