Search in sources :

Example 1 with Receiver

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;
}
Also used : Target(org.apache.qpid.proton.amqp.messaging.Target) Symbol(org.apache.qpid.proton.amqp.Symbol) ProtonReceiver(io.vertx.proton.ProtonReceiver) Receiver(org.apache.qpid.proton.engine.Receiver) Source(org.apache.qpid.proton.amqp.messaging.Source)

Example 2 with Receiver

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));
}
Also used : Connection(org.apache.qpid.proton.engine.Connection) ProtonReceiver(io.vertx.proton.ProtonReceiver) Receiver(org.apache.qpid.proton.engine.Receiver) Record(org.apache.qpid.proton.engine.Record) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Example 3 with Receiver

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
    }
}
Also used : Connection(org.apache.qpid.proton.engine.Connection) ProtonReceiver(io.vertx.proton.ProtonReceiver) Receiver(org.apache.qpid.proton.engine.Receiver) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Example 4 with Receiver

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
    }
}
Also used : Connection(org.apache.qpid.proton.engine.Connection) ProtonReceiver(io.vertx.proton.ProtonReceiver) Receiver(org.apache.qpid.proton.engine.Receiver) Session(org.apache.qpid.proton.engine.Session) Test(org.junit.Test)

Example 5 with Receiver

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();
        }
    }
}
Also used : Message(org.apache.qpid.proton.message.Message) ProtonReceiver(io.vertx.proton.ProtonReceiver) Receiver(org.apache.qpid.proton.engine.Receiver) Delivery(org.apache.qpid.proton.engine.Delivery)

Aggregations

ProtonReceiver (io.vertx.proton.ProtonReceiver)5 Receiver (org.apache.qpid.proton.engine.Receiver)5 Connection (org.apache.qpid.proton.engine.Connection)3 Session (org.apache.qpid.proton.engine.Session)3 Test (org.junit.Test)3 Symbol (org.apache.qpid.proton.amqp.Symbol)1 Source (org.apache.qpid.proton.amqp.messaging.Source)1 Target (org.apache.qpid.proton.amqp.messaging.Target)1 Delivery (org.apache.qpid.proton.engine.Delivery)1 Record (org.apache.qpid.proton.engine.Record)1 Message (org.apache.qpid.proton.message.Message)1