1 64 65 package com.jcorporate.expresso.core.cache; 66 67 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList; 68 import com.jcorporate.expresso.core.registry.ExpressoThread; 69 import org.apache.log4j.Logger; 70 71 import java.util.Iterator ; 72 73 96 97 public class CacheCleaner extends ExpressoThread { 98 private static final transient Logger log = Logger.getLogger(CacheCleaner.class); 99 100 private CopyOnWriteArrayList cacheSystems = new CopyOnWriteArrayList(); 101 102 private boolean done = false; 103 104 protected CacheCleaner() { 105 super(); 106 } 107 108 114 public void registerCacheSystem(CacheSystem newCache) { 115 cacheSystems.add(newCache); 116 if (log.isDebugEnabled()) { 117 log.debug("Registering cache system: " + ((Object ) newCache).toString() + " for cleaning"); 118 } 119 } 120 121 122 127 public void run() { 128 super.run(); 129 130 if (log.isDebugEnabled()) { 131 log.debug("Starting Cache Cleaning"); 132 } 133 134 while (!this.isInterrupted() && !done) { 135 for (Iterator i = cacheSystems.iterator(); i.hasNext();) { 136 if (this.isInterrupted()) { 140 return; 141 } 142 143 CacheSystem oneCacheSystem = (CacheSystem) i.next(); 144 145 if (log.isDebugEnabled()) { 146 log.debug("Cleaning cache system: " + ((Object ) oneCacheSystem).toString()); 147 } 148 149 oneCacheSystem.adjustForMemory(); 150 151 for (Iterator j = oneCacheSystem.getAllCacheNames().iterator(); 152 j.hasNext();) { 153 String oneCacheName = (String ) j.next(); 154 Cache oneCache = oneCacheSystem.getCache(oneCacheName); 155 if (oneCache != null) { 156 oneCache.getItems(); 161 } 162 } 163 } 164 165 if (isInterrupted()) { 166 break; 167 } else { 168 try { 169 sleep(30000); 172 } catch (InterruptedException ex) { 173 break; 174 } 175 } 176 } 177 178 if (log.isDebugEnabled()) { 179 log.debug("Cache cleaner exiting."); 180 } 181 } 182 183 public void interrupt() { 184 done = true; 185 super.interrupt(); 186 } 187 } 188 | Popular Tags |