use of org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger 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.type.UnsignedInteger 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.type.UnsignedInteger in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController.
@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " [...]" + " <Not in spec yet>" + " AMQP-140" + " If a message cannot be routed to the destination implied in the \"to:\" field," + " and the source does not allow for the rejected outcome" + " [...] when messages are being sent within a transaction and have been sent pre-settled." + " In this case the behaviour defined for transactions (of essentially marking" + " the transaction as rollback only) should take precedence. " + "" + " AMQP spec 4.3 Discharging a Transaction" + " If the coordinator is unable to complete the discharge, the coordinator MUST convey" + " the error to the controller as a transaction-error. If the source for the link to" + " the coordinator supports the rejected outcome, then the message MUST be rejected" + " with this outcome carrying the transaction-error.")
@Test
public void transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final UnsignedInteger linkHandle = UnsignedInteger.ONE;
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(linkHandle).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.TRUE).transferDeliveryId(UnsignedInteger.valueOf(1)).transfer();
final Discharge discharge = new Discharge();
discharge.setTxnId(txnState.getCurrentTransactionId());
discharge.setFail(false);
interaction.transferHandle(txnState.getHandle()).transferDeliveryId(UnsignedInteger.valueOf(2)).transferSettled(Boolean.FALSE).transferDeliveryTag(new Binary(("transaction-" + 2).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
Disposition dischargeTransactionDisposition = getDispositionForDeliveryId(interaction, UnsignedInteger.valueOf(2));
assertThat(dischargeTransactionDisposition.getSettled(), is(equalTo(true)));
assertThat(dischargeTransactionDisposition.getState(), is(instanceOf(Rejected.class)));
Rejected rejected = (Rejected) dischargeTransactionDisposition.getState();
Error error = rejected.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeNotSupportedByTxController.
@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " [...]" + " <Not in spec yet>" + " AMQP-140" + " If a message cannot be routed to the destination implied in the \"to:\" field," + " and the source does not allow for the rejected outcome" + " [...] when messages are being sent within a transaction and have been sent pre-settled." + " In this case the behaviour defined for transactions (of essentially marking" + " the transaction as rollback only) should take precedence. " + "" + " AMQP spec 4.3 Discharging a Transaction" + " If the coordinator is unable to complete the discharge, the coordinator MUST convey" + " the error to the controller as a transaction-error." + " [...]" + " If the source does not support the rejected outcome, the transactional resource MUST" + " detach the link to the coordinator, with the detach performative carrying" + " the transaction-error")
@Test
public void transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeNotSupportedByTxController() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final UnsignedInteger linkHandle = UnsignedInteger.ONE;
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachName("testTransactionCoordinator-" + txnState.getHandle()).attachHandle(txnState.getHandle()).attachInitialDeliveryCount(UnsignedInteger.ZERO).attachTarget(new Coordinator()).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(linkHandle).attachTarget(new Target()).attachName("link-" + linkHandle).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.TRUE).transfer();
final Discharge discharge = new Discharge();
discharge.setTxnId(txnState.getCurrentTransactionId());
discharge.setFail(false);
interaction.transferHandle(txnState.getHandle()).transferSettled(Boolean.FALSE).transferDeliveryId(UnsignedInteger.valueOf(4)).transferDeliveryTag(new Binary(("transaction-" + 4).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
Detach transactionCoordinatorDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
Error transactionCoordinatorDetachError = transactionCoordinatorDetach.getError();
assertThat(transactionCoordinatorDetachError, is(notNullValue()));
assertThat(transactionCoordinatorDetachError.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger 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