vgritsenko 01/08/20 08:46:08
Modified: src/org/apache/cocoon/components/store MRUMemoryStore.java
Log:
minor changes:
- logging
- file naming logic in separate method
Revision Changes Path
1.11 +41 -39
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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MRUMemoryStore.java 2001/08/20 13:55:13 1.10
+++ MRUMemoryStore.java 2001/08/20 15:46:08 1.11
@@ -115,7 +115,7 @@
getLogger().debug("Looking up FilesystemStore" + FilesystemStore.ROLE);
this.fsstore = (Store)manager.lookup(Store.ROLE + "/Filesystem");
} catch(ComponentException e) {
- getLogger().error("Error in MRUMemoryStore!",e);
+ getLogger().error("Error in compose()!", e);
}
}
@@ -131,11 +131,11 @@
this.cachedirstr = IOUtils.getContextFilePath(this.workdir.getPath(),
this.cachedir.getPath());
- getLogger().debug("MRUMemoryStore context path="
+ getLogger().debug("Context path="
+
IOUtils.getContextFilePath(this.workdir.getPath(),this.cachedir.getPath()));
} catch (Exception e) {
- getLogger().error("Error in MRUMemoryStore()",e);
+ getLogger().error("Error in contextualize()",e);
}
}
@@ -178,7 +178,7 @@
this.usecleanupthread =
params.getParameter("usecleanupthread","true").equals("true");
if (this.usecleanupthread) {
- getLogger().debug("MRUMemoryStore intializing checker thread");
+ getLogger().debug("Intializing checker thread");
Thread checker = new Thread(this);
checker.setPriority(this.priority);
checker.setDaemon(true);
@@ -187,7 +187,7 @@
}
if (this.filesystem) {
- getLogger().debug("MRUMemoryStore intializing writer thread");
+ getLogger().debug("Intializing writer thread");
writer = new Thread(this);
writer.setPriority(this.priority);
writer.setDaemon(true);
@@ -220,29 +220,20 @@
} else if(Thread.currentThread().getName().equals("writer")) {
while(!writerstack.empty()) {
try {
- getLogger().debug("MRUMemoryStore writerthread awake!");
- TmpStackObject tmpstackobject = new TmpStackObject();
- Object key = new Object();
- Object object = new Object();
- tmpstackobject = (TmpStackObject)this.writerstack.pop();
- key = tmpstackobject.getKey();
- object = tmpstackobject.getObject();
- this.fsstore.store(this.cachedirstr + File.separator +
URLEncoder.encode(key.toString()),object);
- key = null;
- object = null;
- tmpstackobject = null;
+ getLogger().debug("Writerthread awake!");
+ TmpStackObject tmp = (TmpStackObject)this.writerstack.pop();
+ String key = tmp.getKey().toString();
+ this.fsstore.store(getFileName(key), tmp.getObject());
} catch(java.io.IOException e) {
- getLogger().error("Error in MRUMemoryStore",e);
+ getLogger().error("Error in writer thread",e);
} catch(Exception ex) {
- getLogger().error("Error in MRUMemoryStore",ex);
+ getLogger().error("Error in writer thread",ex);
}
}
synchronized (this.writer) {
try {
writer.wait();
- } catch (InterruptedException e) {
- getLogger().error("Error in MRUMemoryStore:",e);
- }
+ } catch (InterruptedException ignored) {}
}
}
}
@@ -263,8 +254,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. value: " + 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... */
@@ -276,9 +267,9 @@
/** put the object on the filesystem */
if(this.filesystem) {
if(this.checkSeriazable(value)) {
- getLogger().debug("MRUMemoryStore storing object on fs");
+ getLogger().debug("Storing object on fs");
this.writerstack.push(new TmpStackObject(key,value));
- getLogger().debug("MRUMemoryStore stack size=" + writerstack.size());
+ getLogger().debug("Stack size=" + writerstack.size());
serialisedFlag = true;
synchronized (this.writer) {
this.writer.notify();
@@ -292,14 +283,14 @@
/** ..put the new object in the cache, on the top of course ... */
this.cache.put(key, new
CacheObject(value,System.currentTimeMillis(),serialisedFlag));
this.mrulist.addFirst(key);
- getLogger().debug("MRUMemoryStore hashmap size=" + cache.size());
+ getLogger().debug("Hashmap size=" + cache.size());
}
/**
* Get the object associated to the given unique key.
*/
public Object get(Object key) {
- getLogger().debug("MRUMemoryStore getting object from memory. Key: " + key);
+ getLogger().debug("Getting object from memory. Key: " + key);
Object tmpobject = new Object();
try {
@@ -308,24 +299,24 @@
this.mrulist.addFirst(key);
return ((CacheObject)this.cache.get(key)).getCacheObject();
} catch(NullPointerException e) {
- getLogger().debug("MRUMemoryStore object not found in memory");
+ getLogger().debug("Object not found in memory");
/** try to fetch from filesystem */
if(this.filesystem) {
- tmpobject = this.fsstore.get(this.cachedirstr + File.separator +
URLEncoder.encode(key.toString()));
+ tmpobject = this.fsstore.get(getFileName(key.toString()));
if (tmpobject == null) {
- getLogger().debug( "MRUMemoryStore did NOT find object on fs. Looked for: "
+ URLEncoder.encode(key.toString()) );
+ getLogger().debug( "Object was NOT found on fs. Looked for: " +
URLEncoder.encode(key.toString()) );
return null;
} else {
- getLogger().debug("MRUMemoryStore found object on fs");
+ 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 MRUMemoryStore!",e);
+ getLogger().error("Error in get()!",e);
return null;
} catch (java.io.IOException ioe) {
- getLogger().error("Error in MRUMemoryStore!",e);
+ getLogger().error("Error in get()!",e);
return null;
}
}
@@ -340,7 +331,7 @@
* the object associated to the given key or null if not found.
*/
public void remove(Object key) {
- getLogger().debug("MRUMemoryStore removing object from store");
+ 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()));
@@ -369,11 +360,11 @@
*/
public void free() {
try {
- getLogger().debug("MRUMemoryStore freeing store");
+ getLogger().debug("Freeing store");
this.cache.remove(this.mrulist.getLast());
this.mrulist.removeLast();
} catch (Exception e) {
- getLogger().error("Error in MRUMemoryStore:",e);
+ getLogger().error("Error in free()", e);
}
}
@@ -384,7 +375,7 @@
*/
private boolean checkSeriazable(Object object) {
try {
- getLogger().debug("MRUMemoryStore object=" + object);
+ getLogger().debug("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")))
{
@@ -393,11 +384,22 @@
return false;
}
} catch (Exception e) {
- getLogger().error("Error in MRUMemoryStore!",e);
+ getLogger().error("Error in checkSeriazable()!", e);
return false;
}
}
-
+
+ private String getFileName(String key)
+ {
+ return new StringBuffer()
+ .append(this.cachedirstr)
+ .append(File.separator)
+// .append(HashUtil.hash(key.toString()) & 0x1F)
+// .append(File.separator)
+ .append(URLEncoder.encode(key.toString()))
+ .toString();
+ }
+
/**
* Container object for the documents.
*/
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]