# HG changeset patch # User robcast # Date 1098642230 -7200 # Node ID b74c914b48a93686ca3018b7ee9b605fe70e79bb # Parent 0a212bc468ad7d2c4a15e3db18e1c269a8ebca9f Servlet version 1.5.0b -- the beginning of the next generation :-) - code restructuring to improve scaleability - new Initialiser servlet that must be run first - image transformation work moved to DigilibImageWorker class - Maximum number of concurrent threads limited by Semaphore - old JIMI toolkit implementation removed diff -r 0a212bc468ad -r b74c914b48a9 servlet/src/digilib/servlet/DigilibWorker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/servlet/DigilibWorker.java Sun Oct 24 20:23:50 2004 +0200 @@ -0,0 +1,126 @@ +/* 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 org.apache.log4j.Logger; + +import EDU.oswego.cs.dl.util.concurrent.FIFOSemaphore; +import EDU.oswego.cs.dl.util.concurrent.Semaphore; + +/** + * image operation worker. + * + * @author casties + * + */ +public abstract class DigilibWorker { + + protected static Logger logger = Logger.getLogger(DigilibWorker.class); + + private static int runningThreads = 0; + + public static Semaphore lock = new FIFOSemaphore(1); + + protected boolean busy = false; + + protected Exception error; + + /** + * @param job + */ + public DigilibWorker() { + super(); + busy = true; + error = null; + } + + public abstract void work() throws Exception; + + /** + * Do the work. + */ + public void run() { + try { + lock.acquire(); + } catch (InterruptedException e) { + error = e; + busy = false; + return; + } + logger.debug((++runningThreads) + " running threads"); + try { + work(); + } catch (Exception e) { + error = e; + logger.error(e); + } + busy = false; + runningThreads--; + lock.release(); + } + + + /** Returns the name of this thread. + * + * @return + */ + public String getName() { + return Thread.currentThread().getName(); + } + + /** + * @return Returns the busy. + */ + public boolean isBusy() { + return busy; + } + + /** + * returns if an error occurred. + * + * @return + */ + public boolean hasError() { + return (error != null); + } + + /** + * @return Returns the error. + */ + public Exception getError() { + return error; + } + + /** + * @return Returns the lock. + */ + public static Semaphore getLock() { + return lock; + } + + /** + * @param lock + * The lock to set. + */ + public static void setLock(Semaphore lock) { + DigilibWorker.lock = lock; + } +} diff -r 0a212bc468ad -r b74c914b48a9 servlet/src/digilib/servlet/DocumentBean.java --- a/servlet/src/digilib/servlet/DocumentBean.java Sun Oct 24 20:23:50 2004 +0200 +++ b/servlet/src/digilib/servlet/DocumentBean.java Sun Oct 24 20:23:50 2004 +0200 @@ -41,7 +41,7 @@ public class DocumentBean { // general logger - Logger logger = Logger.getLogger("digilib.docubean"); + private static Logger logger = Logger.getLogger("digilib.docubean"); // AuthOps object to check authorization private AuthOps authOp; @@ -85,12 +85,7 @@ .getAttribute("digilib.servlet.configuration"); if (dlConfig == null) { // create new Configuration - try { - dlConfig = new DigilibConfiguration(conf); - context.setAttribute("digilib.servlet.configuration", dlConfig); - } catch (Exception e) { - throw new ServletException(e); - } + throw new ServletException("ERROR: No configuration!"); } // get cache diff -r 0a212bc468ad -r b74c914b48a9 servlet/src/digilib/servlet/Initialiser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/servlet/Initialiser.java Sun Oct 24 20:23:50 2004 +0200 @@ -0,0 +1,161 @@ +/* Initialiser.java -- initalisation servlet for setup tasks + * + * 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.io.File; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; + +import org.apache.log4j.Logger; +import org.apache.log4j.xml.DOMConfigurator; + +import EDU.oswego.cs.dl.util.concurrent.FIFOSemaphore; +import EDU.oswego.cs.dl.util.concurrent.Semaphore; +import digilib.auth.AuthOps; +import digilib.auth.XMLAuthOps; +import digilib.io.AliasingDocuDirCache; +import digilib.io.DocuDirCache; +import digilib.io.FileOps; + +/** + * Initalisation servlet for setup tasks. + * + * @author casties + * + */ +public class Initialiser extends HttpServlet { + + private static final long serialVersionUID = -5126621114382549343L; + + /** servlet version */ + public static final String iniVersion = "0.1b1"; + + /** gengeral logger for this class */ + private static Logger logger = Logger.getLogger("digilib.init"); + + /** AuthOps instance */ + AuthOps authOp; + + /** DocuDirCache instance */ + DocuDirCache dirCache; + + /** DigilibConfiguration instance */ + DigilibConfiguration dlConfig; + + /** use authorization database */ + boolean useAuthentication = false; + + /** + * Initialisation on first run. + * + * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) + */ + public void init(ServletConfig config) throws ServletException { + super.init(config); + + System.out + .println("***** Digital Image Library Initialisation Servlet (version " + + iniVersion + ") *****"); + + // get our ServletContext + ServletContext context = config.getServletContext(); + // see if there is a Configuration instance + dlConfig = (DigilibConfiguration) context + .getAttribute("digilib.servlet.configuration"); + if (dlConfig == null) { + // create new Configuration + try { + dlConfig = new DigilibConfiguration(config); + + /* + * further initialization + */ + + // set up the logger + File logConf = ServletOps.getConfigFile((File) dlConfig + .getValue("log-config-file"), config); + DOMConfigurator.configure(logConf.getAbsolutePath()); + dlConfig.setValue("log-config-file", logConf); + // say hello in the log file + logger + .info("***** Digital Image Library Initialisation Servlet (version " + + iniVersion + ") *****"); + // directory cache + String[] bd = (String[]) dlConfig.getValue("basedir-list"); + int[] fcs = { FileOps.CLASS_IMAGE, FileOps.CLASS_TEXT, + FileOps.CLASS_SVG }; + if (dlConfig.getAsBoolean("use-mapping")) { + // with mapping file + File mapConf = ServletOps.getConfigFile((File) dlConfig + .getValue("mapping-file"), config); + dirCache = new AliasingDocuDirCache(bd, fcs, mapConf, + dlConfig); + dlConfig.setValue("mapping-file", mapConf); + } else { + // without mapping + dirCache = new DocuDirCache(bd, fcs, dlConfig); + } + dlConfig.setValue("servlet.dir.cache", dirCache); + // useAuthentication + if (dlConfig.getAsBoolean("use-authorization")) { + // DB version + //authOp = new DBAuthOpsImpl(util); + // XML version + File authConf = ServletOps.getConfigFile((File) dlConfig + .getValue("auth-file"), config); + authOp = new XMLAuthOps(authConf); + dlConfig.setValue("servlet.auth.op", authOp); + dlConfig.setValue("auth-file", authConf); + } + // DocuImage class + Class cl = Class.forName(dlConfig + .getAsString("docuimage-class")); + dlConfig.setDocuImageClass(cl); + dlConfig.setValue("servlet.docuimage.class", cl.getName()); + // worker threads + int nt = dlConfig.getAsInt("worker-threads"); + Semaphore lck = new FIFOSemaphore(nt); + DigilibWorker.setLock(lck); + // set as the servlets main config + context.setAttribute("digilib.servlet.configuration", dlConfig); + + } catch (Exception e) { + throw new ServletException(e); + } + } else { + // say hello in the log file + logger + .info("***** Digital Image Library Initialisation Servlet (version " + + iniVersion + ") *****"); + logger.warn("Already initialised?"); + // set our AuthOps + useAuthentication = dlConfig.getAsBoolean("use-authorization"); + // AuthOps instance + authOp = (AuthOps) dlConfig.getValue("servlet.auth.op"); + // DocuDirCache instance + dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); + } + } + +} diff -r 0a212bc468ad -r b74c914b48a9 servlet/src/digilib/servlet/Raster.java --- a/servlet/src/digilib/servlet/Raster.java Sun Oct 24 20:23:50 2004 +0200 +++ b/servlet/src/digilib/servlet/Raster.java Sun Oct 24 20:23:50 2004 +0200 @@ -94,13 +94,8 @@ (DigilibConfiguration) context.getAttribute( "digilib.servlet.configuration"); if (dlConfig == null) { - // create new Configuration - try { - dlConfig = new DigilibConfiguration(config); - context.setAttribute("digilib.servlet.configuration", dlConfig); - } catch (Exception e) { - throw new ServletException(e); - } + // no config + throw new ServletException("ERROR: No Configuration!"); } // say hello in the log file logger.info(