use of org.apache.qpid.server.txn.ServerTransaction in project qpid-broker-j by apache.
the class AbstractAMQPConnection method registerTransactionTickers.
@Override
public void registerTransactionTickers(final ServerTransaction serverTransaction, final Action<String> closeAction, final long notificationRepeatPeriod) {
NamedAddressSpace addressSpace = getAddressSpace();
if (addressSpace instanceof QueueManagingVirtualHost) {
final QueueManagingVirtualHost<?> virtualhost = (QueueManagingVirtualHost<?>) addressSpace;
EventLogger eventLogger = virtualhost.getEventLogger();
final Set<Ticker> tickers = new LinkedHashSet<>(4);
if (virtualhost.getStoreTransactionOpenTimeoutWarn() > 0) {
tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionOpenTimeoutWarn(), notificationRepeatPeriod, serverTransaction::getTransactionStartTime, age -> eventLogger.message(getLogSubject(), ConnectionMessages.OPEN_TXN(age))));
}
if (virtualhost.getStoreTransactionOpenTimeoutClose() > 0) {
tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionOpenTimeoutClose(), notificationRepeatPeriod, serverTransaction::getTransactionStartTime, age -> closeAction.performAction(OPEN_TRANSACTION_TIMEOUT_ERROR)));
}
if (virtualhost.getStoreTransactionIdleTimeoutWarn() > 0) {
tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionIdleTimeoutWarn(), notificationRepeatPeriod, serverTransaction::getTransactionUpdateTime, age -> eventLogger.message(getLogSubject(), ConnectionMessages.IDLE_TXN(age))));
}
if (virtualhost.getStoreTransactionIdleTimeoutClose() > 0) {
tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionIdleTimeoutClose(), notificationRepeatPeriod, serverTransaction::getTransactionUpdateTime, age -> closeAction.performAction(IDLE_TRANSACTION_TIMEOUT_ERROR)));
}
if (!tickers.isEmpty()) {
for (Ticker ticker : tickers) {
getAggregateTicker().addTicker(ticker);
}
notifyWork();
}
_transactionTickers.put(serverTransaction, tickers);
}
}
use of org.apache.qpid.server.txn.ServerTransaction in project qpid-broker-j by apache.
the class AbstractQueue method clearQueue.
// ------ Management functions
@Override
public long clearQueue() {
QueueEntryIterator queueListIterator = getEntries().iterator();
long count = 0;
ServerTransaction txn = new LocalTransaction(getVirtualHost().getMessageStore());
while (queueListIterator.advance()) {
final QueueEntry node = queueListIterator.getNode();
boolean acquired = node.acquireOrSteal(new Runnable() {
@Override
public void run() {
dequeueEntry(node);
}
});
if (acquired) {
dequeueEntry(node, txn);
}
}
txn.commit();
return count;
}
use of org.apache.qpid.server.txn.ServerTransaction in project qpid-broker-j by apache.
the class LastValueQueueList method discardEntry.
private void discardEntry(final QueueEntry entry) {
if (entry.acquire()) {
ServerTransaction txn = new AutoCommitTransaction(getQueue().getVirtualHost().getMessageStore());
txn.dequeue(entry.getEnqueueRecord(), new ServerTransaction.Action() {
@Override
public void postCommit() {
entry.delete();
}
@Override
public void onRollback() {
}
});
}
}
use of org.apache.qpid.server.txn.ServerTransaction in project qpid-broker-j by apache.
the class AMQChannel method receiveTxSelect.
@Override
public void receiveTxSelect() {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("RECV[" + _channelId + "] TxSelect");
}
ServerTransaction txn = _transaction;
if (txn instanceof LocalTransaction) {
getConnection().unregisterTransactionTickers(_transaction);
}
_transaction = _connection.createLocalTransaction();
long notificationRepeatPeriod = getContextValue(Long.class, TRANSACTION_TIMEOUT_NOTIFICATION_REPEAT_PERIOD);
getConnection().registerTransactionTickers(_transaction, message -> _connection.sendConnectionCloseAsync(AMQPConnection.CloseReason.TRANSACTION_TIMEOUT, message), notificationRepeatPeriod);
MethodRegistry methodRegistry = _connection.getMethodRegistry();
TxSelectOkBody responseBody = methodRegistry.createTxSelectOkBody();
_connection.writeFrame(responseBody.generateFrame(_channelId));
}
use of org.apache.qpid.server.txn.ServerTransaction in project qpid-broker-j by apache.
the class AMQPConnection_1_0Impl method createIdentifiedTransaction.
@Override
public IdentifiedTransaction createIdentifiedTransaction() {
ServerTransaction[] openTransactions = _openTransactions;
final int maxOpenTransactions = openTransactions.length;
int id = 0;
for (; id < maxOpenTransactions; id++) {
if (openTransactions[id] == null) {
break;
}
}
// we need to expand the transaction array;
if (id == maxOpenTransactions) {
final int newSize = maxOpenTransactions < 1024 ? 2 * maxOpenTransactions : maxOpenTransactions + 1024;
_openTransactions = new ServerTransaction[newSize];
System.arraycopy(openTransactions, 0, _openTransactions, 0, maxOpenTransactions);
}
final LocalTransaction serverTransaction = createLocalTransaction();
_openTransactions[id] = serverTransaction;
return new IdentifiedTransaction(id, serverTransaction);
}
Aggregations