diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/Explorer.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/Explorer.kt index 3bef43206d..4323e74d2c 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/Explorer.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/Explorer.kt @@ -12,8 +12,8 @@ class Explorer(val explorerController: ExplorerController) : AutoCloseable { fun open(config: NodeConfig, onExit: (NodeConfig) -> Unit) { val explorerDir = config.explorerDir.toFile() - if (!explorerDir.isDirectory() && !explorerDir.mkdirs()) { - log.warn("Failed to create working directory '{}'", explorerDir.getAbsolutePath()) + if (!explorerDir.isDirectory && !explorerDir.mkdirs()) { + log.warn("Failed to create working directory '{}'", explorerDir.absolutePath) onExit(config) return } @@ -30,6 +30,8 @@ class Explorer(val explorerController: ExplorerController) : AutoCloseable { ) process = p + log.info("Launched Node Explorer for '{}'", config.legalName) + executor.submit { val exitValue = p.waitFor() process = null diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/WebServer.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/WebServer.kt new file mode 100644 index 0000000000..977ad666a9 --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/WebServer.kt @@ -0,0 +1,40 @@ +package net.corda.demobench.model + +import org.slf4j.LoggerFactory +import java.util.concurrent.Executors + +class WebServer(val webServerController: WebServerController) : AutoCloseable { + private val log = LoggerFactory.getLogger(WebServer::class.java) + + private val executor = Executors.newSingleThreadExecutor() + private var process: Process? = null + + fun open(config: NodeConfig, onExit: (NodeConfig) -> Unit) { + val nodeDir = config.nodeDir.toFile() + + if (!nodeDir.isDirectory) { + log.warn("Working directory '{}' does not exist.", nodeDir.absolutePath) + onExit(config) + return + } + + val p = webServerController.execute(config.nodeDir) + process = p + + log.info("Launched Web Server for '{}'", config.legalName) + + executor.submit { + val exitValue = p.waitFor() + process = null + + log.info("Web Server for '{}' has exited (value={})", config.legalName, exitValue) + onExit(config) + } + } + + override fun close() { + executor.shutdown() + process?.destroy() + } + +} diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/WebServerController.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/WebServerController.kt new file mode 100644 index 0000000000..dd2118bc36 --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/WebServerController.kt @@ -0,0 +1,19 @@ +package net.corda.demobench.model + +import tornadofx.Controller +import java.nio.file.Path + +class WebServerController : Controller() { + + private val jvm by inject() + private val cordaPath = jvm.applicationDir.resolve("corda").resolve("corda.jar") + + init { + log.info("Web Server JAR: $cordaPath") + } + + internal fun execute(cwd: Path) = jvm.execute(cordaPath, cwd, "--webserver") + + fun webServer() = WebServer(this) + +} \ No newline at end of file diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTerminalView.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTerminalView.kt index b511ccbecf..531a5dbcd8 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTerminalView.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/views/NodeTerminalView.kt @@ -23,6 +23,7 @@ class NodeTerminalView : Fragment() { private val nodeController by inject() private val explorerController by inject() + private val webServerController by inject() private val nodeName by fxid