use of org.apache.qpid.server.queue.BaseQueue in project qpid-broker-j by apache.
the class AsyncAutoCommitTransaction method enqueue.
@Override
public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, EnqueueAction postTransactionAction) {
Transaction txn = null;
try {
final MessageEnqueueRecord[] records = new MessageEnqueueRecord[queues.size()];
int i = 0;
for (BaseQueue queue : queues) {
if (queue.getMessageDurability().persist(message.isPersistent())) {
LOGGER.debug("Enqueue of message number {} to transaction log. Queue : {}", message.getMessageNumber(), queue.getName());
if (txn == null) {
txn = _messageStore.newTransaction();
}
records[i] = txn.enqueueMessage(queue, message);
}
i++;
}
ListenableFuture<Void> future;
if (txn != null) {
future = txn.commitTranAsync((Void) null);
txn = null;
} else {
future = Futures.immediateFuture(null);
}
final EnqueueAction underlying = postTransactionAction;
addEnqueueFuture(future, new Action() {
@Override
public void postCommit() {
if (underlying != null) {
underlying.postCommit(records);
}
}
@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.queue.BaseQueue in project qpid-broker-j by apache.
the class DistributedTransaction method enqueue.
@Override
public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, final EnqueueAction postTransactionAction) {
if (_branch != null) {
final MessageEnqueueRecord[] enqueueRecords = new MessageEnqueueRecord[queues.size()];
int i = 0;
for (BaseQueue queue : queues) {
final int pos = i;
_branch.enqueue(queue, message, new org.apache.qpid.server.util.Action<MessageEnqueueRecord>() {
@Override
public void performAction(final MessageEnqueueRecord record) {
enqueueRecords[pos] = record;
}
});
i++;
}
addPostTransactionAction(new Action() {
@Override
public void postCommit() {
postTransactionAction.postCommit(enqueueRecords);
}
@Override
public void onRollback() {
postTransactionAction.onRollback();
}
});
} else {
_autoCommitTransaction.enqueue(queues, message, postTransactionAction);
}
}
use of org.apache.qpid.server.queue.BaseQueue in project qpid-broker-j by apache.
the class AutoCommitTransaction method enqueue.
@Override
public void enqueue(Collection<? extends BaseQueue> queues, EnqueueableMessage message, EnqueueAction postTransactionAction) {
Transaction txn = null;
try {
MessageEnqueueRecord[] enqueueRecords = new MessageEnqueueRecord[queues.size()];
int i = 0;
for (BaseQueue queue : queues) {
if (queue.getMessageDurability().persist(message.isPersistent())) {
LOGGER.debug("Enqueue of message number {} to transaction log. Queue : {}", message.getMessageNumber(), queue.getName());
if (txn == null) {
txn = _messageStore.newTransaction();
}
enqueueRecords[i] = txn.enqueueMessage(queue, message);
}
i++;
}
if (txn != null) {
txn.commitTran();
txn = null;
}
if (postTransactionAction != null) {
postTransactionAction.postCommit(enqueueRecords);
}
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.queue.BaseQueue in project qpid-broker-j by apache.
the class AutoCommitTransactionTest method createTestAMQQueue.
private BaseQueue createTestAMQQueue(final boolean durable) {
BaseQueue queue = mock(BaseQueue.class);
when(queue.getMessageDurability()).thenReturn(durable ? MessageDurability.DEFAULT : MessageDurability.NEVER);
return queue;
}
use of org.apache.qpid.server.queue.BaseQueue in project qpid-broker-j by apache.
the class AutoCommitTransactionTest method createTestQueueEntries.
private Collection<MessageInstance> createTestQueueEntries(boolean[] queueDurableFlags, boolean[] messagePersistentFlags) {
Collection<MessageInstance> queueEntries = new ArrayList<MessageInstance>();
assertTrue("Boolean arrays must be the same length", queueDurableFlags.length == messagePersistentFlags.length);
for (int i = 0; i < queueDurableFlags.length; i++) {
final BaseQueue queue = createTestAMQQueue(queueDurableFlags[i]);
final ServerMessage message = createTestMessage(messagePersistentFlags[i]);
final boolean hasRecord = queueDurableFlags[i] && messagePersistentFlags[i];
queueEntries.add(new MockMessageInstance() {
@Override
public ServerMessage getMessage() {
return message;
}
@Override
public TransactionLogResource getOwningResource() {
return queue;
}
@Override
public MessageEnqueueRecord getEnqueueRecord() {
if (hasRecord) {
return mock(MessageEnqueueRecord.class);
} else {
return null;
}
}
});
}
return queueEntries;
}
Aggregations