Search in sources :

Example 56 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class AbstractQueue method getOldestMessageArrivalTime.

@Override
public long getOldestMessageArrivalTime() {
    long oldestMessageArrivalTime = -1L;
    while (oldestMessageArrivalTime == -1L) {
        QueueEntryList entries = getEntries();
        QueueEntry entry = entries == null ? null : entries.getOldestEntry();
        if (entry != null) {
            ServerMessage message = entry.getMessage();
            if (message != null) {
                try (MessageReference reference = message.newReference()) {
                    oldestMessageArrivalTime = reference.getMessage().getArrivalTime();
                } catch (MessageDeletedException e) {
                // ignore - the oldest message was deleted after it was discovered - we need to find the new oldest message
                }
            }
        } else {
            oldestMessageArrivalTime = 0;
        }
    }
    return oldestMessageArrivalTime;
}
Also used : MessageDeletedException(org.apache.qpid.server.message.MessageDeletedException) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageReference(org.apache.qpid.server.message.MessageReference)

Example 57 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage 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 58 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class DirectExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKey.

public void testRouteToQueueViaTwoExchangesWithReplacementRoutingKey() {
    Map<String, Object> viaExchangeArguments = new HashMap<>();
    viaExchangeArguments.put(Exchange.NAME, "via_exchange");
    viaExchangeArguments.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
    Exchange via = _vhost.createChild(Exchange.class, viaExchangeArguments);
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    boolean exchToViaBind = _exchange.bind(via.getName(), "key1", Collections.singletonMap(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, "key2"), false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    boolean viaToQueueBind = via.bind(queue.getName(), "key2", Collections.emptyMap(), false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(_messageWithNoHeaders, "key1", _instanceProperties);
    assertTrue("Message unexpectedly not routed to queue", result.hasRoutes());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 59 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class DirectExchangeTest method testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering.

public void testRouteToQueueViaTwoExchangesWithReplacementRoutingKeyAndFiltering() {
    Map<String, Object> viaExchangeArguments = new HashMap<>();
    viaExchangeArguments.put(Exchange.NAME, getTestName() + "_via_exch");
    viaExchangeArguments.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
    Exchange via = _vhost.createChild(Exchange.class, viaExchangeArguments);
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    Map<String, Object> exchToViaBindArguments = new HashMap<>();
    exchToViaBindArguments.put(Binding.BINDING_ARGUMENT_REPLACEMENT_ROUTING_KEY, "key2");
    exchToViaBindArguments.put(JMS_SELECTOR.toString(), "prop = True");
    boolean exchToViaBind = _exchange.bind(via.getName(), "key1", exchToViaBindArguments, false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    boolean viaToQueueBind = via.bind(queue.getName(), "key2", Collections.emptyMap(), false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(createTestMessage(Collections.singletonMap("prop", true)), "key1", _instanceProperties);
    assertTrue("Message unexpectedly not routed to queue", result.hasRoutes());
    result = _exchange.route(createTestMessage(Collections.singletonMap("prop", false)), "key1", _instanceProperties);
    assertFalse("Message unexpectedly routed to queue", result.hasRoutes());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Example 60 with ServerMessage

use of org.apache.qpid.server.message.ServerMessage in project qpid-broker-j by apache.

the class DirectExchangeTest method testRouteToQueueViaTwoExchanges.

public void testRouteToQueueViaTwoExchanges() {
    String boundKey = "key";
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(Exchange.NAME, getTestName());
    attributes.put(Exchange.TYPE, ExchangeDefaults.DIRECT_EXCHANGE_CLASS);
    Exchange via = _vhost.createChild(Exchange.class, attributes);
    Queue<?> queue = _vhost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, getTestName() + "_queue"));
    boolean exchToViaBind = _exchange.bind(via.getName(), boundKey, Collections.emptyMap(), false);
    assertTrue("Exchange to exchange bind operation should be successful", exchToViaBind);
    boolean viaToQueueBind = via.bind(queue.getName(), boundKey, Collections.emptyMap(), false);
    assertTrue("Exchange to queue bind operation should be successful", viaToQueueBind);
    RoutingResult<ServerMessage<?>> result = _exchange.route(_messageWithNoHeaders, boundKey, _instanceProperties);
    assertTrue("Message unexpectedly not routed to queue", result.hasRoutes());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Aggregations

ServerMessage (org.apache.qpid.server.message.ServerMessage)103 HashMap (java.util.HashMap)26 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)16 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)16 Exchange (org.apache.qpid.server.model.Exchange)14 MessageReference (org.apache.qpid.server.message.MessageReference)13 ArrayList (java.util.ArrayList)9 MessageInstance (org.apache.qpid.server.message.MessageInstance)8 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)7 Queue (org.apache.qpid.server.model.Queue)7 StoredMessage (org.apache.qpid.server.store.StoredMessage)6 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)3 TestConsumerTarget (org.apache.qpid.server.consumer.TestConsumerTarget)3 MessageDeletedException (org.apache.qpid.server.message.MessageDeletedException)3 PrivilegedAction (java.security.PrivilegedAction)2 UUID (java.util.UUID)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 MessageInstanceConsumer (org.apache.qpid.server.message.MessageInstanceConsumer)2 RoutingResult (org.apache.qpid.server.message.RoutingResult)2