# HG changeset patch # User robcast # Date 1286988054 -7200 # Node ID e2ff961001afcd1e2fc3c7eacd465480fbd7c7c6 # Parent f140d5ee8c0b92008d9e6e43969714788778c696 first step towards more standard java.util.concurrent design diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/DigilibImageWorker.java --- a/servlet/src/digilib/servlet/DigilibImageWorker.java Tue Oct 12 20:42:58 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,274 +0,0 @@ -/* DigilibImageWorker.java -- worker for image operations - * - * Digital Image Library servlet components - * - * Copyright (C) 2004 Robert Casties (robcast@mail.berlios.de) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * Please read license.txt for the full details. A copy of the GPL may be found - * at http://www.gnu.org/copyleft/lgpl.html - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA 02111-1307 USA - * - * Created on 19.10.2004 - */ - -package digilib.servlet; - -import java.awt.Rectangle; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.io.OutputStream; - -import digilib.image.DocuImage; -import digilib.image.ImageOpException; -import digilib.image.ImageOps; -import digilib.io.FileOpException; -import digilib.io.ImageFile; - -/** - * worker for image operations. - * - * @author casties - * - */ -public class DigilibImageWorker extends DigilibWorker { - - private DigilibConfiguration dlConfig; - - //HttpServletResponse response; - - OutputStream outstream; - - long startTime; - - String mimeType; - - int scaleQual; - - //DigilibRequest dlRequest; - - //ImageJobInformation ijd; - - float paramROT; - - float paramCONT; - - float paramBRGT; - - float[] paramRGBM; - - float[] paramRGBA; - - ImageFile fileToLoad; - - float areaXoff; - - float areaYoff; - - float areaWidth; - - float areaHeight; - - float scaleXY; - - Rectangle2D outerUserImgArea; - - Rectangle2D innerUserImgArea; - - float minSubsample; - - boolean wholeRotArea; - - boolean vmir; - boolean hmir; - - int forceType; - - - public DigilibImageWorker(DigilibConfiguration dlConfig, OutputStream outstream, ImageJobInformation jobinfo) { - super(); - - this.dlConfig = dlConfig; - this.outstream = outstream; - this.mimeType = jobinfo.get_mimeType(); - this.scaleQual = jobinfo.get_scaleQual(); - this.paramROT = jobinfo.getAsFloat("rot"); - this.paramCONT = jobinfo.getAsFloat("cont"); - this.paramBRGT = jobinfo.getAsFloat("brgt"); - this.paramRGBM = jobinfo.get_paramRGBM(); - this.paramRGBA = jobinfo.get_paramRGBA(); - try { - this.fileToLoad = jobinfo.get_fileToLoad(); - this.scaleXY = jobinfo.get_scaleXY(); - this.outerUserImgArea = jobinfo.get_outerUserImgArea(); - this.innerUserImgArea = jobinfo.get_innerUserImgArea(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ImageOpException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - this.minSubsample = dlConfig.getAsFloat("subsample-minimum"); - this.wholeRotArea = jobinfo.get_wholeRotArea(); - this.forceType = jobinfo.get_forceType(); - this.hmir = jobinfo.get_hmir(); - this.vmir = jobinfo.get_vmir(); - } - - /* - * do the work - */ - public DocuImage render() throws FileOpException, IOException, ImageOpException { - - logger.debug("image worker " + this.getName() + " working"); - startTime = System.currentTimeMillis(); - - /* crop and scale image */ - - // new DocuImage instance - DocuImage docuImage = dlConfig.getDocuImageInstance(); - if (docuImage == null) { - throw new ImageOpException("Unable to load DocuImage class!"); - } - - // set interpolation quality - docuImage.setQuality(scaleQual); - - Rectangle loadRect = outerUserImgArea.getBounds(); - // use subimage loading if possible - if (docuImage.isSubimageSupported()) { - logger.debug("Subimage: scale " + scaleXY + " = " + (1 / scaleXY)); - float subf = 1f; - float subsamp = 1f; - if (scaleXY < 1) { - subf = 1 / scaleXY; - // for higher quality reduce subsample factor by - // minSubsample - if (scaleQual > 0) { - subsamp = (float) Math.max(Math.floor(subf / minSubsample), - 1d); - } else { - subsamp = (float) Math.floor(subf); - } - scaleXY = subsamp / subf; - logger.debug("Using subsampling: " + subsamp + " rest " - + scaleXY); - } - - docuImage.loadSubimage(fileToLoad, loadRect, (int) subsamp); - - logger.debug("SUBSAMP: " + subsamp + " -> " + docuImage.getWidth() - + "x" + docuImage.getHeight()); - - docuImage.scale(scaleXY, scaleXY); - - } else { - // else load and crop the whole file - docuImage.loadImage(fileToLoad); - docuImage.crop((int) loadRect.getX(), (int) loadRect.getY(), - (int) loadRect.getWidth(), (int) loadRect.getHeight()); - - docuImage.scale(scaleXY, scaleXY); - } - - // mirror image - // operation mode: "hmir": mirror horizontally, "vmir": mirror - // vertically - if (hmir) { - docuImage.mirror(0); - } - if (vmir) { - docuImage.mirror(90); - } - - // rotate image - if (paramROT != 0d) { - docuImage.rotate(paramROT); - if (wholeRotArea) { - // crop to the inner bounding box - float xcrop = (float) (docuImage.getWidth() - innerUserImgArea - .getWidth() - * scaleXY); - float ycrop = (float) (docuImage.getHeight() - innerUserImgArea - .getHeight() - * scaleXY); - if ((xcrop > 0) || (ycrop > 0)) { - // only crop smaller - xcrop = (xcrop > 0) ? xcrop : 0; - ycrop = (ycrop > 0) ? ycrop : 0; - // crop image - docuImage.crop((int) (xcrop / 2), (int) (ycrop / 2), - (int) (docuImage.getWidth() - xcrop), - (int) (docuImage.getHeight() - ycrop)); - } - } - - } - - // color modification - if ((paramRGBM != null) || (paramRGBA != null)) { - // make shure we actually have two arrays - if (paramRGBM == null) { - paramRGBM = new float[3]; - } - if (paramRGBA == null) { - paramRGBA = new float[3]; - } - // calculate "contrast" values (c=2^x) - float[] mult = new float[3]; - for (int i = 0; i < 3; i++) { - mult[i] = (float) Math.pow(2, (float) paramRGBM[i]); - } - docuImage.enhanceRGB(mult, paramRGBA); - } - - // contrast and brightness enhancement - if ((paramCONT != 0f) || (paramBRGT != 0f)) { - float mult = (float) Math.pow(2, paramCONT); - docuImage.enhance(mult, paramBRGT); - } - - logger.debug("rendered in " + (System.currentTimeMillis() - startTime) + "ms"); - - return docuImage; - } - - public void write(DocuImage img) throws FileOpException, IOException { - /* write the resulting image */ - - // setup output -- if output type is forced use that otherwise - // if source is JPG then dest will be JPG else it's PNG - if (forceType != ImageOps.TYPE_AUTO) { - if (forceType == ImageOps.TYPE_JPEG) { - mimeType = "image/jpeg"; - } - if (forceType == ImageOps.TYPE_PNG) { - mimeType = "image/png"; - } - } else if ((mimeType.equals("image/jpeg") - || mimeType.equals("image/jp2") || mimeType.equals("image/fpx"))) { - mimeType = "image/jpeg"; - } else { - mimeType = "image/png"; - } - - // write the image - img.writeImage(mimeType, outstream); - outstream.flush(); - - - logger.info("image worker " + this.getName() + " done in " - + (System.currentTimeMillis() - startTime)); - - img.dispose(); - } -} diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/DigilibImageWorker1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/servlet/DigilibImageWorker1.java Wed Oct 13 18:40:54 2010 +0200 @@ -0,0 +1,274 @@ +/* DigilibImageWorker.java -- worker for image operations + * + * Digital Image Library servlet components + * + * Copyright (C) 2004 Robert Casties (robcast@mail.berlios.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * Please read license.txt for the full details. A copy of the GPL may be found + * at http://www.gnu.org/copyleft/lgpl.html + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 19.10.2004 + */ + +package digilib.servlet; + +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; +import java.io.IOException; +import java.io.OutputStream; + +import digilib.image.DocuImage; +import digilib.image.ImageOpException; +import digilib.image.ImageOps; +import digilib.io.FileOpException; +import digilib.io.ImageFile; + +/** + * worker for image operations. + * + * @author casties + * + */ +public class DigilibImageWorker1 extends DigilibWorker1 { + + private DigilibConfiguration dlConfig; + + //HttpServletResponse response; + + OutputStream outstream; + + long startTime; + + String mimeType; + + int scaleQual; + + //DigilibRequest dlRequest; + + //ImageJobInformation ijd; + + float paramROT; + + float paramCONT; + + float paramBRGT; + + float[] paramRGBM; + + float[] paramRGBA; + + ImageFile fileToLoad; + + float areaXoff; + + float areaYoff; + + float areaWidth; + + float areaHeight; + + float scaleXY; + + Rectangle2D outerUserImgArea; + + Rectangle2D innerUserImgArea; + + float minSubsample; + + boolean wholeRotArea; + + boolean vmir; + boolean hmir; + + int forceType; + + + public DigilibImageWorker1(DigilibConfiguration dlConfig, OutputStream outstream, ImageJobInformation jobinfo) { + super(); + + this.dlConfig = dlConfig; + this.outstream = outstream; + this.mimeType = jobinfo.get_mimeType(); + this.scaleQual = jobinfo.get_scaleQual(); + this.paramROT = jobinfo.getAsFloat("rot"); + this.paramCONT = jobinfo.getAsFloat("cont"); + this.paramBRGT = jobinfo.getAsFloat("brgt"); + this.paramRGBM = jobinfo.get_paramRGBM(); + this.paramRGBA = jobinfo.get_paramRGBA(); + try { + this.fileToLoad = jobinfo.get_fileToLoad(); + this.scaleXY = jobinfo.get_scaleXY(); + this.outerUserImgArea = jobinfo.get_outerUserImgArea(); + this.innerUserImgArea = jobinfo.get_innerUserImgArea(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ImageOpException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + this.minSubsample = dlConfig.getAsFloat("subsample-minimum"); + this.wholeRotArea = jobinfo.get_wholeRotArea(); + this.forceType = jobinfo.get_forceType(); + this.hmir = jobinfo.get_hmir(); + this.vmir = jobinfo.get_vmir(); + } + + /* + * do the work + */ + public DocuImage render() throws FileOpException, IOException, ImageOpException { + + logger.debug("image worker " + this.getName() + " working"); + startTime = System.currentTimeMillis(); + + /* crop and scale image */ + + // new DocuImage instance + DocuImage docuImage = dlConfig.getDocuImageInstance(); + if (docuImage == null) { + throw new ImageOpException("Unable to load DocuImage class!"); + } + + // set interpolation quality + docuImage.setQuality(scaleQual); + + Rectangle loadRect = outerUserImgArea.getBounds(); + // use subimage loading if possible + if (docuImage.isSubimageSupported()) { + logger.debug("Subimage: scale " + scaleXY + " = " + (1 / scaleXY)); + float subf = 1f; + float subsamp = 1f; + if (scaleXY < 1) { + subf = 1 / scaleXY; + // for higher quality reduce subsample factor by + // minSubsample + if (scaleQual > 0) { + subsamp = (float) Math.max(Math.floor(subf / minSubsample), + 1d); + } else { + subsamp = (float) Math.floor(subf); + } + scaleXY = subsamp / subf; + logger.debug("Using subsampling: " + subsamp + " rest " + + scaleXY); + } + + docuImage.loadSubimage(fileToLoad, loadRect, (int) subsamp); + + logger.debug("SUBSAMP: " + subsamp + " -> " + docuImage.getWidth() + + "x" + docuImage.getHeight()); + + docuImage.scale(scaleXY, scaleXY); + + } else { + // else load and crop the whole file + docuImage.loadImage(fileToLoad); + docuImage.crop((int) loadRect.getX(), (int) loadRect.getY(), + (int) loadRect.getWidth(), (int) loadRect.getHeight()); + + docuImage.scale(scaleXY, scaleXY); + } + + // mirror image + // operation mode: "hmir": mirror horizontally, "vmir": mirror + // vertically + if (hmir) { + docuImage.mirror(0); + } + if (vmir) { + docuImage.mirror(90); + } + + // rotate image + if (paramROT != 0d) { + docuImage.rotate(paramROT); + if (wholeRotArea) { + // crop to the inner bounding box + float xcrop = (float) (docuImage.getWidth() - innerUserImgArea + .getWidth() + * scaleXY); + float ycrop = (float) (docuImage.getHeight() - innerUserImgArea + .getHeight() + * scaleXY); + if ((xcrop > 0) || (ycrop > 0)) { + // only crop smaller + xcrop = (xcrop > 0) ? xcrop : 0; + ycrop = (ycrop > 0) ? ycrop : 0; + // crop image + docuImage.crop((int) (xcrop / 2), (int) (ycrop / 2), + (int) (docuImage.getWidth() - xcrop), + (int) (docuImage.getHeight() - ycrop)); + } + } + + } + + // color modification + if ((paramRGBM != null) || (paramRGBA != null)) { + // make shure we actually have two arrays + if (paramRGBM == null) { + paramRGBM = new float[3]; + } + if (paramRGBA == null) { + paramRGBA = new float[3]; + } + // calculate "contrast" values (c=2^x) + float[] mult = new float[3]; + for (int i = 0; i < 3; i++) { + mult[i] = (float) Math.pow(2, (float) paramRGBM[i]); + } + docuImage.enhanceRGB(mult, paramRGBA); + } + + // contrast and brightness enhancement + if ((paramCONT != 0f) || (paramBRGT != 0f)) { + float mult = (float) Math.pow(2, paramCONT); + docuImage.enhance(mult, paramBRGT); + } + + logger.debug("rendered in " + (System.currentTimeMillis() - startTime) + "ms"); + + return docuImage; + } + + public void write(DocuImage img) throws FileOpException, IOException { + /* write the resulting image */ + + // setup output -- if output type is forced use that otherwise + // if source is JPG then dest will be JPG else it's PNG + if (forceType != ImageOps.TYPE_AUTO) { + if (forceType == ImageOps.TYPE_JPEG) { + mimeType = "image/jpeg"; + } + if (forceType == ImageOps.TYPE_PNG) { + mimeType = "image/png"; + } + } else if ((mimeType.equals("image/jpeg") + || mimeType.equals("image/jp2") || mimeType.equals("image/fpx"))) { + mimeType = "image/jpeg"; + } else { + mimeType = "image/png"; + } + + // write the image + img.writeImage(mimeType, outstream); + outstream.flush(); + + + logger.info("image worker " + this.getName() + " done in " + + (System.currentTimeMillis() - startTime)); + + img.dispose(); + } +} diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/DigilibPDFWorker.java --- a/servlet/src/digilib/servlet/DigilibPDFWorker.java Tue Oct 12 20:42:58 2010 +0200 +++ b/servlet/src/digilib/servlet/DigilibPDFWorker.java Wed Oct 13 18:40:54 2010 +0200 @@ -43,7 +43,7 @@ * @author cmielack * */ -public class DigilibPDFWorker extends DigilibWorker { +public class DigilibPDFWorker extends DigilibWorker1 { private DigilibConfiguration dlConfig = null; @@ -165,7 +165,7 @@ ImageJobInformation iji = job_info.getImageJobInformation(); iji.setValue("pn", pn); // create image worker - DigilibImageWorker image_worker = new DigilibImageWorker(dlConfig, null, iji); + DigilibImageWorker1 image_worker = new DigilibImageWorker1(dlConfig, null, iji); try { DocuImage img = image_worker.render(); diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/DigilibWorker.java --- a/servlet/src/digilib/servlet/DigilibWorker.java Tue Oct 12 20:42:58 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,195 +0,0 @@ -/* DigilibWorker.java -- image operation worker - * - * Digital Image Library servlet components - * - * Copyright (C) 2004 Robert Casties (robcast@mail.berlios.de) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * Please read license.txt for the full details. A copy of the GPL may be found - * at http://www.gnu.org/copyleft/lgpl.html - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA 02111-1307 USA - * - * Created on 18.10.2004 - */ -package digilib.servlet; - -import java.util.concurrent.Semaphore; - -import org.apache.log4j.Logger; - -import digilib.image.DocuImage; - -/** - * image operation worker. - * - * @author casties - */ -public abstract class DigilibWorker { - - protected static Logger logger = Logger.getLogger(DigilibWorker.class); - - private static int maxRunningThreads = 0; - - private static int runningThreads = 0; - - private static int waitingThreads = 0; - - private static int maxWaitingThreads = 0; - - public static Semaphore sem = new Semaphore(2, true); - - protected Throwable error; - - /** - * @param job - */ - public DigilibWorker() { - super(); - error = null; - } - - public abstract DocuImage render() throws Exception; - - public abstract void write(DocuImage img) throws Exception; - - /** - * Do the work. - */ - public void run() { - logger.debug((++waitingThreads) + " waiting threads"); - DocuImage img = null; - try { - sem.acquire(); - waitingThreads--; - } catch (InterruptedException e) { - error = e; - waitingThreads--; - // should we reinterrupt? - return; - } - logger.debug((++runningThreads) + " running threads"); - try { - /* - * do rendering under the semaphore - */ - img = render(); - } catch (Throwable e) { - error = e; - logger.error(e); - } finally { - runningThreads--; - sem.release(); - } - /* - * write the result without semaphore - */ - if (!hasError()) { - try{ - write(img); - } catch (Throwable e) { - error = e; - logger.error(e); - } - } - } - - /** - * 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.getNumWaiting() <= DigilibWorker.maxWaitingThreads)); - } - - /** - * returns if an error occurred. - * - * @return - */ - public boolean hasError() { - return (error != null); - } - - /** - * @return Returns the error. - */ - public Throwable getError() { - return error; - } - - /** - * @return Returns the semaphore. - */ - public static Semaphore getSemaphore() { - return sem; - } - - /** - * @param sem - * The semaphore to set. - */ - public static void setSemaphore(Semaphore sem) { - DigilibWorker.sem = sem; - } - - public static void setSemaphore(int maxrun, boolean fair) { - sem = new Semaphore(maxrun, fair); - maxRunningThreads = maxrun; - } - - /** - * The number of currently running threads (approximate). - * - * @return - */ - public static int getNumRunning() { - return (maxRunningThreads - sem.availablePermits()); - } - - /** - * The number of currently waiting threads (approximate). - * - * @return - */ - public static int getNumWaiting() { - return sem.getQueueLength(); - } - - /** - * @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; - } - - public static int getMaxRunningThreads() { - return maxRunningThreads; - } - - public static void setMaxRunningThreads(int maxRunningThreads) { - DigilibWorker.maxRunningThreads = maxRunningThreads; - } -} diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/DigilibWorker1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/servlet/DigilibWorker1.java Wed Oct 13 18:40:54 2010 +0200 @@ -0,0 +1,195 @@ +/* DigilibWorker.java -- image operation worker + * + * Digital Image Library servlet components + * + * Copyright (C) 2004 Robert Casties (robcast@mail.berlios.de) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * Please read license.txt for the full details. A copy of the GPL may be found + * at http://www.gnu.org/copyleft/lgpl.html + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 18.10.2004 + */ +package digilib.servlet; + +import java.util.concurrent.Semaphore; + +import org.apache.log4j.Logger; + +import digilib.image.DocuImage; + +/** + * image operation worker. + * + * @author casties + */ +public abstract class DigilibWorker1 { + + protected static Logger logger = Logger.getLogger(DigilibWorker1.class); + + private static int maxRunningThreads = 0; + + private static int runningThreads = 0; + + private static int waitingThreads = 0; + + private static int maxWaitingThreads = 0; + + public static Semaphore sem = new Semaphore(2, true); + + protected Throwable error; + + /** + * @param job + */ + public DigilibWorker1() { + super(); + error = null; + } + + public abstract DocuImage render() throws Exception; + + public abstract void write(DocuImage img) throws Exception; + + /** + * Do the work. + */ + public void run() { + logger.debug((++waitingThreads) + " waiting threads"); + DocuImage img = null; + try { + sem.acquire(); + waitingThreads--; + } catch (InterruptedException e) { + error = e; + waitingThreads--; + // should we reinterrupt? + return; + } + logger.debug((++runningThreads) + " running threads"); + try { + /* + * do rendering under the semaphore + */ + img = render(); + } catch (Throwable e) { + error = e; + logger.error(e); + } finally { + runningThreads--; + sem.release(); + } + /* + * write the result without semaphore + */ + if (!hasError()) { + try{ + write(img); + } catch (Throwable e) { + error = e; + logger.error(e); + } + } + } + + /** + * 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 ((DigilibWorker1.maxWaitingThreads == 0) || (DigilibWorker1.getNumWaiting() <= DigilibWorker1.maxWaitingThreads)); + } + + /** + * returns if an error occurred. + * + * @return + */ + public boolean hasError() { + return (error != null); + } + + /** + * @return Returns the error. + */ + public Throwable getError() { + return error; + } + + /** + * @return Returns the semaphore. + */ + public static Semaphore getSemaphore() { + return sem; + } + + /** + * @param sem + * The semaphore to set. + */ + public static void setSemaphore(Semaphore sem) { + DigilibWorker1.sem = sem; + } + + public static void setSemaphore(int maxrun, boolean fair) { + sem = new Semaphore(maxrun, fair); + maxRunningThreads = maxrun; + } + + /** + * The number of currently running threads (approximate). + * + * @return + */ + public static int getNumRunning() { + return (maxRunningThreads - sem.availablePermits()); + } + + /** + * The number of currently waiting threads (approximate). + * + * @return + */ + public static int getNumWaiting() { + return sem.getQueueLength(); + } + + /** + * @return Returns the maxWaitingThreads. + */ + public static int getMaxWaitingThreads() { + return maxWaitingThreads; + } + + /** + * @param maxWaitingThreads The maxWaitingThreads to set. + */ + public static void setMaxWaitingThreads(int maxWaitingThreads) { + DigilibWorker1.maxWaitingThreads = maxWaitingThreads; + } + + public static int getMaxRunningThreads() { + return maxRunningThreads; + } + + public static void setMaxRunningThreads(int maxRunningThreads) { + DigilibWorker1.maxRunningThreads = maxRunningThreads; + } +} diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/ImageJobInformation.java --- a/servlet/src/digilib/servlet/ImageJobInformation.java Tue Oct 12 20:42:58 2010 +0200 +++ b/servlet/src/digilib/servlet/ImageJobInformation.java Wed Oct 13 18:40:54 2010 +0200 @@ -636,6 +636,18 @@ return hasOption("mo","vmir"); } + public float getRot(){ + return getAsFloat("rot"); + } + + public float getCont(){ + return getAsFloat("cont"); + } + + public float getBrgt(){ + return getAsFloat("brgt"); + } + public boolean checkSendAsFile(){ return hasOption("mo", "file") || hasOption("mo", "rawfile"); diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/Initialiser.java --- a/servlet/src/digilib/servlet/Initialiser.java Tue Oct 12 20:42:58 2010 +0200 +++ b/servlet/src/digilib/servlet/Initialiser.java Wed Oct 13 18:40:54 2010 +0200 @@ -134,9 +134,9 @@ ImageOps.setDocuImage(di); // worker threads int nt = dlConfig.getAsInt("worker-threads"); - DigilibWorker.setSemaphore(nt, true); + DigilibWorker1.setSemaphore(nt, true); int mt = dlConfig.getAsInt("max-waiting-threads"); - DigilibWorker.setMaxWaitingThreads(mt); + DigilibWorker1.setMaxWaitingThreads(mt); // set as the servlets main config context.setAttribute("digilib.servlet.configuration", dlConfig); diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/PDFCache.java --- a/servlet/src/digilib/servlet/PDFCache.java Tue Oct 12 20:42:58 2010 +0200 +++ b/servlet/src/digilib/servlet/PDFCache.java Wed Oct 13 18:40:54 2010 +0200 @@ -125,7 +125,7 @@ notifyUser(status, docid, request, response); } else if (status == STATUS_DONE) { try { - sendFile(docid, downloadFilename(pdfji), response); + sendFile(docid, getDownloadFilename(pdfji), response); } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage()); @@ -212,7 +212,7 @@ * @param pdfji * @return */ - public String downloadFilename(PDFJobInformation pdfji){ + public String getDownloadFilename(PDFJobInformation pdfji){ // filename example: digilib_example_pgs1-3.pdf String filename; filename = "digilib_"; diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/PDFMaker.java --- a/servlet/src/digilib/servlet/PDFMaker.java Tue Oct 12 20:42:58 2010 +0200 +++ b/servlet/src/digilib/servlet/PDFMaker.java Wed Oct 13 18:40:54 2010 +0200 @@ -41,7 +41,7 @@ public void run() { - if (! DigilibWorker.canRun()) { + if (! DigilibWorker1.canRun()) { // TODO include the logger logger.error("Servlet overloaded!"); return; diff -r f140d5ee8c0b -r e2ff961001af servlet/src/digilib/servlet/Scaler.java --- a/servlet/src/digilib/servlet/Scaler.java Tue Oct 12 20:42:58 2010 +0200 +++ b/servlet/src/digilib/servlet/Scaler.java Wed Oct 13 18:40:54 2010 +0200 @@ -222,7 +222,7 @@ logger.error(e1.getMessage()); } - if (! DigilibWorker.canRun()) { + if (! DigilibWorker1.canRun()) { logger.error("Servlet overloaded!"); try { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); @@ -233,7 +233,7 @@ } - DigilibWorker job=null; + DigilibWorker1 job=null; try { long startTime = System.currentTimeMillis(); @@ -261,7 +261,7 @@ } - job = new DigilibImageWorker(dlConfig, outputstream , jobdeclaration); + job = new DigilibImageWorker1(dlConfig, outputstream , jobdeclaration); job.run();