.doOnSuccess(fbData -> increment(fbClient.getServerGroupName(), _cacheName, "RETRY_" + ((fbData == null) ? "MISS" : "HIT"))) .toObservable())) .firstOrDefault(null, fbData -> (fbData != null)).toSingle();
.doOnSuccess(fbData -> increment(fbClient.getServerGroupName(), _cacheName, "RETRY_" + ((fbData == null) ? "MISS" : "HIT"))) .toObservable())) .firstOrDefault(null, fbData -> (fbData != null)).toSingle();
@Override public void run() { Observable.range(1, 10).firstOrDefault(3).subscribe(new Action1<Integer>() { @Override public void call(Integer integer) { log(integer); } }); } });
@Override public Single<String> getContent(final EventTypeCursor cursor) { final Observable<HttpResponseChunk> request = getContent0(cursor, 1); return request.map(HttpResponseChunk::getContent).firstOrDefault(null).toSingle(); }
/** * Retrieves encryption extension installed in the virtual machine, if the extension is * not installed then return an empty observable. * * @return an observable that emits the encryption extension installed in the virtual machine */ private Observable<VirtualMachineExtension> getEncryptionExtensionInstalledInVMAsync() { return virtualMachine.listExtensionsAsync() // firstOrDefault() is used intentionally here instead of first() to ensure // this method return empty observable if matching extension is not found. // .firstOrDefault(null, new Func1<VirtualMachineExtension, Boolean>() { @Override public Boolean call(final VirtualMachineExtension extension) { return extension.publisherName().equalsIgnoreCase(encryptionExtensionPublisher) && extension.typeName().equalsIgnoreCase(encryptionExtensionType()); } }).flatMap(new Func1<VirtualMachineExtension, Observable<VirtualMachineExtension>>() { @Override public Observable<VirtualMachineExtension> call(VirtualMachineExtension extension) { if (extension == null) { return Observable.empty(); } return Observable.just(extension); } }); }
/** * Returns the first item emitted by this {@code BlockingObservable} that matches a predicate, or a default * value if it emits no such items. * * @param defaultValue * a default value to return if this {@code BlockingObservable} emits no matching items * @param predicate * a predicate function to evaluate items emitted by this {@code BlockingObservable} * @return the first item emitted by this {@code BlockingObservable} that matches the predicate, or the * default value if this {@code BlockingObservable} emits no matching items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#first-and-firstordefault">RxJava Wiki: firstOrDefault()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/hh229759.aspx">MSDN: Observable.FirstOrDefault</a> */ public T firstOrDefault(T defaultValue, Func1<? super T, Boolean> predicate) { return blockForSingle(o.filter(predicate).map(Functions.<T>identity()).firstOrDefault(defaultValue)); }
/** * Returns the first item emitted by this {@code BlockingObservable}, or a default value if it emits no * items. * * @param defaultValue * a default value to return if this {@code BlockingObservable} emits no items * @return the first item emitted by this {@code BlockingObservable}, or the default value if it emits no * items * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Blocking-Observable-Operators#first-and-firstordefault">RxJava Wiki: firstOrDefault()</a> * @see <a href="http://msdn.microsoft.com/en-us/library/hh229320.aspx">MSDN: Observable.FirstOrDefault</a> */ public T firstOrDefault(T defaultValue) { return blockForSingle(o.map(Functions.<T>identity()).firstOrDefault(defaultValue)); }
/** * Retrieves encryption extension installed in the virtual machine, if the extension is * not installed then return an empty observable. * * @return an observable that emits the encryption extension installed in the virtual machine */ private Observable<VirtualMachineExtension> getEncryptionExtensionInstalledInVMAsync() { return virtualMachine.listExtensionsAsync() // firstOrDefault() is used intentionally here instead of first() to ensure // this method return empty observable if matching extension is not found. // .firstOrDefault(null, new Func1<VirtualMachineExtension, Boolean>() { @Override public Boolean call(final VirtualMachineExtension extension) { return extension.publisherName().equalsIgnoreCase(encryptionExtensionPublisher) && extension.typeName().equalsIgnoreCase(encryptionExtensionType()); } }).flatMap(new Func1<VirtualMachineExtension, Observable<VirtualMachineExtension>>() { @Override public Observable<VirtualMachineExtension> call(VirtualMachineExtension extension) { if (extension == null) { return Observable.empty(); } return Observable.just(extension); } }); }
@Override public Single<String> getEvent(final EventTypeCursor cursor) { final Observable<HttpResponseChunk> request = getContent0(cursor, 1); return request.map(chunk -> getEvent0(chunk.getContent(), cursor.getEventType())).firstOrDefault(null) .toSingle(); }
@Override public Single<List<NakadiPartition>> getPartitions(final EventType eventType) { final HttpGetPartitions httpGetPartitions = new HttpGetPartitions(nakadiUrl, eventType); final Observable<HttpResponseChunk> request = new RxHttpRequest(partitionsTimeoutMillis, authorizationValueProvider).createRequest(httpGetPartitions); return request.filter(chunk -> { checkArgument(chunk.getStatusCode() == 200, "Get partitions for event [%s] , result [%s / %s]", eventType, chunk.getStatusCode(), chunk.getContent()); return true; }).map(chunk -> getPartitions(chunk.getContent())).firstOrDefault(Collections.emptyList()) .toSingle(); }
.getFromReplica(id, ReplicaMode.ALL, target) .timeout(replicaTimeout, TimeUnit.MILLISECONDS) .firstOrDefault(null) .filter(new Func1<D, Boolean>() { @Override
.observeOn(uiScheduler) .firstOrDefault(defaultList, items -> items != null && !items.isEmpty()) .subscribe(subscriber);