KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bluecubs > xinco > server > XincoCronServlet


1 /**
2  *Copyright 2006 blueCubs.com
3  *
4  *Licensed under the Apache License, Version 2.0 (the "License");
5  *you may not use this file except in compliance with the License.
6  *You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *Unless required by applicable law or agreed to in writing, software
11  *distributed under the License is distributed on an "AS IS" BASIS,
12  *WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *See the License for the specific language governing permissions and
14  *limitations under the License.
15  *
16  *************************************************************
17  * This project supports the blueCubs vision of giving back
18  * to the community in exchange for free software!
19  * More information on: http://www.bluecubs.org
20  *************************************************************
21  *
22  * Name: XincoCronServlet
23  *
24  * Description: cronjob servlet
25  *
26  * Original Author: Alexander Manes
27  * Date: 2005/01/17
28  *
29  * Modifications:
30  *
31  * Who? When? What?
32  * - - -
33  *
34  *************************************************************
35  */

36
37 package com.bluecubs.xinco.server;
38
39 import java.io.*;
40 import javax.servlet.*;
41 import javax.servlet.http.*;
42 import com.bluecubs.xinco.archive.*;
43 import com.bluecubs.xinco.index.*;
44 import com.bluecubs.xinco.core.server.XincoDBManager;
45
46 public class XincoCronServlet extends HttpServlet {
47     
48     //single instance of archiving thread
49
XincoArchiveThread xat = null;
50     
51     //single instance of index optimizing thread
52
XincoIndexOptimizeThread xiot = null;
53     
54     /** Initializes the servlet.
55      */

56     public void init(ServletConfig config) throws ServletException {
57         super.init(config);
58         
59         //init archiving thread
60
xat = XincoArchiveThread.getInstance();
61         xat.start();
62         
63         //init index optimizing thread
64
xiot = XincoIndexOptimizeThread.getInstance();
65         xiot.start();
66     }
67     
68     /** Destroys the servlet.
69      */

70     public void destroy() {
71     }
72     
73     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
74      * @param request servlet request
75      * @param response servlet response
76      */

77     protected synchronized void processRequest(HttpServletRequest request, HttpServletResponse response)
78     throws ServletException, IOException {
79             
80         //start output
81
response.setContentType("text/html");
82         PrintWriter out = response.getWriter();
83         
84         //show header
85
out.println("<html>");
86         out.println("<head>");
87         out.println("<title>XincoCron</title>");
88         out.println("<link rel=\"stylesheet\" HREF=\"xincostyle.css\" type=\"text/css\"/>");
89         out.println("</head>");
90
91         out.println("<body>");
92         out.println("<center>");
93         out.println("<span class=\"text\">");
94                 
95         out.println("");
96
97         //show info
98
out.println("<br>");
99         out.println("<table border=\"0\" width=\"750\" cellspacing=\"10\" cellpadding=\"0\">");
100         out.println("<tr>");
101         out.println("<td class=\"text\" width=\"100\"><img SRC=\"blueCubsSmall.gif\" border=\"0\"/></td>");
102         out.println("<td class=\"bigtext\" width=\"650\">XincoCron</td>");
103         out.println("</tr>");
104         out.println("</table>");
105         out.println("<br><br>");
106         out.println("<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\">");
107         out.println("<tr>");
108         out.println("<td class=\"text\" colspan=\"3\">XincoCron initializes and runs services for the xinco DMS web application.</td>");
109         out.println("</tr>");
110         out.println("<tr>");
111         out.println("<td class=\"text\" colspan=\"3\">&nbsp;</td>");
112         out.println("</tr>");
113         out.println("<tr>");
114         out.println("<td class=\"text\" colspan=\"3\"><b>General Status:</b></td>");
115         out.println("</tr>");
116         out.println("<tr>");
117         out.println("<td class=\"text\">Open DB-Connections:</td>");
118         out.println("<td class=\"text\">" + XincoDBManager.count + "</td>");
119         out.println("<td class=\"text\">&nbsp;</td>");
120         out.println("</tr>");
121         out.println("<tr>");
122         out.println("<td class=\"text\" colspan=\"3\">&nbsp;</td>");
123         out.println("</tr>");
124         out.println("<tr>");
125         out.println("<td class=\"text\"><b>Service Name:</b></td>");
126         out.println("<td class=\"text\"><b>First Run:</b></td>");
127         out.println("<td class=\"text\"><b>Last Run:</b></td>");
128         out.println("</tr>");
129
130         out.println("<tr>");
131         out.println("<td class=\"text\">Archiver</td>");
132         String JavaDoc xat_first_run = "";
133         String JavaDoc xat_last_run = "";
134         if (xat != null) {
135             if (xat.firstRun != null) {
136                 xat_first_run = xat.firstRun.getTime().toString();
137             }
138             if (xat.lastRun != null) {
139                 xat_last_run = xat.lastRun.getTime().toString();
140             }
141         }
142         out.println("<td class=\"text\">" + xat_first_run + "</td>");
143         out.println("<td class=\"text\">" + xat_last_run + "</td>");
144         out.println("</tr>");
145
146         out.println("<tr>");
147         out.println("<td class=\"text\">Index Optimizer</td>");
148         String JavaDoc xiot_first_run = "";
149         String JavaDoc xiot_last_run = "";
150         if (xat != null) {
151             if (xiot.firstRun != null) {
152                 xiot_first_run = xiot.firstRun.getTime().toString();
153             }
154             if (xiot.lastRun != null) {
155                 xiot_last_run = xiot.lastRun.getTime().toString();
156             }
157         }
158         out.println("<td class=\"text\">" + xiot_first_run + "</td>");
159         out.println("<td class=\"text\">" + xiot_last_run + "</td>");
160         out.println("</tr>");
161
162         out.println("</table>");
163
164         //show footer
165
out.println("<br><br><br>");
166         out.println("<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\">");
167         out.println("<tr>");
168         out.println("<td class=\"text\">&nbsp;</td>");
169         out.println("<td class=\"text\">&copy; 2004-2006, <a HREF=\"http://www.bluecubs.com\" target=\"_blank\" class=\"link\">blueCubs.com</a> and <a HREF=\"http://www.xinco.org\" target=\"_blank\" class=\"link\">xinco.org</a></td>");
170         out.println("</tr>");
171         out.println("</table>");
172     
173         out.println("</span>");
174         out.println("</center>");
175         out.println("</body>");
176         out.println("</html>");
177
178         out.close();
179         
180     }
181     
182     /** Handles the HTTP <code>GET</code> method.
183      * @param request servlet request
184      * @param response servlet response
185      */

186     protected void doGet(HttpServletRequest request, HttpServletResponse response)
187     throws ServletException, IOException {
188         processRequest(request, response);
189     }
190     
191     /** Handles the HTTP <code>POST</code> method.
192      * @param request servlet request
193      * @param response servlet response
194      */

195     protected void doPost(HttpServletRequest request, HttpServletResponse response)
196     throws ServletException, IOException {
197         processRequest(request, response);
198     }
199     
200     /** Returns a short description of the servlet.
201      */

202     public String JavaDoc getServletInfo() {
203         return "Servlet of xinco";
204     }
205     
206 }
207
Popular Tags