Java Code Examples for io.reactivex.observables.ConnectableObservable#toFlowable()

The following examples show how to use io.reactivex.observables.ConnectableObservable#toFlowable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Subscription.java    From dive-into-graphql-in-java with GNU General Public License v3.0 6 votes vote down vote up
public Publisher<Score> talkScores(final String title) {
    Observable<Score> observable = Observable.create(e -> {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        executorService.scheduleAtFixedRate(() -> {
            Score s = Score.builder()
                           .title(title)
                           .score(Integer.valueOf((int) Math.floor(Math.random()*10)))
                           .build();
            e.onNext(s);
        }, 0, 2, TimeUnit.SECONDS);
    });

    ConnectableObservable connectableObservable = observable.share().publish();
    connectableObservable.connect();
    return connectableObservable.toFlowable(BackpressureStrategy.BUFFER);
}
 
Example 2
Source File: Subscription.java    From dive-into-graphql-in-java with GNU General Public License v3.0 6 votes vote down vote up
public Publisher<Score> talkScores(final String title) {
    Observable<Score> observable = Observable.create(e -> {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        executorService.scheduleAtFixedRate(() -> {
            Score s = Score.builder()
                           .title(title)
                           .score(Integer.valueOf((int) Math.floor(Math.random()*10)))
                           .build();
            e.onNext(s);
        }, 0, 2, TimeUnit.SECONDS);
    });

    ConnectableObservable connectableObservable = observable.share().publish();
    connectableObservable.connect();
    return connectableObservable.toFlowable(BackpressureStrategy.BUFFER);
}
 
Example 3
Source File: NewAssociationPublisher.java    From poc-graphql with MIT License 5 votes vote down vote up
/**
 * Constructor - Init the publishing of the events
 */
public NewAssociationPublisher(BusinessDataRepository bDataRepository) {
    this.businessDataRepository = bDataRepository;
    Observable<String> stockPriceUpdateObservable = Observable.create(emitter -> {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        executorService.scheduleAtFixedRate(verifyPresenceOfNewAssociation(emitter), 0, 20, TimeUnit.SECONDS);
    });
    ConnectableObservable<String> connectableObservable = stockPriceUpdateObservable.share().publish();
    connectableObservable.connect();
    publisher = connectableObservable.toFlowable(BackpressureStrategy.BUFFER);
}
 
Example 4
Source File: CommentPublisher.java    From graphql-java-demo with MIT License 5 votes vote down vote up
public CommentPublisher() {
    Observable<Comment> commentUpdateObservable = Observable.create(emitter -> {
        this.emitter = emitter;
    });

    ConnectableObservable<Comment> connectableObservable = commentUpdateObservable.share().publish();
    connectableObservable.connect();


    publisher = connectableObservable.toFlowable(BackpressureStrategy.BUFFER);
}
 
Example 5
Source File: StockTickerPublisher.java    From graphql-java-examples with MIT License 3 votes vote down vote up
public StockTickerPublisher() {
    Observable<StockPriceUpdate> stockPriceUpdateObservable = Observable.create(emitter -> {

        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        executorService.scheduleAtFixedRate(newStockTick(emitter), 0, 2, TimeUnit.SECONDS);

    });

    ConnectableObservable<StockPriceUpdate> connectableObservable = stockPriceUpdateObservable.share().publish();
    connectableObservable.connect();

    publisher = connectableObservable.toFlowable(BackpressureStrategy.BUFFER);
}
 
Example 6
Source File: StockTickerPublisher.java    From graphql-java-subscription-example with MIT License 3 votes vote down vote up
public StockTickerPublisher() {
    Observable<StockPriceUpdate> stockPriceUpdateObservable = Observable.create(emitter -> {

        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        executorService.scheduleAtFixedRate(newStockTick(emitter), 0, 2, TimeUnit.SECONDS);

    });

    ConnectableObservable<StockPriceUpdate> connectableObservable = stockPriceUpdateObservable.share().publish();
    connectableObservable.connect();

    publisher = connectableObservable.toFlowable(BackpressureStrategy.BUFFER);
}