/*
 * JBoss, Home of Professional Open Source
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.cache.transaction;

import org.jboss.cache.TransactionManagerLookup;

import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.RollbackException;

/**
 *
 * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 */
public class NotifyingTransactionManager extends DummyTransactionManager implements TransactionManagerLookup
{
    public NotifyingTransactionManager()
    {
        super();
    }

    Notification notification;

    public void begin() throws SystemException, NotSupportedException
    {
        super.begin();
        try
        {
            System.out.println("Calling notification.notify()");
            notification.notify(getTransaction());
        }
        catch (RollbackException e)
        {
            e.printStackTrace();
        }
    }

    public TransactionManager getTransactionManager() throws Exception
    {
        return this;
    }

    public interface Notification
    {
        public void notify(Transaction tx) throws SystemException, RollbackException;
    }

}


