Search in sources :

Example 56 with Attach

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

the class AbstractLinkEndpoint method receiveAttach.

@Override
public void receiveAttach(final Attach attach) throws AmqpErrorException {
    _errored = false;
    boolean isAttachingRemoteTerminusNull = (attach.getRole() == Role.SENDER ? attach.getSource() == null : attach.getTarget() == null);
    boolean isAttachingLocalTerminusNull = (attach.getRole() == Role.SENDER ? attach.getTarget() == null : attach.getSource() == null);
    boolean isLocalTerminusNull = (attach.getRole() == Role.SENDER ? getTarget() == null : getSource() == null);
    if (isAttachingRemoteTerminusNull) {
        throw new AmqpErrorException(AmqpError.INVALID_FIELD, "received Attach with remote null terminus.");
    }
    if (isAttachingLocalTerminusNull) {
        recoverLink(attach);
    } else if (isLocalTerminusNull) {
        establishLink(attach);
    } else if (attach.getUnsettled() != null) {
        // TODO: QPID-7845 : Functionality for resuming links is not fully implemented
        if (attach.getUnsettled().isEmpty()) {
            resumeLink(attach);
        } else {
            throw new AmqpErrorException(new Error(AmqpError.NOT_IMPLEMENTED, "Resuming link is not implemented."));
        }
    } else {
        reattachLink(attach);
    }
}
Also used : AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)

Example 57 with Attach

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

the class LinkImpl method attach.

@Override
public final synchronized ListenableFuture<? extends LinkEndpoint<S, T>> attach(final Session_1_0 session, final Attach attach) {
    try {
        if (_role == attach.getRole()) {
            throw new AmqpErrorException(new Error(AmqpError.ILLEGAL_STATE, "Cannot switch SendingLink to ReceivingLink and vice versa"));
        }
        if (_linkEndpoint != null && !session.equals(_linkEndpoint.getSession())) {
            SettableFuture<LinkEndpoint<S, T>> future = SettableFuture.create();
            _thiefQueue.add(new ThiefInformation(session, attach, future));
            startLinkStealingIfNecessary();
            return future;
        } else {
            if (_linkEndpoint == null) {
                _linkEndpoint = createLinkEndpoint(session, attach);
            }
            _linkEndpoint.receiveAttach(attach);
            _linkRegistry.linkChanged(this);
            return Futures.immediateFuture(_linkEndpoint);
        }
    } catch (Exception e) {
        LOGGER.debug("Error attaching link", e);
        return rejectLink(session, e);
    }
}
Also used : AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) LinkError(org.apache.qpid.server.protocol.v1_0.type.transport.LinkError) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) ExecutionException(java.util.concurrent.ExecutionException)

Example 58 with Attach

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

the class LinkImpl method doStealLink.

private ListenableFuture<LinkEndpoint<S, T>> doStealLink(final Session_1_0 session, final Attach attach) {
    final SettableFuture<LinkEndpoint<S, T>> returnFuture = SettableFuture.create();
    LinkEndpoint<S, T> linkEndpoint = _linkEndpoint;
    // check whether linkEndpoint has been closed in the mean time
    if (linkEndpoint != null) {
        linkEndpoint.getSession().doOnIOThreadAsync(() -> {
            // check whether linkEndpoint has been closed in the mean time
            if (_linkEndpoint != null) {
                _linkEndpoint.close(new Error(LinkError.STOLEN, String.format("Link is being stolen by connection '%s'", session.getConnection())));
            }
            doLinkStealAndHandleExceptions(session, attach, returnFuture);
        });
    } else {
        doLinkStealAndHandleExceptions(session, attach, returnFuture);
    }
    return returnFuture;
}
Also used : Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) LinkError(org.apache.qpid.server.protocol.v1_0.type.transport.LinkError)

Example 59 with Attach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach 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);
}
Also used : 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)

Example 60 with Attach

use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach 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);
}
Also used : AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)

Aggregations

Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)85 Test (org.junit.Test)84 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)82 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)82 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)70 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)39 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)37 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)36 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)32 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)32 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)27 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)24 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)23 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)20 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)18 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)17 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)17 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)14 InetSocketAddress (java.net.InetSocketAddress)13 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)11