use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class SendingLinkEndpoint method resumeLink.
@Override
protected void resumeLink(final Attach attach) throws AmqpErrorException {
if (getSource() == null) {
throw new IllegalStateException("Terminus should be set when resuming a Link.");
}
if (attach.getSource() == null) {
throw new IllegalStateException("Attach.getSource should not be null when resuming a Link. That would be recovering the Link.");
}
Source newSource = (Source) attach.getSource();
Source oldSource = getSource();
final SendingDestination destination = getSession().getSendingDestination(getLink(), oldSource);
prepareConsumerOptionsAndFilters(destination);
if (getDestination() instanceof ExchangeSendingDestination && !Boolean.TRUE.equals(newSource.getDynamic())) {
final SendingDestination newDestination = getSession().getSendingDestination(getLink(), newSource);
if (getSession().updateSourceForSubscription(this, newSource, newDestination)) {
setDestination(newDestination);
}
}
attachReceived(attach);
}
use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class SendingLinkEndpoint method prepareConsumerOptionsAndFilters.
private void prepareConsumerOptionsAndFilters(final SendingDestination destination) throws AmqpErrorException {
// TODO QPID-7952: this method might modify the source. this is not good encapsulation. furthermore if it does so then it should inform the link/linkregistry about it!
_destination = destination;
final Source source = getSource();
EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
boolean noLocal = false;
JMSSelectorFilter messageFilter = null;
if (destination instanceof ExchangeSendingDestination) {
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
} else if (destination instanceof StandardSendingDestination) {
MessageSource messageSource = _destination.getMessageSource();
if (messageSource instanceof Queue && ((Queue<?>) messageSource).getAvailableAttributes().contains("topic")) {
source.setDistributionMode(StdDistMode.COPY);
}
Map<Symbol, Filter> filters = source.getFilter();
Map<Symbol, Filter> actualFilters = new HashMap<>();
if (filters != null) {
for (Map.Entry<Symbol, Filter> entry : filters.entrySet()) {
if (entry.getValue() instanceof NoLocalFilter) {
actualFilters.put(entry.getKey(), entry.getValue());
noLocal = true;
} else if (messageFilter == null && entry.getValue() instanceof org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) {
org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter selectorFilter = (org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) entry.getValue();
try {
messageFilter = new JMSSelectorFilter(selectorFilter.getValue());
actualFilters.put(entry.getKey(), entry.getValue());
} catch (ParseException | SelectorParsingException | TokenMgrError e) {
Error error = new Error();
error.setCondition(AmqpError.INVALID_FIELD);
error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
throw new AmqpErrorException(error);
}
}
}
}
source.setFilter(actualFilters.isEmpty() ? null : actualFilters);
if (source.getDistributionMode() != StdDistMode.COPY) {
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
}
} else {
throw new ConnectionScopedRuntimeException("Unknown destination type");
}
if (noLocal) {
options.add(ConsumerOption.NO_LOCAL);
}
FilterManager filters = null;
if (messageFilter != null) {
filters = new FilterManager();
filters.add(messageFilter.getName(), messageFilter);
}
_consumerOptions = options;
_consumerFilters = filters;
}
use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class SendingLinkEndpoint method createConsumerTarget.
private void createConsumerTarget() throws AmqpErrorException {
final Source source = getSource();
_consumerTarget = new ConsumerTarget_1_0(this, _destination instanceof ExchangeSendingDestination || source.getDistributionMode() != StdDistMode.COPY);
try {
final String name = getTarget().getAddress() == null ? getLinkName() : getTarget().getAddress();
_consumer = _destination.getMessageSource().addConsumer(_consumerTarget, _consumerFilters, Message_1_0.class, name, _consumerOptions, getPriority());
_consumerTarget.updateNotifyWorkDesired();
} catch (MessageSource.ExistingExclusiveConsumer e) {
String msg = "Cannot add a consumer to the destination as there is already an exclusive consumer";
throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, msg), e);
} catch (MessageSource.ExistingConsumerPreventsExclusive e) {
String msg = "Cannot add an exclusive consumer to the destination as there is already a consumer";
throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, msg), e);
} catch (MessageSource.ConsumerAccessRefused e) {
String msg = "Cannot add an exclusive consumer to the destination as there is an incompatible exclusivity policy";
throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, msg), e);
} catch (MessageSource.QueueDeleted e) {
String msg = "Cannot add a consumer to the destination as the destination has been deleted";
throw new AmqpErrorException(new Error(AmqpError.RESOURCE_DELETED, msg), e);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class StandardReceivingLinkEndpoint method recoverLink.
@Override
protected void recoverLink(final Attach attach) throws AmqpErrorException {
if (getTarget() == null) {
throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, String.format("Link '%s' not found", getLinkName())));
}
attach.setTarget(getTarget());
receiveAttach(attach);
}
use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class TxnCoordinatorReceivingLinkEndpoint method receiveDelivery.
@Override
protected Error receiveDelivery(Delivery delivery) {
// Only interested in the amqp-value section that holds the message to the coordinator
try (QpidByteBuffer payload = delivery.getPayload()) {
List<EncodingRetainingSection<?>> sections = getSectionDecoder().parseAll(payload);
boolean amqpValueSectionFound = false;
for (EncodingRetainingSection section : sections) {
try {
if (section instanceof AmqpValueSection) {
if (amqpValueSectionFound) {
throw new ConnectionScopedRuntimeException("Received more than one AmqpValue sections");
}
amqpValueSectionFound = true;
Object command = section.getValue();
Session_1_0 session = getSession();
AMQPConnection_1_0<?> connection = session.getConnection();
connection.receivedComplete();
if (command instanceof Declare) {
final IdentifiedTransaction txn = connection.createIdentifiedTransaction();
_createdTransactions.put(txn.getId(), txn.getServerTransaction());
long notificationRepeatPeriod = getSession().getContextValue(Long.class, Session.TRANSACTION_TIMEOUT_NOTIFICATION_REPEAT_PERIOD);
connection.registerTransactionTickers(txn.getServerTransaction(), this::doTimeoutAction, notificationRepeatPeriod);
Declared state = new Declared();
state.setTxnId(Session_1_0.integerToTransactionId(txn.getId()));
updateDisposition(delivery.getDeliveryTag(), state, true);
} else if (command instanceof Discharge) {
Discharge discharge = (Discharge) command;
Error error = discharge(discharge.getTxnId(), Boolean.TRUE.equals(discharge.getFail()));
final DeliveryState outcome;
if (error == null) {
outcome = new Accepted();
} else if (Arrays.asList(getSource().getOutcomes()).contains(Rejected.REJECTED_SYMBOL)) {
final Rejected rejected = new Rejected();
rejected.setError(error);
outcome = rejected;
error = null;
} else {
outcome = null;
}
if (error == null) {
updateDisposition(delivery.getDeliveryTag(), outcome, true);
}
return error;
} else {
throw new ConnectionScopedRuntimeException(String.format("Received unknown command '%s'", command.getClass().getSimpleName()));
}
}
} finally {
section.dispose();
}
}
if (!amqpValueSectionFound) {
throw new ConnectionScopedRuntimeException("Received no AmqpValue section");
}
} catch (AmqpErrorException e) {
return e.getError();
}
return null;
}
Aggregations