Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 19194 invoked by uid 500); 22 Aug 2001 03:22:00 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 19185 invoked by uid 500); 22 Aug 2001 03:22:00 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 22 Aug 2001 03:16:40 -0000 Message-ID: <20010822031640.889.qmail@icarus.apache.org> From: vgritsenko@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/src/org/apache/cocoon/components/store MRUMemoryStore.java X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N vgritsenko 01/08/21 20:16:40 Modified: src/org/apache/cocoon/components/store Tag: cocoon_20_branch MRUMemoryStore.java Log: fixing memory leaks Revision Changes Path No revision No revision 1.2.2.11 +25 -29 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.10 retrieving revision 1.2.2.11 diff -u -r1.2.2.10 -r1.2.2.11 --- MRUMemoryStore.java 2001/08/20 19:18:46 1.2.2.10 +++ MRUMemoryStore.java 2001/08/22 03:16:40 1.2.2.11 @@ -37,7 +37,7 @@ * The objects can also be stored onto the filesystem to hold them in a * persitent state over jvm restarts. * - * The idea was token from the "Writing Advanced Applikation Tutorial" from + * The idea was taken from the "Writing Advanced Application Tutorial" from * javasoft. Many thanx to the writers! * * @author Gerhard Froehlich @@ -154,7 +154,6 @@ */ public void configure(Configuration conf) throws ConfigurationException { this.jvm = Runtime.getRuntime(); - this.cache = new HashMap(75); this.mrulist = new LinkedList(); this.writerstack = new Stack(); @@ -163,6 +162,7 @@ this.heapsize = params.getParameterAsInteger("heapsize",60000000); this.cleanupthreadinterval = params.getParameterAsInteger("cleanupthreadinterval",10); this.maxobjects = params.getParameterAsInteger("maxobjects",100); + this.cache = new HashMap((int)(this.maxobjects * 1.2)); this.priority = params.getParameterAsInteger("threadpriority",Thread.currentThread().getPriority()); this.filesystem = params.getParameterAsBoolean("filesystem",false); if ((this.priority < 1) || (this.priority > 10)) { @@ -203,8 +203,8 @@ * Thread writer writes objects from the writer stack onto the filesystem. */ public void run() { - while (true) { - if(Thread.currentThread().getName().equals("checker")) { + if(Thread.currentThread().getName().equals("checker")) { + while (true) { if (this.jvm.totalMemory() > this.heapsize) { this.jvm.runFinalization(); this.jvm.gc(); @@ -217,13 +217,14 @@ try { Thread.currentThread().sleep(this.cleanupthreadinterval * 1000); } catch (InterruptedException ignore) {} - } else if(Thread.currentThread().getName().equals("writer")) { + } + } else if(Thread.currentThread().getName().equals("writer")) { + while (true) { + getLogger().debug("Writerthread awake!"); while(!writerstack.empty()) { try { - getLogger().debug("Writerthread awake!"); TmpStackObject tmp = (TmpStackObject)this.writerstack.pop(); - String key = tmp.getKey().toString(); - this.fsstore.store(getFileName(key), tmp.getObject()); + this.fsstore.store(getFileName(tmp.getKey().toString()), tmp.getObject()); } catch(java.io.IOException e) { getLogger().error("Error in writer thread",e); } catch(Exception ex) { @@ -256,34 +257,28 @@ public void hold(Object key, Object value) { getLogger().debug("Holding object in memory. key: " + key); getLogger().debug("Holding object in memory. value: " + value); - boolean serialisedFlag; /** ...first test if the max. objects in cache is reached... */ - if(this.mrulist.size() >= this.maxobjects) { + while (this.mrulist.size() >= this.maxobjects) { /** ...ok, heapsize is reached, remove the last element... */ this.free(); } /** put the object on the filesystem */ if(this.filesystem) { - if(this.checkSeriazable(value)) { + if(this.checkSerializable(value)) { getLogger().debug("Storing object on fs"); this.writerstack.push(new TmpStackObject(key,value)); getLogger().debug("Stack size=" + writerstack.size()); - serialisedFlag = true; synchronized (this.writer) { this.writer.notify(); } - } else { - serialisedFlag = false; } - } else { - serialisedFlag = false; } /** ..put the new object in the cache, on the top of course ... */ - this.cache.put(key, new CacheObject(value,System.currentTimeMillis(),serialisedFlag)); + this.cache.put(key, value); + this.mrulist.remove(key); this.mrulist.addFirst(key); - getLogger().debug("Hashmap size=" + cache.size()); } /** @@ -297,7 +292,7 @@ /** put the accessed key on top of the linked list */ this.mrulist.remove(key); this.mrulist.addFirst(key); - return ((CacheObject)this.cache.get(key)).getCacheObject(); + return this.cache.get(key); } catch(NullPointerException e) { getLogger().debug("Object not found in memory"); /** try to fetch from filesystem */ @@ -334,7 +329,7 @@ getLogger().debug("Removing object from store"); this.cache.remove(key); this.mrulist.remove(key); - this.fsstore.remove(this.cachedirstr + File.separator + URLEncoder.encode(key.toString())); + this.fsstore.remove(getFileName(key.toString())); } /** @@ -360,7 +355,6 @@ */ public void free() { try { - getLogger().debug("Freeing store"); this.cache.remove(this.mrulist.getLast()); this.mrulist.removeLast(); } catch (Exception e) { @@ -373,7 +367,7 @@ * FIXME: In the moment only CachedEventObject or * CachedStreamObject are stored. */ - private boolean checkSeriazable(Object object) { + private boolean checkSerializable(Object object) { try { getLogger().debug("Object=" + object); if((object.getClass().getName().equals("org.apache.cocoon.caching.CachedEventObject")) @@ -384,7 +378,7 @@ return false; } } catch (Exception e) { - getLogger().error("Error in checkSeriazable()!", e); + getLogger().error("Error in checkSerializable()!", e); return false; } } @@ -399,21 +393,20 @@ .append(URLEncoder.encode(key.toString())) .toString(); } - + /** * Container object for the documents. - */ class CacheObject { private long time = -1; private Object cacheObject; private boolean serialised; - + public CacheObject(Object ToCacheObject, long lTime, boolean serialised) { this.cacheObject = ToCacheObject; this.time = lTime; this.serialised = serialised; } - + public Object getCacheObject() { return this.cacheObject; } @@ -426,9 +419,12 @@ return this.serialised; } } + */ - /** Temporary container object for the writerstack */ - class TmpStackObject { + /** + * Temporary container object for the writerstack + */ + static class TmpStackObject { private Object object; private Object key; ---------------------------------------------------------------------- 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