From 8750768f4a9e81f399fa8b39a3268f2c47e4375a Mon Sep 17 00:00:00 2001 From: jrhee17 Date: Tue, 23 Jan 2024 16:33:31 +0900 Subject: [PATCH] address comment by @ikhoon --- .../common/DefaultCancellationScheduler.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/linecorp/armeria/internal/common/DefaultCancellationScheduler.java b/core/src/main/java/com/linecorp/armeria/internal/common/DefaultCancellationScheduler.java index 29572d16264..2b0d106ee44 100644 --- a/core/src/main/java/com/linecorp/armeria/internal/common/DefaultCancellationScheduler.java +++ b/core/src/main/java/com/linecorp/armeria/internal/common/DefaultCancellationScheduler.java @@ -17,6 +17,7 @@ package com.linecorp.armeria.internal.common; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; import static java.util.concurrent.TimeUnit.NANOSECONDS; import java.util.concurrent.CompletableFuture; @@ -64,10 +65,6 @@ final class DefaultCancellationScheduler implements CancellationScheduler { private static final AtomicLongFieldUpdater pendingTimeoutNanosUpdater = AtomicLongFieldUpdater.newUpdater(DefaultCancellationScheduler.class, "pendingTimeoutNanos"); - private static final AtomicReferenceFieldUpdater - eventLoopUpdater = AtomicReferenceFieldUpdater.newUpdater( - DefaultCancellationScheduler.class, EventExecutor.class, "eventLoop"); - private static final Runnable noopPendingTask = () -> { }; @@ -78,7 +75,7 @@ final class DefaultCancellationScheduler implements CancellationScheduler { private long timeoutNanos; private long startTimeNanos; @Nullable - private volatile EventExecutor eventLoop; + private EventExecutor eventLoop; @Nullable private CancellationTask task; @Nullable @@ -125,9 +122,8 @@ public void initAndStart(EventExecutor eventLoop, CancellationTask task) { @Override public void init(EventExecutor eventLoop) { - if (!eventLoopUpdater.compareAndSet(this, null, eventLoop)) { - throw new IllegalStateException("Can't init() more than once"); - } + checkState(this.eventLoop == null, "Scheduler is already initialized with %s", this.eventLoop); + this.eventLoop = eventLoop; } @Override