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

Last change on this file since 24408 was 24408, checked in by sjm84, 13 years ago

Some admin fixes

  • Property svn:keywords set to Author Date Id Revision
File size: 10.2 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 public void destroy(){
273 }
274}
275
276
277/***
278 * This program shows how you can time a set of threads. The main()
279 * program demonstrates the timing classes by spawning and timing a
280 * set of threads that just execute a dummy loop.
281 ***/
282/*public class ThreadTiming {
283
284 /** Times a group of threads. Works with TimingWrapper. */
285// public static class ThreadTimer {
286// private boolean __resultReady;
287// private int __monitor[], __numThreads;
288// private long __begin, __end;
289
290 /** Creates a ThreadTimer that can time a given number of threads. */
291// public ThreadTimer(int numThreads) {
292// __monitor = new int[1];
293// __monitor[0] = 0;
294// __numThreads = numThreads;
295// __resultReady = false;
296// }
297
298 /** Starts the timer when all the threads are ready to start. */
299// public void start() {
300// synchronized(__monitor) {
301// if(++__monitor[0] >= __numThreads) {
302// __begin = System.currentTimeMillis();
303// __monitor.notifyAll();
304// } else {
305// while(true) {
306// try {
307// __monitor.wait();
308// } catch(InterruptedException e) {
309// continue;
310// }
311// break;
312// }
313// }
314// }
315// }
316
317 /** Stops the timer when the last thread is done. */
318// public void stop() {
319// synchronized(__monitor) {
320// if(--__monitor[0] <= 0) {
321// __end = System.currentTimeMillis();
322// synchronized(this) {
323// __resultReady = true;
324// notify();
325// }
326// }
327// }
328//}/
329
330 /** Calling thread waits until timing result is ready. */
331// public synchronized void waitForResult() {
332// while(!__resultReady) {
333// try {
334/// wait();
335// } catch(InterruptedException e) {
336// }
337// }
338// __resultReady = false;
339//}
340//
341///** Returns elapsed time in milliseconds. */
342//public long getElapsedTime() {
343// return (__end - __begin);
344//}
345// }
346//
347 /** Wraps a thread so it can be timed with a group. */
348// public static class TimingWrapper implements Runnable {
349// private Runnable __runMe;
350//private ThreadTimer __timer;
351
352// public TimingWrapper(Runnable runMe, ThreadTimer timer) {
353// __runMe = runMe;
354// __timer = timer;
355//}
356
357//public void run() {
358// // Note, this timing approach does not measure thread creation
359// // and thread joining overhead.
360// __timer.start();
361// __runMe.run();
362// __timer.stop();
363//}
364// }
365
366
367//public static final int NUM_THREADS = 10;
368//public static final int NUM_LOOPS = 10000000;
369
370// public static void main(String[] args) {
371//int thread;
372//ThreadTimer timer;
373//
374// timer = new ThreadTimer(NUM_THREADS);
375
376 // Start a number of threads that iterate a dummy loop
377// for(thread = 0; thread < NUM_THREADS; thread++)
378// new Thread(new TimingWrapper(new Runnable() {
379// public void run() {
380// for(int i=0; i < NUM_LOOPS; i++);
381// }
382// }, timer)).start();
383//
384//timer.waitForResult();
385
386// System.out.println("Elapsed Seconds: " +
387// ((double)timer.getElapsedTime())/1000.0);
388// }
389
390//}*/
Note: See TracBrowser for help on using the repository browser.