KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > org > primrose > vendor > websphere > BindPrimroseServlet


1 package uk.org.primrose.vendor.websphere;
2
3 /**
4 * Library name : Primrose - A Java Database Connection Pool.
5 * Published by Ben Keeping, http://primrose.org.uk .
6 * Copyright (C) 2004,2005 Ben Keeping, primrose.org.uk
7 * Email: Use "Contact Us Form" on website
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */

23
24
25 import java.io.*;
26 import javax.servlet.http.*;
27 import javax.servlet.*;
28 import javax.naming.*;
29 import uk.org.primrose.pool.jmx.PoolController;
30 import uk.org.primrose.pool.jmx.MBeanUtil;
31
32 public class BindPrimroseServlet extends HttpServlet {
33     static PoolController pc;
34
35     public void init() throws ServletException {
36
37         // Because this servlet may be init()'d more than once,
38
// we need to test if a pool is already started.
39
// If the ctx lookup returns false, or barfs, we load the pool.
40
boolean load = false;
41         try {
42             Context ctx = new InitialContext();
43             Object JavaDoc o = MBeanUtil.lookup("pool");
44             if (o == null) {
45                 load = true;
46             }
47         } catch (Exception JavaDoc e) {
48             load = true;
49             e.printStackTrace(System.err);
50         }
51
52
53         if (load) {
54
55             pc = new PoolController();
56
57             String JavaDoc poolConfigFile = getServletConfig().getInitParameter("poolConfigFile");
58             if (poolConfigFile == null) {
59                 System.err.println("Cannot find entry for poolConfigFile in web.xml init-param for BindPrimroseServlet.\nExiting. \nShould be :");
60                 System.err.println("<servlet>");
61                 System.err.println("\t<servlet-name>BindPrimroseServlet</servlet-name>");
62                 System.err.println("\t<servlet-class>uk.org.primrose.vendor.websphere.BindPrimroseServlet</servlet-class>");
63                 System.err.println("\t<init-param>");
64                 System.err.println("\t\t<param-name>poolConfigFile</param-name>");
65                 System.err.println("\t\t<param-value>//path/to/poolConfig.properties</param-value>");
66                 System.err.println("\t</init-param>");
67             }
68
69             String JavaDoc poolConfig = null;
70             if (new File(poolConfigFile).exists()) {
71                 poolConfig = poolConfigFile;
72             } else {
73                 System.err.println("[Primnrose] The given poolConfig file '" +poolConfigFile +"' does not exist - cannot load primrose");
74             }
75
76             pc.setPoolConfigFile(poolConfig);
77
78             pc.init(new String JavaDoc[]{});
79
80             try {
81                 // Load the pool info from the config file, and fill the pool queues
82
pc.loadPoolsFromConfigFile(poolConfig, true);
83             } catch (IOException ioe) {
84                 ioe.printStackTrace(System.err);
85             }
86         }
87
88
89     }
90
91     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
92     response.getWriter().println("Primnrose running ... " +pc);
93     }
94
95    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
96     doGet(request, response);
97     }
98
99
100     public void destroy() {
101         pc.destroy();
102     }
103 }
Popular Tags