Java Code Examples for io.reactivex.Flowable#fromFuture()

The following examples show how to use io.reactivex.Flowable#fromFuture() . 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: AWSParameterStoreConfigClient.java    From micronaut-aws with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the Parameter hierarchy from AWS parameter store.
 * Please note this only returns something if the current node has children and will not return itself.
 *
 *
 * @param path path based on the parameter names PRIORITY_TOP.e. /config/application/.*
 * @param nextToken token to paginate in the resultset from AWS
 * @return Publisher for GetParametersByPathResult
 */
private Publisher<GetParametersByPathResult> getHierarchy(String path, String nextToken) {
    LOG.trace("Retrieving parameters by path {}, pagination requested: {}", path, nextToken != null);
    GetParametersByPathRequest getRequest = new GetParametersByPathRequest()
            .withWithDecryption(awsParameterStoreConfiguration.getUseSecureParameters())
            .withPath(path)
            .withRecursive(true)
            .withNextToken(nextToken);

    Future<GetParametersByPathResult> future = client.getParametersByPathAsync(getRequest);

    Flowable<GetParametersByPathResult> invokeFlowable;
    if (executorService != null) {
        invokeFlowable = Flowable.fromFuture(future, Schedulers.from(executorService));
    } else {
        invokeFlowable = Flowable.fromFuture(future);
    }

    return invokeFlowable.onErrorResumeNext(AWSParameterStoreConfigClient::onGetParametersByPathResult);
}
 
Example 2
Source File: AWSParameterStoreConfigClient.java    From micronaut-aws with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the parameters from AWS.
 *
 * @param path this is the hierarchy path (via name field) from the property store
 * @return invokeFlowable - converted future from AWS SDK Async
 */
private Publisher<GetParametersResult> getParameters(String path) {

    GetParametersRequest getRequest = new GetParametersRequest().withWithDecryption(awsParameterStoreConfiguration.getUseSecureParameters()).withNames(path);

    Future<GetParametersResult> future = client.getParametersAsync(getRequest);

    Flowable<GetParametersResult> invokeFlowable;
    if (executorService != null) {
        invokeFlowable = Flowable.fromFuture(future, Schedulers.from(executorService));
    } else {
        invokeFlowable = Flowable.fromFuture(future);
    }

    return invokeFlowable.onErrorResumeNext(AWSParameterStoreConfigClient::onGetParametersError);
}
 
Example 3
Source File: Route53AutoNamingClient.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a list of instances registered with Route53 given a service ID.
 * @param serviceId The service id
 * @return list of serviceInstances usable by MN.
 */
@Override
public Publisher<List<ServiceInstance>> getInstances(String serviceId) {
    if (serviceId == null) {
        serviceId = getRoute53ClientDiscoveryConfiguration().getAwsServiceId();  // we can default to the config file
    }
    ListInstancesRequest instancesRequest = new ListInstancesRequest().withServiceId(serviceId);
    Future<ListInstancesResult> instanceResult = getDiscoveryClient().listInstancesAsync(instancesRequest);
    Flowable<ListInstancesResult> observableInstanceResult = Flowable.fromFuture(instanceResult);
    return observableInstanceResult.flatMap(this::convertInstancesResulttoServiceInstances);
}
 
Example 4
Source File: Route53AutoNamingClient.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a list of service IDs from AWS for a given namespace.
 * @return rx java publisher list of the service IDs in string format
 */
@Override
public Publisher<List<String>> getServiceIds() {
    ServiceFilter serviceFilter = new ServiceFilter().withName("NAMESPACE_ID").withValues(getRoute53ClientDiscoveryConfiguration().getNamespaceId());
    ListServicesRequest listServicesRequest = new ListServicesRequest().withFilters(serviceFilter);
    Future<ListServicesResult> response = getDiscoveryClient().listServicesAsync(listServicesRequest);
    Flowable<ListServicesResult> flowableList = Flowable.fromFuture(response);
    return flowableList.flatMap(this::convertServiceIds);
}
 
Example 5
Source File: KafkaHealthIndicator.java    From micronaut-kafka with Apache License 2.0 4 votes vote down vote up
@Override
public Flowable<HealthResult> getResult() {
    DescribeClusterResult result = adminClient.describeCluster(
            new DescribeClusterOptions().timeoutMs(
                    (int) defaultConfiguration.getHealthTimeout().toMillis()
            )
    );

    Flowable<String> clusterId = Flowable.fromFuture(result.clusterId());
    Flowable<Collection<Node>> nodes = Flowable.fromFuture(result.nodes());
    Flowable<Node> controller = Flowable.fromFuture(result.controller());

    return controller.switchMap(node -> {
        String brokerId = node.idString();
        ConfigResource configResource = new ConfigResource(ConfigResource.Type.BROKER, brokerId);
        DescribeConfigsResult configResult = adminClient.describeConfigs(Collections.singletonList(configResource));
        Flowable<Map<ConfigResource, Config>> configs = Flowable.fromFuture(configResult.all());
        return configs.switchMap(resources -> {
            Config config = resources.get(configResource);
            ConfigEntry ce = config.get(REPLICATION_PROPERTY);
            int replicationFactor = Integer.parseInt(ce.value());
            return nodes.switchMap(nodeList -> clusterId.map(clusterIdString -> {
                int nodeCount = nodeList.size();
                HealthResult.Builder builder;
                if (nodeCount >= replicationFactor) {
                    builder = HealthResult.builder(ID, HealthStatus.UP);
                } else {
                    builder = HealthResult.builder(ID, HealthStatus.DOWN);
                }
                return builder
                        .details(CollectionUtils.mapOf(
                                "brokerId", brokerId,
                                "clusterId", clusterIdString,
                                "nodes", nodeCount
                        )).build();
            }));
        });
    }).onErrorReturn(throwable ->
            HealthResult.builder(ID, HealthStatus.DOWN)
                    .exception(throwable).build()
    );
}