Search in sources :

Example 6 with LocalTransaction

use of org.apache.qpid.server.txn.LocalTransaction in project qpid-broker-j by apache.

the class ServerSession method onClose.

public void onClose() {
    AMQPConnection_0_10 amqpConnection = getAMQPConnection();
    if (_transaction instanceof LocalTransaction) {
        if (((LocalTransaction) _transaction).hasOutstandingWork()) {
            amqpConnection.incrementTransactionRollbackCounter();
        }
        amqpConnection.decrementTransactionOpenCounter();
        _transaction.rollback();
        amqpConnection.unregisterTransactionTickers(_transaction);
    } else if (_transaction instanceof DistributedTransaction) {
        getAddressSpace().getDtxRegistry().endAssociations(_modelObject);
    }
    for (MessageDispositionChangeListener listener : _messageDispositionListenerMap.values()) {
        listener.onRelease(true, true);
    }
    _messageDispositionListenerMap.clear();
    for (Action<? super Session_0_10> task : _modelObject.getTaskList()) {
        task.performAction(_modelObject);
    }
    LogMessage operationalLoggingMessage = _forcedCloseLogMessage.get();
    if (operationalLoggingMessage == null && getConnection().getConnectionCloseMessage() != null) {
        operationalLoggingMessage = ChannelMessages.CLOSE_FORCED(getConnection().getConnectionCloseCode(), getConnection().getConnectionCloseMessage());
    }
    if (operationalLoggingMessage == null) {
        operationalLoggingMessage = ChannelMessages.CLOSE();
    }
    amqpConnection.getEventLogger().message(getLogSubject(), operationalLoggingMessage);
}
Also used : DistributedTransaction(org.apache.qpid.server.txn.DistributedTransaction) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) LogMessage(org.apache.qpid.server.logging.LogMessage)

Example 7 with LocalTransaction

use of org.apache.qpid.server.txn.LocalTransaction in project qpid-broker-j by apache.

the class TxnCoordinatorReceivingLinkEndpoint method discharge.

private Error discharge(Binary transactionIdAsBinary, boolean fail) {
    Error error = null;
    Integer transactionId = null;
    ServerTransaction txn = null;
    try {
        transactionId = Session_1_0.transactionIdToInteger(transactionIdAsBinary);
        txn = _createdTransactions.get(transactionId);
    } catch (UnknownTransactionException | IllegalArgumentException e) {
    // handle error below
    }
    if (txn != null) {
        AMQPConnection_1_0<?> connection = getSession().getConnection();
        if (fail) {
            txn.rollback();
            connection.incrementTransactionRollbackCounter();
        } else if (!(txn instanceof LocalTransaction && ((LocalTransaction) txn).isRollbackOnly())) {
            txn.commit();
        } else {
            txn.rollback();
            connection.incrementTransactionRollbackCounter();
            error = new Error();
            error.setCondition(TransactionError.TRANSACTION_ROLLBACK);
            error.setDescription("The transaction was marked as rollback only due to an earlier issue (e.g. a published message was sent settled but could not be enqueued)");
        }
        _createdTransactions.remove(transactionId);
        connection.unregisterTransactionTickers(txn);
        connection.removeTransaction(transactionId);
        connection.decrementTransactionOpenCounter();
    } else {
        error = new Error();
        error.setCondition(TransactionError.UNKNOWN_ID);
        error.setDescription("Unknown transactionId " + transactionIdAsBinary.toString());
    }
    return error;
}
Also used : UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction)

Example 8 with LocalTransaction

use of org.apache.qpid.server.txn.LocalTransaction in project qpid-broker-j by apache.

the class ServerSession method selectTx.

public void selectTx() {
    ServerTransaction txn = _transaction;
    AMQPConnection_0_10 amqpConnection = getAMQPConnection();
    if (txn instanceof LocalTransaction) {
        amqpConnection.unregisterTransactionTickers(_transaction);
    }
    _transaction = amqpConnection.createLocalTransaction();
    long notificationRepeatPeriod = getModelObject().getContextValue(Long.class, Session.TRANSACTION_TIMEOUT_NOTIFICATION_REPEAT_PERIOD);
    amqpConnection.registerTransactionTickers(_transaction, message -> amqpConnection.sendConnectionCloseAsync(AMQPConnection.CloseReason.TRANSACTION_TIMEOUT, (String) message), notificationRepeatPeriod);
}
Also used : LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction)

Example 9 with LocalTransaction

use of org.apache.qpid.server.txn.LocalTransaction in project qpid-broker-j by apache.

the class AbstractQueue method routeToAlternate.

private void routeToAlternate(List<QueueEntry> entries) {
    ServerTransaction txn = new LocalTransaction(getVirtualHost().getMessageStore());
    for (final QueueEntry entry : entries) {
        // TODO log requeues with a post enqueue action
        int requeues = entry.routeToAlternate(null, txn);
        if (requeues == 0) {
        // TODO log discard
        }
    }
    txn.commit();
}
Also used : LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction)

Example 10 with LocalTransaction

use of org.apache.qpid.server.txn.LocalTransaction in project qpid-broker-j by apache.

the class QueueEntryImpl method routeToAlternate.

@Override
public int routeToAlternate(final Action<? super MessageInstance> action, ServerTransaction txn) {
    if (!isAcquired()) {
        throw new IllegalStateException("Illegal queue entry state. " + this + " is not acquired.");
    }
    final Queue<?> currentQueue = getQueue();
    MessageDestination alternateBindingDestination = currentQueue.getAlternateBindingDestination();
    boolean autocommit = txn == null;
    if (autocommit) {
        txn = new LocalTransaction(getQueue().getVirtualHost().getMessageStore());
    }
    RoutingResult result;
    if (alternateBindingDestination != null) {
        result = alternateBindingDestination.route(getMessage(), getMessage().getInitialRoutingAddress(), getInstanceProperties());
    } else {
        result = new RoutingResult<>(getMessage());
    }
    txn.dequeue(getEnqueueRecord(), new ServerTransaction.Action() {

        @Override
        public void postCommit() {
            delete();
        }

        @Override
        public void onRollback() {
        }
    });
    int enqueues = result.send(txn, null);
    if (autocommit) {
        txn.commit();
    }
    return enqueues;
}
Also used : RoutingResult(org.apache.qpid.server.message.RoutingResult) MessageDestination(org.apache.qpid.server.message.MessageDestination) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction)

Aggregations

LocalTransaction (org.apache.qpid.server.txn.LocalTransaction)12 ServerTransaction (org.apache.qpid.server.txn.ServerTransaction)10 LogMessage (org.apache.qpid.server.logging.LogMessage)2 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)2 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)2 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)2 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)2 AutoCommitTransaction (org.apache.qpid.server.txn.AutoCommitTransaction)2 AccessControlException (java.security.AccessControlException)1 PrivilegedAction (java.security.PrivilegedAction)1 Date (java.util.Date)1 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 MessageDestination (org.apache.qpid.server.message.MessageDestination)1 RoutingResult (org.apache.qpid.server.message.RoutingResult)1 ServerMessage (org.apache.qpid.server.message.ServerMessage)1 MessageFormat (org.apache.qpid.server.plugin.MessageFormat)1 AmqpErrorRuntimeException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorRuntimeException)1 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)1 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)1 Outcome (org.apache.qpid.server.protocol.v1_0.type.Outcome)1