comparison src/org/dancres/blitz/entry/ci/CacheIndexer.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.entry.ci;
2
3 import java.util.logging.Logger;
4 import java.util.logging.Level;
5 import java.util.HashMap;
6
7 import net.jini.config.ConfigurationException;
8
9 import org.dancres.blitz.entry.TupleLocator;
10
11 import org.dancres.blitz.mangler.MangledEntry;
12
13 import org.dancres.blitz.oid.OID;
14
15 import org.dancres.blitz.cache.Cache;
16 import org.dancres.blitz.cache.CacheListener;
17 import org.dancres.blitz.cache.Identifiable;
18
19 import org.dancres.blitz.Logging;
20
21 import org.dancres.blitz.config.ConfigurationFactory;
22 import org.dancres.blitz.config.EntryConstraints;
23 import org.dancres.blitz.config.Fifo;
24
25 /**
26 CacheIndexer is responsible for indexing EntrySleeves held in any
27 cache capable of support CacheListener instances. It supports searching
28 as per other forms of storage via a TupleLocator::find mechanism.
29
30 @todo Maybe use some other kind of list rather than ArrayList which, for
31 large sizes, may not be so good.
32 */
33 public abstract class CacheIndexer {
34 static Logger theLogger =
35 Logging.newLogger("org.dancres.blitz.disk.CacheIndexer");
36
37 private static HashMap _indexers = new HashMap();
38
39 public static CacheIndexer getIndexer(String aType) {
40 synchronized(_indexers) {
41 return (CacheIndexer) _indexers.get(aType);
42 }
43 }
44
45 public static CacheIndexer newIndexer(String aType,
46 EntryConstraints aConstraints) {
47
48 synchronized(_indexers) {
49 CacheIndexer myIndexer;
50
51 if (aConstraints.get(Fifo.class) != null) {
52 theLogger.log(Level.INFO, "Using FIFO indexer: " + aType);
53 myIndexer = new FifoIndexer(aType);
54 } else {
55 theLogger.log(Level.INFO, "Using HASHMAP indexer: " + aType);
56 myIndexer = new HashMapIndexer(aType);
57 }
58
59 _indexers.put(aType, myIndexer);
60
61 return myIndexer;
62 }
63 }
64
65 public abstract TupleLocator find(MangledEntry anEntry);
66
67 public abstract void dirtied(Identifiable anIdentifiable);
68
69 /**
70 Indicates an entry was recovered from disk and loaded into the
71 cache.
72 */
73 public abstract void loaded(Identifiable anIdentifiable);
74
75 /**
76 Indicates an entry was removed from the cache having, if necessary,
77 been saved to disk.
78 */
79 public abstract void flushed(Identifiable anIdentifiable);
80
81 }