Change signature of addJvmShutdownHook

* because with Scala 2.12 it can't infer the right overload
* prefer the `() =>`, but here it's clear that it's a callback
* similar in ActorSystem.registerOnTermination
This commit is contained in:
Patrik Nordwall 2017-01-25 09:01:11 +01:00
parent 94e40460a4
commit ca09f706eb
2 changed files with 4 additions and 4 deletions

View file

@ -377,14 +377,14 @@ final class CoordinatedShutdown private[akka] (
* concurrently, but they are running before Akka internal shutdown
* hooks, e.g. those shutting down Artery.
*/
@tailrec def addJvmShutdownHook(hook: () Unit): Unit = {
@tailrec def addJvmShutdownHook[T](hook: T): Unit = {
if (!runStarted.get) {
val currentLatch = _jvmHooksLatch.get
val newLatch = new CountDownLatch(currentLatch.getCount.toInt + 1)
if (_jvmHooksLatch.compareAndSet(currentLatch, newLatch)) {
try Runtime.getRuntime.addShutdownHook(new Thread {
override def run(): Unit = {
try hook() finally _jvmHooksLatch.get.countDown()
try hook finally _jvmHooksLatch.get.countDown()
}
}) catch {
case e: IllegalStateException
@ -404,6 +404,6 @@ final class CoordinatedShutdown private[akka] (
* hooks, e.g. those shutting down Artery.
*/
def addJvmShutdownHook(hook: Runnable): Unit =
addJvmShutdownHook(() hook.run())
addJvmShutdownHook(hook.run())
}

View file

@ -646,7 +646,7 @@ class ActorDocSpec extends AkkaSpec("""
//#coordinated-shutdown-addTask
//#coordinated-shutdown-jvm-hook
CoordinatedShutdown(system).addJvmShutdownHook { () =>
CoordinatedShutdown(system).addJvmShutdownHook {
println("custom JVM shutdown hook...")
}
//#coordinated-shutdown-jvm-hook