1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.xnap.plugin.festival;
20  
21  import java.util.LinkedList;
22  
23  import org.apache.log4j.Logger;
24  
25  public class FestivalMessageQueue
26  {
27  	
28  
29  	
30  
31  	private LinkedList queue = new LinkedList();
32  	
33      private static Logger logger = Logger.getLogger(FestivalMessageQueue.class);
34  	
35  	
36  	
37      public FestivalMessageQueue()
38  	{
39  	}
40  
41      
42  
43  	public synchronized void clear()
44  	{
45  		queue.clear();
46  	}
47  
48  	public synchronized void addMessage(String message)
49  	{
50  		queue.add(message);
51  		notify();
52  	}
53  
54  	/***
55  	 * Returns the next text message which should be sent to the festival
56  	 * process.
57  	 *
58  	 * @return the text message to read aloud
59  	 *
60  	 * @throws InterruptedException if the thread waiting for the next message
61  	 * was interrupted
62  	 */
63  	public synchronized String getMessage() throws InterruptedException
64  	{
65  		while (queue.size() == 0) {
66  			wait();
67  		}
68  		return (String)queue.removeFirst();
69  	}
70  }