28 |
|
|
29 |
/** An abstract implementation of <code>IndexedPool</code>. |
/** An abstract implementation of <code>IndexedPool</code>. |
30 |
*/ |
*/ |
31 |
public abstract class AbstractPool implements StormPool { |
public abstract class AbstractPool implements IndexedPool { |
32 |
|
|
33 |
/***** IndexedPool stuff |
protected Set indexTypes; |
|
protected Set indexers; |
|
34 |
protected Map indices; |
protected Map indices; |
|
protected AsyncMap indexCache; |
|
|
protected Map dbs; |
|
35 |
|
|
36 |
public AbstractPool(Set indexers, AsyncMap indexCache) { |
/** Get a DB implementation associated with |
37 |
this.indexers = indexers; |
* the given index type URI. |
38 |
this.indexCache = indexCache; |
* The implementing pool has to make sure |
39 |
|
* that this is updated when blocks are added |
40 |
|
* or removed. |
41 |
|
*/ |
42 |
|
protected abstract DB getDB(String typeURI); |
43 |
|
|
44 |
|
public AbstractPool(Set indexTypes) { |
45 |
Map indices = new HashMap(); |
Map indices = new HashMap(); |
|
this.indices = Collections.unmodifyableMap(indices); |
|
|
this.dbs = new HashSet(); |
|
46 |
|
|
47 |
for(Iterator i=indexers.iterator(); i.hasNext();) { |
for(Iterator i=indexTypes.iterator(); i.hasNext();) { |
48 |
Indexer x = (Indexer)i.next(); |
IndexType type = (IndexType)i.next(); |
49 |
|
|
50 |
String uri = x.getIndexTypeURI(); |
String uri = type.getIndexTypeURI(); |
51 |
indices.put(uri, x.getIndex()); |
indices.put(uri, type.createIndex(this, getDB(uri))); |
52 |
} |
} |
53 |
|
|
54 |
|
this.indexTypes = indexTypes; |
55 |
|
this.indices = Collections.unmodifiableMap(indices); |
56 |
} |
} |
57 |
|
|
58 |
public Map getIndices() { return indices; } |
public Map getIndices() { return indices; } |
59 |
|
|
60 |
public Index getIndex(String indexTypeURI) { |
public Object getIndex(String indexTypeURI) { |
61 |
return (Index)getIndices().get(indexTypeURI); |
return getIndices().get(indexTypeURI); |
62 |
|
} |
63 |
|
|
64 |
public Pointer getPointer(String uri) { |
public Pointer getPointer(String uri) { |
65 |
return ((PointerIndex)getIndex(Pointer.pointerIndexURI)).getPointer(uri); |
Object index = getIndex(Pointer.pointerIndexURI); |
66 |
|
return ((Pointer.PointerIndex)index).getPointer(uri); |
67 |
} |
} |
|
************/ |
|
68 |
|
|
69 |
/** |
/** |
70 |
* <code>block</code> must be set by <code>close()</code>. |
* <code>block</code> must be set by <code>close()</code>. |