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