Search in sources :

Example 1 with UnsettledDelivery

use of org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery in project qpid-broker-j by apache.

the class AbstractReceivingLinkEndpoint method receiveTransfer.

void receiveTransfer(final Transfer transfer) {
    if (!isErrored()) {
        Error error = validateTransfer(transfer);
        if (error != null) {
            transfer.dispose();
            if (_currentDelivery != null) {
                _currentDelivery.discard();
                _currentDelivery = null;
            }
            close(error);
            return;
        }
        if (_currentDelivery == null) {
            error = validateNewTransfer(transfer);
            if (error != null) {
                transfer.dispose();
                close(error);
                return;
            }
            _currentDelivery = new Delivery(transfer, this);
            setLinkCredit(getLinkCredit().subtract(UnsignedInteger.ONE));
            getDeliveryCount().incr();
            getSession().getIncomingDeliveryRegistry().addDelivery(transfer.getDeliveryId(), new UnsettledDelivery(transfer.getDeliveryTag(), this));
        } else {
            error = validateSubsequentTransfer(transfer);
            if (error != null) {
                transfer.dispose();
                _currentDelivery.discard();
                _currentDelivery = null;
                close(error);
                return;
            }
            _currentDelivery.addTransfer(transfer);
        }
        if (_currentDelivery.getTotalPayloadSize() > getSession().getConnection().getMaxMessageSize()) {
            error = new Error(LinkError.MESSAGE_SIZE_EXCEEDED, String.format("delivery '%s' exceeds max-message-size %d", _currentDelivery.getDeliveryTag(), getSession().getConnection().getMaxMessageSize()));
            _currentDelivery.discard();
            _currentDelivery = null;
            close(error);
            return;
        }
        if (!_currentDelivery.getResume()) {
            _unsettled.put(_currentDelivery.getDeliveryTag(), _currentDelivery.getState());
        }
        if (_currentDelivery.isAborted() || (_currentDelivery.getResume() && !_unsettled.containsKey(_currentDelivery.getDeliveryTag()))) {
            _unsettled.remove(_currentDelivery.getDeliveryTag());
            getSession().getIncomingDeliveryRegistry().removeDelivery(_currentDelivery.getDeliveryId());
            _currentDelivery = null;
            setLinkCredit(getLinkCredit().add(UnsignedInteger.ONE));
            getDeliveryCount().decr();
        } else if (_currentDelivery.isComplete()) {
            try {
                if (_currentDelivery.isSettled()) {
                    _unsettled.remove(_currentDelivery.getDeliveryTag());
                    getSession().getIncomingDeliveryRegistry().removeDelivery(_currentDelivery.getDeliveryId());
                }
                error = receiveDelivery(_currentDelivery);
                if (error != null) {
                    close(error);
                }
            } finally {
                _currentDelivery = null;
            }
        } else {
            getSession().sendFlowConditional();
        }
    } else {
        End end = new End();
        end.setError(new Error(SessionError.ERRANT_LINK, String.format("Received TRANSFER for link handle %s which is in errored state.", transfer.getHandle())));
        getSession().end(end);
    }
}
Also used : UnsettledDelivery(org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) SessionError(org.apache.qpid.server.protocol.v1_0.type.transport.SessionError) LinkError(org.apache.qpid.server.protocol.v1_0.type.transport.LinkError) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) UnsettledDelivery(org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery)

Example 2 with UnsettledDelivery

use of org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery in project qpid-broker-j by apache.

the class UnsettledDeliveryTest method testNotEqualsWhenLinkEndpointIsDifferent.

@Test
public void testNotEqualsWhenLinkEndpointIsDifferent() {
    final LinkEndpoint<?, ?> linkEndpoint = mock(LinkEndpoint.class);
    assertThat(_unsettledDelivery.equals(new UnsettledDelivery(new Binary(new byte[] { (byte) 32, (byte) 33 }), linkEndpoint)), is(equalTo(false)));
}
Also used : Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Test(org.junit.Test)

Example 3 with UnsettledDelivery

use of org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery in project qpid-broker-j by apache.

the class DeliveryRegistryImplTest method getDeliveryId.

@Test
public void getDeliveryId() {
    _registry.addDelivery(DELIVERY_ID, _unsettledDelivery);
    _registry.addDelivery(DELIVERY_ID_2, new UnsettledDelivery(DELIVERY_TAG, mock(LinkEndpoint.class)));
    final UnsignedInteger deliveryId = _registry.getDeliveryId(DELIVERY_TAG, _unsettledDelivery.getLinkEndpoint());
    assertThat(deliveryId, is(equalTo(DELIVERY_ID)));
}
Also used : UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Test(org.junit.Test)

Example 4 with UnsettledDelivery

use of org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery in project qpid-broker-j by apache.

the class Session_1_0 method sendTransfer.

void sendTransfer(final Transfer xfr, final SendingLinkEndpoint endpoint) {
    _nextOutgoingId.incr();
    final boolean settled = Boolean.TRUE.equals(xfr.getSettled());
    UnsignedInteger deliveryId = UnsignedInteger.valueOf(_nextOutgoingDeliveryId++);
    xfr.setDeliveryId(deliveryId);
    if (!settled) {
        final UnsettledDelivery delivery = new UnsettledDelivery(xfr.getDeliveryTag(), endpoint);
        _outgoingDeliveryRegistry.addDelivery(deliveryId, delivery);
    }
    _remoteIncomingWindow--;
    try (QpidByteBuffer payload = xfr.getPayload()) {
        long remaining = payload == null ? 0 : (long) payload.remaining();
        int payloadSent = _connection.sendFrame(_sendingChannel, xfr, payload);
        if (payload != null) {
            while (payloadSent < remaining && payloadSent >= 0) {
                Transfer continuationTransfer = new Transfer();
                continuationTransfer.setHandle(xfr.getHandle());
                continuationTransfer.setRcvSettleMode(xfr.getRcvSettleMode());
                continuationTransfer.setState(xfr.getState());
                continuationTransfer.setPayload(payload);
                _nextOutgoingId.incr();
                _remoteIncomingWindow--;
                remaining = (long) payload.remaining();
                payloadSent = _connection.sendFrame(_sendingChannel, continuationTransfer, payload);
                continuationTransfer.dispose();
            }
        }
    } catch (OversizeFrameException e) {
        throw new ConnectionScopedRuntimeException(e);
    }
}
Also used : OversizeFrameException(org.apache.qpid.server.protocol.v1_0.framing.OversizeFrameException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) UnsettledDelivery(org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 5 with UnsettledDelivery

use of org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery in project qpid-broker-j by apache.

the class Session_1_0 method receiveDisposition.

public void receiveDisposition(final Disposition disposition) {
    Role dispositionRole = disposition.getRole();
    DeliveryRegistry unsettledDeliveries;
    if (dispositionRole == Role.RECEIVER) {
        unsettledDeliveries = _outgoingDeliveryRegistry;
    } else {
        unsettledDeliveries = _incomingDeliveryRegistry;
    }
    SequenceNumber deliveryId = new SequenceNumber(disposition.getFirst().intValue());
    SequenceNumber last;
    if (disposition.getLast() == null) {
        last = new SequenceNumber(deliveryId.intValue());
    } else {
        last = new SequenceNumber(disposition.getLast().intValue());
    }
    while (deliveryId.compareTo(last) <= 0) {
        UnsignedInteger deliveryIdUnsigned = UnsignedInteger.valueOf(deliveryId.intValue());
        UnsettledDelivery unsettledDelivery = unsettledDeliveries.getDelivery(deliveryIdUnsigned);
        if (unsettledDelivery != null) {
            LinkEndpoint<?, ?> linkEndpoint = unsettledDelivery.getLinkEndpoint();
            linkEndpoint.receiveDeliveryState(unsettledDelivery.getDeliveryTag(), disposition.getState(), disposition.getSettled());
            if (Boolean.TRUE.equals(disposition.getSettled())) {
                unsettledDeliveries.removeDelivery(deliveryIdUnsigned);
            }
        }
        deliveryId.incr();
    }
}
Also used : Role(org.apache.qpid.server.protocol.v1_0.type.transport.Role) UnsettledDelivery(org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) DeliveryRegistry(org.apache.qpid.server.protocol.v1_0.delivery.DeliveryRegistry)

Aggregations

UnsettledDelivery (org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery)3 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)3 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)2 Test (org.junit.Test)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 LinkEndpoint (org.apache.qpid.server.protocol.v1_0.LinkEndpoint)1 DeliveryRegistry (org.apache.qpid.server.protocol.v1_0.delivery.DeliveryRegistry)1 OversizeFrameException (org.apache.qpid.server.protocol.v1_0.framing.OversizeFrameException)1 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)1 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)1 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)1 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)1 LinkError (org.apache.qpid.server.protocol.v1_0.type.transport.LinkError)1 Role (org.apache.qpid.server.protocol.v1_0.type.transport.Role)1 SessionError (org.apache.qpid.server.protocol.v1_0.type.transport.SessionError)1 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)1 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)1 Before (org.junit.Before)1