Search in sources :

Example 1 with SequenceNumber

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

the class Session_1_0 method updateDisposition.

private void updateDisposition(final Role role, final UnsignedInteger first, final UnsignedInteger last, final DeliveryState state, final boolean settled) {
    Disposition disposition = new Disposition();
    disposition.setRole(role);
    disposition.setFirst(first);
    disposition.setLast(last);
    disposition.setSettled(settled);
    disposition.setState(state);
    if (settled) {
        final DeliveryRegistry deliveryRegistry = role == Role.RECEIVER ? _incomingDeliveryRegistry : _outgoingDeliveryRegistry;
        SequenceNumber pos = new SequenceNumber(first.intValue());
        SequenceNumber end = new SequenceNumber(last.intValue());
        while (pos.compareTo(end) <= 0) {
            deliveryRegistry.removeDelivery(UnsignedInteger.valueOf(pos.intValue()));
            pos.incr();
        }
    }
    send(disposition);
}
Also used : Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) DeliveryRegistry(org.apache.qpid.server.protocol.v1_0.delivery.DeliveryRegistry)

Example 2 with SequenceNumber

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

the class Session_1_0 method receiveFlow.

public void receiveFlow(final Flow flow) {
    receivedComplete();
    final SequenceNumber flowNextIncomingId = new SequenceNumber(flow.getNextIncomingId() == null ? _initialOutgoingId.intValue() : flow.getNextIncomingId().intValue());
    if (flowNextIncomingId.compareTo(_nextOutgoingId) > 0) {
        final End end = new End();
        end.setError(new Error(SessionError.WINDOW_VIOLATION, String.format("Next incoming id '%d' exceeds next outgoing id '%d'", flowNextIncomingId.longValue(), _nextOutgoingId.longValue())));
        end(end);
    } else {
        _remoteIncomingWindow = flowNextIncomingId.longValue() + flow.getIncomingWindow().longValue() - _nextOutgoingId.longValue();
        _nextIncomingId = new SequenceNumber(flow.getNextOutgoingId().intValue());
        _remoteOutgoingWindow = flow.getOutgoingWindow();
        UnsignedInteger handle = flow.getHandle();
        if (handle != null) {
            final LinkEndpoint<? extends BaseSource, ? extends BaseTarget> endpoint = _inputHandleToEndpoint.get(handle);
            if (endpoint == null) {
                End end = new End();
                end.setError(new Error(SessionError.UNATTACHED_HANDLE, String.format("Received Flow with unknown handle %d", handle.intValue())));
                end(end);
            } else {
                endpoint.receiveFlow(flow);
            }
        } else {
            final Collection<LinkEndpoint<? extends BaseSource, ? extends BaseTarget>> allLinkEndpoints = _inputHandleToEndpoint.values();
            for (LinkEndpoint<? extends BaseSource, ? extends BaseTarget> le : allLinkEndpoints) {
                le.flowStateChanged();
            }
            if (Boolean.TRUE.equals(flow.getEcho())) {
                sendFlow();
            }
        }
    }
}
Also used : BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) 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) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget)

Example 3 with SequenceNumber

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

Example 4 with SequenceNumber

use of org.apache.qpid.server.protocol.v1_0.SequenceNumber 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 5 with SequenceNumber

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

the class AnonymousTerminusTest method getDispositionForDeliveryId.

private Disposition getDispositionForDeliveryId(final Interaction interaction, final UnsignedInteger deliveryId) throws Exception {
    Disposition dischargeTransactionDisposition = null;
    SequenceNumber id = new SequenceNumber(deliveryId.intValue());
    do {
        Response<?> response = interaction.consumeResponse(Disposition.class, Flow.class).getLatestResponse();
        if (response.getBody() instanceof Disposition) {
            Disposition disposition = (Disposition) response.getBody();
            UnsignedInteger first = disposition.getFirst();
            UnsignedInteger last = disposition.getLast() == null ? disposition.getFirst() : disposition.getLast();
            if (new SequenceNumber(first.intValue()).compareTo(id) >= 0 && new SequenceNumber(last.intValue()).compareTo(id) <= 0) {
                dischargeTransactionDisposition = disposition;
            }
        }
    } while (dischargeTransactionDisposition == null);
    return dischargeTransactionDisposition;
}
Also used : Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) SequenceNumber(org.apache.qpid.server.protocol.v1_0.SequenceNumber) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow)

Aggregations

UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)3 DeliveryRegistry (org.apache.qpid.server.protocol.v1_0.delivery.DeliveryRegistry)2 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SequenceNumber (org.apache.qpid.server.protocol.v1_0.SequenceNumber)1 UnsettledDelivery (org.apache.qpid.server.protocol.v1_0.delivery.UnsettledDelivery)1 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)1 BaseTarget (org.apache.qpid.server.protocol.v1_0.type.BaseTarget)1 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)1 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)1 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)1 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)1 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)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 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)1 LinkError (org.apache.qpid.server.protocol.v1_0.type.transport.LinkError)1