1 7 package org.enhydra.dods.cache.base; 8 9 import org.enhydra.dods.DODS; 10 import org.enhydra.dods.cache.CacheConstants; 11 12 import com.lutris.appserver.server.sql.DatabaseManagerException; 13 import com.lutris.appserver.server.sql.standard.StandardLogicalDatabase; 14 import com.lutris.logging.Logger; 15 16 21 public class BaseCacheManager { 22 23 private static DODSCacheAbstractFactory cacheFactory = null; 24 25 public static boolean isCacheManagerConfigured() { 26 return cacheFactory!=null; 27 } 28 29 private static void configureCacheFactory() { 30 String logicalDbName = null; 31 String cacheFactoryClassName = null; 32 Class cacheFactoryClass = null; 33 try { 34 logicalDbName = DODS.getDatabaseManager().getDefaultDB(); 35 cacheFactoryClassName = ((StandardLogicalDatabase)DODS 36 .getDatabaseManager() 37 .findLogicalDatabase(logicalDbName)) 38 .getDatabaseConfiguration() 39 .getDodsCacheFactory(); 40 if (cacheFactoryClassName != null) { 41 try { 42 cacheFactoryClass = Class.forName(cacheFactoryClassName); 43 cacheFactory = (DODSCacheAbstractFactory)cacheFactoryClass.newInstance(); 44 } catch (Exception e) { 45 DODS.getLogChannel() 46 .write(Logger.ERROR, 47 "Failed to make DODSCacheFactory :" 48 + cacheFactoryClassName 49 + " creating " 50 + CacheConstants.DEFAULT_DODS_CACHE_FACTORY 51 + " instead"); 52 cacheFactory = null; 53 } 54 } 55 if (cacheFactoryClassName == null || cacheFactory == null) { 56 try { 57 cacheFactoryClass = Class.forName(CacheConstants.DEFAULT_DODS_CACHE_FACTORY); 58 cacheFactory = (DODSCacheAbstractFactory) cacheFactoryClass.newInstance(); 59 } catch (Exception e) { 60 String str = "Failed to make "+CacheConstants.DEFAULT_DODS_CACHE_FACTORY; 61 DODS.getLogChannel().write(Logger.CRITICAL, str); 62 throw new Error (str); 63 } 64 } 65 } catch (DatabaseManagerException e){ 66 DODS.getLogChannel().write(Logger.CRITICAL,"Failed to make DODSCacheFactory - CRITICAL ERROR"); 67 } 68 } 69 70 public static DODSCache getDODSCache(int maxSize) { 71 if(!isCacheManagerConfigured()) { 72 configureCacheFactory(); 73 } 74 return cacheFactory.newDODSCache(maxSize); 75 } 76 } 77 | Popular Tags |