1 18 package org.objectweb.perseus.cache; 19 20 import org.objectweb.perseus.cache.api.CacheManager; 21 import org.objectweb.perseus.cache.api.CacheAttributeController; 22 import org.objectweb.fractal.util.Fractal; 23 import org.objectweb.fractal.api.Component; 24 import org.objectweb.fractal.api.Interface; 25 import org.objectweb.fractal.api.control.NameController; 26 import org.objectweb.util.monolog.api.BasicLevel; 27 28 import java.util.StringTokenizer ; 29 30 36 public class CacheManagerFactory { 37 38 39 private static CacheManager singleton = null; 40 41 private final static String CACHE_MANAGER_TM = 42 "org.objectweb.perseus.cache.lib.SimpleCacheManager"; 43 44 public static CacheManager getCacheManager() throws Exception { 45 if (singleton == null) { 46 synchronized(CacheManagerFactory.class) { 47 if (singleton == null) { 48 singleton = newCacheManager(); 49 } 50 } 51 } 52 return singleton; 53 } 54 55 public static CacheManager newCacheManager() throws Exception { 56 Component cm = FractalHelper.instanciate(CACHE_MANAGER_TM); 57 Fractal.getLifeCycleController(cm).startFc(); 58 return (CacheManager) cm.getFcInterface("cache-manager"); 59 } 60 61 public static CacheAttributeController getCacheAttributeController(CacheManager cm) throws Exception { 62 Component primitivecm = getSubComponent( 63 ((Interface) cm).getFcItfOwner(), "cache-manager"); 64 if (primitivecm == null) { 65 throw new Exception ("Impossible to find the CacheAttributeController for the given CacheManager: " + cm); 66 } 67 return (CacheAttributeController) Fractal.getAttributeController(primitivecm); 68 } 69 70 private static Component getSubComponent(Component parent, 71 String path) throws Exception { 72 StringTokenizer st = new StringTokenizer (path, ".", false); 73 Component res = parent; 74 while(st.hasMoreTokens()) { 75 String commponenentname = st.nextToken(); 76 Component[] children = Fractal.getContentController(res) 77 .getFcSubComponents(); 78 int i = 0; 79 while(i<children.length && 80 !Fractal.getNameController(children[i]) 81 .getFcName().equals(commponenentname)) { 82 i++; 83 } 84 if (i<children.length) { 85 res = children[i]; 86 } else { 87 return null; 88 } 89 } 90 return res; 91 } 92 93 } 94 | Popular Tags |