Skip to content

Commit

Permalink
Introduce GrpcExecutionStrategies#offloadNone (#2478)
Browse files Browse the repository at this point in the history
* Introduce GrpcExecutionStrategies#offloadNone

Motivation:

To ensure partiy with HttpExecutionStrategies it makes sense to
introduce "offloadNone" as a static utility method instead of
only making it accessible through a builder.

Modifications:

This changeset adds the static "offloadNone" utility method in
GrpcExecutionStrategies and clarifies the javadoc of "offloadNever"
(which is deprecated) on alternative usage. It also modifies
the Http conversions to include the new strategy explicitly.

Result:

Feature parity between GRPC and HTTP on the "offloadNone" execution
strategy creation.
  • Loading branch information
daschl authored Jan 6, 2023
1 parent 39356fd commit 2344448
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/
public final class GrpcExecutionStrategies {

private static final GrpcExecutionStrategy OFFLOAD_NONE_STRATEGY =
new DefaultGrpcExecutionStrategy(HttpExecutionStrategies.offloadNone());

@Deprecated
private static final GrpcExecutionStrategy NEVER_OFFLOAD_STRATEGY = // FIXME: 0.43 - remove deprecated constant
new DefaultGrpcExecutionStrategy(HttpExecutionStrategies.offloadNever()) {
Expand Down Expand Up @@ -64,15 +67,28 @@ public static GrpcExecutionStrategy defaultStrategy() {
* When merged with another execution strategy the result is always this strategy.
*
* @return {@link GrpcExecutionStrategy} that disables all request-response path offloads.
* @deprecated Use a custom strategy with no offloads instead;
* {@code GrpcExecutionStrategies.customStrategyBuilder().offloadNone().build()}
* @see #offloadNone()
* @deprecated Use {@link #offloadNone()} instead.
*/
// FIXME: 0.43 - remove deprecated method
@Deprecated
public static GrpcExecutionStrategy offloadNever() {
return NEVER_OFFLOAD_STRATEGY;
}

/**
* An {@link GrpcExecutionStrategy} that requires no offloads on the request-response path or transport event path.
* <p>
* For {@link HttpExecutionStrategyInfluencer}s that do not block, the
* {@link HttpExecutionStrategyInfluencer#requiredOffloads()} method should return this value. Unlike
* {@link #offloadNever()}, this strategy merges normally with other execution strategy instances.
* @return {@link GrpcExecutionStrategy} that requires no request-response path offloads.
* @see #offloadNever()
*/
public static GrpcExecutionStrategy offloadNone() {
return OFFLOAD_NONE_STRATEGY;
}

/**
* A {@link GrpcExecutionStrategy} that disables all offloads.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ public interface GrpcExecutionStrategy extends HttpExecutionStrategy {
*
* @return New {@link GrpcExecutionStrategy} using the passed {@link HttpExecutionStrategy}.
*/
static GrpcExecutionStrategy from(HttpExecutionStrategy httpExecutionStrategy) {
static GrpcExecutionStrategy from(final HttpExecutionStrategy httpExecutionStrategy) {
GrpcExecutionStrategy result;
if (httpExecutionStrategy instanceof GrpcExecutionStrategy) {
result = (GrpcExecutionStrategy) httpExecutionStrategy;
} else if (HttpExecutionStrategies.offloadNever() == httpExecutionStrategy) {
result = GrpcExecutionStrategies.offloadNever();
} else if (HttpExecutionStrategies.defaultStrategy() == httpExecutionStrategy) {
result = GrpcExecutionStrategies.defaultStrategy();
} else if (HttpExecutionStrategies.offloadNone() == httpExecutionStrategy) {
result = GrpcExecutionStrategies.offloadNone();
} else {
result = new DefaultGrpcExecutionStrategy(httpExecutionStrategy);
}
Expand Down

0 comments on commit 2344448

Please sign in to comment.