Search in sources :

Example 6 with Flowable

use of io.reactivex.Flowable in project jersey by jersey.

the class FlowableAgentResource method flowable.

@GET
public void flowable(@Suspended final AsyncResponse async) {
    final long time = System.nanoTime();
    final Queue<String> errors = new ConcurrentLinkedQueue<>();
    Flowable.just(new AgentResponse()).zipWith(visited(errors), (agentResponse, visited) -> {
        agentResponse.setVisited(visited);
        return agentResponse;
    }).zipWith(recommended(errors), (agentResponse, recommendations) -> {
        agentResponse.setRecommended(recommendations);
        return agentResponse;
    }).observeOn(Schedulers.io()).subscribe(agentResponse -> {
        agentResponse.setProcessingTime((System.nanoTime() - time) / 1000000);
        async.resume(agentResponse);
    }, async::resume);
}
Also used : Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AsyncResponse(javax.ws.rs.container.AsyncResponse) Path(javax.ws.rs.Path) Singleton(javax.inject.Singleton) Suspended(javax.ws.rs.container.Suspended) Calculation(org.glassfish.jersey.examples.rx.domain.Calculation) Uri(org.glassfish.jersey.server.Uri) Destination(org.glassfish.jersey.examples.rx.domain.Destination) GenericType(javax.ws.rs.core.GenericType) Forecast(org.glassfish.jersey.examples.rx.domain.Forecast) List(java.util.List) Flowable(io.reactivex.Flowable) Recommendation(org.glassfish.jersey.examples.rx.domain.Recommendation) Schedulers(io.reactivex.schedulers.Schedulers) Queue(java.util.Queue) WebTarget(javax.ws.rs.client.WebTarget) RxFlowableInvoker(org.glassfish.jersey.client.rx.rxjava2.RxFlowableInvoker) RxFlowableInvokerProvider(org.glassfish.jersey.client.rx.rxjava2.RxFlowableInvokerProvider) Collections(java.util.Collections) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AgentResponse(org.glassfish.jersey.examples.rx.domain.AgentResponse) GET(javax.ws.rs.GET)

Example 7 with Flowable

use of io.reactivex.Flowable in project RxJava-Android-Samples by kaushikgopal.

the class RxBusDemo_Bottom2Fragment method onStart.

@Override
public void onStart() {
    super.onStart();
    _disposables = new CompositeDisposable();
    Flowable<Object> tapEventEmitter = _rxBus.asFlowable().share();
    _disposables.add(tapEventEmitter.subscribe(event -> {
        if (event instanceof RxBusDemoFragment.TapEvent) {
            _showTapText();
        }
    }));
    Flowable<Object> debouncedEmitter = tapEventEmitter.debounce(1, TimeUnit.SECONDS);
    Flowable<List<Object>> debouncedBufferEmitter = tapEventEmitter.buffer(debouncedEmitter);
    _disposables.add(debouncedBufferEmitter.observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
        _showTapCount(taps.size());
    }));
}
Also used : Bundle(android.os.Bundle) ButterKnife(butterknife.ButterKnife) LayoutInflater(android.view.LayoutInflater) MainActivity(com.morihacky.android.rxjava.MainActivity) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ViewGroup(android.view.ViewGroup) BindView(butterknife.BindView) R(com.morihacky.android.rxjava.R) TimeUnit(java.util.concurrent.TimeUnit) BaseFragment(com.morihacky.android.rxjava.fragments.BaseFragment) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) List(java.util.List) TextView(android.widget.TextView) Flowable(io.reactivex.Flowable) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Nullable(android.support.annotation.Nullable) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 8 with Flowable

use of io.reactivex.Flowable in project RxJava by ReactiveX.

the class FlowableMergeDelayErrorTest method mergeMany.

@SuppressWarnings("unchecked")
@Test
@Ignore("No 2-9 parameter mergeDelayError() overloads")
public void mergeMany() throws Exception {
    for (int i = 2; i < 10; i++) {
        Class<?>[] clazz = new Class[i];
        Arrays.fill(clazz, Flowable.class);
        Flowable<Integer>[] obs = new Flowable[i];
        Arrays.fill(obs, Flowable.just(1));
        Integer[] expected = new Integer[i];
        Arrays.fill(expected, 1);
        Method m = Flowable.class.getMethod("mergeDelayError", clazz);
        TestSubscriber<Integer> ts = TestSubscriber.create();
        ((Flowable<Integer>) m.invoke(null, (Object[]) obs)).subscribe(ts);
        ts.assertValues(expected);
        ts.assertNoErrors();
        ts.assertComplete();
    }
}
Also used : Method(java.lang.reflect.Method) Flowable(io.reactivex.Flowable)

Example 9 with Flowable

use of io.reactivex.Flowable in project RxJava by ReactiveX.

the class SchedulerWhenTest method testRaceConditions.

@Test(timeout = 1000)
public void testRaceConditions() {
    Scheduler comp = Schedulers.computation();
    Scheduler limited = comp.when(new Function<Flowable<Flowable<Completable>>, Completable>() {

        @Override
        public Completable apply(Flowable<Flowable<Completable>> t) {
            return Completable.merge(Flowable.merge(t, 10));
        }
    });
    merge(just(just(1).subscribeOn(limited).observeOn(comp)).repeat(1000)).blockingSubscribe();
}
Also used : Completable(io.reactivex.Completable) Scheduler(io.reactivex.Scheduler) TestScheduler(io.reactivex.schedulers.TestScheduler) Flowable(io.reactivex.Flowable) Test(org.junit.Test)

Example 10 with Flowable

use of io.reactivex.Flowable in project RxCache by VictorAlbertos.

the class ProxyTranslator method getLoaderObservable.

private Observable getLoaderObservable(Method method, Object[] objectsMethod) {
    Observable<?> observable = getObjectFromMethodParam(method, Observable.class, objectsMethod);
    if (observable != null)
        return observable;
    Single single = getObjectFromMethodParam(method, Single.class, objectsMethod);
    if (single != null)
        return single.toObservable();
    Maybe maybe = getObjectFromMethodParam(method, Maybe.class, objectsMethod);
    if (maybe != null)
        return maybe.toObservable();
    Flowable flowable = getObjectFromMethodParam(method, Flowable.class, objectsMethod);
    if (flowable != null)
        return flowable.toObservable();
    String errorMessage = method.getName() + io.rx_cache2.internal.Locale.NOT_REACTIVE_TYPE_FOR_LOADER_WAS_FOUND;
    throw new IllegalArgumentException(errorMessage);
}
Also used : Maybe(io.reactivex.Maybe) Single(io.reactivex.Single) Flowable(io.reactivex.Flowable)

Aggregations

Flowable (io.reactivex.Flowable)16 Test (org.junit.Test)7 Maybe (io.reactivex.Maybe)5 Single (io.reactivex.Single)5 Observable (io.reactivex.Observable)4 Type (java.lang.reflect.Type)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 Schedulers (io.reactivex.schedulers.Schedulers)3 Collections (java.util.Collections)3 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 Nullable (android.support.annotation.Nullable)2 Scheduler (io.reactivex.Scheduler)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Queue (java.util.Queue)2 Singleton (javax.inject.Singleton)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebTarget (javax.ws.rs.client.WebTarget)2