Skip to content

Commit

Permalink
ExecutionStrategy simplification deprecations (#1781) (#1793)
Browse files Browse the repository at this point in the history
Motivation:
removed methods should be deprecated before they are removed.
Modifications:
Marks methods to be removed in #1695 as deprecated and, where possible,
provides and suggests alternatives.
Result:
Warnings for future method removals are provided.
  • Loading branch information
bondolo authored Sep 3, 2021
1 parent 22d9935 commit 1674e44
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public static GrpcExecutionStrategy defaultStrategy() {
*
* @param executor {@link Executor} to use.
* @return Default {@link GrpcExecutionStrategy}.
* @deprecated Set the executor to use on the {@link io.servicetalk.transport.api.ExecutionContext} using
* {@code executor(Executor)} methods on client/server builders.
*/
@Deprecated
public static GrpcExecutionStrategy defaultStrategy(final Executor executor) {
return new DefaultGrpcExecutionStrategy(HttpExecutionStrategies.defaultStrategy(executor));
}
Expand Down Expand Up @@ -133,7 +136,10 @@ public Builder offloadNone() {
*
* @param executor {@link Executor} to use.
* @return {@code this}.
* @deprecated Set the executor to use on the {@link io.servicetalk.transport.api.ExecutionContext} using
* {@code executor(Executor)} methods on client/server builders.
*/
@Deprecated
public Builder executor(Executor executor) {
httpBuilder.executor(executor);
return this;
Expand All @@ -142,10 +148,9 @@ public Builder executor(Executor executor) {
/**
* Enable thread affinity while offloading. When enabled, offloading implementation will favor using a
* single thread per subscribe of a source.
*
* @deprecated Use a single threaded executor with {@link #executor(Executor)} to ensure affinity.
*
* @return {@code this}.
* @deprecated Use a single threaded executor set on {@link io.servicetalk.transport.api.ExecutionContext} using
* {@code executor(Executor)} methods on client/server builders to ensure affinity.
*/
@Deprecated
public Builder offloadWithThreadAffinity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.http.api;

import io.servicetalk.buffer.api.BufferAllocator;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.logging.api.LogLevel;
import io.servicetalk.transport.api.IoExecutor;
import io.servicetalk.transport.api.ServiceTalkSocketOptions;
Expand All @@ -35,6 +36,14 @@
*/
abstract class BaseHttpBuilder<ResolvedAddress> {

/**
* Sets the {@link Executor} for all connections created from this builder.
*
* @param executor {@link Executor} to use.
* @return {@code this}.
*/
public abstract BaseHttpBuilder<ResolvedAddress> executor(Executor executor);

/**
* Sets the {@link IoExecutor} for all connections created from this builder.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.servicetalk.client.api.ServiceDiscoverer;
import io.servicetalk.client.api.ServiceDiscovererEvent;
import io.servicetalk.concurrent.api.BiIntPredicate;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.logging.api.LogLevel;
import io.servicetalk.transport.api.ExecutionContext;
Expand All @@ -45,6 +46,9 @@
*/
abstract class HttpClientBuilder<U, R, SDE extends ServiceDiscovererEvent<R>> extends BaseHttpBuilder<R> {

@Override
public abstract HttpClientBuilder<U, R, SDE> executor(Executor executor);

@Override
public abstract HttpClientBuilder<U, R, SDE> ioExecutor(IoExecutor ioExecutor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public static HttpExecutionStrategy defaultStrategy() {
*
* @param executor {@link Executor} to use.
* @return Default {@link HttpExecutionStrategy}.
* @deprecated Set the executor to use on the {@link io.servicetalk.transport.api.ExecutionContext} using
* {@code executor(Executor)} methods on client/server builders.
*/
@Deprecated
public static HttpExecutionStrategy defaultStrategy(Executor executor) {
return customStrategyBuilder().offloadAll().executor(executor).mergeStrategy(ReturnOther).build();
}
Expand Down Expand Up @@ -226,7 +229,10 @@ public Builder offloadNone() {
*
* @param executor {@link Executor} to use.
* @return {@code this}.
* @deprecated Set the executor to use on the {@link io.servicetalk.transport.api.ExecutionContext} using
* {@code executor(Executor)} methods on client/server builders.
*/
@Deprecated
public Builder executor(Executor executor) {
this.executor = requireNonNull(executor);
return this;
Expand All @@ -251,8 +257,10 @@ public Builder offloadWithThreadAffinity() {
*
* @param mergeStrategy {@link MergeStrategy} to use.
* @return {@code this}.
* @deprecated Will be removed
*/
// Intentionally package-private, API is not required to be public for the lack of use cases.
@Deprecated
Builder mergeStrategy(MergeStrategy mergeStrategy) {
this.mergeStrategy = mergeStrategy;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public interface HttpExecutionStrategy extends ExecutionStrategy {
* trailers, for the passed {@link StreamingHttpRequest} returns a {@link Single}.
* @param <FS> The {@code FlushStrategy} type to use.
* @return {@link Single} which is offloaded as required.
* @deprecated This method will be removed in future releases. If you depend on it, copy the implementation from
* {@link DefaultHttpExecutionStrategy#invokeClient(Executor, Publisher, Object, ClientInvoker)}.
*/
@Deprecated
<FS> Single<StreamingHttpResponse> invokeClient(Executor fallback, Publisher<Object> flattenedRequest,
@Nullable FS flushStrategy, ClientInvoker<FS> client);

Expand Down Expand Up @@ -77,7 +80,10 @@ Publisher<Object> invokeService(Executor fallback, StreamingHttpRequest request,
* @param service {@link Function} representing a service.
* @return A {@link Single} that invokes the passed {@link Function} and returns the result asynchronously.
* Invocation of {@link Function} will be offloaded if configured.
* @deprecated This method will be removed in future releases. If you depend on it, copy the implementation from
* {@link DefaultHttpExecutionStrategy#invokeService(Executor, Function)}.
*/
@Deprecated
<T> Single<T> invokeService(Executor fallback, Function<Executor, T> service);

/**
Expand All @@ -87,7 +93,10 @@ Publisher<Object> invokeService(Executor fallback, StreamingHttpRequest request,
* {@link Executor}.
* @param handler {@link StreamingHttpService} to wrap.
* @return Wrapped {@link StreamingHttpService}.
* @deprecated This method will be removed in future releases. If you depend on it, copy the implementation from
* {@link DefaultHttpExecutionStrategy#offloadService(Executor, StreamingHttpService)}.
*/
@Deprecated
StreamingHttpService offloadService(Executor fallback, StreamingHttpService handler);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.servicetalk.buffer.api.BufferAllocator;
import io.servicetalk.concurrent.api.AsyncContext;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.http.api.HttpApiConversions.ServiceAdapterHolder;
import io.servicetalk.logging.api.LogLevel;
Expand Down Expand Up @@ -282,6 +283,16 @@ public final HttpServerBuilder appendServiceFilter(final Predicate<StreamingHttp
*/
public abstract HttpServerBuilder ioExecutor(IoExecutor ioExecutor);

/**
* Sets the {@link Executor} to use.
*
* @param executor {@link Executor} to use.
* @return {@code this}.
*/
public HttpServerBuilder executor(Executor executor) {
throw new UnsupportedOperationException("Setting Executor not yet supported by " + getClass().getSimpleName());
}

/**
* Sets the {@link BufferAllocator} to be used by this server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.servicetalk.client.api.ConnectionFactoryFilter;
import io.servicetalk.client.api.ServiceDiscoverer;
import io.servicetalk.client.api.ServiceDiscovererEvent;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.logging.api.LogLevel;
import io.servicetalk.transport.api.ClientSecurityConfigurator;
import io.servicetalk.transport.api.ClientSslConfig;
Expand Down Expand Up @@ -82,6 +83,11 @@ default SingleAddressInitializer<U, R> append(SingleAddressInitializer<U, R> toA
@Override
public abstract MultiAddressHttpClientBuilder<U, R> ioExecutor(IoExecutor ioExecutor);

@Override
public MultiAddressHttpClientBuilder<U, R> executor(Executor executor) {
throw new UnsupportedOperationException("Setting Executor not yet supported by " + getClass().getSimpleName());
}

@Override
public abstract MultiAddressHttpClientBuilder<U, R> executionStrategy(HttpExecutionStrategy strategy);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.servicetalk.client.api.partition.PartitionMapFactory;
import io.servicetalk.client.api.partition.PartitionedServiceDiscovererEvent;
import io.servicetalk.concurrent.PublisherSource.Subscriber;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.logging.api.LogLevel;
import io.servicetalk.transport.api.ClientSslConfig;
import io.servicetalk.transport.api.IoExecutor;
Expand Down Expand Up @@ -87,6 +88,11 @@ default SingleAddressInitializer<U, R> append(SingleAddressInitializer<U, R> toA
@Override
public abstract PartitionedHttpClientBuilder<U, R> ioExecutor(IoExecutor ioExecutor);

@Override
public PartitionedHttpClientBuilder<U, R> executor(Executor executor) {
throw new UnsupportedOperationException("Setting Executor not yet supported by " + getClass().getSimpleName());
}

/**
* {@inheritDoc}
* @deprecated {@link #initializer(SingleAddressInitializer)} and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.servicetalk.client.api.ConnectionFactoryFilter;
import io.servicetalk.client.api.ServiceDiscoverer;
import io.servicetalk.client.api.ServiceDiscovererEvent;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.logging.api.LogLevel;
import io.servicetalk.transport.api.ClientSslConfig;
import io.servicetalk.transport.api.IoExecutor;
Expand Down Expand Up @@ -76,6 +77,11 @@ public SingleAddressHttpClientBuilder<U, R> appendConnectionFilter(Predicate<Str
super.appendConnectionFilter(predicate, factory);
}

@Override
public SingleAddressHttpClientBuilder<U, R> executor(Executor executor) {
throw new UnsupportedOperationException("Setting Executor not yet supported by " + getClass().getSimpleName());
}

@Override
public abstract SingleAddressHttpClientBuilder<U, R> appendConnectionFactoryFilter(
ConnectionFactoryFilter<R, FilterableStreamingHttpConnection> factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.http.netty;

import io.servicetalk.buffer.api.BufferAllocator;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.http.api.HttpExecutionContext;
import io.servicetalk.http.api.HttpExecutionStrategy;
Expand Down Expand Up @@ -132,6 +133,12 @@ public HttpServerBuilder ioExecutor(final IoExecutor ioExecutor) {
return this;
}

@Override
public HttpServerBuilder executor(final Executor executor) {
executionContextBuilder.executor(executor);
return this;
}

@Override
public HttpServerBuilder bufferAllocator(final BufferAllocator allocator) {
executionContextBuilder.bufferAllocator(allocator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.servicetalk.concurrent.api.AsyncCloseable;
import io.servicetalk.concurrent.api.Completable;
import io.servicetalk.concurrent.api.CompositeCloseable;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.concurrent.api.ListenableAsyncCloseable;
import io.servicetalk.concurrent.api.Single;
import io.servicetalk.concurrent.api.internal.SubscribableCompletable;
Expand Down Expand Up @@ -356,6 +357,12 @@ public MultiAddressHttpClientBuilder<HostAndPort, InetSocketAddress> ioExecutor(
return this;
}

@Override
public MultiAddressHttpClientBuilder<HostAndPort, InetSocketAddress> executor(final Executor executor) {
builderTemplate.executor(executor);
return this;
}

@Override
public MultiAddressHttpClientBuilder<HostAndPort, InetSocketAddress> bufferAllocator(
final BufferAllocator allocator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.servicetalk.client.api.partition.PartitionedServiceDiscovererEvent;
import io.servicetalk.client.api.partition.UnknownPartitionException;
import io.servicetalk.concurrent.api.Completable;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.concurrent.api.ListenableAsyncCloseable;
import io.servicetalk.concurrent.api.Publisher;
import io.servicetalk.concurrent.api.Single;
Expand Down Expand Up @@ -265,6 +266,12 @@ public PartitionedHttpClientBuilder<U, R> ioExecutor(final IoExecutor ioExecutor
return this;
}

@Override
public PartitionedHttpClientBuilder<U, R> executor(final Executor executor) {
builderTemplate.executor(executor);
return this;
}

@Override
public PartitionedHttpClientBuilder<U, R> bufferAllocator(final BufferAllocator allocator) {
builderTemplate.bufferAllocator(allocator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.servicetalk.concurrent.CompletableSource.Subscriber;
import io.servicetalk.concurrent.api.Completable;
import io.servicetalk.concurrent.api.CompositeCloseable;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.concurrent.api.ListenableAsyncCloseable;
import io.servicetalk.concurrent.api.Publisher;
import io.servicetalk.http.api.DefaultServiceDiscoveryRetryStrategy;
Expand Down Expand Up @@ -418,6 +419,12 @@ public DefaultSingleAddressHttpClientBuilder<U, R> ioExecutor(final IoExecutor i
return this;
}

@Override
public DefaultSingleAddressHttpClientBuilder<U, R> executor(final Executor executor) {
executionContextBuilder.executor(executor);
return this;
}

@Override
public SingleAddressHttpClientBuilder<U, R> executionStrategy(final HttpExecutionStrategy strategy) {
executionContextBuilder.executionStrategy(strategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.http.netty;

import io.servicetalk.buffer.api.BufferAllocator;
import io.servicetalk.concurrent.api.Executor;
import io.servicetalk.http.api.DefaultHttpExecutionContext;
import io.servicetalk.http.api.HttpExecutionContext;
import io.servicetalk.http.api.HttpExecutionStrategy;
Expand Down Expand Up @@ -53,6 +54,17 @@ public HttpExecutionContextBuilder ioExecutor(IoExecutor ioExecutor) {
return this;
}

/**
* Sets the {@link Executor} to use.
*
* @param executor {@link Executor} to use.
* @return {@code this}.
*/
public HttpExecutionContextBuilder executor(Executor executor) {
executionContextBuilder.executor(executor);
return this;
}

/**
* Sets the {@link BufferAllocator} to use.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ public interface ExecutionStrategy {
<T> Publisher<T> offloadReceive(Executor fallback, Publisher<T> original);

/**
* Returns the {@link Executor}, if any for this {@link ExecutionStrategy}.
* Returns the {@link Executor}, if any, for this {@link ExecutionStrategy}.
*
* @return {@link Executor} for this {@link ExecutionStrategy}. {@code null} if none specified.
* @deprecated The {@link Executor} from the {@link io.servicetalk.transport.api.ExecutionContext} should be used
* instead.
*/
@Deprecated
@Nullable
Executor executor();
}

0 comments on commit 1674e44

Please sign in to comment.