Search in sources :

Example 11 with ServerTransaction

use of org.apache.qpid.server.txn.ServerTransaction 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 12 with ServerTransaction

use of org.apache.qpid.server.txn.ServerTransaction 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)

Example 13 with ServerTransaction

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

the class AbstractVirtualHost method executeTransaction.

@Override
public void executeTransaction(TransactionalOperation op) {
    final MessageStore store = getMessageStore();
    final LocalTransaction txn = new LocalTransaction(store);
    op.withinTransaction(new Transaction() {

        @Override
        public void dequeue(final QueueEntry messageInstance) {
            final ServerTransaction.Action deleteAction = new ServerTransaction.Action() {

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

                @Override
                public void onRollback() {
                }
            };
            boolean acquired = messageInstance.acquireOrSteal(new Runnable() {

                @Override
                public void run() {
                    ServerTransaction txn = new AutoCommitTransaction(store);
                    txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction);
                }
            });
            if (acquired) {
                txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction);
            }
        }

        @Override
        public void copy(QueueEntry entry, final Queue<?> queue) {
            final ServerMessage message = entry.getMessage();
            txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {

                @Override
                public void postCommit(MessageEnqueueRecord... records) {
                    queue.enqueue(message, null, records[0]);
                }

                @Override
                public void onRollback() {
                }
            });
        }

        @Override
        public void move(final QueueEntry entry, final Queue<?> queue) {
            final ServerMessage message = entry.getMessage();
            if (entry.acquire()) {
                txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {

                    @Override
                    public void postCommit(MessageEnqueueRecord... records) {
                        queue.enqueue(message, null, records[0]);
                    }

                    @Override
                    public void onRollback() {
                        entry.release();
                    }
                });
                txn.dequeue(entry.getEnqueueRecord(), new ServerTransaction.Action() {

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

                    @Override
                    public void onRollback() {
                    }
                });
            }
        }
    });
    txn.commit();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) PrivilegedAction(java.security.PrivilegedAction) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) QueueEntry(org.apache.qpid.server.queue.QueueEntry) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction)

Example 14 with ServerTransaction

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

the class AbstractAMQPConnection method getOldestTransactionStartTime.

@Override
public Date getOldestTransactionStartTime() {
    long oldest = Long.MAX_VALUE;
    Iterator<ServerTransaction> iterator = getOpenTransactions();
    while (iterator.hasNext()) {
        final ServerTransaction value = iterator.next();
        if (value instanceof LocalTransaction) {
            long transactionStartTimeLong = value.getTransactionStartTime();
            if (transactionStartTimeLong > 0 && oldest > transactionStartTimeLong) {
                oldest = transactionStartTimeLong;
            }
        }
    }
    return oldest == Long.MAX_VALUE ? null : new Date(oldest);
}
Also used : LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Date(java.util.Date)

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