/** * Run the specified code inside a single transaction, with the contained code returning a value * of the parameter type A. * * <p>In most cases this is not needed, because the primitives always create their own transaction * automatically, but it is needed in some circumstances. */ public static <A> A run(Lambda0<A> code) { synchronized (transactionLock) { // If we are already inside a transaction (which must be on the same // thread otherwise we wouldn't have acquired transactionLock), then // keep using that same transaction. Transaction transWas = currentTransaction; try { startIfNecessary(); return code.apply(); } finally { if (transWas == null) currentTransaction.close(); currentTransaction = transWas; } } }
static void run(Handler<Transaction> code) { synchronized (transactionLock) { // If we are already inside a transaction (which must be on the same // thread otherwise we wouldn't have acquired transactionLock), then // keep using that same transaction. Transaction transWas = currentTransaction; try { startIfNecessary(); code.run(currentTransaction); } finally { if (transWas == null) currentTransaction.close(); currentTransaction = transWas; } } }
void close() { while (true) { checkRegen(); if (prioritizedQ.isEmpty()) break; Entry e = prioritizedQ.remove(); entries.remove(e); e.action.run(this); } for (Runnable action : lastQ) action.run(); lastQ.clear(); if (postQ != null) { while (!postQ.isEmpty()) { Iterator<Map.Entry<Integer, Handler<Transaction>>> iter = postQ.entrySet().iterator(); if (iter.hasNext()) { Map.Entry<Integer, Handler<Transaction>> e = iter.next(); int ix = e.getKey(); Handler<Transaction> h = e.getValue(); iter.remove(); Transaction parent = currentTransaction; try { if (ix >= 0) { Transaction trans = new Transaction(); currentTransaction = trans; try { h.run(trans); } finally { trans.close(); } } else { currentTransaction = null; h.run(null); } } finally { currentTransaction = parent; } } } } }