Search in sources :

Example 1 with ServiceDiscoverer

use of io.servicetalk.client.api.ServiceDiscoverer in project servicetalk by apple.

the class DefaultPartitionedHttpClientBuilder method buildStreaming.

@Override
public StreamingHttpClient buildStreaming() {
    final HttpClientBuildContext<U, R> buildContext = builderTemplate.copyBuildCtx();
    final HttpExecutionContext executionContext = buildContext.builder.build().executionContext();
    BiIntFunction<Throwable, ? extends Completable> sdRetryStrategy = serviceDiscovererRetryStrategy;
    if (sdRetryStrategy == null) {
        sdRetryStrategy = retryWithConstantBackoffDeltaJitter(__ -> true, SD_RETRY_STRATEGY_INIT_DURATION, SD_RETRY_STRATEGY_JITTER, executionContext.executor());
    }
    ServiceDiscoverer<U, R, PartitionedServiceDiscovererEvent<R>> psd = new DefaultSingleAddressHttpClientBuilder.RetryingServiceDiscoverer<>(serviceDiscoverer, sdRetryStrategy);
    final PartitionedClientFactory<U, R, FilterableStreamingHttpClient> clientFactory = (pa, sd) -> {
        // build new context, user may have changed anything on the builder from the filter
        DefaultSingleAddressHttpClientBuilder<U, R> builder = buildContext.builder.copyBuildCtx().builder;
        builder.serviceDiscoverer(sd);
        clientFilterFunction.configureForPartition(pa, builder);
        if (clientInitializer != null) {
            clientInitializer.initialize(pa, builder);
        }
        return builder.buildStreaming();
    };
    final Publisher<PartitionedServiceDiscovererEvent<R>> psdEvents = psd.discover(buildContext.address()).flatMapConcatIterable(identity());
    DefaultPartitionedStreamingHttpClientFilter<U, R> partitionedClient = new DefaultPartitionedStreamingHttpClientFilter<>(psdEvents, serviceDiscoveryMaxQueueSize, clientFactory, partitionAttributesBuilderFactory, defaultReqRespFactory(buildContext.httpConfig().asReadOnly(), executionContext.bufferAllocator()), executionContext, partitionMapFactory);
    HttpExecutionStrategy computedStrategy = buildContext.builder.computeChainStrategy(executionContext.executionStrategy());
    LOGGER.debug("Client created with base strategy {} → computed strategy {}", executionContext.executionStrategy(), computedStrategy);
    return new FilterableClientToClient(partitionedClient, computedStrategy);
}
Also used : FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) HttpRequestMethod(io.servicetalk.http.api.HttpRequestMethod) Publisher(io.servicetalk.concurrent.api.Publisher) PartitionMapFactory(io.servicetalk.client.api.partition.PartitionMapFactory) LoggerFactory(org.slf4j.LoggerFactory) ClientGroup(io.servicetalk.client.api.ClientGroup) Function(java.util.function.Function) SD_RETRY_STRATEGY_JITTER(io.servicetalk.http.netty.DefaultSingleAddressHttpClientBuilder.SD_RETRY_STRATEGY_JITTER) FilterableReservedStreamingHttpConnection(io.servicetalk.http.api.FilterableReservedStreamingHttpConnection) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) SD_RETRY_STRATEGY_INIT_DURATION(io.servicetalk.http.netty.DefaultSingleAddressHttpClientBuilder.SD_RETRY_STRATEGY_INIT_DURATION) DefaultSingleAddressHttpClientBuilder.defaultReqRespFactory(io.servicetalk.http.netty.DefaultSingleAddressHttpClientBuilder.defaultReqRespFactory) Objects.requireNonNull(java.util.Objects.requireNonNull) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) Executor(io.servicetalk.concurrent.api.Executor) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) Nullable(javax.annotation.Nullable) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) RetryStrategies.retryWithConstantBackoffDeltaJitter(io.servicetalk.concurrent.api.RetryStrategies.retryWithConstantBackoffDeltaJitter) PartitionedClientFactory(io.servicetalk.client.api.internal.DefaultPartitionedClientGroup.PartitionedClientFactory) HttpClientBuildContext(io.servicetalk.http.netty.DefaultSingleAddressHttpClientBuilder.HttpClientBuildContext) Logger(org.slf4j.Logger) UnknownPartitionException(io.servicetalk.client.api.partition.UnknownPartitionException) PartitionAttributesBuilder(io.servicetalk.client.api.partition.PartitionAttributesBuilder) ListenableAsyncCloseable(io.servicetalk.concurrent.api.ListenableAsyncCloseable) PartitionedHttpClientBuilder(io.servicetalk.http.api.PartitionedHttpClientBuilder) StreamingHttpRequestResponseFactory(io.servicetalk.http.api.StreamingHttpRequestResponseFactory) Single.defer(io.servicetalk.concurrent.api.Single.defer) Single(io.servicetalk.concurrent.api.Single) Completable(io.servicetalk.concurrent.api.Completable) ServiceDiscoverer(io.servicetalk.client.api.ServiceDiscoverer) PartitionedServiceDiscovererEvent(io.servicetalk.client.api.partition.PartitionedServiceDiscovererEvent) HttpRequestMetaData(io.servicetalk.http.api.HttpRequestMetaData) IoExecutor(io.servicetalk.transport.api.IoExecutor) PartitionAttributes(io.servicetalk.client.api.partition.PartitionAttributes) ClosedPartitionException(io.servicetalk.client.api.partition.ClosedPartitionException) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) DefaultPartitionedClientGroup(io.servicetalk.client.api.internal.DefaultPartitionedClientGroup) PowerSetPartitionMapFactory(io.servicetalk.client.api.internal.partition.PowerSetPartitionMapFactory) StreamingHttpResponseFactory(io.servicetalk.http.api.StreamingHttpResponseFactory) Single.failed(io.servicetalk.concurrent.api.Single.failed) Function.identity(java.util.function.Function.identity) AsyncCloseables.emptyAsyncCloseable(io.servicetalk.concurrent.api.AsyncCloseables.emptyAsyncCloseable) ReservedStreamingHttpConnection(io.servicetalk.http.api.ReservedStreamingHttpConnection) BiIntFunction(io.servicetalk.concurrent.api.BiIntFunction) PartitionHttpClientBuilderConfigurator(io.servicetalk.http.api.PartitionHttpClientBuilderConfigurator) SD_RETRY_STRATEGY_JITTER(io.servicetalk.http.netty.DefaultSingleAddressHttpClientBuilder.SD_RETRY_STRATEGY_JITTER) PartitionedServiceDiscovererEvent(io.servicetalk.client.api.partition.PartitionedServiceDiscovererEvent) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy)

Aggregations

BufferAllocator (io.servicetalk.buffer.api.BufferAllocator)1 ClientGroup (io.servicetalk.client.api.ClientGroup)1 ServiceDiscoverer (io.servicetalk.client.api.ServiceDiscoverer)1 DefaultPartitionedClientGroup (io.servicetalk.client.api.internal.DefaultPartitionedClientGroup)1 PartitionedClientFactory (io.servicetalk.client.api.internal.DefaultPartitionedClientGroup.PartitionedClientFactory)1 PowerSetPartitionMapFactory (io.servicetalk.client.api.internal.partition.PowerSetPartitionMapFactory)1 ClosedPartitionException (io.servicetalk.client.api.partition.ClosedPartitionException)1 PartitionAttributes (io.servicetalk.client.api.partition.PartitionAttributes)1 PartitionAttributesBuilder (io.servicetalk.client.api.partition.PartitionAttributesBuilder)1 PartitionMapFactory (io.servicetalk.client.api.partition.PartitionMapFactory)1 PartitionedServiceDiscovererEvent (io.servicetalk.client.api.partition.PartitionedServiceDiscovererEvent)1 UnknownPartitionException (io.servicetalk.client.api.partition.UnknownPartitionException)1 AsyncCloseables.emptyAsyncCloseable (io.servicetalk.concurrent.api.AsyncCloseables.emptyAsyncCloseable)1 BiIntFunction (io.servicetalk.concurrent.api.BiIntFunction)1 Completable (io.servicetalk.concurrent.api.Completable)1 Executor (io.servicetalk.concurrent.api.Executor)1 ListenableAsyncCloseable (io.servicetalk.concurrent.api.ListenableAsyncCloseable)1 Publisher (io.servicetalk.concurrent.api.Publisher)1 RetryStrategies.retryWithConstantBackoffDeltaJitter (io.servicetalk.concurrent.api.RetryStrategies.retryWithConstantBackoffDeltaJitter)1 Single (io.servicetalk.concurrent.api.Single)1