1 | package org.greenstone.gsdl3.build;
|
---|
2 |
|
---|
3 | public class GS2PerlListener
|
---|
4 | implements ConstructionListener {
|
---|
5 |
|
---|
6 | /** a buffer holding all the messages */
|
---|
7 | protected StringBuffer log=null;
|
---|
8 | /** a buffer holding only the latest update */
|
---|
9 | protected StringBuffer update = null;
|
---|
10 |
|
---|
11 | /** a status code */
|
---|
12 | protected int status = -1;
|
---|
13 | /** whether the process this is listeneing to is finshed */
|
---|
14 | protected boolean finished = false;
|
---|
15 |
|
---|
16 | public GS2PerlListener() {
|
---|
17 | this.log = new StringBuffer();
|
---|
18 | this.update = new StringBuffer();
|
---|
19 | }
|
---|
20 |
|
---|
21 | public boolean isFinished() {
|
---|
22 | return this.finished;
|
---|
23 | }
|
---|
24 | public String getLog() {
|
---|
25 | return this.log.toString();
|
---|
26 | }
|
---|
27 | public int getStatus() {
|
---|
28 | return this.status;
|
---|
29 | }
|
---|
30 | synchronized public String getUpdate() {
|
---|
31 | this.log.append(this.update);
|
---|
32 | String tmp = this.update.toString();
|
---|
33 | this.update.delete(0, this.update.length());
|
---|
34 | return tmp;
|
---|
35 | }
|
---|
36 |
|
---|
37 | // do we need to synchronize the methods below?
|
---|
38 |
|
---|
39 | /** This event handler used to signify that a task has been started */
|
---|
40 | synchronized public void processBegun(ConstructionEvent evt) {
|
---|
41 | this.status = evt.getStatus();
|
---|
42 | this.update.append(evt.getMessage()+"\n");
|
---|
43 |
|
---|
44 | }
|
---|
45 | /** This event handler used to signify that a task has been completed */
|
---|
46 | synchronized public void processComplete(ConstructionEvent evt){
|
---|
47 | this.status = evt.getStatus();
|
---|
48 | this.update.append(evt.getMessage()+"\n");
|
---|
49 | }
|
---|
50 | /** This event handler used to send status updates as the task is progressing */
|
---|
51 | synchronized public void processStatus(ConstructionEvent evt){
|
---|
52 | this.status = evt.getStatus();
|
---|
53 | this.update.append(evt.getMessage()+"\n");
|
---|
54 | }
|
---|
55 | /** This event handler used to send any other messages to the listeners */
|
---|
56 | synchronized public void message(ConstructionEvent evt){
|
---|
57 | this.status = evt.getStatus();
|
---|
58 | this.update.append(evt.getMessage()+"\n");
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | }
|
---|