Search in sources :

Example 6 with RoutingResult

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

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

the class AbstractQueueTestBase method testRingOverflowPolicyMessagesRejected.

public void testRingOverflowPolicyMessagesRejected() {
    Map<String, Object> attributes = new HashMap<>(_arguments);
    attributes.put(Queue.OVERFLOW_POLICY, OverflowPolicy.RING);
    attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_MESSAGES, 0);
    Queue<?> queue = getQueue();
    queue.setAttributes(attributes);
    ServerMessage message;
    RoutingResult result;
    message = createMessage(new Long(27), 20, 10);
    result = queue.route(message, message.getInitialRoutingAddress(), null);
    assertTrue("Result should include not accepting route", result.isRejected());
    int headerSize = 20;
    int payloadSize = 10;
    int id = 28;
    attributes = new HashMap<>(_arguments);
    attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_MESSAGES, 10);
    attributes.put(Queue.MAXIMUM_QUEUE_DEPTH_BYTES, 10);
    queue.setAttributes(attributes);
    message = createMessage(new Long(id), headerSize, payloadSize);
    result = queue.route(message, message.getInitialRoutingAddress(), null);
    assertTrue("Result should include not accepting route", result.isRejected());
}
Also used : RoutingResult(org.apache.qpid.server.message.RoutingResult) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage)

Aggregations

RoutingResult (org.apache.qpid.server.message.RoutingResult)7 MessageDestination (org.apache.qpid.server.message.MessageDestination)4 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)3 ServerMessage (org.apache.qpid.server.message.ServerMessage)2 VirtualHostUnavailableException (org.apache.qpid.server.virtualhost.VirtualHostUnavailableException)2 AccessControlException (java.security.AccessControlException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 MessageReference (org.apache.qpid.server.message.MessageReference)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)1 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)1 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)1 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)1 MessageHandle (org.apache.qpid.server.store.MessageHandle)1 MessageStore (org.apache.qpid.server.store.MessageStore)1 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)1 StoredMemoryMessage (org.apache.qpid.server.store.StoredMemoryMessage)1 StoredMessage (org.apache.qpid.server.store.StoredMessage)1