KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > cache > CacheRegistryFactory


1 package org.sapia.regis.cache;
2
3 import java.util.Properties JavaDoc;
4
5 import org.sapia.regis.Registry;
6 import org.sapia.regis.RegistryFactory;
7
8 public class CacheRegistryFactory implements RegistryFactory{
9   
10   /**
11    * This constant corresponds to the property indicating the name of the registry
12    * factory class to wrap for caching.
13    */

14   public static final String JavaDoc FACTORY_CLASS = "org.sapia.regis.cache.factory";
15   
16   /**
17    * This constant corresponds to the property indicating the cache refresh
18    * interval, in seconds.
19    */

20   public static final String JavaDoc 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 JavaDoc props) throws Exception JavaDoc {
26     String JavaDoc intervalProp = (String JavaDoc)props.get(REFRESH_INTERVAL);
27     int interval = DEFAULT_REFRESH_INTERVAL;
28     if(intervalProp != null){
29       interval = Integer.parseInt(intervalProp);
30     }
31     String JavaDoc className = (String JavaDoc)props.get(FACTORY_CLASS);
32     if(className == null){
33       throw new IllegalArgumentException JavaDoc("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