.filter(t -> !t.isDischarged() && !t.isRollbackOnly() && !t.setRollbackOnly()) .map(t -> { final SettableFuture<Void> future = SettableFuture.create(); LocalTransaction.LocalTransactionListener listener = tx -> future.set(null); t.addTransactionListener(listener); if (t.isRollbackOnly() || t.isDischarged()) t.removeTransactionListener(listener);
@Override public void dequeue(MessageEnqueueRecord record, Action postTransactionAction) { sync(); _outstandingWork = true; _postTransactionActions.add(postTransactionAction); initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime(); if(record != null) { try { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Dequeue of message number " + record.getMessageNumber() + " from transaction log. Queue : " + record.getQueueId()); } beginTranIfNecessary(); _transaction.dequeueMessage(record); } catch(RuntimeException e) { tidyUpOnError(e); } } }
@Override public void commit() { commit(null); }
@Override public void commit(Runnable immediateAction) { if(!_state.compareAndSet(LocalTransactionState.ACTIVE, LocalTransactionState.DISCHARGING)) { LocalTransactionState state = _state.get(); String message = state == LocalTransactionState.ROLLBACK_ONLY ? "Transaction has been marked as rollback only" : String.format("Cannot commit transaction in state %s", state); throw new IllegalStateException(message); } sync(); try { if(_transaction != null) { _transaction.commitTran(); } if(immediateAction != null) { immediateAction.run(); } doPostTransactionActions(); } finally { resetDetails(); } }
@Override public void rollback() { if (!_state.compareAndSet(LocalTransactionState.ACTIVE, LocalTransactionState.DISCHARGING) && !_state.compareAndSet(LocalTransactionState.ROLLBACK_ONLY, LocalTransactionState.DISCHARGING) && _state.get() != LocalTransactionState.DISCHARGING) { throw new IllegalStateException(String.format("Cannot roll back transaction with state '%s'", _state.get())); } sync(); try { if(_transaction != null) { _transaction.abortTran(); } } finally { try { doRollbackActions(); } finally { resetDetails(); } } }
@Override public LocalTransaction createLocalTransaction() { _localTransactionBegins.incrementAndGet(); _localTransactionOpens.incrementAndGet(); return new LocalTransaction(getAddressSpace().getMessageStore(), () -> getLastReadTime(), _transactionObserver, getProtocol() != Protocol.AMQP_1_0); }
@Override public void registerTransaction(final ServerTransaction tx) { if (tx instanceof LocalTransaction) { LocalTransaction localTransaction = (LocalTransaction) tx; if (!isDeleted()) { if (_transactions.add(localTransaction)) { localTransaction.addTransactionListener(_localTransactionListener); if (isDeleted()) { localTransaction.setRollbackOnly(); unregisterTransaction(localTransaction); } } } else { localTransaction.setRollbackOnly(); } } }
final LocalTransaction txn = new LocalTransaction(store); txn.commit();
@Override public void addPostTransactionAction(Action postTransactionAction) { sync(); _postTransactionActions.add(postTransactionAction); }
if (((LocalTransaction) _transaction).hasOutstandingWork())
connection.incrementTransactionRollbackCounter(); else if(!(txn instanceof LocalTransaction && ((LocalTransaction)txn).isRollbackOnly()))
((LocalTransaction) transaction).setRollbackOnly(); ((LocalTransaction) transaction).setRollbackOnly();
private void commit(final Runnable immediateAction, boolean async) { if(async && _transaction instanceof LocalTransaction) { ((LocalTransaction)_transaction).commitAsync(new Runnable() { @Override public void run() { try { immediateAction.run(); } finally { _connection.incrementTransactionBeginCounter(); } } }); } else { _transaction.commit(immediateAction); _connection.incrementTransactionBeginCounter(); } }
@Override public void dequeue(final QueueEntry messageInstance) { final ServerTransaction.Action deleteAction = new ServerTransaction.Action() { @Override public void postCommit() { messageInstance.delete(); } @Override public void onRollback() { } }; boolean acquired = messageInstance.acquireOrSteal(new Runnable() { @Override public void run() { ServerTransaction txn = new AutoCommitTransaction(store); txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction); } }); if(acquired) { txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction); } }
throw new IllegalStateException(message); sync(); if(_transaction != null) doPostTransactionActions(); deferred.run(); resetDetails();
private void routeToAlternate(List<QueueEntry> entries) { ServerTransaction txn = new LocalTransaction(getVirtualHost().getMessageStore()); for(final QueueEntry entry : entries) { // TODO log requeues with a post enqueue action int requeues = entry.routeToAlternate(null, txn, null); if(requeues == 0) { // TODO log discard } } txn.commit(); }
private void sync() { if(LOGGER.isDebugEnabled()) { LOGGER.debug("sync() called on channel " + debugIdentity()); } AsyncCommand cmd; while((cmd = _unfinishedCommandsQueue.poll()) != null) { cmd.complete(); } if(_transaction instanceof LocalTransaction) { ((LocalTransaction)_transaction).sync(); } }
if(_transaction instanceof LocalTransaction) if (((LocalTransaction) _transaction).hasOutstandingWork())
@Override public void dequeue(Collection<MessageInstance> queueEntries, Action postTransactionAction) { sync(); _outstandingWork = true; _postTransactionActions.add(postTransactionAction); initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime(); try { for(MessageInstance entry : queueEntries) { final MessageEnqueueRecord record = entry.getEnqueueRecord(); if(record != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Dequeue of message number " + record.getMessageNumber() + " from transaction log. Queue : " + record.getQueueId()); } beginTranIfNecessary(); _transaction.dequeueMessage(record); } } } catch(RuntimeException e) { tidyUpOnError(e); } }