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.module.tools;
11:
12: import org.mmbase.module.core.MMBase;
13: import org.mmbase.util.logging.Logger;
14: import org.mmbase.util.logging.Logging;
15:
16: /**
17: * Bootstrap class that wait's in a thead for MMBase to have a running state. Once the state is running
18: * it calls MMAdmin.probeCall() and finishes.
19: *
20: * @application Admin, Application
21: * @author Daniel Ockeloen
22: * @version $Id: MMAdminProbe.java,v 1.11 2007/10/02 12:15:14 michiel Exp $
23: */
24: public class MMAdminProbe implements Runnable {
25:
26: private static Logger log = Logging
27: .getLoggerInstance(MMAdminProbe.class.getName());
28:
29: private Thread kicker = null;
30:
31: /**
32: * DEFAULT_SLEEP_TIME = 0 ms
33: **/
34: public final static long DEFAULT_SLEEP_TIME = 0;
35:
36: long sleeptime = DEFAULT_SLEEP_TIME;
37:
38: /**
39: * reference to MMAdmin
40: */
41: MMAdmin parent = null;
42: /**
43: * reference to MMBase
44: */
45: private MMBase mmb = null;
46:
47: /**
48: * DEFAULT_START_DELAY = 2000; ms
49: **/
50: public final static long DEFAULT_START_DELAY = 2000;
51:
52: long startdelay = DEFAULT_START_DELAY;
53:
54: public MMAdminProbe(MMAdmin parent, MMBase mmb) {
55: this .parent = parent;
56: this .mmb = mmb;
57: init();
58: }
59:
60: public MMAdminProbe(MMAdmin parent, long sleeptime) {
61: this .parent = parent;
62:
63: this .sleeptime = sleeptime;
64:
65: startdelay = 0;
66: init();
67: }
68:
69: public void init() {
70: if (kicker == null) {
71: kicker = new Thread(this , "MMAdminProbe");
72: kicker.setDaemon(true);
73: kicker.start();
74: } else {
75: log.error("MMAdminProbe thread was already running");
76: }
77: }
78:
79: public void run() {
80: try {
81: while (!mmb.getState()) {
82: try {
83: Thread.sleep(startdelay);
84: } catch (InterruptedException e) {
85: return;
86: }
87: }
88: try {
89: Thread.sleep(sleeptime);
90: } catch (InterruptedException e) {
91: return;
92: }
93: parent.probeCall();
94: } catch (Exception e) {
95: log.error(e.getMessage());
96: log.debug("stacktrace: ", e);
97: }
98: }
99: }
|