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