1 18 package org.apache.activemq.memory; 19 20 25 public class CacheEntryList { 26 27 public final CacheEntry tail = new CacheEntry(null, null); 29 30 public CacheEntryList() { 31 tail.next = tail.previous = tail; 32 } 33 34 public void add(CacheEntry ce) { 35 addEntryBefore(tail, ce); 36 } 37 38 private void addEntryBefore(CacheEntry position, CacheEntry ce) { 39 assert ce.key!=null && ce.next==null && ce.owner==null; 40 41 synchronized( tail ) { 42 ce.owner=this; 43 ce.next = position; 44 ce.previous = position.previous; 45 ce.previous.next = ce; 46 ce.next.previous = ce; 47 } 48 } 49 50 public void clear() { 51 synchronized( tail ) { 52 tail.next = tail.previous = tail; 53 } 54 } 55 56 public CacheEvictor createFIFOCacheEvictor() { 57 return new CacheEvictor() { 58 public CacheEntry evictCacheEntry() { 59 CacheEntry rc; 60 synchronized( tail ) { 61 rc = tail.next; 62 } 63 return rc.remove() ? rc : null; 64 } 65 }; 66 } 67 68 public CacheEvictor createLIFOCacheEvictor() { 69 return new CacheEvictor() { 70 public CacheEntry evictCacheEntry() { 71 CacheEntry rc; 72 synchronized( tail ) { 73 rc = tail.previous; 74 } 75 return rc.remove() ? rc : null; 76 } 77 }; 78 } 79 80 } 81 | Popular Tags |