Return-Path: Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 13504 invoked by uid 500); 23 Feb 2000 00:50:52 -0000 Delivered-To: apmail-xml-cocoon-cvs@apache.org Received: (qmail 13500 invoked by uid 1010); 23 Feb 2000 00:50:51 -0000 Date: 23 Feb 2000 00:50:51 -0000 Message-ID: <20000223005051.13499.qmail@locus.apache.org> From: stefano@locus.apache.org To: xml-cocoon-cvs@apache.org Subject: cvs commit: xml-cocoon/src/org/apache/cocoon/store MemoryStore.java stefano 00/02/22 16:50:51 Modified: src/org/apache/cocoon Engine.java src/org/apache/cocoon/processor/xslt XSLTProcessor.java src/org/apache/cocoon/store MemoryStore.java Log: cleanups Revision Changes Path 1.19 +3 -4 xml-cocoon/src/org/apache/cocoon/Engine.java Index: Engine.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Engine.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- Engine.java 2000/02/16 01:12:29 1.18 +++ Engine.java 2000/02/23 00:50:47 1.19 @@ -1,4 +1,4 @@ -/*-- $Id: Engine.java,v 1.18 2000/02/16 01:12:29 stefano Exp $ -- +/*-- $Id: Engine.java,v 1.19 2000/02/23 00:50:47 stefano Exp $ -- ============================================================================ The Apache Software License, Version 1.1 @@ -72,7 +72,7 @@ * This class implements the engine that does all the document processing. * * @author Stefano Mazzocchi - * @version $Revision: 1.18 $ $Date: 2000/02/16 01:12:29 $ + * @version $Revision: 1.19 $ $Date: 2000/02/23 00:50:47 $ */ public class Engine implements Defaults { @@ -312,8 +312,7 @@ if (page == null) { throw new Exception("FATAL ERROR: the system ran out of memory when" - + " processing the request. Increase your JVM memory as well" - + " as the 'store.memory' value in your configuratios."); + + " processing the request. Increase your JVM memory."); } if (DEBUG) { 1.8 +14 -23 xml-cocoon/src/org/apache/cocoon/processor/xslt/XSLTProcessor.java Index: XSLTProcessor.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xslt/XSLTProcessor.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- XSLTProcessor.java 2000/02/16 01:11:18 1.7 +++ XSLTProcessor.java 2000/02/23 00:50:48 1.8 @@ -1,4 +1,4 @@ -/*-- $Id: XSLTProcessor.java,v 1.7 2000/02/16 01:11:18 stefano Exp $ -- +/*-- $Id: XSLTProcessor.java,v 1.8 2000/02/23 00:50:48 stefano Exp $ -- ============================================================================ The Apache Software License, Version 1.1 @@ -70,7 +70,7 @@ * This class implements an XSLT processor. * * @author Stefano Mazzocchi - * @version $Revision: 1.7 $ $Date: 2000/02/16 01:11:18 $ + * @version $Revision: 1.8 $ $Date: 2000/02/23 00:50:48 $ */ public class XSLTProcessor implements Actor, Processor, Status, Defaults { @@ -98,7 +98,7 @@ try { Object resource = getResource(document, path, browser); - Document stylesheet = getStylesheet(resource, document, request); + Document stylesheet = getStylesheet(resource, request); Document result = this.parser.createEmptyDocument(); return transformer.transform(document, null, stylesheet, resource.toString(), result); } catch (PINotFoundException e) { @@ -154,31 +154,22 @@ } } - private Document getStylesheet(Object resource, Document document, HttpServletRequest request) throws ProcessorException { + private Document getStylesheet(Object resource, HttpServletRequest request) throws ProcessorException { try { - Document sheet; - String stylesheetKey = Utils.encode(request, true) + resource.toString(); - - if (this.hasChanged(stylesheetKey)) { - sheet = getDocument(resource); - this.store.hold(resource, sheet); - this.monitor.watch(stylesheetKey, resource); + Object o = this.store.get(resource); + if ((o != null) && (!this.hasChanged(request))) { + return (Document) o; } else { - Object o = this.store.get(resource); - if (o != null) { - sheet = (Document) o; - } else { - sheet = getDocument(resource); - this.store.hold(resource, sheet); - this.monitor.watch(stylesheetKey, resource); - } + Document sheet = getDocument(resource); + this.store.hold(resource, sheet); + this.monitor.watch(Utils.encode(request), resource); + return sheet; } - - return sheet; } catch (Exception e) { + this.monitor.invalidate(request); throw new ProcessorException("Could not associate stylesheet to document: " - + " error reading " + resource + ": " + e.getMessage()); + + " error reading " + resource + ": " + e); } } @@ -200,7 +191,7 @@ } public boolean hasChanged(Object context) { - return this.monitor.hasChanged((String) context); + return this.monitor.hasChanged(Utils.encode((HttpServletRequest) context)); } public String getStatus() { 1.8 +11 -42 xml-cocoon/src/org/apache/cocoon/store/MemoryStore.java Index: MemoryStore.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/store/MemoryStore.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MemoryStore.java 2000/02/14 00:59:19 1.7 +++ MemoryStore.java 2000/02/23 00:50:50 1.8 @@ -1,4 +1,4 @@ -/*-- $Id: MemoryStore.java,v 1.7 2000/02/14 00:59:19 stefano Exp $ -- +/*-- $Id: MemoryStore.java,v 1.8 2000/02/23 00:50:50 stefano Exp $ -- ============================================================================ The Apache Software License, Version 1.1 @@ -48,6 +48,7 @@ Software Foundation, please see . */ + package org.apache.cocoon.store; import java.io.*; @@ -65,13 +66,18 @@ * sending a note about a method to do it. * * @author Stefano Mazzocchi - * @version $Revision: 1.7 $ $Date: 2000/02/14 00:59:19 $ + * @version $Revision: 1.8 $ $Date: 2000/02/23 00:50:50 $ */ + +public class MemoryStore implements Store, Status { -public class MemoryStore implements Store, Configurable, Status { + /** + * Indicates how much memory should be left free in the JVM for + * normal operation. + */ + private static final int memory = 500000; private Runtime jvm; - private int memory; private Hashtable hashtable; class Container { @@ -89,39 +95,6 @@ this.hashtable = new Hashtable(101, 0.75f); // tune later on } - // !!!!!!!!!!!!!!!! check this method with more JVMs !!!!!!!!!!!!!!!!!!!!! - public void init(Configurations confs) throws InitializationException { - this.memory = Integer.parseInt((String) confs.getNotNull("memory")); - - // create a dummy object that is as big as the required free memory - // this will force the JVM heap to grow to accomodates the required needs. - try { - byte[] dummy = new byte[this.memory]; - for (int i = 0; i < this.memory; dummy[i++] = 1); - } catch (OutOfMemoryError e) { - throw new InitializationException("The system doesn't have " - + memory + " bytes that are required for operation. Please, " - + "increase your JVM memory or lower 'store.memory' requirements."); - } finally { - jvm.gc(); - } - - for (int i = 0; i < 10; i++) { - try { - if (memory < jvm.freeMemory()) { - break; - } else { - Thread.sleep(1000); - } - } catch (InterruptedException ignored) {} - } - - if (memory <= 0) - throw new IllegalArgumentException("Free memory limit must be higher than zero."); - if (memory > jvm.freeMemory()) - throw new IllegalArgumentException("Free memory is already lower than imposed limit. Lower your 'store.memory' configuration."); - } - /** * Store the given object in a persistent state. It is up to the * caller to ensure that the key has a persistent state across @@ -137,11 +110,7 @@ * virtual machine is restarted or some error happens. */ public synchronized void hold(Object key, Object object) { - - while (jvm.freeMemory() < memory) { - this.free(); - } - + if (jvm.freeMemory() < memory) this.free(); this.hashtable.put(key, new Container(object)); }