KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.regis.cache;
2
3 import org.sapia.regis.Node;
4 import org.sapia.regis.Path;
5 import org.sapia.regis.RegisSession;
6 import org.sapia.regis.Registry;
7
8 /**
9  * This class implements a read-only <code>Registry</code> that is meant to wrap
10  * another registry, whose state will be cached by this instance.
11  * <p>
12  * Cache refresh occurs synchronously, at a given time interval.
13  *
14  * @see org.sapia.regis.cache.CacheNode
15  *
16  * @author yduchesne
17  *
18  */

19 public class CacheRegistry implements Registry{
20   
21   private Registry _internal;
22   private CacheNode _root;
23   
24   public RegisSession open() {
25     CacheRegisSession session = new CacheRegisSession(_internal.open());
26     CacheSessions.join(session);
27     return session;
28   }
29   
30   /**
31    * @param reg a <code>Registry</code> whose state should be cached.
32    * @param refreshIntervalMillis an refresh interval, in milliseconds.
33    */

34   public CacheRegistry(Registry reg, long refreshIntervalMillis){
35     _root = new CacheNode(Path.parse(Node.ROOT_NAME), reg, refreshIntervalMillis);
36     _internal = reg;
37   }
38   
39   public Node getRoot() {
40     return _root;
41   }
42   
43   /**
44    * @return the <code>Registry</code> wrapped by this instance.
45    */

46   public Registry internal(){
47     return _internal;
48   }
49   
50   public void close() {
51     _internal.close();
52   }
53 }
54
Popular Tags