Search in sources :

Example 86 with Element

use of net.sf.ehcache.Element in project ORCID-Source by ORCID.

the class ClientDetailsEntityCacheManagerImpl method retrieveByIdP.

@Override
public ClientDetailsEntity retrieveByIdP(String idp) throws IllegalArgumentException {
    Object key = new ClientIdCacheKey("IdP+" + idp, releaseName);
    Date dbDate = retrieveLastModifiedDateByIdP(idp);
    ClientDetailsEntity clientDetails = toClientDetailsEntity(clientDetailsCache.get(key));
    if (needsFresh(dbDate, clientDetails)) {
        try {
            synchronized (lockers.obtainLock(idp)) {
                clientDetails = toClientDetailsEntity(clientDetailsCache.get(key));
                if (needsFresh(dbDate, clientDetails)) {
                    clientDetails = clientDetailsManager.findByIdP(idp);
                    if (clientDetails == null)
                        throw new IllegalArgumentException("Invalid idp " + idp);
                    clientDetailsCache.put(new Element(key, clientDetails));
                }
            }
        } finally {
            lockers.releaseLock(idp);
        }
    }
    return clientDetails;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Element(net.sf.ehcache.Element) Date(java.util.Date)

Example 87 with Element

use of net.sf.ehcache.Element in project ORCID-Source by ORCID.

the class OrcidProfileCacheManagerImpl method retrieveProfileBioAndInternal.

@Override
public OrcidProfile retrieveProfileBioAndInternal(String orcid) {
    Object key = new OrcidCacheKey(orcid, releaseName);
    Date dbDate = retrieveLastModifiedDate(orcid);
    OrcidProfile op = toOrcidProfile(profileBioAndInternalCache.get(key));
    if (needsFresh(dbDate, op))
        try {
            synchronized (profileBioAndInternalLockers.obtainLock(orcid)) {
                op = toOrcidProfile(profileBioAndInternalCache.get(orcid));
                if (needsFresh(dbDate, op)) {
                    op = orcidProfileManager.retrieveFreshOrcidProfile(orcid, LoadOptions.BIO_AND_INTERNAL_ONLY);
                    profileBioAndInternalCache.put(new Element(key, op));
                }
            }
        } finally {
            profileBioAndInternalLockers.releaseLock(orcid);
        }
    return op;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Element(net.sf.ehcache.Element) Date(java.util.Date)

Example 88 with Element

use of net.sf.ehcache.Element in project ORCID-Source by ORCID.

the class WorkEntityCacheManagerImpl method retrieveMinimizedWork.

@Override
public MinimizedWorkEntity retrieveMinimizedWork(long workId, long workLastModified) {
    Object key = new WorkCacheKey(workId, releaseName);
    MinimizedWorkEntity minimizedWorkEntity = toMinimizedWork(getFromMinimizedWorkEntityCache(key));
    if (minimizedWorkEntity == null || minimizedWorkEntity.getLastModified().getTime() < workLastModified) {
        try {
            synchronized (lockerMinimizedWork.obtainLock(Long.toString(workId))) {
                minimizedWorkEntity = toMinimizedWork(getFromMinimizedWorkEntityCache(key));
                if (minimizedWorkEntity == null || minimizedWorkEntity.getLastModified().getTime() < workLastModified) {
                    minimizedWorkEntity = workDao.getMinimizedWorkEntity(workId);
                    workDao.detach(minimizedWorkEntity);
                    minimizedWorkEntityCache.put(new Element(key, minimizedWorkEntity));
                }
            }
        } finally {
            lockerMinimizedWork.releaseLock(Long.toString(workId));
        }
    }
    return minimizedWorkEntity;
}
Also used : MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) Element(net.sf.ehcache.Element)

Example 89 with Element

use of net.sf.ehcache.Element in project ORCID-Source by ORCID.

the class WorkEntityCacheManagerImpl method retrieveFullWork.

/**
     * Retrieves a full WorkEntity
     * @param workId
     * @param workLastModified
     * @return a WorkEntity
     */
@Override
public WorkEntity retrieveFullWork(String orcid, long workId, long workLastModified) {
    Object key = new WorkCacheKey(workId, releaseName);
    WorkEntity workEntity = (WorkEntity) toWorkBaseEntity(getFromFullWorkEntityCache(key));
    if (workEntity == null || workEntity.getLastModified().getTime() < workLastModified) {
        try {
            synchronized (lockerFullWork.obtainLock(Long.toString(workId))) {
                workEntity = (WorkEntity) toWorkBaseEntity(getFromFullWorkEntityCache(key));
                if (workEntity == null || workEntity.getLastModified().getTime() < workLastModified) {
                    workEntity = workDao.getWork(orcid, workId);
                    workDao.detach(workEntity);
                    fullWorkEntityCache.put(new Element(key, workEntity));
                }
            }
        } finally {
            lockerMinimizedWork.releaseLock(Long.toString(workId));
        }
    }
    return workEntity;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) Element(net.sf.ehcache.Element)

Example 90 with Element

use of net.sf.ehcache.Element in project ORCID-Source by ORCID.

the class StatisticsCacheManagerImpl method setLatestStatisticsSummary.

@Override
public void setLatestStatisticsSummary() {
    LOG.info("Getting the latest statistics summary");
    StatisticsSummary summary = statisticsManagerReadOnly.getLatestStatisticsModel();
    if (statisticsCache.get(CACHE_STATISTICS_KEY) == null) {
        statisticsCache.put(new Element(CACHE_STATISTICS_KEY, summary));
    } else {
        statisticsCache.replace(new Element(CACHE_STATISTICS_KEY, summary));
    }
}
Also used : StatisticsSummary(org.orcid.jaxb.model.statistics.StatisticsSummary) Element(net.sf.ehcache.Element)

Aggregations

Element (net.sf.ehcache.Element)114 Test (org.junit.Test)21 CacheKey (org.apereo.portal.utils.cache.CacheKey)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Cache (net.sf.ehcache.Cache)7 HashSet (java.util.HashSet)6 CacheException (net.sf.ehcache.CacheException)6 MalformedURLException (java.net.MalformedURLException)5 ConfigurationException (javax.naming.ConfigurationException)5 Ehcache (net.sf.ehcache.Ehcache)5 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)5 EntityIdentifier (org.apereo.portal.EntityIdentifier)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URISyntaxException (java.net.URISyntaxException)4 SQLException (java.sql.SQLException)4 EntityExistsException (javax.persistence.EntityExistsException)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 BaseCacheTest (org.apache.camel.component.BaseCacheTest)4