use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received in project qpid-broker-j by apache.
the class Session_1_0 method receiveTransfer.
public void receiveTransfer(final Transfer transfer) {
_nextIncomingId.incr();
_remoteOutgoingWindow = _remoteOutgoingWindow.subtract(UnsignedInteger.ONE);
UnsignedInteger inputHandle = transfer.getHandle();
LinkEndpoint<? extends BaseSource, ? extends BaseTarget> linkEndpoint = _inputHandleToEndpoint.get(inputHandle);
if (linkEndpoint == null) {
Error error = new Error();
error.setCondition(SessionError.UNATTACHED_HANDLE);
error.setDescription("TRANSFER called on Session for link handle " + inputHandle + " which is not attached.");
_connection.close(error);
} else if (!(linkEndpoint instanceof AbstractReceivingLinkEndpoint)) {
Error error = new Error();
error.setCondition(AmqpError.PRECONDITION_FAILED);
error.setDescription("Received TRANSFER for link handle " + inputHandle + " which is a sending link not a receiving link.");
_connection.close(error);
} else {
AbstractReceivingLinkEndpoint endpoint = ((AbstractReceivingLinkEndpoint) linkEndpoint);
endpoint.receiveTransfer(transfer);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received 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.type.messaging.Received in project qpid-broker-j by apache.
the class OutcomeTest method modifiedOutcomeWithUndeliverableHere.
@Test
@SpecificationTest(section = "3.4.5", description = "If the undeliverable-here is set, then any messages released" + " MUST NOT be redelivered to the modifying link endpoint.")
public void modifiedOutcomeWithUndeliverableHere() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, "message1");
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, "message2");
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).flowIncomingWindow(UnsignedInteger.ONE).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery();
Object firstDeliveryPayload = interaction.getDecodedLatestDelivery();
assertThat(firstDeliveryPayload, is(equalTo("message1")));
Modified modifiedOutcome = new Modified();
modifiedOutcome.setUndeliverableHere(Boolean.TRUE);
interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionFirstFromLatestDelivery().dispositionState(modifiedOutcome).disposition().flowIncomingWindow(UnsignedInteger.valueOf(2)).flowLinkCredit(UnsignedInteger.valueOf(2)).flowNextIncomingIdFromLatestDelivery().flow().receiveDelivery().decodeLatestDelivery();
Object secondDeliveryPayload = interaction.getDecodedLatestDelivery();
assertThat(secondDeliveryPayload, is(equalTo("message2")));
// verify that no unexpected performative is received by closing
interaction.doCloseConnection();
}
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received in project qpid-broker-j by apache.
the class TransferTest method receiveTransferReceiverIndicatesNonTerminalDeliveryState.
@Test
@SpecificationTest(section = "2.6.12", description = "[...] the receiving application MAY wish to indicate" + " non-terminal delivery states to the sender")
public void receiveTransferReceiverIndicatesNonTerminalDeliveryState() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction();
Open open = interaction.negotiateProtocol().consumeResponse().openMaxFrameSize(UnsignedInteger.valueOf(4096)).open().consumeResponse().getLatestResponse(Open.class);
int negotiatedFrameSize = open.getMaxFrameSize().intValue();
String testMessageData = Stream.generate(() -> "*").limit(negotiatedFrameSize).collect(Collectors.joining());
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, testMessageData);
interaction.begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow().sync();
MessageDecoder messageDecoder = new MessageDecoder();
Transfer first = interaction.consumeResponse(Transfer.class).getLatestResponse(Transfer.class);
assertThat(first.getMore(), is(equalTo(true)));
messageDecoder.addTransfer(first);
final long firstRemaining;
try (QpidByteBuffer payload = first.getPayload()) {
firstRemaining = payload.remaining();
}
Received state = new Received();
state.setSectionNumber(UnsignedInteger.ZERO);
state.setSectionOffset(UnsignedLong.valueOf(firstRemaining + 1));
interaction.dispositionSettled(false).dispositionRole(Role.RECEIVER).dispositionState(state).disposition().sync();
Transfer second = interaction.consumeResponse(Transfer.class).getLatestResponse(Transfer.class);
assertThat(second.getMore(), isOneOf(false, null));
messageDecoder.addTransfer(second);
assertThat(messageDecoder.getData(), is(equalTo(testMessageData)));
Disposition disposition = interaction.dispositionSettled(false).dispositionRole(Role.RECEIVER).dispositionState(new Accepted()).disposition().consumeResponse(Disposition.class).getLatestResponse(Disposition.class);
assertThat(disposition.getSettled(), is(true));
interaction.consumeResponse(null, Flow.class);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Received in project qpid-broker-j by apache.
the class TransferTest method receiveTransferSenderSettleModeSettled.
@Test
@SpecificationTest(section = "2.7.3", description = "The sender SHOULD respect the receiver’s desired settlement mode if" + " the receiver initiates the attach exchange and the sender supports the desired mode.")
public void receiveTransferSenderSettleModeSettled() throws Exception {
getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_DATA);
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final Interaction interaction = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse().begin().consumeResponse().attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSndSettleMode(SenderSettleMode.SETTLED).attach().consumeResponse(Attach.class);
Attach attach = interaction.getLatestResponse(Attach.class);
assumeThat(attach.getSndSettleMode(), is(equalTo(SenderSettleMode.SETTLED)));
interaction.flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
List<Transfer> transfers = interaction.receiveDelivery().getLatestDelivery();
final AtomicBoolean isSettled = new AtomicBoolean();
transfers.forEach(transfer -> {
if (Boolean.TRUE.equals(transfer.getSettled())) {
isSettled.set(true);
}
});
assertThat(isSettled.get(), is(true));
// verify no unexpected performative received by closing the connection
interaction.doCloseConnection();
}
}
Aggregations