static void setCacheManagerNameIfNeeded(SessionFactoryOptions settings, Configuration configuration, Map properties) { overwriteCacheManagerIfConfigured( configuration, properties ); if (configuration.getName() == null) { String sessionFactoryName = settings.getSessionFactoryName(); if (sessionFactoryName != null) { configuration.setName( sessionFactoryName ); } else { configuration.setName( "Hibernate " + settings.getUuid() ); } } }
private long getOffHeapLimit() { try { Class<Store> enterpriseFmClass = (Class<Store>) Class.forName(FeaturesManager.ENTERPRISE_FM_CLASSNAME); try { return (Long)enterpriseFmClass.getMethod("getMaxBytesAllocatable").invoke(null); } catch (NoSuchMethodException e) { throw new CacheException("Cache: " + getName() + " cannot find static factory" + " method create(Ehcache, String)" + " in store class " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, cause); } catch (IllegalAccessException e) { throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } } catch (ClassNotFoundException e) { throw new CacheException("Cache " + getName() + " cannot be configured because the off-heap store class could not be found. " + "You must use an enterprise version of Ehcache to successfully enable overflowToOffHeap."); } }
/** * Returns a new cacheManager or returns already created one. * If another cacheManager with same name already exists in the VM, returns it. Otherwise creates a new one and returns the new * cacheManager. * Subsequent calls with config having same name of the cacheManager will return same instance until it has been shut down. * There can be only one unnamed CacheManager in the VM * * @param configuration the configuration object * @param msg Message printed when creating new cacheManager * @return a new cacheManager or an already existing one in the VM with same name * @since 2.5 */ private static CacheManager newInstance(Configuration configuration, String msg) throws CacheException { synchronized (CacheManager.class) { String name = configuration.getName(); if (name == null) { name = DEFAULT_NAME; } CacheManager cacheManager = CACHE_MANAGERS_MAP.get(name); if (cacheManager == null) { LOG.debug(msg); cacheManager = new CacheManager(configuration); } return cacheManager; } }
private void assertNoCacheManagerExistsWithSameName(Configuration configuration) { synchronized (CacheManager.class) { final String name; final boolean isNamed; if (configuration.getName() != null) { name = configuration.getName(); isNamed = true; } else { name = DEFAULT_NAME; isNamed = false; } CacheManager cacheManager = CACHE_MANAGERS_MAP.get(name); if (cacheManager == null) { CACHE_MANAGERS_MAP.put(name, this); CACHE_MANAGERS_REVERSE_MAP.put(this, name); } else { ConfigurationSource configurationSource = cacheManager.getConfiguration().getConfigurationSource(); final String msg = "Another " + (isNamed ? "CacheManager with same name '" + name + "'" : "unnamed CacheManager") + " already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:\n" + "1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name" + " or create one if necessary\n" + "2. Shutdown the earlier cacheManager before creating new one with same name.\n" + "The source of the existing CacheManager is: " + (configurationSource == null ? "[Programmatically configured]" : configurationSource); throw new CacheException(msg); } } }
addAttribute(new SimpleNodeAttribute("name", configuration.getName()).optional(true)); addAttribute(new SimpleNodeAttribute("monitoring", configuration.getMonitoring()).optional(true).defaultValue( Configuration.DEFAULT_MONITORING.name().toLowerCase()));
private long getOffHeapLimit() { try { Class<Store> enterpriseFmClass = (Class<Store>) Class.forName(FeaturesManager.ENTERPRISE_FM_CLASSNAME); try { return (Long)enterpriseFmClass.getMethod("getMaxBytesAllocatable").invoke(null); } catch (NoSuchMethodException e) { throw new CacheException("Cache: " + getName() + " cannot find static factory" + " method create(Ehcache, String)" + " in store class " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, cause); } catch (IllegalAccessException e) { throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } } catch (ClassNotFoundException e) { throw new CacheException("Cache " + getName() + " cannot be configured because the off-heap store class could not be found. " + "You must use an enterprise version of Ehcache to successfully enable overflowToOffHeap."); } }
private long getOffHeapLimit() { try { Class<Store> enterpriseFmClass = (Class<Store>) Class.forName(FeaturesManager.ENTERPRISE_FM_CLASSNAME); try { return (Long)enterpriseFmClass.getMethod("getMaxBytesAllocatable").invoke(null); } catch (NoSuchMethodException e) { throw new CacheException("Cache: " + getName() + " cannot find static factory" + " method create(Ehcache, String)" + " in store class " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, cause); } catch (IllegalAccessException e) { throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } } catch (ClassNotFoundException e) { throw new CacheException("Cache " + getName() + " cannot be configured because the off-heap store class could not be found. " + "You must use an enterprise version of Ehcache to successfully enable overflowToOffHeap."); } }
private long getOffHeapLimit() { try { Class<Store> enterpriseFmClass = ClassLoaderUtil.loadClass(FeaturesManager.ENTERPRISE_FM_CLASSNAME); try { return (Long)enterpriseFmClass.getMethod("getMaxBytesAllocatable").invoke(null); } catch (NoSuchMethodException e) { throw new CacheException("Cache: " + getName() + " cannot find static factory" + " method create(Ehcache, String)" + " in store class " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, cause); } catch (IllegalAccessException e) { throw new CacheException("Cache: " + getName() + " cannot instantiate store " + FeaturesManager.ENTERPRISE_FM_CLASSNAME, e); } } catch (ClassNotFoundException e) { throw new CacheException("Cache " + getName() + " cannot be configured because the off-heap store class could not be found. " + "You must use an enterprise version of Ehcache to successfully enable overflowToOffHeap."); } }
/** * Returns a new cacheManager or returns already created one. * If another cacheManager with same name already exists in the VM, returns it. Otherwise creates a new one and returns the new * cacheManager. * Subsequent calls with config having same name of the cacheManager will return same instance until it has been shut down. * There can be only one unnamed CacheManager in the VM * * @param configuration the configuration object * @param msg Message printed when creating new cacheManager * @return a new cacheManager or an already existing one in the VM with same name * @since 2.5 */ private static CacheManager newInstance(Configuration configuration, String msg) throws CacheException { synchronized (CacheManager.class) { String name = configuration.getName(); if (name == null) { name = DEFAULT_NAME; } CacheManager cacheManager = CACHE_MANAGERS_MAP.get(name); if (cacheManager == null) { LOG.debug(msg); cacheManager = new CacheManager(configuration); } return cacheManager; } }
/** * Returns a new cacheManager or returns already created one. * If another cacheManager with same name already exists in the VM, returns it. Otherwise creates a new one and returns the new * cacheManager. * Subsequent calls with config having same name of the cacheManager will return same instance until it has been shut down. * There can be only one unnamed CacheManager in the VM * * @param configuration the configuration object * @param msg Message printed when creating new cacheManager * @return a new cacheManager or an already existing one in the VM with same name * @since 2.5 */ private static CacheManager newInstance(Configuration configuration, String msg) throws CacheException { synchronized (CacheManager.class) { String name = configuration.getName(); if (name == null) { name = DEFAULT_NAME; } CacheManager cacheManager = CACHE_MANAGERS_MAP.get(name); if (cacheManager == null) { LOG.debug(msg); cacheManager = new CacheManager(configuration); } return cacheManager; } }
/** * Returns a new cacheManager or returns already created one. * If another cacheManager with same name already exists in the VM, returns it. Otherwise creates a new one and returns the new * cacheManager. * Subsequent calls with config having same name of the cacheManager will return same instance until it has been shut down. * There can be only one unnamed CacheManager in the VM * * @param fileName name of the file to read the config from * @param msg Message printed when creating new cacheManager * @return a new cacheManager or an already existing one in the VM with same name * @since 2.5 */ private static CacheManager newInstance(Configuration configuration, String msg) throws CacheException { synchronized (CacheManager.class) { String name = configuration.getName(); if (name == null) { name = DEFAULT_NAME; } CacheManager cacheManager = CACHE_MANAGERS_MAP.get(name); if (cacheManager == null) { LOG.debug(msg); cacheManager = new CacheManager(configuration); } return cacheManager; } }
private void assertNoCacheManagerExistsWithSameName(Configuration configuration) { synchronized (CacheManager.class) { final String name; final boolean isNamed; if (configuration.getName() != null) { name = configuration.getName(); isNamed = true; } else { name = DEFAULT_NAME; isNamed = false; } CacheManager cacheManager = CACHE_MANAGERS_MAP.get(name); if (cacheManager == null) { CACHE_MANAGERS_MAP.put(name, this); CACHE_MANAGERS_REVERSE_MAP.put(this, name); } else { ConfigurationSource configurationSource = cacheManager.getConfiguration().getConfigurationSource(); final String msg = "Another " + (isNamed ? "CacheManager with same name '" + name + "'" : "unnamed CacheManager") + " already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:\n" + "1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name" + " or create one if necessary\n" + "2. Shutdown the earlier cacheManager before creating new one with same name.\n" + "The source of the existing CacheManager is: " + (configurationSource == null ? "[Programmatically configured]" : configurationSource); throw new CacheException(msg); } } }
private void assertNoCacheManagerExistsWithSameName(Configuration configuration) { synchronized (CacheManager.class) { final String name; final boolean isNamed; if (configuration.getName() != null) { name = configuration.getName(); isNamed = true; } else { name = DEFAULT_NAME; isNamed = false; } CacheManager cacheManager = CACHE_MANAGERS_MAP.get(name); if (cacheManager == null) { CACHE_MANAGERS_MAP.put(name, this); CACHE_MANAGERS_REVERSE_MAP.put(this, name); } else { ConfigurationSource configurationSource = cacheManager.getConfiguration().getConfigurationSource(); final String msg = "Another " + (isNamed ? "CacheManager with same name '" + name + "'" : "unnamed CacheManager") + " already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:\n" + "1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name" + " or create one if necessary\n" + "2. Shutdown the earlier cacheManager before creating new one with same name.\n" + "The source of the existing CacheManager is: " + (configurationSource == null ? "[Programmatically configured]" : configurationSource); throw new CacheException(msg); } } }
private void assertNoCacheManagerExistsWithSameName(Configuration configuration) { synchronized (CacheManager.class) { final String name; final boolean isNamed; if (configuration.getName() != null) { name = configuration.getName(); isNamed = true; } else { name = DEFAULT_NAME; isNamed = false; } CacheManager cacheManager = CACHE_MANAGERS_MAP.get(name); if (cacheManager == null) { CACHE_MANAGERS_MAP.put(name, this); CACHE_MANAGERS_REVERSE_MAP.put(this, name); } else { ConfigurationSource configurationSource = cacheManager.getConfiguration().getConfigurationSource(); final String msg = "Another " + (isNamed ? "CacheManager with same name '" + name + "'" : "unnamed CacheManager") + " already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:\n" + "1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name" + " or create one if necessary\n" + "2. Shutdown the earlier cacheManager before creating new one with same name.\n" + "The source of the existing CacheManager is: " + (configurationSource == null ? "[Programmatically configured]" : configurationSource); throw new CacheException(msg); } } }
@Override public void afterPropertiesSet() throws IOException, CacheException { InputStream is = XmlMerger.merge(OA_XML_CONFIG_FILE, PROJECT_XML_CONFIG_FILE, servletContext); Configuration configuration = ConfigurationFactory.parseConfiguration(is); String path = System.getProperty("java.io.tmpdir") + servletContext.getContextPath() + "/ehcache"; configuration.addDiskStore(new DiskStoreConfiguration().path(path)); configuration.setName(configuration.getName() + servletContext.getContextPath() + UUID.randomUUID()); cacheManager = new CacheManager(configuration); createMBean(); }
if(cacheManager == null) { final Configuration configuration = ConfigurationFactory.parseConfiguration(configurationURL); if(configuration.getName() == null) { configuration.setName(uri.toString() + "::" + classLoader.toString() + "::" + this.toString());
if(cacheManager == null) { final Configuration configuration = ConfigurationFactory.parseConfiguration(configurationURL); if(configuration.getName() == null) { configuration.setName(uri.toString() + "::" + classLoader.toString() + "::" + this.toString());
@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; }
static void setCacheManagerNameIfNeeded(SessionFactoryOptions settings, Configuration configuration, Map properties) { overwriteCacheManagerIfConfigured( configuration, properties ); if (configuration.getName() == null) { String sessionFactoryName = settings.getSessionFactoryName(); if (sessionFactoryName != null) { configuration.setName( sessionFactoryName ); } else { configuration.setName( "Hibernate " + settings.getUuid() ); } } }
addAttribute(new SimpleNodeAttribute("name", configuration.getName()).optional(true)); addAttribute(new SimpleNodeAttribute("updateCheck", configuration.getUpdateCheck()).optional(true).defaultValue( String.valueOf(Configuration.DEFAULT_UPDATE_CHECK)));