Search in sources :

Example 26 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class AbstractQueue method attemptDelivery.

/**
 * Attempt delivery for the given consumer.
 *
 * Looks up the next node for the consumer and attempts to deliver it.
 *
 * @param sub the consumer
 * @return true if we have completed all possible deliveries for this sub.
 */
private MessageContainer attemptDelivery(QueueConsumer<?, ?> sub) {
    // avoid referring old deleted queue entry in sub._queueContext._lastSeen
    QueueEntry node = getNextAvailableEntry(sub);
    boolean subActive = sub.isActive() && !sub.isSuspended();
    if (node != null && subActive && (sub.getPriority() == Integer.MAX_VALUE || noHigherPriorityWithCredit(sub, node))) {
        if (_virtualHost.getState() != State.ACTIVE) {
            throw new ConnectionScopedRuntimeException("Delivery halted owing to " + "virtualhost state " + _virtualHost.getState());
        }
        if (node.isAvailable() && mightAssign(sub, node)) {
            if (sub.allocateCredit(node)) {
                MessageReference messageReference = null;
                if ((sub.acquires() && !assign(sub, node)) || (!sub.acquires() && (messageReference = node.newMessageReference()) == null)) {
                    // restore credit here that would have been taken away by allocateCredit since we didn't manage
                    // to acquire the entry for this consumer
                    sub.restoreCredit(node);
                } else {
                    setLastSeenEntry(sub, node);
                    return new MessageContainer(node, messageReference);
                }
            } else {
                sub.awaitCredit(node);
            }
        }
    }
    return NO_MESSAGES;
}
Also used : MessageContainer(org.apache.qpid.server.message.MessageContainer) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) MessageReference(org.apache.qpid.server.message.MessageReference)

Example 27 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class AbstractConsumerTarget method sendNextMessage.

@Override
public boolean sendNextMessage() {
    MessageContainer messageContainer = null;
    MessageInstanceConsumer consumer = null;
    boolean iteratedCompleteList = false;
    while (messageContainer == null) {
        if (_pullIterator == null || !_pullIterator.hasNext()) {
            if (iteratedCompleteList) {
                break;
            }
            iteratedCompleteList = true;
            _pullIterator = getConsumers().iterator();
        }
        if (_pullIterator.hasNext()) {
            consumer = _pullIterator.next();
            messageContainer = consumer.pullMessage();
        }
    }
    if (messageContainer != null) {
        MessageInstance entry = messageContainer.getMessageInstance();
        try {
            send(consumer, entry, false);
        } catch (MessageConversionException mce) {
            restoreCredit(entry.getMessage());
            final TransactionLogResource owningResource = entry.getOwningResource();
            if (owningResource instanceof MessageSource) {
                final MessageSource.MessageConversionExceptionHandlingPolicy handlingPolicy = ((MessageSource) owningResource).getMessageConversionExceptionHandlingPolicy();
                switch(handlingPolicy) {
                    case CLOSE:
                        entry.release(consumer);
                        throw new ConnectionScopedRuntimeException(String.format("Unable to convert message %s for this consumer", entry.getMessage()), mce);
                    case ROUTE_TO_ALTERNATE:
                        if (consumer.acquires()) {
                            int enqueues = entry.routeToAlternate(null, null);
                            if (enqueues == 0) {
                                LOGGER.info("Failed to convert message {} for this consumer because '{}'." + "  Message discarded.", entry.getMessage(), mce.getMessage());
                            } else {
                                LOGGER.info("Failed to convert message {} for this consumer because '{}'." + "  Message routed to alternate.", entry.getMessage(), mce.getMessage());
                            }
                        } else {
                            LOGGER.info("Failed to convert message {} for this browser because '{}'." + "  Message skipped.", entry.getMessage(), mce.getMessage());
                        }
                        break;
                    case REJECT:
                        entry.reject(consumer);
                        entry.release(consumer);
                        LOGGER.info("Failed to convert message {} for this consumer because '{}'." + "  Message skipped.", entry.getMessage(), mce.getMessage());
                        break;
                    default:
                        throw new ServerScopedRuntimeException("Unrecognised policy " + handlingPolicy);
                }
            } else {
                throw new ConnectionScopedRuntimeException(String.format("Unable to convert message %s for this consumer", entry.getMessage()), mce);
            }
        } finally {
            if (messageContainer.getMessageReference() != null) {
                messageContainer.getMessageReference().release();
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : MessageInstance(org.apache.qpid.server.message.MessageInstance) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) MessageContainer(org.apache.qpid.server.message.MessageContainer) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) MessageSource(org.apache.qpid.server.message.MessageSource) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Example 28 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class TopicExchangeImpl method onBindingUpdated.

@Override
protected synchronized void onBindingUpdated(final BindingIdentifier binding, final Map<String, Object> newArguments) {
    final String bindingKey = binding.getBindingKey();
    final MessageDestination destination = binding.getDestination();
    LOGGER.debug("Updating binding of queue {} with routing key {}", destination.getName(), bindingKey);
    String routingKey = TopicNormalizer.normalize(bindingKey);
    try {
        if (_bindings.containsKey(binding)) {
            TopicExchangeResult result = _topicExchangeResults.get(routingKey);
            updateTopicExchangeResult(result, binding, newArguments);
        }
    } catch (AMQInvalidArgumentException e) {
        throw new ConnectionScopedRuntimeException(e);
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) AMQInvalidArgumentException(org.apache.qpid.server.filter.AMQInvalidArgumentException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) TopicExchangeResult(org.apache.qpid.server.exchange.topic.TopicExchangeResult)

Example 29 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method testOpenDatabaseWhenFacadeIsNotOpened.

public void testOpenDatabaseWhenFacadeIsNotOpened() throws Exception {
    DatabaseConfig createIfAbsentDbConfig = DatabaseConfig.DEFAULT.setAllowCreate(true);
    EnvironmentFacade ef = createMaster();
    ef.close();
    try {
        ef.openDatabase("myDatabase", createIfAbsentDbConfig);
        fail("Database open should fail");
    } catch (ConnectionScopedRuntimeException e) {
        assertEquals("Unexpected exception", "Environment facade is not in opened state", e.getMessage());
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) EnvironmentFacade(org.apache.qpid.server.store.berkeleydb.EnvironmentFacade) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 30 with ConnectionScopedRuntimeException

use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacade method mutateEnvironmentConfigValue.

void mutateEnvironmentConfigValue(final String paramName, final Object newValue) {
    final ReplicatedEnvironment environment = _environment.get();
    if (environment != null) {
        try {
            final ReplicationMutableConfig oldConfig = environment.getRepMutableConfig();
            final ReplicationMutableConfig newConfig = oldConfig.setConfigParam(paramName, String.valueOf(newValue));
            environment.setRepMutableConfig(newConfig);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Node {} param {} has been changed to {}", _prettyGroupNodeName, paramName, newValue);
            }
        } catch (RuntimeException e) {
            RuntimeException handled = handleDatabaseException(String.format("Exception on setting %s", paramName), e);
            if (handled instanceof ConnectionScopedRuntimeException || handled instanceof ServerScopedRuntimeException) {
                throw handled;
            }
            throw new ConnectionScopedRuntimeException(String.format("Cannot set %s to %s on node %s", paramName, newValue, _prettyGroupNodeName), e);
        }
    } else {
        throw new ConnectionScopedRuntimeException(String.format("Cannot set %s to %s on node %s as environment does not currently exists", paramName, newValue, _prettyGroupNodeName));
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Aggregations

ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)32 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)9 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)7 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)6 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 AmqpValueSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)4 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)3 AmqpSequenceSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection)3 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)3 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)3 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)2 ObjectOutputStream (java.io.ObjectOutputStream)2 BufferUnderflowException (java.nio.BufferUnderflowException)2