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.servlet;
11:
12: import org.mmbase.module.core.MMBase;
13: import org.mmbase.module.Module;
14: import org.mmbase.util.logging.Logging;
15: import org.mmbase.util.logging.Logger;
16: import javax.servlet.ServletException;
17:
18: /**
19: * Seperate thread to init MMBase. This is because init() of Servlets and Filters must take little
20: * time, to not hold other web-apps. Init of MMBase may take indefinitely if e.g. the database is down.
21: *
22: * @version $Id: MMBaseStartThread.java,v 1.7 2007/07/30 09:02:52 michiel Exp $
23: * @author Michiel Meeuwissen
24: * @since MMBase-1.7
25: */
26: public class MMBaseStartThread extends Thread {
27:
28: private static final Logger log = Logging
29: .getLoggerInstance(MMBaseStartThread.class);
30:
31: public MMBaseStartThread(MMBaseStarter s) {
32: super (new Job(s), "MMBase Start Thread");
33: setDaemon(true); // if init never ends, don't hinder destroy
34: }
35:
36: /**
37: * @since MMBase-1.9
38: */
39: public static class Job implements Runnable {
40: private final MMBaseStarter starter;
41:
42: public Job(MMBaseStarter s) {
43: starter = s;
44: }
45:
46: public void run() {
47: synchronized (Module.class) {
48: log.debug("Running for " + starter);
49: if (starter.getMMBase() == null) {
50: try {
51: MMBase mmb = MMBase.getMMBase();
52: if (mmb == null) {
53: throw new Exception("getMMBase gave null");
54: }
55: starter.setInitException(null); // no error.
56: log.service("Ready for " + starter);
57: starter.setMMBase(mmb);
58: } catch (Throwable e) {
59: log.fatal(
60: "Could not instantiate the MMBase module! "
61: + e.getClass().getName() + " "
62: + e.getMessage(), e);
63: starter
64: .setInitException(new ServletException(
65: e));
66: }
67: } else {
68: log.warn("Starter '" + starter
69: + "' already has mmbase member");
70: }
71: }
72: }
73: }
74:
75: }
|