Search in sources :

Example 1 with ProtonSubscriberWrapperImpl

use of io.vertx.proton.streams.impl.ProtonSubscriberWrapperImpl in project vertx-proton by vert-x3.

the class MessageSubscriberBlackboxVerificationTckTest method createSubscriber.

@Override
public Subscriber<Message> createSubscriber() {
    int actualPort = server.actualPort();
    ProtonClient client = ProtonClient.create(vertx);
    AtomicReference<Subscriber<Message>> ref = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    client.connect("localhost", actualPort, result -> {
        if (result.succeeded()) {
            ProtonConnection conn = result.result();
            conn.open();
            ProtonSubscriber<Message> stream = ProtonStreams.createProducer(conn, "myAddress");
            ((ProtonSubscriberWrapperImpl) stream).setEmitOnConnectionEnd(false);
            ref.set(stream);
        } else {
            LOG.error("Connection failed");
        }
        latch.countDown();
    });
    try {
        LOG.trace("Awaiting connection");
        boolean res = latch.await(2, TimeUnit.SECONDS);
        LOG.trace("Client connected: " + res);
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while creating subscriber", e);
    }
    return ref.get();
}
Also used : Message(org.apache.qpid.proton.message.Message) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProtonClient(io.vertx.proton.ProtonClient) CountDownLatch(java.util.concurrent.CountDownLatch) ProtonConnection(io.vertx.proton.ProtonConnection) Subscriber(org.reactivestreams.Subscriber) ProtonSubscriber(io.vertx.proton.streams.ProtonSubscriber) ProtonSubscriberWrapperImpl(io.vertx.proton.streams.impl.ProtonSubscriberWrapperImpl)

Example 2 with ProtonSubscriberWrapperImpl

use of io.vertx.proton.streams.impl.ProtonSubscriberWrapperImpl in project vertx-proton by vert-x3.

the class MessageSubscriberWhiteboxVerificationTckTest method createSubscriber.

@Override
public Subscriber<Message> createSubscriber(WhiteboxSubscriberProbe<Message> probe) {
    int actualPort = server.actualPort();
    ProtonClient client = ProtonClient.create(vertx);
    AtomicReference<Subscriber<Message>> ref = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    client.connect("localhost", actualPort, result -> {
        if (result.succeeded()) {
            ProtonConnection conn = result.result();
            conn.open();
            // Modified stream impl, overriding methods to add test probe instrumentation
            ProtonSubscriberImpl subscriber = new ProtonSubscriberImpl("myAddress", (ProtonConnectionImpl) conn);
            ProtonSubscriber<Message> stream = new ProtonSubscriberWrapperImpl(subscriber) {

                @Override
                public void onSubscribe(final Subscription s) {
                    super.onSubscribe(s);
                    probe.registerOnSubscribe(new SubscriberPuppet() {

                        @Override
                        public void triggerRequest(long n) {
                            s.request(n);
                        }

                        @Override
                        public void signalCancel() {
                            s.cancel();
                        }
                    });
                }

                @Override
                public void onNext(Message value) {
                    probe.registerOnNext(value);
                    super.onNext(value);
                }

                @Override
                public void onError(Throwable t) {
                    probe.registerOnError(t);
                    super.onError(t);
                }

                @Override
                public void onComplete() {
                    probe.registerOnComplete();
                    super.onComplete();
                }
            };
            ref.set(stream);
        } else {
            LOG.error("Connection failed");
        }
        latch.countDown();
    });
    try {
        LOG.trace("Awaiting connection");
        boolean res = latch.await(2, TimeUnit.SECONDS);
        LOG.trace("Client connected: " + res);
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while creating subscriber", e);
    }
    return ref.get();
}
Also used : Message(org.apache.qpid.proton.message.Message) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProtonClient(io.vertx.proton.ProtonClient) CountDownLatch(java.util.concurrent.CountDownLatch) ProtonConnection(io.vertx.proton.ProtonConnection) Subscriber(org.reactivestreams.Subscriber) ProtonSubscriber(io.vertx.proton.streams.ProtonSubscriber) ProtonSubscriberImpl(io.vertx.proton.streams.impl.ProtonSubscriberImpl) ProtonSubscriberWrapperImpl(io.vertx.proton.streams.impl.ProtonSubscriberWrapperImpl) Subscription(org.reactivestreams.Subscription)

Aggregations

ProtonClient (io.vertx.proton.ProtonClient)2 ProtonConnection (io.vertx.proton.ProtonConnection)2 ProtonSubscriber (io.vertx.proton.streams.ProtonSubscriber)2 ProtonSubscriberWrapperImpl (io.vertx.proton.streams.impl.ProtonSubscriberWrapperImpl)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Message (org.apache.qpid.proton.message.Message)2 Subscriber (org.reactivestreams.Subscriber)2 ProtonSubscriberImpl (io.vertx.proton.streams.impl.ProtonSubscriberImpl)1 Subscription (org.reactivestreams.Subscription)1