vgritsenko    01/08/23 05:20:34

  Modified:    src/org/apache/cocoon/components/store MRUMemoryStore.java
  Log:
  patch from Rick Tessner [[EMAIL PROTECTED]]
  
  Revision  Changes    Path
  1.14      +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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- MRUMemoryStore.java       2001/08/22 03:15:43     1.13
  +++ MRUMemoryStore.java       2001/08/23 12:20:33     1.14
  @@ -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]

Reply via email to