Package org.jasig.portal.concurrency

Examples of org.jasig.portal.concurrency.IEntityCache


    print("***** ENTERING EntityCacheTester.testIEntityCacheAddsAndDeletes() *****");
    String msg = null;
    int idx = 0;
    IBasicEntity ent = null;

    IEntityCache c = getEntityCache();
    ReferenceEntityCache rec = (ReferenceEntityCache) c;
    msg = "Adding " + numTestEntities + " entities to the cache.";
    print(msg);
    for(idx=0; idx<numTestEntities; idx++)
        { c.add(testEntities[idx]); }

    assertEquals(msg, rec.size(), numTestEntities);

    msg = "Retrieving entities from the cache.";
    print(msg);
    for(idx=0; idx<numTestEntities; idx++)
    {
        ent = c.get( testEntityKeys[idx] );
        assertEquals(msg, ent, testEntities[idx]);
    }

    msg = "Removing entities from the cache.";
    print(msg);
    for(idx=0; idx<numTestEntities; idx++)
    {
        c.remove( testEntityKeys[idx] );
        ent = c.get( testEntityKeys[idx] );
        assertNull(msg, ent);
    }

    // We should have removed all entries.
    assertEquals(msg, rec.size(), 0);
View Full Code Here


    int touched = firstAdded / 2;
    int maxSize = (firstAdded + 1);
    int maxIdleSecs = 50;
    int sweepIntervalSecs = maxIdleSecs / 2;

    IEntityCache c = getEntityCache(maxSize, maxIdleSecs*1000, sweepIntervalSecs*1000);
    msg = "Adding " + firstAdded + " entities to the cache.";
    print(msg);
    for(idx=0; idx<firstAdded; idx++)
        { c.add(testEntities[idx]); }

    assertEquals(msg, c.size(), firstAdded);

    int sleepSecs = ((maxIdleSecs + sweepIntervalSecs) / 2);
    print("Now sleeping for " + sleepSecs  + " secs.");
    Thread.sleep(sleepSecs*1000);

    print("Now touching " + touched + " entries.");
    for(idx=0; idx<touched; idx++)
        { c.get(testEntityKeys[idx]); }

    msg = "Adding " + secondAdded + " entities to the cache.";
    print(msg);
    for(idx=firstAdded; idx<firstAdded+secondAdded; idx++)
        { c.add(testEntities[idx]); }

    print("Now sleeping for " + (maxIdleSecs/2) + " secs.");
    Thread.sleep(maxIdleSecs*500);

    msg = "Sweep should have purged " + (firstAdded - touched) + " entries.";
    print(msg);
    assertEquals(msg, (touched + secondAdded), c.size());

    print("***** LEAVING EntityCacheTester.testIEntityCacheSweep() *****");

}
 
View Full Code Here

    String msg = null;
    int idx = 0;
    IBasicEntity ent = null;
    int numEntitiesToBeTested = 100;

    IEntityCache c = getInvalidatingEntityCache();
    ReferenceInvalidatingEntityCache rec = (ReferenceInvalidatingEntityCache) c;
    msg = "Adding " + numEntitiesToBeTested + " entities to the cache.";
    print(msg);
    for(idx=0; idx<numEntitiesToBeTested; idx++)
        { c.add(testEntities[idx]); }

    assertEquals(msg, rec.size(), numEntitiesToBeTested);

    msg = "Retrieving entities from the cache.";
    print(msg);
    for(idx=0; idx<numEntitiesToBeTested; idx++)
    {
        ent = c.get( testEntityKeys[idx] );
        assertEquals(msg, ent, testEntities[idx]);
    }

    msg = "Removing entities from the cache.";
    print(msg);
    for(idx=0; idx<numEntitiesToBeTested; idx++)
    {
        c.remove( testEntityKeys[idx] );
        ent = c.get( testEntityKeys[idx] );
        assertNull(msg, ent);
    }

    // We should have removed all entries.
    assertEquals(msg, rec.size(), 0);
View Full Code Here

    IBasicEntity ent = null;
    int numEntitiesToBeAdded = 10;
    int numEntitiesToBeUpdated = 5;
    int numEntitiesToBeDeleted = 5;

    IEntityCache cacheA = getInvalidatingEntityCache();
    ReferenceInvalidatingEntityCache recA = (ReferenceInvalidatingEntityCache) cacheA;
    IEntityCache cacheB = getInvalidatingEntityCache();
    ReferenceInvalidatingEntityCache recB = (ReferenceInvalidatingEntityCache) cacheB;

    msg = "Adding " + numEntitiesToBeAdded + " entities to both caches.";
    print(msg);
    for(idx=0; idx<numEntitiesToBeAdded; idx++)
    {
        cacheA.add(testEntities[idx]);
        cacheB.add(testEntities[idx]);
    }

    assertEquals(msg, recA.size(), numEntitiesToBeAdded);
    assertEquals(msg, recB.size(), numEntitiesToBeAdded);

    Thread.sleep(100);

    msg = "Updating " + numEntitiesToBeUpdated + " in first cache.";
    print(msg);
    for(idx=0; idx<numEntitiesToBeUpdated; idx++)
        { cacheA.update( testEntities[idx] ); }

    msg = "Removing " + numEntitiesToBeDeleted + " from second cache.";
    print(msg);
    for(idx=numEntitiesToBeUpdated; idx<numEntitiesToBeAdded; idx++)
        { cacheB.remove( testEntityKeys[idx] ); }

    print("Will now sleep for " + (cacheSweepIntervalSecs + 5) + " seconds.");
    Thread.sleep( (cacheSweepIntervalSecs + 5) * 1000);

    // Check the caches.
View Full Code Here

    int idx = 0;
    int numEntitiesToBeAdded = 10;
    int numEntitiesToBeUpdated = 5;
    int numEntitiesToBeDeleted = 2;

    IEntityCache cacheA = getInvalidatingEntityCache();
    ReferenceInvalidatingEntityCache recA = (ReferenceInvalidatingEntityCache) cacheA;
    IEntityCache cacheB = getInvalidatingEntityCache();
    ReferenceInvalidatingEntityCache recB = (ReferenceInvalidatingEntityCache) cacheB;

    msg = "Adding " + numEntitiesToBeAdded + " entities to FIRST cache.";
    print(msg);
    for(idx=0; idx<numEntitiesToBeAdded; idx++)
        { cacheA.add(testEntities[idx]); }
    assertEquals(msg, recA.size(), numEntitiesToBeAdded);

    Thread.sleep(100);

    msg = "Updating " + numEntitiesToBeUpdated + " in first cache.";
    print(msg);
    for(idx=0; idx<numEntitiesToBeUpdated; idx++)
        { cacheA.update( testEntities[idx] ); }

    msg = "Adding " + numEntitiesToBeAdded + " entities to SECOND cache.";
    print(msg);
    for(idx=0; idx<numEntitiesToBeAdded; idx++)
        { cacheB.add(testEntities[idx]); }
    assertEquals(msg, recB.size(), numEntitiesToBeAdded);
   
    msg = "Removing " + numEntitiesToBeDeleted + " from second cache.";
     print(msg);
     for(idx=numEntitiesToBeUpdated; idx<numEntitiesToBeUpdated + numEntitiesToBeDeleted; idx++)
         { cacheB.remove( testEntityKeys[idx] ); }
  
    print("Will now sleep for " + (cacheSweepIntervalSecs + 5) + " seconds.");
    Thread.sleep( (cacheSweepIntervalSecs + 5) * 1000);

    // Check the caches.
View Full Code Here

private void createCaches() throws CachingException
{
    for ( Iterator types = EntityTypes.singleton().getAllEntityTypes(); types.hasNext() ;)
    {
        Class type = (Class) types.next();
        IEntityCache cache = createCache(type);
        getCaches().put( type, cache );
    }
}
View Full Code Here

* @param type Class
* @return IEntityCache
* @exception org.jasig.portal.concurrency.CachingException
*/
public IEntityCache getCache(Class type) throws CachingException {
    IEntityCache c = (IEntityCache)getCaches().get(type);
    if ( c == null )
    {
        c = createCache(type);
        getCaches().put(type, c);
    }
View Full Code Here

     * @see org.jasig.portal.concurrency.IEntityCachingService#add(org.jasig.portal.IBasicEntity)
     */
    public void add(IBasicEntity entity) throws CachingException {
        final EntityIdentifier entityIdentifier = entity.getEntityIdentifier();
        final Class<? extends IBasicEntity> entityType = entityIdentifier.getType();
        final IEntityCache entityCache = this.getCache(entityType);
       
        entityCache.add(entity);
    }
View Full Code Here

    /* (non-Javadoc)
     * @see org.jasig.portal.concurrency.IEntityCachingService#get(java.lang.Class, java.lang.String)
     */
    public IBasicEntity get(Class<? extends IBasicEntity> entityType, String key) throws CachingException {
        final IEntityCache entityCache = this.getCache(entityType);
        return entityCache.get(key);
    }
View Full Code Here

    /* (non-Javadoc)
     * @see org.jasig.portal.concurrency.IEntityCachingService#remove(java.lang.Class, java.lang.String)
     */
    public void remove(Class<? extends IBasicEntity> entityType, String key) throws CachingException {
        final IEntityCache entityCache = this.getCache(entityType);
        entityCache.remove(key);
    }
View Full Code Here

TOP

Related Classes of org.jasig.portal.concurrency.IEntityCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.