Search in sources :

Example 31 with Symbol

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);
}
Also used : Pattern(java.util.regex.Pattern) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) AccessControlException(java.security.AccessControlException) NotFoundException(org.apache.qpid.server.model.NotFoundException) TerminusDurability(org.apache.qpid.server.protocol.v1_0.type.messaging.TerminusDurability) MessageSource(org.apache.qpid.server.message.MessageSource) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) LinkModel(org.apache.qpid.server.protocol.LinkModel) TerminusExpiryPolicy(org.apache.qpid.server.protocol.v1_0.type.messaging.TerminusExpiryPolicy) Collection(java.util.Collection)

Example 32 with Symbol

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);
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) AccessControlException(java.security.AccessControlException) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 33 with Symbol

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);
}
Also used : HashMap(java.util.HashMap) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) ArrayList(java.util.ArrayList) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Map(java.util.Map) HashMap(java.util.HashMap)

Example 34 with 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;
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)

Example 35 with Symbol

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;
}
Also used : BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source)

Aggregations

Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)27 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)11 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)7 Map (java.util.Map)6 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)6 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)6 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)6 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)5 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)5 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)4 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)4 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3