From 6e5af62be75cd7f184f17f8241038599b6e0d820 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Fri, 2 Feb 2018 22:02:34 +0100 Subject: [PATCH] Shutting down executor service to that application can exit cleanly --- .../rhubarb_for_spine/AnimationFileModel.kt | 5 ++--- .../com/rhubarb_lip_sync/rhubarb_for_spine/MainModel.kt | 5 +++-- .../com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt | 9 +++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AnimationFileModel.kt b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AnimationFileModel.kt index 3a1f610..005c784 100644 --- a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AnimationFileModel.kt +++ b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AnimationFileModel.kt @@ -8,9 +8,9 @@ import java.nio.file.Path import tornadofx.getValue import tornadofx.observable import tornadofx.setValue -import java.util.concurrent.Executors +import java.util.concurrent.ExecutorService -class AnimationFileModel(animationFilePath: Path) { +class AnimationFileModel(animationFilePath: Path, private val executor: ExecutorService) { val spineJson = SpineJson(animationFilePath) val slotsProperty = SimpleObjectProperty>() @@ -50,7 +50,6 @@ class AnimationFileModel(animationFilePath: Path) { var mouthShapesError by mouthShapesErrorProperty private set - private val executor = Executors.newSingleThreadExecutor() val audioFileModelsProperty = SimpleListProperty( spineJson.audioEvents .map { event -> diff --git a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainModel.kt b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainModel.kt index 678e436..f860a44 100644 --- a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainModel.kt +++ b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainModel.kt @@ -8,8 +8,9 @@ import tornadofx.setValue import java.nio.file.Files import java.nio.file.InvalidPathException import java.nio.file.Paths +import java.util.concurrent.ExecutorService -class MainModel { +class MainModel(private val executor: ExecutorService) { val filePathStringProperty = SimpleStringProperty(getDefaultPathString()).alsoListen { value -> filePathError = getExceptionMessage { animationFileModel = null @@ -28,7 +29,7 @@ class MainModel { throw Exception("File does not exist.") } - animationFileModel = AnimationFileModel(path) + animationFileModel = AnimationFileModel(path, executor) } } var filePathString by filePathStringProperty diff --git a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt index 38ec0bf..7b24be0 100644 --- a/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt +++ b/extras/rhubarb-for-spine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt @@ -14,10 +14,11 @@ import tornadofx.* import java.io.File import java.time.LocalDate import java.time.Period +import java.util.concurrent.Executors class MainView : View() { - - val mainModel = MainModel() + private val executor = Executors.newSingleThreadExecutor() + private val mainModel = MainModel(executor) class Person(val id: Int, val name: String, val birthday: LocalDate) { val age: Int get() = Period.between(birthday, LocalDate.now()).years @@ -119,6 +120,10 @@ class MainView : View() { } } + whenUndocked { + executor.shutdownNow() + } + filePathButton!!.onAction = EventHandler { val fileChooser = FileChooser().apply { title = "Open Spine JSON file"