Java Code Examples for org.apache.qpid.proton.engine.Sender#delivery()

The following examples show how to use org.apache.qpid.proton.engine.Sender#delivery() . 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: Spout.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public void onLinkFlow(Event evt) {
    Link link = evt.getLink();
    if (link instanceof Sender) {
        Sender sender = (Sender) link;
        while ((sent < count) && sender.getCredit() > 0) {
            Delivery dlv = sender.delivery(String.format("spout-%s", sent).getBytes());

            Message msg = new Message(String.format("Hello World! [%s]", sent));
            byte[] bytes = msg.getBytes();
            sender.send(bytes, 0, bytes.length);
            sender.advance();

            if (!quiet) {
                System.out.println(String.format("Sent %s to %s: %s", new String(dlv.getTag()),
                                                 sender.getTarget().getAddress(), msg));
            }
            sent++;
        }
    }
}
 
Example 2
Source File: Send.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public void onLinkFlow(Event event) {
    Sender snd = (Sender)event.getLink();
    if (snd.getCredit() > 0) {
        byte[] msgData = new byte[1024];
        int length;
        while(true) {
            try {
                length = message.encode(msgData, 0, msgData.length);
                break;
            } catch(BufferOverflowException e) {
                msgData = new byte[msgData.length * 2];
            }
        }
        byte[] tag = String.valueOf(nextTag++).getBytes();
        Delivery dlv = snd.delivery(tag);
        snd.send(msgData, 0, length);
        dlv.settle();
        snd.advance();
        snd.close();
        snd.getSession().close();
        snd.getSession().getConnection().close();
    }
}
 
Example 3
Source File: DeferredSettlementTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private Delivery sendMessageToClient(String deliveryTag, int messageBody)
{
    byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8);

    Message m = Proton.message();
    m.setBody(new AmqpValue(messageBody));

    byte[] encoded = new byte[BUFFER_SIZE];
    int len = m.encode(encoded, 0, BUFFER_SIZE);

    assertTrue("given array was too small", len < BUFFER_SIZE);

    Sender serverSender = getServer().getSender();
    Delivery serverDelivery = serverSender.delivery(tag);
    int sent = serverSender.send(encoded, 0, len);

    assertEquals("sender unable to send all data at once as assumed for simplicity", len, sent);

    boolean senderAdvanced = serverSender.advance();
    assertTrue("sender has not advanced", senderAdvanced);

    return serverDelivery;
}
 
Example 4
Source File: EventImplTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTransportWithDeliveryContext()
{
    Transport transport = Transport.Factory.create();
    Connection connection = Connection.Factory.create();
    transport.bind(connection);

    Session session = connection.session();
    Sender sender = session.sender("mySender");

    Delivery delivery = sender.delivery("tag".getBytes());

    EventImpl event = createEvent(delivery, Event.Type.DELIVERY);

    assertNotNull("No transport returned", event.getTransport());
    assertSame("Incorrect transport returned", transport, event.getTransport());
}
 
Example 5
Source File: Server.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private int send(String address, Sender snd) {
    if (snd == null) {
        Router.Routes<Sender> routes = router.getOutgoing(address);
        snd = routes.choose();
        if (snd == null) {
            return 0;
        }
    }

    int count = 0;
    while (snd.getCredit() > 0 && snd.getQueued() < 1024) {
        Message msg = messages.get(address);
        if (msg == null) {
            snd.drained();
            return count;
        }
        Delivery dlv = snd.delivery(nextTag());
        byte[] bytes = msg.getBytes();
        snd.send(bytes, 0, bytes.length);
        dlv.settle();
        count++;
        if (!quiet) {
            System.out.println(String.format("Sent message(%s): %s", address, msg));
        }
    }

    return count;
}
 
Example 6
Source File: ReactorTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void onLinkFlow(Event event) {
    Sender link = (Sender)event.getLink();
    while (link.getCredit() > 0 && remaining > 0) {
        Delivery dlv = link.delivery(new byte[0]);
        assertNotNull(dlv);
        dlv.settle();
        link.advance();
        --remaining;
    }

    if (remaining == 0) {
        event.getConnection().close();
    }
}
 
Example 7
Source File: TransportImplTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private Delivery sendMessage(Sender sender, String deliveryTag, String messageContent)
{
    byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8);

    Message m = Message.Factory.create();
    m.setBody(new AmqpValue(messageContent));

    byte[] encoded = new byte[BUFFER_SIZE];
    int len = m.encode(encoded, 0, BUFFER_SIZE);

    assertTrue("given array was too small", len < BUFFER_SIZE);

    Delivery delivery = sender.delivery(tag);

    int sent = sender.send(encoded, 0, len);

    assertEquals("sender unable to send all data at once as assumed for simplicity", len, sent);

    boolean senderAdvanced = sender.advance();
    assertTrue("sender has not advanced", senderAdvanced);

    return delivery;
}