Search in sources :

Example 16 with Received

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);
    }
}
Also used : Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) SessionError(org.apache.qpid.server.protocol.v1_0.type.transport.SessionError) LinkError(org.apache.qpid.server.protocol.v1_0.type.transport.LinkError) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 17 with Received

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();
            }
        }
    }
}
Also used : BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) SessionError(org.apache.qpid.server.protocol.v1_0.type.transport.SessionError) LinkError(org.apache.qpid.server.protocol.v1_0.type.transport.LinkError) End(org.apache.qpid.server.protocol.v1_0.type.transport.End) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget)

Example 18 with Received

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();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Modified(org.apache.qpid.server.protocol.v1_0.type.messaging.Modified) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 19 with Received

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);
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) MessageDecoder(org.apache.qpid.tests.protocol.v1_0.MessageDecoder) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Received(org.apache.qpid.server.protocol.v1_0.type.messaging.Received) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 20 with Received

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();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)9 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)9 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)7 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)6 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)6 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)6 Test (org.junit.Test)6 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)5 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)5 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)5 ConnectionEstablishmentPolicy (org.apache.qpid.server.virtualhost.ConnectionEstablishmentPolicy)5 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 ConnectionError (org.apache.qpid.server.protocol.v1_0.type.transport.ConnectionError)4 InetSocketAddress (java.net.InetSocketAddress)3 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)3 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)3 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)3 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)3 LinkError (org.apache.qpid.server.protocol.v1_0.type.transport.LinkError)3