1 17 18 package org.sape.carbon.services.cache.total; 19 20 import java.util.Collections ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 import org.sape.carbon.core.component.Component; 25 import org.sape.carbon.core.component.ComponentConfiguration; 26 import org.sape.carbon.core.component.lifecycle.Configurable; 27 import org.sape.carbon.core.component.lifecycle.Initializable; 28 import org.sape.carbon.services.cache.CacheLoadException; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 33 48 public class WritableCache 49 extends AbstractTotalCache 50 implements Configurable, Initializable { 51 52 53 private Log log = LogFactory.getLog(this.getClass()); 54 55 56 private Map activeMap = null; 57 58 59 private TotalCacheDataLoader dataLoader = null; 60 61 68 public void refreshAll() throws CacheLoadException { 69 70 if (log.isTraceEnabled()) { 71 log.trace("Refreshing Cache"); 72 } 73 74 synchronized (this.activeMap) { 75 this.activeMap.clear(); 76 this.activeMap.putAll(this.dataLoader.loadAllData()); 77 } 78 } 79 80 83 public void configure(ComponentConfiguration configuration) { 84 85 this.dataLoader = 86 ((TotalCacheConfiguration) configuration).getDataLoader(); 87 } 88 89 92 public void initialize(Component thisComponent) throws Exception { 93 94 Map holdingMap; 95 if (this.dataLoader instanceof ConfigurableMapTypeCacheDataLoader) { 98 holdingMap = ((ConfigurableMapTypeCacheDataLoader)this.dataLoader). 99 getMapInstance(); 100 } else { 101 holdingMap = new HashMap (); 102 } 103 this.activeMap = Collections.synchronizedMap(holdingMap); 104 } 105 106 109 protected Map getCacheMap() { 110 return this.activeMap; 111 } 112 } | Popular Tags |