use of io.reactivex.Observable in project RxCache by VictorAlbertos.
the class GetProvidersClass method getMethods.
private List<ProvidersClass.Method> getMethods(Element classElement) throws ValidationException {
List<? extends Element> enclosedElements = classElement.getEnclosedElements();
List<ProvidersClass.Method> methods = new ArrayList<>();
for (Element methodElement : enclosedElements) {
if (!isAnnotatedWithActionable(methodElement))
continue;
if (methodElement.getKind() != ElementKind.METHOD)
continue;
Symbol.MethodSymbol methodSymbol = (Symbol.MethodSymbol) methodElement;
String nameMethod = methodSymbol.getSimpleName().toString();
Type returnType = methodSymbol.getReturnType();
if (!returnType.tsym.toString().equals(TypeName.get(Observable.class).toString())) {
throw new ValidationException(methodSymbol, "Error parsing %s provider. Only Observable<List> type is supported as observable loader", nameMethod);
}
Type enclosingTypeObservable = returnType.getTypeArguments().get(0);
if (!enclosingTypeObservable.tsym.toString().equals(TypeName.get(List.class).toString())) {
throw new ValidationException(methodSymbol, "Error parsing %s provider. Only Observable<List> type is supported as observable loader", nameMethod);
}
List<Symbol.VarSymbol> params = methodSymbol.getParameters();
boolean hasEvictProvider = hasEvictProvider(params);
boolean hasEvictDynamicKey = hasEvictDynamicKey(params);
boolean hasEvictDynamicKeyGroup = hasEvictDynamicKeyGroup(params);
if (!hasEvictProvider && !hasEvictDynamicKey && !hasEvictDynamicKeyGroup) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
if (hasEvictProvider && hasEvictDynamicKey) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
if (hasEvictProvider && hasEvictDynamicKeyGroup) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
if (hasEvictDynamicKey && hasEvictDynamicKeyGroup) {
throw new ValidationException(methodElement, "Error parsing %s provider. The provider requires one evicting argument: EvictProvider, EvictDynamicKey or EvictDynamicKeyGroup", nameMethod);
}
boolean hasDynamicKey = hasDynamicKey(params);
boolean hasDynamicKeyGroup = hasDynamicKeyGroup(params);
methods.add(new ProvidersClass.Method(nameMethod, methodElement, enclosingTypeObservable, hasDynamicKey, hasDynamicKeyGroup));
}
return methods;
}
use of io.reactivex.Observable in project RxCache by VictorAlbertos.
the class ProxyProviders method invoke.
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
return Observable.defer(new Callable<ObservableSource<?>>() {
@Override
public ObservableSource<?> call() throws Exception {
Observable observable = processorProviders.process(proxyTranslator.processMethod(method, args));
Class<?> methodType = method.getReturnType();
if (methodType == Observable.class)
return Observable.just(observable);
if (methodType == Single.class)
return Observable.just(Single.fromObservable(observable));
if (methodType == Maybe.class) {
return Observable.just(Maybe.fromSingle(Single.fromObservable(observable)));
}
if (method.getReturnType() == io.reactivex.Flowable.class) {
return Observable.just(observable.toFlowable(BackpressureStrategy.MISSING));
}
String errorMessage = method.getName() + io.rx_cache2.internal.Locale.INVALID_RETURN_TYPE;
throw new RuntimeException(errorMessage);
}
}).blockingFirst();
}
use of io.reactivex.Observable in project mosby by sockeqwe.
the class MainMenuPresenter method bindIntents.
@Override
protected void bindIntents() {
Observable<List<String>> loadCategories = intent(MainMenuView::loadCategoriesIntent).doOnNext(categoryName -> Timber.d("intent: load category %s", categoryName)).flatMap(ignored -> backendApi.getAllCategories().subscribeOn(Schedulers.io()));
Observable<String> selectCategory = intent(MainMenuView::selectCategoryIntent).doOnNext(categoryName -> Timber.d("intent: select category %s", categoryName)).startWith(MainMenuItem.HOME);
List<Observable<?>> allIntents = new ArrayList<>(2);
allIntents.add(loadCategories);
allIntents.add(selectCategory);
Observable<MenuViewState> menuViewStateObservable = Observable.combineLatest(allIntents, (Function<Object[], MenuViewState>) objects -> {
List<String> categories = (List<String>) objects[0];
String selectedCategory = (String) objects[1];
List<MainMenuItem> categoriesItems = new ArrayList<MainMenuItem>(categories.size() + 1);
categoriesItems.add(new MainMenuItem(MainMenuItem.HOME, selectedCategory.equals(MainMenuItem.HOME)));
for (int i = 0; i < categories.size(); i++) {
String category = categories.get(i);
categoriesItems.add(new MainMenuItem(category, category.equals(selectedCategory)));
}
return new MenuViewState.DataState(categoriesItems);
}).startWith(new MenuViewState.LoadingState()).onErrorReturn(MenuViewState.ErrorState::new).observeOn(AndroidSchedulers.mainThread());
subscribeViewState(menuViewStateObservable, MainMenuView::render);
}
use of io.reactivex.Observable in project nem2-sdk-java by nemtech.
the class AggregateTransactionServiceImpl method isComplete.
@Override
public Observable<Boolean> isComplete(SignedTransaction signedTransaction) {
Validate.notNull(signedTransaction, "signedTransaction is required");
Validate.isTrue(signedTransaction.getType() == TransactionType.AGGREGATE_COMPLETE, "signedTransaction type must be AGGREGATE_COMPLETE");
AggregateTransaction transaction = (AggregateTransaction) BinarySerializationImpl.INSTANCE.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
/*
* Include both initiator & cosigners
*/
Set<Address> signers = transaction.getCosignatures().stream().map(AggregateTransactionCosignature::getSigner).map(PublicAccount::getAddress).collect(Collectors.toSet());
signers.add(signedTransaction.getSigner().getAddress());
return Observable.fromIterable(transaction.getInnerTransactions()).flatMap(innerTransaction -> multisigRepository.getMultisigAccountInfo(innerTransaction.getSigner().orElseThrow(IllegalArgumentException::new).getAddress()).flatMap(multisigAccountInfo -> multisigAccountInfo.getMinRemoval() != 0 && multisigAccountInfo.getMinApproval() != 0 ? multisigRepository.getMultisigAccountGraphInfo(multisigAccountInfo.getAccountAddress()).map(graphInfo -> validateCosignatories(graphInfo, signers, innerTransaction)) : Observable.just(signers.stream().anyMatch(s -> s.equals(multisigAccountInfo.getAccountAddress()))))).all(v -> v).toObservable();
}
use of io.reactivex.Observable in project nem2-sdk-java by nemtech.
the class PaginationStreamerTester method runSearch.
private void runSearch(int pageSize, int totalEntries, Integer limit) {
try {
criteria.setPageSize(pageSize);
List<E> infos = IntStream.range(0, totalEntries).mapToObj((i) -> Mockito.mock(entityClass)).collect(Collectors.toList());
Assertions.assertEquals(totalEntries, infos.size());
List<Observable<Page<E>>> pages = toPages(infos, criteria.getPageSize());
Mockito.when(repository.search(Mockito.eq(criteria))).thenAnswer(new ReturnsElementsOf(pages));
Observable<E> search = streamer.search(criteria);
if (limit != null) {
search = search.take(limit);
}
List<E> returnedInfos = search.toList().toFuture().get();
Assertions.assertEquals(infos.subList(0, limit == null ? infos.size() : limit), returnedInfos);
int totalPagesRead = limit == null ? pages.size() : (int) Math.ceil(limit.doubleValue() / pageSize);
Mockito.verify(repository, Mockito.times(totalPagesRead)).search(Mockito.eq(criteria));
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
Aggregations