Refine search
private void getTags() { RetrofitHelper.getSearchAPI() .getHotSearchTags() .compose(bindToLifecycle()) .map(HotSearchTag::getList) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(listBeans -> { hotSearchTags.addAll(listBeans); initTagLayout(); }, throwable -> { }); }
@Override public void parse(String itemId, String url, Callback callback) { Observable.defer(() -> fromCache(itemId)) .subscribeOn(mIoScheduler) .flatMap(content -> content != null ? Observable.just(content) : fromNetwork(itemId, url)) .map(content -> AndroidUtils.TextUtils.equals(EMPTY_CONTENT, content) ? null : content) .observeOn(mMainThreadScheduler) .subscribe(callback::onResponse); }
@Override protected Observable<Boolean> construct() { return Observable.create(new OnSubscribe<Boolean>() { @Override public void call(Subscriber<? super Boolean> s) { s.onError(new RuntimeException("onError")); } }).subscribeOn(userScheduler); }
@Override public Observable<Bucket> call() { return inputEventStream .observe() .window(bucketSizeInMs, TimeUnit.MILLISECONDS) //bucket it by the counter window so we can emit to the next operator in time chunks, not on every OnNext .flatMap(reduceBucketToSummary) //for a given bucket, turn it into a long array containing counts of event types .startWith(emptyEventCountsToStart); //start it with empty arrays to make consumer logic as generic as possible (windows are always full) } });
@Override public void login(String username, String password, boolean createAccount, Callback callback) { execute(postLogin(username, password, createAccount)) .flatMap(response -> { if (response.code() == HttpURLConnection.HTTP_OK) { return Observable.error(new UserServices.Exception(parseLoginError(response))); } return Observable.just(response.code() == HttpURLConnection.HTTP_MOVED_TEMP); }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); }
private void setQRCode(String content) { Observable.just(QRCodeEncoder.syncEncodeQRCode(content, UIUtils.dip2Px(100))) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(bitmap -> mIvCard.setImageBitmap(bitmap), this::loadQRCardError); }
public void downloadFile(View view) { subscription = getObservable() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(getObserver()); } }
@VisibleForTesting OnSubscribe<Message> getOnSubscribe() { return subscriber -> { Observable<Long> interval = Observable.interval(pollTimeInMS, TimeUnit.MILLISECONDS); interval.flatMap((Long x)->{ List<Message> msgs = receiveMessages(); return Observable.from(msgs); }).subscribe(subscriber::onNext, subscriber::onError); }; }
@Override public Observable<ServiceResponse<Page<SubscriptionInner>>> call(ServiceResponse<Page<SubscriptionInner>> page) { String nextPageLink = page.body().nextPageLink(); if (nextPageLink == null) { return Observable.just(page); } return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); } });
/** * 获取福利图片 * @return */ public static Observable<WelfarePhotoInfo> getWelfarePhoto(int page) { return sWelfareService.getWelfarePhoto(page) .subscribeOn(Schedulers.io()) .unsubscribeOn(Schedulers.io()) .subscribeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread()) .flatMap(_flatMapWelfarePhotos()); }
public void startCachingStreamValuesIfUnstarted() { if (rollingDistributionSubscription.get() == null) { //the stream is not yet started Subscription candidateSubscription = observe().subscribe(rollingDistribution); if (rollingDistributionSubscription.compareAndSet(null, candidateSubscription)) { //won the race to set the subscription } else { //lost the race to set the subscription, so we need to cancel this one candidateSubscription.unsubscribe(); } } }
@Override protected Observable<Integer> construct() { return Observable.just(1, 2, 3) .concatWith(Observable.<Integer> error(new RuntimeException("forced error"))) .subscribeOn(Schedulers.computation()); }
@Test public void noEvents() throws InterruptedException { CountDownLatch commandLatch = new CountDownLatch(1); CountDownLatch threadPoolLatch = new CountDownLatch(1); Subscriber<HystrixCommandCompletion> commandSubscriber = getLatchedSubscriber(commandLatch); readCommandStream.observe().take(1).subscribe(commandSubscriber); Subscriber<HystrixCommandCompletion> threadPoolSubscriber = getLatchedSubscriber(threadPoolLatch); readThreadPoolStream.observe().take(1).subscribe(threadPoolSubscriber); //no writes assertFalse(commandLatch.await(1000, TimeUnit.MILLISECONDS)); assertFalse(threadPoolLatch.await(1000, TimeUnit.MILLISECONDS)); }
private List<MarkedEdge> createConnectionSearchEdges( final Entity testEntity, final GraphManager graphManager, final int edgeCount ) { final List<MarkedEdge> connectionSearchEdges = Observable.range( 0, edgeCount ).flatMap( integer -> { //create our connection edge. final Id connectingId = createId( "connecting" ); final Edge connectionEdge = CpNamingUtils.createConnectionEdge( connectingId, "likes", testEntity.getId() ); return graphManager.writeEdge( connectionEdge ).subscribeOn( Schedulers.io() ); }, 20).toList().toBlocking().last(); assertEquals( "All edges saved", edgeCount, connectionSearchEdges.size() ); return connectionSearchEdges; }
@Override protected Observable<String> construct() { executed = true; return Observable.just(value).delay(duration, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()) .doOnNext(new Action1<String>() { @Override public void call(String t1) { System.out.println("successfully executed"); } }); }
/** * Gets the specified resource provider. * * @param resourceProviderNamespace The namespace of the resource provider. * @throws IllegalArgumentException thrown if parameters fail the validation * @throws CloudException thrown if the request is rejected by server * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent * @return the ProviderInner object if successful. */ public ProviderInner get(String resourceProviderNamespace) { return getWithServiceResponseAsync(resourceProviderNamespace).toBlocking().single().body(); }