You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by st...@locus.apache.org on 2000/02/14 01:59:19 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon/store MemoryStore.java Store.java
stefano 00/02/13 16:59:19
Modified: src/org/apache/cocoon Defaults.java Engine.java
cocoon.properties
src/org/apache/cocoon/cache Cache.java CocoonCache.java
NoCache.java
src/org/apache/cocoon/store MemoryStore.java Store.java
Log:
Better memory handling (needs more portability tests but JMeter
_heavy_ loads show no problem on my systems on all the JVMs)
Revision Changes Path
1.10 +19 -18 xml-cocoon/src/org/apache/cocoon/Defaults.java
Index: Defaults.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Defaults.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Defaults.java 2000/02/13 18:29:16 1.9
+++ Defaults.java 2000/02/14 00:59:17 1.10
@@ -1,36 +1,36 @@
-/*-- $Id: Defaults.java,v 1.9 2000/02/13 18:29:16 stefano Exp $ --
+/*-- $Id: Defaults.java,v 1.10 2000/02/14 00:59:17 stefano Exp $ --
============================================================================
The Apache Software License, Version 1.1
============================================================================
-
+
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
-
+
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
-
+
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-
+
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
-
+
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
-
+
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
apache@apache.org.
-
+
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
-
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
@@ -41,12 +41,12 @@
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
+ Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.cocoon;
@@ -54,7 +54,7 @@
* The Cocoon strings.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.9 $ $Date: 2000/02/13 18:29:16 $
+ * @version $Revision: 1.10 $ $Date: 2000/02/14 00:59:17 $
*/
public interface Defaults {
@@ -72,7 +72,7 @@
public static final String STATUS_URL = "selfservlet.uri";
public static final String STATUS_URL_DEFAULT = "/Cocoon.xml";
public static final String ERROR_INTERNALLY = "handle.errors.internally";
-
+
public static final String PARSER_PROP = "parser";
public static final String PARSER_DEFAULT = "org.apache.cocoon.parser.XercesParser";
public static final String TRANSFORMER_PROP = "transformer";
@@ -87,13 +87,14 @@
public static final String FORMATTER_PROP = "formatter";
public static final String BROWSERS_PROP = "browser";
public static final String INTERPRETER_PROP = "interpreter";
-
+
public static final String COCOON_PROCESS_PI = "cocoon-process";
public static final String COCOON_FORMAT_PI = "cocoon-format";
public static final String STYLESHEET_PI = "xml-stylesheet";
-
+
public static final String DEFAULT_BROWSER = "default";
-
- public static final boolean DEBUG = false;
+
+ public static final int LOOPS = 10;
+
public static final boolean VERBOSE = true;
}
1.17 +62 -41 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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Engine.java 2000/02/13 18:29:16 1.16
+++ Engine.java 2000/02/14 00:59:18 1.17
@@ -1,4 +1,4 @@
-/*-- $Id: Engine.java,v 1.16 2000/02/13 18:29:16 stefano Exp $ --
+/*-- $Id: Engine.java,v 1.17 2000/02/14 00:59:18 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 <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.16 $ $Date: 2000/02/13 18:29:16 $
+ * @version $Revision: 1.17 $ $Date: 2000/02/14 00:59:18 $
*/
public class Engine implements Defaults {
@@ -253,47 +253,67 @@
// disabled, we need to process it
if (page == null) {
- // create the Page wrapper
- page = new Page();
-
- // get the document producer
- Producer producer = producers.getProducer(request);
-
- // set the producer as a page changeable point
- page.setChangeable(producer);
-
- // pass the produced stream to the parser
- Document document = producer.getDocument(request);
-
- // pass needed parameters to the processor pipeline
- Hashtable environment = new Hashtable();
- environment.put("path", producer.getPath(request));
- environment.put("browser", browsers.map(agent));
- environment.put("request", request);
- environment.put("response", response);
-
- // process the document through the document processors
- while (true) {
- Processor processor = processors.getProcessor(document);
- if (processor == null) break;
- document = processor.process(document, environment);
- page.setChangeable(processor);
+ // continue until the page is done.
+ for (int i = 0; i < LOOPS; i++) {
+ // catch if any OutOfMemoryError is thrown
+ try {
+ // create the Page wrapper
+ page = new Page();
+
+ // get the document producer
+ Producer producer = producers.getProducer(request);
+
+ // set the producer as a page changeable point
+ page.setChangeable(producer);
+
+ // pass the produced stream to the parser
+ Document document = producer.getDocument(request);
+
+ // pass needed parameters to the processor pipeline
+ Hashtable environment = new Hashtable();
+ environment.put("path", producer.getPath(request));
+ environment.put("browser", browsers.map(agent));
+ environment.put("request", request);
+ environment.put("response", response);
+
+ // process the document through the document processors
+ while (true) {
+ Processor processor = processors.getProcessor(document);
+ if (processor == null) break;
+ document = processor.process(document, environment);
+ page.setChangeable(processor);
+ }
+
+ // get the right formatter for the page
+ Formatter formatter = formatters.getFormatter(document);
+
+ // FIXME: I know it sucks to encapsulate a nice stream into
+ // a long String to push it into the cache. In the future,
+ // we'll find a smarter way to do it.
+
+ // format the page
+ StringWriter writer = new StringWriter();
+ formatter.format(document, writer, environment);
+
+ // fill the page bean with content
+ page.setContent(writer.toString());
+ page.setContentType(formatter.getMIMEType());
+
+ // page is done without memory errors so exit the loop
+ break;
+ } catch (OutOfMemoryError e) {
+ // force the cache to free some of its content.
+ cache.flush();
+ // reset the page to signal the error
+ page = null;
+ }
}
-
- // get the right formatter for the page
- Formatter formatter = formatters.getFormatter(document);
+ }
- // FIXME: I know it sucks to encapsulate a nice stream into
- // a long String to push it into the cache. In the future,
- // we'll find a smarter way to do it.
-
- // format the page
- StringWriter writer = new StringWriter();
- formatter.format(document, writer, environment);
-
- // fill the page bean with content
- page.setContent(writer.toString());
- page.setContentType(formatter.getMIMEType());
+ 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.");
}
if (DEBUG) {
@@ -319,6 +339,7 @@
+ (page.isCached() ? "from cache " : "")
+ "in " + time + " milliseconds by "
+ Cocoon.version() + " -->");
+ out.println("<!-- free memory: " + Runtime.getRuntime().freeMemory() + " -->");
}
// send all content so that client doesn't wait while caching.
1.14 +11 -16 xml-cocoon/src/org/apache/cocoon/cocoon.properties
Index: cocoon.properties
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/cocoon.properties,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- cocoon.properties 2000/02/13 18:29:16 1.13
+++ cocoon.properties 2000/02/14 00:59:18 1.14
@@ -8,7 +8,7 @@
# Global Configurations #
##########################################
-# Indicates whether or not Cocoon should be visible if
+# Indicates whether or not Cocoon should be visible if
# the requested URI equals the specified one.
selfservlet.enabled = true
selfservlet.uri = /Cocoon.xml
@@ -109,7 +109,7 @@
# Set the libraries associated with the given namespace.
# Use the syntax:
# processor.xsp.library.<namespace-tag>.<language> = URL to file
-# where "URL to file" is usually starting with file:// if you locate
+# where "URL to file" is usually starting with file:// if you locate
# your custom library in your file system.
processor.xsp.library.context.java = resource://org/apache/cocoon/processor/xsp/library/java/context.xsl
processor.xsp.library.cookie.java = resource://org/apache/cocoon/processor/xsp/library/java/cookie.xsl
@@ -122,13 +122,13 @@
# LDAP Processor
processor.type.ldap = org.apache.cocoon.processor.ldap.LdapProcessor
-# NOTE: see the LDAP processor user guide for the packages required for
+# NOTE: see the LDAP processor user guide for the packages required for
# this processor.
#### !!!!WARNING!!!! ###########
# The DCP processor should be considered -deprecated- and we highly suggest
-# you to convert all of your DCP stuff into XSP pages that, in the future,
+# you to convert all of your DCP stuff into XSP pages that, in the future,
# will totally replace DCP.
#
# Dynamic Content Processor (DCP)
@@ -152,20 +152,20 @@
formatter.type.text/xslfo = org.apache.cocoon.formatter.FO2PDFFormatter
formatter.type.model/vrml = org.apache.cocoon.formatter.VRMLFormatter
-# This is used when no <?cocoon?> PI is present to indicate
+# This is used when no <?cocoon?> PI is present to indicate
# which MIME type to associate to the document.
# NOTE: this type must present in the above map.
formatter.default = text/html
# Specifies the text stream format. (meaningful for text formatters only)
-# Supported styles are
+# Supported styles are
# - normal
# - compact
formatter.style = normal
-
+
##########################################
# Cache Managers #
##########################################
@@ -186,15 +186,10 @@
# the default object storage
store = org.apache.cocoon.store.MemoryStore
-# Indicate the minimum amount of memory (in bytes) that should be always
-# available to the jvm. If your JVM contains less than 300Kb free when it
-# starts you may either:
-# - lower this limit, following the indication of the throw exception.
-# - add your JVM startup heap size (suggested).
-# To the latter either:
-# - (java 1.1) add -ms<size> as command line argument
-# - (java 1.2) add -Xms<size> as command line argument
-store.memory = 200000
+# Indicate the minimum amount of memory (in bytes) that should be always
+# available to the JVM.
+# NOTE: refer to the Installation instructions for more informations on this.
+store.memory = 1000000
1.5 +23 -17 xml-cocoon/src/org/apache/cocoon/cache/Cache.java
Index: Cache.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/cache/Cache.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Cache.java 2000/02/13 18:29:18 1.4
+++ Cache.java 2000/02/14 00:59:18 1.5
@@ -1,36 +1,36 @@
-/*-- $Id: Cache.java,v 1.4 2000/02/13 18:29:18 stefano Exp $ --
+/*-- $Id: Cache.java,v 1.5 2000/02/14 00:59:18 stefano Exp $ --
============================================================================
The Apache Software License, Version 1.1
============================================================================
-
+
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
-
+
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
-
+
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-
+
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
-
+
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
-
+
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
apache@apache.org.
-
+
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
-
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
@@ -41,12 +41,12 @@
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
+ Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.cocoon.cache;
@@ -57,21 +57,27 @@
* The interface that all caching implementations must adhere to.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.4 $Date: 2000/02/13 18:29:18 $
+ * @version $Revision: 1.5 $Date: 2000/02/14 00:59:18 $
*/
-
+
public interface Cache extends Actor {
/**
* It returns null if no page is available.
- */
+ */
public Page getPage(HttpServletRequest request);
-
+
/**
* Sets the page into the cache system using data from the request
* object for indexing.
*/
public void setPage(Page page, HttpServletRequest request);
-
+
+ /**
+ * Flushes the cache and forces an additional cache cleanup. This is
+ * normally used when the system requires additional memory.
+ */
+ public void flush();
+
}
1.6 +27 -19 xml-cocoon/src/org/apache/cocoon/cache/CocoonCache.java
Index: CocoonCache.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/cache/CocoonCache.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CocoonCache.java 2000/02/13 18:29:18 1.5
+++ CocoonCache.java 2000/02/14 00:59:18 1.6
@@ -1,36 +1,36 @@
-/*-- $Id: CocoonCache.java,v 1.5 2000/02/13 18:29:18 stefano Exp $ --
+/*-- $Id: CocoonCache.java,v 1.6 2000/02/14 00:59:18 stefano Exp $ --
============================================================================
The Apache Software License, Version 1.1
============================================================================
-
+
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
-
+
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
-
+
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-
+
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
-
+
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
-
+
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
apache@apache.org.
-
+
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
-
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
@@ -41,12 +41,12 @@
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
+ Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.cocoon.cache;
@@ -62,16 +62,16 @@
* statically and dynamically generated.
*
* @author <a href="stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.5 $Date: 2000/02/13 18:29:18 $
+ * @version $Revision: 1.6 $Date: 2000/02/14 00:59:18 $
*/
public class CocoonCache implements Cache, Status {
private Store store;
-
+
public void init(Director director) {
this.store = (Store) director.getActor("store");
}
-
+
/**
* This method retrieves a page from the store
* and checks if its changeable points have changed.
@@ -84,7 +84,7 @@
if (page == null) {
return null;
}
-
+
boolean changed = false;
Enumeration e = page.getChangeables();
while (e.hasMoreElements()) {
@@ -94,19 +94,27 @@
break;
}
}
-
+
return (changed) ? null : page;
}
-
+
/**
* This method inserts the page in cache and associates it
* with the given request.
*/
public void setPage(Page page, HttpServletRequest request) {
- if (!page.isCached()) {
+ if (!page.isCached()) {
page.setCached(true);
this.store.hold(Utils.encode(request), page);
}
+ }
+
+ /**
+ * Flushes the cache and forces an additional cache cleanup. This is
+ * normally used when the system requires additional memory.
+ */
+ public void flush() {
+ this.store.free();
}
public String getStatus() {
1.5 +19 -15 xml-cocoon/src/org/apache/cocoon/cache/NoCache.java
Index: NoCache.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/cache/NoCache.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NoCache.java 2000/02/13 18:29:18 1.4
+++ NoCache.java 2000/02/14 00:59:18 1.5
@@ -1,36 +1,36 @@
-/*-- $Id: NoCache.java,v 1.4 2000/02/13 18:29:18 stefano Exp $ --
+/*-- $Id: NoCache.java,v 1.5 2000/02/14 00:59:18 stefano Exp $ --
============================================================================
The Apache Software License, Version 1.1
============================================================================
-
+
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
-
+
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
-
+
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-
+
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
-
+
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
-
+
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
apache@apache.org.
-
+
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
-
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
@@ -41,12 +41,12 @@
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
+ Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.cocoon.cache;
@@ -57,18 +57,22 @@
* A caching implementation that doesn't cache anything :).
*
* @author <a href="stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.4 $Date: 2000/02/13 18:29:18 $
+ * @version $Revision: 1.5 $Date: 2000/02/14 00:59:18 $
*/
public class NoCache extends AbstractActor implements Cache, Status {
public Page getPage(HttpServletRequest request) {
return null;
}
-
+
public void setPage(Page page, HttpServletRequest request) {
// do nothing
}
-
+
+ public void flush() {
+ Runtime.getRuntime().gc();
+ }
+
public String getStatus() {
return "<b>No cache</b>";
}
1.7 +69 -38 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- MemoryStore.java 2000/02/13 18:29:42 1.6
+++ MemoryStore.java 2000/02/14 00:59:19 1.7
@@ -1,36 +1,36 @@
-/*-- $Id: MemoryStore.java,v 1.6 2000/02/13 18:29:42 stefano Exp $ --
+/*-- $Id: MemoryStore.java,v 1.7 2000/02/14 00:59:19 stefano Exp $ --
============================================================================
The Apache Software License, Version 1.1
============================================================================
-
+
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
-
+
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
-
+
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-
+
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
-
+
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
-
+
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
apache@apache.org.
-
+
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
-
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
@@ -41,12 +41,12 @@
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
+ Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.cocoon.store;
@@ -65,20 +65,20 @@
* sending a note about a method to do it.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.6 $ $Date: 2000/02/13 18:29:42 $
+ * @version $Revision: 1.7 $ $Date: 2000/02/14 00:59:19 $
*/
public class MemoryStore implements Store, Configurable, Status {
-
+
private Runtime jvm;
private int memory;
private Hashtable hashtable;
-
+
class Container {
public Object object;
public long time = 0;
public int count = 0;
-
+
public Container(Object object) {
this.object = object;
}
@@ -89,38 +89,59 @@
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"));
- if (memory <= 0)
+ // 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. (free memory available:" + jvm.freeMemory() + "). See documentation and FAQ on how to solve this problem.");
+ 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
* different JVM executions.
- */
+ */
public void store(Object key, Object value) {
throw new RuntimeException("Method MemoryStore.store() not implemented!");
}
-
+
/**
* Holds the given object in a volatile state. This means
* the object store will discard held objects if the
* virtual machine is restarted or some error happens.
- */
+ */
public synchronized void hold(Object key, Object object) {
-
+
while (jvm.freeMemory() < memory) {
- Object worst = this.getWorst();
- if (worst != null) this.hashtable.remove(worst);
- jvm.runFinalization();
- jvm.gc();
+ this.free();
}
-
+
this.hashtable.put(key, new Container(object));
}
@@ -160,7 +181,17 @@
public synchronized Enumeration list() {
return this.hashtable.keys();
}
-
+
+ /**
+ * Frees some of the fast memory used by this store.
+ */
+ public void free() {
+ Object worst = this.getWorst();
+ if (worst != null) this.hashtable.remove(worst);
+ jvm.runFinalization();
+ jvm.gc();
+ }
+
/**
* This method returns the key to the worst object included.
*
@@ -170,15 +201,15 @@
* it may be called more than once per each insert
* method in the cache and its complexity is currently
* linear with the cache size.
- */
+ */
private Object getWorst() {
long time = System.currentTimeMillis();
long minimum = Long.MAX_VALUE;
Object minimumKey = null;
-
+
Enumeration keys = this.hashtable.keys();
Enumeration values = this.hashtable.elements();
-
+
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Container value = (Container) values.nextElement();
@@ -188,28 +219,28 @@
minimumKey = key;
}
}
-
+
return minimumKey;
}
-
+
/**
* This method evaluates every contained object and is
* a function of LRU (last recently used) and LFU (last frequenly used)
* paradigms.
*
* NOTE: this evaluation system may be rendered pluggable if different
- * paradigms are found better for different situations. At this point,
+ * paradigms are found better for different situations. At this point,
* I'm not sure this counts that much.
*/
private long evaluate(Container c, long time) {
return (factor * c.count) + (Long.MAX_VALUE >> 1) - (time - c.time);
}
-
- /**
+
+ /**
* Indicates the factor of LFU compared to LRU. See code for more details.
*/
private static final long factor = 2;
-
+
/**
* Returns the signature of this store implementation
*/
@@ -223,5 +254,5 @@
buffer.append("</li>");
}
return buffer.toString();
- }
+ }
}
1.6 +25 -20 xml-cocoon/src/org/apache/cocoon/store/Store.java
Index: Store.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/store/Store.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Store.java 2000/02/13 18:29:42 1.5
+++ Store.java 2000/02/14 00:59:19 1.6
@@ -1,36 +1,36 @@
-/*-- $Id: Store.java,v 1.5 2000/02/13 18:29:42 stefano Exp $ --
+/*-- $Id: Store.java,v 1.6 2000/02/14 00:59:19 stefano Exp $ --
============================================================================
The Apache Software License, Version 1.1
============================================================================
-
+
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
-
+
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
-
+
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-
+
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
-
+
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
-
+
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
apache@apache.org.
-
+
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
-
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
@@ -41,12 +41,12 @@
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
+
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
- Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
+ Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-
+
*/
package org.apache.cocoon.store;
@@ -59,7 +59,7 @@
* implement.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.5 $ $Date: 2000/02/13 18:29:42 $
+ * @version $Revision: 1.6 $ $Date: 2000/02/14 00:59:19 $
*/
public interface Store {
@@ -68,34 +68,39 @@
* Get the object associated to the given unique key.
*/
Object get(Object key);
-
+
/**
* Store the given object in a persistent state. It is up to the
* caller to ensure that the key has a persistent state across
* different JVM executions.
- */
+ */
void store(Object key, Object value);
/**
* Holds the given object in a volatile state. This means
* the object store will discard held objects if the
* virtual machine is restarted or some error happens.
- */
+ */
void hold(Object key, Object value);
-
+
/**
* Remove the object associated to the given key.
*/
void remove(Object key);
-
+
/**
* Indicates if the given key is associated to a contained object.
*/
boolean containsKey(Object key);
-
+
/**
* Returns the list of used keys.
*/
Enumeration list();
-
+
+ /**
+ * Frees some of the fast memory used by this store.
+ */
+ void free();
+
}