1 23 24 package com.sun.ejb.containers.util.cache; 25 26 import java.util.Properties ; 27 28 import com.sun.ejb.spi.container.SFSBContainerCallback; 29 30 public class NRUSessionCache 31 extends LruSessionCache 32 { 33 34 protected boolean doOrdering = false; 35 protected int orderingThreshold = 0; 36 37 public NRUSessionCache(String cacheName, 38 SFSBContainerCallback container, int cacheIdleTime, int removalTime) 39 { 40 super("NRU-" + cacheName, container, cacheIdleTime, removalTime); 41 } 42 43 public void init(int maxEntries, float loadFactor, Properties props) { 44 super.init(maxEntries, loadFactor, props); 45 orderingThreshold = (int) (0.75 * threshold); 46 } 47 48 protected CacheItem itemAdded(CacheItem item) { 49 CacheItem addedItem = super.itemAdded(item); 50 doOrdering = (entryCount >= orderingThreshold); 51 return addedItem; 52 } 53 54 protected void itemAccessed(CacheItem item) { 55 LruCacheItem lc = (LruCacheItem) item; 56 synchronized (this) { 57 if (lc.isTrimmed) { 58 lc.isTrimmed = false; 59 CacheItem overflow = super.itemAdded(item); 60 if (overflow != null) { 61 trimItem(overflow); 62 } 63 } else if (doOrdering) { 64 super.itemAccessed(item); 65 } 66 } 67 } 68 69 protected void itemRefreshed(CacheItem item, int oldSize) { 70 } 71 72 protected void itemRemoved(CacheItem item) { 73 super.itemRemoved(item); 74 doOrdering = (entryCount >= orderingThreshold); 75 } 76 77 public void trimTimedoutItems(int maxCount) { 78 if (doOrdering) { 81 super.trimTimedoutItems(maxCount); 82 } else { 83 trimUnSortedTimedoutItems(maxCount); 86 } 87 } 88 89 } 90 | Popular Tags |