Search in sources :

Example 1 with Subject

use of rx.subjects.Subject in project AndroidNews by zhjohow.

the class RxBus method post.

/**
 * 触发事件
 *
 * @param content
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void post(@NonNull Object tag, @NonNull Object content) {
    LogUtils.logd("post" + "eventName: " + tag);
    List<Subject> subjectList = subjectMapper.get(tag);
    if (!isEmpty(subjectList)) {
        for (Subject subject : subjectList) {
            subject.onNext(content);
            LogUtils.logd("onEvent" + "eventName: " + tag);
        }
    }
}
Also used : PublishSubject(rx.subjects.PublishSubject) Subject(rx.subjects.Subject)

Example 2 with Subject

use of rx.subjects.Subject in project ribbon by Netflix.

the class HttpMetaRequest method convertToRibbonResponse.

private Observable<RibbonResponse<Observable<T>>> convertToRibbonResponse(final HystrixObservableCommandChain<T> commandChain, final Observable<ResultCommandPair<T>> hystrixNotificationObservable) {
    return Observable.create(new OnSubscribe<RibbonResponse<Observable<T>>>() {

        @Override
        public void call(final Subscriber<? super RibbonResponse<Observable<T>>> t1) {
            final Subject<T, T> subject = ReplaySubject.create();
            hystrixNotificationObservable.materialize().subscribe(new Action1<Notification<ResultCommandPair<T>>>() {

                AtomicBoolean first = new AtomicBoolean(true);

                @Override
                public void call(Notification<ResultCommandPair<T>> notification) {
                    if (first.compareAndSet(true, false)) {
                        HystrixObservableCommand<T> command = notification.isOnError() ? commandChain.getLastCommand() : notification.getValue().getCommand();
                        t1.onNext(new ResponseWithSubject<T>(subject, command));
                        t1.onCompleted();
                    }
                    if (notification.isOnNext()) {
                        subject.onNext(notification.getValue().getResult());
                    } else if (notification.isOnCompleted()) {
                        subject.onCompleted();
                    } else {
                        // onError
                        subject.onError(notification.getThrowable());
                    }
                }
            });
        }
    });
}
Also used : Action1(rx.functions.Action1) Observable(rx.Observable) Subject(rx.subjects.Subject) ReplaySubject(rx.subjects.ReplaySubject) Notification(rx.Notification) RibbonResponse(com.netflix.ribbon.RibbonResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResultCommandPair(com.netflix.ribbon.hystrix.ResultCommandPair)

Aggregations

Subject (rx.subjects.Subject)2 RibbonResponse (com.netflix.ribbon.RibbonResponse)1 ResultCommandPair (com.netflix.ribbon.hystrix.ResultCommandPair)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Notification (rx.Notification)1 Observable (rx.Observable)1 Action1 (rx.functions.Action1)1 PublishSubject (rx.subjects.PublishSubject)1 ReplaySubject (rx.subjects.ReplaySubject)1