changeset 348:af55194647a6

Servlet version 1.5.7b - new max-waiting-threads parameter and handling - DocumentBean also gets real image sizes (for dlInfo-xml et al.)
author robcast
date Fri, 22 Apr 2005 19:16:41 +0200
parents a87e80bfbd47
children bafd7b503d14
files servlet/src/digilib/servlet/Initialiser.java servlet/src/digilib/servlet/Scaler.java
diffstat 2 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/servlet/Initialiser.java	Fri Apr 22 19:16:41 2005 +0200
+++ b/servlet/src/digilib/servlet/Initialiser.java	Fri Apr 22 19:16:41 2005 +0200
@@ -137,6 +137,8 @@
 				int nt = dlConfig.getAsInt("worker-threads");
 				Semaphore lck = new FIFOSemaphore(nt); 
 				DigilibWorker.setLock(lck);
+				int mt = dlConfig.getAsInt("max-waiting-threads");
+				DigilibWorker.setMaxWaitingThreads(mt);
 				// set as the servlets main config
 				context.setAttribute("digilib.servlet.configuration", dlConfig);
 
--- a/servlet/src/digilib/servlet/Scaler.java	Fri Apr 22 19:16:41 2005 +0200
+++ b/servlet/src/digilib/servlet/Scaler.java	Fri Apr 22 19:16:41 2005 +0200
@@ -53,13 +53,13 @@
 /**
  * @author casties
  */
-//public class Scaler extends HttpServlet implements SingleThreadModel {
+// public class Scaler extends HttpServlet implements SingleThreadModel {
 public class Scaler extends HttpServlet {
 
 	private static final long serialVersionUID = -325080527268912852L;
 
 	/** digilib servlet version (for all components) */
-	public static final String dlVersion = "1.5.5b";
+	public static final String dlVersion = "1.5.7b";
 
 	/** logger for accounting requests */
 	private static Logger accountlog = Logger.getLogger("account.request");
@@ -202,7 +202,7 @@
 	}
 
 	/** main request handler. */
-	void processRequest(HttpServletRequest request, HttpServletResponse response)
+void processRequest(HttpServletRequest request, HttpServletResponse response)
 			throws ServletException {
 
 		if (dlConfig == null) {
@@ -315,7 +315,7 @@
 		}
 		// operation mode: "lores": try to use scaled image, "hires": use
 		// unscaled image
-		//   "autores": try best fitting resolution
+		// "autores": try best fitting resolution
 		if (dlRequest.hasOption("mo", "lores")) {
 			loresOnly = true;
 			hiresOnly = false;
@@ -355,7 +355,7 @@
 					: paramDH;
 		}
 
-		//"big" try for all file/image actions
+		// "big" try for all file/image actions
 		try {
 
 			// ImageFileset of the image to load
@@ -478,6 +478,29 @@
 				return;
 			}
 
+			
+			/*
+			 * stop here if we're overloaded...
+			 * 
+			 * 503 Service Unavailable 
+			 * The server is currently unable to
+			 * handle the request due to a temporary overloading or maintenance
+			 * of the server. The implication is that this is a temporary
+			 * condition which will be alleviated after some delay. If known,
+			 * the length of the delay MAY be indicated in a Retry-After header.
+			 * If no Retry-After is given, the client SHOULD handle the response
+			 * as it would for a 500 response. Note: The existence of the 503
+			 * status code does not imply that a server must use it when
+			 * becoming overloaded. Some servers may wish to simply refuse the
+			 * connection.
+			 * (RFC2616 HTTP1.1)
+			 */
+			if (! DigilibWorker.canRun()) {
+				logger.error("Servlet overloaded!");
+				response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+				return;
+			}
+			
 			// set missing dw or dh from aspect ratio
 			float imgAspect = fileToLoad.getAspect();
 			if (paramDW == 0) {
@@ -645,7 +668,6 @@
 					"ERROR: Other Image Operation Error: " + e, response);
 		}
 	}
-
 	/**
 	 * Returns the DocuDirent corresponding to the DigilibRequest.
 	 * 
@@ -693,4 +715,4 @@
 
 	}
 
-} //Scaler class
+} // Scaler class