Search in sources :

Example 31 with Configuration

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

the class SingletonEhcacheRegionFactory method resolveCacheManager.

@Override
protected CacheManager resolveCacheManager(SessionFactoryOptions settings, Map properties) {
    try {
        String configurationResourceName = getOptions().getServiceRegistry().getService(ConfigurationService.class).getSetting(EHCACHE_CONFIGURATION_RESOURCE_NAME, value -> value == null ? null : value.toString());
        if (configurationResourceName == null || configurationResourceName.length() == 0) {
            try {
                REFERENCE_COUNT.incrementAndGet();
                return CacheManager.create();
            } catch (RuntimeException e) {
                REFERENCE_COUNT.decrementAndGet();
                throw e;
            }
        }
        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);
        }
        try {
            REFERENCE_COUNT.incrementAndGet();
            Configuration config = HibernateEhcacheUtils.loadAndCorrectConfiguration(url);
            setCacheManagerNameIfNeeded(settings, config, properties);
            return CacheManager.create(config);
        } catch (RuntimeException e) {
            REFERENCE_COUNT.decrementAndGet();
            throw e;
        }
    } 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) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) URL(java.net.URL)

Example 32 with Configuration

use of net.sf.ehcache.config.Configuration in project goodies by sonatype.

the class LdapServer method start.

public void start() throws Exception {
    if (running) {
        throw new IllegalStateException("The LdapServer is already running");
    }
    long start = System.currentTimeMillis();
    if (port <= 0) {
        port = portRegistry.reservePort();
    }
    // an example that shows how to create and configure embedded apacheds instance
    // http://svn.apache.org/repos/asf/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DefaultDirectoryServiceFactory.java
    directoryService = new DefaultDirectoryService();
    // support multiple embedded ldap servers by assigning each one a distinct cache
    URL configURL = getClass().getClassLoader().getResource("directory-cacheservice.xml");
    Configuration config = ConfigurationFactory.parseConfiguration(configURL);
    config.setName(config.getName() + '_' + System.identityHashCode(this));
    directoryService.setCacheService(new CacheService(new CacheManager(config)));
    directoryService.setInstanceLayout(new InstanceLayout(workingDirectory));
    SchemaManager schemaManager = new DefaultSchemaManager();
    directoryService.setSchemaManager(schemaManager);
    // required by group mapping tests
    schemaManager.enable("nis");
    initPartitions(directoryService);
    ldapServer = new org.apache.directory.server.ldap.LdapServer();
    Transport transport = new TcpTransport(LOCALHOST, port);
    transport.setEnableSSL(ldapsKeystore != null);
    ldapServer.setTransports(transport);
    if (ldapsKeystore != null) {
        ldapServer.setKeystoreFile(ldapsKeystore.getCanonicalPath());
    }
    if (ldapsKeystorePassword != null) {
        ldapServer.setCertificatePassword(ldapsKeystorePassword);
    }
    ldapServer.setDirectoryService(directoryService);
    // allowed authentication mechanisms
    Authenticator[] authenticators;
    switch(authLevel) {
        case SIMPLE:
            authenticators = new Authenticator[] { new SimpleAuthenticator() };
            break;
        case STRONG:
            authenticators = new Authenticator[] { new StrongAuthenticator() };
            ldapServer.setSaslMechanismHandlers(saslHandlers);
            ldapServer.setSaslHost(LOCALHOST);
            ldapServer.setSaslRealms(Arrays.asList(getSaslRealm()));
            ldapServer.setSearchBaseDn(searchBaseDn);
            break;
        case NONE:
        default:
            directoryService.setAllowAnonymousAccess(true);
            authenticators = new Authenticator[] { new AnonymousAuthenticator(), new SimpleAuthenticator() };
            break;
    }
    AuthenticationInterceptor auth = (AuthenticationInterceptor) directoryService.getInterceptor(InterceptorEnum.AUTHENTICATION_INTERCEPTOR.getName());
    auth.setAuthenticators(authenticators);
    directoryService.startup();
    ldapServer.start();
    running = true;
    log.debug("Started LdapServer in {} ms", System.currentTimeMillis() - start);
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) Configuration(net.sf.ehcache.config.Configuration) AuthenticationInterceptor(org.apache.directory.server.core.authn.AuthenticationInterceptor) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) AnonymousAuthenticator(org.apache.directory.server.core.authn.AnonymousAuthenticator) URL(java.net.URL) DefaultDirectoryService(org.apache.directory.server.core.DefaultDirectoryService) StrongAuthenticator(org.apache.directory.server.core.authn.StrongAuthenticator) SimpleAuthenticator(org.apache.directory.server.core.authn.SimpleAuthenticator) CacheManager(net.sf.ehcache.CacheManager) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) TcpTransport(org.apache.directory.server.protocol.shared.transport.TcpTransport) Transport(org.apache.directory.server.protocol.shared.transport.Transport) AnonymousAuthenticator(org.apache.directory.server.core.authn.AnonymousAuthenticator) Authenticator(org.apache.directory.server.core.authn.Authenticator) SimpleAuthenticator(org.apache.directory.server.core.authn.SimpleAuthenticator) StrongAuthenticator(org.apache.directory.server.core.authn.StrongAuthenticator) CacheService(org.apache.directory.server.core.api.CacheService) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager)

Example 33 with Configuration

use of net.sf.ehcache.config.Configuration in project joynr by bmwcarit.

the class AccessControlClientModule method provideCacheManager.

@Provides
@Singleton
public CacheManager provideCacheManager() {
    Configuration configuration = new Configuration();
    configuration.setName("LDACEhCacheManager");
    configuration.setUpdateCheck(false);
    return CacheManager.create(configuration);
}
Also used : Configuration(net.sf.ehcache.config.Configuration) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Configuration (net.sf.ehcache.config.Configuration)33 CacheManager (net.sf.ehcache.CacheManager)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)15 URL (java.net.URL)10 Test (org.junit.Test)9 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)7 Ehcache (net.sf.ehcache.Ehcache)5 IOException (java.io.IOException)4 Cache (net.sf.ehcache.Cache)4 CacheException (org.hibernate.cache.CacheException)4 File (java.io.File)3 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)3 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)3 CacheService (org.apache.directory.server.core.api.CacheService)3 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)3 Provides (com.google.inject.Provides)2 Singleton (com.google.inject.Singleton)2 MalformedURLException (java.net.MalformedURLException)2 NormalizingComparator (org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator)2 ComparatorRegistry (org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry)2