Search in sources :

Example 91 with CacheManager

use of net.sf.ehcache.CacheManager in project OpenClinica by OpenClinica.

the class SQLFactory method run.

public void run(String dbName, ResourceLoader resourceLoader) {
    // we get the type of the database and run the factory, picking
    // up all the queries. NOTE that this should only be run
    // during the init servlets' action, and then it will
    // remain in static memory. tbh 9/8/04
    // ssachs 20041011
    // modified this section so that files are added using the
    // public static final strings above which are not specific to the
    // database
    // key is the public static final sting used above; value is the actual
    // filename
    HashMap fileList = new HashMap();
    CacheManager cacheManager = new CacheManager();
    try {
        if (resourceLoader != null && cacheManager != null)
            cacheManager = cacheManager.create(resourceLoader.getResource("classpath:org/akaza/openclinica/ehcache.xml").getInputStream());
    } catch (CacheException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    EhCacheWrapper ehCache = new EhCacheWrapper("com.akaza.openclinica.dao.core.DAOCache", cacheManager);
    setEhCacheWrapper(ehCache);
    if ("oracle".equals(dbName)) {
        // logger.warn("Oracle Test");
        fileList.put(this.DAO_USERACCOUNT, "oracle_useraccount_dao.xml");
        fileList.put(this.DAO_ARCHIVED_DATASET_FILE, "oracle_archived_dataset_file_dao.xml");
        fileList.put(this.DAO_STUDY, "oracle_study_dao.xml");
        fileList.put(this.DAO_STUDYEVENTDEFNITION, "oracle_studyeventdefinition_dao.xml");
        fileList.put(this.DAO_STUDYEVENT, "oracle_study_event_dao.xml");
        fileList.put(this.DAO_STUDYGROUP, "oracle_study_group_dao.xml");
        fileList.put(this.DAO_STUDYGROUPCLASS, "oracle_study_group_class_dao.xml");
        fileList.put(this.DAO_STUDYSUBJECT, "oracle_study_subject_dao.xml");
        fileList.put(this.DAO_SUBJECT, "oracle_subject_dao.xml");
        fileList.put(this.DAO_SUBJECTGROUPMAP, "oracle_subject_group_map_dao.xml");
        fileList.put(this.DAO_EVENTDEFINITIONCRF, "oracle_event_definition_crf_dao.xml");
        fileList.put(this.DAO_AUDITEVENT, "oracle_audit_event_dao.xml");
        fileList.put(this.DAO_AUDIT, "oracle_audit_dao.xml");
        fileList.put(this.DAO_ITEM, "oracle_item_dao.xml");
        fileList.put(this.DAO_ITEMDATA, "oracle_itemdata_dao.xml");
        fileList.put(this.DAO_CRF, "oracle_crf_dao.xml");
        fileList.put(this.DAO_CRFVERSION, "oracle_crfversion_dao.xml");
        fileList.put(this.DAO_DATASET, "oracle_dataset_dao.xml");
        fileList.put(this.DAO_SECTION, "oracle_section_dao.xml");
        fileList.put(this.DAO_FILTER, "oracle_filter_dao.xml");
        fileList.put(this.DAO_MASKING, "oracle_masking_dao.xml");
        fileList.put(this.DAO_EVENTCRF, "oracle_eventcrf_dao.xml");
        fileList.put(this.DAO_ITEMFORMMETADATA, "oracle_item_form_metadata_dao.xml");
        fileList.put(this.DAO_DISCREPANCY_NOTE, "oracle_discrepancy_note_dao.xml");
        fileList.put(this.DAO_STUDY_PARAMETER, "oracle_study_parameter_value_dao.xml");
        fileList.put(this.DAO_ITEM_GROUP, "oracle_item_group_dao.xml");
        fileList.put(this.DAO_ITEM_GROUP_METADATA, "oracle_item_group_metadata_dao.xml");
        fileList.put(this.DAO_RULESET, "oracle_ruleset_dao.xml");
        fileList.put(this.DAO_RULE, "oracle_rule_dao.xml");
        fileList.put(this.DAO_RULE_ACTION, "oracle_action_dao.xml");
        fileList.put(this.DAO_EXPRESSION, "oracle_expression_dao.xml");
        fileList.put(this.DAO_RULESET_RULE, "oracle_rulesetrule_dao.xml");
        fileList.put(this.DAO_RULESET_AUDIT, "oracle_ruleset_audit_dao.xml");
        fileList.put(this.DAO_RULESETRULE_AUDIT, "oracle_rulesetrule_audit_dao.xml");
        fileList.put(this.DAO_ODM_EXTRACT, "oracle_odm_extract_dao.xml");
    // fileList.put(this.DAO_SUBJECTTRANSFER, "oracle_subjecttransfer_dao.xml");
    } else if ("postgres".equals(dbName)) {
        fileList.put(this.DAO_USERACCOUNT, "useraccount_dao.xml");
        fileList.put(this.DAO_ARCHIVED_DATASET_FILE, "archived_dataset_file_dao.xml");
        fileList.put(this.DAO_STUDY, "study_dao.xml");
        fileList.put(this.DAO_STUDYEVENTDEFNITION, "studyeventdefinition_dao.xml");
        fileList.put(this.DAO_STUDYEVENT, "study_event_dao.xml");
        fileList.put(this.DAO_STUDYGROUP, "study_group_dao.xml");
        fileList.put(this.DAO_STUDYGROUPCLASS, "study_group_class_dao.xml");
        fileList.put(this.DAO_STUDYSUBJECT, "study_subject_dao.xml");
        fileList.put(this.DAO_SUBJECT, "subject_dao.xml");
        fileList.put(this.DAO_SUBJECTGROUPMAP, "subject_group_map_dao.xml");
        fileList.put(this.DAO_EVENTDEFINITIONCRF, "event_definition_crf_dao.xml");
        fileList.put(this.DAO_AUDITEVENT, "audit_event_dao.xml");
        fileList.put(this.DAO_AUDIT, "audit_dao.xml");
        fileList.put(this.DAO_ITEM, "item_dao.xml");
        fileList.put(this.DAO_ITEMDATA, "itemdata_dao.xml");
        fileList.put(this.DAO_CRF, "crf_dao.xml");
        fileList.put(this.DAO_CRFVERSION, "crfversion_dao.xml");
        fileList.put(this.DAO_DATASET, "dataset_dao.xml");
        fileList.put(this.DAO_SECTION, "section_dao.xml");
        fileList.put(this.DAO_FILTER, "filter_dao.xml");
        fileList.put(this.DAO_MASKING, "masking_dao.xml");
        fileList.put(this.DAO_EVENTCRF, "eventcrf_dao.xml");
        fileList.put(this.DAO_ITEMFORMMETADATA, "item_form_metadata_dao.xml");
        fileList.put(this.DAO_DISCREPANCY_NOTE, "discrepancy_note_dao.xml");
        fileList.put(this.DAO_STUDY_PARAMETER, "study_parameter_value_dao.xml");
        fileList.put(this.DAO_ITEM_GROUP, "item_group_dao.xml");
        fileList.put(this.DAO_ITEM_GROUP_METADATA, "item_group_metadata_dao.xml");
        fileList.put(this.DAO_RULESET, "ruleset_dao.xml");
        fileList.put(this.DAO_RULE, "rule_dao.xml");
        fileList.put(this.DAO_RULE_ACTION, "action_dao.xml");
        fileList.put(this.DAO_EXPRESSION, "expression_dao.xml");
        fileList.put(this.DAO_RULESET_RULE, "rulesetrule_dao.xml");
        fileList.put(this.DAO_RULESET_AUDIT, "ruleset_audit_dao.xml");
        fileList.put(this.DAO_RULESETRULE_AUDIT, "rulesetrule_audit_dao.xml");
        fileList.put(this.DAO_SUBJECTTRANSFER, "subjecttransfer_dao.xml");
        fileList.put(this.DAO_ODM_EXTRACT, "odm_extract_dao.xml");
    // add files here as we port over to postgres, tbh
    } else // should be either oracle or postgres, but what if the file is
    // gone?
    {
    // throw an exception here, ssachs
    }
    Set DAONames = fileList.keySet();
    Iterator DAONamesIt = DAONames.iterator();
    while (DAONamesIt.hasNext()) {
        String DAOName = (String) DAONamesIt.next();
        String DAOFileName = (String) fileList.get(DAOName);
        DAODigester newDaoDigester = new DAODigester();
        try {
            if (System.getProperty("catalina.home") == null) {
                String path = getPropertiesDir();
                newDaoDigester.setInputStream(new FileInputStream(path + DAOFileName));
            } else {
                String path = CoreResources.PROPERTIES_DIR;
                newDaoDigester.setInputStream(resourceLoader.getResource("classpath:properties/" + DAOFileName).getInputStream());
            // newDaoDigester.setInputStream(new FileInputStream(path + DAOFileName));
            }
            try {
                newDaoDigester.run();
                digesters.put(DAOName, newDaoDigester);
            } catch (SAXException saxe) {
                saxe.printStackTrace();
            }
        // end try block for xml
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    // end try block for files
    }
// end for loop
}
Also used : EhCacheWrapper(org.akaza.openclinica.dao.cache.EhCacheWrapper) Set(java.util.Set) HashMap(java.util.HashMap) CacheException(net.sf.ehcache.CacheException) Iterator(java.util.Iterator) CacheManager(net.sf.ehcache.CacheManager) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Example 92 with CacheManager

use of net.sf.ehcache.CacheManager in project gocd by gocd.

the class CacheInformationProvider method asJson.

@Override
public Map<String, Object> asJson() {
    LinkedHashMap<String, Object> json = new LinkedHashMap<>();
    for (CacheManager cacheManager : CacheManager.ALL_CACHE_MANAGERS) {
        LinkedHashMap<String, Object> jsonForManager = new LinkedHashMap<>();
        json.put(cacheManager.getName(), jsonForManager);
        for (String cacheName : cacheManager.getCacheNames()) {
            Cache cache = cacheManager.getCache(cacheName);
            LinkedHashMap<String, Object> cacheJson = new LinkedHashMap<>();
            jsonForManager.put(cacheName, cacheJson);
            cacheJson.put("Cache configuration information", getCacheConfigurationInformationAsJson(cache));
            cacheJson.put("Cache runtime information", getCacheRuntimeInformationAsJson(cache));
        }
    }
    return json;
}
Also used : CacheManager(net.sf.ehcache.CacheManager) LinkedHashMap(java.util.LinkedHashMap) Cache(net.sf.ehcache.Cache)

Example 93 with CacheManager

use of net.sf.ehcache.CacheManager in project dble by actiontech.

the class EnchachePooFactory method createCachePool.

@Override
public CachePool createCachePool(String poolName, int cacheSize, int expiredSeconds) {
    CacheManager cacheManager = CacheManager.create();
    Cache enCache = cacheManager.getCache(poolName);
    if (enCache == null) {
        CacheConfiguration cacheConf = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
        cacheConf.setName(poolName);
        if (cacheConf.getMaxEntriesLocalHeap() != 0) {
            cacheConf.setMaxEntriesLocalHeap(cacheSize);
        } else {
            cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
        }
        cacheConf.setTimeToIdleSeconds(expiredSeconds);
        Cache cache = new Cache(cacheConf);
        cacheManager.addCache(cache);
        return new EnchachePool(poolName, cache, cacheSize);
    } else {
        return new EnchachePool(poolName, enCache, cacheSize);
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 94 with CacheManager

use of net.sf.ehcache.CacheManager in project cia by Hack23.

the class CustomSimpleCachingHeadersPageCachingFilter method getCacheManager.

@Override
protected CacheManager getCacheManager() {
    final List<CacheManager> allCacheManagers = CacheManager.ALL_CACHE_MANAGERS;
    CacheManager foundCacheManager = null;
    for (final CacheManager cacheManager : allCacheManagers) {
        if (cacheManager.getActiveConfigurationText().contains(WEB_CACHE_MANAGER)) {
            foundCacheManager = cacheManager;
            continue;
        }
    }
    return foundCacheManager;
}
Also used : CacheManager(net.sf.ehcache.CacheManager)

Example 95 with CacheManager

use of net.sf.ehcache.CacheManager 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)

Aggregations

CacheManager (net.sf.ehcache.CacheManager)102 Cache (net.sf.ehcache.Cache)55 ClassPathResource (org.springframework.core.io.ClassPathResource)21 Element (net.sf.ehcache.Element)20 Configuration (net.sf.ehcache.config.Configuration)18 Test (org.junit.Test)18 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)17 MarkupCache (org.apache.wicket.markup.MarkupCache)10 CacheException (net.sf.ehcache.CacheException)9 IOException (java.io.IOException)7 Ehcache (net.sf.ehcache.Ehcache)7 UpdatingSelfPopulatingCache (net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache)6 URL (java.net.URL)5 BlockingCache (net.sf.ehcache.constructs.blocking.BlockingCache)5 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)5 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)4 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)4 Around (org.aspectj.lang.annotation.Around)4 Before (org.junit.Before)4 File (java.io.File)3