comparison src/org/dancres/blitz/SearchFactory.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;
2
3 import java.lang.ref.WeakReference;
4 import java.io.IOException;
5
6 import org.dancres.blitz.txnlock.BaulkedParty;
7 import org.dancres.blitz.entry.SearchVisitor;
8 import org.dancres.blitz.entry.EntryRepository;
9 import org.dancres.blitz.entry.EntryRepositoryFactory;
10
11 /**
12 * Use this class for standard blocking searches, single or bulk. For these
13 * kinds of searches we care not how many conflicts we get, just when they
14 * are resolved at which point we pass them over to our associated MatchTask
15 * which can choose to act on them or not.
16 */
17 public class SearchFactory implements VisitorBaulkedPartyFactory {
18 public BaulkedParty newParty(SingleMatchTask aMatchTask) {
19 return new BaulkedPartyImpl(aMatchTask);
20 }
21
22 public BaulkedParty newParty(BulkTakeVisitor aMatchTask) {
23 return new BaulkedPartyImpl(aMatchTask);
24 }
25
26 public void enableResolutionSignal() {
27 // Nothing to do for the standard search case
28 }
29
30 private static class BaulkedPartyImpl implements BaulkedParty {
31 private WeakReference _task;
32
33 public BaulkedPartyImpl(SingleMatchTask aMatchTask) {
34 _task = new WeakReference(aMatchTask);
35 }
36
37 public BaulkedPartyImpl(BulkMatchTask aMatchTask) {
38 _task = new WeakReference(aMatchTask);
39 }
40
41 public void blocked(Object aHandback) {
42 // Doesn't matter
43 }
44
45 public void unblocked(Object aHandback) {
46 Handback myHandback = (Handback) aHandback;
47
48 try {
49 SearchVisitor myVisitor = getVisitor();
50
51 if (myVisitor == null)
52 return;
53
54 EntryRepository myRepos =
55 EntryRepositoryFactory.get().get(myHandback.getType());
56
57 myRepos.find(myVisitor, myHandback.getOID(),
58 myHandback.getEntry());
59
60 } catch (IOException aDbe) {
61 }
62 }
63
64 private SearchVisitor getVisitor() {
65 MatchTask myTask = (MatchTask) _task.get();
66
67 if (myTask == null)
68 return null;
69 else
70 return myTask.getVisitor();
71 }
72 }
73 }