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);
}
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();
}
}
}
}
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();
}
}
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);
}
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;
}
Aggregations