KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > cache > server > DistributedCacheCoordinatorBean


1 package com.knowgate.cache.server;
2
3 import java.lang.System JavaDoc;
4 import java.util.TreeMap JavaDoc;
5
6 import javax.ejb.CreateException JavaDoc;
7 import javax.ejb.SessionBean JavaDoc;
8 import javax.ejb.SessionContext JavaDoc;
9
10 public class DistributedCacheCoordinatorBean implements SessionBean JavaDoc {
11   private SessionContext JavaDoc sessionContext;
12   private TreeMap JavaDoc oBTree;
13
14   // -----------------------------------------------------------------
15

16   public void setSessionContext(SessionContext JavaDoc sessionContext) {
17     this.sessionContext = sessionContext;
18   }
19
20   // -----------------------------------------------------------------
21

22   public void ejbCreate() throws CreateException JavaDoc {
23      oBTree = new TreeMap JavaDoc();
24   }
25
26   // -----------------------------------------------------------------
27

28   public void ejbRemove() {
29     oBTree.clear();
30     oBTree = null;
31   }
32
33   // -----------------------------------------------------------------
34

35   public void ejbActivate() { }
36
37   // -----------------------------------------------------------------
38

39   public void ejbPassivate() { }
40
41   // -----------------------------------------------------------------
42

43   public long now() {
44     return System.currentTimeMillis();
45   }
46
47   // -----------------------------------------------------------------
48

49   public long lastModified(String JavaDoc sKey) {
50     Long JavaDoc oDt = (Long JavaDoc) oBTree.get(sKey);
51
52     if (oDt==null) oDt = new Long JavaDoc((long) 0);
53
54     return oDt.longValue();
55   }
56
57   // -----------------------------------------------------------------
58

59   public long modify(String JavaDoc sKey) {
60     Long JavaDoc oDt = new Long JavaDoc(System.currentTimeMillis());
61
62     oBTree.remove(sKey);
63     oBTree.put(sKey, oDt);
64
65     return oDt.longValue();
66   }
67
68   // -----------------------------------------------------------------
69

70   public void expire(String JavaDoc sKey) {
71     oBTree.remove(sKey);
72   }
73
74   // -----------------------------------------------------------------
75

76   public void flush() {
77     oBTree.clear();
78   }
79 }
Popular Tags