use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.
the class SendingLinkEndpoint method detach.
@Override
protected void detach(Error error, final boolean close) {
if (_consumerTarget != null) {
_consumerTarget.close();
}
Source source = getSource();
TerminusExpiryPolicy expiryPolicy = source.getExpiryPolicy();
NamedAddressSpace addressSpace = getSession().getConnection().getAddressSpace();
List<Symbol> sourceCapabilities = source.getCapabilities() == null ? Collections.emptyList() : Arrays.asList(source.getCapabilities());
if (close || TerminusExpiryPolicy.LINK_DETACH.equals(expiryPolicy) || ((expiryPolicy == null || TerminusExpiryPolicy.SESSION_END.equals(expiryPolicy)) && getSession().isClosing()) || (TerminusExpiryPolicy.CONNECTION_CLOSE.equals(expiryPolicy) && getSession().getConnection().isClosing())) {
Error closingError = null;
if (getDestination() instanceof ExchangeSendingDestination && addressSpace instanceof QueueManagingVirtualHost) {
cleanUpUnsettledDeliveries();
try {
((QueueManagingVirtualHost) addressSpace).removeSubscriptionQueue(((ExchangeSendingDestination) getDestination()).getQueue().getName());
TerminusDurability sourceDurability = source.getDurable();
if (sourceDurability != null && !TerminusDurability.NONE.equals(sourceDurability) && sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
Pattern containerIdPattern = sourceCapabilities.contains(Session_1_0.GLOBAL_CAPABILITY) ? ANY_CONTAINER_ID : Pattern.compile("^" + Pattern.quote(getSession().getConnection().getRemoteContainerId()) + "$");
Pattern linkNamePattern = Pattern.compile("^" + Pattern.quote(getLinkName()) + "\\|?\\d*$");
final Collection<LinkModel> links = addressSpace.findSendingLinks(containerIdPattern, linkNamePattern);
for (LinkModel link : links) {
if (link instanceof Link_1_0) {
((Link_1_0) link).linkClosed();
}
}
}
} catch (AccessControlException e) {
LOGGER.error("Error unregistering subscription", e);
closingError = new Error(AmqpError.NOT_ALLOWED, "Error unregistering subscription");
} catch (IllegalStateException e) {
String message;
if (sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
String subscriptionName = getLinkName();
int separator = subscriptionName.indexOf("|");
if (separator > 0) {
subscriptionName = subscriptionName.substring(0, separator);
}
message = "There are active consumers on the shared subscription '" + subscriptionName + "'";
} else {
message = e.getMessage();
}
closingError = new Error(AmqpError.RESOURCE_LOCKED, message);
} catch (NotFoundException e) {
closingError = new Error(AmqpError.NOT_FOUND, e.getMessage());
}
}
if (error == null) {
error = closingError;
} else {
LOGGER.warn("Unexpected error on detaching endpoint {}: {}", getLinkName(), error);
}
} else if (addressSpace instanceof QueueManagingVirtualHost && ((QueueManagingVirtualHost) addressSpace).isDiscardGlobalSharedSubscriptionLinksOnDetach() && sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(Session_1_0.GLOBAL_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
// However, we keep one link (ending with "|global") to perform a null-source lookup upon un-subscription.
if (!getLinkName().endsWith("|global")) {
getLink().linkClosed();
} else {
Pattern linkNamePattern = Pattern.compile("^" + Pattern.quote(getLinkName()) + "$");
final Collection<LinkModel> links = addressSpace.findSendingLinks(ANY_CONTAINER_ID, linkNamePattern);
if (links.size() > 1) {
getLink().linkClosed();
}
}
}
super.detach(error, close);
}
use of org.apache.qpid.server.protocol.v1_0.type.Symbol 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.Symbol in project qpid-broker-j by apache.
the class StandardReceivingLinkEndpoint method attachReceived.
@Override
public void attachReceived(final Attach attach) throws AmqpErrorException {
super.attachReceived(attach);
Source source = (Source) attach.getSource();
Target target = new Target();
Target attachTarget = (Target) attach.getTarget();
setDeliveryCount(new SequenceNumber(attach.getInitialDeliveryCount().intValue()));
target.setAddress(attachTarget.getAddress());
target.setDynamic(attachTarget.getDynamic());
if (Boolean.TRUE.equals(attachTarget.getDynamic()) && attachTarget.getDynamicNodeProperties() != null) {
Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
if (attachTarget.getDynamicNodeProperties().containsKey(Session_1_0.LIFETIME_POLICY)) {
dynamicNodeProperties.put(Session_1_0.LIFETIME_POLICY, attachTarget.getDynamicNodeProperties().get(Session_1_0.LIFETIME_POLICY));
}
target.setDynamicNodeProperties(dynamicNodeProperties);
}
target.setDurable(TerminusDurability.min(attachTarget.getDurable(), getLink().getHighestSupportedTerminusDurability()));
final List<Symbol> targetCapabilities = new ArrayList<>();
if (attachTarget.getCapabilities() != null) {
final List<Symbol> desiredCapabilities = Arrays.asList(attachTarget.getCapabilities());
if (desiredCapabilities.contains(Symbol.valueOf("temporary-topic"))) {
targetCapabilities.add(Symbol.valueOf("temporary-topic"));
}
if (desiredCapabilities.contains(Symbol.valueOf("topic"))) {
targetCapabilities.add(Symbol.valueOf("topic"));
}
target.setCapabilities(targetCapabilities.toArray(new Symbol[targetCapabilities.size()]));
}
target.setExpiryPolicy(attachTarget.getExpiryPolicy());
final ReceivingDestination destination = getSession().getReceivingDestination(getLink(), target);
targetCapabilities.addAll(Arrays.asList(destination.getCapabilities()));
target.setCapabilities(targetCapabilities.toArray(new Symbol[targetCapabilities.size()]));
setCapabilities(targetCapabilities);
setDestination(destination);
if (!Boolean.TRUE.equals(attach.getIncompleteUnsettled())) {
Map remoteUnsettled = attach.getUnsettled();
Map<Binary, DeliveryState> unsettledCopy = new HashMap<>(_unsettled);
for (Map.Entry<Binary, DeliveryState> entry : unsettledCopy.entrySet()) {
Binary deliveryTag = entry.getKey();
if (remoteUnsettled == null || !remoteUnsettled.containsKey(deliveryTag)) {
_unsettled.remove(deliveryTag);
}
}
}
getLink().setTermini(source, target);
_rejectedOutcomeSupportedBySource = source.getOutcomes() != null && Arrays.asList(source.getOutcomes()).contains(Rejected.REJECTED_SYMBOL);
}
use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.
the class SymbolTypeConstructor method construct.
@Override
public Symbol construct(final QpidByteBuffer in, final ValueHandler handler) throws AmqpErrorException {
int size;
if (!in.hasRemaining(getSize())) {
throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
}
if (getSize() == 1) {
size = in.getUnsignedByte();
} else {
size = in.getInt();
}
if (!in.hasRemaining(size)) {
throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
}
byte[] data = new byte[size];
in.get(data);
final BinaryString binaryStr = new BinaryString(data);
Symbol symbolVal = SYMBOL_MAP.get(binaryStr);
if (symbolVal == null) {
symbolVal = Symbol.valueOf(new String(data, ASCII));
SYMBOL_MAP.putIfAbsent(binaryStr, symbolVal);
}
return symbolVal;
}
use of org.apache.qpid.server.protocol.v1_0.type.Symbol in project qpid-broker-j by apache.
the class Interaction method attachSourceOutcomes.
public Interaction attachSourceOutcomes(final Symbol... outcomes) {
Source source = ((Source) _attach.getSource());
source.setOutcomes(outcomes);
_attach.setSource(source);
return this;
}
Aggregations