2 * Portions Copyright 2004 Sun Microsystems, Inc.
3 * Portions Copyright 1999-2004 Language Technologies Institute,
4 * Carnegie Mellon University.
5 * All Rights Reserved. Use is subject to license terms.
7 * See the file "license.terms" for information on usage and
8 * redistribution of this file, and for a DISCLAIMER OF ALL
11 package com.sun.speech.freetts;
13 import java.util.LinkedList;
16 * Manages a process queue for utterances. Utterances that are
17 * queued to a processor can be written via the post method.
18 * A processing thread can wait for an utterance to arrive via the
21 public class OutputQueue {
22 private LinkedList list = new LinkedList();
24 private final static int DEFAULT_SIZE = 5;
25 private volatile boolean closed = false;
28 * Creates an OutputQueue with the given size.
30 * @param size the size of the queue
32 public OutputQueue(int size) {
37 * Creates a queue with the default size.
39 public OutputQueue() {
44 * Posts the given utterance to the queue. This call will block if
47 * @param utterance the utterance to post
49 * @throws IllegalStateException if the queue is closed
51 public synchronized void post(Utterance utterance) {
53 throw new IllegalStateException("output queue closed");
56 while (list.size() >= size) {
59 } catch (InterruptedException ie) {
71 public synchronized void close() {
79 * Determines if the queue is closed.
81 * @return true the queue is closed; otherwise false
83 public boolean isClosed() {
88 * Blocks until there is an utterance in the queue.
90 * @return the next utterance. On a close or interrupt, a null is
93 public synchronized Utterance pend() {
94 Utterance utterance = null;
95 while (list.size() == 0) {
98 } catch (InterruptedException ie) {
102 utterance = (Utterance) list.removeFirst();
108 * Removes all items from this OutputQueue.
110 public synchronized void removeAll() {