|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.hd.d.pg2k.webSvr.exhibit.ExhibitServlet
public final class ExhibitServlet
This is the servlet that serves exhibit data. This is optimised to serve large quantities of binary data efficiently, and to get headers right to optimise performance of caches, spiders, etc, while not losing site of usage logging.
This expects to be loaded when the whole Web application starts and remain there until the Web application shuts down, and so creates and destroys the data pipeline as a side-effect.
| Field Summary | |
|---|---|
private static int |
DEFAULT_BUF_SIZE
Default transfer buffer size; chosen to be efficient but not huge. |
private static boolean |
ENABLE_READAHEAD
If true then enable async read-ahead for large exhibits where throughput is low. |
private boolean |
initialised
Private to init(); ensure exactly-once semantics for init(). |
private static int |
MIN_BLOCKS_FOR_READAHEAD
Minimum number of blocks to consider using async read-ahead; strictly positive. |
static boolean |
ONLY_DESTROYED_ON_SHUTDOWN
True if we know that this servlet is only unloaded when the site is brought down. |
private static byte[] |
QUEUE_POISON
Can be inserted into the data queue by the async thread to force the foreground thread to quit. |
private static long |
serialVersionUID
Unique Serialisation class ID generated by http://random.hd.org/. |
| Constructor Summary | |
|---|---|
ExhibitServlet()
|
|
| Method Summary | |
|---|---|
void |
destroy()
Shut down gracefully. |
void |
doAction(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
boolean isHEAD)
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. |
private static DataSourceBean |
getDataSource(javax.servlet.ServletConfig config,
javax.servlet.http.HttpServletRequest request)
Get singleton (per-servlet-context) data pipeline/cache instance. |
long |
getLastModified(javax.servlet.http.HttpServletRequest request)
Get `last-modified' time for exhibit. |
void |
init(javax.servlet.ServletConfig config)
Retrieve some important configuration data and cache it away. |
private static byte[] |
readNextBlock(long startTime,
java.nio.ByteBuffer buffer,
java.util.concurrent.ArrayBlockingQueue<byte[]> byteBufs,
DataSourceBean ds,
ExhibitStaticAttr esa,
int start,
javax.servlet.ServletContext servletContext,
javax.servlet.ServletOutputStream os)
Read the next block of data from the exhibit using the given buffer returning it as a byte[]; never null nor zero-length. |
| Methods inherited from class javax.servlet.http.HttpServlet |
|---|
doDelete, doOptions, doPost, doPut, doTrace, 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 |
|---|
private static final int DEFAULT_BUF_SIZE
public static final boolean ONLY_DESTROYED_ON_SHUTDOWN
private boolean initialised
private static final boolean ENABLE_READAHEAD
private static final int MIN_BLOCKS_FOR_READAHEAD
private static final byte[] QUEUE_POISON
private static final long serialVersionUID
| Constructor Detail |
|---|
public ExhibitServlet()
| Method Detail |
|---|
public void destroy()
destroy in interface javax.servlet.Servletdestroy in class javax.servlet.GenericServlet
private static DataSourceBean getDataSource(javax.servlet.ServletConfig config,
javax.servlet.http.HttpServletRequest request)
public void init(javax.servlet.ServletConfig config)
throws javax.servlet.ServletException
init in interface javax.servlet.Servletinit in class javax.servlet.GenericServletjavax.servlet.ServletException
public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws java.io.IOException
doGet in class javax.servlet.http.HttpServletrequest - The servlet request we are processingresponse - The servlet response we are producing
java.io.IOException - if an input/output error occurs
public void doHead(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws java.io.IOException
doHead in class javax.servlet.http.HttpServletrequest - The servlet request we are processingresponse - The servlet response we are producing
java.io.IOException - if an input/output error occurs
public void doAction(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
boolean isHEAD)
throws java.io.IOException
If an exhibit is requested by a syntactically-invalid name, we produce an HTTP `forbidden' (403) response.
If we request an exhibit with a valid name, but that does not exist, return return a `non found' (404) response (unless there are no exhibits available, perhaps because of a database problem, in which case we may return `service unavailable' in the hope that that will prevent search engines from purging our exhibits if they happen to visit when we are reloading the database).
We refuse to deal with some dubious requests (eg apparently links directly to our exhibits from external sites) if we are too busy, or if this server is marked as slow/expensive, so as to conserve resources for bona fide users. Dubious requests are rejected with a temporary failure (5xx) code or a redirection to an alternate URL.
Were we observe poor throughput due to excessive time in data fetches then we may switch to an asynchronous read-ahead mode.
TODO:
request - The servlet request we are processingresponse - The servlet response we are producing
java.io.IOException - if an input/output error occurs
private static byte[] readNextBlock(long startTime,
java.nio.ByteBuffer buffer,
java.util.concurrent.ArrayBlockingQueue<byte[]> byteBufs,
DataSourceBean ds,
ExhibitStaticAttr esa,
int start,
javax.servlet.ServletContext servletContext,
javax.servlet.ServletOutputStream os)
throws java.io.IOException,
java.lang.InterruptedException
os - if non-null may be used to flush() data down to the user;
not safe to call from any thread other than the servlet threadbyteBufs - source of recycled byte buffers that we can use rather than using new,
we freely discard anything we find that isn't suitable for our purposes; never null
java.io.IOException
java.lang.InterruptedExceptionpublic final long getLastModified(javax.servlet.http.HttpServletRequest request)
If returning a last-modified value causes difficulty (eg with Tomcat 4.0.1) then we return -1.
getLastModified in class javax.servlet.http.HttpServletrequest - The servlet request we are processing
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||