@Override public void addPostTransactionAction(Action postTransactionAction) { sync(); _postTransactionActions.add(postTransactionAction); }
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(); } }
@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 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(); } }
throw new IllegalStateException(message); sync(); if(_transaction != null)
@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 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); } }
@Override public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, EnqueueAction postTransactionAction) sync(); _outstandingWork = true; initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime();
@Override public void enqueue(TransactionLogResource queue, EnqueueableMessage message, EnqueueAction postTransactionAction) sync(); _outstandingWork = true; initTransactionStartTimeIfNecessaryAndAdvanceUpdateTime();