Search in sources :

Example 1 with ServerTransaction

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AccessControlContext(java.security.AccessControlContext) SocketAddress(java.net.SocketAddress) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) SaslSettings(org.apache.qpid.server.security.auth.sasl.SaslSettings) SettableFuture(com.google.common.util.concurrent.SettableFuture) ConnectionMessages(org.apache.qpid.server.logging.messages.ConnectionMessages) ContextProvider(org.apache.qpid.server.model.ContextProvider) TransactionObserver(org.apache.qpid.server.txn.TransactionObserver) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) Map(java.util.Map) Port(org.apache.qpid.server.model.Port) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PrivilegedAction(java.security.PrivilegedAction) InetSocketAddress(java.net.InetSocketAddress) List(java.util.List) Principal(java.security.Principal) Transport(org.apache.qpid.server.model.Transport) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException) ConnectionLogSubject(org.apache.qpid.server.logging.subjects.ConnectionLogSubject) AccessController(java.security.AccessController) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) StatisticsGatherer(org.apache.qpid.server.stats.StatisticsGatherer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) FlowToDiskTransactionObserver(org.apache.qpid.server.txn.FlowToDiskTransactionObserver) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) HashMap(java.util.HashMap) EventLogger(org.apache.qpid.server.logging.EventLogger) LogSubject(org.apache.qpid.server.logging.LogSubject) ConnectionPrincipal(org.apache.qpid.server.connection.ConnectionPrincipal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) FixedKeyMapCreator(org.apache.qpid.server.util.FixedKeyMapCreator) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) TaskExecutorProvider(org.apache.qpid.server.model.TaskExecutorProvider) EventLoggerProvider(org.apache.qpid.server.logging.EventLoggerProvider) NetworkConnection(org.apache.qpid.server.transport.network.NetworkConnection) LinkedHashSet(java.util.LinkedHashSet) Session(org.apache.qpid.server.model.Session) Ticker(org.apache.qpid.server.transport.network.Ticker) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Logger(org.slf4j.Logger) Action(org.apache.qpid.server.util.Action) Iterator(java.util.Iterator) Broker(org.apache.qpid.server.model.Broker) State(org.apache.qpid.server.model.State) SubjectDomainCombiner(javax.security.auth.SubjectDomainCombiner) Protocol(org.apache.qpid.server.model.Protocol) Connection(org.apache.qpid.server.model.Connection) Subject(javax.security.auth.Subject) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) EventLogger(org.apache.qpid.server.logging.EventLogger) Ticker(org.apache.qpid.server.transport.network.Ticker) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace)

Example 2 with ServerTransaction

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

Example 3 with ServerTransaction

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() {
            }
        });
    }
}
Also used : AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction)

Example 4 with ServerTransaction

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

Example 5 with ServerTransaction

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

Aggregations

ServerTransaction (org.apache.qpid.server.txn.ServerTransaction)14 LocalTransaction (org.apache.qpid.server.txn.LocalTransaction)11 AutoCommitTransaction (org.apache.qpid.server.txn.AutoCommitTransaction)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)3 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)3 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)3 AccessControlException (java.security.AccessControlException)2 PrivilegedAction (java.security.PrivilegedAction)2 Date (java.util.Date)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)2 TransactionalState (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState)2 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 AccessControlContext (java.security.AccessControlContext)1 AccessController (java.security.AccessController)1 Principal (java.security.Principal)1