Introduce the CancellationScheduler interface#5220
Conversation
CancellationScheduler interface
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #5220 +/- ##
===========================================
+ Coverage 0 74.05% +74.05%
- Complexity 0 19968 +19968
===========================================
Files 0 1717 +1717
Lines 0 73576 +73576
Branches 0 9364 +9364
===========================================
+ Hits 0 54489 +54489
- Misses 0 14647 +14647
- Partials 0 4440 +4440
☔ View full report in Codecov by Sentry. |
| import io.netty.util.concurrent.EventExecutor; | ||
|
|
||
| @SuppressWarnings("UnstableApiUsage") | ||
| final class DefaultCancellationScheduler implements CancellationScheduler { |
There was a problem hiding this comment.
I didn't look at this class because I think there's no logic change. Please let me know If it's. 😎
There was a problem hiding this comment.
Did a diff with the main branch so that review can be done more easily
user@AL02437565 Projects % diff upstream-armeria/core/src/main/java/com/linecorp/armeria/internal/common/CancellationScheduler.java armeria/core/src/main/java/com/linecorp/armeria/internal/common/DefaultCancellationScheduler.java
39,40c39
< @SuppressWarnings("UnstableApiUsage")
< public final class CancellationScheduler {
---
> final class DefaultCancellationScheduler implements CancellationScheduler {
42c41
< private static final AtomicReferenceFieldUpdater<CancellationScheduler, CancellationFuture>
---
> private static final AtomicReferenceFieldUpdater<DefaultCancellationScheduler, CancellationFuture>
44c43
< CancellationScheduler.class, CancellationFuture.class, "whenCancelling");
---
> DefaultCancellationScheduler.class, CancellationFuture.class, "whenCancelling");
46c45
< private static final AtomicReferenceFieldUpdater<CancellationScheduler, CancellationFuture>
---
> private static final AtomicReferenceFieldUpdater<DefaultCancellationScheduler, CancellationFuture>
48c47
< CancellationScheduler.class, CancellationFuture.class, "whenCancelled");
---
> DefaultCancellationScheduler.class, CancellationFuture.class, "whenCancelled");
50c49
< private static final AtomicReferenceFieldUpdater<CancellationScheduler, TimeoutFuture>
---
> private static final AtomicReferenceFieldUpdater<DefaultCancellationScheduler, TimeoutFuture>
52c51
< CancellationScheduler.class, TimeoutFuture.class, "whenTimingOut");
---
> DefaultCancellationScheduler.class, TimeoutFuture.class, "whenTimingOut");
54c53
< private static final AtomicReferenceFieldUpdater<CancellationScheduler, TimeoutFuture>
---
> private static final AtomicReferenceFieldUpdater<DefaultCancellationScheduler, TimeoutFuture>
56c55
< CancellationScheduler.class, TimeoutFuture.class, "whenTimedOut");
---
> DefaultCancellationScheduler.class, TimeoutFuture.class, "whenTimedOut");
58c57
< private static final AtomicReferenceFieldUpdater<CancellationScheduler, Runnable>
---
> private static final AtomicReferenceFieldUpdater<DefaultCancellationScheduler, Runnable>
60c59
< CancellationScheduler.class, Runnable.class, "pendingTask");
---
> DefaultCancellationScheduler.class, Runnable.class, "pendingTask");
62,63c61,62
< private static final AtomicLongFieldUpdater<CancellationScheduler> pendingTimeoutNanosUpdater =
< AtomicLongFieldUpdater.newUpdater(CancellationScheduler.class, "pendingTimeoutNanos");
---
> private static final AtomicLongFieldUpdater<DefaultCancellationScheduler> pendingTimeoutNanosUpdater =
> AtomicLongFieldUpdater.newUpdater(DefaultCancellationScheduler.class, "pendingTimeoutNanos");
93c92
< public CancellationScheduler(long timeoutNanos) {
---
> DefaultCancellationScheduler(long timeoutNanos) {
99c98
< * Initializes this {@link CancellationScheduler}.
---
> * Initializes this {@link DefaultCancellationScheduler}.
100a100
> @Override
137a138
> @Override
141a143
> @Override
176a179
> @Override
295a299
> @Override
299a304
> @Override
328a334
> @Override
336a343
> @Override
341a349
> @Override
345a354
> @Override
349a359
> @Override
362a373
> @Override
375a387
> @Override
394a407
> @Override
413a427
> @Override
495,517d508
< enum State {
< INIT,
< INACTIVE,
< SCHEDULED,
< FINISHING,
< FINISHED
< }
<
< /**
< * A cancellation task invoked by the scheduler when its timeout exceeds or invoke by the user.
< */
< public interface CancellationTask {
< /**
< * Returns {@code true} if the cancellation task can be scheduled.
< */
< boolean canSchedule();
<
< /**
< * Invoked by the scheduler with the cause of cancellation.
< */
< void run(Throwable cause);
< }
<
user@AL02437565 Projects %
There was a problem hiding this comment.
So I guess there's no logic changes then. 😉
|
|
||
| @Override | ||
| public long timeoutNanos() { | ||
| return 0; |
There was a problem hiding this comment.
Will MAX_VALUE be more appropriate?
Never mind, 0 will be fine.
| } | ||
| } | ||
| static CancellationScheduler finished(boolean server) { | ||
| final CancellationScheduler cancellationScheduler = of(0); |
There was a problem hiding this comment.
minor) Should we cache and reuse?
if (server) {
return serverfinishedCancellationScheduler;
} else {
...
}
6864add to
0bc6edd
Compare
Motivation: While working on line#5212, I realized that `noopResponseCancellationScheduler` is an already completed scheduler. When we create a `DefaultClientRequestContext` for the upgrade request, we use this scheduler. https://github.com/line/armeria/blob/8e139d972f5137f9d1805ddda4a7aeae60fecd40/core/src/main/java/com/linecorp/armeria/client/HttpClientPipelineConfigurator.java#L550 However, actually what we want is a scheduler which never completes instead of an already completed scheduler. For this reason, I propose that we separate a - `CancellationScheduler#noop`: signifies a scheduler which never completes - `CancellationScheduler#finished`: signifies a scheduler which already completed Note that the upgrade request is already bound by `connectTimeout`, so it is safe to use a `CancellationScheduler` which never completes. Modifications: - Rename `CancellationScheduler` to `DefaultCancellationScheduler`, and reduce visibility - Introduce an interface `CancellationScheduler` - Introduce factory methods `CancellationScheduler#of`, `CancellationScheduler#noop`, `CancellationScheduler#finished` Result: - It is easier to handle line#5212. - Cleaner code overall. <!-- Visit this URL to learn more about how to write a pull request description: https://armeria.dev/community/developer-guide#how-to-write-pull-request-description -->
Motivation:
While working on #5212, I realized that
noopResponseCancellationScheduleris an already completed scheduler.When we create a
DefaultClientRequestContextfor the upgrade request, we use this scheduler.armeria/core/src/main/java/com/linecorp/armeria/client/HttpClientPipelineConfigurator.java
Line 550 in 8e139d9
However, actually what we want is a scheduler which never completes instead of an already completed scheduler.
For this reason, I propose that we separate a
CancellationScheduler#noop: signifies a scheduler which never completesCancellationScheduler#finished: signifies a scheduler which already completedNote that the upgrade request is already bound by
connectTimeout, so it is safe to use aCancellationSchedulerwhich never completes.Modifications:
CancellationSchedulertoDefaultCancellationScheduler, and reduce visibilityCancellationSchedulerCancellationScheduler#of,CancellationScheduler#noop,CancellationScheduler#finishedResult:
CancellationSchedulerfinishes even if not started #5212.