view src/org/dancres/blitz/WriteEscortImpl.java @ 27:511648fa4d64 Version 2.1

Version to 2.1
author Dan Creswell <dan.creswell@gmail.com>
date Mon, 04 Jan 2010 13:00:40 +0000
parents 3dc0c5604566
children
line wrap: on
line source

package org.dancres.blitz;

import net.jini.core.transaction.TransactionException;

import org.dancres.blitz.mangler.MangledEntry;

import org.dancres.blitz.entry.WriteEscort;
import org.dancres.blitz.entry.OpInfo;

import org.dancres.blitz.txn.TxnState;

import org.dancres.blitz.txnlock.*;

class WriteEscortImpl implements WriteEscort {
    private TxnState theTxnState;
    private OpInfo theInfo;

    private TransactionException theException;

    WriteEscortImpl(TxnState aTxnState) {
        theTxnState = aTxnState;
    }

    public boolean writing(OpInfo anInfo) {
        LockMgr myMgr = TxnLocks.getLockMgr(anInfo.getType());
        TxnLock myLock = myMgr.newLock(anInfo.getOID());

        synchronized(myLock) {
            myLock.acquire(theTxnState, TxnLock.WRITE, null, null, false);

            // System.out.println(theTxnState.getId() + " Wr: " + myLock);
        }

        try {
            theTxnState.add(new EntryTxnOp(TxnLock.WRITE, anInfo, myLock));
        } catch (TransactionException aTE) {
            myLock.release(theTxnState, TxnLock.WRITE);
            theException = aTE;
            return false;
        }

        theInfo = anInfo;

        return true;
    }

    OpInfo getInfo() throws TransactionException {
        if (theException != null)
            throw theException;
        else
            return theInfo;
    }
}