io.reactivex.parallel.ParallelFlowable Java Examples
The following examples show how to use
io.reactivex.parallel.ParallelFlowable.
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: ParallelFlowableLife.java From rxjava-RxLife with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public void subscribe(@NonNull Subscriber<? super T>[] subscribers) { if (!validate(subscribers)) { return; } int n = subscribers.length; Subscriber<? super T>[] parents = new Subscriber[n]; for (int i = 0; i < n; i++) { Subscriber<? super T> a = subscribers[i]; if (a instanceof ConditionalSubscriber) { parents[i] = new LifeConditionalSubscriber<>((ConditionalSubscriber<? super T>) a, scope); } else { parents[i] = new LifeSubscriber<>(a, scope); } } ParallelFlowable<T> upStream = this.upStream; if (onMain) upStream = upStream.runOn(AndroidSchedulers.mainThread()); upStream.subscribe(parents); }
Example #2
Source File: CurrentTraceContextAssemblyTrackingMatrixTest.java From brave with Apache License 2.0 | 6 votes |
@Test public void parallelFlowable_conditional_assembleInScope_subscribeInScope() { ParallelFlowable<Integer> source, errorSource; try (Scope scope = currentTraceContext.newScope(assemblyContext)) { source = Flowable.range(1, 3).parallel() .filter(lessThanThreeInAssemblyContext) .doOnNext(e -> assertInAssemblyContext()) .doOnComplete(this::assertInAssemblyContext); errorSource = Flowable.<Integer>concat( Flowable.error(new IllegalStateException()), Flowable.error(new IllegalStateException())) .parallel() .filter(lessThanThreeInAssemblyContext) .doOnError(t -> assertInAssemblyContext()) .doOnComplete(this::assertInAssemblyContext); } subscribeInDifferentContext(source, errorSource).assertResult(1, 2); }
Example #3
Source File: CurrentTraceContextAssemblyTrackingMatrixTest.java From brave with Apache License 2.0 | 6 votes |
@Test public void parallelFlowable_conditional_assembleInScope_subscribeNoScope() { ParallelFlowable<Integer> source, errorSource; try (Scope scope = currentTraceContext.newScope(assemblyContext)) { source = Flowable.range(1, 3).parallel() .filter(lessThanThreeInAssemblyContext) .doOnNext(e -> assertInAssemblyContext()) .doOnComplete(this::assertInAssemblyContext); errorSource = Flowable.<Integer>concat( Flowable.error(new IllegalStateException()), Flowable.error(new IllegalStateException())) .parallel() .filter(lessThanThreeInAssemblyContext) .doOnError(t -> assertInAssemblyContext()) .doOnComplete(this::assertInAssemblyContext); } subscribeInNoContext(source, errorSource).assertResult(1, 2); }
Example #4
Source File: CurrentTraceContextAssemblyTrackingMatrixTest.java From brave with Apache License 2.0 | 5 votes |
TestObserver<Integer> subscribeInDifferentContext(ParallelFlowable<Integer> source, ParallelFlowable<Integer> errorSource) { source = source.doOnSubscribe(s -> assertInSubscribeContext()); errorSource = errorSource.doOnSubscribe(s -> assertInSubscribeContext()); try (Scope scope2 = currentTraceContext.newScope(subscribeContext)) { errorSource.sequential().test().assertFailure(IllegalStateException.class); return source.sequential().toObservable().test(); } }
Example #5
Source File: CurrentTraceContextAssemblyTrackingMatrixTest.java From brave with Apache License 2.0 | 5 votes |
TestObserver<Integer> subscribeInNoContext(ParallelFlowable<Integer> source, ParallelFlowable<Integer> errorSource) { source = source.doOnSubscribe(s -> assertInNoContext()); errorSource = errorSource.doOnSubscribe(s -> assertInNoContext()); errorSource.sequential().test().assertFailure(IllegalStateException.class); return source.sequential().toObservable().test(); }
Example #6
Source File: CurrentTraceContextAssemblyTrackingMatrixTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void parallelFlowable_conditional_assembleNoScope_subscribeInScope() { ParallelFlowable<Integer> source = Flowable.range(1, 3).parallel() .filter(lessThanThreeInSubscribeContext) .doOnNext(e -> assertInSubscribeContext()) .doOnComplete(this::assertInSubscribeContext); ParallelFlowable<Integer> errorSource = Flowable.<Integer>concat( Flowable.error(new IllegalStateException()), Flowable.error(new IllegalStateException())) .parallel() .filter(lessThanThreeInSubscribeContext) .doOnError(t -> assertInSubscribeContext()) .doOnComplete(this::assertInSubscribeContext); subscribeInDifferentContext(source, errorSource).assertResult(1, 2); }
Example #7
Source File: CurrentTraceContextAssemblyTrackingMatrixTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void parallelFlowable_assembleNoScope_subscribeInScope() { ParallelFlowable<Integer> source = Flowable.range(1, 3).parallel() .doOnNext(e -> assertInSubscribeContext()) .doOnComplete(this::assertInSubscribeContext); ParallelFlowable<Integer> errorSource = Flowable.<Integer>concat( Flowable.error(new IllegalStateException()), Flowable.error(new IllegalStateException())) .parallel() .doOnError(t -> assertInSubscribeContext()) .doOnComplete(this::assertInSubscribeContext); subscribeInDifferentContext(source, errorSource).assertResult(1, 2, 3); }
Example #8
Source File: CurrentTraceContextAssemblyTrackingMatrixTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void parallelFlowable_assembleInScope_subscribeInScope() { ParallelFlowable<Integer> source, errorSource; try (Scope scope = currentTraceContext.newScope(assemblyContext)) { source = Flowable.range(1, 3).parallel() .doOnNext(e -> assertInAssemblyContext()) .doOnComplete(this::assertInAssemblyContext); errorSource = Flowable.<Integer>concat( Flowable.error(new IllegalStateException()), Flowable.error(new IllegalStateException())) .parallel() .doOnError(t -> assertInAssemblyContext()) .doOnComplete(this::assertInAssemblyContext); } subscribeInDifferentContext(source, errorSource).assertResult(1, 2, 3); }
Example #9
Source File: CurrentTraceContextAssemblyTrackingMatrixTest.java From brave with Apache License 2.0 | 5 votes |
@Test public void parallelFlowable_assembleInScope_subscribeNoScope() { ParallelFlowable<Integer> source, errorSource; try (Scope scope = currentTraceContext.newScope(assemblyContext)) { source = Flowable.range(1, 3).parallel() .doOnNext(e -> assertInAssemblyContext()) .doOnComplete(this::assertInAssemblyContext); errorSource = Flowable.<Integer>concat( Flowable.error(new IllegalStateException()), Flowable.error(new IllegalStateException())) .parallel() .doOnError(t -> assertInAssemblyContext()) .doOnComplete(this::assertInAssemblyContext); } subscribeInNoContext(source, errorSource).assertResult(1, 2, 3); }
Example #10
Source File: ParallelPerf.java From akarnokd-misc with Apache License 2.0 | 5 votes |
@Setup public void setup() { flowable = ParallelFlowable.from(Flowable.range(0, count)).runOn(Schedulers.computation()) .filter(v -> { Blackhole.consumeCPU(cost); return false; }) .sequential(); flowableFJ = ParallelFlowable.from(Flowable.range(0, count)) .runOn(Schedulers.from(ForkJoinPool.commonPool())) .filter(v -> { Blackhole.consumeCPU(cost); return false; }) .sequential(); }
Example #11
Source File: ParallelFlowableRange.java From rxjava2 with MIT License | 5 votes |
public static void main(String[] args) { int numberOfRails = 4; // can query #processors with parallelism() ParallelFlowable .from(Flowable.range(1, 10), numberOfRails) .runOn(Schedulers.computation()) .map(i -> i * i) .filter(i -> i % 3 == 0) .sequential() .subscribe(System.out::println); }
Example #12
Source File: Scheduler.java From Learn-Java-12-Programming with MIT License | 5 votes |
private static void parallel3(){ ParallelFlowable src = Flowable.fromArray("one","two","three").parallel(); src.runOn(Schedulers.computation()) .doAfterNext(s -> System.out.println("1: " + Thread.currentThread().getName() + " => " + s)) .flatMap(w -> Flowable.fromArray(((String)w).split(""))) .runOn(Schedulers.computation()) .doAfterNext(s -> System.out.println("2: " + Thread.currentThread().getName() + " => " + s)) .sequential() .subscribe(s -> System.out.println("3: " + s)); pauseMs(100); }
Example #13
Source File: Wrappers.java From brave with Apache License 2.0 | 4 votes |
public static <T> ParallelFlowable<T> wrap( ParallelFlowable<T> source, CurrentTraceContext contextScoper, TraceContext assembled) { return new TraceContextParallelFlowable<>(source, contextScoper, assembled); }
Example #14
Source File: TraceContextParallelFlowable.java From brave with Apache License 2.0 | 4 votes |
TraceContextParallelFlowable( ParallelFlowable<T> source, CurrentTraceContext contextScoper, TraceContext assembled) { this.source = source; this.contextScoper = contextScoper; this.assembled = assembled; }
Example #15
Source File: RequestContextParallelFlowable.java From armeria with Apache License 2.0 | 4 votes |
RequestContextParallelFlowable(ParallelFlowable<T> source, RequestContext assemblyContext) { this.source = source; this.assemblyContext = assemblyContext; }
Example #16
Source File: RxJava2AssemblyTrackingTest.java From RxJava2Debug with Apache License 2.0 | 4 votes |
static ParallelFlowable<Integer> createParallelFlowable() { return Flowable.range(1, 5).concatWith(Flowable.<Integer>error(new IOException())).parallel(); }
Example #17
Source File: ParallelFlowableOnAssembly.java From RxJava2Debug with Apache License 2.0 | 4 votes |
ParallelFlowableOnAssembly(ParallelFlowable<T> source) { this.source = source; this.assembled = new RxJavaAssemblyException(); }
Example #18
Source File: ParallelFlowableLife.java From rxjava-RxLife with Apache License 2.0 | 4 votes |
ParallelFlowableLife(ParallelFlowable<T> upStream, Scope scope, boolean onMain) { this.upStream = upStream; this.scope = scope; this.onMain = onMain; }