Search in sources :

Example 1 with ReplayProcessor

use of io.reactivex.rxjava3.processors.ReplayProcessor in project redisson by redisson.

the class RedissonTopicRx method getMessages.

public <M> Flowable<M> getMessages(Class<M> type) {
    ReplayProcessor<M> p = ReplayProcessor.create();
    return p.doOnRequest(new LongConsumer() {

        @Override
        public void accept(long n) throws Exception {
            AtomicLong counter = new AtomicLong(n);
            RFuture<Integer> t = topic.addListenerAsync(type, new MessageListener<M>() {

                @Override
                public void onMessage(CharSequence channel, M msg) {
                    p.onNext(msg);
                    if (counter.decrementAndGet() == 0) {
                        topic.removeListenerAsync(this);
                        p.onComplete();
                    }
                }
            });
            t.whenComplete((id, e) -> {
                if (e != null) {
                    p.onError(e);
                    return;
                }
                p.doOnCancel(new Action() {

                    @Override
                    public void run() throws Exception {
                        topic.removeListenerAsync(id);
                    }
                });
            });
        }
    });
}
Also used : RFuture(org.redisson.api.RFuture) AtomicLong(java.util.concurrent.atomic.AtomicLong) Flowable(io.reactivex.rxjava3.core.Flowable) RTopic(org.redisson.api.RTopic) MessageListener(org.redisson.api.listener.MessageListener) LongConsumer(io.reactivex.rxjava3.functions.LongConsumer) Action(io.reactivex.rxjava3.functions.Action) ReplayProcessor(io.reactivex.rxjava3.processors.ReplayProcessor) LongConsumer(io.reactivex.rxjava3.functions.LongConsumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Action(io.reactivex.rxjava3.functions.Action) MessageListener(org.redisson.api.listener.MessageListener) RFuture(org.redisson.api.RFuture)

Example 2 with ReplayProcessor

use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.

the class ReplayProcessorTest method peekStateTimeAndSizeValue.

@Test
public void peekStateTimeAndSizeValue() {
    ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.DAYS, Schedulers.computation(), 1);
    assertNull(rp.getValue());
    assertEquals(0, rp.getValues().length);
    assertNull(rp.getValues(new Integer[2])[0]);
    rp.onComplete();
    assertNull(rp.getValue());
    assertEquals(0, rp.getValues().length);
    assertNull(rp.getValues(new Integer[2])[0]);
    rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.DAYS, Schedulers.computation(), 1);
    rp.onError(new TestException());
    assertNull(rp.getValue());
    assertEquals(0, rp.getValues().length);
    assertNull(rp.getValues(new Integer[2])[0]);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 3 with ReplayProcessor

use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.

the class ReplayProcessorTest method subscriptionLeak.

@Test
public void subscriptionLeak() {
    ReplayProcessor<Object> replaySubject = ReplayProcessor.create();
    Disposable connection = replaySubject.subscribe();
    assertEquals(1, replaySubject.subscriberCount());
    connection.dispose();
    assertEquals(0, replaySubject.subscriberCount());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Example 4 with ReplayProcessor

use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.

the class ReplayProcessorTest method sizeAndHasAnyValueUnboundedEmptyError.

@Test
public void sizeAndHasAnyValueUnboundedEmptyError() {
    ReplayProcessor<Object> rs = ReplayProcessor.create();
    rs.onError(new TestException());
    assertEquals(0, rs.size());
    assertFalse(rs.hasValue());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 5 with ReplayProcessor

use of io.reactivex.rxjava3.processors.ReplayProcessor in project RxJava by ReactiveX.

the class ReplayProcessorTest method unboundedZeroRequestError.

@Test
public void unboundedZeroRequestError() {
    final ReplayProcessor<Integer> source = ReplayProcessor.create();
    source.onError(new TestException());
    source.test(0).assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)16 Flowable (io.reactivex.rxjava3.core.Flowable)3 LongConsumer (io.reactivex.rxjava3.functions.LongConsumer)3 ReplayProcessor (io.reactivex.rxjava3.processors.ReplayProcessor)3 Action (io.reactivex.rxjava3.functions.Action)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.Test)2 Publisher (org.reactivestreams.Publisher)2 RFuture (org.redisson.api.RFuture)2 Single (io.reactivex.rxjava3.core.Single)1 Disposable (io.reactivex.rxjava3.disposables.Disposable)1 Consumer (io.reactivex.rxjava3.functions.Consumer)1 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RedissonKeys (org.redisson.RedissonKeys)1 RTopic (org.redisson.api.RTopic)1 MessageListener (org.redisson.api.listener.MessageListener)1 RedisClient (org.redisson.client.RedisClient)1