use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow in project qpid-broker-j by apache.
the class SendingLinkEndpoint method receiveFlow.
@Override
public void receiveFlow(final Flow flow) {
UnsignedInteger receiverDeliveryCount = flow.getDeliveryCount();
UnsignedInteger receiverLinkCredit = flow.getLinkCredit();
setDrain(flow.getDrain());
Map<Symbol, Object> properties = flow.getProperties();
if (properties != null) {
final Binary transactionId = (Binary) properties.get(Symbol.valueOf("txn-id"));
if (transactionId != null) {
try {
getSession().getTransaction(transactionId);
} catch (UnknownTransactionException e) {
close(new Error(TransactionError.UNKNOWN_ID, e.getMessage()));
return;
}
}
_transactionId = transactionId;
}
if (receiverDeliveryCount == null) {
setLinkCredit(receiverLinkCredit);
} else {
// 2.6.7 Flow Control : link_credit_snd := delivery_count_rcv + link_credit_rcv - delivery_count_snd
SequenceNumber limit = new SequenceNumber(receiverDeliveryCount.intValue()).add(receiverLinkCredit.intValue());
if (limit.compareTo(getDeliveryCount()) <= 0) {
setLinkCredit(UnsignedInteger.valueOf(0));
} else {
setLinkCredit(limit.subtract(getDeliveryCount().intValue()).unsignedIntegerValue());
}
}
// send flow when echo=true or drain=true but link credit is zero
boolean sendFlow = Boolean.TRUE.equals(flow.getEcho()) || (Boolean.TRUE.equals(flow.getDrain()) && getLinkCredit().equals(UnsignedInteger.ZERO));
flowStateChanged();
if (sendFlow) {
sendFlow();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow in project qpid-broker-j by apache.
the class AbstractLinkEndpoint method sendFlow.
private void sendFlow(boolean echo) {
if (_state == State.ATTACHED || _state == State.ATTACH_SENT) {
Flow flow = new Flow();
flow.setDeliveryCount(_deliveryCount.unsignedIntegerValue());
flow.setEcho(echo);
if (_stopped) {
flow.setLinkCredit(UnsignedInteger.ZERO);
flow.setDrain(true);
_lastSentCreditLimit = _deliveryCount.unsignedIntegerValue();
} else {
flow.setLinkCredit(_linkCredit);
_lastSentCreditLimit = _linkCredit.add(_deliveryCount.unsignedIntegerValue());
flow.setDrain(_drain);
}
flow.setAvailable(_available);
flow.setHandle(getLocalHandle());
getSession().sendFlow(flow);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeReceivingLinkWithSingleUnsettledAccepted.
@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 resumeReceivingLinkWithSingleUnsettledAccepted() 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).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
Attach attach = interaction.getLatestResponse(Attach.class);
assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
List<Transfer> transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer transfer = transfers.get(0);
Binary deliveryTag = transfer.getDeliveryTag();
assertThat(deliveryTag, is(notNullValue()));
assertThat(transfer.getSettled(), is(not(equalTo(true))));
Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(data, is(equalTo(getTestName())));
Detach detach = interaction.detach().consumeResponse().getLatestResponse(Detach.class);
assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
interaction.attachUnsettled(Collections.singletonMap(deliveryTag, new Accepted())).attach().consumeResponse(Attach.class);
Attach resumeAttach = interaction.getLatestResponse(Attach.class);
Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
assertThat(unsettled, is(notNullValue()));
assertThat(unsettled.entrySet(), hasSize(1));
Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
assertThat(entry.getKey(), is(equalTo(deliveryTag)));
interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer resumeTransfer = transfers.get(0);
assertThat(resumeTransfer.getResume(), is(equalTo(true)));
assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
assertThat(resumeTransfer.getPayload(), is(nullValue()));
if (!Boolean.TRUE.equals(resumeTransfer.getSettled())) {
interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
}
interaction.doCloseConnection();
final String content = getTestName() + "_2";
Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, content);
assertThat(Utils.receiveMessage(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME), Matchers.is(Matchers.equalTo(content)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow in project qpid-broker-j by apache.
the class ResumeDeliveriesTest method resumeReceivingLinkOneUnsettledWithNoOutcome.
@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 resumeReceivingLinkOneUnsettledWithNoOutcome() 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).attachSndSettleMode(SenderSettleMode.UNSETTLED).attach().consumeResponse();
Attach attach = interaction.getLatestResponse(Attach.class);
assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.UNSETTLED)));
interaction.flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
List<Transfer> transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer transfer = transfers.get(0);
Binary deliveryTag = transfer.getDeliveryTag();
assertThat(deliveryTag, is(notNullValue()));
Object data = interaction.decodeLatestDelivery().getDecodedLatestDelivery();
assertThat(data, is(equalTo(getTestName())));
Detach detach = interaction.detach().consumeResponse(Detach.class).getLatestResponse(Detach.class);
assertThat(detach.getClosed(), anyOf(nullValue(), equalTo(false)));
interaction.attachUnsettled(Collections.singletonMap(deliveryTag, null)).attach().consumeResponse(Attach.class);
Attach resumeAttach = interaction.getLatestResponse(Attach.class);
Map<Binary, DeliveryState> unsettled = resumeAttach.getUnsettled();
assertThat(unsettled, is(notNullValue()));
assertThat(unsettled.entrySet(), hasSize(1));
Map.Entry<Binary, DeliveryState> entry = unsettled.entrySet().iterator().next();
assertThat(entry.getKey(), is(equalTo(deliveryTag)));
interaction.flowNextIncomingId(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery();
transfers = interaction.getLatestDelivery();
assertThat(transfers, hasSize(1));
Transfer resumeTransfer = transfers.get(0);
assertThat(resumeTransfer.getResume(), is(equalTo(true)));
assertThat(resumeTransfer.getDeliveryTag(), is(equalTo(deliveryTag)));
assertThat(resumeTransfer.getPayload(), is(notNullValue()));
interaction.dispositionSettled(true).dispositionState(new Accepted()).dispositionRole(Role.RECEIVER).disposition();
interaction.doCloseConnection();
final String content = getTestName() + "_2";
Utils.putMessageOnQueue(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME, content);
assertThat(Utils.receiveMessage(getBrokerAdmin(), BrokerAdmin.TEST_QUEUE_NAME), Matchers.is(Matchers.equalTo(content)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Flow in project qpid-broker-j by apache.
the class AttachTest method attachReceiverWithNullTarget.
@Test
@SpecificationTest(section = "2.6.3", description = "Note that if the application chooses not to create a terminus, the session endpoint will" + " still create a link endpoint and issue an attach indicating that the link endpoint has" + " no associated local terminus. In this case, the session endpoint MUST immediately" + " detach the newly created link endpoint.")
@BrokerSpecific(kind = BrokerAdmin.KIND_BROKER_J)
public void attachReceiverWithNullTarget() throws Exception {
String queueName = BrokerAdmin.TEST_QUEUE_NAME;
getBrokerAdmin().createQueue(queueName);
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
Interaction interaction = transport.newInteraction();
final Attach responseAttach = interaction.negotiateOpen().begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(queueName).attachTarget(null).attach().consumeResponse().getLatestResponse(Attach.class);
assertThat(responseAttach.getName(), is(notNullValue()));
assertThat(responseAttach.getHandle().longValue(), is(both(greaterThanOrEqualTo(0L)).and(lessThan(UnsignedInteger.MAX_VALUE.longValue()))));
assertThat(responseAttach.getRole(), is(Role.SENDER));
assertThat(responseAttach.getInitialDeliveryCount(), is((UnsignedInteger.ZERO)));
assertThat(responseAttach.getSource(), is(nullValue()));
assertThat(responseAttach.getTarget(), is(nullValue()));
final Detach responseDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
assertThat(responseDetach.getClosed(), is(true));
assertThat(responseDetach.getError(), is(notNullValue()));
assertThat(responseDetach.getError().getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
final End endResponse = interaction.flowHandleFromLinkHandle().flowEcho(true).flow().consumeResponse().getLatestResponse(End.class);
assertThat(endResponse.getError(), is(notNullValue()));
// QPID-7954
// assertThat(endResponse.getError().getCondition(), is(equalTo(SessionError.ERRANT_LINK)));
}
}
Aggregations