com.faa.flyfaa
Class FlyFAAPoolServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--com.faa.flyfaa.FlyFAAPoolServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class FlyFAAPoolServlet
extends javax.servlet.http.HttpServlet

FlyFAAPoolServlet is the start-up servlet for the flyFAA Java application. The init method reads configuration properties from a properties file and calls the createConnectionPool method and the createCacheImpl method to create a pool of pooled-connections. The service method accesses the ois_program table and displays all the active Ground Delay Programs. A small enhancement to the service method added a call to the getServletInfo method.

Author:
Jeffrey H. Carroll
See Also:
Serialized Form

Field Summary
private  java.lang.String dbDriver
          The type of drivers to be used (thin or thick).
static java.lang.String DOCTYPE
          A String specifying which level of HTML a document purports to be written in
private static java.util.Properties flyProps
          The properties file for the flyfaa java application.
private static java.lang.String jdbcLogFile
          Contains the name of the base log file from the properties file.
private  oracle.jdbc.pool.OracleConnectionPoolDataSource l_ocpds
          The source of the database connection pool.
protected static javax.sql.PooledConnection m_connectionPool
          The pool of connections
(package private)  boolean MadeLog
          Flag to let me know whether the log file has been created.
private static oracle.jdbc.pool.OracleConnectionCacheImpl ocacheimpl
          The pool of Pooled Connections
private  oracle.jdbc.pool.OracleConnectionEventListener ocel
          An object that registers to receive events generated by a PooledConnection
private  java.io.PrintWriter out
          A printWriter for the log.
private  java.util.Timer t
          A Timer object to hold a reference to the Timer used to schedule the DatabaseUpdater
 
Fields inherited from class javax.servlet.http.HttpServlet
HEADER_IFMODSINCE, HEADER_LASTMOD, LSTRING_FILE, lStrings, METHOD_DELETE, METHOD_GET, METHOD_HEAD, METHOD_OPTIONS, METHOD_POST, METHOD_PUT, METHOD_TRACE
 
Fields inherited from class javax.servlet.GenericServlet
config
 
Constructor Summary
FlyFAAPoolServlet()
           
 
Method Summary
private  void createCacheImpl()
           
private  void createConnectionPool()
          Creates a Database Connection Pool (Also called Pooled Connection) using JDBC 2.0 API.
private  java.lang.String CreateLog()
          Creates a new PrintWriter, constructing the filename from the flyfaalogfile property and a date/time string of the form yyyy_MMMddHHmm, for writing log messages.
 void destroy()
          Destroys the servlet.
 java.lang.String getServletInfo()
          Overrides the getServletInfo() method which is supposed to return basic information about the Servlet.
static java.lang.String headWithTitle(java.lang.String title)
          Returns an HTML string containing a document title suitable for use at the beginning of a webpage.
 void init(javax.servlet.ServletConfig config)
          Initializes the servlet.
private  void logging(java.lang.String msg)
          Writes a message to the log file prefixed by a date/timestamp.
private  void logging(java.lang.Throwable t, java.lang.String msg)
          Writes a message to the log file including an exception.
 void service(javax.servlet.http.HttpServletRequest p_req, javax.servlet.http.HttpServletResponse p_res)
          This method is called whenever this servlet is invoked.
 
Methods inherited from class javax.servlet.http.HttpServlet
, doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getAllDeclaredMethods, getLastModified, maybeSetLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_connectionPool

protected static javax.sql.PooledConnection m_connectionPool
The pool of connections

out

private java.io.PrintWriter out
A printWriter for the log.

jdbcLogFile

private static java.lang.String jdbcLogFile
Contains the name of the base log file from the properties file.

MadeLog

boolean MadeLog
Flag to let me know whether the log file has been created.

l_ocpds

private oracle.jdbc.pool.OracleConnectionPoolDataSource l_ocpds
The source of the database connection pool.

ocacheimpl

private static oracle.jdbc.pool.OracleConnectionCacheImpl ocacheimpl
The pool of Pooled Connections

ocel

private oracle.jdbc.pool.OracleConnectionEventListener ocel
An object that registers to receive events generated by a PooledConnection

flyProps

private static java.util.Properties flyProps
The properties file for the flyfaa java application.

dbDriver

private java.lang.String dbDriver
The type of drivers to be used (thin or thick).

t

private java.util.Timer t
A Timer object to hold a reference to the Timer used to schedule the DatabaseUpdater

DOCTYPE

public static final java.lang.String DOCTYPE
A String specifying which level of HTML a document purports to be written in
Constructor Detail

FlyFAAPoolServlet

public FlyFAAPoolServlet()
Method Detail

headWithTitle

public static java.lang.String headWithTitle(java.lang.String title)
Returns an HTML string containing a document title suitable for use at the beginning of a webpage.
Parameters:
title - The string to be used as the document's title

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Initializes the servlet. The method is called once, automatically, by the iPlanet Web Server when it loads the servlet. The init() method should save the ServletConfig object so that it can be returned by the getServletConfig() method. Here we will get a pooled connection object (or Connection Pool).

Overrides:
init in class javax.servlet.GenericServlet
Parameters:
config - The ServletConfig object passed from the Servlet container
Throws:
javax.servlet.ServletException - If the properties file cannot be found or read, or if the connection pool cache cannot be created

CreateLog

private java.lang.String CreateLog()
                            throws java.lang.NullPointerException
Creates a new PrintWriter, constructing the filename from the flyfaalogfile property and a date/time string of the form yyyy_MMMddHHmm, for writing log messages. If the file cannot be opened, standard error is opened instead.
Returns:
String containing the name of the log file if it was created successfully, or an empty string if it was not.
Throws:
java.lang.NullPointerException - if the flyfaalogfile property does not contain a period

service

public void service(javax.servlet.http.HttpServletRequest p_req,
                    javax.servlet.http.HttpServletResponse p_res)
             throws javax.servlet.ServletException,
                    java.io.IOException
This method is called whenever this servlet is invoked. This servlet is invoked by going to http://<server:port>/flyfaapool/com.faa.flyfaa.FlyFAAPoolServlet

Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
p_req - The HttpServletRequest object representing the user's request.
p_res - The HttpServletResponse object representing the object being used to assist this servlet in sending an HTTP response to the client.
Throws:
javax.servlet.ServletException - if a database access error occurs executing the query
java.io.IOException - because that's what a good service method should do

createConnectionPool

private void createConnectionPool()
                           throws java.sql.SQLException,
                                  java.lang.NullPointerException
Creates a Database Connection Pool (Also called Pooled Connection) using JDBC 2.0 API. Substitute the connection parameters with appropriate values in the properties file as defined by the init method. The log file is created before the connection pool is created, but database connection details in the log are avoided by setting the OracleConnectionPoolDataSource's logWriter to null.

Throws:
java.sql.SQLException - If any of the properties file database connection properties consist solely of white space, that is, the trim method returns a string which is of zero length.
java.lang.NullPointerException - If any of the properties file database connection properties are null, that is, trying to call the trim method on a null string.

createCacheImpl

private void createCacheImpl()
                      throws java.sql.SQLException,
                             java.lang.NumberFormatException

logging

private void logging(java.lang.String msg)
Writes a message to the log file prefixed by a date/timestamp.

Parameters:
msg - The message to be written to the log file.

logging

private void logging(java.lang.Throwable t,
                     java.lang.String msg)
Writes a message to the log file including an exception. The message is prefixed by a date/timestamp.

Parameters:
t - An exception (in general, anything of type Throwable) for which the stack trace will be written to the log file.
msg - A text string to be written to the log file.

getServletInfo

public java.lang.String getServletInfo()
Overrides the getServletInfo() method which is supposed to return basic information about the Servlet. This method returns information about the connection pool cache size.

Overrides:
getServletInfo in class javax.servlet.GenericServlet
Returns:
String - HTML containing some database connection pool cache statistics.

destroy

public void destroy()
Destroys the servlet. This method is called once when the servlet is unloaded. According to the OracleConnectionCache documentation, the listener should be deregistered when closing the PooledConnection, for example:

m_connectionPool.removeConnectionEventListener(ocel); 
Overrides:
destroy in class javax.servlet.GenericServlet