org.perf4j.servlet
Class AbstractGraphingServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.perf4j.servlet.AbstractGraphingServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
GraphingServlet, GraphingServlet

public abstract class AbstractGraphingServlet
extends javax.servlet.http.HttpServlet

This servlet class serves as the base class for displaying performance charts in a web environment. This class sets up the framework for sending the HTML response. Subclasses are only responsible for determining how to find the graphs to display by implementing the getGraphByName and getAllKnownGraphNames methods.

Author:
Alex Devine
See Also:
Serialized Form

Field Summary
protected  List<String> graphNames
          Setting an init parameter "graphNames" to a comma-separated list of the names of graphs to display by default sets this member variable.
 
Constructor Summary
AbstractGraphingServlet()
           
 
Method Summary
 void destroy()
           
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected abstract  List<String> getAllKnownGraphNames()
          Subclasses should implement this method to return a list of all possible known graph names.
protected  Map<String,StatisticsChartGenerator> getChartGeneratorsToDisplay(javax.servlet.http.HttpServletRequest request)
          Helper method generates the list of charts that are to be displayed in this call to the servlet.
protected abstract  StatisticsChartGenerator getGraphByName(String name)
          Subclasses should implement this method to return a chart generator by its name.
 void init()
           
protected  void writeChart(String name, StatisticsChartGenerator chartGenerator, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Helper method writes the chart to the page using an img tag.
protected  void writeFooter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Helper method writes the HTML footer, closing the body and HTML tags.
protected  void writeHeader(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Helper method writes the HTML header, everything up to the opening body tag.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

graphNames

protected List<String> graphNames
Setting an init parameter "graphNames" to a comma-separated list of the names of graphs to display by default sets this member variable. Subclass implementations determine how graphs are named. For example, the GraphingServlet uses the names of GraphingStatisticsAppenders to determine which graphs to show.

Constructor Detail

AbstractGraphingServlet

public AbstractGraphingServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException,
                     IOException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

doPost

protected void doPost(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws javax.servlet.ServletException,
                      IOException
Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

writeHeader

protected void writeHeader(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
                    throws javax.servlet.ServletException,
                           IOException
Helper method writes the HTML header, everything up to the opening body tag. Subclasses may wish to override.

Throws:
javax.servlet.ServletException
IOException

writeChart

protected void writeChart(String name,
                          StatisticsChartGenerator chartGenerator,
                          javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
                   throws javax.servlet.ServletException,
                          IOException
Helper method writes the chart to the page using an img tag. Subclasses may wish to override.

Parameters:
name - the name of the chart to write
chartGenerator - the chart generator responsible for creating the chart URL
request - the incoming servlet request
response - the servlet respone
Throws:
javax.servlet.ServletException
IOException

writeFooter

protected void writeFooter(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
                    throws javax.servlet.ServletException,
                           IOException
Helper method writes the HTML footer, closing the body and HTML tags. Subclasses may wish to override.

Throws:
javax.servlet.ServletException
IOException

getChartGeneratorsToDisplay

protected Map<String,StatisticsChartGenerator> getChartGeneratorsToDisplay(javax.servlet.http.HttpServletRequest request)
Helper method generates the list of charts that are to be displayed in this call to the servlet. In general subclasses should not need to override this method.

Parameters:
request - The incoming request, which may contain a list of "graphName" parameters, in which case those graphs will be displayed
Returns:
A map of graph name to the chart generator capable of creating the URL for the graph.

getGraphByName

protected abstract StatisticsChartGenerator getGraphByName(String name)
Subclasses should implement this method to return a chart generator by its name. Subclasses may use any method necessary to find the underlying repository of charts.

Parameters:
name - the name of the graph to return
Returns:
the chart generator capable of creating the requested chart.

getAllKnownGraphNames

protected abstract List<String> getAllKnownGraphNames()
Subclasses should implement this method to return a list of all possible known graph names.

Returns:
The list of possible graph names for which getGraphByName will return a valid chart generator.


Copyright © 2008-2011 perf4j.org. All Rights Reserved.