View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  	//--- Constant(s) ---
28  
29  	//--- Data field(s) ---
30  
31  	private LinkedList queue = new LinkedList();
32  	
33      private static Logger logger = Logger.getLogger(FestivalMessageQueue.class);
34  	
35  	//--- Constructor(s) ---
36  	
37      public FestivalMessageQueue()
38  	{
39  	}
40  
41      //--- Method(s) ---
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  }