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

The following examples show how to use org.apache.qpid.proton.engine.Sender#getCredit() . 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: 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 4
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();
    }
}