KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > tools > MMAdminProbe


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.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.10 2005/10/23 18:00:50 nklasens Exp $
23  */

24 public class MMAdminProbe implements Runnable JavaDoc {
25
26     private static Logger log = Logging.getLoggerInstance(MMAdminProbe.class.getName());
27
28     private Thread JavaDoc kicker = null;
29
30     /**
31      * DEFAULT_SLEEP_TIME = 0 ms
32      **/

33     public final static long DEFAULT_SLEEP_TIME = 0;
34
35     long sleeptime = DEFAULT_SLEEP_TIME;
36
37     /**
38      * reference to MMAdmin
39      */

40     MMAdmin parent=null;
41     /**
42      * reference to MMBase
43      */

44     private MMBase mmb = null;
45
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 JavaDoc(this,"MMAdminProbe");
72             kicker.setDaemon(true);
73             kicker.start();
74         } else {
75             log.error("MMAdminProbe thread was already running");
76         }
77     }
78
79
80     public void run() {
81         try {
82             while (!mmb.getState()) {
83                 try {Thread.sleep(startdelay);} catch (InterruptedException JavaDoc e){ return;}
84             }
85             try { Thread.sleep(sleeptime); } catch (InterruptedException JavaDoc e){ return;}
86             parent.probeCall();
87         } catch(Exception JavaDoc e) {
88             log.error(e.getMessage());
89             log.error(Logging.stackTrace(e));
90         }
91     }
92 }
Popular Tags