vgritsenko 01/08/23 05:22:24
Modified: src/org/apache/cocoon/components/store Tag: cocoon_20_branch
MRUMemoryStore.java
Log:
Rick Tessner [[EMAIL PROTECTED]]
Revision Changes Path
No revision
No revision
1.2.2.12 +29 -27
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.11
retrieving revision 1.2.2.12
diff -u -r1.2.2.11 -r1.2.2.12
--- MRUMemoryStore.java 2001/08/22 03:16:40 1.2.2.11
+++ MRUMemoryStore.java 2001/08/23 12:22:23 1.2.2.12
@@ -24,6 +24,7 @@
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;
@@ -205,7 +206,8 @@
public void run() {
if(Thread.currentThread().getName().equals("checker")) {
while (true) {
- if (this.jvm.totalMemory() > this.heapsize) {
+ // amount of memory used is greater then heapsize
+ if (this.jvm.totalMemory() - this.jvm.freeMemory() > this.heapsize) {
this.jvm.runFinalization();
this.jvm.gc();
synchronized (this) {
@@ -225,7 +227,7 @@
try {
TmpStackObject tmp = (TmpStackObject)this.writerstack.pop();
this.fsstore.store(getFileName(tmp.getKey().toString()),
tmp.getObject());
- } catch(java.io.IOException e) {
+ } catch(IOException e) {
getLogger().error("Error in writer thread",e);
} catch(Exception ex) {
getLogger().error("Error in writer thread",ex);
@@ -286,39 +288,39 @@
*/
public Object get(Object key) {
getLogger().debug("Getting object from memory. Key: " + key);
- Object tmpobject = new Object();
- try {
+ Object tmpobject = this.cache.get(key);
+ if ( tmpobject != null ) {
/** put the accessed key on top of the linked list */
this.mrulist.remove(key);
this.mrulist.addFirst(key);
- return this.cache.get(key);
- } catch(NullPointerException e) {
- getLogger().debug("Object not found in memory");
- /** try to fetch from filesystem */
- if(this.filesystem) {
- tmpobject = this.fsstore.get(getFileName(key.toString()));
- if (tmpobject == null) {
- getLogger().debug( "Object was NOT found on fs. Looked for: " +
URLEncoder.encode(key.toString()) );
+ return tmpobject;
+ }
+
+ getLogger().debug("Object not found in memory");
+ /** try to fetch from filesystem */
+ if(this.filesystem) {
+ tmpobject = this.fsstore.get(getFileName(key.toString()));
+ if (tmpobject == null) {
+ getLogger().debug( "Object was NOT found on fs. Looked for: " +
URLEncoder.encode(key.toString()) );
+ return null;
+ } else {
+ getLogger().debug("Object was found on fs");
+ try {
+ tmpobject = IOUtils.deserializeObject((File)tmpobject);
+ this.hold(key,tmpobject);
+ return tmpobject;
+ } catch (ClassNotFoundException ce) {
+ getLogger().error("Error in get()!", ce);
return null;
- } else {
- getLogger().debug("Object was found on fs");
- try {
- tmpobject = IOUtils.deserializeObject((File)tmpobject);
- this.hold(key,tmpobject);
- return tmpobject;
- } catch (ClassNotFoundException ce) {
- getLogger().error("Error in get()!",e);
- return null;
- } catch (java.io.IOException ioe) {
- getLogger().error("Error in get()!",e);
- return null;
- }
+ } catch (IOException ioe) {
+ getLogger().error("Error in get()!", ioe);
+ return null;
}
- } else {
- return null;
}
}
+
+ return null;
}
/**
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]