/** * @return cacheElement.getElementAttributes(); * @see ICacheElement#getElementAttributes */ @Override public IElementAttributes getElementAttributes() { return cacheElement.getElementAttributes(); }
/** * @return cacheElement.getElementAttributes(); * @see ICacheElement#getElementAttributes */ @Override public IElementAttributes getElementAttributes() { return cacheElement.getElementAttributes(); }
/** * Gets the elementAttributes attribute of the Cache object. * <p> * @param key * @return The elementAttributes value * @throws CacheException * @throws IOException */ public IElementAttributes getElementAttributes( K key ) throws CacheException, IOException { ICacheElement<K, V> ce = get( key ); if ( ce == null ) { throw new ObjectNotFoundException( "key " + key + " is not found" ); } return ce.getElementAttributes(); }
/** * Puts an item to the cache. * <p> * @param ce Description of the Parameter * @throws IOException Description of the Exception */ @Override public void update(ICacheElement<K, V> ce) throws IOException { putCnt.incrementAndGet(); ce.getElementAttributes().setLastAccessTimeNow(); lock.lock(); try { map.put(ce.getKey(), new SoftReferenceElementDescriptor<K, V>(ce)); strongReferences.add(ce); trimStrongReferences(); } finally { lock.unlock(); } }
/** * Gets the elementAttributes attribute of the Cache object. * <p> * @param key * @return The elementAttributes value * @throws CacheException * @throws IOException */ public IElementAttributes getElementAttributes( K key ) throws CacheException, IOException { ICacheElement<K, V> ce = get( key ); if ( ce == null ) { throw new ObjectNotFoundException( "key " + key + " is not found" ); } return ce.getElementAttributes(); }
/** * Constructor for the PurgatoryElement<K, V> object * * @param cacheElement CacheElement */ public PurgatoryElement( ICacheElement<K, V> cacheElement ) { super(cacheElement.getCacheName(), cacheElement.getKey(), cacheElement.getVal(), cacheElement.getElementAttributes()); this.cacheElement = cacheElement; }
/** * Constructor for the PurgatoryElement<K, V> object * <p> * @param cacheElement CacheElement */ public PurgatoryElement( ICacheElement<K, V> cacheElement ) { super(cacheElement.getCacheName(), cacheElement.getKey(), cacheElement.getVal(), cacheElement.getElementAttributes()); this.cacheElement = cacheElement; }
cacheElement.getElementAttributes().setLastAccessTimeNow();
private void touch(final K key, final ICacheElement<K, V> element) { if (config.isStoreByValue()) { final K copy = copy(serializer, manager.getClassLoader(), key); try { delegate.update(new CacheElement<K, V>(name, copy, element.getVal(), element.getElementAttributes())); } catch (final IOException e) { throw new CacheException(e); } } }
private void touch(final K key, final ICacheElement<K, V> element) { if (config.isStoreByValue()) { final K copy = copy(serializer, manager.getClassLoader(), key); try { delegate.update(new CacheElement<K, V>(name, copy, element.getVal(), element.getElementAttributes())); } catch (final IOException e) { throw new CacheException(e); } } }
/** * * @throws Exception */ public void testSimpleElementRetrieval() throws Exception { CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" ); jcs.put( "test_key", "test_data" ); long now = System.currentTimeMillis(); ICacheElement<String, String> elem = jcs.getCacheElement( "test_key" ); assertEquals( "Name wasn't right", "testCache1", elem.getCacheName() ); long diff = now - elem.getElementAttributes().getCreateTime(); assertTrue( "Create time should have been at or after the call", diff >= 0 ); }
/** * * @throws Exception */ public void testSimpleElementRetrieval() throws Exception { CacheAccess<String, String> jcs = JCS.getInstance( "testCache1" ); jcs.put( "test_key", "test_data" ); long now = System.currentTimeMillis(); ICacheElement<String, String> elem = jcs.getCacheElement( "test_key" ); assertEquals( "Name wasn't right", "testCache1", elem.getCacheName() ); long diff = now - elem.getElementAttributes().getCreateTime(); assertTrue( "Create time should have been at or after the call", diff >= 0 ); }
/** Verify basic data */ public void testElementAttributes_normal() { // SETUP String cacheName = "myCacheName"; String key = "myKey"; String value = "myValue"; IElementAttributes elementAttributes = new ElementAttributes(); ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value ); PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement ); purgatoryElement.setElementAttributes( elementAttributes ); // DO WORK IElementAttributes result = cacheElement.getElementAttributes(); // VERIFY assertEquals( "Should have set the attributes on the element", elementAttributes, result ); }
/** Verify basic data */ public void testElementAttributes_normal() { // SETUP String cacheName = "myCacheName"; String key = "myKey"; String value = "myValue"; IElementAttributes elementAttributes = new ElementAttributes(); ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value ); PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement ); purgatoryElement.setElementAttributes( elementAttributes ); // DO WORK IElementAttributes result = cacheElement.getElementAttributes(); // VERIFY assertEquals( "Should have set the attributes on the element", elementAttributes, result ); }
/** verify the check for removal * <p> * @throws IOException */ public void testCheckForRemoval_IdleTooLong() throws IOException { // SETUP CompositeCacheAttributes cacheAttr = new CompositeCacheAttributes(); cacheAttr.setCacheName("testRegion"); cacheAttr.setMaxMemoryIdleTimeSeconds( 10 ); cacheAttr.setMaxSpoolPerRun( 10 ); CompositeCache<String, String> cache = new CompositeCache<String, String>(cacheAttr, new ElementAttributes()); String key = "key"; String value = "value"; ICacheElement<String, String> element = new CacheElement<String, String>( "testRegion", key, value ); ElementAttributes elementAttr = new ElementAttributes(); elementAttr.setIsEternal( false ); element.setElementAttributes( elementAttr ); element.getElementAttributes().setMaxLife(100); element.getElementAttributes().setIdleTime( 1 ); long now = System.currentTimeMillis(); // add two seconds now += 2000; // DO WORK boolean result = cache.isExpired( element, now, ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND, ElementEventType.EXCEEDED_IDLETIME_BACKGROUND ); // VERIFY assertTrue( "Item should have expired.", result ); }
/** verify the check for removal * <p> * @throws IOException */ public void testCheckForRemoval_NotExpired() throws IOException { // SETUP CompositeCacheAttributes cacheAttr = new CompositeCacheAttributes(); cacheAttr.setCacheName("testRegion"); cacheAttr.setMaxMemoryIdleTimeSeconds( 10 ); cacheAttr.setMaxSpoolPerRun( 10 ); CompositeCache<String, String> cache = new CompositeCache<String, String>(cacheAttr, new ElementAttributes()); String key = "key"; String value = "value"; ICacheElement<String, String> element = new CacheElement<String, String>( "testRegion", key, value ); ElementAttributes elementAttr = new ElementAttributes(); elementAttr.setIsEternal( false ); element.setElementAttributes( elementAttr ); element.getElementAttributes().setMaxLife(1); long now = System.currentTimeMillis(); // subtract two seconds now -= 2000; // DO WORK boolean result = cache.isExpired( element, now, ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND, ElementEventType.EXCEEDED_IDLETIME_BACKGROUND ); // VERIFY assertFalse( "Item should not have expired.", result ); }
/** verify the check for removal * <p> * @throws IOException */ public void testCheckForRemoval_NotExpired() throws IOException { // SETUP CompositeCacheAttributes cacheAttr = new CompositeCacheAttributes(); cacheAttr.setCacheName("testRegion"); cacheAttr.setMaxMemoryIdleTimeSeconds( 10 ); cacheAttr.setMaxSpoolPerRun( 10 ); CompositeCache<String, String> cache = new CompositeCache<String, String>(cacheAttr, new ElementAttributes()); String key = "key"; String value = "value"; ICacheElement<String, String> element = new CacheElement<String, String>( "testRegion", key, value ); ElementAttributes elementAttr = new ElementAttributes(); elementAttr.setIsEternal( false ); element.setElementAttributes( elementAttr ); element.getElementAttributes().setMaxLife(1); long now = System.currentTimeMillis(); // subtract two seconds now -= 2000; // DO WORK boolean result = cache.isExpired( element, now, ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND, ElementEventType.EXCEEDED_IDLETIME_BACKGROUND ); // VERIFY assertFalse( "Item should not have expired.", result ); }
assertEquals( "Attributes should be the same.", before.getElementAttributes().getMaxLife(), after .getElementAttributes().getMaxLife() ); assertEquals( "Keys should be the same.", before.getKey(), after.getKey() ); assertEquals( "Cache name should be the same.", before.getCacheName(), after.getCacheName() );
/** * Verify that elements that go in the region after this call take the new attributes. * @throws Exception */ public void testSetDefaultElementAttributes() throws Exception { CacheAccess<String, String> access = JCS.getInstance( "test" ); assertNotNull( "We should have an access class", access ); long maxLife = 9876; IElementAttributes attr = new ElementAttributes(); attr.setMaxLife(maxLife); access.setDefaultElementAttributes( attr ); assertEquals( "Wrong element attributes.", attr.getMaxLife(), access.getDefaultElementAttributes() .getMaxLife() ); String key = "mykey"; String value = "myvalue"; access.put( key, value ); ICacheElement<String, String> element = access.getCacheElement( key ); assertEquals( "Wrong max life. Should have the new value.", maxLife, element.getElementAttributes() .getMaxLife() ); }
/** * Verify that elements that go in the region after this call take the new attributes. * @throws Exception */ public void testSetDefaultElementAttributes() throws Exception { CacheAccess<String, String> access = JCS.getInstance( "test" ); assertNotNull( "We should have an access class", access ); long maxLife = 9876; IElementAttributes attr = new ElementAttributes(); attr.setMaxLife(maxLife); access.setDefaultElementAttributes( attr ); assertEquals( "Wrong element attributes.", attr.getMaxLife(), access.getDefaultElementAttributes() .getMaxLife() ); String key = "mykey"; String value = "myvalue"; access.put( key, value ); ICacheElement<String, String> element = access.getCacheElement( key ); assertEquals( "Wrong max life. Should have the new value.", maxLife, element.getElementAttributes() .getMaxLife() ); }