rx.functions.Func2 Java Examples

The following examples show how to use rx.functions.Func2. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PartitionKeyInternalTest.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
/**
 * Tests {@link PartitionKeyInternal#contains(PartitionKeyInternal)} method.
 */
@Test(groups="unit")
public void contains() {
    Func2<String, String, Boolean> verifyContains = (parentPartitionKey, childPartitionKey) ->
            PartitionKeyInternal.fromJsonString(parentPartitionKey)
                    .contains(PartitionKeyInternal.fromJsonString(childPartitionKey));

    assertThat(verifyContains.call("[]", "[]")).isTrue();
    assertThat(verifyContains.call("[]", "[{}]")).isTrue();
    assertThat(verifyContains.call("[]", "[null]")).isTrue();
    assertThat(verifyContains.call("[]", "[true]")).isTrue();
    assertThat(verifyContains.call("[]", "[false]")).isTrue();
    assertThat(verifyContains.call("[]", "[2]")).isTrue();
    assertThat(verifyContains.call("[]", "[\"fdfd\"]")).isTrue();

    assertThat(verifyContains.call("[2]", "[]")).isFalse();
    assertThat(verifyContains.call("[2]", "[2]")).isTrue();
    assertThat(verifyContains.call("[2]", "[2, \"USA\"]")).isTrue();
    assertThat(verifyContains.call("[1]", "[2, \"USA\"]")).isFalse();
}
 
Example #2
Source File: RingtoneHelper.java    From android with Apache License 2.0 6 votes vote down vote up
public Observable<List<Tone>> getToneList() {
    return getInternalMediaList()
            .mergeWith(getExternalMediaList())
            .flatMapIterable(new Func1<List<Tone>, Iterable<Tone>>() {
                @Override
                public Iterable<Tone> call(List<Tone> tones) {
                    return tones;
                }
            })
            .toSortedList(new Func2<Tone, Tone, Integer>() {
                @Override
                public Integer call(Tone x, Tone y) {
                    return x.getName().compareTo(y.getName());
                }
            });
}
 
Example #3
Source File: ServerSentEventRequestHandler.java    From mantis with Apache License 2.0 6 votes vote down vote up
public ServerSentEventRequestHandler(Observable<T> observableToServe,
                              Func1<T, String> encoder,
                              Func1<Throwable, String> errorEncoder,
                              Predicate<T> predicate,
                              Func2<Map<String, List<String>>, Context, Void> requestPreprocessor,
                              Func2<Map<String, List<String>>, Context, Void> requestPostprocessor,
                              Context context,
                              int batchInterval) {
    this.observableToServe = observableToServe;
    this.encoder = encoder;
    this.errorEncoder = errorEncoder;
    this.predicate = predicate;
    this.requestPreprocessor = requestPreprocessor;
    this.requestPostprocessor = requestPostprocessor;
    this.context = context;
    this.flushIntervalMillis = batchInterval;
}
 
Example #4
Source File: StageExecutors.java    From mantis with Apache License 2.0 6 votes vote down vote up
/**
 * @param go
 * @param computation
 *
 * @return untyped to support multiple callers return types
 */
@SuppressWarnings("unchecked")
private static <K, T, R> Observable<Observable<R>> executeMantisGroupsInParallel(Observable<Observable<MantisGroup<K, T>>> go, Computation computation,
                                                                                 final Context context, final boolean applyTimeoutToInners, final long timeout) {
    logger.info("initializing {}", computation.getClass().getCanonicalName());
    computation.init(context);

    // from groups to observable
    final Func2<Context, Observable<MantisGroup<K, T>>, Observable<R>> c
            = (Func2<Context, Observable<MantisGroup<K, T>>, Observable<R>>) computation;

    return
            go
                    .lift(new MonitorOperator<>("worker_stage_outer"))
                    .map(observable -> c
                            .call(context, observable
                                    .subscribeOn(Schedulers.computation())
                                    .lift(new MonitorOperator<MantisGroup<K, T>>("worker_stage_inner_input")))
                            .lift(new MonitorOperator<R>("worker_stage_inner_output")));
}
 
Example #5
Source File: RetryWhenNetworkException.java    From RxjavaRetrofitDemo-master with MIT License 6 votes vote down vote up
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
    return observable
            .zipWith(Observable.range(1, count + 1), new Func2<Throwable, Integer, Wrapper>() {
                @Override
                public Wrapper call(Throwable throwable, Integer integer) {
                    return new Wrapper(throwable, integer);
                }
            }).flatMap(new Func1<Wrapper, Observable<?>>() {
                @Override
                public Observable<?> call(Wrapper wrapper) {
                    if ((wrapper.throwable instanceof ConnectException
                            || wrapper.throwable instanceof SocketTimeoutException
                            || wrapper.throwable instanceof TimeoutException)
                            && wrapper.index < count + 1) { //如果超出重试次数也抛出错误,否则默认是会进入onCompleted
                        return Observable.timer(delay + (wrapper.index - 1) * increaseDelay, TimeUnit.MILLISECONDS);

                    }
                    return Observable.error(wrapper.throwable);
                }
            });
}
 
Example #6
Source File: RetryWhenNetworkException.java    From Bailan with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
    return observable
            .zipWith(Observable.range(1, count + 1), new Func2<Throwable, Integer, Wrapper>() {
                @Override
                public Wrapper call(Throwable throwable, Integer integer) {
                    //压缩规则 合并后的结果是一个Observable<Wrapper>
                    return new Wrapper(throwable, integer);
                }
            }).flatMap(new Func1<Wrapper, Observable<?>>() {
                @Override
                public Observable<?> call(Wrapper wrapper) {
                    //转换规则
                    if ((wrapper.throwable instanceof ConnectException
                            || wrapper.throwable instanceof SocketTimeoutException
                            || wrapper.throwable instanceof TimeoutException)
                            && wrapper.index < count + 1) { //如果超出重试次数也抛出错误,否则默认是会进入onCompleted
                        return Observable.timer(delay + (wrapper.index - 1) * increaseDelay, TimeUnit.MILLISECONDS);

                    }
                    return Observable.error(wrapper.throwable);
                }
            });
}
 
Example #7
Source File: HttpSourceImpl.java    From mantis with Apache License 2.0 6 votes vote down vote up
public Builder(
        HttpClientFactory<R, E> clientFactory,
        HttpRequestFactory<R> requestFactory,
        Func2<ServerContext<HttpClientResponse<E>>, E, T> postProcessor
) {
    this.requestFactory = requestFactory;
    this.httpClientFactory = clientFactory;
    this.serverProvider = EMPTY_HTTP_SERVER_PROVIDER;
    this.postProcessor = postProcessor;

    // Do not resume by default
    this.clientResumePolicy = new ClientResumePolicy<R, E>() {
        @Override
        public Observable<HttpClientResponse<E>> onError(ServerClientContext<R, E> clientContext, int attempts, Throwable error) {
            return null;
        }

        @Override
        public Observable<HttpClientResponse<E>> onCompleted(ServerClientContext<R, E> clientContext, int attempts) {
            return null;
        }
    };

    //			this.clientResumePolicy = ClientResumePolicies.maxRepeat(9);
    observer = PublishSubject.create();
}
 
Example #8
Source File: RetryWhenNetworkException.java    From RxjavaRetrofitDemo-string-master with MIT License 6 votes vote down vote up
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
    return observable
            .zipWith(Observable.range(1, count + 1), new Func2<Throwable, Integer, Wrapper>() {
                @Override
                public Wrapper call(Throwable throwable, Integer integer) {
                    return new Wrapper(throwable, integer);
                }
            }).flatMap(new Func1<Wrapper, Observable<?>>() {
                @Override
                public Observable<?> call(Wrapper wrapper) {
                    if ((wrapper.throwable instanceof ConnectException
                            || wrapper.throwable instanceof SocketTimeoutException
                            || wrapper.throwable instanceof TimeoutException)
                            && wrapper.index < count + 1) { //如果超出重试次数也抛出错误,否则默认是会进入onCompleted
                        return Observable.timer(delay + (wrapper.index - 1) * increaseDelay, TimeUnit.MILLISECONDS);

                    }
                    return Observable.error(wrapper.throwable);
                }
            });
}
 
Example #9
Source File: WebAppBaseImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public Observable<Map<String, AppSetting>> getAppSettingsAsync() {
    return Observable.zip(listAppSettings(), listSlotConfigurations(), new Func2<StringDictionaryInner, SlotConfigNamesResourceInner, Map<String, AppSetting>>() {
        @Override
        public Map<String, AppSetting> call(final StringDictionaryInner appSettingsInner, final SlotConfigNamesResourceInner slotConfigs) {
            if (appSettingsInner == null || appSettingsInner.properties() == null) {
                return null;
            }
            return Maps.asMap(appSettingsInner.properties().keySet(), new Function<String, AppSetting>() {
                @Override
                public AppSetting apply(String input) {
                    return new AppSettingImpl(input, appSettingsInner.properties().get(input),
                            slotConfigs != null && slotConfigs.appSettingNames() != null && slotConfigs.appSettingNames().contains(input));
                }
            });
        }
    });
}
 
Example #10
Source File: DeploymentSlotsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public Observable<DeploymentSlot> getByParentAsync(final String resourceGroup, final String parentName, final String name) {
    return innerCollection.getSlotAsync(resourceGroup, parentName, name).flatMap(new Func1<SiteInner, Observable<DeploymentSlot>>() {
        @Override
        public Observable<DeploymentSlot> call(final SiteInner siteInner) {
            if (siteInner == null) {
                return null;
            }
            return Observable.zip(
                    innerCollection.getConfigurationSlotAsync(resourceGroup, parentName, name),
                    innerCollection.getDiagnosticLogsConfigurationSlotAsync(resourceGroup, parentName, name),
                    new Func2<SiteConfigResourceInner, SiteLogsConfigInner, DeploymentSlot>() {
                        @Override
                        public DeploymentSlot call(SiteConfigResourceInner siteConfigResourceInner, SiteLogsConfigInner logsConfigInner) {
                            return wrapModel(siteInner, siteConfigResourceInner, logsConfigInner);
                        }
                    });
        }
    });
}
 
Example #11
Source File: GoogleSearchController.java    From FloatingSearchView with Apache License 2.0 6 votes vote down vote up
private Observable<SearchResult[]> getQueryObservable(String query) {
    return mSearch.search(query)
            .flatMap(new Func1<Response, Observable<SearchResult[]>>() {
                @Override
                public Observable<SearchResult[]> call(Response response) {
                    if (response.responseData == null)
                        return Observable.error(new SearchException(response.responseDetails));
                    return Observable.just(response.responseData.results);
                }
            })
            .retry(new Func2<Integer, Throwable, Boolean>() {
                @Override
                public Boolean call(Integer integer, Throwable throwable) {
                    return throwable instanceof InterruptedIOException;
                }
            });
}
 
Example #12
Source File: DeploymentSlotsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
DeploymentSlotsImpl(final WebAppImpl parent) {
    super(parent.manager().inner().webApps(), parent.manager());

    this.parent = parent;
    final WebAppsInner innerCollection = this.inner();
    converter = new PagedListConverter<SiteInner, DeploymentSlot>() {
        @Override
        public Observable<DeploymentSlot> typeConvertAsync(final SiteInner siteInner) {
            return Observable.zip(
                    innerCollection.getConfigurationSlotAsync(siteInner.resourceGroup(), parent.name(), siteInner.name()),
                    innerCollection.getDiagnosticLogsConfigurationSlotAsync(siteInner.resourceGroup(), parent.name(), siteInner.name()),
                    new Func2<SiteConfigResourceInner, SiteLogsConfigInner, DeploymentSlot>() {
                        @Override
                        public DeploymentSlot call(SiteConfigResourceInner siteConfigResourceInner, SiteLogsConfigInner logsConfigInner) {
                            return wrapModel(siteInner, siteConfigResourceInner, logsConfigInner);
                        }
                    });
        }
    };
}
 
Example #13
Source File: WebAppsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public Observable<WebApp> getByResourceGroupAsync(final String groupName, final String name) {
    final WebAppsImpl self = this;
    return this.inner().getByResourceGroupAsync(groupName, name).flatMap(new Func1<SiteInner, Observable<WebApp>>() {
        @Override
        public Observable<WebApp> call(final SiteInner siteInner) {
            if (siteInner == null) {
                return Observable.just(null);
            }
            return Observable.zip(
                    self.inner().getConfigurationAsync(groupName, name),
                    self.inner().getDiagnosticLogsConfigurationAsync(groupName, name),
                    new Func2<SiteConfigResourceInner, SiteLogsConfigInner, WebApp>() {
                        @Override
                        public WebApp call(SiteConfigResourceInner siteConfigResourceInner, SiteLogsConfigInner logsConfigInner) {
                            return wrapModel(siteInner, siteConfigResourceInner, logsConfigInner);
                        }
                    });
        }
    });

}
 
Example #14
Source File: DocumentProducer.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
public Observable<DocumentProducerFeedResponse> produceAsync() {
    Func2<String, Integer, RxDocumentServiceRequest> sourcePartitionCreateRequestFunc =
            (token, maxItemCount) -> createRequestFunc.call(targetRange, token, maxItemCount);
    Observable<FeedResponse<T>> obs = Paginator
            .getPaginatedQueryResultAsObservable(
                    feedOptions, 
                    sourcePartitionCreateRequestFunc,
                    executeRequestFuncWithRetries, 
                    resourceType, 
                    top, 
                    pageSize)
            .map(rsp -> {
                lastResponseContinuationToken = rsp.getResponseContinuation();
                this.fetchExecutionRangeAccumulator.endFetchRange(rsp.getActivityId(),
                        rsp.getResults().size(),
                        this.retries);
                this.fetchSchedulingMetrics.stop();
                return rsp;});
    
    return splitProof(obs.map(page -> new DocumentProducerFeedResponse(page)));
}
 
Example #15
Source File: StageExecutors.java    From mantis with Apache License 2.0 6 votes vote down vote up
/**
 * @param oo
 * @param computation
 *
 * @return untyped to support multiple callers return types
 */
@SuppressWarnings("unchecked")
private static <T, R> Observable<Observable<R>> executeInners(Observable<Observable<T>> oo, Computation computation,
                                                              final Context context, final boolean applyTimeoutToInners, final long timeout) {
    logger.info("initializing {}", computation.getClass().getCanonicalName());
    computation.init(context);

    // from groups to observable
    final Func2<Context, Observable<T>, Observable<R>> c
            = (Func2<Context, Observable<T>, Observable<R>>) computation;

    return
            oo
                    .lift(new MonitorOperator<>("worker_stage_outer"))
                    .map(observable -> c
                            .call(context, observable
                                    .lift(new MonitorOperator<T>("worker_stage_inner_input")))
                            .lift(new MonitorOperator<R>("worker_stage_inner_output")));
}
 
Example #16
Source File: RetryWhenNetworkException.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
    return observable
            .zipWith(Observable.range(1, count + 1), new Func2<Throwable, Integer, Wrapper>() {
                @Override
                public Wrapper call(Throwable throwable, Integer integer) {
                    return new Wrapper(throwable, integer);
                }
            }).flatMap((Func1<Wrapper, Observable<?>>) wrapper -> {
                if ((wrapper.throwable instanceof ConnectException
                        || wrapper.throwable instanceof SocketTimeoutException
                        || wrapper.throwable instanceof TimeoutException)
                        && wrapper.index < count + 1) { //如果超出重试次数也抛出错误,否则默认是会进入onCompleted
                    Log.e("tag", "retry---->" + wrapper.index);
                    return Observable.timer(delay + (wrapper.index - 1) * increaseDelay, TimeUnit.MILLISECONDS);
                }
                return Observable.error(wrapper.throwable);
            });
}
 
Example #17
Source File: RetryWhenNetworkException.java    From Bailan with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
    return observable
            .zipWith(Observable.range(1, count + 1), new Func2<Throwable, Integer, Wrapper>() {
                @Override
                public Wrapper call(Throwable throwable, Integer integer) {
                    //压缩规则 合并后的结果是一个Observable<Wrapper>
                    return new Wrapper(throwable, integer);
                }
            }).flatMap(new Func1<Wrapper, Observable<?>>() {
                @Override
                public Observable<?> call(Wrapper wrapper) {
                    //转换规则
                    if ((wrapper.throwable instanceof ConnectException
                            || wrapper.throwable instanceof SocketTimeoutException
                            || wrapper.throwable instanceof TimeoutException)
                            && wrapper.index < count + 1) { //如果超出重试次数也抛出错误,否则默认是会进入onCompleted
                        return Observable.timer(delay + (wrapper.index - 1) * increaseDelay, TimeUnit.MILLISECONDS);

                    }
                    return Observable.error(wrapper.throwable);
                }
            });
}
 
Example #18
Source File: RxDocumentClientImpl.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
private <T extends Resource> Observable<FeedResponse<T>> readFeed(FeedOptions options, ResourceType resourceType, Class<T> klass, String resourceLink) {
    if (options == null) {
        options = new FeedOptions();
    }

    int maxPageSize = options.getMaxItemCount() != null ? options.getMaxItemCount() : -1;
    final FeedOptions finalFeedOptions = options;
    Func2<String, Integer, RxDocumentServiceRequest> createRequestFunc = (continuationToken, pageSize) -> {
        Map<String, String> requestHeaders = new HashMap<>();
        if (continuationToken != null) {
            requestHeaders.put(HttpConstants.HttpHeaders.CONTINUATION, continuationToken);
        }
        requestHeaders.put(HttpConstants.HttpHeaders.PAGE_SIZE, Integer.toString(pageSize));
        RxDocumentServiceRequest request =  RxDocumentServiceRequest.create(OperationType.ReadFeed,
                resourceType, resourceLink, requestHeaders, finalFeedOptions);
        return request;
    };

    Func1<RxDocumentServiceRequest, Observable<FeedResponse<T>>> executeFunc = request -> {
        return ObservableHelper.inlineIfPossibleAsObs(() -> readFeed(request).map(response -> toFeedResponsePage(response, klass)),
                this.resetSessionTokenRetryPolicy.getRequestPolicy());
    };

    return Paginator.getPaginatedQueryResultAsObservable(options, createRequestFunc, executeFunc, klass, maxPageSize);
}
 
Example #19
Source File: RetryWhenNetworkException.java    From RxRetrofit-mvp with MIT License 6 votes vote down vote up
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
    return observable
            .zipWith(Observable.range(1, count + 1), new Func2<Throwable, Integer, Wrapper>() {
                @Override
                public Wrapper call(Throwable throwable, Integer integer) {
                    return new Wrapper(throwable, integer);
                }
            }).flatMap(new Func1<Wrapper, Observable<?>>() {
                @Override
                public Observable<?> call(Wrapper wrapper) {
                    if ((wrapper.throwable instanceof ConnectException
                            || wrapper.throwable instanceof SocketTimeoutException
                            || wrapper.throwable instanceof TimeoutException)
                            && wrapper.index < count + 1) { //如果超出重试次数也抛出错误,否则默认是会进入onCompleted
                        return Observable.timer(delay + (wrapper.index - 1) * increaseDelay, TimeUnit.MILLISECONDS);

                    }
                    return Observable.error(wrapper.throwable);
                }
            });
}
 
Example #20
Source File: FunctionDeploymentSlotsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
FunctionDeploymentSlotsImpl(final FunctionAppImpl parent) {
    super(parent.manager().inner().webApps(), parent.manager());

    this.parent = parent;
    final WebAppsInner innerCollection = this.inner();
    converter = new PagedListConverter<SiteInner, FunctionDeploymentSlot>() {
        @Override
        public Observable<FunctionDeploymentSlot> typeConvertAsync(final SiteInner siteInner) {
            return Observable.zip(
                    innerCollection.getConfigurationSlotAsync(siteInner.resourceGroup(), parent.name(), siteInner.name()),
                    innerCollection.getDiagnosticLogsConfigurationSlotAsync(siteInner.resourceGroup(), parent.name(), siteInner.name()),
                    new Func2<SiteConfigResourceInner, SiteLogsConfigInner, FunctionDeploymentSlot>() {
                        @Override
                        public FunctionDeploymentSlot call(SiteConfigResourceInner siteConfigResourceInner, SiteLogsConfigInner logsConfigInner) {
                            return wrapModel(siteInner, siteConfigResourceInner, logsConfigInner);
                        }
                    });
        }
    };
}
 
Example #21
Source File: FunctionDeploymentSlotsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public Observable<FunctionDeploymentSlot> getByParentAsync(final String resourceGroup, final String parentName, final String name) {
    return innerCollection.getSlotAsync(resourceGroup, parentName, name).flatMap(new Func1<SiteInner, Observable<FunctionDeploymentSlot>>() {
        @Override
        public Observable<FunctionDeploymentSlot> call(final SiteInner siteInner) {
            if (siteInner == null) {
                return null;
            }
            return Observable.zip(
                    innerCollection.getConfigurationSlotAsync(resourceGroup, parentName, name),
                    innerCollection.getDiagnosticLogsConfigurationSlotAsync(resourceGroup, parentName, name),
                    new Func2<SiteConfigResourceInner, SiteLogsConfigInner, FunctionDeploymentSlot>() {
                        @Override
                        public FunctionDeploymentSlot call(SiteConfigResourceInner siteConfigResourceInner, SiteLogsConfigInner logsConfigInner) {
                            return wrapModel(siteInner, siteConfigResourceInner, logsConfigInner);
                        }
                    });
        }
    });
}
 
Example #22
Source File: FunctionAppsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
FunctionAppsImpl(final AppServiceManager manager) {
    super(manager.inner().webApps(), manager);
    converter = new PagedListConverter<SiteInner, FunctionApp>() {
        @Override
        public Observable<FunctionApp> typeConvertAsync(final SiteInner siteInner) {
            return Observable.zip(
                    manager().inner().webApps().getConfigurationAsync(siteInner.resourceGroup(), siteInner.name()),
                    manager().inner().webApps().getDiagnosticLogsConfigurationAsync(siteInner.resourceGroup(), siteInner.name()),
                    new Func2<SiteConfigResourceInner, SiteLogsConfigInner, FunctionApp>() {
                        @Override
                        public FunctionApp call(SiteConfigResourceInner siteConfigResourceInner, SiteLogsConfigInner logsConfigInner) {
                            return wrapModel(siteInner, siteConfigResourceInner, logsConfigInner);
                        }
                    });
        }

        @Override
        protected boolean filter(SiteInner inner) {
            return inner.kind() != null && Arrays.asList(inner.kind().split(",")).contains("functionapp");
        }
    };
}
 
Example #23
Source File: RetryWhenNetworkException.java    From Rx-Retrofit with MIT License 6 votes vote down vote up
@Override
public Observable<?> call(Observable<? extends Throwable> observable) {
    return observable
            .zipWith(Observable.range(1, count + 1), new Func2<Throwable, Integer, Wrapper>() {
                @Override
                public Wrapper call(Throwable throwable, Integer integer) {
                    return new Wrapper(throwable, integer);
                }
            }).flatMap(new Func1<Wrapper, Observable<?>>() {
                @Override
                public Observable<?> call(Wrapper wrapper) {
                    if ((wrapper.throwable instanceof ConnectException
                            || wrapper.throwable instanceof SocketTimeoutException
                            || wrapper.throwable instanceof TimeoutException)
                            && wrapper.index < count + 1) { //如果超出重试次数也抛出错误,否则默认是会进入onCompleted
                        return Observable.timer(delay + (wrapper.index - 1) * increaseDelay, TimeUnit.MILLISECONDS);

                    }
                    return Observable.error(wrapper.throwable);
                }
            });
}
 
Example #24
Source File: Fetcher.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
public Fetcher(Func2<String, Integer, RxDocumentServiceRequest> createRequestFunc,
               Func1<RxDocumentServiceRequest, Observable<FeedResponse<T>>> executeFunc,
               FeedOptionsBase options,
               boolean isChangeFeed,
               int top,
               int maxItemCount) {

    this.createRequestFunc = createRequestFunc;
    this.executeFunc = executeFunc;
    this.isChangeFeed = isChangeFeed;

    this.continuationToken = options.getRequestContinuation();
    this.top = top;
    if (top == -1) {
        this.maxItemCount = maxItemCount;
    } else {
        // it is a top query, we should not retrieve more than requested top.
        this.maxItemCount = Math.min(maxItemCount, top);
    }
    this.shouldFetchMore = true;
}
 
Example #25
Source File: FunctionAppsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public Observable<FunctionApp> getByResourceGroupAsync(final String groupName, final String name) {
    final FunctionAppsImpl self = this;
    return this.inner().getByResourceGroupAsync(groupName, name).flatMap(new Func1<SiteInner, Observable<FunctionApp>>() {
        @Override
        public Observable<FunctionApp> call(final SiteInner siteInner) {
            if (siteInner == null) {
                return Observable.just(null);
            }
            return Observable.zip(
                    self.inner().getConfigurationAsync(groupName, name),
                    self.inner().getDiagnosticLogsConfigurationAsync(groupName, name),
                    new Func2<SiteConfigResourceInner, SiteLogsConfigInner, FunctionApp>() {
                        @Override
                        public FunctionApp call(SiteConfigResourceInner siteConfigResourceInner, SiteLogsConfigInner logsConfigInner) {
                            return wrapModel(siteInner, siteConfigResourceInner, logsConfigInner);
                        }
                    });
        }
    });
}
 
Example #26
Source File: WebAppsImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
WebAppsImpl(final AppServiceManager manager) {
    super(manager.inner().webApps(), manager);
    converter = new PagedListConverter<SiteInner, WebApp>() {
        @Override
        protected boolean filter(SiteInner inner) {
            return inner.kind() == null || Arrays.asList(inner.kind().split(",")).contains("app");
        }

        @Override
        public Observable<WebApp> typeConvertAsync(final SiteInner siteInner) {
            return Observable.zip(
                    manager().inner().webApps().getConfigurationAsync(siteInner.resourceGroup(), siteInner.name()),
                    manager().inner().webApps().getDiagnosticLogsConfigurationAsync(siteInner.resourceGroup(), siteInner.name()),
                    new Func2<SiteConfigResourceInner, SiteLogsConfigInner, WebApp>() {
                        @Override
                        public WebApp call(SiteConfigResourceInner siteConfigResourceInner, SiteLogsConfigInner logsConfigInner) {
                            return wrapModel(siteInner, siteConfigResourceInner, logsConfigInner);
                        }
                    });
        }
    };
}
 
Example #27
Source File: ChatHelper.java    From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Func2<Void, ArrayList<QBUser>, ArrayList<QBUser>> mergeResult() {
    return new Func2<Void, ArrayList<QBUser>, ArrayList<QBUser>>() {
        @Override
        public ArrayList<QBUser> call(Void aVoid, ArrayList<QBUser> qbUsers) {
            return qbUsers;
        }
    };
}
 
Example #28
Source File: RTree.java    From rtree-3d with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Observable sequence of trees created by progressively adding
 * entries.
 * 
 * @param entries
 *            the entries to add
 * @return a sequence of trees
 */
public Observable<RTree<T, S>> add(Observable<Entry<T, S>> entries) {
    return entries.scan(this, new Func2<RTree<T, S>, Entry<T, S>, RTree<T, S>>() {

        @Override
        public RTree<T, S> call(RTree<T, S> tree, Entry<T, S> entry) {
            return tree.add(entry);
        }
    });
}
 
Example #29
Source File: DefaultChannelFactory.java    From rxrabbit with MIT License 5 votes vote down vote up
private synchronized ChannelWrapper createChannel(ChannelType type, Func2<Integer, Channel, ChannelImpl> channelFunction) throws IOException {
    Channel innerChannel = getOrCreateConnection(type).createChannel();
    ConnectionInfo info = conToChannel.get(type);
    ChannelImpl channel = channelFunction.call(innerChannel.hashCode(), innerChannel);
    info.channels.add(channel);
    log.infoWithParams("Successfully created "+type+" channel.",
            "channel", channel,
            "properties", info.clientProperties);
    return channel;
}
 
Example #30
Source File: RTree.java    From rtree-3d with Apache License 2.0 5 votes vote down vote up
private Box calculateMaxView(RTree<T, S> tree) {
    return tree.entries().reduce(Optional.<Box> absent(),
            new Func2<Optional<Box>, Entry<T, S>, Optional<Box>>() {

                @Override
                public Optional<Box> call(Optional<Box> r, Entry<T, S> entry) {
                    if (r.isPresent())
                        return of(r.get().add(entry.geometry().mbb()));
                    else
                        return of(entry.geometry().mbb());
                }
            }).toBlocking().single().or(box(0, 0, 0, 0, 0, 0));
}