KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > util > OneShotEvent


1 package hudson.util;
2
3 /**
4  * Concurrency primitive "event".
5  *
6  * @author Kohsuke Kawaguchi
7  */

8 public final class OneShotEvent {
9     private boolean signaled;
10
11     /**
12      * Non-blocking method that signals this event.
13      */

14     public synchronized void signal() {
15         if(signaled) return;
16         this.signaled = true;
17         notify();
18     }
19
20     /**
21      * Blocks until the event becomes the signaled state.
22      *
23      * <p>
24      * This method blocks infinitely until a value is offered.
25      */

26     public synchronized void block() throws InterruptedException JavaDoc {
27         while(!signaled)
28             wait();
29     }
30
31     /**
32      * Blocks until the event becomes the signaled state.
33      *
34      * <p>
35      * If the specified amount of time elapses,
36      * this method returns null even if the value isn't offered.
37      */

38     public synchronized void block(long timeout) throws InterruptedException JavaDoc {
39         if(!signaled)
40             wait(timeout);
41     }
42
43     /**
44      * Returns true if a value is offered.
45      */

46     public synchronized boolean isSignaled() {
47         return signaled;
48     }
49 }
50
Popular Tags