org.hd.d.pg2k.webSvr.bgImg
Class BgImageServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.hd.d.pg2k.webSvr.bgImg.BgImageServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public final class BgImageServlet
extends javax.servlet.http.HttpServlet

Servlet to serve dynamic and partially-random HTML-page background image. This serves a randomly-generated image which we would like to be slightly different for each visitor.

This is intended to be pleasing on the eye, and possible, if required, to read normal black text over. So the image is nearly white with a slowly changing 'watermark' image.

To minimise bandwidth fetching this, and CPU time generating it, this is designed to be served with the "caching" filter in front of it, so that any one user should typically only fetch a new image once per week or thereabouts, though each user should get a different one. Also, the image dimensions and quality are adjusted to those of a "standard" thumbnail, which does not take you lots of space in memory or on the wire.

We may cache the last image generated, so that if the system is busy the last image may be returned again rather than a new one being generated.

See Also:
Serialized Form

Field Summary
private static byte[][] _imageCache
          Simple cache by "seed" value of background images as raw byte[]; each entry is computed on demand.
private static java.lang.Object _imageCacheLock
          Lock for access to _imageCache.
private static long creationTime
          Construction time for this class.
private static int MIN_BGS
          Minimum number of different backgrounds seen; strictly positive.
private static long serialVersionUID
          Unique Serialisation class ID generated by http://random.hd.org/.
 
Constructor Summary
BgImageServlet()
           
 
Method Summary
 void doAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Respond to a GET/HEAD request for the content served by this servlet.
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Respond to a GET request for the content served by this servlet.
 void doHead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Respond to a HEAD request for the content served by this servlet.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

creationTime

private static final long creationTime
Construction time for this class. Used to modify the relationship between client IP address and the background selected.


MIN_BGS

private static final int MIN_BGS
Minimum number of different backgrounds seen; strictly positive. Possibly good if prime to scatter client's more uniformly across the image set.

As this value gets larger, memory consumption will go up.

We set this not to use more than about 1%--2% of total memory, although we may find an abnormally-small heap size during startup when this will get computed.


_imageCache

private static final byte[][] _imageCache
Simple cache by "seed" value of background images as raw byte[]; each entry is computed on demand. This is indexed by a hash on the client's IP address, and caches a background image.

The size of this array determines how many different images we hold, and more will use more memory.

Access the array contents only under the _imageCacheLock.

We vary the size of this array a little on each run to vary the mix. The array size stays constant while the class remains loaded.


_imageCacheLock

private static final java.lang.Object _imageCacheLock
Lock for access to _imageCache.


serialVersionUID

private static final long serialVersionUID
Unique Serialisation class ID generated by http://random.hd.org/.

See Also:
Constant Field Values
Constructor Detail

BgImageServlet

public BgImageServlet()
Method Detail

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws java.io.IOException
Respond to a GET request for the content served by this servlet.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - The servlet request we are processing
response - The servlet response we are producing
Throws:
java.io.IOException - if an input/output error occurs

doHead

public void doHead(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws java.io.IOException
Respond to a HEAD request for the content served by this servlet.

Overrides:
doHead in class javax.servlet.http.HttpServlet
Parameters:
request - The servlet request we are processing
response - The servlet response we are producing
Throws:
java.io.IOException - if an input/output error occurs

doAction

public void doAction(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws java.io.IOException
Respond to a GET/HEAD request for the content served by this servlet. Returns the exhibit data, with a correct MIME type.

Parameters:
request - The servlet request we are processing
response - The servlet response we are producing
Throws:
java.io.IOException - if an input/output error occurs

DHD Multimedia Gallery V1.53.0

Copyright (c) 1996-2009, Damon Hart-Davis. All rights reserved.