comparison src/org/dancres/blitz/entry/LongtermOfferImpl.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 import java.util.logging.Level;
5
6 import org.dancres.blitz.arc.CacheBlockDescriptor;
7 import org.dancres.blitz.oid.OID;
8
9 /**
10 */
11 public class LongtermOfferImpl implements LongtermOffer {
12 private CacheBlockDescriptor _cbd;
13
14 LongtermOfferImpl(CacheBlockDescriptor aDescriptor) {
15 _cbd = aDescriptor;
16
17 // System.err.println("Locked: " + _cbd + ", " + Thread.currentThread());
18 }
19
20 public String getEntryType() {
21 return ((EntrySleeveImpl) _cbd.getContent()).getType();
22 }
23
24 public boolean offer(SearchVisitor aVisitor) throws IOException {
25 long myStartTime = System.currentTimeMillis();
26
27 EntrySleeveImpl mySleeve =
28 (EntrySleeveImpl) _cbd.getContent();
29
30 boolean offered = false;
31
32 /*
33 If the JS specification is changed to cope with the issues
34 discussed in http://archives.java.sun.com/cgi-bin/wa?A2=ind0311&L=javaspaces-users&F=&S=&P=4599 and http://archives.java.sun.com/cgi-bin/wa?A2=ind0311&L=javaspaces-users&F=&S=&P=3590 then we need to do two things:
35
36 (1) Allow the SearchVisitor to see Sleeve's even if they've
37 expired.
38 (2) Having "shown" it to the SearchVisitor we'd need to
39 query the ReapFilters and if they don't boycott, mark the
40 item deleted.
41
42 These two steps have the effect of allowing a *ifExists to
43 conflict on lease-expired entries that have been locked
44 by a transaction and ensures we only delete such entries
45 when no transactions have posession of them anymore. Of
46 course, this is somewhat slower and less efficient as
47 there's never a circumstance under which we can be assured
48 that a SearchVisitor *never* sees a particular entry again.
49
50 If we must implement the strategy of flunking a transaction
51 owing to a lock on a lease expired object, this would be
52 best dealt with by having TxnOp's check expiries at prepare
53 or commit time. However this is much less appealing as what
54 is basically a pessimistic transaction API becomes
55 optimistic in this case and only in this case.
56
57 All this applies to the similar statement in offer() below.
58 */
59 if (!mySleeve.getState().test(SleeveState.DELETED)) {
60
61 // If it's expired, mark it deleted, subject to filters
62 //
63 if (mySleeve.hasExpired(myStartTime)) {
64
65 if (!EntryRepositoryFactory.getReaper().filter(mySleeve)) {
66 mySleeve.getState().set(SleeveState.DELETED);
67 mySleeve.markDirty();
68
69 // Update stats
70 // theCounters.didPurge();
71
72 // myLog.incDeletions();
73 }
74 } else {
75 OpInfo myInfo =
76 new FindEntryOpInfo(mySleeve.getType(),
77 mySleeve.getOID(),
78 aVisitor.isDeleter());
79
80 SearchOffer myOffer =
81 new SearchOfferImpl(mySleeve.getEntry(),
82 myInfo);
83
84 aVisitor.offer(myOffer);
85
86 offered = true;
87
88 // myLog.incOffers();
89 }
90 }
91
92 return offered;
93 }
94
95 public void release() throws IOException {
96 // System.err.println("Unlocked: " + _cbd + ", " + Thread.currentThread());
97 _cbd.release();
98 }
99
100 public OID getOID() {
101 return ((EntrySleeveImpl) _cbd.getContent()).getOID();
102 }
103 }