KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > util > TimerListNode


1 package org.jacorb.trading.util;
2 /**
3  * TimerListNode.java
4  *
5  *
6  * Created: Sat Feb 5 11:41:42 2000
7  *
8  * @author Nicolas Noffke
9  * @version $Id: TimerListNode.java,v 1.5 2004/04/28 12:37:29 brose Exp $
10  */

11
12 public class TimerListNode{
13   private TimerListNode next = null;
14   private boolean do_interrupt = true;
15   private boolean interrupt_sent = false;
16
17   public Thread JavaDoc interruptee = null;
18   public long wakeup_time;
19
20   public TimerListNode(){}
21
22   public TimerListNode(Thread JavaDoc interruptee, long wakeup_time){
23     this.interruptee = interruptee;
24     this.wakeup_time = wakeup_time;
25   }
26
27   public boolean hasNext(){
28     return next != null;
29   }
30
31   /**
32    * Get the next node of this list. Blocks until
33    * a node is available.
34    *
35    * @return the next node in this list.
36    */

37   public synchronized TimerListNode getNext(){
38     while (next == null)
39       try{
40     wait();
41       }catch(Exception JavaDoc _e){
42       }
43     
44     return next;
45   }
46
47   /**
48    * Set the following node for this node.
49    * Will notify all threads blocked on this node.
50    *
51    * @param node the next node.
52    */

53   public synchronized void setNext(TimerListNode node){
54     next = node;
55     notifyAll();
56   }
57
58
59   public synchronized void doInterrupt(){
60     if (do_interrupt){
61       interrupt_sent = true;
62       interruptee.interrupt();
63     }
64   }
65
66   public synchronized void stopTimer(){
67
68     if (! interrupt_sent)
69       do_interrupt = false;
70     else
71       try{
72     wait(); //wait for interrupt to come
73
}catch(Exception JavaDoc _e){
74       }
75   }
76 } // TimerListNode
77

78
79
80
81
82
83
84
85
86
87
88
89
Popular Tags