Skip to content

Commit

Permalink
Add package private isAlive and specific Exception type
Browse files Browse the repository at this point in the history
The motivation for this is to make it possible to not submit a new task when the TickWheelExecutor is being shutdown.
This mostly happens at the end, so we just want to make sure we dont submit or fail with an exception.
  • Loading branch information
hamnis committed May 25, 2021
1 parent 4d8fed8 commit ada8b98
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
package org.http4s.blaze.util

import java.util.concurrent.atomic.AtomicReference

import scala.annotation.tailrec
import scala.util.control.NonFatal
import scala.util.control.{NoStackTrace, NonFatal}
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import org.http4s.blaze.util.TickWheelExecutor.DefaultWheelSize
Expand Down Expand Up @@ -77,6 +76,8 @@ class TickWheelExecutor(wheelSize: Int = DefaultWheelSize, val tick: Duration =
def shutdown(): Unit =
alive = false

private[http4s] def isAlive = alive

/** Schedule the `Runnable` on the [[TickWheelExecutor]]
*
* Execution is performed on the [[TickWheelExecutor]]s thread, so only extremely small
Expand Down Expand Up @@ -127,7 +128,7 @@ class TickWheelExecutor(wheelSize: Int = DefaultWheelSize, val tick: Duration =
Cancelable.NoopCancel
}
}
else sys.error("TickWheelExecutor is shutdown")
else throw TickWheelExecutor.AlreadyShutdownException

// Deals with appending and removing tasks from the buckets
private def handleTasks(): Unit = {
Expand Down Expand Up @@ -273,6 +274,9 @@ class TickWheelExecutor(wheelSize: Int = DefaultWheelSize, val tick: Duration =
}

object TickWheelExecutor {
object AlreadyShutdownException
extends RuntimeException("TickWheelExecutor is shutdown")
with NoStackTrace

/** Default size of the hash wheel */
val DefaultWheelSize = 512
Expand Down

0 comments on commit ada8b98

Please sign in to comment.