Search in sources :

Example 11 with DeliveryState

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

the class Interaction method handleCoordinatorResponse.

private DeliveryState handleCoordinatorResponse() throws Exception {
    final Set<Class<?>> expected = new HashSet<>(Collections.singletonList(Disposition.class));
    if (_coordinatorCredits.decrementAndGet() == 0) {
        expected.add(Flow.class);
    }
    final Map<Class<?>, ?> responses = consumeResponses(expected, Collections.singleton(Flow.class));
    final Disposition disposition = (Disposition) responses.get(Disposition.class);
    if (expected.contains(Flow.class)) {
        Flow flow = (Flow) responses.get(Flow.class);
        if (flow.getHandle().equals(getCoordinatorHandle())) {
            final UnsignedInteger linkCredit = flow.getLinkCredit();
            if (linkCredit != null) {
                _coordinatorCredits.set(linkCredit.longValue());
            }
        }
    }
    if (!Boolean.TRUE.equals(disposition.getSettled())) {
        throw new IllegalStateException("Coordinator disposition is not settled");
    }
    return disposition.getState();
}
Also used : Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) HashSet(java.util.HashSet) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow)

Example 12 with DeliveryState

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

the class Session_1_0 method updateDisposition.

void updateDisposition(final Role role, final Set<Binary> deliveryTags, final DeliveryState state, final boolean settled) {
    final DeliveryRegistry deliveryRegistry = role == Role.RECEIVER ? _incomingDeliveryRegistry : _outgoingDeliveryRegistry;
    SortedSet<UnsignedInteger> deliveryIds = deliveryTags.stream().map(deliveryRegistry::getDeliveryIdByTag).collect(Collectors.toCollection(TreeSet::new));
    final Iterator<UnsignedInteger> iterator = deliveryIds.iterator();
    if (iterator.hasNext()) {
        UnsignedInteger begin = iterator.next();
        UnsignedInteger end = begin;
        while (iterator.hasNext()) {
            final UnsignedInteger deliveryId = iterator.next();
            if (!end.add(UnsignedInteger.ONE).equals(deliveryId)) {
                updateDisposition(role, begin, end, state, settled);
                begin = deliveryId;
                end = begin;
            } else {
                end = deliveryId;
            }
        }
        updateDisposition(role, begin, end, state, settled);
    }
}
Also used : UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) DeliveryRegistry(org.apache.qpid.server.protocol.v1_0.delivery.DeliveryRegistry)

Example 13 with DeliveryState

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

the class Session_1_0 method updateDisposition.

void updateDisposition(final Role role, final Binary deliveryTag, final DeliveryState state, final boolean settled) {
    final DeliveryRegistry deliveryRegistry = role == Role.RECEIVER ? _incomingDeliveryRegistry : _outgoingDeliveryRegistry;
    UnsignedInteger deliveryId = deliveryRegistry.getDeliveryIdByTag(deliveryTag);
    if (deliveryId == null) {
        throw new ConnectionScopedRuntimeException(String.format("Delivery with tag '%s' is not found in unsettled deliveries", deliveryTag));
    }
    updateDisposition(role, deliveryId, deliveryId, state, settled);
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) DeliveryRegistry(org.apache.qpid.server.protocol.v1_0.delivery.DeliveryRegistry)

Example 14 with DeliveryState

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

the class AbstractLinkEndpoint method handleOversizedUnsettledMapIfNecessary.

private Attach handleOversizedUnsettledMapIfNecessary(final Attach attachToSend) {
    final AMQPDescribedTypeRegistry describedTypeRegistry = getSession().getConnection().getDescribedTypeRegistry();
    final ValueWriter<Attach> valueWriter = describedTypeRegistry.getValueWriter(attachToSend);
    if (valueWriter.getEncodedSize() + 8 > getSession().getConnection().getMaxFrameSize()) {
        _localIncompleteUnsettled = true;
        attachToSend.setIncompleteUnsettled(true);
        final int targetSize = getSession().getConnection().getMaxFrameSize();
        int lowIndex = 0;
        Map<Binary, DeliveryState> localUnsettledMap = attachToSend.getUnsettled();
        if (localUnsettledMap == null) {
            localUnsettledMap = Collections.emptyMap();
        }
        int highIndex = localUnsettledMap.size();
        int currentIndex = (highIndex - lowIndex) / 2;
        int oldIndex;
        HashMap<Binary, DeliveryState> unsettledMap = null;
        int totalSize;
        do {
            HashMap<Binary, DeliveryState> partialUnsettledMap = new HashMap<>(currentIndex);
            final Iterator<Map.Entry<Binary, DeliveryState>> iterator = localUnsettledMap.entrySet().iterator();
            for (int i = 0; i < currentIndex; ++i) {
                final Map.Entry<Binary, DeliveryState> entry = iterator.next();
                partialUnsettledMap.put(entry.getKey(), entry.getValue());
            }
            attachToSend.setUnsettled(partialUnsettledMap);
            totalSize = describedTypeRegistry.getValueWriter(attachToSend).getEncodedSize() + FRAME_HEADER_SIZE;
            if (totalSize > targetSize) {
                highIndex = currentIndex;
            } else if (totalSize < targetSize) {
                lowIndex = currentIndex;
                unsettledMap = partialUnsettledMap;
            } else {
                lowIndex = highIndex = currentIndex;
                unsettledMap = partialUnsettledMap;
            }
            oldIndex = currentIndex;
            currentIndex = lowIndex + (highIndex - lowIndex) / 2;
        } while (oldIndex != currentIndex);
        if (unsettledMap == null || unsettledMap.isEmpty()) {
            final End endWithError = new End();
            endWithError.setError(new Error(AmqpError.FRAME_SIZE_TOO_SMALL, "Cannot fit a single unsettled delivery into Attach frame."));
            getSession().end(endWithError);
        }
        attachToSend.setUnsettled(unsettledMap);
    } else {
        _localIncompleteUnsettled = false;
    }
    return attachToSend;
}
Also used : AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) HashMap(java.util.HashMap) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with DeliveryState

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

the class Delivery method addTransfer.

final void addTransfer(Transfer transfer) {
    if (_aborted) {
        throw new IllegalStateException(String.format("Delivery '%s/%d' is already aborted", _deliveryTag, _deliveryId.intValue()));
    }
    if (_complete) {
        throw new IllegalStateException(String.format("Delivery '%s/%d' is already completed", _deliveryTag, _deliveryId.intValue()));
    }
    _transfers.add(transfer);
    if (Boolean.TRUE.equals(transfer.getAborted())) {
        _aborted = true;
        discard();
    }
    if (!Boolean.TRUE.equals(transfer.getMore())) {
        _complete = true;
    }
    if (Boolean.TRUE.equals(transfer.getSettled())) {
        _settled = true;
    }
    if (Boolean.TRUE.equals(transfer.getResume())) {
        _resume = true;
    }
    if (transfer.getState() != null) {
        DeliveryState currentState;
        if (_state instanceof TransactionalState) {
            currentState = ((TransactionalState) _state).getOutcome();
        } else {
            currentState = _state;
        }
        if (!(currentState instanceof Outcome)) {
            _state = transfer.getState();
        }
    }
    if (transfer.getRcvSettleMode() != null) {
        if (_receiverSettleMode == null) {
            _receiverSettleMode = transfer.getRcvSettleMode();
        }
    }
    try (QpidByteBuffer payload = transfer.getPayload()) {
        if (payload != null) {
            _totalPayloadSize += (long) payload.remaining();
        }
    }
}
Also used : DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Outcome(org.apache.qpid.server.protocol.v1_0.type.Outcome) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState)

Aggregations

DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)21 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)15 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)14 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)13 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)13 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)13 Test (org.junit.Test)13 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)12 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)10 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)9 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)9 HashMap (java.util.HashMap)8 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)8 Ignore (org.junit.Ignore)7 Map (java.util.Map)6 Rejected (org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected)6 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)6 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)5 TransactionalState (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState)5 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)5