use of org.apache.qpid.server.store.Transaction in project qpid-broker-j by apache.
the class MessageStoreSerializer_v1 method deserializeMessageInstances.
private Record deserializeMessageInstances(final MessageStore store, final Map<UUID, UUID> queueIdMap, final Map<Long, StoredMessage<?>> messageMap, final Deserializer deserializer, Record nextRecord) throws IOException {
while (nextRecord.getType() == RecordType.MESSAGE_INSTANCE) {
MessageInstanceRecord messageInstanceRecord = (MessageInstanceRecord) nextRecord;
final StoredMessage<?> storedMessage = messageMap.get(messageInstanceRecord.getMessageNumber());
final UUID queueId = queueIdMap.get(messageInstanceRecord.getQueueId());
if (storedMessage != null && queueId != null) {
final Transaction txn = store.newTransaction();
EnqueueableMessage msg = new EnqueueableMessage() {
@Override
public long getMessageNumber() {
return storedMessage.getMessageNumber();
}
@Override
public boolean isPersistent() {
return true;
}
@Override
public StoredMessage getStoredMessage() {
return storedMessage;
}
};
txn.enqueueMessage(new TransactionLogResource() {
@Override
public String getName() {
return queueId.toString();
}
@Override
public UUID getId() {
return queueId;
}
@Override
public MessageDurability getMessageDurability() {
return MessageDurability.DEFAULT;
}
}, msg);
txn.commitTranAsync(null);
}
nextRecord = deserializer.readRecord();
}
return nextRecord;
}
use of org.apache.qpid.server.store.Transaction in project qpid-broker-j by apache.
the class AsyncAutoCommitTransaction method enqueue.
@Override
public void enqueue(TransactionLogResource queue, EnqueueableMessage message, EnqueueAction postTransactionAction) {
Transaction txn = null;
try {
ListenableFuture<Void> future;
final MessageEnqueueRecord enqueueRecord;
if (queue.getMessageDurability().persist(message.isPersistent())) {
LOGGER.debug("Enqueue of message number {} to transaction log. Queue : {}", message.getMessageNumber(), queue.getName());
txn = _messageStore.newTransaction();
enqueueRecord = txn.enqueueMessage(queue, message);
future = txn.commitTranAsync(null);
txn = null;
} else {
future = Futures.immediateFuture(null);
enqueueRecord = null;
}
final EnqueueAction underlying = postTransactionAction;
addEnqueueFuture(future, new Action() {
@Override
public void postCommit() {
underlying.postCommit(enqueueRecord);
}
@Override
public void onRollback() {
underlying.onRollback();
}
}, message.isPersistent());
postTransactionAction = null;
} finally {
final EnqueueAction underlying = postTransactionAction;
rollbackIfNecessary(new Action() {
@Override
public void postCommit() {
}
@Override
public void onRollback() {
if (underlying != null) {
underlying.onRollback();
}
}
}, txn);
}
}
use of org.apache.qpid.server.store.Transaction in project qpid-broker-j by apache.
the class AutoCommitTransaction method dequeue.
@Override
public void dequeue(MessageEnqueueRecord record, Action postTransactionAction) {
Transaction txn = null;
try {
if (record != null) {
LOGGER.debug("Dequeue of message number {} from transaction log. Queue : {}", record.getMessageNumber(), record.getQueueId());
txn = _messageStore.newTransaction();
txn.dequeueMessage(record);
txn.commitTran();
txn = null;
}
postTransactionAction.postCommit();
postTransactionAction = null;
} finally {
rollbackIfNecessary(postTransactionAction, txn);
}
}
use of org.apache.qpid.server.store.Transaction in project qpid-broker-j by apache.
the class AutoCommitTransaction method dequeue.
@Override
public void dequeue(Collection<MessageInstance> queueEntries, Action postTransactionAction) {
Transaction txn = null;
try {
for (MessageInstance entry : queueEntries) {
MessageEnqueueRecord enqueueRecord = entry.getEnqueueRecord();
if (enqueueRecord != null) {
LOGGER.debug("Dequeue of message number {} from transaction log. Queue : {}", enqueueRecord.getMessageNumber(), enqueueRecord.getQueueId());
if (txn == null) {
txn = _messageStore.newTransaction();
}
txn.dequeueMessage(enqueueRecord);
}
}
if (txn != null) {
txn.commitTran();
txn = null;
}
postTransactionAction.postCommit();
postTransactionAction = null;
} finally {
rollbackIfNecessary(postTransactionAction, txn);
}
}
use of org.apache.qpid.server.store.Transaction in project qpid-broker-j by apache.
the class DtxBranch method rollback.
public synchronized void rollback() throws StoreException {
LOGGER.debug("Performing rollback for DtxBranch {}", _xid);
if (_timeoutFuture != null) {
LOGGER.debug("Attempting to cancel previous timeout task future for DtxBranch {}", _xid);
boolean succeeded = _timeoutFuture.cancel(false);
_timeoutFuture = null;
LOGGER.debug("Cancelling previous timeout task {} for DtxBranch {}", (succeeded ? "succeeded" : "failed"), _xid);
}
if (_transaction != null) {
// prepare has previously been called
Transaction txn = _dtxRegistry.getMessageStore().newTransaction();
txn.removeXid(_storedXidRecord);
txn.commitTran();
_transaction.abortTran();
}
for (ServerTransaction.Action action : _postTransactionActions) {
action.onRollback();
}
_postTransactionActions.clear();
}
Aggregations