本文整理汇总了Java中org.apache.qpid.proton.engine.Receiver.current方法的典型用法代码示例。如果您正苦于以下问题:Java Receiver.current方法的具体用法?Java Receiver.current怎么用?Java Receiver.current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.qpid.proton.engine.Receiver
的用法示例。
在下文中一共展示了Receiver.current方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDelivery
import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
@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());
}
}
示例2: testDispositionAfterCloseSent
import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
/**
* Verify that no Disposition frame is emitted by the Transport should a Delivery
* have disposition applied after the Close frame was sent.
*/
@Test
public void testDispositionAfterCloseSent()
{
MockTransportImpl transport = new MockTransportImpl();
Connection connection = Proton.connection();
transport.bind(connection);
connection.open();
Session session = connection.session();
session.open();
String linkName = "myReceiver";
Receiver receiver = session.receiver(linkName);
receiver.flow(5);
receiver.open();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, 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);
assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Flow);
Delivery delivery = receiver.current();
assertNull("Should not yet have a delivery", delivery);
// Send the necessary responses to open/begin/attach as well as a transfer
transport.handleFrame(new TransportFrame(0, new Open(), null));
Begin begin = new Begin();
begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
begin.setNextOutgoingId(UnsignedInteger.ONE);
begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
transport.handleFrame(new TransportFrame(0, begin, null));
Attach attach = new Attach();
attach.setHandle(UnsignedInteger.ZERO);
attach.setRole(Role.SENDER);
attach.setName(linkName);
attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
transport.handleFrame(new TransportFrame(0, attach, null));
String deliveryTag = "tag1";
String messageContent = "content1";
handleTransfer(transport, 1, deliveryTag, messageContent);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
delivery = verifyDelivery(receiver, deliveryTag, messageContent);
assertNotNull("Should now have a delivery", delivery);
// Cause the Close frame to be sent
connection.close();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(4) instanceof Close);
delivery.disposition(Released.getInstance());
delivery.settle();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
}
示例3: onDelivery
import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
void onDelivery() {
if (this.handler == null) {
return;
}
Receiver receiver = getReceiver();
Delivery delivery = receiver.current();
if (delivery != null) {
int count;
while ((count = receiver.recv(buffer, 0, buffer.length)) > 0) {
current.write(buffer, 0, count);
}
if (delivery.isPartial()) {
// Delivery is not yet completely received,
// return and allow further frames to arrive.
return;
}
byte[] data = current.toByteArray();
current.reset();
Message msg = Proton.message();
msg.decode(data, 0, data.length);
receiver.advance();
ProtonDeliveryImpl delImpl = new ProtonDeliveryImpl(delivery);
handler.handle(delImpl, msg);
if (autoAccept && delivery.getLocalState() == null) {
accepted(delImpl, true);
}
if (prefetch > 0) {
// Replenish credit if prefetch is configured.
// TODO: batch credit replenish, optionally flush if exceeding a given threshold?
flow(1, false);
} else {
processForDrainCompletion();
}
}
}
示例4: verifyDelivery
import org.apache.qpid.proton.engine.Receiver; //导入方法依赖的package包/类
private Delivery verifyDelivery(Receiver receiver, String deliveryTag, String messageContent)
{
Delivery delivery = receiver.current();
assertTrue(Arrays.equals(deliveryTag.getBytes(StandardCharsets.UTF_8), delivery.getTag()));
assertNull(delivery.getLocalState());
assertNull(delivery.getRemoteState());
assertFalse(delivery.isPartial());
assertTrue(delivery.isReadable());
byte[] received = new byte[BUFFER_SIZE];
int len = receiver.recv(received, 0, BUFFER_SIZE);
assertTrue("given array was too small", len < BUFFER_SIZE);
Message m = Proton.message();
m.decode(received, 0, len);
Object messageBody = ((AmqpValue)m.getBody()).getValue();
assertEquals("Unexpected message content", messageContent, messageBody);
boolean receiverAdvanced = receiver.advance();
assertTrue("receiver has not advanced", receiverAdvanced);
return delivery;
}