Search in sources :

Example 1 with StopWatch

use of com.fernandocejas.frodo.internal.StopWatch in project frodo by android10.

the class LogStreamObservable method get.

@Override
<T> Observable<T> get(T type) throws Throwable {
    final StopWatch stopWatch = new StopWatch();
    final Counter emittedItems = new Counter(joinPoint.getMethodName());
    return ((Observable<T>) joinPoint.proceed()).doOnSubscribe(new Action0() {

        @Override
        public void call() {
            stopWatch.start();
        }
    }).doOnNext(new Action1<T>() {

        @Override
        public void call(T value) {
            emittedItems.increment();
            messageManager.printObservableOnNextWithValue(observableInfo, value);
        }
    }).doOnError(new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            messageManager.printObservableOnError(observableInfo, throwable);
        }
    }).doOnTerminate(new Action0() {

        @Override
        public void call() {
            stopWatch.stop();
            observableInfo.setTotalExecutionTime(stopWatch.getTotalTimeMillis());
            observableInfo.setTotalEmittedItems(emittedItems.tally());
            messageManager.printObservableItemTimeInfo(observableInfo);
        }
    });
}
Also used : Action0(rx.functions.Action0) Counter(com.fernandocejas.frodo.internal.Counter) Action1(rx.functions.Action1) StopWatch(com.fernandocejas.frodo.internal.StopWatch)

Example 2 with StopWatch

use of com.fernandocejas.frodo.internal.StopWatch in project frodo by android10.

the class LogEverythingObservable method get.

@Override
<T> Observable<T> get(T type) throws Throwable {
    final StopWatch stopWatch = new StopWatch();
    final Counter emittedItems = new Counter(joinPoint.getMethodName());
    return ((Observable<T>) joinPoint.proceed()).doOnSubscribe(new Action0() {

        @Override
        public void call() {
            stopWatch.start();
            messageManager.printObservableOnSubscribe(observableInfo);
        }
    }).doOnEach(new Action1<Notification<? super T>>() {

        @Override
        public void call(Notification<? super T> notification) {
            if (!observableInfo.getSubscribeOnThread().isPresent() && (notification.isOnNext() || notification.isOnError())) {
                observableInfo.setSubscribeOnThread(Thread.currentThread().getName());
            }
        }
    }).doOnNext(new Action1<T>() {

        @Override
        public void call(T value) {
            emittedItems.increment();
            messageManager.printObservableOnNextWithValue(observableInfo, value);
        }
    }).doOnError(new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            messageManager.printObservableOnError(observableInfo, throwable);
        }
    }).doOnCompleted(new Action0() {

        @Override
        public void call() {
            messageManager.printObservableOnCompleted(observableInfo);
        }
    }).doOnTerminate(new Action0() {

        @Override
        public void call() {
            stopWatch.stop();
            observableInfo.setTotalExecutionTime(stopWatch.getTotalTimeMillis());
            observableInfo.setTotalEmittedItems(emittedItems.tally());
            messageManager.printObservableOnTerminate(observableInfo);
            messageManager.printObservableItemTimeInfo(observableInfo);
        }
    }).doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            if (!observableInfo.getObserveOnThread().isPresent()) {
                observableInfo.setObserveOnThread(Thread.currentThread().getName());
            }
            messageManager.printObservableThreadInfo(observableInfo);
            messageManager.printObservableOnUnsubscribe(observableInfo);
        }
    });
}
Also used : Action0(rx.functions.Action0) Counter(com.fernandocejas.frodo.internal.Counter) Action1(rx.functions.Action1) Observable(rx.Observable) Notification(rx.Notification) StopWatch(com.fernandocejas.frodo.internal.StopWatch)

Aggregations

Counter (com.fernandocejas.frodo.internal.Counter)2 StopWatch (com.fernandocejas.frodo.internal.StopWatch)2 Action0 (rx.functions.Action0)2 Action1 (rx.functions.Action1)2 Notification (rx.Notification)1 Observable (rx.Observable)1