Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/entry/CleanerImpl.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; | |
2 | |
3 import java.io.IOException; | |
4 | |
5 import org.dancres.blitz.arc.CacheBlockDescriptor; | |
6 import org.dancres.blitz.lease.ReapFilter; | |
7 import org.dancres.blitz.oid.OID; | |
8 | |
9 /** | |
10 Responsible for taking each ID passed, attempting to load the | |
11 specified sleeve, checking with ReapFilters and then deleting sleeve | |
12 if appropriate. Note, Storage is expected to pass OID's to us | |
13 whilst we pass EntrySleeveImpls to our ReapFilter. | |
14 */ | |
15 public class CleanerImpl implements EntryReaper { | |
16 private SleeveCache theCache; | |
17 private ReapFilter theFilter; | |
18 | |
19 /** | |
20 * @param aCache the cache to request sleeves from for OIDs | |
21 * passed in by Storage | |
22 * @param aFilter the filter to check with before performing deletion. | |
23 */ | |
24 CleanerImpl(SleeveCache aCache, ReapFilter aFilter) { | |
25 theCache = aCache; | |
26 theFilter = aFilter; | |
27 } | |
28 | |
29 public void clean(TupleLocator aLocator) throws IOException { | |
30 /** | |
31 Accept TupleLocator from Storage | |
32 Attempt load to cache | |
33 Check with theFilter | |
34 Mark deleted (if filter says okay) | |
35 Release CBD | |
36 */ | |
37 long myCurrentTime = System.currentTimeMillis(); | |
38 | |
39 long myPurged = 0; | |
40 | |
41 while (aLocator.fetchNext()) { | |
42 OID myOID = aLocator.getOID(); | |
43 | |
44 CacheBlockDescriptor myCBD = theCache.load(myOID); | |
45 | |
46 if (myCBD != null) { | |
47 EntrySleeveImpl mySleeve = (EntrySleeveImpl) | |
48 myCBD.getContent(); | |
49 | |
50 /* | |
51 If you expect a particular EntrySleeve to be cleaned | |
52 and it's not happening, uncomment these to provide some | |
53 hints | |
54 System.err.println("Has expired: " + | |
55 mySleeve.hasExpired(myCurrentTime)); | |
56 | |
57 System.err.println("Has deleted: " + | |
58 mySleeve.getState().test(SleeveState.DELETED)); | |
59 | |
60 System.err.println("Filtered: " + | |
61 theFilter.filter(mySleeve)); | |
62 */ | |
63 | |
64 if ((mySleeve.hasExpired(myCurrentTime)) && | |
65 (! mySleeve.getState().test(SleeveState.DELETED)) && | |
66 (! theFilter.filter(mySleeve))) { | |
67 | |
68 /* | |
69 System.err.println("Lease delete:" + | |
70 mySleeve.getUid()); | |
71 */ | |
72 | |
73 mySleeve.getState().set(SleeveState.DELETED); | |
74 mySleeve.markDirty(); | |
75 theCache.getCounters().didPurge(); | |
76 | |
77 ++myPurged; | |
78 } | |
79 | |
80 myCBD.release(); | |
81 } | |
82 } | |
83 | |
84 EntryStorage.theLogger.info("Reaper purged " + theCache + | |
85 " " + myPurged); | |
86 } | |
87 } |