[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/lava gzz/storm/impl/AbstractLocalPool.java ...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] gzz/lava gzz/storm/impl/AbstractLocalPool.java ... |
Date: |
Sat, 11 Jan 2003 13:01:40 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Benja Fallenstein <address@hidden> 03/01/11 13:01:39
Modified files:
lava/gzz/storm/impl: AbstractLocalPool.java AbstractPool.java
TransientPool.java
Added files:
lava/test/gzz/storm: ContentTypeIndexType.java IndexedPool.meta
lava/test/gzz/storm/impl: TransientPoolIndexing.test
Log message:
Cool-- implement indexing for TransientPool
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/AbstractLocalPool.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/AbstractPool.java.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/TransientPool.java.diff?tr1=1.21&tr2=1.22&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/ContentTypeIndexType.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/IndexedPool.meta?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/impl/TransientPoolIndexing.test?rev=1.1
Patches:
Index: gzz/lava/gzz/storm/impl/AbstractLocalPool.java
diff -u gzz/lava/gzz/storm/impl/AbstractLocalPool.java:1.4
gzz/lava/gzz/storm/impl/AbstractLocalPool.java:1.5
--- gzz/lava/gzz/storm/impl/AbstractLocalPool.java:1.4 Wed Jan 8 22:45:06 2003
+++ gzz/lava/gzz/storm/impl/AbstractLocalPool.java Sat Jan 11 13:01:38 2003
@@ -45,7 +45,7 @@
}
// XXX temporary, until subclasses have implementations
- public DB getDB(String typeURI) {
+ protected DB getDB(String typeURI) {
return null;
}
}
Index: gzz/lava/gzz/storm/impl/AbstractPool.java
diff -u gzz/lava/gzz/storm/impl/AbstractPool.java:1.8
gzz/lava/gzz/storm/impl/AbstractPool.java:1.9
--- gzz/lava/gzz/storm/impl/AbstractPool.java:1.8 Mon Dec 30 11:02:02 2002
+++ gzz/lava/gzz/storm/impl/AbstractPool.java Sat Jan 11 13:01:38 2003
@@ -29,6 +29,7 @@
/** An abstract implementation of <code>IndexedPool</code>.
*/
public abstract class AbstractPool implements IndexedPool {
+ private static void pa(String s) { System.out.println(s); }
protected Set indexTypes;
protected Map indices;
@@ -59,7 +60,7 @@
public Map getIndices() { return indices; }
public Object getIndex(String indexTypeURI) {
- return getIndices().get(indexTypeURI);
+ return getIndices().get(indexTypeURI);
}
public Pointer getPointer(String uri) {
@@ -108,6 +109,36 @@
InputStream is = getRawInputStream();
Headers822.readHeader(is);
return is;
+ }
+ }
+
+ /** A convenience class for using a byte array
+ * as a hashtable key (in DB implementations).
+ */
+ protected static final class Key {
+ protected byte[] key;
+ protected int hashCode;
+
+ protected Key(byte[] key) {
+ this.key = key;
+ hashCode = 0;
+
+ for(int i=0; i<key.length; i++) {
+ hashCode += 77;
+ hashCode ^= key[i];
+ }
+ }
+
+ public boolean equals(Object o) {
+ if(!(o instanceof Key)) return false;
+ Key k = (Key)o;
+ if(hashCode != k.hashCode) return false;
+ if(key == k.key) return true;
+ return Arrays.equals(key, k.key);
+ }
+
+ public int hashCode() {
+ return hashCode;
}
}
}
Index: gzz/lava/gzz/storm/impl/TransientPool.java
diff -u gzz/lava/gzz/storm/impl/TransientPool.java:1.21
gzz/lava/gzz/storm/impl/TransientPool.java:1.22
--- gzz/lava/gzz/storm/impl/TransientPool.java:1.21 Mon Dec 30 08:48:23 2002
+++ gzz/lava/gzz/storm/impl/TransientPool.java Sat Jan 11 13:01:38 2003
@@ -37,6 +37,10 @@
*/
protected Map blocks = new HashMap();
+ /** The DB objects by index type URI.
+ */
+ protected Map dbs;
+
protected class TransientBlockOutputStream extends
AbstractBlockOutputStream
{
@@ -52,6 +56,8 @@
block = new TransientBlock(makeIdFromDigest(),
baos.toByteArray(), header);
blocks.put(block.getId(), block);
+
+ added(block);
}
}
@@ -70,6 +76,28 @@
}
}
+ protected class TransientDB implements DB {
+ protected Map mappings = new HashMap();
+
+ protected Set getSet(byte[] key) {
+ Key k = new Key(key);
+ Set s = (Set)mappings.get(k);
+ if(s == null) {
+ s = new HashSet();
+ mappings.put(k, s);
+ }
+ return s;
+ }
+
+ public Collector get(byte[] key) {
+ return new SimpleSetCollector(new HashSet(getSet(key)));
+ }
+
+ protected void add(Mapping m) {
+ getSet(m.key).add(m);
+ }
+ }
+
public TransientPool(Set indexTypes) {
super(indexTypes);
}
@@ -92,6 +120,8 @@
Block block = new TransientBlock(id, bytes, header);
blocks.put(id, block);
+
+ added(block);
}
public void delete(Block b) {
blocks.keySet().remove(b.getId());
@@ -108,5 +138,29 @@
public BlockOutputStream getBlockOutputStream(Header822 hdr)
throws IOException {
return new TransientBlockOutputStream(new VerbatimHeader822(hdr));
+ }
+
+ protected DB getDB(String typeURI) {
+ if(dbs == null) dbs = new HashMap();
+ DB db = (DB)dbs.get(typeURI);
+ if(db == null) {
+ db = new TransientDB();
+ dbs.put(typeURI, db);
+ }
+ return db;
+ }
+
+ protected void added(Block block) throws IOException {
+ for(Iterator i = indexTypes.iterator(); i.hasNext();) {
+ IndexType it = (IndexType)i.next();
+ Set mappings = it.getMappings(block);
+ for(Iterator j = mappings.iterator(); j.hasNext();) {
+ Mapping m = (Mapping)j.next();
+ if(!m.block.equals(block.getId()))
+ throw new Error("Wrong block in mapping: "+m);
+
+ ((TransientDB)getDB(it.getIndexTypeURI())).add(m);
+ }
+ }
}
}
- [Gzz-commits] gzz/lava gzz/storm/impl/AbstractLocalPool.java ...,
Benja Fallenstein <=