view src/org/dancres/blitz/notify/TxnNotifys.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.notify;

import java.io.IOException;

import java.util.HashMap;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.logging.Level;

import org.dancres.blitz.txn.TxnState;

import org.dancres.blitz.oid.OID;

/**
   Tracks notify registrations associated with specific transactions.
   This is done so that when we receive a transaction ended event we can
   cleanup any outstanding templates associated with that transaction.
 
   @deprecated Transactional de-reg is handled by the generator when receiving
   end of transaction message.
 */
class TxnNotifys {
    private HashMap theRegsByTxn = new HashMap();

    synchronized void track(OID aOID, TxnState aTxn) {
        // System.out.println("Tracking: " + aOID + ", " + aTxn.getId());

        LinkedList myRegs = getRegs(aTxn);

        if (myRegs == null) {
            myRegs = new LinkedList();
            theRegsByTxn.put(aTxn.getId(), myRegs);
        }

        myRegs.add(aOID);
    }

    /**
       Return an Iterator of OID's
     */
    void unRegAll(TxnState aTxn) {
        Iterator myEventGenOIDs = null;

        synchronized(this) {
            LinkedList myRegs = (LinkedList) theRegsByTxn.remove(aTxn.getId());

            if (myRegs != null)
                myEventGenOIDs = myRegs.iterator();
        }

        if (myEventGenOIDs != null) {
            while (myEventGenOIDs.hasNext()) {
                OID myOID = (OID) myEventGenOIDs.next();
                
                try {
                    EventGeneratorFactory.get().cancel(myOID);
                } catch (IOException aDbe) {
                }
            }
        }
    }

    private LinkedList getRegs(TxnState aTxn) {
        return (LinkedList) theRegsByTxn.get(aTxn.getId());
    }
}