use of org.apache.qpid.proton.engine.Receiver in project vertx-proton by vert-x3.
the class ProtonSessionImpl method createReceiver.
@Override
public ProtonReceiver createReceiver(String address, ProtonLinkOptions receiverOptions) {
Receiver receiver = session.receiver(getOrCreateLinkName(receiverOptions));
Symbol[] outcomes = new Symbol[] { Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };
Source source = new Source();
source.setAddress(address);
source.setOutcomes(outcomes);
source.setDefaultOutcome(Released.getInstance());
Target target = new Target();
receiver.setSource(source);
receiver.setTarget(target);
ProtonReceiverImpl r = new ProtonReceiverImpl(receiver);
r.openHandler((result) -> {
LOG.trace("Receiver open completed");
});
r.closeHandler((result) -> {
if (result.succeeded()) {
LOG.trace("Receiver closed");
} else {
LOG.warn("Receiver closed with error", result.cause());
}
});
// Default to at-least-once
r.setQoS(ProtonQoS.AT_LEAST_ONCE);
return r;
}
use of org.apache.qpid.proton.engine.Receiver in project vertx-proton by vert-x3.
the class ProtonReceiverImplTest method testAttachments.
@Test
public void testAttachments() {
Connection conn = Connection.Factory.create();
Session sess = conn.session();
Receiver r = sess.receiver("name");
ProtonReceiverImpl receiver = new ProtonReceiverImpl(r);
Record attachments = receiver.attachments();
assertNotNull("Expected attachments but got null", attachments);
assertSame("Got different attachments on subsequent call", attachments, receiver.attachments());
String key = "My-Connection-Key";
assertNull("Expected attachment to be null", attachments.get(key, Connection.class));
attachments.set(key, Connection.class, conn);
assertNotNull("Expected attachment to be returned", attachments.get(key, Connection.class));
assertSame("Expected attachment to be given object", conn, attachments.get(key, Connection.class));
}
use of org.apache.qpid.proton.engine.Receiver in project vertx-proton by vert-x3.
the class ProtonReceiverImplTest method testDrainWithoutHandlerThrowsIAE.
@Test
public void testDrainWithoutHandlerThrowsIAE() {
Connection conn = Connection.Factory.create();
Session sess = conn.session();
Receiver r = sess.receiver("name");
ProtonReceiverImpl receiver = new ProtonReceiverImpl(r);
receiver.setPrefetch(0);
try {
receiver.drain(0, null);
fail("should have thrown due to lack of handler");
} catch (IllegalArgumentException iae) {
// Expected
}
}
use of org.apache.qpid.proton.engine.Receiver in project vertx-proton by vert-x3.
the class ProtonReceiverImplTest method testDrainWithoutDisablingPrefetchThrowsISE.
@Test
public void testDrainWithoutDisablingPrefetchThrowsISE() {
Connection conn = Connection.Factory.create();
Session sess = conn.session();
Receiver r = sess.receiver("name");
ProtonReceiverImpl receiver = new ProtonReceiverImpl(r);
try {
receiver.drain(0, h -> {
});
fail("should have thrown due to prefetch still being enabled");
} catch (IllegalStateException ise) {
// Expected
}
}
use of org.apache.qpid.proton.engine.Receiver in project vertx-proton by vert-x3.
the class ProtonReceiverImpl method onDelivery.
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()) {
// 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();
}
}
}
Aggregations