Java Code Examples for org.apache.qpid.proton.engine.Delivery#pending()

The following examples show how to use org.apache.qpid.proton.engine.Delivery#pending() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Server.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public void onDelivery(Event evt) {
    Delivery dlv = evt.getDelivery();
    Link link = dlv.getLink();
    if (link instanceof Sender) {
        dlv.settle();
    } else {
        Receiver rcv = (Receiver) link;
        if (!dlv.isPartial()) {
            byte[] bytes = new byte[dlv.pending()];
            rcv.recv(bytes, 0, bytes.length);
            String address = router.getAddress(rcv);
            Message message = new Message(bytes);
            messages.put(address, message);
            dlv.disposition(Accepted.getInstance());
            dlv.settle();
            if (!quiet) {
                System.out.println(String.format("Got message(%s): %s", address, message));
            }
            send(address);
        }
    }
}
 
Example 2
Source File: Drain.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public void onDelivery(Event evt) {
    Delivery dlv = evt.getDelivery();
    if (dlv.getLink() instanceof Receiver) {
        Receiver receiver = (Receiver) dlv.getLink();

        if (!dlv.isPartial()) {
            byte[] bytes = new byte[dlv.pending()];
            receiver.recv(bytes, 0, bytes.length);
            Message msg = new Message(bytes);

            if (!quiet) {
                System.out.println(String.format("Got message: %s", msg));
            }
            received++;
            dlv.settle();
        }

        if ((received >= count) || (!block && !receiver.draining())) {
            receiver.getSession().getConnection().close();
        }
    }
}
 
Example 3
Source File: Recv.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onDelivery(Event event) {
    Receiver recv = (Receiver)event.getLink();
    Delivery delivery = recv.current();
    if (delivery.isReadable() && !delivery.isPartial()) {
        int size = delivery.pending();
        byte[] buffer = new byte[size];
        int read = recv.recv(buffer, 0, buffer.length);
        recv.advance();

        Message msg = Proton.message();
        msg.decode(buffer, 0, read);
        System.out.println(((AmqpValue)msg.getBody()).getValue());
    }
}
 
Example 4
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private Delivery verifyDeliveryRawPayload(Receiver receiver, String deliveryTag, byte[] payload)
{
    Delivery delivery = receiver.current();

    assertTrue(Arrays.equals(deliveryTag.getBytes(StandardCharsets.UTF_8), delivery.getTag()));

    assertFalse(delivery.isPartial());
    assertTrue(delivery.isReadable());

    byte[] received = new byte[delivery.pending()];
    int len = receiver.recv(received, 0, BUFFER_SIZE);

    assertEquals("unexpected length", len, received.length);

    assertArrayEquals("Received delivery payload not as expected", payload, received);

    boolean receiverAdvanced = receiver.advance();
    assertTrue("receiver has not advanced", receiverAdvanced);

    return delivery;
}