use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class Interaction method txnDischarge.
public Interaction txnDischarge(Binary transactionId, boolean failed) throws Exception {
txnSendDischarge(transactionId, failed);
final DeliveryState state = handleCoordinatorResponse();
_transactionalState.setDeliveryState(state);
return this;
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class SendingLinkEndpoint method attachReceived.
@Override
public void attachReceived(final Attach attach) throws AmqpErrorException {
super.attachReceived(attach);
Target target = (Target) attach.getTarget();
Source source = getSource();
if (source == null) {
source = new Source();
Source attachSource = (Source) attach.getSource();
final Modified defaultOutcome = new Modified();
defaultOutcome.setDeliveryFailed(true);
source.setDefaultOutcome(defaultOutcome);
source.setOutcomes(Accepted.ACCEPTED_SYMBOL, Released.RELEASED_SYMBOL, Rejected.REJECTED_SYMBOL);
source.setAddress(attachSource.getAddress());
source.setDynamic(attachSource.getDynamic());
if (Boolean.TRUE.equals(attachSource.getDynamic()) && attachSource.getDynamicNodeProperties() != null) {
Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
if (attachSource.getDynamicNodeProperties().containsKey(Session_1_0.LIFETIME_POLICY)) {
dynamicNodeProperties.put(Session_1_0.LIFETIME_POLICY, attachSource.getDynamicNodeProperties().get(Session_1_0.LIFETIME_POLICY));
}
source.setDynamicNodeProperties(dynamicNodeProperties);
}
source.setDurable(TerminusDurability.min(attachSource.getDurable(), getLink().getHighestSupportedTerminusDurability()));
source.setExpiryPolicy(attachSource.getExpiryPolicy());
source.setDistributionMode(attachSource.getDistributionMode());
source.setFilter(attachSource.getFilter());
source.setCapabilities(attachSource.getCapabilities());
final SendingDestination destination = getSession().getSendingDestination(getLink(), source);
source.setCapabilities(destination.getCapabilities());
getLink().setSource(source);
prepareConsumerOptionsAndFilters(destination);
}
getLink().setTarget(target);
final MessageInstanceConsumer oldConsumer = getConsumer();
createConsumerTarget();
_resumeAcceptedTransfers.clear();
_resumeFullTransfers.clear();
final NamedAddressSpace addressSpace = getSession().getConnection().getAddressSpace();
// TODO: QPID-7845 : Resuming links is unsupported at the moment. Thus, cleaning up unsettled deliveries unconditionally.
cleanUpUnsettledDeliveries();
getSession().addDeleteTask(_cleanUpUnsettledDeliveryTask);
Map<Binary, OutgoingDelivery> unsettledCopy = new HashMap<>(_unsettled);
Map<Binary, DeliveryState> remoteUnsettled = attach.getUnsettled() == null ? Collections.emptyMap() : new HashMap<>(attach.getUnsettled());
final boolean isUnsettledComplete = !Boolean.TRUE.equals(attach.getIncompleteUnsettled());
for (Map.Entry<Binary, OutgoingDelivery> entry : unsettledCopy.entrySet()) {
Binary deliveryTag = entry.getKey();
final MessageInstance queueEntry = entry.getValue().getMessageInstance();
if (!remoteUnsettled.containsKey(deliveryTag) && isUnsettledComplete) {
queueEntry.setRedelivered();
queueEntry.release(oldConsumer);
_unsettled.remove(deliveryTag);
} else if (remoteUnsettled.get(deliveryTag) instanceof Outcome) {
Outcome outcome = (Outcome) remoteUnsettled.get(deliveryTag);
if (outcome instanceof Accepted) {
if (oldConsumer.acquires()) {
AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
if (queueEntry.acquire() || queueEntry.isAcquired()) {
txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {
@Override
public void postCommit() {
queueEntry.delete();
}
@Override
public void onRollback() {
}
});
}
}
} else if (outcome instanceof Released) {
if (oldConsumer.acquires()) {
AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {
@Override
public void postCommit() {
queueEntry.release(oldConsumer);
}
@Override
public void onRollback() {
}
});
}
}
// TODO: QPID-7845: Handle rejected and modified outcome
remoteUnsettled.remove(deliveryTag);
_resumeAcceptedTransfers.add(deliveryTag);
} else {
_resumeFullTransfers.add(queueEntry);
// TODO:QPID-7845: exists in receivers map, but not yet got an outcome ... should resend with resume = true
}
}
getConsumerTarget().updateNotifyWorkDesired();
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState 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("temporary-queue"))) {
targetCapabilities.add(Symbol.valueOf("temporary-queue"));
}
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.type.DeliveryState in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeReceivingLinkEmptyUnsettled.
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed," + " the unsettled field from the attach frame will carry" + " the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeReceivingLinkEmptyUnsettled() throws Exception {
Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, getTestName());
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction().negotiateOpen().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flowNextIncomingIdFromPeerLatestSessionBeginAndDeliveryCount().flow().receiveDelivery().decodeLatestDelivery();
Object data = interaction.getDecodedLatestDelivery();
assertThat(data, is(equalTo(getTestName())));
interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionFirstFromLatestDelivery().dispositionRole(Role.RECEIVER).disposition();
Detach detach = interaction.detach().consume(Detach.class, Flow.class);
assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
interaction.attachUnsettled(new HashMap<>()).attach().consumeResponse(Attach.class);
Attach attach = interaction.getLatestResponse(Attach.class);
Map<Binary, DeliveryState> unsettled = attach.getUnsettled();
assumeThat(unsettled, notNullValue());
assertThat(unsettled.entrySet(), empty());
}
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeSendingLinkSinglePartialDelivery.
@Ignore("QPID-7845")
@Test
@SpecificationTest(section = "2.6.13", description = "When a suspended link having unsettled deliveries is resumed, the unsettled field from the" + " attach frame will carry the delivery-tags and delivery state of all deliveries" + " considered unsettled by the issuing link endpoint.")
public void resumeSendingLinkSinglePartialDelivery() throws Exception {
final String destination = BrokerAdmin.TEST_QUEUE_NAME;
final Binary deliveryTag = new Binary("testDeliveryTag".getBytes(StandardCharsets.UTF_8));
QpidByteBuffer[] messagePayload = Utils.splitPayload(getTestName(), 2);
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final UnsignedInteger linkHandle1 = UnsignedInteger.ZERO;
final Interaction interaction = transport.newInteraction();
interaction.negotiateOpen().begin().consumeResponse(Begin.class);
// 1. attach with ReceiverSettleMode.SECOND
interaction.attachHandle(linkHandle1).attachRole(Role.SENDER).attachTargetAddress(destination).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
// 2. send a partial delivery
interaction.transferHandle(linkHandle1).transferDeliveryId(UnsignedInteger.ZERO).transferDeliveryTag(deliveryTag).transferMore(true).transferPayload(messagePayload[0]).transfer();
// 3. detach the link
interaction.detach().consumeResponse(Detach.class);
// 4. resume the link
final UnsignedInteger linkHandle2 = UnsignedInteger.ONE;
final Attach responseAttach2 = interaction.attachHandle(linkHandle2).attachUnsettled(Collections.singletonMap(deliveryTag, null)).attach().consumeResponse().getLatestResponse(Attach.class);
// 5. assert content of unsettled map
assertThat(responseAttach2.getTarget(), is(notNullValue()));
final Map<Binary, DeliveryState> remoteUnsettled = responseAttach2.getUnsettled();
assertThat(remoteUnsettled, is(notNullValue()));
assertThat(remoteUnsettled.keySet(), is(equalTo(Collections.singleton(deliveryTag))));
interaction.transferHandle(linkHandle2).transferResume(true).transfer().sync().transferMore(false).transferPayload(messagePayload[1]).transfer();
for (final QpidByteBuffer payload : messagePayload) {
payload.dispose();
}
boolean settled = false;
do {
interaction.consumeResponse();
Response<?> response = interaction.getLatestResponse();
assertThat(response, is(notNullValue()));
Object body = response.getBody();
if (body instanceof Disposition) {
Disposition disposition = (Disposition) body;
assertThat(disposition.getSettled(), is(Matchers.equalTo(true)));
assertThat(disposition.getFirst(), equalTo(UnsignedInteger.ZERO));
settled = true;
} else if (!(body instanceof Flow)) {
fail("Unexpected response " + body);
}
} while (!settled);
interaction.doCloseConnection();
}
}
Aggregations