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