1 | |
package org.paneris.jammyjoes.upload; |
2 | |
|
3 | |
import java.io.IOException; |
4 | |
import java.io.PrintWriter; |
5 | |
import java.util.Date; |
6 | |
|
7 | |
import javax.servlet.Servlet; |
8 | |
import javax.servlet.ServletConfig; |
9 | |
import javax.servlet.ServletException; |
10 | |
import javax.servlet.ServletRequest; |
11 | |
import javax.servlet.ServletResponse; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | 0 | public class WardenLauncher implements Servlet { |
18 | |
|
19 | |
private ServletConfig config; |
20 | 0 | Thread warden = null; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public void init(ServletConfig config) throws ServletException { |
30 | 0 | System.err.println(new Date() + " Starting the JammyJoes WardenLauncher"); |
31 | 0 | this.config = config; |
32 | |
|
33 | |
|
34 | 0 | if (warden==null) { |
35 | 0 | Warden war = new Warden(this); |
36 | 0 | warden = new Thread(war, "warden"); |
37 | 0 | warden.start(); |
38 | |
} |
39 | 0 | } |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public void destroy() { |
50 | |
|
51 | 0 | } |
52 | |
|
53 | |
public ServletConfig getServletConfig() { |
54 | 0 | return config; |
55 | |
} |
56 | |
|
57 | |
public String getServletInfo() { |
58 | 0 | return "A servlet to launch a warden thread. This warden uploads "+ |
59 | |
"data to ecentives every 24 hours."; |
60 | |
} |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public void service(ServletRequest req, ServletResponse resp) |
68 | |
throws ServletException, IOException { |
69 | |
|
70 | |
|
71 | |
|
72 | 0 | resp.setContentType("text/html"); |
73 | 0 | PrintWriter out = resp.getWriter(); |
74 | 0 | out.println("The warden thread "+ |
75 | |
((warden!=null)?" is launched":" is not launched") |
76 | |
); |
77 | 0 | out.close(); |
78 | 0 | } |
79 | |
|
80 | |
} |