Search in sources :

Example 1 with HttpHeadersFactory

use of io.servicetalk.http.api.HttpHeadersFactory in project servicetalk by apple.

the class DefaultMultiAddressUrlHttpClientBuilder method buildStreaming.

@Override
public StreamingHttpClient buildStreaming() {
    final CompositeCloseable closeables = newCompositeCloseable();
    try {
        final HttpExecutionContext executionContext = executionContextBuilder.build();
        final ClientFactory clientFactory = new ClientFactory(builderFactory, executionContext, singleAddressInitializer);
        final CachingKeyFactory keyFactory = closeables.prepend(new CachingKeyFactory());
        final HttpHeadersFactory headersFactory = this.headersFactory;
        FilterableStreamingHttpClient urlClient = closeables.prepend(new StreamingUrlHttpClient(executionContext, clientFactory, keyFactory, new DefaultStreamingHttpRequestResponseFactory(executionContext.bufferAllocator(), headersFactory != null ? headersFactory : DefaultHttpHeadersFactory.INSTANCE, HTTP_1_1)));
        // Need to wrap the top level client (group) in order for non-relative redirects to work
        urlClient = redirectConfig == null ? urlClient : new RedirectingHttpRequesterFilter(redirectConfig).create(urlClient);
        LOGGER.debug("Multi-address client created with base strategy {}", executionContext.executionStrategy());
        return new FilterableClientToClient(urlClient, executionContext.executionStrategy());
    } catch (final Throwable t) {
        closeables.closeAsync().subscribe();
        throw t;
    }
}
Also used : DefaultHttpHeadersFactory(io.servicetalk.http.api.DefaultHttpHeadersFactory) HttpHeadersFactory(io.servicetalk.http.api.HttpHeadersFactory) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) CompositeCloseable(io.servicetalk.concurrent.api.CompositeCloseable) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) DefaultStreamingHttpRequestResponseFactory(io.servicetalk.http.api.DefaultStreamingHttpRequestResponseFactory) RedirectingHttpRequesterFilter(io.servicetalk.http.utils.RedirectingHttpRequesterFilter)

Example 2 with HttpHeadersFactory

use of io.servicetalk.http.api.HttpHeadersFactory in project servicetalk by apple.

the class DefaultPartitionedHttpClientBuilder method buildStreaming.

@Override
public StreamingHttpClient buildStreaming() {
    final HttpExecutionContext executionContext = executionContextBuilder.build();
    BiIntFunction<Throwable, ? extends Completable> sdRetryStrategy = serviceDiscovererRetryStrategy;
    if (sdRetryStrategy == null) {
        sdRetryStrategy = retryWithConstantBackoffDeltaJitter(__ -> true, SD_RETRY_STRATEGY_INIT_DURATION, SD_RETRY_STRATEGY_JITTER, executionContext.executor());
    }
    final 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
        final SingleAddressHttpClientBuilder<U, R> builder = requireNonNull(builderFactory.get());
        builder.serviceDiscoverer(sd);
        setExecutionContext(builder, executionContext);
        if (clientInitializer != null) {
            clientInitializer.initialize(pa, builder);
        }
        return builder.buildStreaming();
    };
    final Publisher<PartitionedServiceDiscovererEvent<R>> psdEvents = psd.discover(address).flatMapConcatIterable(identity());
    final HttpHeadersFactory headersFactory = this.headersFactory;
    final DefaultPartitionedStreamingHttpClientFilter<U, R> partitionedClient = new DefaultPartitionedStreamingHttpClientFilter<>(psdEvents, serviceDiscoveryMaxQueueSize, clientFactory, partitionAttributesBuilderFactory, new DefaultStreamingHttpRequestResponseFactory(executionContext.bufferAllocator(), headersFactory != null ? headersFactory : DefaultHttpHeadersFactory.INSTANCE, HTTP_1_1), executionContext, partitionMapFactory);
    LOGGER.debug("Partitioned client created with base strategy {}", executionContext.executionStrategy());
    return new FilterableClientToClient(partitionedClient, executionContext.executionStrategy());
}
Also used : FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) HttpRequestMethod(io.servicetalk.http.api.HttpRequestMethod) LoggerFactory(org.slf4j.LoggerFactory) ClientGroup(io.servicetalk.client.api.ClientGroup) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) Executor(io.servicetalk.concurrent.api.Executor) RetryStrategies.retryWithConstantBackoffDeltaJitter(io.servicetalk.concurrent.api.RetryStrategies.retryWithConstantBackoffDeltaJitter) PartitionedClientFactory(io.servicetalk.client.api.internal.DefaultPartitionedClientGroup.PartitionedClientFactory) UnknownPartitionException(io.servicetalk.client.api.partition.UnknownPartitionException) PartitionedHttpClientBuilder(io.servicetalk.http.api.PartitionedHttpClientBuilder) ServiceDiscoverer(io.servicetalk.client.api.ServiceDiscoverer) PartitionedServiceDiscovererEvent(io.servicetalk.client.api.partition.PartitionedServiceDiscovererEvent) DefaultHttpHeadersFactory(io.servicetalk.http.api.DefaultHttpHeadersFactory) HttpRequestMetaData(io.servicetalk.http.api.HttpRequestMetaData) PartitionAttributes(io.servicetalk.client.api.partition.PartitionAttributes) ClosedPartitionException(io.servicetalk.client.api.partition.ClosedPartitionException) DefaultPartitionedClientGroup(io.servicetalk.client.api.internal.DefaultPartitionedClientGroup) PowerSetPartitionMapFactory(io.servicetalk.client.api.internal.partition.PowerSetPartitionMapFactory) Function.identity(java.util.function.Function.identity) ReservedStreamingHttpConnection(io.servicetalk.http.api.ReservedStreamingHttpConnection) BiIntFunction(io.servicetalk.concurrent.api.BiIntFunction) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Publisher(io.servicetalk.concurrent.api.Publisher) PartitionMapFactory(io.servicetalk.client.api.partition.PartitionMapFactory) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SD_RETRY_STRATEGY_JITTER(io.servicetalk.http.netty.DefaultSingleAddressHttpClientBuilder.SD_RETRY_STRATEGY_JITTER) FilterableReservedStreamingHttpConnection(io.servicetalk.http.api.FilterableReservedStreamingHttpConnection) SD_RETRY_STRATEGY_INIT_DURATION(io.servicetalk.http.netty.DefaultSingleAddressHttpClientBuilder.SD_RETRY_STRATEGY_INIT_DURATION) Objects.requireNonNull(java.util.Objects.requireNonNull) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) Nullable(javax.annotation.Nullable) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) Logger(org.slf4j.Logger) PartitionAttributesBuilder(io.servicetalk.client.api.partition.PartitionAttributesBuilder) ListenableAsyncCloseable(io.servicetalk.concurrent.api.ListenableAsyncCloseable) 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) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) IoExecutor(io.servicetalk.transport.api.IoExecutor) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) StreamingHttpResponseFactory(io.servicetalk.http.api.StreamingHttpResponseFactory) Single.failed(io.servicetalk.concurrent.api.Single.failed) DefaultSingleAddressHttpClientBuilder.setExecutionContext(io.servicetalk.http.netty.DefaultSingleAddressHttpClientBuilder.setExecutionContext) AsyncCloseables.emptyAsyncCloseable(io.servicetalk.concurrent.api.AsyncCloseables.emptyAsyncCloseable) HttpHeadersFactory(io.servicetalk.http.api.HttpHeadersFactory) HTTP_1_1(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1) DefaultStreamingHttpRequestResponseFactory(io.servicetalk.http.api.DefaultStreamingHttpRequestResponseFactory) DefaultHttpHeadersFactory(io.servicetalk.http.api.DefaultHttpHeadersFactory) HttpHeadersFactory(io.servicetalk.http.api.HttpHeadersFactory) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) DefaultStreamingHttpRequestResponseFactory(io.servicetalk.http.api.DefaultStreamingHttpRequestResponseFactory) 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)

Aggregations

DefaultHttpHeadersFactory (io.servicetalk.http.api.DefaultHttpHeadersFactory)2 DefaultStreamingHttpRequestResponseFactory (io.servicetalk.http.api.DefaultStreamingHttpRequestResponseFactory)2 FilterableStreamingHttpClient (io.servicetalk.http.api.FilterableStreamingHttpClient)2 HttpExecutionContext (io.servicetalk.http.api.HttpExecutionContext)2 HttpHeadersFactory (io.servicetalk.http.api.HttpHeadersFactory)2 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 AsyncCloseables.newCompositeCloseable (io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable)1 BiIntFunction (io.servicetalk.concurrent.api.BiIntFunction)1