Mercurial > hg > blitz_stable
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/dancres/blitz/SearchFactory.java Sat Mar 21 11:00:06 2009 +0000 @@ -0,0 +1,73 @@ +package org.dancres.blitz; + +import java.lang.ref.WeakReference; +import java.io.IOException; + +import org.dancres.blitz.txnlock.BaulkedParty; +import org.dancres.blitz.entry.SearchVisitor; +import org.dancres.blitz.entry.EntryRepository; +import org.dancres.blitz.entry.EntryRepositoryFactory; + +/** + * Use this class for standard blocking searches, single or bulk. For these + * kinds of searches we care not how many conflicts we get, just when they + * are resolved at which point we pass them over to our associated MatchTask + * which can choose to act on them or not. + */ +public class SearchFactory implements VisitorBaulkedPartyFactory { + public BaulkedParty newParty(SingleMatchTask aMatchTask) { + return new BaulkedPartyImpl(aMatchTask); + } + + public BaulkedParty newParty(BulkTakeVisitor aMatchTask) { + return new BaulkedPartyImpl(aMatchTask); + } + + public void enableResolutionSignal() { + // Nothing to do for the standard search case + } + + private static class BaulkedPartyImpl implements BaulkedParty { + private WeakReference _task; + + public BaulkedPartyImpl(SingleMatchTask aMatchTask) { + _task = new WeakReference(aMatchTask); + } + + public BaulkedPartyImpl(BulkMatchTask aMatchTask) { + _task = new WeakReference(aMatchTask); + } + + public void blocked(Object aHandback) { + // Doesn't matter + } + + public void unblocked(Object aHandback) { + Handback myHandback = (Handback) aHandback; + + try { + SearchVisitor myVisitor = getVisitor(); + + if (myVisitor == null) + return; + + EntryRepository myRepos = + EntryRepositoryFactory.get().get(myHandback.getType()); + + myRepos.find(myVisitor, myHandback.getOID(), + myHandback.getEntry()); + + } catch (IOException aDbe) { + } + } + + private SearchVisitor getVisitor() { + MatchTask myTask = (MatchTask) _task.get(); + + if (myTask == null) + return null; + else + return myTask.getVisitor(); + } + } +}