本文整理汇总了Java中rx.schedulers.Timestamped类的典型用法代码示例。如果您正苦于以下问题:Java Timestamped类的具体用法?Java Timestamped怎么用?Java Timestamped使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Timestamped类属于rx.schedulers包,在下文中一共展示了Timestamped类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runCode
import rx.schedulers.Timestamped; //导入依赖的package包/类
public void runCode() {
Observable
.interval(100, TimeUnit.MILLISECONDS)
.take(3)
.timestamp()
.subscribe(new Observer<Timestamped>() {
@Override
public void onCompleted() {
println("------>onCompleted()");
}
@Override
public void onError(Throwable e) {
println("------>onError()" + e);
}
@Override
public void onNext(Timestamped mTimestamped) {
println("------->onNext()"+mTimestamped);
}
});
}
示例2: getRecentPhotosFilter
import rx.schedulers.Timestamped; //导入依赖的package包/类
private Func1<Timestamped<RecentPhotosResponse>, Boolean> getRecentPhotosFilter(final ITimestampedView timestampedView) {
return new Func1<Timestamped<RecentPhotosResponse>, Boolean>() {
@Override
public Boolean call(Timestamped<RecentPhotosResponse> recentPhotosResponseTimestamped) {
StringBuilder logMessage = new StringBuilder("getMergedPhotos().filter() - Filtering results");
if (recentPhotosResponseTimestamped == null) {
logMessage.append(", recentPhotosResponseTimestamped is null");
} else {
logMessage.append(", timestamps=").append(recentPhotosResponseTimestamped.getTimestampMillis()).append(">").append(timestampedView.getViewDataTimestampMillis()).append("?");
}
logMessage.append(", thread=").append(Thread.currentThread().getName());
Log.d(CLASSNAME, logMessage.toString());
// filter it
// if result is null - ignore it
// if timestamp of new arrived (emission) data is less than timestamp of already displayed data — ignore it.
return recentPhotosResponseTimestamped != null
&& recentPhotosResponseTimestamped.getValue() != null
&& recentPhotosResponseTimestamped.getValue().photos != null
&& recentPhotosResponseTimestamped.getTimestampMillis() > timestampedView.getViewDataTimestampMillis();
}
};
}
示例3: call
import rx.schedulers.Timestamped; //导入依赖的package包/类
/**
* @return a sequence of timestamped values created by adding timestamps to each item in the input sequence.
*/
@Override
public Subscriber<? super T> call(final Subscriber<? super Timestamped<T>> o) {
return new Subscriber<T>(o) {
@Override
public void onComplete() {
o.onComplete();
}
@Override
public void onError(Throwable e) {
o.onError(e);
}
@Override
public void onNext(T t) {
o.onNext(new Timestamped<T>(scheduler.now(), t));
}
};
}
示例4: timestampWithScheduler
import rx.schedulers.Timestamped; //导入依赖的package包/类
@Test
public void timestampWithScheduler() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Timestamped<Integer>> m = source.timestamp(scheduler);
m.subscribe(observer);
source.onNext(1);
scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);
source.onNext(2);
scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);
source.onNext(3);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext(new Timestamped<Integer>(0, 1));
inOrder.verify(observer, times(1)).onNext(new Timestamped<Integer>(100, 2));
inOrder.verify(observer, times(1)).onNext(new Timestamped<Integer>(200, 3));
verify(observer, never()).onError(any(Throwable.class));
verify(observer, never()).onComplete();
}
示例5: timestampWithScheduler2
import rx.schedulers.Timestamped; //导入依赖的package包/类
@Test
public void timestampWithScheduler2() {
TestScheduler scheduler = new TestScheduler();
PublishSubject<Integer> source = PublishSubject.create();
Observable<Timestamped<Integer>> m = source.timestamp(scheduler);
m.subscribe(observer);
source.onNext(1);
source.onNext(2);
scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);
scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);
source.onNext(3);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext(new Timestamped<Integer>(0, 1));
inOrder.verify(observer, times(1)).onNext(new Timestamped<Integer>(0, 2));
inOrder.verify(observer, times(1)).onNext(new Timestamped<Integer>(200, 3));
verify(observer, never()).onError(any(Throwable.class));
verify(observer, never()).onComplete();
}
示例6: call
import rx.schedulers.Timestamped; //导入依赖的package包/类
/**
* @return a sequence of timestamped values created by adding timestamps to each item in the input sequence.
*/
@Override
public Subscriber<? super T> call(final Subscriber<? super Timestamped<T>> o) {
return new Subscriber<T>(o) {
@Override
public void onCompleted() {
o.onCompleted();
}
@Override
public void onError(Throwable e) {
o.onError(e);
}
@Override
public void onNext(T t) {
o.onNext(new Timestamped<T>(scheduler.now(), t));
}
};
}
示例7: call
import rx.schedulers.Timestamped; //导入依赖的package包/类
public Subscriber<? super T> call(final Subscriber<? super Timestamped<T>> o) {
return new Subscriber<T>(o) {
public void onCompleted() {
o.onCompleted();
}
public void onError(Throwable e) {
o.onError(e);
}
public void onNext(T t) {
o.onNext(new Timestamped(OperatorTimestamp.this.scheduler.now(), t));
}
};
}
示例8: getMergedPhotos
import rx.schedulers.Timestamped; //导入依赖的package包/类
@RxLogObservable
private Observable<Timestamped<RecentPhotosResponse>> getMergedPhotos() {
return Observable.mergeDelayError(
flickrDiskRepository.getRecentPhotos().subscribeOn(Schedulers.io()),
flickrNetworkRepository.getRecentPhotos().timestamp().doOnNext(new Action1<Timestamped<RecentPhotosResponse>>() {
@Override
public void call(Timestamped<RecentPhotosResponse> recentPhotosResponse) {
Log.d(CLASSNAME, "flickrApiRepository.getRecentPhotos().doOnNext() - Saving photos to disk - thread=" + Thread.currentThread().getName());
flickrDiskRepository.savePhotos(recentPhotosResponse);
}
}).subscribeOn(Schedulers.io())
);
}
示例9: getRecentPhotos
import rx.schedulers.Timestamped; //导入依赖的package包/类
@RxLogObservable
public Observable<Timestamped<RecentPhotosResponse>> getRecentPhotos() {
return Observable.fromCallable(new Callable<Timestamped<RecentPhotosResponse>>() {
@Override
public Timestamped<RecentPhotosResponse> call() throws Exception {
// if (true) throw new RuntimeException("DISK.getRecentPhotos() fake Exception!");
String serializedPhotoList = sharedPreferences.getString(RECENT_PHOTOS_RESPONSE_KEY, "");
Timestamped<RecentPhotosResponse> photos = null;
if (!TextUtils.isEmpty(serializedPhotoList)) {
photos = flickrPhotosJsonAdapter.fromJson(serializedPhotoList);
}
return photos;
}
});
}
示例10: setupView
import rx.schedulers.Timestamped; //导入依赖的package包/类
private void setupView(View view) {
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.flickr_swipe_refresh);
swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_orange_dark);
swipeRefreshLayout.setOnRefreshListener(this);
recyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
recyclerView.setHasFixedSize(true);
// use a linear layout manager
recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
// specify an adapter
recyclerView.setAdapter(flickrListAdapter = new FlickrListAdapter(new Timestamped<>(getViewDataTimestampMillis(), Collections.<FlickrCardVM>emptyList())));
}
示例11: fetchFlickrItems
import rx.schedulers.Timestamped; //导入依赖的package包/类
private void fetchFlickrItems() {
isRefreshing(true);
unsubscribe();
Observable<Timestamped<List<FlickrCardVM>>> recentPhotosObservable = flickrDomainService
.getRecentPhotos(this)
.observeOn(AndroidSchedulers.mainThread(), true); // delayError = true
flickrListSubscription = recentPhotosObservable.subscribe(flickrRecentPhotosOnNext, flickrRecentPhotosOnError, flickrRecenPhotosOnComplete);
}
示例12: sync
import rx.schedulers.Timestamped; //导入依赖的package包/类
/**
* Fetches a new value, caches it and immediately emits it to subscribers. If this errors,
* the error will <em>not</em> be relayed to subscribers of {@link #get()}
*/
public Completable sync() {
return fetch()
.doOnNext(new Action1<Timestamped<T>>() {
@Override public void call(Timestamped<T> tTimestamped) {
updates.onNext(tTimestamped.getValue());
}
})
.toCompletable();
}
示例13: fetch
import rx.schedulers.Timestamped; //导入依赖的package包/类
private Observable<Timestamped<T>> fetch() {
return Observable.defer(new Func0<Observable<Timestamped<T>>>() {
@Override public Observable<Timestamped<T>> call() {
Observable<Timestamped<T>> newCache = coldSource.timestamp(scheduler).cache();
cache = newCache;
return newCache;
}
}).doOnError(new Action1<Throwable>() {
@Override public void call(Throwable throwable) {
invalidate();
}
});
}
示例14: loadData
import rx.schedulers.Timestamped; //导入依赖的package包/类
private void loadData() {
LocationHelper locationHelper = new LocationHelper(this, mGoogleApiClient);
Subscription subscription = locationHelper.getLocation()
.timeout(LOCATION_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.timestamp()
.flatMap(new Func1<Timestamped<Location>, Observable<WeatherData>>() {
@Override
public Observable<WeatherData> call(final Timestamped<Location> timestampedLocation) {
final Location location = timestampedLocation.getValue();
double lat = location.getLatitude();
double lon = location.getLongitude();
return getWeatherForecast(lat, lon);
}
})
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<WeatherData>() {
@Override
public void onCompleted() {
Timber.d("onCompleted()");
}
@Override
public void onError(Throwable e) {
Timber.d("onError: %s", e.getMessage());
hideLoadingIndicator();
}
@Override
public void onNext(WeatherData weatherData) {
updateUi(weatherData);
}
});
mCompositeSubscription.add(subscription);
}
示例15: test_10
import rx.schedulers.Timestamped; //导入依赖的package包/类
@Test
public void test_10() {
Observable.just(1, 2, 3)
.timestamp().subscribe(new Action1<Timestamped<Integer>>() {
@Override
public void call(Timestamped<Integer> integerTimestamped) {
System.out.println(integerTimestamped.toString());
}
});
}