KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > security > implementation > cloudcontext > builders > CacheInvalidator


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.security.implementation.cloudcontext.builders;
11
12 import java.util.*;
13
14 import org.mmbase.module.core.MMBaseObserver;
15 import org.mmbase.module.core.MMBase;
16 import org.mmbase.util.logging.*;
17
18 /**
19  * Invalidates the security caches if somethings changes in the
20  * security nodes. This Observer will be subscribed to all security
21  * builders for this goal (in their init methods).
22  *
23  * @todo undoubtly, this is too crude.
24  *
25  * @author Michiel Meeuwissen
26  * @version $Id: CacheInvalidator.java,v 1.8 2006/03/28 23:06:58 michiel Exp $
27  * @since MMBase-1.7
28  */

29 class CacheInvalidator implements MMBaseObserver {
30
31     private static final Logger log = Logging.getLoggerInstance(CacheInvalidator.class);
32
33     private static CacheInvalidator instance = new CacheInvalidator();
34
35     // this is a singleton
36
static CacheInvalidator getInstance() {
37         return instance;
38     }
39     
40     private CacheInvalidator() {
41     }
42
43     private List securityCaches = new ArrayList(); // list of all security caches that must be invalidated
44

45     /**
46      * A security builder can add its cache(s)
47      */

48     synchronized void addCache(Map c) {
49         securityCaches.add(c);
50     }
51
52     // javadoc inherited
53
public boolean nodeRemoteChanged(String JavaDoc machine, String JavaDoc number, String JavaDoc builder, String JavaDoc ctype) {
54         return nodeChanged(machine, number, builder, ctype);
55     }
56
57
58     // javadoc inherited
59
public boolean nodeLocalChanged(String JavaDoc machine, String JavaDoc number, String JavaDoc builder, String JavaDoc ctype) {
60         return nodeChanged(machine, number, builder, ctype);
61     }
62
63     /**
64      * What happens if something changes: clear the caches
65      */

66     synchronized protected boolean nodeChanged(String JavaDoc machine, String JavaDoc number, String JavaDoc builder, String JavaDoc ctype) {
67         if (((int) (System.currentTimeMillis() / 1000) - MMBase.startTime) > 300) {
68             log.service("A security object " + number + " (" + builder + ") has changed, invalidating all security caches");
69         } else if (log.isDebugEnabled()) {
70             log.debug("A security object " + number + " (" + builder + ") has changed, invalidating all security caches");
71         }
72         Iterator i = securityCaches.iterator();
73         while (i.hasNext()) {
74             Map c = (Map) i.next();
75             c.clear();
76         }
77         return true;
78     }
79
80 }
81
Popular Tags