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; } } } } }
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; } } }