001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.servlets;
006:
007: import org.geotools.data.jdbc.ConnectionPoolManager;
008: import java.util.logging.Logger;
009: import javax.servlet.ServletException;
010: import javax.servlet.http.HttpServlet;
011: import javax.servlet.http.HttpServletRequest;
012: import javax.servlet.http.HttpServletResponse;
013:
014: /**
015: * Initializes all logging functions.
016: *
017: * @author Rob Hranac, Vision for New York
018: * @author Chris Holmes, TOPP
019: * @version $Id: FreefsLog.java 7746 2007-11-13 15:38:35Z aaime $
020: */
021: public class FreefsLog extends HttpServlet {
022: /** Standard logging instance for class */
023: private static final Logger LOGGER = org.geotools.util.logging.Logging
024: .getLogger("org.vfny.geoserver.servlets");
025:
026: /** Default name for configuration directory */
027: private static final String CONFIG_DIR = "data/";
028:
029: /**
030: * Initializes logging and config.
031: *
032: * @throws ServletException DOCUMENT ME!
033: */
034: public void init() throws ServletException {
035: //configure log4j, since console logging is configured elsewhere
036: // we deny all logging, this is really just to prevent log4j
037: // initilization warnings
038: // TODO: this is a hack, log config should be cleaner
039:
040: //JD: Commenting out
041: // ConsoleAppender appender = new ConsoleAppender(new PatternLayout());
042: // appender.addFilter(new DenyAllFilter());
043: //
044: // BasicConfigurator.configure(appender);
045: //
046: //HACK: java.util.prefs are awful. See
047: //http://www.allaboutbalance.com/disableprefs. When the site comes
048: //back up we should implement their better way of fixing the problem.
049: System.setProperty("java.util.prefs.syncInterval", "5000000");
050: }
051:
052: /**
053: * Initializes logging.
054: *
055: * @param req The servlet request object.
056: * @param res The servlet response object.
057: */
058: public void doGet(HttpServletRequest req, HttpServletResponse res) {
059: //BasicConfigurator.configure();
060: }
061:
062: /**
063: * Closes down the zserver if it is running, and frees up resources.
064: *
065: * @task REVISIT: what we should consider is having geotools provide a
066: * nicer way to clean up datastores's resources, something like a
067: * close, so that we could just iterate through all the datastores
068: * calling close. Once that's done we can clean up this method a
069: * bit.
070: */
071: public void destroy() {
072: super .destroy();
073: ConnectionPoolManager.getInstance().closeAll();
074:
075: /*
076: HACK: we must get a standard API way for releasing resources...
077: */
078: try {
079: Class sdepfClass = Class
080: .forName("org.geotools.data.arcsde.ConnectionPoolFactory");
081:
082: LOGGER.fine("SDE datasource found, releasing resources");
083:
084: java.lang.reflect.Method m = sdepfClass.getMethod(
085: "getInstance", new Class[0]);
086: Object pfInstance = m.invoke(sdepfClass, new Object[0]);
087:
088: LOGGER.fine("got sde connection pool factory instance: "
089: + pfInstance);
090:
091: java.lang.reflect.Method closeMethod = pfInstance
092: .getClass().getMethod("closeAll", new Class[0]);
093:
094: closeMethod.invoke(pfInstance, new Object[0]);
095: LOGGER
096: .info("just asked SDE datasource to release connections");
097: } catch (ClassNotFoundException cnfe) {
098: LOGGER.fine("No SDE datasource found");
099: } catch (Exception ex) {
100: ex.printStackTrace();
101: }
102: }
103: }
|