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);
}
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;
}
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);
}
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();
}
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;
}
Aggregations