Search in sources :

Example 6 with Configuration

use of net.sf.ehcache.config.Configuration in project spring-framework by spring-projects.

the class EhCacheCacheManagerTests method setup.

@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();
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Before(org.junit.Before)

Example 7 with Configuration

use of net.sf.ehcache.config.Configuration in project gocd by gocd.

the class GoCacheFactory method createCacheManager.

private CacheManager createCacheManager() throws UnsupportedEncodingException {
    Configuration configuration = new Configuration();
    configuration.setUpdateCheck(false);
    configuration.addDiskStore(diskStore());
    configuration.setDefaultCacheConfiguration(new CacheConfiguration("cache", 10000));
    return new CacheManager(configuration);
}
Also used : DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 8 with Configuration

use of net.sf.ehcache.config.Configuration in project wildfly by wildfly.

the class InMemoryDirectoryServiceFactory method init.

/**
     * {@inheritDoc}
     */
@Override
public void init(String name) throws Exception {
    if ((directoryService == null) || directoryService.isStarted()) {
        return;
    }
    int id = counter++;
    directoryService.setInstanceId(name + id);
    // instance layout
    InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + directoryService.getInstanceId());
    if (instanceLayout.getInstanceDirectory().exists()) {
        try {
            FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory());
        } catch (IOException e) {
            LOG.warn("couldn't delete the instance directory before initializing the DirectoryService", e);
        }
    }
    directoryService.setInstanceLayout(instanceLayout);
    // EhCache in disabled-like-mode
    String cacheName = "ApacheDSTestCache-" + id;
    Configuration ehCacheConfig = new Configuration();
    ehCacheConfig.setName(cacheName);
    CacheConfiguration defaultCache = new CacheConfiguration(cacheName, 1).eternal(false).timeToIdleSeconds(30).timeToLiveSeconds(30).overflowToDisk(false);
    ehCacheConfig.addDefaultCache(defaultCache);
    cacheManager = new CacheManager(ehCacheConfig);
    CacheService cacheService = new CacheService(cacheManager);
    directoryService.setCacheService(cacheService);
    // Init the schema
    // SchemaLoader loader = new SingleLdifSchemaLoader();
    SchemaLoader loader = new JarLdifSchemaLoader();
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    schemaManager.loadAllEnabled();
    ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
    for (LdapComparator<?> comparator : comparatorRegistry) {
        if (comparator instanceof NormalizingComparator) {
            ((NormalizingComparator) comparator).setOnServer();
        }
    }
    directoryService.setSchemaManager(schemaManager);
    InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager);
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(inMemorySchemaPartition);
    directoryService.setSchemaPartition(schemaPartition);
    List<Throwable> errors = schemaManager.getErrors();
    if (errors.size() != 0) {
        throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }
    DnFactory dnFactory = new DefaultDnFactory(schemaManager, cacheService.getCache("dnCache"));
    // Init system partition
    Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), dnFactory, "system", ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system"));
    systemPartition.setSchemaManager(directoryService.getSchemaManager());
    partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
    directoryService.setSystemPartition(systemPartition);
    directoryService.startup();
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) Partition(org.apache.directory.server.core.api.partition.Partition) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) SchemaLoader(org.apache.directory.api.ldap.model.schema.registries.SchemaLoader) JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) Configuration(net.sf.ehcache.config.Configuration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) DefaultDnFactory(org.apache.directory.server.core.shared.DefaultDnFactory) NormalizingComparator(org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator) IOException(java.io.IOException) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) SubschemaAdministrativePoint(org.apache.directory.server.core.api.administrative.SubschemaAdministrativePoint) TriggerExecutionAdministrativePoint(org.apache.directory.server.core.api.administrative.TriggerExecutionAdministrativePoint) AccessControlAdministrativePoint(org.apache.directory.server.core.api.administrative.AccessControlAdministrativePoint) CollectiveAttributeAdministrativePoint(org.apache.directory.server.core.api.administrative.CollectiveAttributeAdministrativePoint) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) DnFactory(org.apache.directory.server.core.api.DnFactory) DefaultDnFactory(org.apache.directory.server.core.shared.DefaultDnFactory) JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) CacheManager(net.sf.ehcache.CacheManager) ComparatorRegistry(org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry) File(java.io.File) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) CacheService(org.apache.directory.server.core.api.CacheService) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)

Example 9 with Configuration

use of net.sf.ehcache.config.Configuration in project gocd by gocd.

the class UserCacheFactory method createCacheManager.

private CacheManager createCacheManager() {
    Configuration configuration = new Configuration();
    configuration.setDefaultCacheConfiguration(new CacheConfiguration("cache", 10000));
    return new CacheManager(configuration);
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 10 with Configuration

use of net.sf.ehcache.config.Configuration in project hibernate-orm by hibernate.

the class SingletonEhCacheRegionFactory method start.

@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
    this.settings = settings;
    try {
        String configurationResourceName = null;
        if (properties != null) {
            configurationResourceName = (String) properties.get(NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME);
        }
        if (configurationResourceName == null || configurationResourceName.length() == 0) {
            manager = CacheManager.create();
            REFERENCE_COUNT.incrementAndGet();
        } else {
            URL url;
            try {
                url = new URL(configurationResourceName);
            } catch (MalformedURLException e) {
                if (!configurationResourceName.startsWith("/")) {
                    configurationResourceName = "/" + configurationResourceName;
                    LOG.debugf("prepending / to %s. It should be placed in the root of the classpath rather than in a package.", configurationResourceName);
                }
                url = loadResource(configurationResourceName);
            }
            final Configuration configuration = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
            manager = CacheManager.create(configuration);
            REFERENCE_COUNT.incrementAndGet();
        }
        mbeanRegistrationHelper.registerMBean(manager, properties);
    } catch (net.sf.ehcache.CacheException e) {
        throw new CacheException(e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Configuration(net.sf.ehcache.config.Configuration) CacheException(org.hibernate.cache.CacheException) URL(java.net.URL)

Aggregations

Configuration (net.sf.ehcache.config.Configuration)13 CacheManager (net.sf.ehcache.CacheManager)9 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)5 URL (java.net.URL)3 File (java.io.File)2 CacheException (org.hibernate.cache.CacheException)2 Before (org.junit.Before)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)1 NormalizingComparator (org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator)1 ComparatorRegistry (org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry)1 SchemaLoader (org.apache.directory.api.ldap.model.schema.registries.SchemaLoader)1 JarLdifSchemaLoader (org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader)1 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)1 CacheService (org.apache.directory.server.core.api.CacheService)1 DnFactory (org.apache.directory.server.core.api.DnFactory)1