use of io.reactivex.flowables.ConnectableFlowable in project RxJava by ReactiveX.
the class RxJavaPluginsTest method overrideConnectableFlowable.
@SuppressWarnings("rawtypes")
@Test
public void overrideConnectableFlowable() {
try {
RxJavaPlugins.setOnConnectableFlowableAssembly(new Function<ConnectableFlowable, ConnectableFlowable>() {
@Override
public ConnectableFlowable apply(ConnectableFlowable co) throws Exception {
return new ConnectableFlowable() {
@Override
public void connect(Consumer connection) {
}
@SuppressWarnings("unchecked")
@Override
protected void subscribeActual(Subscriber subscriber) {
subscriber.onSubscribe(new ScalarSubscription(subscriber, 10));
}
};
}
});
Flowable.just(1).publish().autoConnect().test().assertResult(10);
} finally {
RxJavaPlugins.reset();
}
Flowable.just(1).publish().autoConnect().test().assertResult(1);
}
use of io.reactivex.flowables.ConnectableFlowable in project RxJava by ReactiveX.
the class RxJavaPluginsTest method clearIsPassthrough.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void clearIsPassthrough() {
try {
RxJavaPlugins.reset();
assertNull(RxJavaPlugins.onAssembly((Observable) null));
assertNull(RxJavaPlugins.onAssembly((ConnectableObservable) null));
assertNull(RxJavaPlugins.onAssembly((Flowable) null));
assertNull(RxJavaPlugins.onAssembly((ConnectableFlowable) null));
Observable oos = new Observable() {
@Override
public void subscribeActual(Observer t) {
}
};
Flowable fos = new Flowable() {
@Override
public void subscribeActual(Subscriber t) {
}
};
assertSame(oos, RxJavaPlugins.onAssembly(oos));
assertSame(fos, RxJavaPlugins.onAssembly(fos));
assertNull(RxJavaPlugins.onAssembly((Single) null));
Single sos = new Single() {
@Override
public void subscribeActual(SingleObserver t) {
}
};
assertSame(sos, RxJavaPlugins.onAssembly(sos));
assertNull(RxJavaPlugins.onAssembly((Completable) null));
Completable cos = new Completable() {
@Override
public void subscribeActual(CompletableObserver t) {
}
};
assertSame(cos, RxJavaPlugins.onAssembly(cos));
assertNull(RxJavaPlugins.onAssembly((Maybe) null));
assertNull(RxJavaPlugins.onSchedule(null));
Maybe myb = new Maybe() {
@Override
public void subscribeActual(MaybeObserver t) {
}
};
assertSame(myb, RxJavaPlugins.onAssembly(myb));
assertNull(RxJavaPlugins.onSchedule(null));
Runnable action = Functions.EMPTY_RUNNABLE;
assertSame(action, RxJavaPlugins.onSchedule(action));
class AllSubscriber implements Subscriber, Observer, SingleObserver, CompletableObserver, MaybeObserver {
@Override
public void onSuccess(Object value) {
}
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onSubscribe(Subscription s) {
}
@Override
public void onNext(Object t) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
}
}
AllSubscriber all = new AllSubscriber();
assertNull(RxJavaPlugins.onSubscribe(Observable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Observable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Flowable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Flowable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Single.just(1), null));
assertSame(all, RxJavaPlugins.onSubscribe(Single.just(1), all));
assertNull(RxJavaPlugins.onSubscribe(Completable.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Completable.never(), all));
assertNull(RxJavaPlugins.onSubscribe(Maybe.never(), null));
assertSame(all, RxJavaPlugins.onSubscribe(Maybe.never(), all));
// These hooks don't exist in 2.0
// Subscription subscription = Subscriptions.empty();
//
// assertNull(RxJavaPlugins.onObservableReturn(null));
//
// assertSame(subscription, RxJavaPlugins.onObservableReturn(subscription));
//
// assertNull(RxJavaPlugins.onSingleReturn(null));
//
// assertSame(subscription, RxJavaPlugins.onSingleReturn(subscription));
//
// TestException ex = new TestException();
//
// assertNull(RxJavaPlugins.onObservableError(null));
//
// assertSame(ex, RxJavaPlugins.onObservableError(ex));
//
// assertNull(RxJavaPlugins.onSingleError(null));
//
// assertSame(ex, RxJavaPlugins.onSingleError(ex));
//
// assertNull(RxJavaPlugins.onCompletableError(null));
//
// assertSame(ex, RxJavaPlugins.onCompletableError(ex));
//
// Observable.Operator oop = new Observable.Operator() {
// @Override
// public Object call(Object t) {
// return t;
// }
// };
//
// assertNull(RxJavaPlugins.onObservableLift(null));
//
// assertSame(oop, RxJavaPlugins.onObservableLift(oop));
//
// assertNull(RxJavaPlugins.onSingleLift(null));
//
// assertSame(oop, RxJavaPlugins.onSingleLift(oop));
//
// Completable.CompletableOperator cop = new Completable.CompletableOperator() {
// @Override
// public CompletableSubscriber call(CompletableSubscriber t) {
// return t;
// }
// };
//
// assertNull(RxJavaPlugins.onCompletableLift(null));
//
// assertSame(cop, RxJavaPlugins.onCompletableLift(cop));
final Scheduler s = ImmediateThinScheduler.INSTANCE;
Callable<Scheduler> c = new Callable<Scheduler>() {
@Override
public Scheduler call() throws Exception {
return s;
}
};
assertSame(s, RxJavaPlugins.onComputationScheduler(s));
assertSame(s, RxJavaPlugins.onIoScheduler(s));
assertSame(s, RxJavaPlugins.onNewThreadScheduler(s));
assertSame(s, RxJavaPlugins.onSingleScheduler(s));
assertSame(s, RxJavaPlugins.initComputationScheduler(c));
assertSame(s, RxJavaPlugins.initIoScheduler(c));
assertSame(s, RxJavaPlugins.initNewThreadScheduler(c));
assertSame(s, RxJavaPlugins.initSingleScheduler(c));
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.flowables.ConnectableFlowable in project RxJava-Android-Samples by kaushikgopal.
the class RxBusDemo_Bottom3Fragment method onStart.
@Override
public void onStart() {
super.onStart();
_disposables = new CompositeDisposable();
ConnectableFlowable<Object> tapEventEmitter = _rxBus.asFlowable().publish();
//
_disposables.add(tapEventEmitter.subscribe(event -> {
if (event instanceof RxBusDemoFragment.TapEvent) {
_showTapText();
}
}));
_disposables.add(tapEventEmitter.publish(stream -> stream.buffer(stream.debounce(1, TimeUnit.SECONDS))).observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
_showTapCount(taps.size());
}));
_disposables.add(tapEventEmitter.connect());
}
use of io.reactivex.flowables.ConnectableFlowable in project brave by openzipkin.
the class CurrentTraceContextAssemblyTrackingMatrixTest method connectableObservable_assembleInScope_subscribeNoScope.
// NOTE: we aren't doing separate tests for conditional ConnectableFlowable as there are no
// operations on the type that are conditional (ex filter)
@Test
public void connectableObservable_assembleInScope_subscribeNoScope() {
ConnectableObservable<Integer> source, errorSource;
try (Scope scope = currentTraceContext.newScope(assemblyContext)) {
source = Observable.range(1, 3).doOnNext(e -> assertInAssemblyContext()).doOnComplete(this::assertInAssemblyContext).publish();
errorSource = Observable.<Integer>error(new IllegalStateException()).doOnError(t -> assertInAssemblyContext()).doOnComplete(this::assertInAssemblyContext).publish();
}
subscribeInNoContext(source.autoConnect(), errorSource.autoConnect()).assertResult(1, 2, 3);
}
use of io.reactivex.flowables.ConnectableFlowable in project incubator-gobblin by apache.
the class StreamModelTaskRunner method run.
protected void run() throws Exception {
// Get the fork operator. By default IdentityForkOperator is used with a single branch.
ForkOperator forkOperator = closer.register(this.taskContext.getForkOperator());
RecordStreamWithMetadata<?, ?> stream = this.extractor.recordStream(this.shutdownRequested);
ConnectableFlowable connectableStream = stream.getRecordStream().publish();
stream = stream.withRecordStream(connectableStream);
stream = stream.mapRecords(r -> {
this.task.onRecordExtract();
return r;
});
if (this.task.isStreamingTask()) {
// Start watermark manager and tracker
if (this.watermarkTracker.isPresent()) {
this.watermarkTracker.get().start();
}
this.watermarkManager.get().start();
((StreamingExtractor) this.taskContext.getRawSourceExtractor()).start(this.watermarkStorage.get());
stream = stream.mapRecords(r -> {
AcknowledgableWatermark ackableWatermark = new AcknowledgableWatermark(r.getWatermark());
if (watermarkTracker.isPresent()) {
watermarkTracker.get().track(ackableWatermark);
}
r.addCallBack(ackableWatermark);
return r;
});
}
// Use the recordStreamProcessor list if it is configured. This list can contain both all RecordStreamProcessor types
if (!this.recordStreamProcessors.isEmpty()) {
for (RecordStreamProcessor streamProcessor : this.recordStreamProcessors) {
stream = streamProcessor.processStream(stream, this.taskState);
}
} else {
if (this.converter instanceof MultiConverter) {
// if multiconverter, unpack it
for (Converter cverter : ((MultiConverter) this.converter).getConverters()) {
stream = cverter.processStream(stream, this.taskState);
}
} else {
stream = this.converter.processStream(stream, this.taskState);
}
}
stream = this.rowChecker.processStream(stream, this.taskState);
Forker.ForkedStream<?, ?> forkedStreams = new Forker().forkStream(stream, forkOperator, this.taskState);
boolean isForkAsync = !this.task.areSingleBranchTasksSynchronous(this.taskContext) || forkedStreams.getForkedStreams().size() > 1;
int bufferSize = this.taskState.getPropAsInt(ConfigurationKeys.FORK_RECORD_QUEUE_CAPACITY_KEY, ConfigurationKeys.DEFAULT_FORK_RECORD_QUEUE_CAPACITY);
for (int fidx = 0; fidx < forkedStreams.getForkedStreams().size(); fidx++) {
RecordStreamWithMetadata<?, ?> forkedStream = forkedStreams.getForkedStreams().get(fidx);
if (forkedStream != null) {
if (isForkAsync) {
forkedStream = forkedStream.mapStream(f -> f.observeOn(Schedulers.from(this.taskExecutor.getForkExecutor()), false, bufferSize));
}
Fork fork = new Fork(this.taskContext, forkedStream.getGlobalMetadata().getSchema(), forkedStreams.getForkedStreams().size(), fidx, this.taskMode);
fork.consumeRecordStream(forkedStream);
this.forks.put(Optional.of(fork), Optional.of(Futures.immediateFuture(null)));
this.task.configureStreamingFork(fork, this.watermarkingStrategy);
}
}
connectableStream.connect();
if (!ExponentialBackoff.awaitCondition().callable(() -> this.forks.keySet().stream().map(Optional::get).allMatch(Fork::isDone)).initialDelay(1000L).maxDelay(1000L).maxWait(TimeUnit.MINUTES.toMillis(60)).await()) {
throw new TimeoutException("Forks did not finish withing specified timeout.");
}
}
Aggregations