Mercurial > hg > blitz_stable
comparison src/org/dancres/blitz/WriteEscortImpl.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 net.jini.core.transaction.TransactionException; | |
4 | |
5 import org.dancres.blitz.mangler.MangledEntry; | |
6 | |
7 import org.dancres.blitz.entry.WriteEscort; | |
8 import org.dancres.blitz.entry.OpInfo; | |
9 | |
10 import org.dancres.blitz.txn.TxnState; | |
11 | |
12 import org.dancres.blitz.txnlock.*; | |
13 | |
14 class WriteEscortImpl implements WriteEscort { | |
15 private TxnState theTxnState; | |
16 private OpInfo theInfo; | |
17 | |
18 private TransactionException theException; | |
19 | |
20 WriteEscortImpl(TxnState aTxnState) { | |
21 theTxnState = aTxnState; | |
22 } | |
23 | |
24 public boolean writing(OpInfo anInfo) { | |
25 LockMgr myMgr = TxnLocks.getLockMgr(anInfo.getType()); | |
26 TxnLock myLock = myMgr.newLock(anInfo.getOID()); | |
27 | |
28 synchronized(myLock) { | |
29 myLock.acquire(theTxnState, TxnLock.WRITE, null, null, false); | |
30 | |
31 // System.out.println(theTxnState.getId() + " Wr: " + myLock); | |
32 } | |
33 | |
34 try { | |
35 theTxnState.add(new EntryTxnOp(TxnLock.WRITE, anInfo, myLock)); | |
36 } catch (TransactionException aTE) { | |
37 myLock.release(theTxnState, TxnLock.WRITE); | |
38 theException = aTE; | |
39 return false; | |
40 } | |
41 | |
42 theInfo = anInfo; | |
43 | |
44 return true; | |
45 } | |
46 | |
47 OpInfo getInfo() throws TransactionException { | |
48 if (theException != null) | |
49 throw theException; | |
50 else | |
51 return theInfo; | |
52 } | |
53 } |