Search in sources :

Example 21 with Detach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.

the class ErrantLinkEndpoint method close.

@Override
public void close(final Error error) {
    Detach detach = new Detach();
    detach.setHandle(_localHandle);
    detach.setClosed(true);
    detach.setError(error);
    _session.sendDetach(detach);
    _session.dissociateEndpoint(this);
    destroy();
    _link.linkClosed();
}
Also used : Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach)

Example 22 with Detach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.

the class SendingLinkEndpoint method remoteDetachedPerformDetach.

@Override
protected void remoteDetachedPerformDetach(final Detach detach) {
    TerminusExpiryPolicy expiryPolicy = getSource().getExpiryPolicy();
    if (Boolean.TRUE.equals(detach.getClosed()) || TerminusExpiryPolicy.LINK_DETACH.equals(expiryPolicy) || ((expiryPolicy == null || TerminusExpiryPolicy.SESSION_END.equals(expiryPolicy)) && getSession().isClosing()) || (TerminusExpiryPolicy.CONNECTION_CLOSE.equals(expiryPolicy) && getSession().getConnection().isClosing())) {
        cleanUpUnsettledDeliveries();
        close();
    } else if (detach.getError() != null) {
        cleanUpUnsettledDeliveries();
        detach();
        destroy();
        getConsumerTarget().updateNotifyWorkDesired();
    } else {
        detach();
        // TODO: QPID-7845 : Resuming links is unsupported at the moment. Destroying link unconditionally.
        destroy();
        getConsumerTarget().updateNotifyWorkDesired();
    }
}
Also used : TerminusExpiryPolicy(org.apache.qpid.server.protocol.v1_0.type.messaging.TerminusExpiryPolicy)

Example 23 with Detach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.

the class Session_1_0 method receiveDetach.

public void receiveDetach(final Detach detach) {
    receivedComplete();
    UnsignedInteger handle = detach.getHandle();
    detach(handle, detach);
}
Also used : UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 24 with Detach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach in project qpid-broker-j by apache.

the class Session_1_0Test method testReceiveReattachRebindingQueueNoActiveLinks.

public void testReceiveReattachRebindingQueueNoActiveLinks() {
    final String linkName = "testLink";
    final String address = "amq.direct/" + TOPIC_NAME;
    Attach attach = createSharedTopicAttach(true, linkName, address, true);
    _session.receiveAttach(attach);
    assertAttachSent(_connection, _session, attach);
    assertQueues(TOPIC_NAME, LifetimePolicy.PERMANENT);
    sendDetach(_session, attach.getHandle(), false);
    ArgumentCaptor<FrameBody> frameCapture = ArgumentCaptor.forClass(FrameBody.class);
    verify(_connection, times(2)).sendFrame(eq(_session.getChannelId()), frameCapture.capture());
    assertTrue(frameCapture.getAllValues().get(1) instanceof Detach);
    assertQueues(TOPIC_NAME, LifetimePolicy.PERMANENT);
    String topicName2 = TOPIC_NAME + "2";
    final String address2 = "amq.direct/" + topicName2;
    Attach attach2 = createSharedTopicAttach(true, linkName, address2, true);
    _session.receiveAttach(attach2);
    assertAttachSent(_connection, _session, attach2, 2);
    assertQueues(topicName2, LifetimePolicy.PERMANENT);
}
Also used : Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) FrameBody(org.apache.qpid.server.protocol.v1_0.type.FrameBody) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach)

Example 25 with Detach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Detach 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)

Aggregations

Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)27 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)27 Test (org.junit.Test)27 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)24 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)23 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)21 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)13 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)12 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)11 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)11 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)10 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)10 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)9 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)9 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)8 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)8 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)7 Ignore (org.junit.Ignore)7 HashMap (java.util.HashMap)5 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)4