-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(deadline) changed the name of deadline property to timeout.
- Loading branch information
Бацура Сергей Александрович
authored and
Бацура Сергей Александрович
committed
Sep 6, 2024
1 parent
f365af7
commit 1aaef80
Showing
7 changed files
with
44 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,42 +28,42 @@ | |
import lombok.extern.slf4j.Slf4j; | ||
import net.devh.boot.grpc.client.channelfactory.GrpcChannelConfigurer; | ||
import net.devh.boot.grpc.client.config.GrpcChannelsProperties; | ||
import net.devh.boot.grpc.client.interceptor.DeadlineSetupClientInterceptor; | ||
import net.devh.boot.grpc.client.interceptor.TimeoutSetupClientInterceptor; | ||
|
||
/** | ||
* The deadline autoconfiguration for the client. | ||
* The timeout autoconfiguration for the client. | ||
* | ||
* <p> | ||
* You can disable this config by using: | ||
* </p> | ||
* | ||
* <pre> | ||
* <code>@ImportAutoConfiguration(exclude = GrpcClientDeadlineAutoConfiguration.class)</code> | ||
* <code>@ImportAutoConfiguration(exclude = GrpcClientTimeoutAutoConfiguration.class)</code> | ||
* </pre> | ||
* | ||
* @author Sergei Batsura ([email protected]) | ||
*/ | ||
@Slf4j | ||
@Configuration(proxyBeanMethods = false) | ||
@AutoConfigureBefore(GrpcClientAutoConfiguration.class) | ||
public class GrpcClientDeadlineAutoConfiguration { | ||
public class GrpcClientTimeoutAutoConfiguration { | ||
|
||
/** | ||
* Creates a {@link GrpcChannelConfigurer} bean applying the default deadline from config to each new call using a | ||
* Creates a {@link GrpcChannelConfigurer} bean applying the default timeout from config to each new call using a | ||
* {@link ClientInterceptor}. | ||
* | ||
* @param props The properties for deadline configuration. | ||
* @return The GrpcChannelConfigurer bean with interceptor if deadline is configured. | ||
* @see DeadlineSetupClientInterceptor | ||
* @param props The properties for timeout configuration. | ||
* @return The GrpcChannelConfigurer bean with interceptor if timeout is configured. | ||
* @see TimeoutSetupClientInterceptor | ||
*/ | ||
@Bean | ||
GrpcChannelConfigurer deadlineGrpcChannelConfigurer(final GrpcChannelsProperties props) { | ||
GrpcChannelConfigurer timeoutGrpcChannelConfigurer(final GrpcChannelsProperties props) { | ||
requireNonNull(props, "properties"); | ||
|
||
return (channel, name) -> { | ||
Duration deadline = props.getChannel(name).getDeadline(); | ||
if (deadline != null && deadline.toMillis() > 0L) { | ||
channel.intercept(new DeadlineSetupClientInterceptor(deadline)); | ||
Duration timeout = props.getChannel(name).getTimeout(); | ||
if (timeout != null && timeout.toMillis() > 0L) { | ||
channel.intercept(new TimeoutSetupClientInterceptor(timeout)); | ||
} | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,25 +28,25 @@ | |
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Deadline setup client interceptor that create new deadline instance from defaultDeadline. | ||
* Timeout setup client interceptor that create new deadline instance from the timeout. | ||
* | ||
* @author Sergei Batsura ([email protected]) | ||
*/ | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class DeadlineSetupClientInterceptor implements ClientInterceptor { | ||
public class TimeoutSetupClientInterceptor implements ClientInterceptor { | ||
|
||
private final Duration defaultDeadline; | ||
private final Duration timeout; | ||
|
||
@Override | ||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( | ||
final MethodDescriptor<ReqT, RespT> method, | ||
final CallOptions callOptions, | ||
final Channel next) { | ||
|
||
if (defaultDeadline != null && callOptions.getDeadline() == null) { | ||
if (timeout != null && callOptions.getDeadline() == null) { | ||
return next.newCall(method, | ||
callOptions.withDeadlineAfter(defaultDeadline.toMillis(), TimeUnit.MILLISECONDS)); | ||
callOptions.withDeadlineAfter(timeout.toMillis(), TimeUnit.MILLISECONDS)); | ||
} else { | ||
return next.newCall(method, callOptions); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters