Java Code Examples for org.apache.qpid.proton.engine.Sender#drained()
The following examples show how to use
org.apache.qpid.proton.engine.Sender#drained() .
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 | 5 votes |
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 2
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
/** * Verify that no Flow frame is emitted by the Transport should a Sender * have credit drained added after the Close frame was sent. */ @Test public void testSenderFlowAfterCloseSent() { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); transport.bind(connection); connection.open(); Collector collector = Collector.Factory.create(); connection.collect(collector); Session session = connection.session(); session.open(); String linkName = "mySender"; Sender sender = session.sender(linkName); sender.open(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size()); assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open); assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin); assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach); assertFalse("Should not be in drain yet", sender.getDrain()); // Send the necessary responses to open/begin/attach then give sender credit and drain transport.handleFrame(new TransportFrame(0, new Open(), null)); Begin begin = new Begin(); begin.setRemoteChannel(UnsignedShort.valueOf((short) 0)); transport.handleFrame(new TransportFrame(0, begin, null)); Attach attach = new Attach(); attach.setHandle(UnsignedInteger.ZERO); attach.setRole(Role.RECEIVER); attach.setName(linkName); attach.setInitialDeliveryCount(UnsignedInteger.ZERO); transport.handleFrame(new TransportFrame(0, attach, null)); int credit = 10; Flow flow = new Flow(); flow.setHandle(UnsignedInteger.ZERO); flow.setDeliveryCount(UnsignedInteger.ZERO); flow.setNextIncomingId(UnsignedInteger.ONE); flow.setNextOutgoingId(UnsignedInteger.ZERO); flow.setIncomingWindow(UnsignedInteger.valueOf(1024)); flow.setOutgoingWindow(UnsignedInteger.valueOf(1024)); flow.setDrain(true); flow.setLinkCredit(UnsignedInteger.valueOf(credit)); transport.handleFrame(new TransportFrame(0, flow, null)); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size()); assertTrue("Should not be in drain", sender.getDrain()); assertEquals("Should have credit", credit, sender.getCredit()); // Cause the Close frame to be sent connection.close(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size()); assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Close); // Drain the credit and verify the transport doesn't // send any Flow frame, as a Close frame was sent already. int drained = sender.drained(); assertEquals("Should have drained all credit", credit, drained); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size()); }