this.abortBeforeCompletion = abortBeforeCompletion;
}
public void notify(Transaction tx, TransactionContext transactionContext) throws SystemException, RollbackException
{
OrderedSynchronizationHandler osh = transactionContext.getOrderedSynchronizationHandler();
final Transaction finalTx = tx;
System.out.println("Notify called.");
// add an aborting sync handler.
Synchronization abort = new Synchronization()
{
public void beforeCompletion()
{
if (abortBeforeCompletion)
{
cache3.getConfiguration().getRuntimeConfig().getChannel().close();
System.out.println("Returning from abort.beforeCompletion");
try
{
finalTx.setRollbackOnly();
}
catch (SystemException e)
{
throw new RuntimeException("Unable to set rollback", e);
}
throw new RuntimeException("Dummy exception");
}
}
public void afterCompletion(int i)
{
if (!abortBeforeCompletion)
{
cache3.getConfiguration().getRuntimeConfig().getChannel().close();
System.out.println("Returning from abort.afterCompletion");
throw new RuntimeException("Dummy exception");
}
}
};
osh.registerAtHead(abort);
System.out.println("Added sync handler.");
}