use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class SendingLinkEndpoint method recoverLink.
@Override
protected void recoverLink(final Attach attach) throws AmqpErrorException {
Source source = getSource();
if (source == null && attach.getDesiredCapabilities() != null) {
List<Symbol> capabilities = Arrays.asList(attach.getDesiredCapabilities());
if (capabilities.contains(Session_1_0.GLOBAL_CAPABILITY) && capabilities.contains(Session_1_0.SHARED_CAPABILITY) && getLinkName().endsWith("|global")) {
NamedAddressSpace namedAddressSpace = getSession().getConnection().getAddressSpace();
Collection<Link_1_0<? extends BaseSource, ? extends BaseTarget>> links = namedAddressSpace.findSendingLinks(ANY_CONTAINER_ID, Pattern.compile("^" + Pattern.quote(getLinkName()) + "$"));
for (Link_1_0<? extends BaseSource, ? extends BaseTarget> link : links) {
BaseSource baseSource = link.getSource();
if (baseSource instanceof Source) {
Source linkSource = (Source) baseSource;
source = new Source(linkSource);
getLink().setSource(source);
break;
}
}
}
}
if (source == null) {
throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, ""));
}
attach.setSource(source);
receiveAttach(attach);
}
use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class SendingLinkEndpoint method attachReceived.
@Override
public void attachReceived(final Attach attach) throws AmqpErrorException {
super.attachReceived(attach);
Target target = (Target) attach.getTarget();
Source source = getSource();
if (source == null) {
source = new Source();
Source attachSource = (Source) attach.getSource();
final Modified defaultOutcome = new Modified();
defaultOutcome.setDeliveryFailed(true);
source.setDefaultOutcome(defaultOutcome);
source.setOutcomes(Accepted.ACCEPTED_SYMBOL, Released.RELEASED_SYMBOL, Rejected.REJECTED_SYMBOL);
source.setAddress(attachSource.getAddress());
source.setDynamic(attachSource.getDynamic());
if (Boolean.TRUE.equals(attachSource.getDynamic()) && attachSource.getDynamicNodeProperties() != null) {
Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
if (attachSource.getDynamicNodeProperties().containsKey(Session_1_0.LIFETIME_POLICY)) {
dynamicNodeProperties.put(Session_1_0.LIFETIME_POLICY, attachSource.getDynamicNodeProperties().get(Session_1_0.LIFETIME_POLICY));
}
source.setDynamicNodeProperties(dynamicNodeProperties);
}
source.setDurable(TerminusDurability.min(attachSource.getDurable(), getLink().getHighestSupportedTerminusDurability()));
source.setExpiryPolicy(attachSource.getExpiryPolicy());
source.setDistributionMode(attachSource.getDistributionMode());
source.setFilter(attachSource.getFilter());
source.setCapabilities(attachSource.getCapabilities());
final SendingDestination destination = getSession().getSendingDestination(getLink(), source);
source.setCapabilities(destination.getCapabilities());
getLink().setSource(source);
prepareConsumerOptionsAndFilters(destination);
}
getLink().setTarget(target);
final MessageInstanceConsumer oldConsumer = getConsumer();
createConsumerTarget();
_resumeAcceptedTransfers.clear();
_resumeFullTransfers.clear();
final NamedAddressSpace addressSpace = getSession().getConnection().getAddressSpace();
// TODO: QPID-7845 : Resuming links is unsupported at the moment. Thus, cleaning up unsettled deliveries unconditionally.
cleanUpUnsettledDeliveries();
getSession().addDeleteTask(_cleanUpUnsettledDeliveryTask);
Map<Binary, OutgoingDelivery> unsettledCopy = new HashMap<>(_unsettled);
Map<Binary, DeliveryState> remoteUnsettled = attach.getUnsettled() == null ? Collections.emptyMap() : new HashMap<>(attach.getUnsettled());
final boolean isUnsettledComplete = !Boolean.TRUE.equals(attach.getIncompleteUnsettled());
for (Map.Entry<Binary, OutgoingDelivery> entry : unsettledCopy.entrySet()) {
Binary deliveryTag = entry.getKey();
final MessageInstance queueEntry = entry.getValue().getMessageInstance();
if (!remoteUnsettled.containsKey(deliveryTag) && isUnsettledComplete) {
queueEntry.setRedelivered();
queueEntry.release(oldConsumer);
_unsettled.remove(deliveryTag);
} else if (remoteUnsettled.get(deliveryTag) instanceof Outcome) {
Outcome outcome = (Outcome) remoteUnsettled.get(deliveryTag);
if (outcome instanceof Accepted) {
if (oldConsumer.acquires()) {
AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
if (queueEntry.acquire() || queueEntry.isAcquired()) {
txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {
@Override
public void postCommit() {
queueEntry.delete();
}
@Override
public void onRollback() {
}
});
}
}
} else if (outcome instanceof Released) {
if (oldConsumer.acquires()) {
AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {
@Override
public void postCommit() {
queueEntry.release(oldConsumer);
}
@Override
public void onRollback() {
}
});
}
}
// TODO: QPID-7845: Handle rejected and modified outcome
remoteUnsettled.remove(deliveryTag);
_resumeAcceptedTransfers.add(deliveryTag);
} else {
_resumeFullTransfers.add(queueEntry);
// TODO:QPID-7845: exists in receivers map, but not yet got an outcome ... should resend with resume = true
}
}
getConsumerTarget().updateNotifyWorkDesired();
}
use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class Session_1_0 method getReceivingDestination.
public ReceivingDestination getReceivingDestination(final Link_1_0<?, ?> link, final Target target) throws AmqpErrorException {
final ReceivingDestination destination;
if (target != null) {
if (Boolean.TRUE.equals(target.getDynamic())) {
MessageDestination tempDestination = createDynamicDestination(link, target.getDynamicNodeProperties(), target.getCapabilities());
if (tempDestination != null) {
target.setAddress(_primaryDomain + tempDestination.getName());
} else {
throw new AmqpErrorException(AmqpError.INTERNAL_ERROR, "Cannot create dynamic destination");
}
}
String addr = target.getAddress();
if (addr == null || "".equals(addr.trim())) {
destination = new AnonymousRelayDestination(getAddressSpace(), target, _connection.getEventLogger());
} else {
DestinationAddress destinationAddress = new DestinationAddress(getAddressSpace(), addr);
MessageDestination messageDestination = destinationAddress.getMessageDestination();
if (messageDestination != null) {
destination = new NodeReceivingDestination(destinationAddress, target.getDurable(), target.getExpiryPolicy(), target.getCapabilities(), _connection.getEventLogger());
} else {
destination = null;
}
}
} else {
destination = null;
}
if (destination == null) {
throw new AmqpErrorException(AmqpError.NOT_FOUND, String.format("Could not find destination for target '%s'", target));
}
return destination;
}
use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class Session_1_0 method createDynamicDestination.
private MessageDestination createDynamicDestination(final Link_1_0<?, ?> link, Map properties, final Symbol[] capabilities) throws AmqpErrorException {
final Set<Symbol> capabilitySet = capabilities == null ? Collections.emptySet() : Sets.newHashSet(capabilities);
boolean isTopic = capabilitySet.contains(Symbol.valueOf("temporary-topic")) || capabilitySet.contains(Symbol.valueOf("topic"));
final String destName = (isTopic ? "TempTopic" : "TempQueue") + UUID.randomUUID().toString();
try {
Map<String, Object> attributes = convertDynamicNodePropertiesToAttributes(link, properties, destName);
Class<? extends MessageDestination> clazz = isTopic ? Exchange.class : MessageDestination.class;
if (isTopic) {
attributes.put(Exchange.TYPE, ExchangeDefaults.FANOUT_EXCHANGE_CLASS);
}
return Subject.doAs(getSubjectWithAddedSystemRights(), (PrivilegedAction<MessageDestination>) () -> getAddressSpace().createMessageDestination(clazz, attributes));
} catch (AccessControlException e) {
throw new AmqpErrorException(AmqpError.UNAUTHORIZED_ACCESS, e.getMessage());
} catch (AbstractConfiguredObject.DuplicateNameException e) {
LOGGER.error("A temporary destination was created with a name which collided with an existing destination name '{}'", destName);
throw new ConnectionScopedRuntimeException(e);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException in project qpid-broker-j by apache.
the class Session_1_0 method createExchangeDestination.
private ExchangeSendingDestination createExchangeDestination(final String exchangeName, final String bindingKey, final String linkName, final Source source) throws AmqpErrorException {
ExchangeSendingDestination exchangeDestination = null;
Exchange<?> exchange = getExchange(exchangeName);
if (exchange != null) {
if (!Boolean.TRUE.equals(source.getDynamic())) {
String remoteContainerId = getConnection().getRemoteContainerId();
exchangeDestination = new ExchangeSendingDestination(exchange, linkName, bindingKey, remoteContainerId, source);
source.setFilter(exchangeDestination.getFilters());
source.setDistributionMode(StdDistMode.COPY);
} else {
// TODO
throw new AmqpErrorException(new Error(AmqpError.NOT_IMPLEMENTED, "Temporary subscription is not implemented"));
}
}
return exchangeDestination;
}
Aggregations