source: main/trunk/greenstone3/src/java/org/greenstone/admin/gui/ThreadControl.java@ 28862

Last change on this file since 28862 was 28862, checked in by kjdon, 10 years ago

destroy method of Thread has been deprecated. and ThreadControl.destroy never did anything anyway, so I have deleted it

  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the GAI application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: Chi-Yu Huang, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.admin.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import java.net.*;
43import javax.swing.*;
44import javax.swing.event.*;
45
46import org.greenstone.admin.GAI;
47import org.greenstone.admin.GAIManager;
48import org.greenstone.admin.gui.LogPane;
49import org.greenstone.admin.gui.ParsingProgress;
50import org.apache.tools.ant.*;
51import org.apache.tools.ant.helper.ProjectHelperImpl;
52
53
54
55public class ThreadControl
56 extends Thread {
57
58 private GAIManager gai_man;
59
60 public ThreadControl(){
61 }
62
63 public void run(){
64 }
65
66
67 public void executeAntTarget(String command_string) throws IOException {
68 Project ant = new Project();
69 File buildFile = new File (GAI.gsdl3_src_home + File.separator + "build.xml");
70
71 //Set up a PrintStream pointing at a file
72 //FileOutputStream ant_out =
73 // new FileOutputStream(GAI.gsdl3_src_home + File.separator + "ant_out.log");
74 //FileOutputStream ant_err =
75 // new FileOutputStream(GAI.gsdl3_src_home + File.separator + "ant_err.log");
76
77 // BufferedOutputStream ant_out_buffer =
78 // new BufferedOutputStream(ant_out, 1024);
79 //BufferedOutputStream ant_err_buffer =
80 /// new BufferedOutputStream(ant_err, 1024);
81
82 //PrintStream ant_out_ps =
83 // new PrintStream(ant_out_buffer, false);
84 //PrintStream ant_err_ps =
85 // new PrintStream(ant_err_buffer, false);
86
87 DefaultLogger log = new DefaultLogger();
88 //log.setErrorPrintStream(ant_err_ps);
89 //log.setOutputPrintStream(ant_out_ps);
90
91 log.setErrorPrintStream(System.err);
92 log.setOutputPrintStream(System.out);
93 log.setMessageOutputLevel(Project.MSG_INFO);
94 ant.addBuildListener(log);
95 try {
96 ant.init();
97 ant.fireBuildStarted();
98 ProjectHelper helper = ProjectHelper.getProjectHelper();
99 helper.parse(ant, buildFile);
100 ant.executeTarget(command_string);
101 ant.fireBuildFinished(null);
102 }
103 catch (BuildException e) {
104 e.printStackTrace(System.err);
105 ant.fireBuildFinished(e);
106 }
107 /*finally {
108 System.setOut(ant_out_ps);
109 System.setErr(ant_err_ps);
110 }*/
111
112 //boolean ant_success = checkAntResult();
113 //ant_out_ps.close();
114 //ant_err_ps.close();
115 /*if (!ant_success){
116 int result = JOptionPane.showConfirmDialog((Component) null, "Ant building call was failed, do you want to see the log file?", "Exit Confirmation", JOptionPane.YES_NO_OPTION);
117 if ( result == JOptionPane.YES_OPTION) {
118 //System.exit(1);
119 // Showing ant_out.log content
120 } else if (result == JOptionPane.NO_OPTION) {
121 JOptionPane.showMessageDialog((Component) null,"You can see the log file from Log Pane!");
122 }
123 } else {
124 //System.err.println("****Ant build successed");
125 //JOptionPane.showMessageDialog((Component) null,"You can see the log file from Log Pane!");
126
127 }*/
128 }
129
130 /*public boolean checkAntResult(){
131 try {
132 String filename = GAI.gsdl3_src_home + File.separator +"ant_out.log";
133 String fileLine;
134
135 BufferedReader ant_result = new BufferedReader(new FileReader(filename));
136
137 while ((fileLine = ant_result.readLine()) != null) {
138 if (fileLine.matches("BUILD SUCCESSFUL")){
139 //return true;
140 return false;
141 } else if (fileLine.matches("BUILD FAILED")){
142 //System.err.println("***Ant result"+fileLine);
143 return false;
144 }
145 }
146 } catch (Exception e) {
147 e.printStackTrace();
148
149 }
150 return false;
151 }*/
152
153
154 public class restartTomcatServer
155 implements Runnable {
156 private String command_string = null;
157 /* Construct a restartTomcatServer Object*/
158 public restartTomcatServer(String command_string) {
159 this.command_string = command_string;
160 }
161
162 public void run() {
163 try {
164 executeAntTarget(this.command_string);
165 } catch(Exception e) {
166 System.out.println(e.getMessage());
167 }
168 }
169 }
170
171 public class startupTomcatServer
172 implements Runnable {
173 private String command_string = null;
174 /* Construct a startupTomcatServer Object*/
175 public startupTomcatServer(String command_string) {
176 this.command_string = command_string;
177 }
178 public void run() {
179 try {
180 executeAntTarget(this.command_string);
181 } catch(Exception e) {
182 System.out.println(e.getMessage());
183 }
184 }
185 }
186
187 public class shutdownTomcatServer
188 implements Runnable {
189 private String command_string = null;
190 /* Construct a shutdownTomcatServer Object*/
191 public shutdownTomcatServer(String command_string) {
192 this.command_string = command_string;
193 }
194 public void run() {
195 try {
196 executeAntTarget(this.command_string);
197 } catch(Exception e) {
198 System.out.println(e.getMessage());
199 }
200 }
201 }
202
203 public class startupMysqlServer
204 implements Runnable {
205 private String command_string = null;
206
207 /* Construct a startupMysqlServer Object*/
208 public startupMysqlServer(String command_string) {
209 this.command_string = command_string;
210 }
211 public void run() {
212 try {
213 executeAntTarget(this.command_string);
214 } catch(Exception e) {
215 System.out.println(e.getMessage());
216 }
217 }
218 }
219
220 public class shutdownMysqlServer
221 implements Runnable {
222 private String command_string = null;
223 /* Construct a shutdownMysqlServer Object*/
224 public shutdownMysqlServer(String command_string) {
225 this.command_string = command_string;
226 }
227 public void run() {
228 try {
229 executeAntTarget(this.command_string);
230 } catch(Exception e) {
231 System.out.println(e.getMessage());
232 }
233 }
234 }
235
236 public class restartMysqlServer
237 implements Runnable {
238 private String command_string = null;
239 /* Construct a restartMysqlServer Object*/
240 public restartMysqlServer(String command_string) {
241 this.command_string = command_string;
242 }
243 public void run() {
244 try {
245 executeAntTarget(this.command_string);
246 } catch(Exception e) {
247 System.out.println(e.getMessage());
248 }
249 }
250 }
251
252 public class installGS3
253 implements Runnable {
254 private String command_string = null;
255
256 /* Install GSDL3 through ant program*/
257 public installGS3(String command_string) {
258 this.command_string = command_string;
259 }
260 public void run() {
261 try {
262
263 executeAntTarget(this.command_string);
264 // ant_success;
265 } catch(Exception e) {
266 System.out.println(e.getMessage());
267 }
268 }
269 }
270
271
272}
273
274
275/***
276 * This program shows how you can time a set of threads. The main()
277 * program demonstrates the timing classes by spawning and timing a
278 * set of threads that just execute a dummy loop.
279 ***/
280/*public class ThreadTiming {
281
282 /** Times a group of threads. Works with TimingWrapper. */
283// public static class ThreadTimer {
284// private boolean __resultReady;
285// private int __monitor[], __numThreads;
286// private long __begin, __end;
287
288 /** Creates a ThreadTimer that can time a given number of threads. */
289// public ThreadTimer(int numThreads) {
290// __monitor = new int[1];
291// __monitor[0] = 0;
292// __numThreads = numThreads;
293// __resultReady = false;
294// }
295
296 /** Starts the timer when all the threads are ready to start. */
297// public void start() {
298// synchronized(__monitor) {
299// if(++__monitor[0] >= __numThreads) {
300// __begin = System.currentTimeMillis();
301// __monitor.notifyAll();
302// } else {
303// while(true) {
304// try {
305// __monitor.wait();
306// } catch(InterruptedException e) {
307// continue;
308// }
309// break;
310// }
311// }
312// }
313// }
314
315 /** Stops the timer when the last thread is done. */
316// public void stop() {
317// synchronized(__monitor) {
318// if(--__monitor[0] <= 0) {
319// __end = System.currentTimeMillis();
320// synchronized(this) {
321// __resultReady = true;
322// notify();
323// }
324// }
325// }
326//}/
327
328 /** Calling thread waits until timing result is ready. */
329// public synchronized void waitForResult() {
330// while(!__resultReady) {
331// try {
332/// wait();
333// } catch(InterruptedException e) {
334// }
335// }
336// __resultReady = false;
337//}
338//
339///** Returns elapsed time in milliseconds. */
340//public long getElapsedTime() {
341// return (__end - __begin);
342//}
343// }
344//
345 /** Wraps a thread so it can be timed with a group. */
346// public static class TimingWrapper implements Runnable {
347// private Runnable __runMe;
348//private ThreadTimer __timer;
349
350// public TimingWrapper(Runnable runMe, ThreadTimer timer) {
351// __runMe = runMe;
352// __timer = timer;
353//}
354
355//public void run() {
356// // Note, this timing approach does not measure thread creation
357// // and thread joining overhead.
358// __timer.start();
359// __runMe.run();
360// __timer.stop();
361//}
362// }
363
364
365//public static final int NUM_THREADS = 10;
366//public static final int NUM_LOOPS = 10000000;
367
368// public static void main(String[] args) {
369//int thread;
370//ThreadTimer timer;
371//
372// timer = new ThreadTimer(NUM_THREADS);
373
374 // Start a number of threads that iterate a dummy loop
375// for(thread = 0; thread < NUM_THREADS; thread++)
376// new Thread(new TimingWrapper(new Runnable() {
377// public void run() {
378// for(int i=0; i < NUM_LOOPS; i++);
379// }
380// }, timer)).start();
381//
382//timer.waitForResult();
383
384// System.out.println("Elapsed Seconds: " +
385// ((double)timer.getElapsedTime())/1000.0);
386// }
387
388//}*/
Note: See TracBrowser for help on using the repository browser.