You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/10/10 11:23:08 UTC
cvs commit: xml-cocoon2/src/org/apache/cocoon/components/store MRUMemoryStore.java
cziegeler 01/10/10 02:23:08
Modified: src/org/apache/cocoon/components/store MRUMemoryStore.java
Log:
NPE Patch for MRUMemoryStore
Submitted by: Ovidiu Predescu [ovidiu@cup.hp.com]
Revision Changes Path
1.21 +63 -41 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.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- MRUMemoryStore.java 2001/10/08 20:03:15 1.20
+++ MRUMemoryStore.java 2001/10/10 09:23:08 1.21
@@ -7,28 +7,50 @@
*****************************************************************************/
package org.apache.cocoon.components.store;
-import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLoggable;
-import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.cocoon.Constants;
-import org.apache.cocoon.util.ClassUtils;
-import org.apache.cocoon.util.IOUtils;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URLEncoder;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.LinkedList;
+import org.apache.avalon.framework.component.ComponentException;
+
+import org.apache.avalon.framework.component.ComponentManager;
+
+import org.apache.avalon.framework.component.Composable;
+
+import org.apache.avalon.framework.configuration.Configurable;
+
+import org.apache.avalon.framework.configuration.Configuration;
+
+import org.apache.avalon.framework.configuration.ConfigurationException;
+
+import org.apache.avalon.framework.context.Context;
+
+import org.apache.avalon.framework.context.ContextException;
+
+import org.apache.avalon.framework.context.Contextualizable;
+
+import org.apache.avalon.framework.logger.AbstractLoggable;
+
+import org.apache.avalon.framework.parameters.Parameters;
+
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.cocoon.Constants;
+
+import org.apache.cocoon.util.ClassUtils;
+
+import org.apache.cocoon.util.IOUtils;
+
+
+
+import java.io.File;
+
+import java.io.IOException;
+
+import java.net.URLEncoder;
+
+import java.util.Enumeration;
+
+import java.util.HashMap;
+
+import java.util.LinkedList;
+
import java.util.Stack;
/**
@@ -45,11 +67,11 @@
* @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
*/
-public class MRUMemoryStore extends AbstractLoggable implements Store, Configurable,
- ThreadSafe, Runnable,
+public class MRUMemoryStore extends AbstractLoggable implements Store, Configurable,
+ ThreadSafe, Runnable,
Composable, Contextualizable {
-
-
+
+
private int priority;
private int maxobjects;
private boolean filesystem;
@@ -68,7 +90,7 @@
/**
* Get components of the ComponentManager
- *
+ *
* @param the ComponentManager
*/
public void compose(ComponentManager manager) throws ComponentException {
@@ -82,7 +104,7 @@
getLogger().error("Error in compose()!", e);
}
}
-
+
/**
* Get the context
*
@@ -96,9 +118,9 @@
this.workdir = (File)context.get(Constants.CONTEXT_WORK_DIR);
this.cachedirstr = IOUtils.getContextFilePath(this.workdir.getPath(),
this.cachedir.getPath());
-
- getLogger().debug("Context path="
- + IOUtils.getContextFilePath(this.workdir.getPath(),this.cachedir.getPath()));
+
+ getLogger().debug("Context path="
+ + IOUtils.getContextFilePath(this.workdir.getPath(),this.cachedir.getPath()));
} catch (Exception e) {
getLogger().error("Error in contextualize()",e);
@@ -123,7 +145,7 @@
this.writerstack = new Stack();
this.storejanitor.register(this);
-
+
Parameters params = Parameters.fromConfiguration(conf);
this.maxobjects = params.getParameterAsInteger("maxobjects",100);
this.cache = new HashMap((int)(this.maxobjects * 1.2));
@@ -156,7 +178,7 @@
try {
TmpStackObject tmp = (TmpStackObject)this.writerstack.pop();
this.fsstore.store(getFileName(tmp.getKey().toString()), tmp.getObject());
- } catch(IOException e) {
+ } catch(IOException e) {
getLogger().error("Error in writer thread",e);
} catch(Exception ex) {
getLogger().error("Error in writer thread",ex);
@@ -170,7 +192,7 @@
}
}
}
-
+
/**
* Store the given object in a persistent state. It is up to the
* caller to ensure that the key has a persistent state across
@@ -184,7 +206,7 @@
}
/**
- * This method holds the requested object in a HashMap combined
+ * This method holds the requested object in a HashMap combined
* with a LinkedList to create the MRU.
* It also stores objects onto the filesystem if configured.
*
@@ -194,7 +216,7 @@
public void hold(Object key, Object value) {
getLogger().debug("Holding object in memory. key: " + key);
getLogger().debug("Holding object in memory. value: " + value);
-
+
/** ...first test if the max. objects in cache is reached... */
while (this.mrulist.size() >= this.maxobjects) {
/** ...ok, heapsize is reached, remove the last element... */
@@ -208,7 +230,7 @@
this.writerstack.push(new TmpStackObject(key,value));
getLogger().debug("Stack size=" + writerstack.size());
synchronized (this.writer) {
- this.writer.notify();
+ this.writer.notify();
}
}
}
@@ -270,7 +292,7 @@
getLogger().debug("Removing object from store");
this.cache.remove(key);
this.mrulist.remove(key);
- if(this.filesystem) {
+ if(this.filesystem && key != null) {
this.fsstore.remove(getFileName(key.toString()));
}
}
@@ -315,7 +337,7 @@
}
/**
- * This method checks if an object is seriazable.
+ * This method checks if an object is seriazable.
* FIXME: In the moment only CachedEventObject or
* CachedStreamObject are stored.
*
@@ -325,7 +347,7 @@
private boolean checkSerializable(Object object) {
try {
getLogger().debug("Object=" + object);
- if((object.getClass().getName().equals("org.apache.cocoon.caching.CachedEventObject"))
+ 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"))) {
return true;
@@ -339,7 +361,7 @@
}
/**
- * This method puts together a filename for
+ * This method puts together a filename for
* the object, which shall be stored on the
* filesystem.
*
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org