@Override public void call(Subscriber<? super T> subscriber) { delegate.lift(breaker).subscribe(new SafeSubscriber<>(subscriber)); } }, delegate, breaker);
public Observable<GDMModel> getObservable() { return modelSubject.lift(new BufferOperator()).filter(m -> { if (!afterClosedStream.get() && !gdmModelDeque.isEmpty()) { gdmModelDeque.removeLast(); } if (m != null) { outGoingCounter.incrementAndGet(); return true; } nonOutGoingCounter.incrementAndGet(); return false; }).doOnCompleted(() -> LOG .info("complete {} writer observable; received '{}' records + emitted '{}' (left '{}'; discarded '{}'; polled '{}') records", type, inComingCounter.get(), outGoingCounter.get(), inComingCounter.get() - outGoingCounter.get(), nonOutGoingCounter.get(), dequePolledCounter.get())); }
/** * This will eagerly dispose this {@link Subject} without waiting for the no subscription timeout period, * if configured. * * This must be invoked when the caller is sure that no one will subscribe to this subject. Any subscriber after * this call will receive an error that the subject is disposed. * * @return {@code true} if the subject was disposed by this call (if and only if there was no subscription). */ public boolean disposeIfNotSubscribed() { if (state.casState(State.STATES.UNSUBSCRIBED, State.STATES.DISPOSED)) { state.bufferedSubject.lift(new AutoReleaseByteBufOperator<T>()).subscribe(Subscribers.empty()); // Drain all items so that ByteBuf gets released. return true; } return false; }
/** * This will eagerly dispose this {@link Subject} without waiting for the no subscription timeout period, * if configured. * * This must be invoked when the caller is sure that no one will subscribe to this subject. Any subscriber after * this call will receive an error that the subject is disposed. * * @return {@code true} if the subject was disposed by this call (if and only if there was no subscription). */ public boolean disposeIfNotSubscribed() { if (state.casState(State.STATES.UNSUBSCRIBED, State.STATES.DISPOSED)) { state.bufferedSubject.lift(new AutoReleaseByteBufOperator<T>()).subscribe(Subscribers.empty()); // Drain all items so that ByteBuf gets released. return true; } return false; }
private <C> SubjectAndWrapper<C> getSubjectAndWrapper(Interest<C, ?> interest, boolean initialize) { @SuppressWarnings("unchecked") SubjectAndWrapper<C> sub = (SubjectAndWrapper<C>) observables.get(interest); if (initialize && sub == null) { SubscriptionTracker tracker = new SubscriptionTracker(() -> observables.remove(interest)); Subject<C, C> subject = PublishSubject.<C>create().toSerialized(); //error handling: //OperatorIgnoreError - in case subscribers and us run in the same thread, an error in the subscriber //may error out the whole observable, which is definitely NOT what we want. Observable<C> wrapper = null; wrapper = subject.lift(new OperatorIgnoreError<>()).doOnSubscribe(tracker.onSubscribe()) .doOnUnsubscribe(tracker.onUnsubscribe()); sub = new SubjectAndWrapper<>(subject, wrapper); observables.put(interest, sub); } return sub; }