use of org.apache.qpid.server.txn.LocalTransaction in project qpid-broker-j by apache.
the class AbstractVirtualHost method executeTransaction.
@Override
public void executeTransaction(TransactionalOperation op) {
final MessageStore store = getMessageStore();
final LocalTransaction txn = new LocalTransaction(store);
op.withinTransaction(new Transaction() {
@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);
}
}
@Override
public void copy(QueueEntry entry, final Queue<?> queue) {
final ServerMessage message = entry.getMessage();
txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {
@Override
public void postCommit(MessageEnqueueRecord... records) {
queue.enqueue(message, null, records[0]);
}
@Override
public void onRollback() {
}
});
}
@Override
public void move(final QueueEntry entry, final Queue<?> queue) {
final ServerMessage message = entry.getMessage();
if (entry.acquire()) {
txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {
@Override
public void postCommit(MessageEnqueueRecord... records) {
queue.enqueue(message, null, records[0]);
}
@Override
public void onRollback() {
entry.release();
}
});
txn.dequeue(entry.getEnqueueRecord(), new ServerTransaction.Action() {
@Override
public void postCommit() {
entry.delete();
}
@Override
public void onRollback() {
}
});
}
}
});
txn.commit();
}
use of org.apache.qpid.server.txn.LocalTransaction in project qpid-broker-j by apache.
the class AbstractAMQPConnection method getOldestTransactionStartTime.
@Override
public Date getOldestTransactionStartTime() {
long oldest = Long.MAX_VALUE;
Iterator<ServerTransaction> iterator = getOpenTransactions();
while (iterator.hasNext()) {
final ServerTransaction value = iterator.next();
if (value instanceof LocalTransaction) {
long transactionStartTimeLong = value.getTransactionStartTime();
if (transactionStartTimeLong > 0 && oldest > transactionStartTimeLong) {
oldest = transactionStartTimeLong;
}
}
}
return oldest == Long.MAX_VALUE ? null : new Date(oldest);
}
Aggregations