You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by vg...@apache.org on 2008/11/08 01:32:02 UTC
svn commit: r712324 - in
/xml/xindice/trunk/java/src/org/apache/xindice/core: Collection.java
cache/DocumentCache.java cache/DocumentCacheImpl.java
Author: vgritsenko
Date: Fri Nov 7 16:32:01 2008
New Revision: 712324
URL: http://svn.apache.org/viewvc?rev=712324&view=rev
Log:
Document cache cleanup: Remove CacheEntry, re-use Entry
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCache.java
xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCacheImpl.java
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java?rev=712324&r1=712323&r2=712324&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Fri Nov 7 16:32:01 2008
@@ -243,6 +243,9 @@
this.parent = parent;
}
+ public boolean isCompressed() {
+ return compressed;
+ }
// -- Internal Implementation Methods -----------------------------------
@@ -915,9 +918,7 @@
flushSymbolTable();
if (cache != null) {
- cache.putEntry(this, key,
- compressed ? DocumentCache.COMPRESSED : DocumentCache.UNCOMPRESSED,
- value, entryMeta);
+ cache.putEntry(this, key, Entry.DOCUMENT, value, entryMeta);
}
DBObserver.getInstance().loadDocument(this, record, document);
@@ -928,7 +929,7 @@
}
if (cache != null) {
- cache.putEntry(this, key, DocumentCache.BINARY, value, entryMeta);
+ cache.putEntry(this, key, Entry.BINARY, value, entryMeta);
}
return new Entry(key, value.getData(), entryMeta);
@@ -1372,8 +1373,7 @@
// Cache Stuff
if (cache != null) {
- cache.putEntry(this, key,
- compressed ? DocumentCache.COMPRESSED : DocumentCache.UNCOMPRESSED,
+ cache.putEntry(this, key, Entry.DOCUMENT,
new Value(documentBytes), Entry.createMetaMap(record));
}
@@ -1441,7 +1441,7 @@
Record record = writeRecord(key, false, bytes);
if (cache != null) {
- cache.putEntry(this, key, DocumentCache.BINARY, new Value(bytes), Entry.createMetaMap(record));
+ cache.putEntry(this, key, Entry.BINARY, new Value(bytes), Entry.createMetaMap(record));
}
// update the meta for this document
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCache.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCache.java?rev=712324&r1=712323&r2=712324&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCache.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCache.java Fri Nov 7 16:32:01 2008
@@ -28,21 +28,12 @@
/**
* DocumentCache implements a simple caching system for
- * Collection resources.
+ * collection resource entries.
*
* @version $Revision$, $Date$
*/
public interface DocumentCache {
- /** Compressed document resource type */
- int COMPRESSED = 1;
-
- /** Uncompressed document resource type */
- int UNCOMPRESSED = 2;
-
- /** Binary resource type */
- int BINARY = 3;
-
/**
* Cache key consists of collection and resource key
*/
@@ -114,7 +105,7 @@
* @param value entry value
* @param meta resource meta attributes map
*/
- void putEntry(Collection col, Key key, int type, Value value, Map meta);
+ void putEntry(Collection col, Key key, byte type, Value value, Map meta);
/**
* Stores resource meta entry in the cache
@@ -124,7 +115,7 @@
* @param type resource type: COMPRESSED, UNCOMPRESSED, BINARY
* @param meta resource metadata attributes map
*/
- void putEntryMeta(Collection col, Key key, int type, Map meta);
+ void putEntryMeta(Collection col, Key key, byte type, Map meta);
/**
* Remove resource entry from the cache
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCacheImpl.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCacheImpl.java?rev=712324&r1=712323&r2=712324&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCacheImpl.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/cache/DocumentCacheImpl.java Fri Nov 7 16:32:01 2008
@@ -57,85 +57,48 @@
private final Map table = new WeakHashMap();
- private class CacheEntry {
- private final int type;
- private final Key key;
- private final Value value;
- private Map meta;
-
- public CacheEntry(int type, Key key, Value value, Map meta) {
- this.type = type;
- this.key = key;
- this.value = value;
- this.meta = meta;
- }
-
- public int getType() {
- return type;
- }
-
- public Key getKey() {
- return key;
- }
-
- public Value getValue() {
- return value;
- }
-
- public Map getMeta() {
- return meta;
- }
-
- void setMeta(Map meta) {
- this.meta = meta;
- }
- }
-
-
public Entry getEntry(Collection col, Key key) {
- CacheEntry e;
+ Entry e;
synchronized (table) {
- e = (CacheEntry) table.get(new CacheKey(col, key));
+ e = (Entry) table.get(new CacheKey(col, key));
}
if (e == null) {
return null;
}
- switch (e.getType()) {
- case DocumentCache.COMPRESSED:
- {
+ switch (e.getEntryType()) {
+ case Entry.DOCUMENT:
+ Document doc;
+ if (col.isCompressed()) {
SymbolTable s = col.getSymbols();
NodeSource ns = new NodeSource(col, key);
- Document doc = new DocumentImpl(e.getValue().getData(), s, ns);
- return new Entry(key, doc, e.getMeta());
- }
-
- case DocumentCache.UNCOMPRESSED:
- try {
- Document doc = DOMParser.toDocument(e.getValue());
- ((DBDocument) doc).setSource(new NodeSource(col, key));
- return new Entry(key, doc, e.getMeta());
- } catch (Exception ex) {
- if (log.isWarnEnabled()) {
- log.warn("ignored exception", ex);
+ doc = new DocumentImpl(((Value) e.getValue()).getData(), s, ns);
+ } else {
+ try {
+ doc = DOMParser.toDocument((Value) e.getValue());
+ ((DBDocument) doc).setSource(new NodeSource(col, key));
+ } catch (Exception ex) {
+ if (log.isWarnEnabled()) {
+ log.warn("ignored exception", ex);
+ }
+ return null;
}
}
- break;
+ return new Entry(key, doc, e.getMeta());
- case DocumentCache.BINARY:
- return new Entry(Entry.BINARY, key, e.getValue().getData(), e.getMeta());
+ case Entry.BINARY:
+ return new Entry(key, ((Value) e.getValue()).getData(), e.getMeta());
default:
- throw new IllegalStateException("Invalid cache entry type: <" + e.getType() + ">");
+ throw new IllegalStateException("Invalid cache entry type: <" + e.getEntryType() + ">");
}
- return null;
}
public Entry getEntryMeta(Collection col, Key key) {
- CacheEntry e;
+ Entry e;
synchronized (table) {
- e = (CacheEntry) table.get(new CacheKey(col, key));
+ e = (Entry) table.get(new CacheKey(col, key));
}
if (e == null) {
return null;
@@ -144,22 +107,23 @@
return new Entry(key, e.getMeta());
}
- public void putEntry(Collection col, Key key, int type, Value value, Map meta) {
+ public void putEntry(Collection col, Key key, byte type, Value value, Map meta) {
CacheKey ckey = new CacheKey(col, key);
synchronized (table) {
- table.put(ckey, new CacheEntry(type, key, value, meta));
+ table.put(ckey, new Entry(type, key, value, meta));
}
}
- public void putEntryMeta(Collection col, Key key, int type, Map meta) {
+ public void putEntryMeta(Collection col, Key key, byte type, Map meta) {
CacheKey ckey = new CacheKey(col, key);
synchronized (table) {
- CacheEntry e = (CacheEntry) table.get(ckey);
+ Entry e = (Entry) table.get(ckey);
if (e == null) {
- e = new CacheEntry(type, key, null, meta);
+ e = new Entry(type, key, null, meta);
} else {
- e.setMeta(meta);
+ e = new Entry(type, key, e.getValue(), meta);
}
+
table.put(ckey, e);
}
}