From 04cf836cf0283b953485a2ebd18414c3a0dfb754 Mon Sep 17 00:00:00 2001 From: Cruz Julian Bishop Date: Fri, 29 Jun 2012 21:59:48 +1000 Subject: [PATCH] Change Timeout.cancel() to return a boolean value, true on a successful cancel As requested in the javadoc for HashedWheelTimer --- .../src/main/java/io/netty/util/HashedWheelTimer.java | 6 +++--- common/src/main/java/io/netty/util/Timeout.java | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/io/netty/util/HashedWheelTimer.java b/common/src/main/java/io/netty/util/HashedWheelTimer.java index ca31f06ebc..a55a1498a8 100644 --- a/common/src/main/java/io/netty/util/HashedWheelTimer.java +++ b/common/src/main/java/io/netty/util/HashedWheelTimer.java @@ -501,13 +501,13 @@ public class HashedWheelTimer implements Timer { } @Override - public void cancel() { + public boolean cancel() { if (!state.compareAndSet(ST_INIT, ST_CANCELLED)) { - // TODO return false - return; + return false; } wheel[stopIndex].remove(this); + return true; } @Override diff --git a/common/src/main/java/io/netty/util/Timeout.java b/common/src/main/java/io/netty/util/Timeout.java index 139553f1bc..30a7da3ae1 100644 --- a/common/src/main/java/io/netty/util/Timeout.java +++ b/common/src/main/java/io/netty/util/Timeout.java @@ -44,9 +44,11 @@ public interface Timeout { boolean isCancelled(); /** - * Cancels the {@link TimerTask} associated with this handle. It the - * task has been executed or cancelled already, it will return with no - * side effect. + * Attempts to cancel the {@link TimerTask} associated with this handle. + * If the task has been executed or cancelled already, it will return with + * no side effect. + * + * @return True if the cancellation completed successfully, otherwise false */ - void cancel(); + boolean cancel(); }