Remove default blockTimeout on interface clients

See gh-30403
This commit is contained in:
Olga MaciaszekSharma 2023-04-28 17:57:44 +02:00 committed by rstoyanchev
parent e416dfdbc0
commit 033548a760
6 changed files with 33 additions and 15 deletions

View File

@ -497,6 +497,11 @@ Annotated, HTTP exchange methods support the following return values:
TIP: You can also use any other async or reactive types registered in the TIP: You can also use any other async or reactive types registered in the
`ReactiveAdapterRegistry`. `ReactiveAdapterRegistry`.
TIP: For non-reactive types, blocking from a reactive publisher is performed
under the hood by the framework. By default, it is done without a timeout.
You can set a timeout for blocking by calling `blockTimeout(Duration blockTimeout)`
on `HttpServiceProxyFactory.Builder`.
[[rest-http-interface-exceptions]] [[rest-http-interface-exceptions]]
=== Exception Handling === Exception Handling

View File

@ -1063,3 +1063,8 @@ method parameters:
Annotated, RSocket exchange methods support return values that are concrete value(s), or Annotated, RSocket exchange methods support return values that are concrete value(s), or
any producer of value(s) that can be adapted to a Reactive Streams `Publisher` via any producer of value(s) that can be adapted to a Reactive Streams `Publisher` via
`ReactiveAdapterRegistry`. `ReactiveAdapterRegistry`.
TIP: For non-reactive types, blocking from a reactive publisher is performed
under the hood by the framework. By default, it is done without a timeout.
You can set a timeout for blocking by calling `blockTimeout(Duration blockTimeout)`
on `RSocketServiceProxyFactory.Builder`.

View File

@ -67,7 +67,7 @@ final class RSocketServiceMethod {
RSocketServiceMethod( RSocketServiceMethod(
Method method, Class<?> containingClass, List<RSocketServiceArgumentResolver> argumentResolvers, Method method, Class<?> containingClass, List<RSocketServiceArgumentResolver> argumentResolvers,
RSocketRequester rsocketRequester, @Nullable StringValueResolver embeddedValueResolver, RSocketRequester rsocketRequester, @Nullable StringValueResolver embeddedValueResolver,
ReactiveAdapterRegistry reactiveRegistry, Duration blockTimeout) { ReactiveAdapterRegistry reactiveRegistry, @Nullable Duration blockTimeout) {
this.method = method; this.method = method;
this.parameters = initMethodParameters(method); this.parameters = initMethodParameters(method);
@ -125,7 +125,7 @@ final class RSocketServiceMethod {
private static Function<RSocketRequestValues, Object> initResponseFunction( private static Function<RSocketRequestValues, Object> initResponseFunction(
RSocketRequester requester, Method method, RSocketRequester requester, Method method,
ReactiveAdapterRegistry reactiveRegistry, Duration blockTimeout) { ReactiveAdapterRegistry reactiveRegistry, @Nullable Duration blockTimeout) {
MethodParameter returnParam = new MethodParameter(method, -1); MethodParameter returnParam = new MethodParameter(method, -1);
Class<?> returnType = returnParam.getParameterType(); Class<?> returnType = returnParam.getParameterType();
@ -164,8 +164,10 @@ final class RSocketServiceMethod {
return reactiveAdapter.fromPublisher(responsePublisher); return reactiveAdapter.fromPublisher(responsePublisher);
} }
return (blockForOptional ? return (blockForOptional ?
((Mono<?>) responsePublisher).blockOptional(blockTimeout) : (blockTimeout != null ? ((Mono<?>) responsePublisher).blockOptional(blockTimeout) :
((Mono<?>) responsePublisher).block(blockTimeout)); ((Mono<?>) responsePublisher).blockOptional()) :
(blockTimeout != null ? ((Mono<?>) responsePublisher).block(blockTimeout) :
((Mono<?>) responsePublisher).block()));
}); });
} }

View File

@ -59,13 +59,14 @@ public final class RSocketServiceProxyFactory {
private final ReactiveAdapterRegistry reactiveAdapterRegistry; private final ReactiveAdapterRegistry reactiveAdapterRegistry;
@Nullable
private final Duration blockTimeout; private final Duration blockTimeout;
private RSocketServiceProxyFactory( private RSocketServiceProxyFactory(
RSocketRequester rsocketRequester, List<RSocketServiceArgumentResolver> argumentResolvers, RSocketRequester rsocketRequester, List<RSocketServiceArgumentResolver> argumentResolvers,
@Nullable StringValueResolver embeddedValueResolver, @Nullable StringValueResolver embeddedValueResolver,
ReactiveAdapterRegistry reactiveAdapterRegistry, Duration blockTimeout) { ReactiveAdapterRegistry reactiveAdapterRegistry, @Nullable Duration blockTimeout) {
this.rsocketRequester = rsocketRequester; this.rsocketRequester = rsocketRequester;
this.argumentResolvers = argumentResolvers; this.argumentResolvers = argumentResolvers;
@ -139,7 +140,7 @@ public final class RSocketServiceProxyFactory {
private ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); private ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
@Nullable @Nullable
private Duration blockTimeout = Duration.ofSeconds(5); private Duration blockTimeout;
private Builder() { private Builder() {
} }
@ -189,7 +190,8 @@ public final class RSocketServiceProxyFactory {
/** /**
* Configure how long to wait for a response for an HTTP service method * Configure how long to wait for a response for an HTTP service method
* with a synchronous (blocking) method signature. * with a synchronous (blocking) method signature.
* <p>By default this is 5 seconds. * <p>By default this is {@code null},
* in which case means blocking on publishers is done without a timeout.
* @param blockTimeout the timeout value * @param blockTimeout the timeout value
* @return this same builder instance * @return this same builder instance
*/ */
@ -207,7 +209,7 @@ public final class RSocketServiceProxyFactory {
return new RSocketServiceProxyFactory( return new RSocketServiceProxyFactory(
this.rsocketRequester, initArgumentResolvers(), this.rsocketRequester, initArgumentResolvers(),
this.embeddedValueResolver, this.reactiveAdapterRegistry, this.embeddedValueResolver, this.reactiveAdapterRegistry,
(this.blockTimeout != null ? this.blockTimeout : Duration.ofSeconds(5))); this.blockTimeout);
} }
private List<RSocketServiceArgumentResolver> initArgumentResolvers() { private List<RSocketServiceArgumentResolver> initArgumentResolvers() {

View File

@ -71,7 +71,7 @@ final class HttpServiceMethod {
HttpServiceMethod( HttpServiceMethod(
Method method, Class<?> containingClass, List<HttpServiceArgumentResolver> argumentResolvers, Method method, Class<?> containingClass, List<HttpServiceArgumentResolver> argumentResolvers,
HttpClientAdapter client, @Nullable StringValueResolver embeddedValueResolver, HttpClientAdapter client, @Nullable StringValueResolver embeddedValueResolver,
ReactiveAdapterRegistry reactiveRegistry, Duration blockTimeout) { ReactiveAdapterRegistry reactiveRegistry, @Nullable Duration blockTimeout) {
this.method = method; this.method = method;
this.parameters = initMethodParameters(method); this.parameters = initMethodParameters(method);
@ -275,7 +275,7 @@ final class HttpServiceMethod {
private record ResponseFunction( private record ResponseFunction(
Function<HttpRequestValues, Publisher<?>> responseFunction, Function<HttpRequestValues, Publisher<?>> responseFunction,
@Nullable ReactiveAdapter returnTypeAdapter, @Nullable ReactiveAdapter returnTypeAdapter,
boolean blockForOptional, Duration blockTimeout) { boolean blockForOptional, @Nullable Duration blockTimeout) {
private ResponseFunction( private ResponseFunction(
Function<HttpRequestValues, Publisher<?>> responseFunction, Function<HttpRequestValues, Publisher<?>> responseFunction,
@ -298,8 +298,10 @@ final class HttpServiceMethod {
} }
return (this.blockForOptional ? return (this.blockForOptional ?
((Mono<?>) responsePublisher).blockOptional(this.blockTimeout) : (this.blockTimeout != null ? ((Mono<?>) responsePublisher).blockOptional(this.blockTimeout) :
((Mono<?>) responsePublisher).block(this.blockTimeout)); ((Mono<?>) responsePublisher).blockOptional()) :
(this.blockTimeout != null ? ((Mono<?>) responsePublisher).block(this.blockTimeout) :
((Mono<?>) responsePublisher).block()));
} }

View File

@ -66,13 +66,14 @@ public final class HttpServiceProxyFactory {
private final ReactiveAdapterRegistry reactiveAdapterRegistry; private final ReactiveAdapterRegistry reactiveAdapterRegistry;
@Nullable
private final Duration blockTimeout; private final Duration blockTimeout;
private HttpServiceProxyFactory( private HttpServiceProxyFactory(
HttpClientAdapter clientAdapter, List<HttpServiceArgumentResolver> argumentResolvers, HttpClientAdapter clientAdapter, List<HttpServiceArgumentResolver> argumentResolvers,
@Nullable StringValueResolver embeddedValueResolver, @Nullable StringValueResolver embeddedValueResolver,
ReactiveAdapterRegistry reactiveAdapterRegistry, Duration blockTimeout) { ReactiveAdapterRegistry reactiveAdapterRegistry, @Nullable Duration blockTimeout) {
this.clientAdapter = clientAdapter; this.clientAdapter = clientAdapter;
this.argumentResolvers = argumentResolvers; this.argumentResolvers = argumentResolvers;
@ -208,7 +209,8 @@ public final class HttpServiceProxyFactory {
/** /**
* Configure how long to wait for a response for an HTTP service method * Configure how long to wait for a response for an HTTP service method
* with a synchronous (blocking) method signature. * with a synchronous (blocking) method signature.
* <p>By default this is 5 seconds. * <p>By default this is {@code null},
* in which case means blocking on publishers is done without a timeout.
* @param blockTimeout the timeout value * @param blockTimeout the timeout value
* @return this same builder instance * @return this same builder instance
*/ */
@ -226,7 +228,7 @@ public final class HttpServiceProxyFactory {
return new HttpServiceProxyFactory( return new HttpServiceProxyFactory(
this.clientAdapter, initArgumentResolvers(), this.clientAdapter, initArgumentResolvers(),
this.embeddedValueResolver, this.reactiveAdapterRegistry, this.embeddedValueResolver, this.reactiveAdapterRegistry,
(this.blockTimeout != null ? this.blockTimeout : Duration.ofSeconds(5))); this.blockTimeout);
} }
private List<HttpServiceArgumentResolver> initArgumentResolvers() { private List<HttpServiceArgumentResolver> initArgumentResolvers() {