All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.resilience4j.adapter.RxJava2Adapter Maven / Gradle / Ivy

Go to download

Resilience4j is a lightweight, easy-to-use fault tolerance library designed for Java8 and functional programming

There is a newer version: 2.2.0
Show newest version
package io.github.resilience4j.adapter;

import io.github.resilience4j.core.EventPublisher;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.processors.FlowableProcessor;
import io.reactivex.processors.PublishProcessor;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subjects.Subject;

public class RxJava2Adapter {

    /**
     * Converts the EventPublisher into a Flowable.
     *
     * @param eventPublisher the event publisher
     * @param  the type of the event
     * @return the Flowable
     */
    public static  Flowable toFlowable(EventPublisher eventPublisher) {
        PublishProcessor publishProcessor = PublishProcessor.create();
        FlowableProcessor flowableProcessor = publishProcessor.toSerialized();
        eventPublisher.onEvent(flowableProcessor::onNext);
        return flowableProcessor;
    }

    /**
     * Converts the EventPublisher into an Observable.
     *
     * @param eventPublisher the event publisher
     * @param  the type of the event
     * @return the Observable
     */
    public static  Observable toObservable(EventPublisher eventPublisher) {
        PublishSubject publishSubject = PublishSubject.create();
        Subject serializedSubject = publishSubject.toSerialized();
        eventPublisher.onEvent(serializedSubject::onNext);
        return serializedSubject;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy