KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > cache > Engine


1 package info.magnolia.cms.cache;
2
3 import info.magnolia.cms.beans.config.ContentRepository;
4 import info.magnolia.cms.core.Content;
5 import info.magnolia.cms.module.AbstractModule;
6 import info.magnolia.cms.module.InitializationException;
7 import info.magnolia.cms.module.InvalidConfigException;
8 import info.magnolia.cms.module.RegisterException;
9 import info.magnolia.cms.util.NodeDataUtil;
10
11 import org.apache.commons.lang.BooleanUtils;
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14
15
16 /**
17  * @author Fabrizio Giustina
18  * @version $Revision: 6341 $ ($Author: philipp $)
19  */

20 public class Engine extends AbstractModule {
21
22     /**
23      * Logger.
24      */

25     private static Log log = LogFactory.getLog(Engine.class);
26
27     private CacheManager cacheManager = CacheManagerFactory.getCacheManager();
28
29     /**
30      * Init cache manager
31      */

32     public void init(Content configNode) throws InvalidConfigException, InitializationException {
33         this.cacheManager.init(configNode);
34         this.setInitialized(true);
35     }
36
37     /**
38      * @see info.magnolia.cms.module.Module#destroy()
39      */

40     public void destroy() {
41         if (this.cacheManager.isRunning()) {
42             this.cacheManager.stop();
43         }
44     }
45
46     /**
47      * @see info.magnolia.cms.module.AbstractModule#onRegister(int)
48      */

49     protected void onRegister(int registerState) throws RegisterException {
50         // set the cache inactive if this is an admin instance (default)
51
try {
52             boolean admin = BooleanUtils.toBoolean(NodeDataUtil.getString(
53                 ContentRepository.CONFIG,
54                 "/server/admin",
55                 "true"));
56             if (admin) {
57                 NodeDataUtil.getOrCreate(this.getModuleNode().getContent("config"), "active").setValue(false);
58             }
59         }
60         catch (Exception JavaDoc e) {
61             log.error("can't set the caches active flag properly", e);
62         }
63     }
64
65 }
66
Popular Tags