Search in sources :

Example 56 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class CachingCharacterPipelineComponentTest method testCacheHit.

@Test
public void testCacheHit() {
    final MockHttpServletRequest mockReq = new MockHttpServletRequest();
    final MockHttpServletResponse mockRes = new MockHttpServletResponse();
    final CacheKey cacheKey = CacheKey.build("testCacheKey");
    final CachedEventReader<CharacterEvent> eventReader = new CachedEventReader<CharacterEvent>(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
    final Element cacheElement = new Element(cacheKey, eventReader);
    final Ehcache cache = createMock(Ehcache.class);
    final CharacterPipelineComponent targetComponent = createMock(CharacterPipelineComponent.class);
    final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
    expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
    expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
    expect(cache.get(cacheKey)).andReturn(cacheElement);
    replay(cache, targetComponent, elementsProvider);
    final CachingCharacterPipelineComponent cachingComponent = new CachingCharacterPipelineComponent();
    cachingComponent.setCache(cache);
    cachingComponent.setWrappedComponent(targetComponent);
    cachingComponent.setResourcesElementsProvider(elementsProvider);
    final PipelineEventReader<CharacterEventReader, CharacterEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
    Assert.assertNotNull(actualEventReader);
    Assert.assertNotNull(actualEventReader.getEventReader());
    Assert.assertFalse(actualEventReader.getEventReader().hasNext());
    verify(cache, targetComponent, elementsProvider);
}
Also used : CharacterPipelineComponent(org.apereo.portal.rendering.CharacterPipelineComponent) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Element(net.sf.ehcache.Element) CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) Ehcache(net.sf.ehcache.Ehcache) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CacheKey(org.apereo.portal.utils.cache.CacheKey) Test(org.junit.Test)

Example 57 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class LrsActorService method getLrsActor.

@Override
public LrsActor getLrsActor(String userName) {
    Element element = this.lrsActorCache.get(userName);
    if (element != null) {
        return (LrsActor) element.getObjectValue();
    }
    final String email;
    final String name;
    final IPersonAttributes person = personAttributeDao.getPerson(userName);
    if (person == null) {
        email = userName;
        name = userName + "@example.com";
    } else {
        email = getEmail(person);
        name = getName(person);
    }
    final LrsActor lrsActor = new LrsActor("mailto:" + email, name);
    this.lrsActorCache.put(new Element(userName, lrsActor));
    return lrsActor;
}
Also used : IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) Element(net.sf.ehcache.Element) LrsActor(org.apereo.portal.events.tincan.om.LrsActor)

Example 58 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class EntityGroupImpl method primRemoveMember.

/**
     * Removes the <code>IGroupMember</code> key from the appropriate key cache, by copying the
     * cache, removing the key from the copy and replacing the original with the copy. At this
     * point, <code>gm</code> still has <code>this</code> in its containing groups cache. That cache
     * entry is not removed until update(), when changes are committed to the store.
     *
     * @param gm org.apereo.portal.groups.IGroupMember
     */
private void primRemoveMember(IGroupMember gm) throws GroupsException {
    final EntityIdentifier cacheKey = getUnderlyingEntityIdentifier();
    Element element = childrenCache.get(cacheKey);
    @SuppressWarnings("unchecked") final Set<IGroupMember> set = element != null ? (Set<IGroupMember>) element.getObjectValue() : buildChildrenSet();
    final Set<IGroupMember> children = new HashSet<>(set);
    children.remove(gm);
    childrenCache.put(new Element(cacheKey, children));
}
Also used : Element(net.sf.ehcache.Element) EntityIdentifier(org.apereo.portal.EntityIdentifier) HashSet(java.util.HashSet)

Example 59 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class EntityGroupImpl method getChildren.

/**
     * Returns an <code>Iterator</code> over the <code>GroupMembers</code> in our member <code>
     * Collection</code>. Reflects pending changes.
     *
     * @return Iterator
     */
@Override
public Set<IGroupMember> getChildren() throws GroupsException {
    final EntityIdentifier cacheKey = getUnderlyingEntityIdentifier();
    Element element = childrenCache.get(cacheKey);
    if (element == null) {
        final Set<IGroupMember> children = buildChildrenSet();
        element = new Element(cacheKey, children);
        childrenCache.put(element);
    }
    @SuppressWarnings("unchecked") final Set<IGroupMember> rslt = (Set<IGroupMember>) element.getObjectValue();
    return rslt;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Element(net.sf.ehcache.Element) EntityIdentifier(org.apereo.portal.EntityIdentifier)

Example 60 with Element

use of net.sf.ehcache.Element in project uPortal by Jasig.

the class GroupMemberImpl method getParentGroups.

/**
     * Returns an <code>Iterator</code> over this <code>IGroupMember's</code> parent groups.
     * Synchronize the collection of keys with adds and removes.
     *
     * @return Iterator
     */
@Override
public Set<IEntityGroup> getParentGroups() throws GroupsException {
    final EntityIdentifier cacheKey = getUnderlyingEntityIdentifier();
    Element element = parentGroupsCache.get(cacheKey);
    if (element == null) {
        final Set<IEntityGroup> groups = buildParentGroupsSet();
        element = new Element(cacheKey, groups);
        parentGroupsCache.put(element);
    }
    @SuppressWarnings("unchecked") final Set<IEntityGroup> rslt = (Set<IEntityGroup>) element.getObjectValue();
    return rslt;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Element(net.sf.ehcache.Element) EntityIdentifier(org.apereo.portal.EntityIdentifier)

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