Search in sources :

Example 16 with Transaction

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;
}
Also used : MessageDurability(org.apache.qpid.server.store.MessageDurability) Transaction(org.apache.qpid.server.store.Transaction) EnqueueableMessage(org.apache.qpid.server.message.EnqueueableMessage) UUID(java.util.UUID) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource)

Example 17 with Transaction

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);
    }
}
Also used : Transaction(org.apache.qpid.server.store.Transaction) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 18 with Transaction

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);
    }
}
Also used : Transaction(org.apache.qpid.server.store.Transaction)

Example 19 with Transaction

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);
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) Transaction(org.apache.qpid.server.store.Transaction) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord)

Example 20 with Transaction

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();
}
Also used : Transaction(org.apache.qpid.server.store.Transaction)

Aggregations

Transaction (org.apache.qpid.server.store.Transaction)20 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)12 MessageStore (org.apache.qpid.server.store.MessageStore)6 UUID (java.util.UUID)5 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)4 MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)4 MessageInstanceHandler (org.apache.qpid.server.store.handler.MessageInstanceHandler)4 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)3 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)3 EnqueueableMessage (org.apache.qpid.server.message.EnqueueableMessage)2 MessageInstance (org.apache.qpid.server.message.MessageInstance)2 MessageReference (org.apache.qpid.server.message.MessageReference)2 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2 BaseQueue (org.apache.qpid.server.queue.BaseQueue)2 StoredMessage (org.apache.qpid.server.store.StoredMessage)2 EnqueueRecord (org.apache.qpid.server.store.Transaction.EnqueueRecord)2 DistributedTransactionHandler (org.apache.qpid.server.store.handler.DistributedTransactionHandler)2 DtxBranch (org.apache.qpid.server.txn.DtxBranch)2