cziegeler 01/07/17 03:41:24
Modified: src/org/apache/cocoon/components/store Tag: cocoon_20_branch
MRUMemoryStore.java
webapp Tag: cocoon_20_branch cocoon.xconf
Log:
Applied patch for fixing a NPE
Submitted by: Gerhard Froehlich
Revision Changes Path
No revision
No revision
1.2.2.3 +24 -24
xml-cocoon2/src/org/apache/cocoon/components/store/MRUMemoryStore.java
Index: MRUMemoryStore.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/store/MRUMemoryStore.java,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -u -r1.2.2.2 -r1.2.2.3
--- MRUMemoryStore.java 2001/07/15 20:47:39 1.2.2.2
+++ MRUMemoryStore.java 2001/07/17 10:41:22 1.2.2.3
@@ -82,11 +82,6 @@
private boolean filesystem;
/**
- * Indicates the interval of the WriterThread
- */
- private int writerthreadinterval;
-
- /**
* The heart of the cache
*/
private HashMap cache;
@@ -97,6 +92,7 @@
private File cachefile;
private Store fsstore;
private Stack writerstack;
+ private Thread writer;
/** the component manager */
protected ComponentManager manager;
@@ -121,7 +117,6 @@
* <LI>maxobjects = how many objects will be stored in memory (Default: 10o
objects)</LI>
* <LI>threadpriority = priority of the thread (1-10). (Default: 10)</LI>
* <LI>filesystem = use filesystem storage to keep object persistent (Default:
false)</LI>
- * <LI>writerthreadinterval = time in millis to sleep between writing onto the
filesystem (Default: 100 millis)</LI>
* <LI>usecleanupthread = use a cleanup daemon thread. (Default: true)</LI>
* </UL>
*/
@@ -138,13 +133,9 @@
this.maxobjects = params.getParameterAsInteger("maxobjects",100);
this.priority =
params.getParameterAsInteger("threadpriority",Thread.currentThread().getPriority());
this.filesystem = params.getParameterAsBoolean("filesystem",false);
- this.writerthreadinterval =
params.getParameterAsInteger("writerthreadinterval",100);
if ((this.priority < 1) || (this.priority > 10)) {
throw new ConfigurationException("MRUMemoryStore cleanup thread priority must
be between 1 and 10!");
}
- if ((this.writerthreadinterval < 1)) {
- throw new ConfigurationException("MRUMemoryStore writer thread interval must
be at least 1 millis!");
- }
if ((this.maxobjects < 1)) {
throw new ConfigurationException("MRUMemoryStore maxobjects must be at least
1 milli second!");
}
@@ -165,7 +156,7 @@
if (this.filesystem) {
getLogger().debug("MRUMemoryStore intializing writer thread");
- Thread writer = new Thread(this);
+ writer = new Thread(this);
writer.setPriority(this.priority);
writer.setDaemon(true);
writer.setName("writer");
@@ -195,8 +186,9 @@
Thread.currentThread().sleep(this.cleanupthreadinterval * 1000);
} catch (InterruptedException ignore) {}
} else if(Thread.currentThread().getName().equals("writer")) {
- if(!writerstack.empty()) {
+ while(!writerstack.empty()) {
try {
+ getLogger().debug("MRUMemoryStore writerthread awake!");
TmpStackObject tmpstackobject = new TmpStackObject();
Object key = new Object();
Object object = new Object();
@@ -213,9 +205,13 @@
getLogger().error("Error in MRUMemoryStore",ex);
}
}
- try {
- Thread.currentThread().sleep(this.writerthreadinterval);
- } catch (InterruptedException ignore) {}
+ synchronized (this.writer) {
+ try {
+ writer.wait();
+ } catch (InterruptedException e) {
+ getLogger().error("Error in MRUMemoryStore:",e);
+ }
+ }
}
}
}
@@ -235,7 +231,8 @@
* It also can store the objects onto the filesystem if configured.
*/
public void hold(Object key, Object value) {
- getLogger().debug("MRUMemoryStore holding object in memory. Key: " + key);
+ getLogger().debug("MRUMemoryStore holding object in memory. key: " + key);
+ getLogger().debug("MRUMemoryStore holding object in memory. value: " + value);
boolean serialisedFlag;
/** ...first test if the max. objects in cache is reached... */
@@ -251,6 +248,9 @@
this.writerstack.push(new TmpStackObject(key,value));
getLogger().debug("MRUMemoryStore stack size=" + writerstack.size());
serialisedFlag = true;
+ synchronized (this.writer) {
+ this.writer.notify();
+ }
} else {
serialisedFlag = false;
}
@@ -268,7 +268,6 @@
*/
public Object get(Object key) {
getLogger().debug("MRUMemoryStore getting object from memory. Key: " + key);
- //CacheObject tmpobject = new CacheObject();
Object tmpobject = new Object();
try {
@@ -284,8 +283,7 @@
if (tmpobject == null) {
return null;
} else {
- getLogger().debug("MRUMemoryStor found object on fs");
-
+ getLogger().debug("MRUMemoryStore found object on fs");
try {
tmpobject = IOUtils.deserializeObject((File)tmpobject);
this.hold(key,tmpobject);
@@ -337,19 +335,21 @@
* It removes the last element in the cache.
*/
public void free() {
- if(this.checkSeriazable(cache.get(this.mrulist.getLast()))) {
- this.writerstack.push(new
TmpStackObject(this.mrulist.getLast(),cache.get(this.mrulist.getLast())));
+ try {
+ getLogger().debug("MRUMemoryStore freeing store");
+ this.cache.remove(this.mrulist.getLast());
+ this.mrulist.removeLast();
+ } catch (Exception e) {
+ getLogger().error("Error in MRUMemoryStore:",e);
}
- this.cache.remove(this.mrulist.getLast());
- this.mrulist.removeLast();
}
/**
* This method checks if an object is seriazable
*/
private boolean checkSeriazable(Object object) {
- getLogger().debug("MRUMemoryStore checkSeriazable(): " +
object.getClass().getName());
try {
+ getLogger().debug("MRUMemoryStore object=" + object);
if((object.getClass().getName().equals("org.apache.cocoon.caching.CachedEventObject"))
||
(object.getClass().getName().equals("org.apache.cocoon.caching.CachedStreamObject"))
||
(ClassUtils.implementsInterface(object.getClass().getName(),"org.apache.cocoon.caching.CacheValidity")))
{
No revision
No revision
1.7.2.13 +6 -19 xml-cocoon2/webapp/cocoon.xconf
Index: cocoon.xconf
===================================================================
RCS file: /home/cvs/xml-cocoon2/webapp/cocoon.xconf,v
retrieving revision 1.7.2.12
retrieving revision 1.7.2.13
diff -u -r1.7.2.12 -r1.7.2.13
--- cocoon.xconf 2001/07/16 13:23:35 1.7.2.12
+++ cocoon.xconf 2001/07/17 10:41:23 1.7.2.13
@@ -31,9 +31,6 @@
threadpriority: Indicates the priority of the cleanup thread.
(1 is the lowest priority and 10 is the highest).
filesystem: Turns the filesystem storage for objects on or off.
- writerthreadinterval: Inidicates the interval of the writer thread in millis.
- This background threads writes objects onto the
- filesystem.
-->
<store class="org.apache.cocoon.components.store.MRUMemoryStore">
<parameter name="freememory" value="1000000"/>
@@ -42,8 +39,7 @@
<parameter name="maxobjects" value="100"/>
<parameter name="usecleanupthread" value="true"/>
<parameter name="threadpriority" value="5"/>
- <parameter name="filesystem" value="false"/>
- <parameter name="writerthreadinterval" value="100"/>
+ <parameter name="filesystem" value="true"/>
</store>
<!-- The url factory adds special url protocols to the system, they
@@ -66,10 +62,6 @@
<parameter name="preload" value="true"/>
</program-generator>
- <jsp-engine>
- <parameter name="servlet-class" value="org.apache.jasper.servlet.JspServlet"/>
- </jsp-engine>
-
<programming-languages>
<java-language name="java">
<!-- compiler parameter specifies which class to use to compile Java.
@@ -183,9 +175,9 @@
The default is true.
-->
- <dburl>@database-url@</dburl>
- <user>@database-user@</user>
- <password>@database-password@</password>
+ <dburl>jdbc:hsqldb:${install.war}/cocoon/WEB-INF/db/cocoondb</dburl>
+ <user>sa</user>
+ <password></password>
</jdbc>
</datasources>
@@ -209,9 +201,6 @@
threadpriority: Indicates the priority of the cleanup thread.
(1 is the lowest priority and 10 is the highest).
filesystem: Turns the filesystem storage for objects on or off.
- writerthreadinterval: Inidicates the interval of the writer thread in millis.
- This background threads writes objects onto the
- filesystem.
-->
<stream-cache class="org.apache.cocoon.components.store.MRUMemoryStore">
<parameter name="freememory" value="1000000"/>
@@ -220,8 +209,7 @@
<parameter name="maxobjects" value="100"/>
<parameter name="usecleanupthread" value="true"/>
<parameter name="threadpriority" value="5"/>
- <parameter name="filesystem" value="false"/>
- <parameter name="writerthreadinterval" value="500"/>
+ <parameter name="filesystem" value="true"/>
</stream-cache>
<!-- An EventPipeline connects the generator and the various transformers
@@ -255,8 +243,7 @@
<parameter name="maxobjects" value="100"/>
<parameter name="usecleanupthread" value="true"/>
<parameter name="threadpriority" value="5"/>
- <parameter name="filesystem" value="false"/>
- <parameter name="writerthreadinterval" value="500"/>
+ <parameter name="filesystem" value="true"/>
</event-cache>
<!-- The SAXConnector connects the various pipeline components.
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]