changeset 346:5275a132dbd1

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 69fee4d7eb52
children a87e80bfbd47
files servlet/src/digilib/servlet/DigilibConfiguration.java servlet/src/digilib/servlet/DigilibRequest.java servlet/src/digilib/servlet/DigilibWorker.java
diffstat 3 files changed, 44 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java	Wed Feb 23 18:13:40 2005 +0100
+++ b/servlet/src/digilib/servlet/DigilibConfiguration.java	Fri Apr 22 19:16:41 2005 +0200
@@ -143,6 +143,8 @@
 		newParameter("safe-dir-index", Boolean.FALSE, null, 'f');
 		// number of working threads
 		newParameter("worker-threads", new Integer(1), null, 'f');
+		// max number of waiting threads
+		newParameter("max-waiting-threads", new Integer(0), null, 'f');
 
 	}
 
--- a/servlet/src/digilib/servlet/DigilibRequest.java	Wed Feb 23 18:13:40 2005 +0100
+++ b/servlet/src/digilib/servlet/DigilibRequest.java	Fri Apr 22 19:16:41 2005 +0200
@@ -157,6 +157,10 @@
 		newParameter("img.dpix", new Integer(0), null, 'c');
 		// image dpi y
 		newParameter("img.dpiy", new Integer(0), null, 'c');
+		// hires image size x
+		newParameter("img.pix_x", new Integer(0), null, 'c');
+		// hires image size y
+		newParameter("img.pix_y", new Integer(0), null, 'c');
 		// total number of pages
 		newParameter("pt", new Integer(0), null, 'c');
 		//	display level of digilib (0 = just image, 1 = one HTML page
--- a/servlet/src/digilib/servlet/DigilibWorker.java	Wed Feb 23 18:13:40 2005 +0100
+++ b/servlet/src/digilib/servlet/DigilibWorker.java	Fri Apr 22 19:16:41 2005 +0200
@@ -29,7 +29,6 @@
  * image operation worker.
  * 
  * @author casties
- *  
  */
 public abstract class DigilibWorker {
 
@@ -39,6 +38,8 @@
 
 	private static int waitingThreads = 0;
 
+	private static int maxWaitingThreads = 0;
+
 	public static Semaphore lock = new FIFOSemaphore(1);
 
 	protected boolean busy = false;
@@ -76,21 +77,30 @@
 		} catch (Exception e) {
 			error = e;
 			logger.error(e);
+		} finally {
+			busy = false;
+			runningThreads--;
+			lock.release();
 		}
-		busy = false;
-		runningThreads--;
-		lock.release();
 	}
 
-	
-	/** Returns the name of this thread.
+	/**
+	 * Returns the name of this thread.
 	 * 
 	 * @return
 	 */
 	public String getName() {
 		return Thread.currentThread().getName();
 	}
-	
+
+	/** Returns if the worker could run (i.e. is not overloaded).
+	 * 
+	 * @return
+	 */
+	public static boolean canRun() {
+		return ((DigilibWorker.maxWaitingThreads == 0) || (DigilibWorker.waitingThreads <= DigilibWorker.maxWaitingThreads));
+	}
+
 	/**
 	 * @return Returns the busy.
 	 */
@@ -128,18 +138,36 @@
 	public static void setLock(Semaphore lock) {
 		DigilibWorker.lock = lock;
 	}
-	
-	/** The number of currently running threads (approximate).
+
+	/**
+	 * The number of currently running threads (approximate).
+	 * 
 	 * @return
 	 */
 	public static int getNumRunning() {
 		return runningThreads;
 	}
 
-	/** The number of currently waiting threads (approximate).
+	/**
+	 * The number of currently waiting threads (approximate).
+	 * 
 	 * @return
 	 */
 	public static int getNumWaiting() {
 		return waitingThreads;
 	}
+
+	/**
+	 * @return Returns the maxWaitingThreads.
+	 */
+	public static int getMaxWaitingThreads() {
+		return maxWaitingThreads;
+	}
+
+	/**
+	 * @param maxWaitingThreads The maxWaitingThreads to set.
+	 */
+	public static void setMaxWaitingThreads(int maxWaitingThreads) {
+		DigilibWorker.maxWaitingThreads = maxWaitingThreads;
+	}
 }