/** * get an Iterator for the values stored in the cache * @returns an Iterator */ public Iterator values() { ArrayList valueList = new ArrayList(); synchronized (this) { LruCacheItem item = tail; while (item != null) { StatefulEJBContext ctx = (StatefulEJBContext) item.getValue(); if (ctx != null) { valueList.add(ctx); } //Ensure that for head the lPrev is null if( (item == head) && (item.getLPrev() != null) ) { _logger.log(Level.WARNING, ITERATOR_RESETTING_HEAD_LPREV, cacheName); item.setLPrev(null); } // traverse to the previous one item = item.getLPrev(); } } return valueList.iterator(); }
public void shutdown() { ArrayList<StatefulEJBContext> valueList = new ArrayList<StatefulEJBContext>(); synchronized (this) { LruCacheItem item = tail; while (item != null) { StatefulEJBContext ctx = (StatefulEJBContext) item.getValue(); if (ctx != null) { item.setTrimmed(true); valueList.add(ctx); } // Ensure that for head the lPrev is null if ((item == head) && (item.getLPrev() != null)) { _logger.log(Level.WARNING, ITERATOR_RESETTING_HEAD_LPREV, cacheName); item.setLPrev(null); } // traverse to the previous one item = item.getLPrev(); } } for (StatefulEJBContext ctx : valueList) { container.passivateEJB(ctx); } }
@Override protected CacheItem trimLru(long currentTime) { LruCacheItem trimItem = tail; if (tail != head) { tail = trimItem.getLPrev(); if (tail == null) { _logger.log(Level.WARNING, TRIM_LRU_RESETTING_HEAD_AND_TAIL, cacheName); // do not let the tail go past the head tail = head = null; } else { tail.setLNext(null); } } else { tail = head = null; } if (trimItem != null) { trimItem.setTrimmed(true); trimItem.setLPrev(null); trimCount++; listSize--; } return trimItem; }