1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.goetz.domino.log4j.config;
18
19 import java.io.File;
20 import java.util.Date;
21 import java.util.Timer;
22 import java.util.TimerTask;
23
24 import javax.servlet.ServletConfig;
25 import javax.servlet.ServletException;
26 import javax.servlet.http.HttpServlet;
27
28 import org.apache.log4j.helpers.LogLog;
29
30 /***
31 * Controller for the sample application.
32 *
33 * @author Bernd G?tz
34 * @deprecated in favour of file change notification.
35 */
36 public class Log4JReloadServlet extends HttpServlet {
37
38 ServerThread t;
39 int port = 0;
40 int delay = DEFAULTDELAY;
41
42 static int DEFAULTDELAY = 60000*5;
43
44 public void init(ServletConfig config) throws ServletException {
45
46 super.init(config);
47
48 String logj4ConfigDir = config.getInitParameter("configdir");
49 String portStr = config.getInitParameter("port");
50 if ((portStr != null) && (portStr.length() > 0)) {
51 port = new Integer(portStr).intValue();
52 }
53 String delayStr = config.getInitParameter("delay");
54 if ((delayStr != null) && (delayStr.length() > 0)) {
55 delay = new Integer(delayStr).intValue();
56 }
57
58
59
60
61 if (port != 0) {
62 LogLog.debug("Starting the listener thread...");
63 t = new ServerThread("Log4jReload", port, logj4ConfigDir);
64 t.setDaemon(true);
65 t.start();
66 LogLog.debug("Listener thread successfully started");
67 } else {
68 LogLog.debug("Starting file watcher...");
69 File f = new File(logj4ConfigDir +
70 File.separator + "log4j.properties");
71 if (!f.exists()) {
72 System.out.println("Could not initialize file watcher - file: " +
73 f.getName());
74 }
75 TimerTask task = new ConfigFileWatcher(f);
76 Timer t = new Timer();
77 t.schedule(task, new Date(), delay);
78 LogLog.debug("File watcher successfully started");
79 }
80
81 }
82
83 public void destroy() {
84 LogLog.debug("super.destroy");
85 super.destroy();
86 LogLog.debug("Destroy log4j reload servlet");
87 if (port != 0) {
88 if (t != null) {
89 LogLog.debug("Calling done on thread");
90 t.done();
91 LogLog.debug("Done called");
92 t = null;
93 }
94 }
95 }
96
97 }