01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.cache;
11:
12: import org.mmbase.core.event.*;
13: import org.mmbase.module.core.*;
14:
15: /**
16: * A cache for MMObjectNodes.
17: *
18: * @author Michiel Meeuwissen
19: * @version $Id: NodeCache.java,v 1.7 2006/09/04 12:53:51 michiel Exp $
20: */
21: public class NodeCache extends Cache<Integer, MMObjectNode> implements
22: NodeEventListener {
23: private static final int CACHE_SIZE = 4 * 1024;
24:
25: private static NodeCache cache;
26:
27: public static NodeCache getCache() {
28: return cache;
29: }
30:
31: static {
32: cache = new NodeCache();
33: cache.putCache();
34: }
35:
36: public String getName() {
37: return "Nodes";
38: }
39:
40: public String getDescription() {
41: return "Node number -> MMObjectNodes";
42: }
43:
44: /**
45: * Creates the MMBase ObjectNodes Cache.
46: */
47: private NodeCache() {
48: super (CACHE_SIZE);
49: // node cache is registered as a Listener in MMBase.java.
50: }
51:
52: public MMObjectNode remove(Object key) {
53: RelatedNodesCache.getCache().removeNode((Integer) key);
54: return super .remove(key);
55: }
56:
57: public void notify(NodeEvent event) {
58: int type = event.getType();
59: if (type == Event.TYPE_DELETE
60: || ((!event.isLocal()) && type == Event.TYPE_CHANGE)) {
61: remove(event.getNodeNumber());
62: }
63: }
64: }
|