1 package org.sapia.regis.cache; 2 3 import java.util.Properties ; 4 5 import org.sapia.regis.Registry; 6 import org.sapia.regis.RegistryFactory; 7 8 public class CacheRegistryFactory implements RegistryFactory{ 9 10 14 public static final String FACTORY_CLASS = "org.sapia.regis.cache.factory"; 15 16 20 public static final String REFRESH_INTERVAL = "org.sapia.regis.cache.interval"; 21 22 23 public static final int DEFAULT_REFRESH_INTERVAL = 60 * 2; 24 25 public Registry connect(Properties props) throws Exception { 26 String intervalProp = (String )props.get(REFRESH_INTERVAL); 27 int interval = DEFAULT_REFRESH_INTERVAL; 28 if(intervalProp != null){ 29 interval = Integer.parseInt(intervalProp); 30 } 31 String className = (String )props.get(FACTORY_CLASS); 32 if(className == null){ 33 throw new IllegalArgumentException ("Registry factory class not set - " + FACTORY_CLASS); 34 } 35 Registry toCache = ((RegistryFactory)Class.forName(className).newInstance()).connect(props); 36 CacheRegistry cache = new CacheRegistry(toCache, interval*1000); 37 return cache; 38 } 39 } 40 | Popular Tags |