-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add java.time.Duration overloads to CallOptions, AbstractStub, Deadline, and other APIs #10245
Comments
Also leaving a breadcrumb that Eric mentioned to me: those methods will probably need the |
We still support non-javatime on Android, so these will need to be surface-level conveniences only. They should immediately convert to the current long-timeunit tuple methods. |
SGTM --- this is very similar to what we do in Guava APIs that historically accept a You'll likely want to decompose to nanoseconds, but be aware of the potential for overflow (which happens at +/- 292 years). We've been using a helper function to decompose a |
APIs that would be quick: Then there's a longer tail: Dunno about these and blocking methods in general. The only occurrence in java.util.concerrent is TimeUnit. I don't see a single blocking method have Duration in Java, so I think we'll leave the awaitTermination and blocking as old-style: |
Thanks! My understanding is that the JDK folks have been a bit apprehensive about adding |
/assign |
Huh. I was able to assign you. I thought folks had to be in the grpc org for that to work. |
Hi @ejona86
|
My question is where should I create the java file for method |
In Guava, we just made a package-private I'm not sure if gRPC can use Java 11+ APIs, but if so, you could do what @ejona86 suggested above: |
Doh, |
Cool. Thanks!
|
In So I'd add an overload and have it's impl just delegate to the safe nano decomposition helper: public final ScheduledHandle scheduleWithFixedDelay(Runnable task, Duration initialDelay, Duration delay, ScheduledExecutorService timerService) {
return scheduleWithFixedDelay(
task,
toNanosSaturated(initialDelay),
toNanosSaturated(delay),
TimeUnit.NANOSECONDS,
timerService);
} |
Sending a PR per-package or sets-of-classes is fine. |
Hi @shubhamraj-samsung it's been a while since your last comment and I also don't see any related PR/draft. |
@ejona86 TimeUnit.NANOSECONDS.convert takes a long and a TimeUnit as arguments and returns the value in nanoseconds. java.time.Duration has getSeconds() so we could call TimeUnit.NANOSECONDS.convert(duration.getSeconds(), TimeUnit.SECONDS). But the nano portion from Duration will be lost. |
Two slight corrections to the above comment:
|
About the 2nd point, yes, by overflow I meant the overflow and its handling in the exception block that we call saturation. |
@ejona86 During implementing java.time.Duration, I faced an issue with java version in build.gradle for the module grpc-api, to fix this issue we changed from VERSION_1_7 to VERSION_1_8 in my Local as java.time.Duration is part of Java 1.8 release. Please suggest FYI below is the error message: |
We used to use |
@ejona86 can you also look at the concern I raised above about using the TimeUnit.NANOSECONDS.convert(long, TimeUnit) approach? |
Reverting changes for DeadLine and raising the PR for the same. |
@kannanjgithub wrote:
No, I was talking about the one that accepts a Duration directly. But then it was pointed out that method is Java 11+. So that meant we needed a helper to wrap |
Is your feature request related to a problem?
long, TimeUnit
APIs encourage plumbing a pair of variables through various layers, or require plumbing a single ambiguous numeric primitive (e.g.,long deadlineInSeconds
). The modern alternative is to use ajava.time.Duration
.Describe the solution you'd like
Every API that requests a
long, TimeUnit
should have ajava.time.Duration
overload as wellDescribe alternatives you've considered
n/a
Additional context
n/a
The text was updated successfully, but these errors were encountered: