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.io.IOException;
22 import java.io.OutputStream;
23
24 import org.apache.log4j.Logger;
25 import org.xnap.gui.StatusBar;
26
27 public class FestivalRunner implements Runnable
28 {
29
30
31
32
33 private boolean die = false;
34 private OutputStream out;
35 private FestivalMessageQueue queue;
36 private Thread t = null;
37
38 private static Logger logger = Logger.getLogger(FestivalRunner.class);
39
40
41
42 public FestivalRunner(FestivalMessageQueue queue, OutputStream out)
43 {
44 this.out = out;
45 this.queue = queue;
46 }
47
48
49
50 public void start()
51 {
52 die = false;
53 t = new Thread(this, "FestivalRunner");
54 t.start();
55 }
56
57 public void stop()
58 {
59 die = true;
60 if (t != null) {
61 t.interrupt();
62 }
63 }
64
65 public void run()
66 {
67 while (!die) {
68 String msg = null;
69 try {
70 msg = queue.getMessage();
71 }
72 catch (InterruptedException ie) {
73 continue;
74 }
75 try {
76 out.write(msg.getBytes());
77 out.flush();
78 }
79 catch (IOException ie) {
80 StatusBar.setText("Error writing to festival");
81 logger.debug("Error writing to festival", ie);
82 return;
83 }
84 }
85 }
86 }