source: main/trunk/gli/src/org/greenstone/gatherer/DebugStream.java@ 31831

Last change on this file since 31831 was 31692, checked in by ak19, 7 years ago

Major changes to SafeProcess and classes of the download package, by bringing the final GLI (and final Greenstone) class DownloadJob over to use SafeProcess. Significant changes to SafeProcess: 1. Introduction of cancelRunningProcess as a new method, so that callers don't need to know how cancelling a process is implemented (as an interrupt) nor do they need to know what thread they ought to interrupt (which should be the thread that launched SafeProcess), nor do they need to know of the complexity surrounding the join() blocking call which should not be interrupted. 2. Introduction of the SafeProcess.MainHandler interface that provides methods that allow implementers to write hooks to various stages of the SafeProcess' internal process' life cycle. 3. moved process cleanUp() code into a reusable method within SafeProcess. Significant changes to DownloadJob and its associated DownloadProgressBar and DownloadScrollPane classes: 1. Unused member vars removed or commented out and those that can be declared final are now declared so, as a programming pricinple for thread safety, since DownloadJob and the other download classes will have to interact with multiple threads and could be called by different threads. 2. Replaced existing actionPerformed() and callDownload() of DownloadJob with SafeProcess and implemented the necessary Hooks in the SafeProcess.MainHandler() interface to ensure that perl is still told to terminate wget on a cancel action. 3. Replaced DownloadScrollPane's deleteDownloadJob() with a new version that now more responsively removes its DownloadProgressBar (with controls) for a DownloadJob. It's called by the SafeProcess.MainHandler interface hooks implemented by DownloadJob, so DownloadScrollPane no longer needs to wait() to be notify()ed when a process has cleaned up on premature termination by a cancel action. 4. Made the necessary methods in DownloadProgressBar synchronized for thread safety. 5. GShell now uses SafeProcess' new cancelRunningProcess() method in place of directly calling interrupt on the (GShell) thread that launched SafeProcess.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/**
2 *############################################################################
3 * A component of the Greenstone Librarian Interface, part of the Greenstone
4 * digital library suite from the New Zealand Digital Library Project at the
5 * University of Waikato, New Zealand.
6 *
7 * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ
8 *
9 * Copyright (C) 2004 New Zealand Digital Library Project
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *############################################################################
25 */
26
27package org.greenstone.gatherer;
28
29
30import java.io.*;
31import java.util.*;
32
33
34public class DebugStream
35{
36 static private boolean debugging_enabled = false;
37 static private PrintStream debug_stream = null;
38
39
40 static public void closeDebugStream()
41 {
42 if (debug_stream != null) {
43 try {
44 debug_stream.flush();
45 debug_stream.close();
46 }
47 catch (Exception exception) {
48 exception.printStackTrace();
49 }
50 }
51 }
52
53
54 static public void enableDebugging()
55 {
56 debugging_enabled = true;
57 }
58
59
60 static synchronized public boolean isDebuggingEnabled()
61 {
62 return debugging_enabled;
63 }
64
65
66 static synchronized public void print(Properties properties)
67 {
68 if (debugging_enabled) {
69 if (debug_stream != null) {
70 properties.list(debug_stream);
71 }
72 properties.list(System.err);
73 }
74 }
75
76
77 /** Print a message to the debug stream. */
78 static synchronized public void print(String message)
79 {
80 if (debugging_enabled) {
81 if (debug_stream != null) {
82 debug_stream.print(message);
83 }
84 System.err.print(message);
85 }
86 }
87
88
89 /** Print a message to the debug stream. */
90 static synchronized public void println(String message)
91 {
92 if (debugging_enabled) {
93 if (debug_stream != null) {
94 debug_stream.println(message);
95 }
96 System.err.println(message);
97 }
98 }
99
100
101 /** Print a stack trace to the debug stream, and always to STDERR. */
102 static synchronized public void printStackTrace(Exception exception)
103 {
104 if (debugging_enabled && debug_stream != null) {
105 exception.printStackTrace(debug_stream);
106 }
107 exception.printStackTrace();
108 }
109
110
111 static public void setDebugFile(String debug_file_path)
112 {
113 try {
114 debug_stream = new PrintStream(new FileOutputStream(debug_file_path));
115 }
116 catch (Exception exception) {
117 exception.printStackTrace();
118 }
119 }
120}
Note: See TracBrowser for help on using the repository browser.