KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > logger > Waiter


1 /*
2  * Waiter.java
3  *
4  * Created on June 15, 2005, 1:49 PM
5  *
6  * To change this template, choose Tools | Options and locate the template under
7  * the Source Creation and Management node. Right-click the template and choose
8  * Open. You can then make changes to the template in the Source Editor.
9  */

10
11 package org.netbeans.modules.logger;
12
13 import org.netbeans.modules.logger.listeners.ListenerTools;
14
15 /**
16  * This class is necessary to make the whole IDE wait for user input at launchtime.
17  * @author loicsegapelli
18  */

19 public class Waiter implements Runnable JavaDoc{
20     
21     Main main;
22     /**
23      * as long as <CODE>true</CODE> the waiting loop will go on.
24      */

25     private boolean keepOn=true;
26     
27     /** Creates a new instance of Waiter */
28     public Waiter() {
29     }
30     
31     /**
32      * When an object implementing interface <code>Runnable</code> is used
33      * to create a thread, starting the thread causes the object's
34      * <code>run</code> method to be called in that separately executing
35      * thread.
36      * <p>
37      * The general contract of the method <code>run</code> is that it may
38      * take any action whatsoever.
39      *
40      * @see java.lang.Thread#run()
41      */

42     public void run() {
43         while(keepOn)
44             try{
45                 Thread.sleep(500);
46             } catch(java.lang.InterruptedException JavaDoc e){
47                 ListenerTools.logError(e);
48             }
49     }
50     
51     /**
52      * We have to use a waiting loop instead of a more elegant notify() call. The
53      * reason is that <CODE>Waiter</CODE> is a <CODE>Thread</CODE> created
54      * by <CODE>Main</CODE> which extends <CODE>ModuleInstall</CODE>, and using
55      * method <CODE>myThread.notify()</CODE> generates a
56      * <CODE>java.lang.IllegalMonitorStateException</CODE>
57      */

58     public void makeMeWait(){
59         while(keepOn)
60             try{
61                 Thread.sleep(500);
62             } catch(java.lang.InterruptedException JavaDoc e){
63                 ListenerTools.logError(e);
64             }
65     }
66     
67     /**
68      * changes the value of boolean <CODE>keepOn</CODE>, ending the waiting loop
69      */

70     public void wakeUp(){
71         keepOn = false;
72     }
73     
74 }
75
Popular Tags